JDBCConfigurazioneRicercaServiceSearchImpl.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.util.List;
  22. import java.util.ArrayList;
  23. import java.util.Map;

  24. import java.sql.Connection;

  25. import org.slf4j.Logger;

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

  27. import org.openspcoop2.core.plugins.IdConfigurazioneServizioAzione;
  28. import org.openspcoop2.core.plugins.Plugin;
  29. import org.openspcoop2.core.plugins.dao.jdbc.JDBCConfigurazioneServizioAzioneBaseLib;
  30. import org.openspcoop2.core.plugins.dao.jdbc.JDBCPluginsBaseLib;

  31. import org.openspcoop2.generic_project.expression.impl.sql.ISQLFieldConverter;
  32. import org.openspcoop2.generic_project.dao.jdbc.utils.IJDBCFetch;
  33. import org.openspcoop2.generic_project.dao.jdbc.utils.JDBCObject;
  34. import org.openspcoop2.generic_project.dao.jdbc.IJDBCServiceSearchWithId;
  35. import org.openspcoop2.monitor.engine.config.ricerche.IdConfigurazioneRicerca;
  36. import org.openspcoop2.monitor.engine.config.ricerche.InfoPlugin;
  37. import org.openspcoop2.generic_project.utils.UtilsTemplate;
  38. import org.openspcoop2.generic_project.beans.CustomField;
  39. import org.openspcoop2.generic_project.beans.InUse;
  40. import org.openspcoop2.generic_project.beans.IField;
  41. import org.openspcoop2.generic_project.beans.NonNegativeNumber;
  42. import org.openspcoop2.generic_project.beans.UnionExpression;
  43. import org.openspcoop2.generic_project.beans.Union;
  44. import org.openspcoop2.generic_project.beans.FunctionField;
  45. import org.openspcoop2.generic_project.exception.MultipleResultException;
  46. import org.openspcoop2.generic_project.exception.NotFoundException;
  47. import org.openspcoop2.generic_project.exception.NotImplementedException;
  48. import org.openspcoop2.generic_project.exception.ServiceException;
  49. import org.openspcoop2.generic_project.expression.IExpression;
  50. import org.openspcoop2.generic_project.dao.jdbc.JDBCExpression;
  51. import org.openspcoop2.generic_project.dao.jdbc.JDBCPaginatedExpression;

  52. import org.openspcoop2.generic_project.dao.jdbc.JDBCServiceManagerProperties;
  53. import org.openspcoop2.monitor.engine.config.ricerche.dao.jdbc.converter.ConfigurazioneRicercaFieldConverter;
  54. import org.openspcoop2.monitor.engine.config.ricerche.dao.jdbc.fetch.ConfigurazioneRicercaFetch;
  55. import org.openspcoop2.monitor.engine.config.ricerche.ConfigurazioneRicerca;

  56. /**    
  57.  * JDBCConfigurazioneRicercaServiceSearchImpl
  58.  *
  59.  * @author Poli Andrea (poli@link.it)
  60.  * @author $Author$
  61.  * @version $Rev$, $Date$
  62.  */
  63. public class JDBCConfigurazioneRicercaServiceSearchImpl implements IJDBCServiceSearchWithId<ConfigurazioneRicerca, IdConfigurazioneRicerca, JDBCServiceManager> {

  64.     private ConfigurazioneRicercaFieldConverter _configurazioneRicercaFieldConverter = null;
  65.     public ConfigurazioneRicercaFieldConverter getConfigurazioneRicercaFieldConverter() {
  66.         if(this._configurazioneRicercaFieldConverter==null){
  67.             this._configurazioneRicercaFieldConverter = new ConfigurazioneRicercaFieldConverter(this.jdbcServiceManager.getJdbcProperties().getDatabaseType());
  68.         }      
  69.         return this._configurazioneRicercaFieldConverter;
  70.     }
  71.     @Override
  72.     public ISQLFieldConverter getFieldConverter() {
  73.         return this.getConfigurazioneRicercaFieldConverter();
  74.     }
  75.    
  76.     private ConfigurazioneRicercaFetch configurazioneRicercaFetch = new ConfigurazioneRicercaFetch();
  77.     public ConfigurazioneRicercaFetch getConfigurazioneRicercaFetch() {
  78.         return this.configurazioneRicercaFetch;
  79.     }
  80.     @Override
  81.     public IJDBCFetch getFetch() {
  82.         return getConfigurazioneRicercaFetch();
  83.     }
  84.    
  85.    
  86.     private JDBCServiceManager jdbcServiceManager = null;

  87.     @Override
  88.     public void setServiceManager(JDBCServiceManager serviceManager) throws ServiceException{
  89.         this.jdbcServiceManager = serviceManager;
  90.     }
  91.    
  92.     @Override
  93.     public JDBCServiceManager getServiceManager() throws ServiceException{
  94.         return this.jdbcServiceManager;
  95.     }
  96.    

  97.     @Override
  98.     public IdConfigurazioneRicerca convertToId(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject, ConfigurazioneRicerca configurazioneRicerca) throws NotImplementedException, ServiceException, Exception{
  99.    
  100.         IdConfigurazioneRicerca idConfigurazioneRicerca = new IdConfigurazioneRicerca();
  101.         idConfigurazioneRicerca.setIdConfigurazioneRicerca(configurazioneRicerca.getIdConfigurazioneRicerca());
  102.         idConfigurazioneRicerca.setIdConfigurazioneServizioAzione(configurazioneRicerca.getIdConfigurazioneServizioAzione());
  103.         return idConfigurazioneRicerca;

  104.     }
  105.    
  106.     @Override
  107.     public ConfigurazioneRicerca get(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject, IdConfigurazioneRicerca id, org.openspcoop2.generic_project.beans.IDMappingBehaviour idMappingResolutionBehaviour) throws NotFoundException, MultipleResultException, NotImplementedException, ServiceException,Exception {
  108.         Long id_configurazioneRicerca = ( (id!=null && id.getId()!=null && id.getId()>0) ? id.getId() : this.findIdConfigurazioneRicerca(jdbcProperties, log, connection, sqlQueryObject, id, true));
  109.         return this.getEngine(jdbcProperties, log, connection, sqlQueryObject, id_configurazioneRicerca,idMappingResolutionBehaviour);
  110.        
  111.        
  112.     }
  113.    
  114.     @Override
  115.     public boolean exists(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject, IdConfigurazioneRicerca id) throws MultipleResultException, NotImplementedException, ServiceException,Exception {

  116.         Long id_configurazioneRicerca = this.findIdConfigurazioneRicerca(jdbcProperties, log, connection, sqlQueryObject, id, false);
  117.         return id_configurazioneRicerca != null && id_configurazioneRicerca > 0;
  118.        
  119.     }
  120.    
  121.     @Override
  122.     public List<IdConfigurazioneRicerca> findAllIds(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject, JDBCPaginatedExpression expression, org.openspcoop2.generic_project.beans.IDMappingBehaviour idMappingResolutionBehaviour) throws NotImplementedException, ServiceException,Exception {

  123.         List<IdConfigurazioneRicerca> list = new ArrayList<IdConfigurazioneRicerca>();

  124.         // TODO: implementazione non efficiente.
  125.         // Per ottenere una implementazione efficiente:
  126.         // 1. Usare metodo select di questa classe indirizzando esattamente i field necessari a create l'ID logico
  127.         // 2. Usare metodo getConfigurazioneRicercaFetch() sul risultato della select per ottenere un oggetto ConfigurazioneRicerca
  128.         //    La fetch con la map inserirĂ  nell'oggetto solo i valori estratti
  129.         // 3. Usare metodo convertToId per ottenere l'id

  130.         List<Long> ids = this.findAllTableIds(jdbcProperties, log, connection, sqlQueryObject, expression);
  131.        
  132.         for(Long id: ids) {
  133.             ConfigurazioneRicerca configurazioneRicerca = this.get(jdbcProperties, log, connection, sqlQueryObject, id, idMappingResolutionBehaviour);
  134.             IdConfigurazioneRicerca idConfigurazioneRicerca = this.convertToId(jdbcProperties,log,connection,sqlQueryObject,configurazioneRicerca);
  135.             list.add(idConfigurazioneRicerca);
  136.         }

  137.         return list;
  138.        
  139.     }
  140.    
  141.     @Override
  142.     public List<ConfigurazioneRicerca> findAll(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject, JDBCPaginatedExpression expression, org.openspcoop2.generic_project.beans.IDMappingBehaviour idMappingResolutionBehaviour) throws NotImplementedException, ServiceException,Exception {

  143.         List<ConfigurazioneRicerca> list = new ArrayList<ConfigurazioneRicerca>();
  144.        
  145.         // TODO: implementazione non efficiente.
  146.         // Per ottenere una implementazione efficiente:
  147.         // 1. Usare metodo select di questa classe indirizzando esattamente i field necessari
  148.         // 2. Usare metodo getConfigurazioneRicercaFetch() sul risultato della select per ottenere un oggetto ConfigurazioneRicerca
  149.         //    La fetch con la map inserirĂ  nell'oggetto solo i valori estratti

  150.         List<Long> ids = this.findAllTableIds(jdbcProperties, log, connection, sqlQueryObject, expression);
  151.        
  152.         for(Long id: ids) {
  153.             list.add(this.get(jdbcProperties, log, connection, sqlQueryObject, id, idMappingResolutionBehaviour));
  154.         }

  155.         return list;      
  156.        
  157.     }
  158.    
  159.     @Override
  160.     public ConfigurazioneRicerca find(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject, JDBCExpression expression, org.openspcoop2.generic_project.beans.IDMappingBehaviour idMappingResolutionBehaviour)
  161.         throws NotFoundException, MultipleResultException, NotImplementedException, ServiceException,Exception {

  162.         long id = this.findTableId(jdbcProperties, log, connection, sqlQueryObject, expression);
  163.         if(id>0){
  164.             return this.get(jdbcProperties, log, connection, sqlQueryObject, id, idMappingResolutionBehaviour);
  165.         }else{
  166.             throw new NotFoundException("Entry with id["+id+"] not found");
  167.         }
  168.        
  169.     }
  170.    
  171.     @Override
  172.     public NonNegativeNumber count(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject, JDBCExpression expression) throws NotImplementedException, ServiceException,Exception {
  173.        
  174.         List<Object> listaQuery = org.openspcoop2.generic_project.dao.jdbc.utils.GenericJDBCUtilities.prepareCount(jdbcProperties, log, connection, sqlQueryObject, expression,
  175.                                                 this.getConfigurazioneRicercaFieldConverter(), ConfigurazioneRicerca.model());
  176.        
  177.         sqlQueryObject.addSelectCountField(this.getConfigurazioneRicercaFieldConverter().toTable(ConfigurazioneRicerca.model())+".pid","tot",true);
  178.        
  179.         joinEngine(expression,sqlQueryObject);
  180.        
  181.         return org.openspcoop2.generic_project.dao.jdbc.utils.GenericJDBCUtilities.count(jdbcProperties, log, connection, sqlQueryObject, expression,
  182.                                                                             this.getConfigurazioneRicercaFieldConverter(), ConfigurazioneRicerca.model(),listaQuery);
  183.     }

  184.     @Override
  185.     public InUse inUse(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject, IdConfigurazioneRicerca id) throws NotFoundException, NotImplementedException, ServiceException,Exception {
  186.        
  187.         Long id_configurazioneRicerca = this.findIdConfigurazioneRicerca(jdbcProperties, log, connection, sqlQueryObject, id, true);
  188.         return this.inUseEngine(jdbcProperties, log, connection, sqlQueryObject, id_configurazioneRicerca);
  189.        
  190.     }

  191.     @Override
  192.     public List<Object> select(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject,
  193.                                                     JDBCPaginatedExpression paginatedExpression, IField field) throws ServiceException,NotFoundException,NotImplementedException,Exception {
  194.         return this.select(jdbcProperties, log, connection, sqlQueryObject,
  195.                                 paginatedExpression, false, field);
  196.     }
  197.    
  198.     @Override
  199.     public List<Object> select(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject,
  200.                                                     JDBCPaginatedExpression paginatedExpression, boolean distinct, IField field) throws ServiceException,NotFoundException,NotImplementedException,Exception {
  201.         List<Map<String,Object>> map =
  202.             this.select(jdbcProperties, log, connection, sqlQueryObject, paginatedExpression, distinct, new IField[]{field});
  203.         return org.openspcoop2.generic_project.dao.jdbc.utils.GenericJDBCUtilities.selectSingleObject(map);
  204.     }
  205.    
  206.     @Override
  207.     public List<Map<String,Object>> select(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject,
  208.                                                     JDBCPaginatedExpression paginatedExpression, IField ... field) throws ServiceException,NotFoundException,NotImplementedException,Exception {
  209.         return this.select(jdbcProperties, log, connection, sqlQueryObject,
  210.                                 paginatedExpression, false, field);
  211.     }
  212.    
  213.     @Override
  214.     public List<Map<String,Object>> select(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject,
  215.                                                     JDBCPaginatedExpression paginatedExpression, boolean distinct, IField ... field) throws ServiceException,NotFoundException,NotImplementedException,Exception {
  216.        
  217.         org.openspcoop2.generic_project.dao.jdbc.utils.GenericJDBCUtilities.setFields(sqlQueryObject,paginatedExpression,field);
  218.         try{
  219.        
  220.             ISQLQueryObject sqlQueryObjectDistinct =
  221.                         org.openspcoop2.generic_project.dao.jdbc.utils.GenericJDBCUtilities.prepareSqlQueryObjectForSelectDistinct(distinct,sqlQueryObject, paginatedExpression, log,
  222.                                                 this.getConfigurazioneRicercaFieldConverter(), field);

  223.             return selectEngine(jdbcProperties, log, connection, sqlQueryObject, paginatedExpression, sqlQueryObjectDistinct);
  224.            
  225.         }finally{
  226.             org.openspcoop2.generic_project.dao.jdbc.utils.GenericJDBCUtilities.removeFields(sqlQueryObject,paginatedExpression,field);
  227.         }
  228.     }

  229.     @Override
  230.     public Object aggregate(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject,
  231.                                                     JDBCExpression expression, FunctionField functionField) throws ServiceException,NotFoundException,NotImplementedException,Exception {
  232.         Map<String,Object> map =
  233.             this.aggregate(jdbcProperties, log, connection, sqlQueryObject, expression, new FunctionField[]{functionField});
  234.         return org.openspcoop2.generic_project.dao.jdbc.utils.GenericJDBCUtilities.selectAggregateObject(map,functionField);
  235.     }
  236.    
  237.     @Override
  238.     public Map<String,Object> aggregate(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject,
  239.                                                     JDBCExpression expression, FunctionField ... functionField) throws ServiceException,NotFoundException,NotImplementedException,Exception {                                                  
  240.        
  241.         org.openspcoop2.generic_project.dao.jdbc.utils.GenericJDBCUtilities.setFields(sqlQueryObject,expression,functionField);
  242.         try{
  243.             List<Map<String,Object>> list = selectEngine(jdbcProperties, log, connection, sqlQueryObject, expression);
  244.             return list.get(0);
  245.         }finally{
  246.             org.openspcoop2.generic_project.dao.jdbc.utils.GenericJDBCUtilities.removeFields(sqlQueryObject,expression,functionField);
  247.         }
  248.     }

  249.     @Override
  250.     public List<Map<String,Object>> groupBy(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject,
  251.                                                     JDBCExpression expression, FunctionField ... functionField) throws ServiceException,NotFoundException,NotImplementedException,Exception {
  252.        
  253.         if(expression.getGroupByFields().isEmpty()){
  254.             throw new ServiceException("GroupBy conditions not found in expression");
  255.         }
  256.        
  257.         org.openspcoop2.generic_project.dao.jdbc.utils.GenericJDBCUtilities.setFields(sqlQueryObject,expression,functionField);
  258.         try{
  259.             return selectEngine(jdbcProperties, log, connection, sqlQueryObject, expression);
  260.         }finally{
  261.             org.openspcoop2.generic_project.dao.jdbc.utils.GenericJDBCUtilities.removeFields(sqlQueryObject,expression,functionField);
  262.         }
  263.     }
  264.    

  265.     @Override
  266.     public List<Map<String,Object>> groupBy(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject,
  267.                                                     JDBCPaginatedExpression paginatedExpression, FunctionField ... functionField) throws ServiceException,NotFoundException,NotImplementedException,Exception {
  268.        
  269.         if(paginatedExpression.getGroupByFields().isEmpty()){
  270.             throw new ServiceException("GroupBy conditions not found in expression");
  271.         }
  272.        
  273.         org.openspcoop2.generic_project.dao.jdbc.utils.GenericJDBCUtilities.setFields(sqlQueryObject,paginatedExpression,functionField);
  274.         try{
  275.             return selectEngine(jdbcProperties, log, connection, sqlQueryObject, paginatedExpression);
  276.         }finally{
  277.             org.openspcoop2.generic_project.dao.jdbc.utils.GenericJDBCUtilities.removeFields(sqlQueryObject,paginatedExpression,functionField);
  278.         }
  279.     }
  280.    
  281.     protected List<Map<String,Object>> selectEngine(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject,
  282.                                                 IExpression expression) throws ServiceException,NotFoundException,NotImplementedException,Exception {
  283.         return selectEngine(jdbcProperties, log, connection, sqlQueryObject, expression, null);
  284.     }
  285.     protected List<Map<String,Object>> selectEngine(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject,
  286.                                                 IExpression expression, ISQLQueryObject sqlQueryObjectDistinct) throws ServiceException,NotFoundException,NotImplementedException,Exception {
  287.        
  288.         List<Object> listaQuery = new ArrayList<>();
  289.         List<JDBCObject> listaParams = new ArrayList<>();
  290.         List<Object> returnField = org.openspcoop2.generic_project.dao.jdbc.utils.GenericJDBCUtilities.prepareSelect(jdbcProperties, log, connection, sqlQueryObject,
  291.                                 expression, this.getConfigurazioneRicercaFieldConverter(), ConfigurazioneRicerca.model(),
  292.                                 listaQuery,listaParams);
  293.        
  294.         joinEngine(expression,sqlQueryObject);
  295.        
  296.         List<Map<String,Object>> list = org.openspcoop2.generic_project.dao.jdbc.utils.GenericJDBCUtilities.select(jdbcProperties, log, connection,
  297.                                         org.openspcoop2.generic_project.dao.jdbc.utils.GenericJDBCUtilities.prepareSqlQueryObjectForSelectDistinct(sqlQueryObject,sqlQueryObjectDistinct),
  298.                                         expression, this.getConfigurazioneRicercaFieldConverter(), ConfigurazioneRicerca.model(),
  299.                                         listaQuery,listaParams,returnField);
  300.         if(list!=null && !list.isEmpty()){
  301.             return list;
  302.         }
  303.         else{
  304.             throw org.openspcoop2.generic_project.dao.jdbc.utils.GenericJDBCUtilities.newNotFoundException();
  305.         }
  306.     }
  307.    
  308.     @Override
  309.     public List<Map<String,Object>> union(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject,
  310.                                                 Union union, UnionExpression ... unionExpression) throws ServiceException,NotFoundException,NotImplementedException,Exception {    
  311.        
  312.         List<ISQLQueryObject> sqlQueryObjectInnerList = new ArrayList<>();
  313.         List<JDBCObject> jdbcObjects = new ArrayList<>();
  314.         List<Class<?>> returnClassTypes = org.openspcoop2.generic_project.dao.jdbc.utils.GenericJDBCUtilities.prepareUnion(jdbcProperties, log, connection, sqlQueryObject,
  315.                                 this.getConfigurazioneRicercaFieldConverter(), ConfigurazioneRicerca.model(),
  316.                                 sqlQueryObjectInnerList, jdbcObjects, union, unionExpression);
  317.        
  318.         if(unionExpression!=null){
  319.             for (int i = 0; i < unionExpression.length; i++) {
  320.                 UnionExpression ue = unionExpression[i];
  321.                 IExpression expression = ue.getExpression();
  322.                 joinEngine(expression,sqlQueryObjectInnerList.get(i));
  323.             }
  324.         }
  325.        
  326.         List<Map<String,Object>> list = org.openspcoop2.generic_project.dao.jdbc.utils.GenericJDBCUtilities.union(jdbcProperties, log, connection, sqlQueryObject,
  327.                                         this.getConfigurazioneRicercaFieldConverter(), ConfigurazioneRicerca.model(),
  328.                                         sqlQueryObjectInnerList, jdbcObjects, returnClassTypes, union, unionExpression);
  329.         if(list!=null && !list.isEmpty()){
  330.             return list;
  331.         }
  332.         else{
  333.             throw org.openspcoop2.generic_project.dao.jdbc.utils.GenericJDBCUtilities.newNotFoundException();
  334.         }                              
  335.     }
  336.    
  337.     @Override
  338.     public NonNegativeNumber unionCount(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject,
  339.                                                 Union union, UnionExpression ... unionExpression) throws ServiceException,NotFoundException,NotImplementedException,Exception {    
  340.        
  341.         List<ISQLQueryObject> sqlQueryObjectInnerList = new ArrayList<>();
  342.         List<JDBCObject> jdbcObjects = new ArrayList<>();
  343.         List<Class<?>> returnClassTypes = org.openspcoop2.generic_project.dao.jdbc.utils.GenericJDBCUtilities.prepareUnionCount(jdbcProperties, log, connection, sqlQueryObject,
  344.                                 this.getConfigurazioneRicercaFieldConverter(), ConfigurazioneRicerca.model(),
  345.                                 sqlQueryObjectInnerList, jdbcObjects, union, unionExpression);
  346.        
  347.         if(unionExpression!=null){
  348.             for (int i = 0; i < unionExpression.length; i++) {
  349.                 UnionExpression ue = unionExpression[i];
  350.                 IExpression expression = ue.getExpression();
  351.                 joinEngine(expression,sqlQueryObjectInnerList.get(i));
  352.             }
  353.         }
  354.        
  355.         NonNegativeNumber number = org.openspcoop2.generic_project.dao.jdbc.utils.GenericJDBCUtilities.unionCount(jdbcProperties, log, connection, sqlQueryObject,
  356.                                         this.getConfigurazioneRicercaFieldConverter(), ConfigurazioneRicerca.model(),
  357.                                         sqlQueryObjectInnerList, jdbcObjects, returnClassTypes, union, unionExpression);
  358.         if(number!=null && number.longValue()>=0){
  359.             return number;
  360.         }
  361.         else{
  362.             throw org.openspcoop2.generic_project.dao.jdbc.utils.GenericJDBCUtilities.newNotFoundException();
  363.         }
  364.     }



  365.     // -- ConstructorExpression

  366.     @Override
  367.     public JDBCExpression newExpression(Logger log) throws NotImplementedException, ServiceException {
  368.         try{
  369.             return new JDBCExpression(this.getConfigurazioneRicercaFieldConverter());
  370.         }catch(Exception e){
  371.             throw new ServiceException(e);
  372.         }
  373.     }


  374.     @Override
  375.     public JDBCPaginatedExpression newPaginatedExpression(Logger log) throws NotImplementedException, ServiceException {
  376.         try{
  377.             return new JDBCPaginatedExpression(this.getConfigurazioneRicercaFieldConverter());
  378.         }catch(Exception e){
  379.             throw new ServiceException(e);
  380.         }
  381.     }
  382.    
  383.     @Override
  384.     public JDBCExpression toExpression(JDBCPaginatedExpression paginatedExpression, Logger log) throws NotImplementedException, ServiceException {
  385.         try{
  386.             return new JDBCExpression(paginatedExpression);
  387.         }catch(Exception e){
  388.             throw new ServiceException(e);
  389.         }
  390.     }

  391.     @Override
  392.     public JDBCPaginatedExpression toPaginatedExpression(JDBCExpression expression, Logger log) throws NotImplementedException, ServiceException {
  393.         try{
  394.             return new JDBCPaginatedExpression(expression);
  395.         }catch(Exception e){
  396.             throw new ServiceException(e);
  397.         }
  398.     }
  399.    
  400.    
  401.    
  402.     // -- DB

  403.     @Override
  404.     public void mappingTableIds(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject, IdConfigurazioneRicerca id, ConfigurazioneRicerca obj) throws NotFoundException,NotImplementedException,ServiceException,Exception{
  405.         _mappingTableIds(jdbcProperties,log,connection,sqlQueryObject,obj,
  406.                 this.get(jdbcProperties,log,connection,sqlQueryObject,id,null));
  407.     }
  408.    
  409.     @Override
  410.     public void mappingTableIds(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject, long tableId, ConfigurazioneRicerca obj) throws NotFoundException,NotImplementedException,ServiceException,Exception{
  411.         _mappingTableIds(jdbcProperties,log,connection,sqlQueryObject,obj,
  412.                 this.get(jdbcProperties,log,connection,sqlQueryObject,tableId,null));
  413.     }
  414.     private void _mappingTableIds(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject, ConfigurazioneRicerca obj, ConfigurazioneRicerca imgSaved) throws NotFoundException,NotImplementedException,ServiceException,Exception{
  415.         if(imgSaved==null){
  416.             return;
  417.         }
  418.         obj.setId(imgSaved.getId());
  419.         if(obj.getIdConfigurazioneServizioAzione()!=null &&
  420.                 imgSaved.getIdConfigurazioneServizioAzione()!=null){
  421.             obj.getIdConfigurazioneServizioAzione().setId(imgSaved.getIdConfigurazioneServizioAzione().getId());
  422.             if(obj.getIdConfigurazioneServizioAzione().getIdConfigurazioneServizio()!=null &&
  423.                     imgSaved.getIdConfigurazioneServizioAzione().getIdConfigurazioneServizio()!=null){
  424.                 obj.getIdConfigurazioneServizioAzione().getIdConfigurazioneServizio().setId(imgSaved.getIdConfigurazioneServizioAzione().getIdConfigurazioneServizio().getId());
  425.             }
  426.         }
  427.         if(obj.getPlugin()!=null &&
  428.                 imgSaved.getPlugin()!=null){
  429.             obj.getPlugin().setId(imgSaved.getPlugin().getId());
  430.         }

  431.     }
  432.    
  433.     @Override
  434.     public ConfigurazioneRicerca get(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject, long tableId, org.openspcoop2.generic_project.beans.IDMappingBehaviour idMappingResolutionBehaviour) throws NotFoundException, MultipleResultException, NotImplementedException, ServiceException, Exception {
  435.         return this.getEngine(jdbcProperties, log, connection, sqlQueryObject, Long.valueOf(tableId), idMappingResolutionBehaviour);
  436.     }
  437.    
  438.     private ConfigurazioneRicerca getEngine(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject, Long tableId, org.openspcoop2.generic_project.beans.IDMappingBehaviour idMappingResolutionBehaviour) throws NotFoundException, MultipleResultException, NotImplementedException, ServiceException, Exception {
  439.    
  440.         org.openspcoop2.generic_project.dao.jdbc.utils.JDBCPreparedStatementUtilities jdbcUtilities =
  441.                     new org.openspcoop2.generic_project.dao.jdbc.utils.JDBCPreparedStatementUtilities(sqlQueryObject.getTipoDatabaseOpenSPCoop2(), log, connection);
  442.        
  443.         ISQLQueryObject sqlQueryObjectGet = sqlQueryObject.newSQLQueryObject();
  444.                
  445.         ConfigurazioneRicerca configurazioneRicerca = new ConfigurazioneRicerca();
  446.        

  447.         // Object configurazioneRicerca
  448.         ISQLQueryObject sqlQueryObjectGet_configurazioneRicerca = sqlQueryObjectGet.newSQLQueryObject();
  449.         sqlQueryObjectGet_configurazioneRicerca.setANDLogicOperator(true);
  450.         sqlQueryObjectGet_configurazioneRicerca.addFromTable(this.getConfigurazioneRicercaFieldConverter().toTable(ConfigurazioneRicerca.model()));
  451.         sqlQueryObjectGet_configurazioneRicerca.addSelectField("pid");
  452.         sqlQueryObjectGet_configurazioneRicerca.addSelectField(this.getConfigurazioneRicercaFieldConverter().toColumn(ConfigurazioneRicerca.model().ID_CONFIGURAZIONE_RICERCA,true));
  453.         sqlQueryObjectGet_configurazioneRicerca.addSelectField(this.getConfigurazioneRicercaFieldConverter().toColumn(ConfigurazioneRicerca.model().ENABLED,true));
  454.         sqlQueryObjectGet_configurazioneRicerca.addSelectField(this.getConfigurazioneRicercaFieldConverter().toColumn(ConfigurazioneRicerca.model().LABEL,true));
  455.         sqlQueryObjectGet_configurazioneRicerca.addWhereCondition("pid=?");

  456.         // Get configurazioneRicerca
  457.         configurazioneRicerca = (ConfigurazioneRicerca) jdbcUtilities.executeQuerySingleResult(sqlQueryObjectGet_configurazioneRicerca.createSQLQuery(), jdbcProperties.isShowSql(), ConfigurazioneRicerca.model(), this.getConfigurazioneRicercaFetch(),
  458.             new JDBCObject(tableId,Long.class));


  459.         if(idMappingResolutionBehaviour==null ||
  460.             (org.openspcoop2.generic_project.beans.IDMappingBehaviour.ENABLED.equals(idMappingResolutionBehaviour) || org.openspcoop2.generic_project.beans.IDMappingBehaviour.USE_TABLE_ID.equals(idMappingResolutionBehaviour))
  461.         ){
  462.             // Object _configurazioneRicerca_configurazioneServizioAzione (recupero id)
  463.             ISQLQueryObject sqlQueryObjectGet_configurazioneRicerca_configurazioneServizioAzione_readFkId = sqlQueryObjectGet.newSQLQueryObject();
  464.             sqlQueryObjectGet_configurazioneRicerca_configurazioneServizioAzione_readFkId.addFromTable(this.getConfigurazioneRicercaFieldConverter().toTable(org.openspcoop2.monitor.engine.config.ricerche.ConfigurazioneRicerca.model()));
  465.             sqlQueryObjectGet_configurazioneRicerca_configurazioneServizioAzione_readFkId.addSelectField("id_configurazione");
  466.             sqlQueryObjectGet_configurazioneRicerca_configurazioneServizioAzione_readFkId.addWhereCondition("pid=?");
  467.             sqlQueryObjectGet_configurazioneRicerca_configurazioneServizioAzione_readFkId.setANDLogicOperator(true);
  468.             Long idFK_configurazioneRicerca_configurazioneServizioAzione = (Long) jdbcUtilities.executeQuerySingleResult(sqlQueryObjectGet_configurazioneRicerca_configurazioneServizioAzione_readFkId.createSQLQuery(), jdbcProperties.isShowSql(),Long.class,
  469.                     new JDBCObject(configurazioneRicerca.getId(),Long.class));
  470.        
  471.             IdConfigurazioneServizioAzione _tmpIdConfigurazioneServizioAzione =
  472.                     JDBCConfigurazioneServizioAzioneBaseLib.getIdConfigurazioneServizioAzione(connection, jdbcProperties, log, idFK_configurazioneRicerca_configurazioneServizioAzione);
  473.             org.openspcoop2.monitor.engine.config.ricerche.IdConfigurazioneServizioAzione idConfigurazioneServizioAzione = new org.openspcoop2.monitor.engine.config.ricerche.IdConfigurazioneServizioAzione();
  474.             idConfigurazioneServizioAzione.setAzione(_tmpIdConfigurazioneServizioAzione.getAzione());
  475.             org.openspcoop2.monitor.engine.config.ricerche.IdConfigurazioneServizio idConfigurazioneServizio = new org.openspcoop2.monitor.engine.config.ricerche.IdConfigurazioneServizio();
  476.             idConfigurazioneServizio.setAccordo(_tmpIdConfigurazioneServizioAzione.getIdConfigurazioneServizio().getAccordo());
  477.             idConfigurazioneServizio.setTipoSoggettoReferente(_tmpIdConfigurazioneServizioAzione.getIdConfigurazioneServizio().getTipoSoggettoReferente());
  478.             idConfigurazioneServizio.setNomeSoggettoReferente(_tmpIdConfigurazioneServizioAzione.getIdConfigurazioneServizio().getNomeSoggettoReferente());
  479.             idConfigurazioneServizio.setVersione(_tmpIdConfigurazioneServizioAzione.getIdConfigurazioneServizio().getVersione());
  480.             idConfigurazioneServizio.setServizio(_tmpIdConfigurazioneServizioAzione.getIdConfigurazioneServizio().getServizio());
  481.             idConfigurazioneServizioAzione.setIdConfigurazioneServizio(idConfigurazioneServizio);
  482.             configurazioneRicerca.setIdConfigurazioneServizioAzione(idConfigurazioneServizioAzione);
  483.         }

  484.         if(idMappingResolutionBehaviour==null ||
  485.                 (org.openspcoop2.generic_project.beans.IDMappingBehaviour.ENABLED.equals(idMappingResolutionBehaviour) || org.openspcoop2.generic_project.beans.IDMappingBehaviour.USE_TABLE_ID.equals(idMappingResolutionBehaviour))
  486.             ){
  487.        
  488.             // Object _configurazioneRicerca_plugin (recupero id)
  489.             ISQLQueryObject sqlQueryObjectGet_configurazioneRicerca_plugin_readFkId = sqlQueryObjectGet.newSQLQueryObject();
  490.             sqlQueryObjectGet_configurazioneRicerca_plugin_readFkId.addFromTable(this.getConfigurazioneRicercaFieldConverter().toTable(org.openspcoop2.monitor.engine.config.ricerche.ConfigurazioneRicerca.model()));
  491.             sqlQueryObjectGet_configurazioneRicerca_plugin_readFkId.addSelectField("id_plugin");
  492.             sqlQueryObjectGet_configurazioneRicerca_plugin_readFkId.addWhereCondition("pid=?");
  493.             sqlQueryObjectGet_configurazioneRicerca_plugin_readFkId.setANDLogicOperator(true);
  494.             Long idFK_configurazioneRicerca_plugin = (Long) jdbcUtilities.executeQuerySingleResult(sqlQueryObjectGet_configurazioneRicerca_plugin_readFkId.createSQLQuery(), jdbcProperties.isShowSql(),Long.class,
  495.                     new JDBCObject(configurazioneRicerca.getId(),Long.class));
  496.        
  497.             Plugin plugin = JDBCPluginsBaseLib.getPlugin(connection, jdbcProperties, log, idFK_configurazioneRicerca_plugin);
  498.             InfoPlugin info = new InfoPlugin();
  499.             info.setTipoPlugin(plugin.getTipoPlugin());
  500.             info.setTipo(plugin.getTipo());
  501.             info.setClassName(plugin.getClassName());
  502.             info.setDescrizione(plugin.getDescrizione());
  503.             info.setLabel(plugin.getLabel());
  504.             configurazioneRicerca.setPlugin(info);
  505.         }
  506.        
  507.         return configurazioneRicerca;  
  508.    
  509.     }
  510.    
  511.     @Override
  512.     public boolean exists(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject, long tableId) throws MultipleResultException, NotImplementedException, ServiceException, Exception {
  513.         return this._exists(jdbcProperties, log, connection, sqlQueryObject, Long.valueOf(tableId));
  514.     }
  515.    
  516.     private boolean _exists(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject, Long tableId) throws MultipleResultException, NotImplementedException, ServiceException, Exception {
  517.    
  518.         org.openspcoop2.generic_project.dao.jdbc.utils.JDBCPreparedStatementUtilities jdbcUtilities =
  519.                     new org.openspcoop2.generic_project.dao.jdbc.utils.JDBCPreparedStatementUtilities(sqlQueryObject.getTipoDatabaseOpenSPCoop2(), log, connection);
  520.                
  521.         boolean existsConfigurazioneRicerca = false;

  522.         sqlQueryObject = sqlQueryObject.newSQLQueryObject();
  523.         sqlQueryObject.setANDLogicOperator(true);

  524.         sqlQueryObject.addFromTable(this.getConfigurazioneRicercaFieldConverter().toTable(ConfigurazioneRicerca.model()));
  525.         sqlQueryObject.addSelectField(this.getConfigurazioneRicercaFieldConverter().toColumn(ConfigurazioneRicerca.model().ID_CONFIGURAZIONE_RICERCA,true));
  526.         sqlQueryObject.addWhereCondition("pid=?");


  527.         // Exists configurazioneRicerca
  528.         existsConfigurazioneRicerca = jdbcUtilities.exists(sqlQueryObject.createSQLQuery(), jdbcProperties.isShowSql(),
  529.             new JDBCObject(tableId,Long.class));

  530.        
  531.         return existsConfigurazioneRicerca;
  532.    
  533.     }
  534.    
  535.     private void joinEngine(IExpression expression, ISQLQueryObject sqlQueryObject) throws NotImplementedException, ServiceException, Exception{
  536.    
  537.         if(expression.inUseModel(ConfigurazioneRicerca.model().ID_CONFIGURAZIONE_SERVIZIO_AZIONE,false)){
  538.             String tableName1 = this.getConfigurazioneRicercaFieldConverter().toTable(ConfigurazioneRicerca.model());
  539.             String tableName2 = this.getConfigurazioneRicercaFieldConverter().toTable(ConfigurazioneRicerca.model().ID_CONFIGURAZIONE_SERVIZIO_AZIONE);
  540.             sqlQueryObject.addWhereCondition(tableName1+".id_configurazione="+tableName2+".id");
  541.         }
  542.         if(expression.inUseModel(ConfigurazioneRicerca.model().ID_CONFIGURAZIONE_SERVIZIO_AZIONE.ID_CONFIGURAZIONE_SERVIZIO,false)){
  543.             String tableName1 = this.getConfigurazioneRicercaFieldConverter().toTable(ConfigurazioneRicerca.model().ID_CONFIGURAZIONE_SERVIZIO_AZIONE);
  544.             String tableName2 = this.getConfigurazioneRicercaFieldConverter().toTable(ConfigurazioneRicerca.model().ID_CONFIGURAZIONE_SERVIZIO_AZIONE.ID_CONFIGURAZIONE_SERVIZIO);
  545.             sqlQueryObject.addWhereCondition(tableName1+".id_config_servizio="+tableName2+".id");
  546.         }
  547.         if(expression.inUseModel(ConfigurazioneRicerca.model().PLUGIN,false)){
  548.             String tableName1 = this.getConfigurazioneRicercaFieldConverter().toTable(ConfigurazioneRicerca.model().PLUGIN);
  549.             String tableName2 = this.getConfigurazioneRicercaFieldConverter().toTable(ConfigurazioneRicerca.model());
  550.             sqlQueryObject.addWhereCondition(tableName1+".id="+tableName2+".id_plugin");
  551.         }
  552.        
  553.         // Check FROM Table necessarie per le join di oggetti annidati dal secondo livello in poi dove pero' non viene poi utilizzato l'oggetto del livello precedente nella espressione
  554.         if(expression.inUseModel(ConfigurazioneRicerca.model().ID_CONFIGURAZIONE_SERVIZIO_AZIONE.ID_CONFIGURAZIONE_SERVIZIO,false)){
  555.             if(expression.inUseModel(ConfigurazioneRicerca.model().ID_CONFIGURAZIONE_SERVIZIO_AZIONE,false)==false){
  556.                 sqlQueryObject.addFromTable(this.getConfigurazioneRicercaFieldConverter().toTable(ConfigurazioneRicerca.model().ID_CONFIGURAZIONE_SERVIZIO_AZIONE));
  557.             }
  558.         }
  559.        
  560.     }
  561.    
  562.     protected java.util.List<Object> getRootTablePrimaryKeyValuesEngine(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject, IdConfigurazioneRicerca id) throws NotFoundException, ServiceException, NotImplementedException, Exception{
  563.         // Identificativi
  564.         java.util.List<Object> rootTableIdValues = new java.util.ArrayList<>();
  565.         Long longId = this.findIdConfigurazioneRicerca(jdbcProperties, log, connection, sqlQueryObject.newSQLQueryObject(), id, true);
  566.         rootTableIdValues.add(longId);
  567.         return rootTableIdValues;
  568.     }
  569.    
  570.     protected Map<String, List<IField>> getMapTableToPKColumnEngine() throws NotImplementedException, Exception{
  571.    
  572.         ConfigurazioneRicercaFieldConverter converter = this.getConfigurazioneRicercaFieldConverter();
  573.         Map<String, List<IField>> mapTableToPKColumn = new java.util.HashMap<>();
  574.         UtilsTemplate<IField> utilities = new UtilsTemplate<>();

  575.         // TODO: Define the columns used to identify the primary key
  576.         //        If a table doesn't have a primary key, don't add it to this map

  577.         // ConfigurazioneRicerca.model()
  578.         mapTableToPKColumn.put(converter.toTable(ConfigurazioneRicerca.model()),
  579.             utilities.newList(
  580.                 new CustomField("id", Long.class, "pid", converter.toTable(ConfigurazioneRicerca.model()))
  581.             ));

  582.         // ConfigurazioneRicerca.model().ID_CONFIGURAZIONE_SERVIZIO_AZIONE
  583.         mapTableToPKColumn.put(converter.toTable(ConfigurazioneRicerca.model().ID_CONFIGURAZIONE_SERVIZIO_AZIONE),
  584.             utilities.newList(
  585.                 new CustomField("id", Long.class, "id", converter.toTable(ConfigurazioneRicerca.model().ID_CONFIGURAZIONE_SERVIZIO_AZIONE))
  586.             ));

  587.         // ConfigurazioneRicerca.model().ID_CONFIGURAZIONE_SERVIZIO_AZIONE.ID_CONFIGURAZIONE_SERVIZIO
  588.         mapTableToPKColumn.put(converter.toTable(ConfigurazioneRicerca.model().ID_CONFIGURAZIONE_SERVIZIO_AZIONE.ID_CONFIGURAZIONE_SERVIZIO),
  589.             utilities.newList(
  590.                 new CustomField("id", Long.class, "id", converter.toTable(ConfigurazioneRicerca.model().ID_CONFIGURAZIONE_SERVIZIO_AZIONE.ID_CONFIGURAZIONE_SERVIZIO))
  591.             ));

  592.         // ConfigurazioneRicerca.model().PLUGIN
  593.         mapTableToPKColumn.put(converter.toTable(ConfigurazioneRicerca.model().PLUGIN),
  594.             utilities.newList(
  595.                 new CustomField("id", Long.class, "id", converter.toTable(ConfigurazioneRicerca.model().PLUGIN))
  596.             ));
  597.        
  598.         return mapTableToPKColumn;      
  599.     }
  600.    
  601.     @Override
  602.     public List<Long> findAllTableIds(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject, JDBCPaginatedExpression paginatedExpression) throws ServiceException, NotImplementedException, Exception {
  603.        
  604.         List<Long> list = new ArrayList<Long>();

  605.         sqlQueryObject.setSelectDistinct(true);
  606.         sqlQueryObject.setANDLogicOperator(true);
  607.         sqlQueryObject.addSelectField(this.getConfigurazioneRicercaFieldConverter().toTable(ConfigurazioneRicerca.model())+".pid");
  608.         Class<?> objectIdClass = Long.class;
  609.        
  610.         List<Object> listaQuery = org.openspcoop2.generic_project.dao.jdbc.utils.GenericJDBCUtilities.prepareFindAll(jdbcProperties, log, connection, sqlQueryObject, paginatedExpression,
  611.                                                 this.getConfigurazioneRicercaFieldConverter(), ConfigurazioneRicerca.model());
  612.        
  613.         joinEngine(paginatedExpression,sqlQueryObject);
  614.        
  615.         List<Object> listObjects = org.openspcoop2.generic_project.dao.jdbc.utils.GenericJDBCUtilities.findAll(jdbcProperties, log, connection, sqlQueryObject, paginatedExpression,
  616.                                                                             this.getConfigurazioneRicercaFieldConverter(), ConfigurazioneRicerca.model(), objectIdClass, listaQuery);
  617.         for(Object object: listObjects) {
  618.             list.add((Long)object);
  619.         }

  620.         return list;
  621.        
  622.     }
  623.    
  624.     @Override
  625.     public long findTableId(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject, JDBCExpression expression) throws ServiceException, NotFoundException, MultipleResultException, NotImplementedException, Exception {
  626.    
  627.         sqlQueryObject.setSelectDistinct(true);
  628.         sqlQueryObject.setANDLogicOperator(true);
  629.         sqlQueryObject.addSelectField(this.getConfigurazioneRicercaFieldConverter().toTable(ConfigurazioneRicerca.model())+".pid");
  630.         Class<?> objectIdClass = Long.class;
  631.        
  632.         List<Object> listaQuery = org.openspcoop2.generic_project.dao.jdbc.utils.GenericJDBCUtilities.prepareFind(jdbcProperties, log, connection, sqlQueryObject, expression,
  633.                                                 this.getConfigurazioneRicercaFieldConverter(), ConfigurazioneRicerca.model());
  634.        
  635.         joinEngine(expression,sqlQueryObject);

  636.         Object res = org.openspcoop2.generic_project.dao.jdbc.utils.GenericJDBCUtilities.find(jdbcProperties, log, connection, sqlQueryObject, expression,
  637.                                                         this.getConfigurazioneRicercaFieldConverter(), ConfigurazioneRicerca.model(), objectIdClass, listaQuery);
  638.         if(res!=null && (((Long) res).longValue()>0) ){
  639.             return ((Long) res).longValue();
  640.         }
  641.         else{
  642.             throw org.openspcoop2.generic_project.dao.jdbc.utils.GenericJDBCUtilities.newNotFoundException();
  643.         }
  644.        
  645.     }

  646.     @Override
  647.     public InUse inUse(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject, long tableId) throws ServiceException, NotFoundException, NotImplementedException, Exception {
  648.         return this.inUseEngine(jdbcProperties, log, connection, sqlQueryObject, Long.valueOf(tableId));
  649.     }

  650.     private InUse inUseEngine(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject, Long tableId) throws ServiceException, NotFoundException, NotImplementedException, Exception {

  651.         InUse inUse = new InUse();
  652.         inUse.setInUse(false);
  653.        
  654.         /*
  655.          * TODO: implement code that checks whether the object identified by the id parameter is used by other objects
  656.         */
  657.        
  658.         // Delete this line when you have implemented the method
  659.         int throwNotImplemented = 1;
  660.         if(throwNotImplemented==1){
  661.                 throw new NotImplementedException("NotImplemented");
  662.         }
  663.         // Delete this line when you have implemented the method

  664.         return inUse;

  665.     }
  666.    
  667.     @Override
  668.     public IdConfigurazioneRicerca findId(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject, long tableId, boolean throwNotFound)
  669.             throws NotFoundException, ServiceException, NotImplementedException, Exception {
  670.        
  671.         org.openspcoop2.generic_project.dao.jdbc.utils.JDBCPreparedStatementUtilities jdbcUtilities =
  672.             new org.openspcoop2.generic_project.dao.jdbc.utils.JDBCPreparedStatementUtilities(sqlQueryObject.getTipoDatabaseOpenSPCoop2(), log, connection);

  673.         ISQLQueryObject sqlQueryObjectGet = sqlQueryObject.newSQLQueryObject();

  674.         // Object _configurazioneRicerca
  675.         sqlQueryObjectGet.addFromTable(this.getConfigurazioneRicercaFieldConverter().toTable(ConfigurazioneRicerca.model()));
  676.         sqlQueryObjectGet.addSelectField(this.getConfigurazioneRicercaFieldConverter().toColumn(ConfigurazioneRicerca.model().ID_CONFIGURAZIONE_RICERCA,true));
  677.         sqlQueryObjectGet.addSelectField("id_configurazione");
  678.         sqlQueryObjectGet.setANDLogicOperator(true);
  679.         sqlQueryObjectGet.addWhereCondition("pid=?");

  680.         // Recupero _configurazioneRicerca
  681.         org.openspcoop2.generic_project.dao.jdbc.utils.JDBCObject [] searchParams_configurazioneRicerca = new org.openspcoop2.generic_project.dao.jdbc.utils.JDBCObject [] {
  682.             new org.openspcoop2.generic_project.dao.jdbc.utils.JDBCObject(tableId,Long.class)
  683.         };
  684.         List<Class<?>> listaFieldIdReturnType_configurazioneRicerca = new ArrayList<Class<?>>();
  685.         listaFieldIdReturnType_configurazioneRicerca.add(String.class);
  686.         listaFieldIdReturnType_configurazioneRicerca.add(Long.class);
  687.         org.openspcoop2.monitor.engine.config.ricerche.IdConfigurazioneRicerca id_configurazioneRicerca = null;
  688.         List<Object> listaFieldId_configurazioneRicerca = jdbcUtilities.executeQuerySingleResult(sqlQueryObjectGet.createSQLQuery(), jdbcProperties.isShowSql(),
  689.                 listaFieldIdReturnType_configurazioneRicerca, searchParams_configurazioneRicerca);
  690.         if(listaFieldId_configurazioneRicerca==null || listaFieldId_configurazioneRicerca.size()<=0){
  691.             if(throwNotFound){
  692.                 throw org.openspcoop2.generic_project.dao.jdbc.utils.GenericJDBCUtilities.newNotFoundException();
  693.             }
  694.         }
  695.         else{
  696.             // set _configurazioneRicerca
  697.             id_configurazioneRicerca = new org.openspcoop2.monitor.engine.config.ricerche.IdConfigurazioneRicerca();
  698.             id_configurazioneRicerca.setIdConfigurazioneRicerca((String)listaFieldId_configurazioneRicerca.get(0));
  699.            
  700.             Long idFK_configurazioneRicerca_configurazioneServizioAzione = (Long) listaFieldId_configurazioneRicerca.get(1);
  701.             IdConfigurazioneServizioAzione _tmpIdConfigurazioneServizioAzione =
  702.                     JDBCConfigurazioneServizioAzioneBaseLib.getIdConfigurazioneServizioAzione(connection, jdbcProperties, log, idFK_configurazioneRicerca_configurazioneServizioAzione);
  703.            
  704.             org.openspcoop2.monitor.engine.config.ricerche.IdConfigurazioneServizioAzione idConfigurazioneServizioAzione = new org.openspcoop2.monitor.engine.config.ricerche.IdConfigurazioneServizioAzione();
  705.             idConfigurazioneServizioAzione.setAzione(_tmpIdConfigurazioneServizioAzione.getAzione());
  706.             org.openspcoop2.monitor.engine.config.ricerche.IdConfigurazioneServizio idConfigurazioneServizio = new org.openspcoop2.monitor.engine.config.ricerche.IdConfigurazioneServizio();
  707.             idConfigurazioneServizio.setAccordo(_tmpIdConfigurazioneServizioAzione.getIdConfigurazioneServizio().getAccordo());
  708.             idConfigurazioneServizio.setTipoSoggettoReferente(_tmpIdConfigurazioneServizioAzione.getIdConfigurazioneServizio().getTipoSoggettoReferente());
  709.             idConfigurazioneServizio.setNomeSoggettoReferente(_tmpIdConfigurazioneServizioAzione.getIdConfigurazioneServizio().getNomeSoggettoReferente());
  710.             idConfigurazioneServizio.setVersione(_tmpIdConfigurazioneServizioAzione.getIdConfigurazioneServizio().getVersione());
  711.             idConfigurazioneServizio.setServizio(_tmpIdConfigurazioneServizioAzione.getIdConfigurazioneServizio().getServizio());
  712.             idConfigurazioneServizioAzione.setIdConfigurazioneServizio(idConfigurazioneServizio);
  713.             id_configurazioneRicerca.setIdConfigurazioneServizioAzione(idConfigurazioneServizioAzione);

  714.         }
  715.        
  716.         return id_configurazioneRicerca;
  717.        
  718.     }

  719.     @Override
  720.     public Long findTableId(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject, IdConfigurazioneRicerca id, boolean throwNotFound)
  721.             throws NotFoundException, ServiceException, NotImplementedException, Exception {
  722.    
  723.         return this.findIdConfigurazioneRicerca(jdbcProperties,log,connection,sqlQueryObject,id,throwNotFound);
  724.            
  725.     }
  726.    
  727.     @Override
  728.     public List<List<Object>> nativeQuery(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject,
  729.                                             String sql,List<Class<?>> returnClassTypes,Object ... param) throws ServiceException,NotFoundException,NotImplementedException,Exception{
  730.        
  731.         return org.openspcoop2.generic_project.dao.jdbc.utils.GenericJDBCUtilities.nativeQuery(jdbcProperties, log, connection, sqlQueryObject,
  732.                                                                                             sql,returnClassTypes,param);
  733.                                                        
  734.     }
  735.    
  736.     protected Long findIdConfigurazioneRicerca(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject, IdConfigurazioneRicerca id, boolean throwNotFound) throws NotFoundException, ServiceException, NotImplementedException, Exception {

  737.         org.openspcoop2.generic_project.dao.jdbc.utils.JDBCPreparedStatementUtilities jdbcUtilities =
  738.             new org.openspcoop2.generic_project.dao.jdbc.utils.JDBCPreparedStatementUtilities(sqlQueryObject.getTipoDatabaseOpenSPCoop2(), log, connection);

  739.         ISQLQueryObject sqlQueryObjectGet = sqlQueryObject.newSQLQueryObject();

  740.         // Object _configurazioneServizioAzione
  741.        
  742.         if(id==null){
  743.             throw new ServiceException("Id is null");
  744.         }
  745.         if(id.getIdConfigurazioneServizioAzione()==null){
  746.             throw new ServiceException("IdConfigurazioneServizioAzione is null");
  747.         }
  748.         if(id.getIdConfigurazioneServizioAzione().getAzione()==null){
  749.             throw new ServiceException("IdConfigurazioneServizioAzione.azione is null");
  750.         }
  751.         if(id.getIdConfigurazioneServizioAzione().getIdConfigurazioneServizio()==null){
  752.             throw new ServiceException("IdConfigurazioneServizioAzione.idConfigurazioneServizio is null");
  753.         }
  754.         if(id.getIdConfigurazioneRicerca()==null){
  755.             throw new ServiceException("IdConfigurazioneRicerca is null");
  756.         }
  757.                
  758.         Long id_configurazioneServizioAzione =
  759.                 JDBCConfigurazioneServizioAzioneBaseLib.getIdConfigurazioneServizioAzione(connection, jdbcProperties, log,
  760.                         id.getIdConfigurazioneServizioAzione().getAzione(),
  761.                         id.getIdConfigurazioneServizioAzione().getIdConfigurazioneServizio().getAccordo(),
  762.                         id.getIdConfigurazioneServizioAzione().getIdConfigurazioneServizio().getTipoSoggettoReferente(),
  763.                         id.getIdConfigurazioneServizioAzione().getIdConfigurazioneServizio().getNomeSoggettoReferente(),
  764.                         id.getIdConfigurazioneServizioAzione().getIdConfigurazioneServizio().getVersione(),
  765.                         id.getIdConfigurazioneServizioAzione().getIdConfigurazioneServizio().getServizio(),
  766.                         throwNotFound);
  767.         if(id_configurazioneServizioAzione==null){
  768.             return null; // permesso se throwNotFound==false
  769.         }
  770.        
  771.        
  772.         // Object _configurazioneRicerca
  773.         sqlQueryObjectGet.addFromTable(this.getConfigurazioneRicercaFieldConverter().toTable(ConfigurazioneRicerca.model()));
  774.         sqlQueryObjectGet.addSelectField("pid");
  775.         sqlQueryObjectGet.setANDLogicOperator(true);
  776.         sqlQueryObjectGet.setSelectDistinct(true);
  777.         sqlQueryObjectGet.addWhereCondition(this.getConfigurazioneRicercaFieldConverter().toColumn(ConfigurazioneRicerca.model().ID_CONFIGURAZIONE_RICERCA,true)+"=?");
  778.         sqlQueryObjectGet.addWhereCondition("id_configurazione=?");

  779.         // Recupero _configurazioneRicerca
  780.         org.openspcoop2.generic_project.dao.jdbc.utils.JDBCObject [] searchParams_configurazioneRicerca = new org.openspcoop2.generic_project.dao.jdbc.utils.JDBCObject [] {
  781.                 new JDBCObject( id.getIdConfigurazioneRicerca(), String.class ),
  782.                 new JDBCObject( id_configurazioneServizioAzione, Long.class )
  783.         };
  784.         Long id_configurazioneRicerca = null;
  785.         try{
  786.             id_configurazioneRicerca = (Long) jdbcUtilities.executeQuerySingleResult(sqlQueryObjectGet.createSQLQuery(), jdbcProperties.isShowSql(),
  787.                         Long.class, searchParams_configurazioneRicerca);
  788.         }catch(NotFoundException notFound){
  789.             if(throwNotFound){
  790.                 throw new NotFoundException(notFound);
  791.             }
  792.         }
  793.         if(id_configurazioneRicerca==null || id_configurazioneRicerca<=0){
  794.             if(throwNotFound){
  795.                 throw org.openspcoop2.generic_project.dao.jdbc.utils.GenericJDBCUtilities.newNotFoundException();
  796.             }
  797.         }
  798.        
  799.         return id_configurazioneRicerca;
  800.     }
  801. }