JDBCConfigurazioneStatisticaServiceSearchImpl.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.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.generic_project.expression.impl.sql.ISQLFieldConverter;
  28. import org.openspcoop2.generic_project.dao.jdbc.utils.IJDBCFetch;
  29. import org.openspcoop2.generic_project.dao.jdbc.utils.JDBCObject;
  30. import org.openspcoop2.generic_project.dao.jdbc.IJDBCServiceSearchWithId;
  31. import org.openspcoop2.monitor.engine.config.statistiche.IdConfigurazioneStatistica;
  32. import org.openspcoop2.monitor.engine.config.statistiche.InfoPlugin;
  33. import org.openspcoop2.generic_project.utils.UtilsTemplate;
  34. import org.openspcoop2.generic_project.beans.CustomField;
  35. import org.openspcoop2.generic_project.beans.InUse;
  36. import org.openspcoop2.generic_project.beans.IField;
  37. import org.openspcoop2.generic_project.beans.NonNegativeNumber;
  38. import org.openspcoop2.generic_project.beans.UnionExpression;
  39. import org.openspcoop2.generic_project.beans.Union;
  40. import org.openspcoop2.generic_project.beans.FunctionField;
  41. import org.openspcoop2.generic_project.exception.MultipleResultException;
  42. import org.openspcoop2.generic_project.exception.NotFoundException;
  43. import org.openspcoop2.generic_project.exception.NotImplementedException;
  44. import org.openspcoop2.generic_project.exception.ServiceException;
  45. import org.openspcoop2.generic_project.expression.IExpression;
  46. import org.openspcoop2.generic_project.dao.jdbc.JDBCExpression;
  47. import org.openspcoop2.generic_project.dao.jdbc.JDBCPaginatedExpression;

  48. import org.openspcoop2.generic_project.dao.jdbc.JDBCServiceManagerProperties;
  49. import org.openspcoop2.monitor.engine.config.statistiche.dao.jdbc.converter.ConfigurazioneStatisticaFieldConverter;
  50. import org.openspcoop2.monitor.engine.config.statistiche.dao.jdbc.fetch.ConfigurazioneStatisticaFetch;
  51. import org.openspcoop2.monitor.engine.config.statistiche.ConfigurazioneStatistica;

  52. import org.openspcoop2.core.plugins.IdConfigurazioneServizioAzione;
  53. import org.openspcoop2.core.plugins.Plugin;
  54. import org.openspcoop2.core.plugins.dao.jdbc.JDBCConfigurazioneServizioAzioneBaseLib;
  55. import org.openspcoop2.core.plugins.dao.jdbc.JDBCPluginsBaseLib;

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

  64.     private ConfigurazioneStatisticaFieldConverter _configurazioneStatisticaFieldConverter = null;
  65.     public ConfigurazioneStatisticaFieldConverter getConfigurazioneStatisticaFieldConverter() {
  66.         if(this._configurazioneStatisticaFieldConverter==null){
  67.             this._configurazioneStatisticaFieldConverter = new ConfigurazioneStatisticaFieldConverter(this.jdbcServiceManager.getJdbcProperties().getDatabaseType());
  68.         }      
  69.         return this._configurazioneStatisticaFieldConverter;
  70.     }
  71.     @Override
  72.     public ISQLFieldConverter getFieldConverter() {
  73.         return this.getConfigurazioneStatisticaFieldConverter();
  74.     }
  75.    
  76.     private ConfigurazioneStatisticaFetch configurazioneStatisticaFetch = new ConfigurazioneStatisticaFetch();
  77.     public ConfigurazioneStatisticaFetch getConfigurazioneStatisticaFetch() {
  78.         return this.configurazioneStatisticaFetch;
  79.     }
  80.     @Override
  81.     public IJDBCFetch getFetch() {
  82.         return getConfigurazioneStatisticaFetch();
  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 IdConfigurazioneStatistica convertToId(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject, ConfigurazioneStatistica configurazioneStatistica) throws NotImplementedException, ServiceException, Exception{
  99.    
  100.         IdConfigurazioneStatistica idConfigurazioneStatistica = new IdConfigurazioneStatistica();
  101.         idConfigurazioneStatistica.setIdConfigurazioneStatistica(configurazioneStatistica.getIdConfigurazioneStatistica());
  102.         idConfigurazioneStatistica.setIdConfigurazioneServizioAzione(configurazioneStatistica.getIdConfigurazioneServizioAzione());
  103.         return idConfigurazioneStatistica;
  104.     }
  105.    
  106.     @Override
  107.     public ConfigurazioneStatistica get(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject, IdConfigurazioneStatistica id, org.openspcoop2.generic_project.beans.IDMappingBehaviour idMappingResolutionBehaviour) throws NotFoundException, MultipleResultException, NotImplementedException, ServiceException,Exception {
  108.         Long id_configurazioneStatistica = ( (id!=null && id.getId()!=null && id.getId()>0) ? id.getId() : this.findIdConfigurazioneStatistica(jdbcProperties, log, connection, sqlQueryObject, id, true));
  109.         return this.getEngine(jdbcProperties, log, connection, sqlQueryObject, id_configurazioneStatistica,idMappingResolutionBehaviour);
  110.        
  111.        
  112.     }
  113.    
  114.     @Override
  115.     public boolean exists(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject, IdConfigurazioneStatistica id) throws MultipleResultException, NotImplementedException, ServiceException,Exception {

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

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

  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 getConfigurazioneStatisticaFetch() sul risultato della select per ottenere un oggetto ConfigurazioneStatistica
  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.             ConfigurazioneStatistica configurazioneStatistica = this.get(jdbcProperties, log, connection, sqlQueryObject, id, idMappingResolutionBehaviour);
  134.             IdConfigurazioneStatistica idConfigurazioneStatistica = this.convertToId(jdbcProperties,log,connection,sqlQueryObject,configurazioneStatistica);
  135.             list.add(idConfigurazioneStatistica);
  136.         }

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

  143.         List<ConfigurazioneStatistica> list = new ArrayList<ConfigurazioneStatistica>();
  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 getConfigurazioneStatisticaFetch() sul risultato della select per ottenere un oggetto ConfigurazioneStatistica
  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 ConfigurazioneStatistica 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.getConfigurazioneStatisticaFieldConverter(), ConfigurazioneStatistica.model());
  176.        
  177.         sqlQueryObject.addSelectCountField(this.getConfigurazioneStatisticaFieldConverter().toTable(ConfigurazioneStatistica.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.getConfigurazioneStatisticaFieldConverter(), ConfigurazioneStatistica.model(),listaQuery);
  183.     }

  184.     @Override
  185.     public InUse inUse(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject, IdConfigurazioneStatistica id) throws NotFoundException, NotImplementedException, ServiceException,Exception {
  186.        
  187.         Long id_configurazioneStatistica = this.findIdConfigurazioneStatistica(jdbcProperties, log, connection, sqlQueryObject, id, true);
  188.         return this.inUseEngine(jdbcProperties, log, connection, sqlQueryObject, id_configurazioneStatistica);
  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.getConfigurazioneStatisticaFieldConverter(), 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.getConfigurazioneStatisticaFieldConverter(), ConfigurazioneStatistica.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.getConfigurazioneStatisticaFieldConverter(), ConfigurazioneStatistica.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.getConfigurazioneStatisticaFieldConverter(), ConfigurazioneStatistica.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.getConfigurazioneStatisticaFieldConverter(), ConfigurazioneStatistica.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.getConfigurazioneStatisticaFieldConverter(), ConfigurazioneStatistica.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.getConfigurazioneStatisticaFieldConverter(), ConfigurazioneStatistica.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.getConfigurazioneStatisticaFieldConverter());
  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.getConfigurazioneStatisticaFieldConverter());
  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, IdConfigurazioneStatistica id, ConfigurazioneStatistica 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, ConfigurazioneStatistica 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, ConfigurazioneStatistica obj, ConfigurazioneStatistica 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 ConfigurazioneStatistica 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 ConfigurazioneStatistica 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.         ConfigurazioneStatistica configurazioneStatistica = new ConfigurazioneStatistica();
  446.        

  447.         // Object configurazioneStatistica
  448.         ISQLQueryObject sqlQueryObjectGet_configurazioneStatistica = sqlQueryObjectGet.newSQLQueryObject();
  449.         sqlQueryObjectGet_configurazioneStatistica.setANDLogicOperator(true);
  450.         sqlQueryObjectGet_configurazioneStatistica.addFromTable(this.getConfigurazioneStatisticaFieldConverter().toTable(ConfigurazioneStatistica.model()));
  451.         sqlQueryObjectGet_configurazioneStatistica.addSelectField("pid");
  452.         sqlQueryObjectGet_configurazioneStatistica.addSelectField(this.getConfigurazioneStatisticaFieldConverter().toColumn(ConfigurazioneStatistica.model().ID_CONFIGURAZIONE_STATISTICA,true));
  453.         sqlQueryObjectGet_configurazioneStatistica.addSelectField(this.getConfigurazioneStatisticaFieldConverter().toColumn(ConfigurazioneStatistica.model().ENABLED,true));
  454.         sqlQueryObjectGet_configurazioneStatistica.addSelectField(this.getConfigurazioneStatisticaFieldConverter().toColumn(ConfigurazioneStatistica.model().LABEL,true));
  455.         sqlQueryObjectGet_configurazioneStatistica.addWhereCondition("pid=?");

  456.         // Get configurazioneStatistica
  457.         configurazioneStatistica = (ConfigurazioneStatistica) jdbcUtilities.executeQuerySingleResult(sqlQueryObjectGet_configurazioneStatistica.createSQLQuery(), jdbcProperties.isShowSql(), ConfigurazioneStatistica.model(), this.getConfigurazioneStatisticaFetch(),
  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 _configurazioneStatistica_configurazioneServizioAzione (recupero id)
  463.             ISQLQueryObject sqlQueryObjectGet_configurazioneStatistica_configurazioneServizioAzione_readFkId = sqlQueryObjectGet.newSQLQueryObject();
  464.             sqlQueryObjectGet_configurazioneStatistica_configurazioneServizioAzione_readFkId.addFromTable(this.getConfigurazioneStatisticaFieldConverter().toTable(org.openspcoop2.monitor.engine.config.statistiche.ConfigurazioneStatistica.model()));
  465.             sqlQueryObjectGet_configurazioneStatistica_configurazioneServizioAzione_readFkId.addSelectField("id_configurazione");
  466.             sqlQueryObjectGet_configurazioneStatistica_configurazioneServizioAzione_readFkId.addWhereCondition("pid=?");
  467.             sqlQueryObjectGet_configurazioneStatistica_configurazioneServizioAzione_readFkId.setANDLogicOperator(true);
  468.             Long idFK_configurazioneStatistica_configurazioneServizioAzione = (Long) jdbcUtilities.executeQuerySingleResult(sqlQueryObjectGet_configurazioneStatistica_configurazioneServizioAzione_readFkId.createSQLQuery(), jdbcProperties.isShowSql(),Long.class,
  469.                     new JDBCObject(configurazioneStatistica.getId(),Long.class));
  470.        
  471.             IdConfigurazioneServizioAzione _tmpIdConfigurazioneServizioAzione =
  472.                     JDBCConfigurazioneServizioAzioneBaseLib.getIdConfigurazioneServizioAzione(connection, jdbcProperties, log, idFK_configurazioneStatistica_configurazioneServizioAzione);
  473.             org.openspcoop2.monitor.engine.config.statistiche.IdConfigurazioneServizioAzione idConfigurazioneServizioAzione = new org.openspcoop2.monitor.engine.config.statistiche.IdConfigurazioneServizioAzione();
  474.             idConfigurazioneServizioAzione.setAzione(_tmpIdConfigurazioneServizioAzione.getAzione());
  475.             org.openspcoop2.monitor.engine.config.statistiche.IdConfigurazioneServizio idConfigurazioneServizio = new org.openspcoop2.monitor.engine.config.statistiche.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.             configurazioneStatistica.setIdConfigurazioneServizioAzione(idConfigurazioneServizioAzione);
  483.         }
  484.        
  485.         if(idMappingResolutionBehaviour==null ||
  486.                 (org.openspcoop2.generic_project.beans.IDMappingBehaviour.ENABLED.equals(idMappingResolutionBehaviour) || org.openspcoop2.generic_project.beans.IDMappingBehaviour.USE_TABLE_ID.equals(idMappingResolutionBehaviour))
  487.             ){
  488.             // Object _configurazioneRicerca_plugin (recupero id)
  489.             ISQLQueryObject sqlQueryObjectGet_configurazioneRicerca_plugin_readFkId = sqlQueryObjectGet.newSQLQueryObject();
  490.             sqlQueryObjectGet_configurazioneRicerca_plugin_readFkId.addFromTable(this.getConfigurazioneStatisticaFieldConverter().toTable(org.openspcoop2.monitor.engine.config.statistiche.ConfigurazioneStatistica.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(configurazioneStatistica.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.             configurazioneStatistica.setPlugin(info);
  505.         }
  506.        
  507.         return configurazioneStatistica;  
  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 existsConfigurazioneStatistica = false;

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

  524.         sqlQueryObject.addFromTable(this.getConfigurazioneStatisticaFieldConverter().toTable(ConfigurazioneStatistica.model()));
  525.         sqlQueryObject.addSelectField(this.getConfigurazioneStatisticaFieldConverter().toColumn(ConfigurazioneStatistica.model().ID_CONFIGURAZIONE_STATISTICA,true));
  526.         sqlQueryObject.addWhereCondition("pid=?");


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

  530.        
  531.         return existsConfigurazioneStatistica;
  532.    
  533.     }
  534.    
  535.     private void joinEngine(IExpression expression, ISQLQueryObject sqlQueryObject) throws NotImplementedException, ServiceException, Exception{
  536.    
  537.         if(expression.inUseModel(ConfigurazioneStatistica.model().ID_CONFIGURAZIONE_SERVIZIO_AZIONE,false)){
  538.             String tableName1 = this.getConfigurazioneStatisticaFieldConverter().toTable(ConfigurazioneStatistica.model());
  539.             String tableName2 = this.getConfigurazioneStatisticaFieldConverter().toTable(ConfigurazioneStatistica.model().ID_CONFIGURAZIONE_SERVIZIO_AZIONE);
  540.             sqlQueryObject.addWhereCondition(tableName1+".id_configurazione="+tableName2+".id");
  541.         }
  542.         if(expression.inUseModel(ConfigurazioneStatistica.model().ID_CONFIGURAZIONE_SERVIZIO_AZIONE.ID_CONFIGURAZIONE_SERVIZIO,false)){
  543.             String tableName1 = this.getConfigurazioneStatisticaFieldConverter().toTable(ConfigurazioneStatistica.model().ID_CONFIGURAZIONE_SERVIZIO_AZIONE);
  544.             String tableName2 = this.getConfigurazioneStatisticaFieldConverter().toTable(ConfigurazioneStatistica.model().ID_CONFIGURAZIONE_SERVIZIO_AZIONE.ID_CONFIGURAZIONE_SERVIZIO);
  545.             sqlQueryObject.addWhereCondition(tableName1+".id_config_servizio="+tableName2+".id");
  546.         }
  547.         if(expression.inUseModel(ConfigurazioneStatistica.model().PLUGIN,false)){
  548.             String tableName1 = this.getConfigurazioneStatisticaFieldConverter().toTable(ConfigurazioneStatistica.model().PLUGIN);
  549.             String tableName2 = this.getConfigurazioneStatisticaFieldConverter().toTable(ConfigurazioneStatistica.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(ConfigurazioneStatistica.model().ID_CONFIGURAZIONE_SERVIZIO_AZIONE.ID_CONFIGURAZIONE_SERVIZIO,false)){
  555.             if(expression.inUseModel(ConfigurazioneStatistica.model().ID_CONFIGURAZIONE_SERVIZIO_AZIONE,false)==false){
  556.                 sqlQueryObject.addFromTable(this.getConfigurazioneStatisticaFieldConverter().toTable(ConfigurazioneStatistica.model().ID_CONFIGURAZIONE_SERVIZIO_AZIONE));
  557.             }
  558.         }

  559.     }
  560.    
  561.     protected java.util.List<Object> getRootTablePrimaryKeyValuesEngine(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject, IdConfigurazioneStatistica id) throws NotFoundException, ServiceException, NotImplementedException, Exception{
  562.         // Identificativi
  563.         java.util.List<Object> rootTableIdValues = new java.util.ArrayList<>();
  564.         Long longId = this.findIdConfigurazioneStatistica(jdbcProperties, log, connection, sqlQueryObject.newSQLQueryObject(), id, true);
  565.         rootTableIdValues.add(longId);        
  566.         return rootTableIdValues;
  567.     }
  568.    
  569.     protected Map<String, List<IField>> getMapTableToPKColumnEngine() throws NotImplementedException, Exception{
  570.    
  571.         ConfigurazioneStatisticaFieldConverter converter = this.getConfigurazioneStatisticaFieldConverter();
  572.         Map<String, List<IField>> mapTableToPKColumn = new java.util.HashMap<>();
  573.         UtilsTemplate<IField> utilities = new UtilsTemplate<>();

  574.         // ConfigurazioneStatistica.model()
  575.         mapTableToPKColumn.put(converter.toTable(ConfigurazioneStatistica.model()),
  576.             utilities.newList(
  577.                 new CustomField("id", Long.class, "pid", converter.toTable(ConfigurazioneStatistica.model()))
  578.             ));

  579.         // ConfigurazioneStatistica.model().ID_CONFIGURAZIONE_SERVIZIO_AZIONE
  580.         mapTableToPKColumn.put(converter.toTable(ConfigurazioneStatistica.model().ID_CONFIGURAZIONE_SERVIZIO_AZIONE),
  581.             utilities.newList(
  582.                 new CustomField("id", Long.class, "id", converter.toTable(ConfigurazioneStatistica.model().ID_CONFIGURAZIONE_SERVIZIO_AZIONE))
  583.             ));

  584.         // ConfigurazioneStatistica.model().ID_CONFIGURAZIONE_SERVIZIO_AZIONE.ID_CONFIGURAZIONE_SERVIZIO
  585.         mapTableToPKColumn.put(converter.toTable(ConfigurazioneStatistica.model().ID_CONFIGURAZIONE_SERVIZIO_AZIONE.ID_CONFIGURAZIONE_SERVIZIO),
  586.             utilities.newList(
  587.                 new CustomField("id", Long.class, "id", converter.toTable(ConfigurazioneStatistica.model().ID_CONFIGURAZIONE_SERVIZIO_AZIONE.ID_CONFIGURAZIONE_SERVIZIO))
  588.             ));

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

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

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

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

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

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

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

  661.         return inUse;

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

  670.         ISQLQueryObject sqlQueryObjectGet = sqlQueryObject.newSQLQueryObject();

  671.          
  672.         // Object _configurazioneStatistica
  673.         sqlQueryObjectGet.addFromTable(this.getConfigurazioneStatisticaFieldConverter().toTable(ConfigurazioneStatistica.model()));
  674.         sqlQueryObjectGet.addSelectField(this.getConfigurazioneStatisticaFieldConverter().toColumn(ConfigurazioneStatistica.model().ID_CONFIGURAZIONE_STATISTICA,true));
  675.         sqlQueryObjectGet.addSelectField("id_configurazione");
  676.         sqlQueryObjectGet.setANDLogicOperator(true);
  677.         sqlQueryObjectGet.addWhereCondition("pid=?");

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

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

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

  737.         ISQLQueryObject sqlQueryObjectGet = sqlQueryObject.newSQLQueryObject();

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

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