JDBCStatisticaInfoServiceSearchImpl.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.core.statistiche.dao.jdbc;

  21. import java.sql.Connection;
  22. import java.util.ArrayList;
  23. import java.util.List;
  24. import java.util.Map;

  25. import org.openspcoop2.core.statistiche.StatisticaInfo;
  26. import org.openspcoop2.core.statistiche.constants.TipoIntervalloStatistico;
  27. import org.openspcoop2.core.statistiche.dao.jdbc.converter.StatisticaInfoFieldConverter;
  28. import org.openspcoop2.core.statistiche.dao.jdbc.fetch.StatisticaInfoFetch;
  29. import org.openspcoop2.generic_project.beans.FunctionField;
  30. import org.openspcoop2.generic_project.beans.IField;
  31. import org.openspcoop2.generic_project.beans.InUse;
  32. import org.openspcoop2.generic_project.beans.NonNegativeNumber;
  33. import org.openspcoop2.generic_project.beans.Union;
  34. import org.openspcoop2.generic_project.beans.UnionExpression;
  35. import org.openspcoop2.generic_project.dao.jdbc.IJDBCServiceSearchWithoutId;
  36. import org.openspcoop2.generic_project.dao.jdbc.JDBCExpression;
  37. import org.openspcoop2.generic_project.dao.jdbc.JDBCPaginatedExpression;
  38. import org.openspcoop2.generic_project.dao.jdbc.JDBCServiceManagerProperties;
  39. import org.openspcoop2.generic_project.dao.jdbc.utils.IJDBCFetch;
  40. import org.openspcoop2.generic_project.dao.jdbc.utils.JDBCObject;
  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.expression.impl.sql.ISQLFieldConverter;
  47. import org.openspcoop2.utils.sql.ISQLQueryObject;
  48. import org.slf4j.Logger;

  49. /**    
  50.  * JDBCStatisticaInfoServiceSearchImpl
  51.  *
  52.  * @author Poli Andrea (poli@link.it)
  53.  * @author $Author$
  54.  * @version $Rev$, $Date$
  55.  */
  56. public class JDBCStatisticaInfoServiceSearchImpl implements IJDBCServiceSearchWithoutId<StatisticaInfo, JDBCServiceManager> {

  57.     private StatisticaInfoFieldConverter _statisticaInfoFieldConverter = null;
  58.     public StatisticaInfoFieldConverter getStatisticaInfoFieldConverter() {
  59.         if(this._statisticaInfoFieldConverter==null){
  60.             this._statisticaInfoFieldConverter = new StatisticaInfoFieldConverter(this.jdbcServiceManager.getJdbcProperties().getDatabaseType());
  61.         }      
  62.         return this._statisticaInfoFieldConverter;
  63.     }
  64.     @Override
  65.     public ISQLFieldConverter getFieldConverter() {
  66.         return this.getStatisticaInfoFieldConverter();
  67.     }
  68.    
  69.     private StatisticaInfoFetch statisticaInfoFetch = new StatisticaInfoFetch();
  70.     public StatisticaInfoFetch getStatisticaInfoFetch() {
  71.         return this.statisticaInfoFetch;
  72.     }
  73.     @Override
  74.     public IJDBCFetch getFetch() {
  75.         return getStatisticaInfoFetch();
  76.     }
  77.    
  78.    
  79.     private JDBCServiceManager jdbcServiceManager = null;

  80.     @Override
  81.     public void setServiceManager(JDBCServiceManager serviceManager) throws ServiceException{
  82.         this.jdbcServiceManager = serviceManager;
  83.     }
  84.    
  85.     @Override
  86.     public JDBCServiceManager getServiceManager() throws ServiceException{
  87.         return this.jdbcServiceManager;
  88.     }
  89.    

  90.    
  91.    
  92.    
  93.    
  94.     @Override
  95.     public List<StatisticaInfo> findAll(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject, JDBCPaginatedExpression expression, org.openspcoop2.generic_project.beans.IDMappingBehaviour idMappingResolutionBehaviour) throws NotImplementedException, ServiceException,Exception {

  96.         List<StatisticaInfo> list = new ArrayList<StatisticaInfo>();
  97.        
  98.         // TODO: implementazione non efficiente.
  99.         // Per ottenere una implementazione efficiente:
  100.         // 1. Usare metodo select di questa classe indirizzando esattamente i field necessari
  101.         // 2. Usare metodo getStatisticaInfoFetch() sul risultato della select per ottenere un oggetto StatisticaInfo
  102.         //    La fetch con la map inserirĂ  nell'oggetto solo i valori estratti

  103.         List<Object> ids = this._findAllObjectIds(jdbcProperties, log, connection, sqlQueryObject, expression);
  104.        
  105.         for(Object id: ids) {
  106.             list.add(this.getEngine(jdbcProperties, log, connection, sqlQueryObject, id, idMappingResolutionBehaviour));
  107.         }

  108.         return list;      
  109.        
  110.     }
  111.    
  112.     @Override
  113.     public StatisticaInfo find(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject, JDBCExpression expression, org.openspcoop2.generic_project.beans.IDMappingBehaviour idMappingResolutionBehaviour)
  114.         throws NotFoundException, MultipleResultException, NotImplementedException, ServiceException,Exception {

  115.         Object id = this._findObjectId(jdbcProperties, log, connection, sqlQueryObject, expression);
  116.         if(id!=null){
  117.             return this.getEngine(jdbcProperties, log, connection, sqlQueryObject, id, idMappingResolutionBehaviour);
  118.         }else{
  119.             throw new NotFoundException("Entry with id["+id+"] not found");
  120.         }
  121.        
  122.     }
  123.    
  124.     @Override
  125.     public NonNegativeNumber count(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject, JDBCExpression expression) throws NotImplementedException, ServiceException,Exception {
  126.        
  127.         List<Object> listaQuery = org.openspcoop2.generic_project.dao.jdbc.utils.GenericJDBCUtilities.prepareCount(jdbcProperties, log, connection, sqlQueryObject, expression,
  128.                                                 this.getStatisticaInfoFieldConverter(), StatisticaInfo.model());
  129.        
  130.         sqlQueryObject.addSelectCountField("tot");
  131.        
  132.         joinEngine(expression,sqlQueryObject);
  133.        
  134.         return org.openspcoop2.generic_project.dao.jdbc.utils.GenericJDBCUtilities.count(jdbcProperties, log, connection, sqlQueryObject, expression,
  135.                                                                             this.getStatisticaInfoFieldConverter(), StatisticaInfo.model(),listaQuery);
  136.     }


  137.     @Override
  138.     public List<Object> select(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject,
  139.                                                     JDBCPaginatedExpression paginatedExpression, IField field) throws ServiceException,NotFoundException,NotImplementedException,Exception {
  140.         return this.select(jdbcProperties, log, connection, sqlQueryObject,
  141.                                 paginatedExpression, false, field);
  142.     }
  143.    
  144.     @Override
  145.     public List<Object> select(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject,
  146.                                                     JDBCPaginatedExpression paginatedExpression, boolean distinct, IField field) throws ServiceException,NotFoundException,NotImplementedException,Exception {
  147.         List<Map<String,Object>> map =
  148.             this.select(jdbcProperties, log, connection, sqlQueryObject, paginatedExpression, distinct, new IField[]{field});
  149.         return org.openspcoop2.generic_project.dao.jdbc.utils.GenericJDBCUtilities.selectSingleObject(map);
  150.     }
  151.    
  152.     @Override
  153.     public List<Map<String,Object>> select(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject,
  154.                                                     JDBCPaginatedExpression paginatedExpression, IField ... field) throws ServiceException,NotFoundException,NotImplementedException,Exception {
  155.         return this.select(jdbcProperties, log, connection, sqlQueryObject,
  156.                                 paginatedExpression, false, field);
  157.     }
  158.    
  159.     @Override
  160.     public List<Map<String,Object>> select(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject,
  161.                                                     JDBCPaginatedExpression paginatedExpression, boolean distinct, IField ... field) throws ServiceException,NotFoundException,NotImplementedException,Exception {
  162.        
  163.         org.openspcoop2.generic_project.dao.jdbc.utils.GenericJDBCUtilities.setFields(sqlQueryObject,paginatedExpression,field);
  164.         try{
  165.        
  166.             ISQLQueryObject sqlQueryObjectDistinct =
  167.                         org.openspcoop2.generic_project.dao.jdbc.utils.GenericJDBCUtilities.prepareSqlQueryObjectForSelectDistinct(distinct,sqlQueryObject, paginatedExpression, log,
  168.                                                 this.getStatisticaInfoFieldConverter(), field);

  169.             return selectEngine(jdbcProperties, log, connection, sqlQueryObject, paginatedExpression, sqlQueryObjectDistinct);
  170.            
  171.         }finally{
  172.             org.openspcoop2.generic_project.dao.jdbc.utils.GenericJDBCUtilities.removeFields(sqlQueryObject,paginatedExpression,field);
  173.         }
  174.     }

  175.     @Override
  176.     public Object aggregate(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject,
  177.                                                     JDBCExpression expression, FunctionField functionField) throws ServiceException,NotFoundException,NotImplementedException,Exception {
  178.         Map<String,Object> map =
  179.             this.aggregate(jdbcProperties, log, connection, sqlQueryObject, expression, new FunctionField[]{functionField});
  180.         return org.openspcoop2.generic_project.dao.jdbc.utils.GenericJDBCUtilities.selectAggregateObject(map,functionField);
  181.     }
  182.    
  183.     @Override
  184.     public Map<String,Object> aggregate(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject,
  185.                                                     JDBCExpression expression, FunctionField ... functionField) throws ServiceException,NotFoundException,NotImplementedException,Exception {                                                  
  186.        
  187.         org.openspcoop2.generic_project.dao.jdbc.utils.GenericJDBCUtilities.setFields(sqlQueryObject,expression,functionField);
  188.         try{
  189.             List<Map<String,Object>> list = selectEngine(jdbcProperties, log, connection, sqlQueryObject, expression);
  190.             return list.get(0);
  191.         }finally{
  192.             org.openspcoop2.generic_project.dao.jdbc.utils.GenericJDBCUtilities.removeFields(sqlQueryObject,expression,functionField);
  193.         }
  194.     }

  195.     @Override
  196.     public List<Map<String,Object>> groupBy(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject,
  197.                                                     JDBCExpression expression, FunctionField ... functionField) throws ServiceException,NotFoundException,NotImplementedException,Exception {
  198.        
  199.         if(expression.getGroupByFields().isEmpty()){
  200.             throw new ServiceException("GroupBy conditions not found in expression");
  201.         }
  202.        
  203.         org.openspcoop2.generic_project.dao.jdbc.utils.GenericJDBCUtilities.setFields(sqlQueryObject,expression,functionField);
  204.         try{
  205.             return selectEngine(jdbcProperties, log, connection, sqlQueryObject, expression);
  206.         }finally{
  207.             org.openspcoop2.generic_project.dao.jdbc.utils.GenericJDBCUtilities.removeFields(sqlQueryObject,expression,functionField);
  208.         }
  209.     }
  210.    

  211.     @Override
  212.     public List<Map<String,Object>> groupBy(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject,
  213.                                                     JDBCPaginatedExpression paginatedExpression, FunctionField ... functionField) throws ServiceException,NotFoundException,NotImplementedException,Exception {
  214.        
  215.         if(paginatedExpression.getGroupByFields().isEmpty()){
  216.             throw new ServiceException("GroupBy conditions not found in expression");
  217.         }
  218.        
  219.         org.openspcoop2.generic_project.dao.jdbc.utils.GenericJDBCUtilities.setFields(sqlQueryObject,paginatedExpression,functionField);
  220.         try{
  221.             return selectEngine(jdbcProperties, log, connection, sqlQueryObject, paginatedExpression);
  222.         }finally{
  223.             org.openspcoop2.generic_project.dao.jdbc.utils.GenericJDBCUtilities.removeFields(sqlQueryObject,paginatedExpression,functionField);
  224.         }
  225.     }
  226.    
  227.     protected List<Map<String,Object>> selectEngine(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject,
  228.                                                 IExpression expression) throws ServiceException,NotFoundException,NotImplementedException,Exception {
  229.         return selectEngine(jdbcProperties, log, connection, sqlQueryObject, expression, null);
  230.     }
  231.     protected List<Map<String,Object>> selectEngine(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject,
  232.                                                 IExpression expression, ISQLQueryObject sqlQueryObjectDistinct) throws ServiceException,NotFoundException,NotImplementedException,Exception {
  233.        
  234.         List<Object> listaQuery = new ArrayList<>();
  235.         List<JDBCObject> listaParams = new ArrayList<>();
  236.         List<Object> returnField = org.openspcoop2.generic_project.dao.jdbc.utils.GenericJDBCUtilities.prepareSelect(jdbcProperties, log, connection, sqlQueryObject,
  237.                                 expression, this.getStatisticaInfoFieldConverter(), StatisticaInfo.model(),
  238.                                 listaQuery,listaParams);
  239.        
  240.         joinEngine(expression,sqlQueryObject);
  241.        
  242.         List<Map<String,Object>> list = org.openspcoop2.generic_project.dao.jdbc.utils.GenericJDBCUtilities.select(jdbcProperties, log, connection,
  243.                                         org.openspcoop2.generic_project.dao.jdbc.utils.GenericJDBCUtilities.prepareSqlQueryObjectForSelectDistinct(sqlQueryObject,sqlQueryObjectDistinct),
  244.                                         expression, this.getStatisticaInfoFieldConverter(), StatisticaInfo.model(),
  245.                                         listaQuery,listaParams,returnField);
  246.         if(list!=null && !list.isEmpty()){
  247.             return list;
  248.         }
  249.         else{
  250.             throw org.openspcoop2.generic_project.dao.jdbc.utils.GenericJDBCUtilities.newNotFoundException();
  251.         }
  252.     }
  253.    
  254.     @Override
  255.     public List<Map<String,Object>> union(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject,
  256.                                                 Union union, UnionExpression ... unionExpression) throws ServiceException,NotFoundException,NotImplementedException,Exception {    
  257.        
  258.         List<ISQLQueryObject> sqlQueryObjectInnerList = new ArrayList<>();
  259.         List<JDBCObject> jdbcObjects = new ArrayList<>();
  260.         List<Class<?>> returnClassTypes = org.openspcoop2.generic_project.dao.jdbc.utils.GenericJDBCUtilities.prepareUnion(jdbcProperties, log, connection, sqlQueryObject,
  261.                                 this.getStatisticaInfoFieldConverter(), StatisticaInfo.model(),
  262.                                 sqlQueryObjectInnerList, jdbcObjects, union, unionExpression);
  263.        
  264.         if(unionExpression!=null){
  265.             for (int i = 0; i < unionExpression.length; i++) {
  266.                 UnionExpression ue = unionExpression[i];
  267.                 IExpression expression = ue.getExpression();
  268.                 joinEngine(expression,sqlQueryObjectInnerList.get(i));
  269.             }
  270.         }
  271.        
  272.         List<Map<String,Object>> list = org.openspcoop2.generic_project.dao.jdbc.utils.GenericJDBCUtilities.union(jdbcProperties, log, connection, sqlQueryObject,
  273.                                         this.getStatisticaInfoFieldConverter(), StatisticaInfo.model(),
  274.                                         sqlQueryObjectInnerList, jdbcObjects, returnClassTypes, union, unionExpression);
  275.         if(list!=null && !list.isEmpty()){
  276.             return list;
  277.         }
  278.         else{
  279.             throw org.openspcoop2.generic_project.dao.jdbc.utils.GenericJDBCUtilities.newNotFoundException();
  280.         }                              
  281.     }
  282.    
  283.     @Override
  284.     public NonNegativeNumber unionCount(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject,
  285.                                                 Union union, UnionExpression ... unionExpression) throws ServiceException,NotFoundException,NotImplementedException,Exception {    
  286.        
  287.         List<ISQLQueryObject> sqlQueryObjectInnerList = new ArrayList<>();
  288.         List<JDBCObject> jdbcObjects = new ArrayList<>();
  289.         List<Class<?>> returnClassTypes = org.openspcoop2.generic_project.dao.jdbc.utils.GenericJDBCUtilities.prepareUnionCount(jdbcProperties, log, connection, sqlQueryObject,
  290.                                 this.getStatisticaInfoFieldConverter(), StatisticaInfo.model(),
  291.                                 sqlQueryObjectInnerList, jdbcObjects, union, unionExpression);
  292.        
  293.         if(unionExpression!=null){
  294.             for (int i = 0; i < unionExpression.length; i++) {
  295.                 UnionExpression ue = unionExpression[i];
  296.                 IExpression expression = ue.getExpression();
  297.                 joinEngine(expression,sqlQueryObjectInnerList.get(i));
  298.             }
  299.         }
  300.        
  301.         NonNegativeNumber number = org.openspcoop2.generic_project.dao.jdbc.utils.GenericJDBCUtilities.unionCount(jdbcProperties, log, connection, sqlQueryObject,
  302.                                         this.getStatisticaInfoFieldConverter(), StatisticaInfo.model(),
  303.                                         sqlQueryObjectInnerList, jdbcObjects, returnClassTypes, union, unionExpression);
  304.         if(number!=null && number.longValue()>=0){
  305.             return number;
  306.         }
  307.         else{
  308.             throw org.openspcoop2.generic_project.dao.jdbc.utils.GenericJDBCUtilities.newNotFoundException();
  309.         }
  310.     }



  311.     // -- ConstructorExpression

  312.     @Override
  313.     public JDBCExpression newExpression(Logger log) throws NotImplementedException, ServiceException {
  314.         try{
  315.             return new JDBCExpression(this.getStatisticaInfoFieldConverter());
  316.         }catch(Exception e){
  317.             throw new ServiceException(e);
  318.         }
  319.     }


  320.     @Override
  321.     public JDBCPaginatedExpression newPaginatedExpression(Logger log) throws NotImplementedException, ServiceException {
  322.         try{
  323.             return new JDBCPaginatedExpression(this.getStatisticaInfoFieldConverter());
  324.         }catch(Exception e){
  325.             throw new ServiceException(e);
  326.         }
  327.     }
  328.    
  329.     @Override
  330.     public JDBCExpression toExpression(JDBCPaginatedExpression paginatedExpression, Logger log) throws NotImplementedException, ServiceException {
  331.         try{
  332.             return new JDBCExpression(paginatedExpression);
  333.         }catch(Exception e){
  334.             throw new ServiceException(e);
  335.         }
  336.     }

  337.     @Override
  338.     public JDBCPaginatedExpression toPaginatedExpression(JDBCExpression expression, Logger log) throws NotImplementedException, ServiceException {
  339.         try{
  340.             return new JDBCPaginatedExpression(expression);
  341.         }catch(Exception e){
  342.             throw new ServiceException(e);
  343.         }
  344.     }
  345.    
  346.    
  347.    
  348.     // -- DB

  349.    
  350.     @Override
  351.     public StatisticaInfo get(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject, long tableId, org.openspcoop2.generic_project.beans.IDMappingBehaviour idMappingResolutionBehaviour) throws NotFoundException, MultipleResultException, NotImplementedException, ServiceException, Exception {
  352.         throw new NotImplementedException("Table without long id column PK");
  353.     }
  354.    
  355.     protected StatisticaInfo getEngine(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject, Object objectId, org.openspcoop2.generic_project.beans.IDMappingBehaviour idMappingResolutionBehaviour) throws NotFoundException, MultipleResultException, NotImplementedException, ServiceException, Exception {
  356.    
  357.         org.openspcoop2.generic_project.dao.jdbc.utils.JDBCPreparedStatementUtilities jdbcUtilities =
  358.                     new org.openspcoop2.generic_project.dao.jdbc.utils.JDBCPreparedStatementUtilities(sqlQueryObject.getTipoDatabaseOpenSPCoop2(), log, connection);
  359.        
  360.         ISQLQueryObject sqlQueryObjectGet = sqlQueryObject.newSQLQueryObject();
  361.                
  362.         StatisticaInfo statisticaInfo = new StatisticaInfo();
  363.        
  364.         if(objectId == null ){
  365.             throw new ServiceException("ID Logico non trovato");
  366.         }
  367.         if(objectId instanceof TipoIntervalloStatistico == false){
  368.             throw new ServiceException("Tipo dell'id non valido, atteso["+TipoIntervalloStatistico.class.getName()+"] trovato["+objectId.getClass().getName()+"]");
  369.         }
  370.         TipoIntervalloStatistico tipoStatistica = (TipoIntervalloStatistico) objectId;
  371.        

  372.         // Object statisticaInfo
  373.         sqlQueryObjectGet.setANDLogicOperator(true);
  374.         sqlQueryObjectGet.addFromTable(this.getStatisticaInfoFieldConverter().toTable(StatisticaInfo.model()));
  375.         sqlQueryObjectGet.addSelectField(this.getStatisticaInfoFieldConverter().toColumn(StatisticaInfo.model().TIPO_STATISTICA,true));
  376.         sqlQueryObjectGet.addSelectField(this.getStatisticaInfoFieldConverter().toColumn(StatisticaInfo.model().DATA_ULTIMA_GENERAZIONE,true));
  377.         sqlQueryObjectGet.addWhereCondition(this.getStatisticaInfoFieldConverter().toColumn(StatisticaInfo.model().TIPO_STATISTICA,true)+"=?");

  378.         // Get statisticaInfo
  379.         statisticaInfo = (StatisticaInfo) jdbcUtilities.executeQuerySingleResult(sqlQueryObjectGet.createSQLQuery(), jdbcProperties.isShowSql(), StatisticaInfo.model(), this.getStatisticaInfoFetch(),
  380.             new JDBCObject(tipoStatistica.getValue(),String.class));
  381.                
  382.        
  383.         return statisticaInfo;  
  384.    
  385.     }
  386.    
  387.     @Override
  388.     public boolean exists(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject, long tableId) throws MultipleResultException, NotImplementedException, ServiceException, Exception {
  389.         throw new NotImplementedException("Table without long id column PK");
  390.     }
  391.    
  392.     protected boolean _exists(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject, Object objectId) throws MultipleResultException, NotImplementedException, ServiceException, Exception {
  393.    
  394.         org.openspcoop2.generic_project.dao.jdbc.utils.JDBCPreparedStatementUtilities jdbcUtilities =
  395.                     new org.openspcoop2.generic_project.dao.jdbc.utils.JDBCPreparedStatementUtilities(sqlQueryObject.getTipoDatabaseOpenSPCoop2(), log, connection);
  396.                
  397.         boolean existsStatisticaInfo = false;

  398.         if(objectId == null ){
  399.             throw new ServiceException("ID Logico non trovato");
  400.         }
  401.         if(objectId instanceof TipoIntervalloStatistico == false){
  402.             throw new ServiceException("Tipo dell'id non valido, atteso["+TipoIntervalloStatistico.class.getName()+"] trovato["+objectId.getClass().getName()+"]");
  403.         }
  404.         TipoIntervalloStatistico tipoStatistica = (TipoIntervalloStatistico) objectId;
  405.        
  406.         sqlQueryObject = sqlQueryObject.newSQLQueryObject();
  407.         sqlQueryObject.setANDLogicOperator(true);

  408.         sqlQueryObject.addFromTable(this.getStatisticaInfoFieldConverter().toTable(StatisticaInfo.model()));
  409.         sqlQueryObject.addSelectField(this.getStatisticaInfoFieldConverter().toColumn(StatisticaInfo.model().TIPO_STATISTICA,true));
  410.         sqlQueryObject.addWhereCondition(this.getStatisticaInfoFieldConverter().toColumn(StatisticaInfo.model().TIPO_STATISTICA,true)+"=?");

  411.         // Exists statisticaInfo
  412.         existsStatisticaInfo = jdbcUtilities.exists(sqlQueryObject.createSQLQuery(), jdbcProperties.isShowSql(),
  413.                 new JDBCObject(tipoStatistica.getValue(),String.class));
  414.        
  415.         return existsStatisticaInfo;
  416.    
  417.     }
  418.    
  419.     private void joinEngine(IExpression expression, ISQLQueryObject sqlQueryObject) throws NotImplementedException, ServiceException, Exception{
  420.    
  421.         // nop;
  422.        
  423.     }
  424.    
  425.     protected java.util.List<Object> getRootTablePrimaryKeyValuesEngine(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject, StatisticaInfo statisticaInfo) throws NotFoundException, ServiceException, NotImplementedException, Exception{
  426.         // Identificativi
  427.         java.util.List<Object> rootTableIdValues = new java.util.ArrayList<>();
  428.         return rootTableIdValues;
  429.     }
  430.    
  431.     protected Map<String, List<IField>> getMapTableToPKColumnEngine() throws NotImplementedException, Exception{
  432.    
  433.         //StatisticaInfoFieldConverter converter = this.getStatisticaInfoFieldConverter();
  434.         Map<String, List<IField>> mapTableToPKColumn = new java.util.HashMap<>();
  435.         //UtilsTemplate<IField> utilities = new UtilsTemplate<>();

  436. //      // StatisticaInfo.model()
  437. //      mapTableToPKColumn.put(converter.toTable(StatisticaInfo.model()),
  438. //          utilities.newList(
  439. //              new CustomField("id", Long.class, "id", converter.toTable(StatisticaInfo.model()))
  440. //          ));
  441.        
  442.         return mapTableToPKColumn;      
  443.     }
  444.    
  445.     @Override
  446.     public List<Long> findAllTableIds(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject, JDBCPaginatedExpression paginatedExpression) throws ServiceException, NotImplementedException, Exception {
  447.        
  448.         throw new NotImplementedException("Table without long id column PK");
  449.        
  450.     }
  451.     public List<Object> _findAllObjectIds(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject, JDBCPaginatedExpression paginatedExpression) throws ServiceException, NotImplementedException, Exception {
  452.        

  453.         sqlQueryObject.addSelectField(this.getStatisticaInfoFieldConverter().toColumn(StatisticaInfo.model().TIPO_STATISTICA,true));
  454.         Class<?> objectIdClass = String.class;
  455.                
  456.         List<Object> listaQuery = org.openspcoop2.generic_project.dao.jdbc.utils.GenericJDBCUtilities.prepareFindAll(jdbcProperties, log, connection, sqlQueryObject, paginatedExpression,
  457.                                                 this.getStatisticaInfoFieldConverter(), StatisticaInfo.model());
  458.        
  459.         joinEngine(paginatedExpression,sqlQueryObject);
  460.        
  461.         List<Object> listObjects = org.openspcoop2.generic_project.dao.jdbc.utils.GenericJDBCUtilities.findAll(jdbcProperties, log, connection, sqlQueryObject, paginatedExpression,
  462.                                                                             this.getStatisticaInfoFieldConverter(), StatisticaInfo.model(), objectIdClass, listaQuery);
  463.         List<Object> newList = new ArrayList<>();
  464.         for (int i = 0; i < listObjects.size(); i++) {
  465.             newList.add(TipoIntervalloStatistico.toEnumConstant((String)listObjects.get(i)));
  466.         }
  467.        
  468.         return newList;
  469.        
  470.     }
  471.    
  472.     @Override
  473.     public long findTableId(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject, JDBCExpression expression) throws ServiceException, NotFoundException, MultipleResultException, NotImplementedException, Exception {
  474.    
  475.         throw new NotImplementedException("Table without long id column PK");
  476.        
  477.     }
  478.    
  479.     public Object _findObjectId(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject, JDBCExpression expression) throws ServiceException, NotFoundException, MultipleResultException, NotImplementedException, Exception {
  480.        
  481.         sqlQueryObject.addSelectField(this.getStatisticaInfoFieldConverter().toColumn(StatisticaInfo.model().TIPO_STATISTICA,true));
  482.         Class<?> objectIdClass = String.class;
  483.                
  484.         List<Object> listaQuery = org.openspcoop2.generic_project.dao.jdbc.utils.GenericJDBCUtilities.prepareFind(jdbcProperties, log, connection, sqlQueryObject, expression,
  485.                                                 this.getStatisticaInfoFieldConverter(), StatisticaInfo.model());
  486.        
  487.         joinEngine(expression,sqlQueryObject);

  488.         Object res = org.openspcoop2.generic_project.dao.jdbc.utils.GenericJDBCUtilities.find(jdbcProperties, log, connection, sqlQueryObject, expression,
  489.                                                         this.getStatisticaInfoFieldConverter(), StatisticaInfo.model(), objectIdClass, listaQuery);
  490.         if(res!=null){
  491.             return TipoIntervalloStatistico.toEnumConstant((String)res);
  492.         }
  493.         else{
  494.             throw org.openspcoop2.generic_project.dao.jdbc.utils.GenericJDBCUtilities.newNotFoundException();
  495.         }
  496.        
  497.     }

  498.     @Override
  499.     public InUse inUse(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject, long tableId) throws ServiceException, NotFoundException, NotImplementedException, Exception {
  500.         throw new NotImplementedException("Table without long id column PK");
  501.     }

  502.     protected InUse inUseEngine(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject, Object objectId) throws ServiceException, NotFoundException, NotImplementedException, Exception {

  503.         InUse inUse = new InUse();
  504.         inUse.setInUse(false);
  505.        
  506.         /*
  507.          * TODO: implement code that checks whether the object identified by the id parameter is used by other objects
  508.         */
  509.        
  510.         // Delete this line when you have implemented the method
  511.         int throwNotImplemented = 1;
  512.         if(throwNotImplemented==1){
  513.                 throw new NotImplementedException("NotImplemented");
  514.         }
  515.         // Delete this line when you have implemented the method

  516.         return inUse;

  517.     }
  518.    

  519.    
  520.     @Override
  521.     public List<List<Object>> nativeQuery(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject,
  522.                                             String sql,List<Class<?>> returnClassTypes,Object ... param) throws ServiceException,NotFoundException,NotImplementedException,Exception{
  523.        
  524.         return org.openspcoop2.generic_project.dao.jdbc.utils.GenericJDBCUtilities.nativeQuery(jdbcProperties, log, connection, sqlQueryObject,
  525.                                                                                             sql,returnClassTypes,param);
  526.                                                        
  527.     }
  528.    
  529. }