JDBCConfigurazioneRicercaServiceImpl.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.ricerche.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.ricerche.IdConfigurazioneRicerca;
  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.ricerche.ConfigurazioneRicerca;

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

  51.     @Override
  52.     public void create(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject, ConfigurazioneRicerca configurazioneRicerca, 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.         // Object _configurazioneServizioAzione
  59.         Long id_configurazioneServizioAzione =
  60.                 JDBCConfigurazioneServizioAzioneBaseLib.getIdConfigurazioneServizioAzione(connection, jdbcProperties, log,
  61.                         configurazioneRicerca.getIdConfigurazioneServizioAzione().getAzione(),
  62.                         configurazioneRicerca.getIdConfigurazioneServizioAzione().getIdConfigurazioneServizio().getAccordo(),
  63.                         configurazioneRicerca.getIdConfigurazioneServizioAzione().getIdConfigurazioneServizio().getTipoSoggettoReferente(),
  64.                         configurazioneRicerca.getIdConfigurazioneServizioAzione().getIdConfigurazioneServizio().getNomeSoggettoReferente(),
  65.                         configurazioneRicerca.getIdConfigurazioneServizioAzione().getIdConfigurazioneServizio().getVersione(),
  66.                         configurazioneRicerca.getIdConfigurazioneServizioAzione().getIdConfigurazioneServizio().getServizio(),
  67.                         true);

  68.         // Object _plugin
  69.         if(configurazioneRicerca.getPlugin()==null || configurazioneRicerca.getPlugin().getClassName()==null){
  70.             throw new ServiceException("ClassName del plugin non fornito");
  71.         }
  72.         Long id_plugin = JDBCPluginsBaseLib.getIdPlugin(connection, jdbcProperties, log, TipoPlugin.RICERCA, configurazioneRicerca.getPlugin().getClassName(), true);


  73.         // Object configurazioneRicerca
  74.         sqlQueryObjectInsert.addInsertTable(this.getConfigurazioneRicercaFieldConverter().toTable(ConfigurazioneRicerca.model()));
  75.         sqlQueryObjectInsert.addInsertField(this.getConfigurazioneRicercaFieldConverter().toColumn(ConfigurazioneRicerca.model().ID_CONFIGURAZIONE_RICERCA,false),"?");
  76.         sqlQueryObjectInsert.addInsertField(this.getConfigurazioneRicercaFieldConverter().toColumn(ConfigurazioneRicerca.model().ENABLED,false),"?");
  77.         sqlQueryObjectInsert.addInsertField(this.getConfigurazioneRicercaFieldConverter().toColumn(ConfigurazioneRicerca.model().LABEL,false),"?");
  78.         sqlQueryObjectInsert.addInsertField("id_configurazione","?");
  79.         sqlQueryObjectInsert.addInsertField("id_plugin","?");

  80.         // Insert configurazioneRicerca
  81.         org.openspcoop2.utils.jdbc.IKeyGeneratorObject keyGenerator = this.getConfigurazioneRicercaFetch().getKeyGeneratorObject(ConfigurazioneRicerca.model());
  82.         long id = jdbcUtilities.insertAndReturnGeneratedKey(sqlQueryObjectInsert, keyGenerator, jdbcProperties.isShowSql(),
  83.             new org.openspcoop2.generic_project.dao.jdbc.utils.JDBCObject(configurazioneRicerca.getIdConfigurazioneRicerca(),ConfigurazioneRicerca.model().ID_CONFIGURAZIONE_RICERCA.getFieldType()),
  84.             new org.openspcoop2.generic_project.dao.jdbc.utils.JDBCObject(configurazioneRicerca.getEnabled(),ConfigurazioneRicerca.model().ENABLED.getFieldType()),
  85.             new org.openspcoop2.generic_project.dao.jdbc.utils.JDBCObject(configurazioneRicerca.getLabel(),ConfigurazioneRicerca.model().LABEL.getFieldType()),
  86.             new org.openspcoop2.generic_project.dao.jdbc.utils.JDBCObject(id_configurazioneServizioAzione,Long.class),
  87.             new org.openspcoop2.generic_project.dao.jdbc.utils.JDBCObject(id_plugin,Long.class)
  88.         );
  89.         configurazioneRicerca.setId(id);

  90.        
  91.     }

  92.     @Override
  93.     public void update(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject, IdConfigurazioneRicerca oldId, ConfigurazioneRicerca configurazioneRicerca, org.openspcoop2.generic_project.beans.IDMappingBehaviour idMappingResolutionBehaviour) throws NotFoundException, NotImplementedException, ServiceException, Exception {
  94.         ISQLQueryObject sqlQueryObjectUpdate = sqlQueryObject.newSQLQueryObject();
  95.         Long longIdByLogicId = this.findIdConfigurazioneRicerca(jdbcProperties, log, connection, sqlQueryObjectUpdate.newSQLQueryObject(), oldId, true);
  96.         Long tableId = configurazioneRicerca.getId();
  97.         if(tableId != null && tableId.longValue() > 0) {
  98.             if(tableId.longValue() != longIdByLogicId.longValue()) {
  99.                 throw new Exception("Ambiguous parameter: configurazioneRicerca.id ["+tableId+"] does not match logic id ["+longIdByLogicId+"]");
  100.             }
  101.         } else {
  102.             tableId = longIdByLogicId;
  103.             configurazioneRicerca.setId(tableId);
  104.         }
  105.         if(tableId==null || tableId<=0){
  106.             throw new Exception("Retrieve tableId failed");
  107.         }

  108.         this.update(jdbcProperties, log, connection, sqlQueryObject, tableId, configurazioneRicerca, idMappingResolutionBehaviour);
  109.     }
  110.     @Override
  111.     public void update(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject, long tableId, ConfigurazioneRicerca configurazioneRicerca, org.openspcoop2.generic_project.beans.IDMappingBehaviour idMappingResolutionBehaviour) throws NotFoundException, NotImplementedException, ServiceException, Exception {
  112.    
  113.         org.openspcoop2.generic_project.dao.jdbc.utils.JDBCPreparedStatementUtilities jdbcUtilities =
  114.                 new org.openspcoop2.generic_project.dao.jdbc.utils.JDBCPreparedStatementUtilities(sqlQueryObject.getTipoDatabaseOpenSPCoop2(), log, connection);
  115.        
  116.         ISQLQueryObject sqlQueryObjectInsert = sqlQueryObject.newSQLQueryObject();
  117.         ISQLQueryObject sqlQueryObjectDelete = sqlQueryObjectInsert.newSQLQueryObject();
  118.         ISQLQueryObject sqlQueryObjectGet = sqlQueryObjectDelete.newSQLQueryObject();
  119.         ISQLQueryObject sqlQueryObjectUpdate = sqlQueryObjectGet.newSQLQueryObject();
  120.        
  121.         boolean setIdMappingResolutionBehaviour =
  122.             (idMappingResolutionBehaviour==null) ||
  123.             org.openspcoop2.generic_project.beans.IDMappingBehaviour.ENABLED.equals(idMappingResolutionBehaviour) ||
  124.             org.openspcoop2.generic_project.beans.IDMappingBehaviour.USE_TABLE_ID.equals(idMappingResolutionBehaviour);
  125.            

  126.         // Object _configurazioneRicerca_configurazioneServizioAzione
  127.         Long id_configurazioneRicerca_configurazioneServizioAzione = null;
  128.         org.openspcoop2.monitor.engine.config.ricerche.IdConfigurazioneServizioAzione idLogic_configurazioneRicerca_configurazioneServizioAzione = null;
  129.         idLogic_configurazioneRicerca_configurazioneServizioAzione = configurazioneRicerca.getIdConfigurazioneServizioAzione();
  130.         if(idLogic_configurazioneRicerca_configurazioneServizioAzione!=null){
  131.             if(idMappingResolutionBehaviour==null ||
  132.                 (org.openspcoop2.generic_project.beans.IDMappingBehaviour.ENABLED.equals(idMappingResolutionBehaviour))){
  133.                 id_configurazioneRicerca_configurazioneServizioAzione =
  134.                         JDBCConfigurazioneServizioAzioneBaseLib.getIdConfigurazioneServizioAzione(connection, jdbcProperties, log,
  135.                                 idLogic_configurazioneRicerca_configurazioneServizioAzione.getAzione(),
  136.                                 idLogic_configurazioneRicerca_configurazioneServizioAzione.getIdConfigurazioneServizio().getAccordo(),
  137.                                 idLogic_configurazioneRicerca_configurazioneServizioAzione.getIdConfigurazioneServizio().getTipoSoggettoReferente(),
  138.                                 idLogic_configurazioneRicerca_configurazioneServizioAzione.getIdConfigurazioneServizio().getNomeSoggettoReferente(),
  139.                                 idLogic_configurazioneRicerca_configurazioneServizioAzione.getIdConfigurazioneServizio().getVersione(),
  140.                                 idLogic_configurazioneRicerca_configurazioneServizioAzione.getIdConfigurazioneServizio().getServizio(),
  141.                                 true);
  142.             }
  143.             else if(org.openspcoop2.generic_project.beans.IDMappingBehaviour.USE_TABLE_ID.equals(idMappingResolutionBehaviour)){
  144.                 id_configurazioneRicerca_configurazioneServizioAzione = idLogic_configurazioneRicerca_configurazioneServizioAzione.getId();
  145.                 if(id_configurazioneRicerca_configurazioneServizioAzione==null || id_configurazioneRicerca_configurazioneServizioAzione<=0){
  146.                     throw new Exception("Logic id not contains table id");
  147.                 }
  148.             }
  149.             configurazioneRicerca.setId(tableId);
  150.         }

  151.         // Object _plugin
  152.         if(configurazioneRicerca.getPlugin()==null || configurazioneRicerca.getPlugin().getClassName()==null){
  153.             throw new ServiceException("ClassName del plugin non fornito");
  154.         }
  155.         Long id_plugin = JDBCPluginsBaseLib.getIdPlugin(connection, jdbcProperties, log, TipoPlugin.RICERCA, configurazioneRicerca.getPlugin().getClassName(), true);
  156.        
  157.         // Object configurazioneRicerca
  158.         sqlQueryObjectUpdate.setANDLogicOperator(true);
  159.         sqlQueryObjectUpdate.addUpdateTable(this.getConfigurazioneRicercaFieldConverter().toTable(ConfigurazioneRicerca.model()));
  160.         boolean isUpdate_configurazioneRicerca = true;
  161.         java.util.List<JDBCObject> lstObjects_configurazioneRicerca = new java.util.ArrayList<>();
  162.         sqlQueryObjectUpdate.addUpdateField(this.getConfigurazioneRicercaFieldConverter().toColumn(ConfigurazioneRicerca.model().ID_CONFIGURAZIONE_RICERCA,false), "?");
  163.         lstObjects_configurazioneRicerca.add(new JDBCObject(configurazioneRicerca.getIdConfigurazioneRicerca(), ConfigurazioneRicerca.model().ID_CONFIGURAZIONE_RICERCA.getFieldType()));
  164.         sqlQueryObjectUpdate.addUpdateField(this.getConfigurazioneRicercaFieldConverter().toColumn(ConfigurazioneRicerca.model().ENABLED,false), "?");
  165.         lstObjects_configurazioneRicerca.add(new JDBCObject(configurazioneRicerca.getEnabled(), ConfigurazioneRicerca.model().ENABLED.getFieldType()));
  166.         sqlQueryObjectUpdate.addUpdateField(this.getConfigurazioneRicercaFieldConverter().toColumn(ConfigurazioneRicerca.model().LABEL,false), "?");
  167.         lstObjects_configurazioneRicerca.add(new JDBCObject(configurazioneRicerca.getLabel(), ConfigurazioneRicerca.model().LABEL.getFieldType()));
  168.         if(setIdMappingResolutionBehaviour){
  169.             sqlQueryObjectUpdate.addUpdateField("id_configurazione","?");
  170.         }
  171.         if(setIdMappingResolutionBehaviour){
  172.             sqlQueryObjectUpdate.addUpdateField("id_plugin", "?");
  173.         }
  174.         if(setIdMappingResolutionBehaviour){
  175.             lstObjects_configurazioneRicerca.add(new JDBCObject(id_configurazioneRicerca_configurazioneServizioAzione, Long.class));
  176.         }
  177.         if(setIdMappingResolutionBehaviour){
  178.             lstObjects_configurazioneRicerca.add(new JDBCObject(id_plugin, Long.class));
  179.         }
  180.         sqlQueryObjectUpdate.addWhereCondition("pid=?");
  181.         lstObjects_configurazioneRicerca.add(new JDBCObject(tableId, Long.class));

  182.         if(isUpdate_configurazioneRicerca) {
  183.             // Update configurazioneRicerca
  184.             jdbcUtilities.executeUpdate(sqlQueryObjectUpdate.createSQLUpdate(), jdbcProperties.isShowSql(),
  185.                 lstObjects_configurazioneRicerca.toArray(new JDBCObject[]{}));
  186.         }

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

  291.     private void deleteEngine(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject, Long id) throws NotImplementedException,ServiceException,Exception {
  292.    
  293.         if(id!=null && id.longValue()<=0){
  294.             throw new ServiceException("Id is less equals 0");
  295.         }
  296.        
  297.         org.openspcoop2.generic_project.dao.jdbc.utils.JDBCPreparedStatementUtilities jdbcUtilities =
  298.                 new org.openspcoop2.generic_project.dao.jdbc.utils.JDBCPreparedStatementUtilities(sqlQueryObject.getTipoDatabaseOpenSPCoop2(), log, connection);
  299.        
  300.         ISQLQueryObject sqlQueryObjectDelete = sqlQueryObject.newSQLQueryObject();
  301.        

  302.         // Object configurazioneRicerca
  303.         sqlQueryObjectDelete.setANDLogicOperator(true);
  304.         sqlQueryObjectDelete.addDeleteTable(this.getConfigurazioneRicercaFieldConverter().toTable(ConfigurazioneRicerca.model()));
  305.         if(id != null)
  306.             sqlQueryObjectDelete.addWhereCondition("pid=?");

  307.         // Delete configurazioneRicerca
  308.         jdbcUtilities.execute(sqlQueryObjectDelete.createSQLDelete(), jdbcProperties.isShowSql(),
  309.             new JDBCObject(id,Long.class));

  310.     }

  311.     @Override
  312.     public void deleteById(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject, IdConfigurazioneRicerca idConfigurazioneRicerca) throws NotImplementedException,ServiceException,Exception {

  313.         Long id = null;
  314.         try{
  315.             id = this.findIdConfigurazioneRicerca(jdbcProperties, log, connection, sqlQueryObject, idConfigurazioneRicerca, true);
  316.         }catch(NotFoundException notFound){
  317.             return;
  318.         }
  319.         this.deleteEngine(jdbcProperties, log, connection, sqlQueryObject, id);
  320.        
  321.     }
  322.    
  323.     @Override
  324.     public NonNegativeNumber deleteAll(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject) throws NotImplementedException,ServiceException,Exception {
  325.        
  326.         return this.deleteAll(jdbcProperties, log, connection, sqlQueryObject, new JDBCExpression(this.getConfigurazioneRicercaFieldConverter()));

  327.     }

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

  330.         java.util.List<Long> lst = this.findAllTableIds(jdbcProperties, log, connection, sqlQueryObject, new JDBCPaginatedExpression(expression));
  331.        
  332.         for(Long id : lst) {
  333.             this.deleteEngine(jdbcProperties, log, connection, sqlQueryObject, id);
  334.         }
  335.        
  336.         return new NonNegativeNumber(lst.size());
  337.    
  338.     }



  339.     // -- DB
  340.    
  341.     @Override
  342.     public void deleteById(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject, long tableId) throws ServiceException, NotImplementedException, Exception {
  343.         this.deleteEngine(jdbcProperties, log, connection, sqlQueryObject, Long.valueOf(tableId));
  344.     }
  345.    
  346.     @Override
  347.     public int nativeUpdate(JDBCServiceManagerProperties jdbcProperties, Logger log,Connection connection,ISQLQueryObject sqlObject, String sql,Object ... param) throws ServiceException,NotImplementedException, Exception {
  348.    
  349.         return org.openspcoop2.generic_project.dao.jdbc.utils.GenericJDBCUtilities.nativeUpdate(jdbcProperties, log, connection, sqlObject,
  350.                                                                                             sql,param);
  351.    
  352.     }
  353. }