JDBCStatistichePdndTracingServiceSearchImpl.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.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.IJDBCServiceSearchWithoutId;
  31. import org.openspcoop2.generic_project.utils.UtilsTemplate;
  32. import org.openspcoop2.generic_project.beans.CustomField;
  33. import org.openspcoop2.generic_project.beans.InUse;
  34. import org.openspcoop2.generic_project.beans.IField;
  35. import org.openspcoop2.generic_project.beans.NonNegativeNumber;
  36. import org.openspcoop2.generic_project.beans.UnionExpression;
  37. import org.openspcoop2.generic_project.beans.Union;
  38. import org.openspcoop2.generic_project.beans.FunctionField;
  39. import org.openspcoop2.generic_project.exception.MultipleResultException;
  40. import org.openspcoop2.generic_project.exception.NotFoundException;
  41. import org.openspcoop2.generic_project.exception.NotImplementedException;
  42. import org.openspcoop2.generic_project.exception.ServiceException;
  43. import org.openspcoop2.generic_project.expression.IExpression;
  44. import org.openspcoop2.generic_project.dao.jdbc.JDBCExpression;
  45. import org.openspcoop2.generic_project.dao.jdbc.JDBCPaginatedExpression;

  46. import org.openspcoop2.generic_project.dao.jdbc.JDBCServiceManagerProperties;
  47. import org.openspcoop2.core.statistiche.dao.jdbc.converter.StatistichePdndTracingFieldConverter;
  48. import org.openspcoop2.core.statistiche.dao.jdbc.fetch.StatistichePdndTracingFetch;
  49. import org.openspcoop2.core.statistiche.model.StatistichePdndTracingModel;
  50. import org.openspcoop2.core.statistiche.StatistichePdndTracing;

  51. /**    
  52.  * JDBCStatistichePdndTracingServiceSearchImpl
  53.  *
  54.  * @author Poli Andrea (poli@link.it)
  55.  * @author Tommaso Burlon (tommaso.burlon@link.it)
  56.  * @author $Author$
  57.  * @version $Rev$, $Date$
  58.  */
  59. public class JDBCStatistichePdndTracingServiceSearchImpl implements IJDBCServiceSearchWithoutId<StatistichePdndTracing, JDBCServiceManager> {

  60.     private StatistichePdndTracingFieldConverter _statistichePdndTracingFieldConverter = null;
  61.     public StatistichePdndTracingFieldConverter getStatistichePdndTracingFieldConverter() {
  62.         if(this._statistichePdndTracingFieldConverter==null){
  63.             this._statistichePdndTracingFieldConverter = new StatistichePdndTracingFieldConverter(this.jdbcServiceManager.getJdbcProperties().getDatabaseType());
  64.         }      
  65.         return this._statistichePdndTracingFieldConverter;
  66.     }
  67.     @Override
  68.     public ISQLFieldConverter getFieldConverter() {
  69.         return this.getStatistichePdndTracingFieldConverter();
  70.     }
  71.    
  72.     private StatistichePdndTracingFetch statistichePdndTracingFetch = new StatistichePdndTracingFetch();
  73.     public StatistichePdndTracingFetch getStatistichePdndTracingFetch() {
  74.         return this.statistichePdndTracingFetch;
  75.     }
  76.     @Override
  77.     public IJDBCFetch getFetch() {
  78.         return getStatistichePdndTracingFetch();
  79.     }
  80.    
  81.    
  82.     private JDBCServiceManager jdbcServiceManager = null;

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

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

  99.         List<StatistichePdndTracing> list = new ArrayList<StatistichePdndTracing>();
  100.         StatistichePdndTracingModel model = StatistichePdndTracing.model();
  101.        
  102.         List<Map<String, Object>> maps = this.select(jdbcProperties, log, connection, sqlQueryObject, expression,
  103.                 new CustomField("id", Long.class, "id", this.getStatistichePdndTracingFieldConverter().toTable(model)),
  104.                 model.CSV,
  105.                 model.DATA_REGISTRAZIONE,
  106.                 model.DATA_TRACCIAMENTO,
  107.                 model.DATA_PUBBLICAZIONE,
  108.                 model.ERROR_DETAILS,
  109.                 model.HISTORY,
  110.                 model.METHOD,
  111.                 model.PDD_CODICE,
  112.                 model.STATO,
  113.                 model.STATO_PDND,
  114.                 model.TENTATIVI_PUBBLICAZIONE,
  115.                 model.FORCE_PUBLISH,
  116.                 model.TRACING_ID);
  117.        

  118.         for (Map<String, Object> map : maps) {
  119.             list.add((StatistichePdndTracing) this.getStatistichePdndTracingFetch().fetch(
  120.                     jdbcProperties.getDatabase(),
  121.                     model,
  122.                     map));
  123.         }
  124.        

  125.         return list;      
  126.        
  127.     }
  128.    
  129.     @Override
  130.     public StatistichePdndTracing find(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject, JDBCExpression expression, org.openspcoop2.generic_project.beans.IDMappingBehaviour idMappingResolutionBehaviour)
  131.         throws NotFoundException, MultipleResultException, NotImplementedException, ServiceException,Exception {

  132.         long id = this.findTableId(jdbcProperties, log, connection, sqlQueryObject, expression);
  133.         if(id>0){
  134.             return this.get(jdbcProperties, log, connection, sqlQueryObject, id, idMappingResolutionBehaviour);
  135.         }else{
  136.             throw new NotFoundException("Entry with id["+id+"] not found");
  137.         }
  138.        
  139.     }
  140.    
  141.     @Override
  142.     public NonNegativeNumber count(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject, JDBCExpression expression) throws NotImplementedException, ServiceException,Exception {
  143.        
  144.         List<Object> listaQuery = org.openspcoop2.generic_project.dao.jdbc.utils.GenericJDBCUtilities.prepareCount(jdbcProperties, log, connection, sqlQueryObject, expression,
  145.                                                 this.getStatistichePdndTracingFieldConverter(), StatistichePdndTracing.model());
  146.        
  147.         sqlQueryObject.addSelectCountField(this.getStatistichePdndTracingFieldConverter().toTable(StatistichePdndTracing.model())+".id","tot",true);
  148.        
  149.         _join(expression,sqlQueryObject);
  150.        
  151.         return org.openspcoop2.generic_project.dao.jdbc.utils.GenericJDBCUtilities.count(jdbcProperties, log, connection, sqlQueryObject, expression,
  152.                                                                             this.getStatistichePdndTracingFieldConverter(), StatistichePdndTracing.model(),listaQuery);
  153.     }


  154.     @Override
  155.     public List<Object> select(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject,
  156.                                                     JDBCPaginatedExpression paginatedExpression, IField field) throws ServiceException,NotFoundException,NotImplementedException,Exception {
  157.         return this.select(jdbcProperties, log, connection, sqlQueryObject,
  158.                                 paginatedExpression, false, field);
  159.     }
  160.    
  161.     @Override
  162.     public List<Object> select(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject,
  163.                                                     JDBCPaginatedExpression paginatedExpression, boolean distinct, IField field) throws ServiceException,NotFoundException,NotImplementedException,Exception {
  164.         List<Map<String,Object>> map =
  165.             this.select(jdbcProperties, log, connection, sqlQueryObject, paginatedExpression, distinct, new IField[]{field});
  166.         return org.openspcoop2.generic_project.dao.jdbc.utils.GenericJDBCUtilities.selectSingleObject(map);
  167.     }
  168.    
  169.     @Override
  170.     public List<Map<String,Object>> select(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject,
  171.                                                     JDBCPaginatedExpression paginatedExpression, IField ... field) throws ServiceException,NotFoundException,NotImplementedException,Exception {
  172.         return this.select(jdbcProperties, log, connection, sqlQueryObject,
  173.                                 paginatedExpression, false, field);
  174.     }
  175.    
  176.     @Override
  177.     public List<Map<String,Object>> select(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject,
  178.                                                     JDBCPaginatedExpression paginatedExpression, boolean distinct, IField ... field) throws ServiceException,NotFoundException,NotImplementedException,Exception {
  179.        
  180.         org.openspcoop2.generic_project.dao.jdbc.utils.GenericJDBCUtilities.setFields(sqlQueryObject,paginatedExpression,field);
  181.         try{
  182.        
  183.             ISQLQueryObject sqlQueryObjectDistinct =
  184.                         org.openspcoop2.generic_project.dao.jdbc.utils.GenericJDBCUtilities.prepareSqlQueryObjectForSelectDistinct(distinct,sqlQueryObject, paginatedExpression, log,
  185.                                                 this.getStatistichePdndTracingFieldConverter(), field);

  186.             return _select(jdbcProperties, log, connection, sqlQueryObject, paginatedExpression, sqlQueryObjectDistinct);
  187.            
  188.         }finally{
  189.             org.openspcoop2.generic_project.dao.jdbc.utils.GenericJDBCUtilities.removeFields(sqlQueryObject,paginatedExpression,field);
  190.         }
  191.     }

  192.     @Override
  193.     public Object aggregate(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject,
  194.                                                     JDBCExpression expression, FunctionField functionField) throws ServiceException,NotFoundException,NotImplementedException,Exception {
  195.         Map<String,Object> map =
  196.             this.aggregate(jdbcProperties, log, connection, sqlQueryObject, expression, new FunctionField[]{functionField});
  197.         return org.openspcoop2.generic_project.dao.jdbc.utils.GenericJDBCUtilities.selectAggregateObject(map,functionField);
  198.     }
  199.    
  200.     @Override
  201.     public Map<String,Object> aggregate(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject,
  202.                                                     JDBCExpression expression, FunctionField ... functionField) throws ServiceException,NotFoundException,NotImplementedException,Exception {                                                  
  203.        
  204.         org.openspcoop2.generic_project.dao.jdbc.utils.GenericJDBCUtilities.setFields(sqlQueryObject,expression,functionField);
  205.         try{
  206.             List<Map<String,Object>> list = _select(jdbcProperties, log, connection, sqlQueryObject, expression);
  207.             return list.get(0);
  208.         }finally{
  209.             org.openspcoop2.generic_project.dao.jdbc.utils.GenericJDBCUtilities.removeFields(sqlQueryObject,expression,functionField);
  210.         }
  211.     }

  212.     @Override
  213.     public List<Map<String,Object>> groupBy(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject,
  214.                                                     JDBCExpression expression, FunctionField ... functionField) throws ServiceException,NotFoundException,NotImplementedException,Exception {
  215.        
  216.         if(expression.getGroupByFields().size()<=0){
  217.             throw new ServiceException("GroupBy conditions not found in expression");
  218.         }
  219.        
  220.         org.openspcoop2.generic_project.dao.jdbc.utils.GenericJDBCUtilities.setFields(sqlQueryObject,expression,functionField);
  221.         try{
  222.             return _select(jdbcProperties, log, connection, sqlQueryObject, expression);
  223.         }finally{
  224.             org.openspcoop2.generic_project.dao.jdbc.utils.GenericJDBCUtilities.removeFields(sqlQueryObject,expression,functionField);
  225.         }
  226.     }
  227.    

  228.     @Override
  229.     public List<Map<String,Object>> groupBy(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject,
  230.                                                     JDBCPaginatedExpression paginatedExpression, FunctionField ... functionField) throws ServiceException,NotFoundException,NotImplementedException,Exception {
  231.        
  232.         if(paginatedExpression.getGroupByFields().size()<=0){
  233.             throw new ServiceException("GroupBy conditions not found in expression");
  234.         }
  235.        
  236.         org.openspcoop2.generic_project.dao.jdbc.utils.GenericJDBCUtilities.setFields(sqlQueryObject,paginatedExpression,functionField);
  237.         try{
  238.             return _select(jdbcProperties, log, connection, sqlQueryObject, paginatedExpression);
  239.         }finally{
  240.             org.openspcoop2.generic_project.dao.jdbc.utils.GenericJDBCUtilities.removeFields(sqlQueryObject,paginatedExpression,functionField);
  241.         }
  242.     }
  243.    
  244.     protected List<Map<String,Object>> _select(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject,
  245.                                                 IExpression expression) throws ServiceException,NotFoundException,NotImplementedException,Exception {
  246.         return _select(jdbcProperties, log, connection, sqlQueryObject, expression, null);
  247.     }
  248.     protected List<Map<String,Object>> _select(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject,
  249.                                                 IExpression expression, ISQLQueryObject sqlQueryObjectDistinct) throws ServiceException,NotFoundException,NotImplementedException,Exception {
  250.        
  251.         List<Object> listaQuery = new ArrayList<Object>();
  252.         List<JDBCObject> listaParams = new ArrayList<JDBCObject>();
  253.         List<Object> returnField = org.openspcoop2.generic_project.dao.jdbc.utils.GenericJDBCUtilities.prepareSelect(jdbcProperties, log, connection, sqlQueryObject,
  254.                                 expression, this.getStatistichePdndTracingFieldConverter(), StatistichePdndTracing.model(),
  255.                                 listaQuery,listaParams);
  256.        
  257.         _join(expression,sqlQueryObject);
  258.        
  259.         List<Map<String,Object>> list = org.openspcoop2.generic_project.dao.jdbc.utils.GenericJDBCUtilities.select(jdbcProperties, log, connection,
  260.                                         org.openspcoop2.generic_project.dao.jdbc.utils.GenericJDBCUtilities.prepareSqlQueryObjectForSelectDistinct(sqlQueryObject,sqlQueryObjectDistinct),
  261.                                         expression, this.getStatistichePdndTracingFieldConverter(), StatistichePdndTracing.model(),
  262.                                         listaQuery,listaParams,returnField);
  263.         if(list!=null && list.size()>0){
  264.             return list;
  265.         }
  266.         else{
  267.             throw new NotFoundException("Not Found");
  268.         }
  269.     }
  270.    
  271.     @Override
  272.     public List<Map<String,Object>> union(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject,
  273.                                                 Union union, UnionExpression ... unionExpression) throws ServiceException,NotFoundException,NotImplementedException,Exception {    
  274.        
  275.         List<ISQLQueryObject> sqlQueryObjectInnerList = new ArrayList<ISQLQueryObject>();
  276.         List<JDBCObject> jdbcObjects = new ArrayList<JDBCObject>();
  277.         List<Class<?>> returnClassTypes = org.openspcoop2.generic_project.dao.jdbc.utils.GenericJDBCUtilities.prepareUnion(jdbcProperties, log, connection, sqlQueryObject,
  278.                                 this.getStatistichePdndTracingFieldConverter(), StatistichePdndTracing.model(),
  279.                                 sqlQueryObjectInnerList, jdbcObjects, union, unionExpression);
  280.        
  281.         if(unionExpression!=null){
  282.             for (int i = 0; i < unionExpression.length; i++) {
  283.                 UnionExpression ue = unionExpression[i];
  284.                 IExpression expression = ue.getExpression();
  285.                 _join(expression,sqlQueryObjectInnerList.get(i));
  286.             }
  287.         }
  288.        
  289.         List<Map<String,Object>> list = org.openspcoop2.generic_project.dao.jdbc.utils.GenericJDBCUtilities.union(jdbcProperties, log, connection, sqlQueryObject,
  290.                                         this.getStatistichePdndTracingFieldConverter(), StatistichePdndTracing.model(),
  291.                                         sqlQueryObjectInnerList, jdbcObjects, returnClassTypes, union, unionExpression);
  292.         if(list!=null && list.size()>0){
  293.             return list;
  294.         }
  295.         else{
  296.             throw new NotFoundException("Not Found");
  297.         }                              
  298.     }
  299.    
  300.     @Override
  301.     public NonNegativeNumber unionCount(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject,
  302.                                                 Union union, UnionExpression ... unionExpression) throws ServiceException,NotFoundException,NotImplementedException,Exception {    
  303.        
  304.         List<ISQLQueryObject> sqlQueryObjectInnerList = new ArrayList<ISQLQueryObject>();
  305.         List<JDBCObject> jdbcObjects = new ArrayList<JDBCObject>();
  306.         List<Class<?>> returnClassTypes = org.openspcoop2.generic_project.dao.jdbc.utils.GenericJDBCUtilities.prepareUnionCount(jdbcProperties, log, connection, sqlQueryObject,
  307.                                 this.getStatistichePdndTracingFieldConverter(), StatistichePdndTracing.model(),
  308.                                 sqlQueryObjectInnerList, jdbcObjects, union, unionExpression);
  309.        
  310.         if(unionExpression!=null){
  311.             for (int i = 0; i < unionExpression.length; i++) {
  312.                 UnionExpression ue = unionExpression[i];
  313.                 IExpression expression = ue.getExpression();
  314.                 _join(expression,sqlQueryObjectInnerList.get(i));
  315.             }
  316.         }
  317.        
  318.         NonNegativeNumber number = org.openspcoop2.generic_project.dao.jdbc.utils.GenericJDBCUtilities.unionCount(jdbcProperties, log, connection, sqlQueryObject,
  319.                                         this.getStatistichePdndTracingFieldConverter(), StatistichePdndTracing.model(),
  320.                                         sqlQueryObjectInnerList, jdbcObjects, returnClassTypes, union, unionExpression);
  321.         if(number!=null && number.longValue()>=0){
  322.             return number;
  323.         }
  324.         else{
  325.             throw new NotFoundException("Not Found");
  326.         }
  327.     }



  328.     // -- ConstructorExpression

  329.     @Override
  330.     public JDBCExpression newExpression(Logger log) throws NotImplementedException, ServiceException {
  331.         try{
  332.             return new JDBCExpression(this.getStatistichePdndTracingFieldConverter());
  333.         }catch(Exception e){
  334.             throw new ServiceException(e);
  335.         }
  336.     }


  337.     @Override
  338.     public JDBCPaginatedExpression newPaginatedExpression(Logger log) throws NotImplementedException, ServiceException {
  339.         try{
  340.             return new JDBCPaginatedExpression(this.getStatistichePdndTracingFieldConverter());
  341.         }catch(Exception e){
  342.             throw new ServiceException(e);
  343.         }
  344.     }
  345.    
  346.     @Override
  347.     public JDBCExpression toExpression(JDBCPaginatedExpression paginatedExpression, Logger log) throws NotImplementedException, ServiceException {
  348.         try{
  349.             return new JDBCExpression(paginatedExpression);
  350.         }catch(Exception e){
  351.             throw new ServiceException(e);
  352.         }
  353.     }

  354.     @Override
  355.     public JDBCPaginatedExpression toPaginatedExpression(JDBCExpression expression, Logger log) throws NotImplementedException, ServiceException {
  356.         try{
  357.             return new JDBCPaginatedExpression(expression);
  358.         }catch(Exception e){
  359.             throw new ServiceException(e);
  360.         }
  361.     }
  362.    
  363.    
  364.    
  365.     // -- DB

  366.    
  367.     @Override
  368.     public StatistichePdndTracing get(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject, long tableId, org.openspcoop2.generic_project.beans.IDMappingBehaviour idMappingResolutionBehaviour) throws NotFoundException, MultipleResultException, NotImplementedException, ServiceException, Exception {
  369.         return this._get(jdbcProperties, log, connection, sqlQueryObject, Long.valueOf(tableId), idMappingResolutionBehaviour);
  370.     }
  371.    
  372.     private StatistichePdndTracing _get(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject, Long tableId, org.openspcoop2.generic_project.beans.IDMappingBehaviour idMappingResolutionBehaviour) throws NotFoundException, MultipleResultException, NotImplementedException, ServiceException, Exception {
  373.    
  374.         org.openspcoop2.generic_project.dao.jdbc.utils.JDBCPreparedStatementUtilities jdbcUtilities =
  375.                     new org.openspcoop2.generic_project.dao.jdbc.utils.JDBCPreparedStatementUtilities(sqlQueryObject.getTipoDatabaseOpenSPCoop2(), log, connection);
  376.        
  377.         ISQLQueryObject sqlQueryObjectGet = sqlQueryObject.newSQLQueryObject();
  378.                
  379.         StatistichePdndTracing statistichePdndTracing = new StatistichePdndTracing();
  380.        

  381.         // Object statistichePdndTracing
  382.         sqlQueryObjectGet.setANDLogicOperator(true);
  383.         sqlQueryObjectGet.addFromTable(this.getStatistichePdndTracingFieldConverter().toTable(StatistichePdndTracing.model()));
  384.         sqlQueryObjectGet.addSelectField("id");
  385.         sqlQueryObjectGet.addSelectField(this.getStatistichePdndTracingFieldConverter().toColumn(StatistichePdndTracing.model().DATA_TRACCIAMENTO,true));
  386.         sqlQueryObjectGet.addSelectField(this.getStatistichePdndTracingFieldConverter().toColumn(StatistichePdndTracing.model().DATA_REGISTRAZIONE,true));
  387.         sqlQueryObjectGet.addSelectField(this.getStatistichePdndTracingFieldConverter().toColumn(StatistichePdndTracing.model().DATA_PUBBLICAZIONE,true));
  388.         sqlQueryObjectGet.addSelectField(this.getStatistichePdndTracingFieldConverter().toColumn(StatistichePdndTracing.model().PDD_CODICE,true));
  389.         sqlQueryObjectGet.addSelectField(this.getStatistichePdndTracingFieldConverter().toColumn(StatistichePdndTracing.model().CSV,true));
  390.         sqlQueryObjectGet.addSelectField(this.getStatistichePdndTracingFieldConverter().toColumn(StatistichePdndTracing.model().METHOD,true));
  391.         sqlQueryObjectGet.addSelectField(this.getStatistichePdndTracingFieldConverter().toColumn(StatistichePdndTracing.model().STATO_PDND,true));
  392.         sqlQueryObjectGet.addSelectField(this.getStatistichePdndTracingFieldConverter().toColumn(StatistichePdndTracing.model().TENTATIVI_PUBBLICAZIONE,true));
  393.         sqlQueryObjectGet.addSelectField(this.getStatistichePdndTracingFieldConverter().toColumn(StatistichePdndTracing.model().FORCE_PUBLISH,true));
  394.         sqlQueryObjectGet.addSelectField(this.getStatistichePdndTracingFieldConverter().toColumn(StatistichePdndTracing.model().STATO,true));
  395.         sqlQueryObjectGet.addSelectField(this.getStatistichePdndTracingFieldConverter().toColumn(StatistichePdndTracing.model().TRACING_ID,true));
  396.         sqlQueryObjectGet.addSelectField(this.getStatistichePdndTracingFieldConverter().toColumn(StatistichePdndTracing.model().ERROR_DETAILS,true));
  397.         sqlQueryObjectGet.addSelectField(this.getStatistichePdndTracingFieldConverter().toColumn(StatistichePdndTracing.model().HISTORY,true));
  398.         sqlQueryObjectGet.addWhereCondition("id=?");

  399.         // Get statistichePdndTracing
  400.         statistichePdndTracing = (StatistichePdndTracing) jdbcUtilities.executeQuerySingleResult(sqlQueryObjectGet.createSQLQuery(), jdbcProperties.isShowSql(), StatistichePdndTracing.model(), this.getStatistichePdndTracingFetch(),
  401.             new JDBCObject(tableId,Long.class));



  402.        
  403.         return statistichePdndTracing;  
  404.    
  405.     }
  406.    
  407.     @Override
  408.     public boolean exists(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject, long tableId) throws MultipleResultException, NotImplementedException, ServiceException, Exception {
  409.         return this._exists(jdbcProperties, log, connection, sqlQueryObject, Long.valueOf(tableId));
  410.     }
  411.    
  412.     private boolean _exists(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject, Long tableId) throws MultipleResultException, NotImplementedException, ServiceException, Exception {
  413.    
  414.         org.openspcoop2.generic_project.dao.jdbc.utils.JDBCPreparedStatementUtilities jdbcUtilities =
  415.                     new org.openspcoop2.generic_project.dao.jdbc.utils.JDBCPreparedStatementUtilities(sqlQueryObject.getTipoDatabaseOpenSPCoop2(), log, connection);
  416.                
  417.         boolean existsStatistichePdndTracing = false;

  418.         sqlQueryObject = sqlQueryObject.newSQLQueryObject();
  419.         sqlQueryObject.setANDLogicOperator(true);

  420.         sqlQueryObject.addFromTable(this.getStatistichePdndTracingFieldConverter().toTable(StatistichePdndTracing.model()));
  421.         sqlQueryObject.addSelectField(this.getStatistichePdndTracingFieldConverter().toColumn(StatistichePdndTracing.model().DATA_TRACCIAMENTO,true));
  422.         sqlQueryObject.addWhereCondition("id=?");


  423.         // Exists statistichePdndTracing
  424.         existsStatistichePdndTracing = jdbcUtilities.exists(sqlQueryObject.createSQLQuery(), jdbcProperties.isShowSql(),
  425.             new JDBCObject(tableId,Long.class));

  426.        
  427.         return existsStatistichePdndTracing;
  428.    
  429.     }
  430.    
  431.     private void _join(IExpression expression, ISQLQueryObject sqlQueryObject) throws NotImplementedException, ServiceException, Exception{
  432.         // ignore no join operation
  433.     }
  434.    
  435.     protected java.util.List<Object> _getRootTablePrimaryKeyValues(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject, StatistichePdndTracing statistichePdndTracing) throws NotFoundException, ServiceException, NotImplementedException, Exception{
  436.         // Identificativi
  437.         java.util.List<Object> rootTableIdValues = new java.util.ArrayList<Object>();
  438.         rootTableIdValues.add(statistichePdndTracing.getId());

  439.         return rootTableIdValues;
  440.     }
  441.    
  442.     protected Map<String, List<IField>> _getMapTableToPKColumn() throws NotImplementedException, Exception{
  443.    
  444.         StatistichePdndTracingFieldConverter converter = this.getStatistichePdndTracingFieldConverter();
  445.         Map<String, List<IField>> mapTableToPKColumn = new java.util.HashMap<String, List<IField>>();
  446.         UtilsTemplate<IField> utilities = new UtilsTemplate<IField>();
  447.        
  448.         // StatistichePdndTracing.model()
  449.         mapTableToPKColumn.put(converter.toTable(StatistichePdndTracing.model()),
  450.             utilities.newList(
  451.                 new CustomField("id", Long.class, "id", converter.toTable(StatistichePdndTracing.model()))
  452.             ));
  453.        
  454.         return mapTableToPKColumn;      
  455.     }
  456.    
  457.     @Override
  458.     public List<Long> findAllTableIds(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject, JDBCPaginatedExpression paginatedExpression) throws ServiceException, NotImplementedException, Exception {
  459.        
  460.         List<Long> list = new ArrayList<>();

  461.         sqlQueryObject.setSelectDistinct(true);
  462.         sqlQueryObject.setANDLogicOperator(true);
  463.         sqlQueryObject.addSelectField(this.getStatistichePdndTracingFieldConverter().toTable(StatistichePdndTracing.model())+".id");
  464.         Class<?> objectIdClass = Long.class;
  465.        
  466.         List<Object> listaQuery = org.openspcoop2.generic_project.dao.jdbc.utils.GenericJDBCUtilities.prepareFindAll(jdbcProperties, log, connection, sqlQueryObject, paginatedExpression,
  467.                                                 this.getStatistichePdndTracingFieldConverter(), StatistichePdndTracing.model());
  468.        
  469.         _join(paginatedExpression,sqlQueryObject);
  470.        
  471.         List<Object> listObjects = org.openspcoop2.generic_project.dao.jdbc.utils.GenericJDBCUtilities.findAll(jdbcProperties, log, connection, sqlQueryObject, paginatedExpression,
  472.                                                                             this.getStatistichePdndTracingFieldConverter(), StatistichePdndTracing.model(), objectIdClass, listaQuery);
  473.         for(Object object: listObjects) {
  474.             list.add((Long)object);
  475.         }

  476.         return list;
  477.        
  478.     }
  479.    
  480.     @Override
  481.     public long findTableId(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject, JDBCExpression expression) throws ServiceException, NotFoundException, MultipleResultException, NotImplementedException, Exception {
  482.    
  483.         sqlQueryObject.setSelectDistinct(true);
  484.         sqlQueryObject.setANDLogicOperator(true);
  485.         sqlQueryObject.addSelectField(this.getStatistichePdndTracingFieldConverter().toTable(StatistichePdndTracing.model())+".id");
  486.         Class<?> objectIdClass = Long.class;
  487.        
  488.         List<Object> listaQuery = org.openspcoop2.generic_project.dao.jdbc.utils.GenericJDBCUtilities.prepareFind(jdbcProperties, log, connection, sqlQueryObject, expression,
  489.                                                 this.getStatistichePdndTracingFieldConverter(), StatistichePdndTracing.model());
  490.        
  491.         _join(expression,sqlQueryObject);

  492.         Object res = org.openspcoop2.generic_project.dao.jdbc.utils.GenericJDBCUtilities.find(jdbcProperties, log, connection, sqlQueryObject, expression,
  493.                                                         this.getStatistichePdndTracingFieldConverter(), StatistichePdndTracing.model(), objectIdClass, listaQuery);
  494.         if(res!=null && (((Long) res).longValue()>0) ){
  495.             return ((Long) res).longValue();
  496.         }
  497.         else{
  498.             throw new NotFoundException("Not Found");
  499.         }
  500.        
  501.     }

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

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

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

  520.         return inUse;

  521.     }
  522.    

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