JDBCTransazioneExportServiceSearchImpl.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.transazioni.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.transazioni.dao.jdbc.converter.TransazioneExportFieldConverter;
  48. import org.openspcoop2.core.transazioni.dao.jdbc.fetch.TransazioneExportFetch;
  49. import org.openspcoop2.core.transazioni.TransazioneExport;

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

  58.     private TransazioneExportFieldConverter _transazioneExportFieldConverter = null;
  59.     public TransazioneExportFieldConverter getTransazioneExportFieldConverter() {
  60.         if(this._transazioneExportFieldConverter==null){
  61.             this._transazioneExportFieldConverter = new TransazioneExportFieldConverter(this.jdbcServiceManager.getJdbcProperties().getDatabaseType());
  62.         }      
  63.         return this._transazioneExportFieldConverter;
  64.     }
  65.     @Override
  66.     public ISQLFieldConverter getFieldConverter() {
  67.         return this.getTransazioneExportFieldConverter();
  68.     }
  69.    
  70.     private TransazioneExportFetch transazioneExportFetch = new TransazioneExportFetch();
  71.     public TransazioneExportFetch getTransazioneExportFetch() {
  72.         return this.transazioneExportFetch;
  73.     }
  74.     @Override
  75.     public IJDBCFetch getFetch() {
  76.         return getTransazioneExportFetch();
  77.     }
  78.    
  79.    
  80.     private JDBCServiceManager jdbcServiceManager = null;

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

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

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

  104.         List<Long> ids = this.findAllTableIds(jdbcProperties, log, connection, sqlQueryObject, expression);
  105.        
  106.         for(Long id: ids) {
  107.             list.add(this.get(jdbcProperties, log, connection, sqlQueryObject, id, idMappingResolutionBehaviour));
  108.         }

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

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


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

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

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

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

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



  312.     // -- ConstructorExpression

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


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

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

  350.    
  351.     @Override
  352.     public TransazioneExport get(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject, long tableId, org.openspcoop2.generic_project.beans.IDMappingBehaviour idMappingResolutionBehaviour) throws NotFoundException, MultipleResultException, NotImplementedException, ServiceException, Exception {
  353.         return this.getEngine(jdbcProperties, log, connection, sqlQueryObject, Long.valueOf(tableId), idMappingResolutionBehaviour);
  354.     }
  355.    
  356.     private TransazioneExport getEngine(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject, Long tableId, org.openspcoop2.generic_project.beans.IDMappingBehaviour idMappingResolutionBehaviour) throws NotFoundException, MultipleResultException, NotImplementedException, ServiceException, Exception {
  357.    
  358.         org.openspcoop2.generic_project.dao.jdbc.utils.JDBCPreparedStatementUtilities jdbcUtilities =
  359.                     new org.openspcoop2.generic_project.dao.jdbc.utils.JDBCPreparedStatementUtilities(sqlQueryObject.getTipoDatabaseOpenSPCoop2(), log, connection);
  360.        
  361.         ISQLQueryObject sqlQueryObjectGet = sqlQueryObject.newSQLQueryObject();
  362.                
  363.         TransazioneExport transazioneExport = new TransazioneExport();
  364.        

  365.         // Object transazioneExport
  366.         ISQLQueryObject sqlQueryObjectGet_transazioneExport = sqlQueryObjectGet.newSQLQueryObject();
  367.         sqlQueryObjectGet_transazioneExport.setANDLogicOperator(true);
  368.         sqlQueryObjectGet_transazioneExport.addFromTable(this.getTransazioneExportFieldConverter().toTable(TransazioneExport.model()));
  369.         sqlQueryObjectGet_transazioneExport.addSelectField("id");
  370.         sqlQueryObjectGet_transazioneExport.addSelectField(this.getTransazioneExportFieldConverter().toColumn(TransazioneExport.model().INTERVALLO_INIZIO,true));
  371.         sqlQueryObjectGet_transazioneExport.addSelectField(this.getTransazioneExportFieldConverter().toColumn(TransazioneExport.model().INTERVALLO_FINE,true));
  372.         sqlQueryObjectGet_transazioneExport.addSelectField(this.getTransazioneExportFieldConverter().toColumn(TransazioneExport.model().NOME,true));
  373.         sqlQueryObjectGet_transazioneExport.addSelectField(this.getTransazioneExportFieldConverter().toColumn(TransazioneExport.model().EXPORT_STATE,true));
  374.         sqlQueryObjectGet_transazioneExport.addSelectField(this.getTransazioneExportFieldConverter().toColumn(TransazioneExport.model().EXPORT_ERROR,true));
  375.         sqlQueryObjectGet_transazioneExport.addSelectField(this.getTransazioneExportFieldConverter().toColumn(TransazioneExport.model().EXPORT_TIME_START,true));
  376.         sqlQueryObjectGet_transazioneExport.addSelectField(this.getTransazioneExportFieldConverter().toColumn(TransazioneExport.model().EXPORT_TIME_END,true));
  377.         sqlQueryObjectGet_transazioneExport.addSelectField(this.getTransazioneExportFieldConverter().toColumn(TransazioneExport.model().DELETE_STATE,true));
  378.         sqlQueryObjectGet_transazioneExport.addSelectField(this.getTransazioneExportFieldConverter().toColumn(TransazioneExport.model().DELETE_ERROR,true));
  379.         sqlQueryObjectGet_transazioneExport.addSelectField(this.getTransazioneExportFieldConverter().toColumn(TransazioneExport.model().DELETE_TIME_START,true));
  380.         sqlQueryObjectGet_transazioneExport.addSelectField(this.getTransazioneExportFieldConverter().toColumn(TransazioneExport.model().DELETE_TIME_END,true));
  381.         sqlQueryObjectGet_transazioneExport.addWhereCondition("id=?");

  382.         // Get transazioneExport
  383.         transazioneExport = (TransazioneExport) jdbcUtilities.executeQuerySingleResult(sqlQueryObjectGet_transazioneExport.createSQLQuery(), jdbcProperties.isShowSql(), TransazioneExport.model(), this.getTransazioneExportFetch(),
  384.             new JDBCObject(tableId,Long.class));



  385.        
  386.         return transazioneExport;  
  387.    
  388.     }
  389.    
  390.     @Override
  391.     public boolean exists(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject, long tableId) throws MultipleResultException, NotImplementedException, ServiceException, Exception {
  392.         return this._exists(jdbcProperties, log, connection, sqlQueryObject, Long.valueOf(tableId));
  393.     }
  394.    
  395.     private boolean _exists(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject, Long tableId) throws MultipleResultException, NotImplementedException, ServiceException, Exception {
  396.    
  397.         org.openspcoop2.generic_project.dao.jdbc.utils.JDBCPreparedStatementUtilities jdbcUtilities =
  398.                     new org.openspcoop2.generic_project.dao.jdbc.utils.JDBCPreparedStatementUtilities(sqlQueryObject.getTipoDatabaseOpenSPCoop2(), log, connection);
  399.                
  400.         boolean existsTransazioneExport = false;

  401.         sqlQueryObject = sqlQueryObject.newSQLQueryObject();
  402.         sqlQueryObject.setANDLogicOperator(true);

  403.         sqlQueryObject.addFromTable(this.getTransazioneExportFieldConverter().toTable(TransazioneExport.model()));
  404.         sqlQueryObject.addSelectField(this.getTransazioneExportFieldConverter().toColumn(TransazioneExport.model().INTERVALLO_INIZIO,true));
  405.         sqlQueryObject.addWhereCondition("id=?");


  406.         // Exists transazioneExport
  407.         existsTransazioneExport = jdbcUtilities.exists(sqlQueryObject.createSQLQuery(), jdbcProperties.isShowSql(),
  408.             new JDBCObject(tableId,Long.class));

  409.        
  410.         return existsTransazioneExport;
  411.    
  412.     }
  413.    
  414.     private void joinEngine(IExpression expression, ISQLQueryObject sqlQueryObject) throws NotImplementedException, ServiceException, Exception{
  415.    
  416.         // nop;
  417.        
  418.     }
  419.    
  420.     protected java.util.List<Object> getRootTablePrimaryKeyValuesEngine(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject, TransazioneExport transazioneExport) throws NotFoundException, ServiceException, NotImplementedException, Exception{
  421.         // Identificativi
  422.         java.util.List<Object> rootTableIdValues = new java.util.ArrayList<>();
  423.         rootTableIdValues.add(transazioneExport.getId());
  424.         return rootTableIdValues;
  425.     }
  426.    
  427.     protected Map<String, List<IField>> getMapTableToPKColumnEngine() throws NotImplementedException, Exception{
  428.    
  429.         TransazioneExportFieldConverter converter = this.getTransazioneExportFieldConverter();
  430.         Map<String, List<IField>> mapTableToPKColumn = new java.util.HashMap<>();
  431.         UtilsTemplate<IField> utilities = new UtilsTemplate<>();

  432.         // TransazioneExport.model()
  433.         mapTableToPKColumn.put(converter.toTable(TransazioneExport.model()),
  434.             utilities.newList(
  435.                 new CustomField("id", Long.class, "id", converter.toTable(TransazioneExport.model()))
  436.             ));
  437.        
  438.         return mapTableToPKColumn;      
  439.     }
  440.    
  441.     @Override
  442.     public List<Long> findAllTableIds(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject, JDBCPaginatedExpression paginatedExpression) throws ServiceException, NotImplementedException, Exception {
  443.        
  444.         List<Long> list = new ArrayList<Long>();

  445.         sqlQueryObject.setSelectDistinct(true);
  446.         sqlQueryObject.setANDLogicOperator(true);
  447.         sqlQueryObject.addSelectField(this.getTransazioneExportFieldConverter().toTable(TransazioneExport.model())+".id");
  448.         Class<?> objectIdClass = Long.class;
  449.        
  450.         List<Object> listaQuery = org.openspcoop2.generic_project.dao.jdbc.utils.GenericJDBCUtilities.prepareFindAll(jdbcProperties, log, connection, sqlQueryObject, paginatedExpression,
  451.                                                 this.getTransazioneExportFieldConverter(), TransazioneExport.model());
  452.        
  453.         joinEngine(paginatedExpression,sqlQueryObject);
  454.        
  455.         List<Object> listObjects = org.openspcoop2.generic_project.dao.jdbc.utils.GenericJDBCUtilities.findAll(jdbcProperties, log, connection, sqlQueryObject, paginatedExpression,
  456.                                                                             this.getTransazioneExportFieldConverter(), TransazioneExport.model(), objectIdClass, listaQuery);
  457.         for(Object object: listObjects) {
  458.             list.add((Long)object);
  459.         }

  460.         return list;
  461.        
  462.     }
  463.    
  464.     @Override
  465.     public long findTableId(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject, JDBCExpression expression) throws ServiceException, NotFoundException, MultipleResultException, NotImplementedException, Exception {
  466.    
  467.         sqlQueryObject.setSelectDistinct(true);
  468.         sqlQueryObject.setANDLogicOperator(true);
  469.         sqlQueryObject.addSelectField(this.getTransazioneExportFieldConverter().toTable(TransazioneExport.model())+".id");
  470.         Class<?> objectIdClass = Long.class;
  471.        
  472.         List<Object> listaQuery = org.openspcoop2.generic_project.dao.jdbc.utils.GenericJDBCUtilities.prepareFind(jdbcProperties, log, connection, sqlQueryObject, expression,
  473.                                                 this.getTransazioneExportFieldConverter(), TransazioneExport.model());
  474.        
  475.         joinEngine(expression,sqlQueryObject);

  476.         Object res = org.openspcoop2.generic_project.dao.jdbc.utils.GenericJDBCUtilities.find(jdbcProperties, log, connection, sqlQueryObject, expression,
  477.                                                         this.getTransazioneExportFieldConverter(), TransazioneExport.model(), objectIdClass, listaQuery);
  478.         if(res!=null && (((Long) res).longValue()>0) ){
  479.             return ((Long) res).longValue();
  480.         }
  481.         else{
  482.             throw org.openspcoop2.generic_project.dao.jdbc.utils.GenericJDBCUtilities.newNotFoundException();
  483.         }
  484.        
  485.     }

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

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

  491.         InUse inUse = new InUse();
  492.         inUse.setInUse(false);
  493.        
  494.         /*
  495.          * TODO: implement code that checks whether the object identified by the id parameter is used by other objects
  496.         */
  497.        
  498.         // Delete this line when you have implemented the method
  499.         int throwNotImplemented = 1;
  500.         if(throwNotImplemented==1){
  501.                 throw new NotImplementedException("NotImplemented");
  502.         }
  503.         // Delete this line when you have implemented the method

  504.         return inUse;

  505.     }
  506.    

  507.    
  508.     @Override
  509.     public List<List<Object>> nativeQuery(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject,
  510.                                             String sql,List<Class<?>> returnClassTypes,Object ... param) throws ServiceException,NotFoundException,NotImplementedException,Exception{
  511.        
  512.         return org.openspcoop2.generic_project.dao.jdbc.utils.GenericJDBCUtilities.nativeQuery(jdbcProperties, log, connection, sqlQueryObject,
  513.                                                                                             sql,returnClassTypes,param);
  514.                                                        
  515.     }
  516.    
  517. }