JDBCConfigurazioneStatisticaServiceImpl.java

  1. /*
  2.  * GovWay - A customizable API Gateway
  3.  * https://govway.org
  4.  *
  5.  * Copyright (c) 2005-2025 Link.it srl (https://link.it).
  6.  *
  7.  * This program is free software: you can redistribute it and/or modify
  8.  * it under the terms of the GNU General Public License version 3, as published by
  9.  * the Free Software Foundation.
  10.  *
  11.  * This program is distributed in the hope that it will be useful,
  12.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14.  * GNU General Public License for more details.
  15.  *
  16.  * You should have received a copy of the GNU General Public License
  17.  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  18.  *
  19.  */
  20. package org.openspcoop2.monitor.engine.config.statistiche.dao.jdbc;

  21. import java.sql.Connection;

  22. import org.openspcoop2.utils.sql.ISQLQueryObject;

  23. import org.slf4j.Logger;

  24. import org.openspcoop2.core.plugins.constants.TipoPlugin;
  25. import org.openspcoop2.core.plugins.dao.jdbc.JDBCConfigurazioneServizioAzioneBaseLib;
  26. import org.openspcoop2.core.plugins.dao.jdbc.JDBCPluginsBaseLib;

  27. import org.openspcoop2.generic_project.dao.jdbc.IJDBCServiceCRUDWithId;
  28. import org.openspcoop2.monitor.engine.config.statistiche.IdConfigurazioneStatistica;
  29. import org.openspcoop2.generic_project.beans.NonNegativeNumber;
  30. import org.openspcoop2.generic_project.beans.UpdateField;
  31. import org.openspcoop2.generic_project.beans.UpdateModel;

  32. import org.openspcoop2.generic_project.dao.jdbc.utils.GenericJDBCUtilities;
  33. import org.openspcoop2.generic_project.dao.jdbc.utils.JDBCObject;
  34. import org.openspcoop2.generic_project.exception.NotFoundException;
  35. import org.openspcoop2.generic_project.exception.NotImplementedException;
  36. import org.openspcoop2.generic_project.exception.ServiceException;
  37. import org.openspcoop2.generic_project.expression.IExpression;
  38. import org.openspcoop2.generic_project.dao.jdbc.JDBCExpression;
  39. import org.openspcoop2.generic_project.dao.jdbc.JDBCPaginatedExpression;

  40. import org.openspcoop2.generic_project.dao.jdbc.JDBCServiceManagerProperties;

  41. import org.openspcoop2.monitor.engine.config.statistiche.ConfigurazioneStatistica;

  42. /**    
  43.  * JDBCConfigurazioneStatisticaServiceImpl
  44.  *
  45.  * @author Poli Andrea (poli@link.it)
  46.  * @author $Author$
  47.  * @version $Rev$, $Date$
  48.  */
  49. public class JDBCConfigurazioneStatisticaServiceImpl extends JDBCConfigurazioneStatisticaServiceSearchImpl
  50.     implements IJDBCServiceCRUDWithId<ConfigurazioneStatistica, IdConfigurazioneStatistica, JDBCServiceManager> {

  51.     @Override
  52.     public void create(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject, ConfigurazioneStatistica configurazioneStatistica, org.openspcoop2.generic_project.beans.IDMappingBehaviour idMappingResolutionBehaviour) throws NotImplementedException,ServiceException,Exception {

  53.         org.openspcoop2.generic_project.dao.jdbc.utils.JDBCPreparedStatementUtilities jdbcUtilities =
  54.                 new org.openspcoop2.generic_project.dao.jdbc.utils.JDBCPreparedStatementUtilities(sqlQueryObject.getTipoDatabaseOpenSPCoop2(), log, connection);
  55.        
  56.         ISQLQueryObject sqlQueryObjectInsert = sqlQueryObject.newSQLQueryObject();
  57.        
  58.         if(configurazioneStatistica.getIdConfigurazioneServizioAzione()==null){
  59.             throw new ServiceException("IdConfigurazioneServizioAzione is null");
  60.         }
  61.         if(configurazioneStatistica.getIdConfigurazioneServizioAzione().getAzione()==null){
  62.             throw new ServiceException("IdConfigurazioneServizioAzione.azione is null");
  63.         }
  64.         if(configurazioneStatistica.getIdConfigurazioneServizioAzione().getIdConfigurazioneServizio()==null){
  65.             throw new ServiceException("IdConfigurazioneServizioAzione.idConfigurazioneServizio is null");
  66.         }
  67.                
  68.          // Object _configurazioneServizioAzione
  69.         Long id_configurazioneServizioAzione =
  70.                 JDBCConfigurazioneServizioAzioneBaseLib.getIdConfigurazioneServizioAzione(connection, jdbcProperties, log,
  71.                         configurazioneStatistica.getIdConfigurazioneServizioAzione().getAzione(),
  72.                         configurazioneStatistica.getIdConfigurazioneServizioAzione().getIdConfigurazioneServizio().getAccordo(),
  73.                         configurazioneStatistica.getIdConfigurazioneServizioAzione().getIdConfigurazioneServizio().getTipoSoggettoReferente(),
  74.                         configurazioneStatistica.getIdConfigurazioneServizioAzione().getIdConfigurazioneServizio().getNomeSoggettoReferente(),
  75.                         configurazioneStatistica.getIdConfigurazioneServizioAzione().getIdConfigurazioneServizio().getVersione(),
  76.                         configurazioneStatistica.getIdConfigurazioneServizioAzione().getIdConfigurazioneServizio().getServizio(),
  77.                         true);
  78.        

  79.         // Object _plugin
  80.         if(configurazioneStatistica.getPlugin()==null || configurazioneStatistica.getPlugin().getClassName()==null){
  81.             throw new ServiceException("ClassName del plugin non fornito");
  82.         }
  83.         Long id_plugin = JDBCPluginsBaseLib.getIdPlugin(connection, jdbcProperties, log, TipoPlugin.STATISTICA, configurazioneStatistica.getPlugin().getClassName(), true);


  84.         // Object configurazioneStatistica
  85.         sqlQueryObjectInsert.addInsertTable(this.getConfigurazioneStatisticaFieldConverter().toTable(ConfigurazioneStatistica.model()));
  86.         sqlQueryObjectInsert.addInsertField(this.getConfigurazioneStatisticaFieldConverter().toColumn(ConfigurazioneStatistica.model().ID_CONFIGURAZIONE_STATISTICA,false),"?");
  87.         sqlQueryObjectInsert.addInsertField(this.getConfigurazioneStatisticaFieldConverter().toColumn(ConfigurazioneStatistica.model().ENABLED,false),"?");
  88.         sqlQueryObjectInsert.addInsertField(this.getConfigurazioneStatisticaFieldConverter().toColumn(ConfigurazioneStatistica.model().LABEL,false),"?");
  89.         sqlQueryObjectInsert.addInsertField("id_configurazione","?");
  90.         sqlQueryObjectInsert.addInsertField("id_plugin","?");

  91.         // Insert configurazioneStatistica
  92.         org.openspcoop2.utils.jdbc.IKeyGeneratorObject keyGenerator = this.getConfigurazioneStatisticaFetch().getKeyGeneratorObject(ConfigurazioneStatistica.model());
  93.         long id = jdbcUtilities.insertAndReturnGeneratedKey(sqlQueryObjectInsert, keyGenerator, jdbcProperties.isShowSql(),
  94.             new org.openspcoop2.generic_project.dao.jdbc.utils.JDBCObject(configurazioneStatistica.getIdConfigurazioneStatistica(),ConfigurazioneStatistica.model().ID_CONFIGURAZIONE_STATISTICA.getFieldType()),
  95.             new org.openspcoop2.generic_project.dao.jdbc.utils.JDBCObject(configurazioneStatistica.getEnabled(),ConfigurazioneStatistica.model().ENABLED.getFieldType()),
  96.             new org.openspcoop2.generic_project.dao.jdbc.utils.JDBCObject(configurazioneStatistica.getLabel(),ConfigurazioneStatistica.model().LABEL.getFieldType()),
  97.             new org.openspcoop2.generic_project.dao.jdbc.utils.JDBCObject(id_configurazioneServizioAzione,Long.class),
  98.             new org.openspcoop2.generic_project.dao.jdbc.utils.JDBCObject(id_plugin,Long.class)
  99.         );
  100.         configurazioneStatistica.setId(id);

  101.        
  102.     }

  103.     @Override
  104.     public void update(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject, IdConfigurazioneStatistica oldId, ConfigurazioneStatistica configurazioneStatistica, org.openspcoop2.generic_project.beans.IDMappingBehaviour idMappingResolutionBehaviour) throws NotFoundException, NotImplementedException, ServiceException, Exception {
  105.         ISQLQueryObject sqlQueryObjectUpdate = sqlQueryObject.newSQLQueryObject();
  106.         Long longIdByLogicId = this.findIdConfigurazioneStatistica(jdbcProperties, log, connection, sqlQueryObjectUpdate.newSQLQueryObject(), oldId, true);
  107.         Long tableId = configurazioneStatistica.getId();
  108.         if(tableId != null && tableId.longValue() > 0) {
  109.             if(tableId.longValue() != longIdByLogicId.longValue()) {
  110.                 throw new Exception("Ambiguous parameter: configurazioneStatistica.id ["+tableId+"] does not match logic id ["+longIdByLogicId+"]");
  111.             }
  112.         } else {
  113.             tableId = longIdByLogicId;
  114.             configurazioneStatistica.setId(tableId);
  115.         }
  116.         if(tableId==null || tableId<=0){
  117.             throw new Exception("Retrieve tableId failed");
  118.         }

  119.         this.update(jdbcProperties, log, connection, sqlQueryObject, tableId, configurazioneStatistica, idMappingResolutionBehaviour);
  120.     }
  121.     @Override
  122.     public void update(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject, long tableId, ConfigurazioneStatistica configurazioneStatistica, org.openspcoop2.generic_project.beans.IDMappingBehaviour idMappingResolutionBehaviour) throws NotFoundException, NotImplementedException, ServiceException, Exception {
  123.    
  124.         org.openspcoop2.generic_project.dao.jdbc.utils.JDBCPreparedStatementUtilities jdbcUtilities =
  125.                 new org.openspcoop2.generic_project.dao.jdbc.utils.JDBCPreparedStatementUtilities(sqlQueryObject.getTipoDatabaseOpenSPCoop2(), log, connection);
  126.        
  127.         ISQLQueryObject sqlQueryObjectInsert = sqlQueryObject.newSQLQueryObject();
  128.         ISQLQueryObject sqlQueryObjectDelete = sqlQueryObjectInsert.newSQLQueryObject();
  129.         ISQLQueryObject sqlQueryObjectGet = sqlQueryObjectDelete.newSQLQueryObject();
  130.         ISQLQueryObject sqlQueryObjectUpdate = sqlQueryObjectGet.newSQLQueryObject();
  131.        
  132.         boolean setIdMappingResolutionBehaviour =
  133.             (idMappingResolutionBehaviour==null) ||
  134.             org.openspcoop2.generic_project.beans.IDMappingBehaviour.ENABLED.equals(idMappingResolutionBehaviour) ||
  135.             org.openspcoop2.generic_project.beans.IDMappingBehaviour.USE_TABLE_ID.equals(idMappingResolutionBehaviour);
  136.            

  137.         // Object _configurazioneStatistica_configurazioneServizioAzione
  138.         Long id_configurazioneStatistica_configurazioneServizioAzione = null;
  139.         org.openspcoop2.monitor.engine.config.statistiche.IdConfigurazioneServizioAzione idLogic_configurazioneStatistica_configurazioneServizioAzione = null;
  140.         idLogic_configurazioneStatistica_configurazioneServizioAzione = configurazioneStatistica.getIdConfigurazioneServizioAzione();
  141.         if(idLogic_configurazioneStatistica_configurazioneServizioAzione!=null){
  142.             if(idMappingResolutionBehaviour==null ||
  143.                 (org.openspcoop2.generic_project.beans.IDMappingBehaviour.ENABLED.equals(idMappingResolutionBehaviour))){
  144.                 id_configurazioneStatistica_configurazioneServizioAzione =
  145.                         JDBCConfigurazioneServizioAzioneBaseLib.getIdConfigurazioneServizioAzione(connection, jdbcProperties, log,
  146.                                 idLogic_configurazioneStatistica_configurazioneServizioAzione.getAzione(),
  147.                                 idLogic_configurazioneStatistica_configurazioneServizioAzione.getIdConfigurazioneServizio().getAccordo(),
  148.                                 idLogic_configurazioneStatistica_configurazioneServizioAzione.getIdConfigurazioneServizio().getTipoSoggettoReferente(),
  149.                                 idLogic_configurazioneStatistica_configurazioneServizioAzione.getIdConfigurazioneServizio().getNomeSoggettoReferente(),
  150.                                 idLogic_configurazioneStatistica_configurazioneServizioAzione.getIdConfigurazioneServizio().getVersione(),
  151.                                 idLogic_configurazioneStatistica_configurazioneServizioAzione.getIdConfigurazioneServizio().getServizio(),
  152.                                 true);
  153.             }
  154.             else if(org.openspcoop2.generic_project.beans.IDMappingBehaviour.USE_TABLE_ID.equals(idMappingResolutionBehaviour)){
  155.                 id_configurazioneStatistica_configurazioneServizioAzione = idLogic_configurazioneStatistica_configurazioneServizioAzione.getId();
  156.                 if(id_configurazioneStatistica_configurazioneServizioAzione==null || id_configurazioneStatistica_configurazioneServizioAzione<=0){
  157.                     throw new Exception("Logic id not contains table id");
  158.                 }
  159.             }
  160.             configurazioneStatistica.setId(tableId);
  161.         }
  162.        
  163.         // Object _plugin
  164.         if(configurazioneStatistica.getPlugin()==null || configurazioneStatistica.getPlugin().getClassName()==null){
  165.             throw new ServiceException("ClassName del plugin non fornito");
  166.         }
  167.         Long id_plugin = JDBCPluginsBaseLib.getIdPlugin(connection, jdbcProperties, log, TipoPlugin.STATISTICA, configurazioneStatistica.getPlugin().getClassName(), true);


  168.         // Object configurazioneStatistica
  169.         sqlQueryObjectUpdate.setANDLogicOperator(true);
  170.         sqlQueryObjectUpdate.addUpdateTable(this.getConfigurazioneStatisticaFieldConverter().toTable(ConfigurazioneStatistica.model()));
  171.         boolean isUpdate_configurazioneStatistica = true;
  172.         java.util.List<JDBCObject> lstObjects_configurazioneStatistica = new java.util.ArrayList<>();
  173.         sqlQueryObjectUpdate.addUpdateField(this.getConfigurazioneStatisticaFieldConverter().toColumn(ConfigurazioneStatistica.model().ID_CONFIGURAZIONE_STATISTICA,false), "?");
  174.         lstObjects_configurazioneStatistica.add(new JDBCObject(configurazioneStatistica.getIdConfigurazioneStatistica(), ConfigurazioneStatistica.model().ID_CONFIGURAZIONE_STATISTICA.getFieldType()));
  175.         sqlQueryObjectUpdate.addUpdateField(this.getConfigurazioneStatisticaFieldConverter().toColumn(ConfigurazioneStatistica.model().ENABLED,false), "?");
  176.         lstObjects_configurazioneStatistica.add(new JDBCObject(configurazioneStatistica.getEnabled(), ConfigurazioneStatistica.model().ENABLED.getFieldType()));
  177.         sqlQueryObjectUpdate.addUpdateField(this.getConfigurazioneStatisticaFieldConverter().toColumn(ConfigurazioneStatistica.model().LABEL,false), "?");
  178.         lstObjects_configurazioneStatistica.add(new JDBCObject(configurazioneStatistica.getLabel(), ConfigurazioneStatistica.model().LABEL.getFieldType()));
  179.         if(setIdMappingResolutionBehaviour){
  180.             sqlQueryObjectUpdate.addUpdateField("id_configurazione","?");
  181.         }
  182.         if(setIdMappingResolutionBehaviour){
  183.             sqlQueryObjectUpdate.addUpdateField("id_plugin", "?");
  184.         }
  185.         if(setIdMappingResolutionBehaviour){
  186.             lstObjects_configurazioneStatistica.add(new JDBCObject(id_configurazioneStatistica_configurazioneServizioAzione, Long.class));
  187.         }
  188.         if(setIdMappingResolutionBehaviour){
  189.             lstObjects_configurazioneStatistica.add(new JDBCObject(id_plugin, Long.class));
  190.         }
  191.         sqlQueryObjectUpdate.addWhereCondition("pid=?");
  192.         lstObjects_configurazioneStatistica.add(new JDBCObject(tableId, Long.class));

  193.         if(isUpdate_configurazioneStatistica) {
  194.             // Update configurazioneStatistica
  195.             jdbcUtilities.executeUpdate(sqlQueryObjectUpdate.createSQLUpdate(), jdbcProperties.isShowSql(),
  196.                 lstObjects_configurazioneStatistica.toArray(new JDBCObject[]{}));
  197.         }

  198.        
  199.     }
  200.    
  201.     @Override
  202.     public void updateFields(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject, IdConfigurazioneStatistica id, UpdateField ... updateFields) throws NotFoundException, NotImplementedException, ServiceException, Exception {
  203.        
  204.         GenericJDBCUtilities.updateFields(jdbcProperties, log, connection, sqlQueryObject,
  205.                 this.getConfigurazioneStatisticaFieldConverter().toTable(ConfigurazioneStatistica.model()),
  206.                 this.getMapTableToPKColumnEngine(),
  207.                 this.getRootTablePrimaryKeyValuesEngine(jdbcProperties, log, connection, sqlQueryObject, id),
  208.                 this.getConfigurazioneStatisticaFieldConverter(), this, null, updateFields);
  209.     }
  210.    
  211.     @Override
  212.     public void updateFields(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject, IdConfigurazioneStatistica id, IExpression condition, UpdateField ... updateFields) throws NotFoundException, NotImplementedException, ServiceException, Exception {
  213.        
  214.         GenericJDBCUtilities.updateFields(jdbcProperties, log, connection, sqlQueryObject,
  215.                 this.getConfigurazioneStatisticaFieldConverter().toTable(ConfigurazioneStatistica.model()),
  216.                 this.getMapTableToPKColumnEngine(),
  217.                 this.getRootTablePrimaryKeyValuesEngine(jdbcProperties, log, connection, sqlQueryObject, id),
  218.                 this.getConfigurazioneStatisticaFieldConverter(), this, condition, updateFields);
  219.     }
  220.    
  221.     @Override
  222.     public void updateFields(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject, IdConfigurazioneStatistica id, UpdateModel ... updateModels) throws NotFoundException, NotImplementedException, ServiceException, Exception {
  223.        
  224.         GenericJDBCUtilities.updateFields(jdbcProperties, log, connection, sqlQueryObject,
  225.                 this.getConfigurazioneStatisticaFieldConverter().toTable(ConfigurazioneStatistica.model()),
  226.                 this.getMapTableToPKColumnEngine(),
  227.                 this.getRootTablePrimaryKeyValuesEngine(jdbcProperties, log, connection, sqlQueryObject, id),
  228.                 this.getConfigurazioneStatisticaFieldConverter(), this, updateModels);
  229.     }  
  230.    
  231.     @Override
  232.     public void updateFields(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject, long tableId, UpdateField ... updateFields) throws NotFoundException, NotImplementedException, ServiceException, Exception {
  233.         java.util.List<Object> ids = new java.util.ArrayList<>();
  234.         ids.add(tableId);
  235.         GenericJDBCUtilities.updateFields(jdbcProperties, log, connection, sqlQueryObject,
  236.                 this.getConfigurazioneStatisticaFieldConverter().toTable(ConfigurazioneStatistica.model()),
  237.                 this.getMapTableToPKColumnEngine(),
  238.                 ids,
  239.                 this.getConfigurazioneStatisticaFieldConverter(), this, null, updateFields);
  240.     }
  241.    
  242.     @Override
  243.     public void updateFields(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject, long tableId, IExpression condition, UpdateField ... updateFields) throws NotFoundException, NotImplementedException, ServiceException, Exception {
  244.         java.util.List<Object> ids = new java.util.ArrayList<>();
  245.         ids.add(tableId);
  246.         GenericJDBCUtilities.updateFields(jdbcProperties, log, connection, sqlQueryObject,
  247.                 this.getConfigurazioneStatisticaFieldConverter().toTable(ConfigurazioneStatistica.model()),
  248.                 this.getMapTableToPKColumnEngine(),
  249.                 ids,
  250.                 this.getConfigurazioneStatisticaFieldConverter(), this, condition, updateFields);
  251.     }
  252.    
  253.     @Override
  254.     public void updateFields(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject, long tableId, UpdateModel ... updateModels) throws NotFoundException, NotImplementedException, ServiceException, Exception {
  255.         java.util.List<Object> ids = new java.util.ArrayList<>();
  256.         ids.add(tableId);
  257.         GenericJDBCUtilities.updateFields(jdbcProperties, log, connection, sqlQueryObject,
  258.                 this.getConfigurazioneStatisticaFieldConverter().toTable(ConfigurazioneStatistica.model()),
  259.                 this.getMapTableToPKColumnEngine(),
  260.                 ids,
  261.                 this.getConfigurazioneStatisticaFieldConverter(), this, updateModels);
  262.     }
  263.    
  264.     @Override
  265.     public void updateOrCreate(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject, IdConfigurazioneStatistica oldId, ConfigurazioneStatistica configurazioneStatistica, org.openspcoop2.generic_project.beans.IDMappingBehaviour idMappingResolutionBehaviour) throws NotImplementedException,ServiceException,Exception {
  266.    
  267.         if(this.exists(jdbcProperties, log, connection, sqlQueryObject, oldId)) {
  268.             this.update(jdbcProperties, log, connection, sqlQueryObject, oldId, configurazioneStatistica,idMappingResolutionBehaviour);
  269.         } else {
  270.             this.create(jdbcProperties, log, connection, sqlQueryObject, configurazioneStatistica,idMappingResolutionBehaviour);
  271.         }
  272.        
  273.     }
  274.    
  275.     @Override
  276.     public void updateOrCreate(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject, long tableId, ConfigurazioneStatistica configurazioneStatistica, org.openspcoop2.generic_project.beans.IDMappingBehaviour idMappingResolutionBehaviour) throws NotImplementedException,ServiceException,Exception {
  277.         if(this.exists(jdbcProperties, log, connection, sqlQueryObject, tableId)) {
  278.             this.update(jdbcProperties, log, connection, sqlQueryObject, tableId, configurazioneStatistica,idMappingResolutionBehaviour);
  279.         } else {
  280.             this.create(jdbcProperties, log, connection, sqlQueryObject, configurazioneStatistica,idMappingResolutionBehaviour);
  281.         }
  282.     }
  283.    
  284.     @Override
  285.     public void delete(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject, ConfigurazioneStatistica configurazioneStatistica) throws NotImplementedException,ServiceException,Exception {
  286.        
  287.        
  288.         Long longId = null;
  289.         if( (configurazioneStatistica.getId()!=null) && (configurazioneStatistica.getId()>0) ){
  290.             longId = configurazioneStatistica.getId();
  291.         }
  292.         else{
  293.             IdConfigurazioneStatistica idConfigurazioneStatistica = this.convertToId(jdbcProperties,log,connection,sqlQueryObject,configurazioneStatistica);
  294.             longId = this.findIdConfigurazioneStatistica(jdbcProperties,log,connection,sqlQueryObject,idConfigurazioneStatistica,false);
  295.             if(longId == null){
  296.                 return; // entry not exists
  297.             }
  298.         }      
  299.        
  300.         this.deleteEngine(jdbcProperties, log, connection, sqlQueryObject, longId);
  301.        
  302.     }

  303.     private void deleteEngine(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject, Long id) throws NotImplementedException,ServiceException,Exception {
  304.    
  305.         if(id!=null && id.longValue()<=0){
  306.             throw new ServiceException("Id is less equals 0");
  307.         }
  308.        
  309.         org.openspcoop2.generic_project.dao.jdbc.utils.JDBCPreparedStatementUtilities jdbcUtilities =
  310.                 new org.openspcoop2.generic_project.dao.jdbc.utils.JDBCPreparedStatementUtilities(sqlQueryObject.getTipoDatabaseOpenSPCoop2(), log, connection);
  311.        
  312.         ISQLQueryObject sqlQueryObjectDelete = sqlQueryObject.newSQLQueryObject();
  313.        

  314.         // Object configurazioneStatistica
  315.         sqlQueryObjectDelete.setANDLogicOperator(true);
  316.         sqlQueryObjectDelete.addDeleteTable(this.getConfigurazioneStatisticaFieldConverter().toTable(ConfigurazioneStatistica.model()));
  317.         if(id != null)
  318.             sqlQueryObjectDelete.addWhereCondition("pid=?");

  319.         // Delete configurazioneStatistica
  320.         jdbcUtilities.execute(sqlQueryObjectDelete.createSQLDelete(), jdbcProperties.isShowSql(),
  321.             new JDBCObject(id,Long.class));

  322.     }

  323.     @Override
  324.     public void deleteById(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject, IdConfigurazioneStatistica idConfigurazioneStatistica) throws NotImplementedException,ServiceException,Exception {

  325.         Long id = null;
  326.         try{
  327.             id = this.findIdConfigurazioneStatistica(jdbcProperties, log, connection, sqlQueryObject, idConfigurazioneStatistica, true);
  328.         }catch(NotFoundException notFound){
  329.             return;
  330.         }
  331.         this.deleteEngine(jdbcProperties, log, connection, sqlQueryObject, id);
  332.        
  333.     }
  334.    
  335.     @Override
  336.     public NonNegativeNumber deleteAll(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject) throws NotImplementedException,ServiceException,Exception {
  337.        
  338.         return this.deleteAll(jdbcProperties, log, connection, sqlQueryObject, new JDBCExpression(this.getConfigurazioneStatisticaFieldConverter()));

  339.     }

  340.     @Override
  341.     public NonNegativeNumber deleteAll(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject, JDBCExpression expression) throws NotImplementedException, ServiceException,Exception {

  342.         java.util.List<Long> lst = this.findAllTableIds(jdbcProperties, log, connection, sqlQueryObject, new JDBCPaginatedExpression(expression));
  343.        
  344.         for(Long id : lst) {
  345.             this.deleteEngine(jdbcProperties, log, connection, sqlQueryObject, id);
  346.         }
  347.        
  348.         return new NonNegativeNumber(lst.size());
  349.    
  350.     }



  351.     // -- DB
  352.    
  353.     @Override
  354.     public void deleteById(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject, long tableId) throws ServiceException, NotImplementedException, Exception {
  355.         this.deleteEngine(jdbcProperties, log, connection, sqlQueryObject, Long.valueOf(tableId));
  356.     }
  357.    
  358.     @Override
  359.     public int nativeUpdate(JDBCServiceManagerProperties jdbcProperties, Logger log,Connection connection,ISQLQueryObject sqlObject, String sql,Object ... param) throws ServiceException,NotImplementedException, Exception {
  360.    
  361.         return org.openspcoop2.generic_project.dao.jdbc.utils.GenericJDBCUtilities.nativeUpdate(jdbcProperties, log, connection, sqlObject,
  362.                                                                                             sql,param);
  363.    
  364.     }
  365. }