JDBCTransazioneApplicativoServerServiceSearchImpl.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.sql.Connection;
  22. import java.util.ArrayList;
  23. import java.util.List;
  24. import java.util.Map;

  25. import org.openspcoop2.core.transazioni.IdTransazioneApplicativoServer;
  26. import org.openspcoop2.core.transazioni.TransazioneApplicativoServer;
  27. import org.openspcoop2.core.transazioni.dao.jdbc.converter.TransazioneApplicativoServerFieldConverter;
  28. import org.openspcoop2.core.transazioni.dao.jdbc.fetch.TransazioneApplicativoServerFetch;
  29. import org.openspcoop2.generic_project.beans.CustomField;
  30. import org.openspcoop2.generic_project.beans.FunctionField;
  31. import org.openspcoop2.generic_project.beans.IField;
  32. import org.openspcoop2.generic_project.beans.InUse;
  33. import org.openspcoop2.generic_project.beans.NonNegativeNumber;
  34. import org.openspcoop2.generic_project.beans.Union;
  35. import org.openspcoop2.generic_project.beans.UnionExpression;
  36. import org.openspcoop2.generic_project.dao.jdbc.IJDBCServiceSearchWithId;
  37. import org.openspcoop2.generic_project.dao.jdbc.JDBCExpression;
  38. import org.openspcoop2.generic_project.dao.jdbc.JDBCPaginatedExpression;
  39. import org.openspcoop2.generic_project.dao.jdbc.JDBCServiceManagerProperties;
  40. import org.openspcoop2.generic_project.dao.jdbc.utils.IJDBCFetch;
  41. import org.openspcoop2.generic_project.dao.jdbc.utils.JDBCObject;
  42. import org.openspcoop2.generic_project.exception.MultipleResultException;
  43. import org.openspcoop2.generic_project.exception.NotFoundException;
  44. import org.openspcoop2.generic_project.exception.NotImplementedException;
  45. import org.openspcoop2.generic_project.exception.ServiceException;
  46. import org.openspcoop2.generic_project.expression.IExpression;
  47. import org.openspcoop2.generic_project.expression.impl.sql.ISQLFieldConverter;
  48. import org.openspcoop2.generic_project.utils.UtilsTemplate;
  49. import org.openspcoop2.utils.sql.ISQLQueryObject;
  50. import org.openspcoop2.utils.sql.SQLQueryObjectCore;
  51. import org.slf4j.Logger;

  52. /**    
  53.  * JDBCTransazioneApplicativoServerServiceSearchImpl
  54.  *
  55.  * @author Poli Andrea (poli@link.it)
  56.  * @author $Author$
  57.  * @version $Rev$, $Date$
  58.  */
  59. public class JDBCTransazioneApplicativoServerServiceSearchImpl implements IJDBCServiceSearchWithId<TransazioneApplicativoServer, IdTransazioneApplicativoServer, JDBCServiceManager> {

  60.     private TransazioneApplicativoServerFieldConverter _transazioneApplicativoServerFieldConverter = null;
  61.     public TransazioneApplicativoServerFieldConverter getTransazioneApplicativoServerFieldConverter() {
  62.         if(this._transazioneApplicativoServerFieldConverter==null){
  63.             this._transazioneApplicativoServerFieldConverter = new TransazioneApplicativoServerFieldConverter(this.jdbcServiceManager.getJdbcProperties().getDatabaseType());
  64.         }      
  65.         return this._transazioneApplicativoServerFieldConverter;
  66.     }
  67.     @Override
  68.     public ISQLFieldConverter getFieldConverter() {
  69.         return this.getTransazioneApplicativoServerFieldConverter();
  70.     }
  71.    
  72.     private TransazioneApplicativoServerFetch transazioneApplicativoServerFetch = new TransazioneApplicativoServerFetch();
  73.     public TransazioneApplicativoServerFetch getTransazioneApplicativoServerFetch() {
  74.         return this.transazioneApplicativoServerFetch;
  75.     }
  76.     @Override
  77.     public IJDBCFetch getFetch() {
  78.         return getTransazioneApplicativoServerFetch();
  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.     @Override
  94.     public IdTransazioneApplicativoServer convertToId(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject, TransazioneApplicativoServer transazioneApplicativoServer) throws NotImplementedException, ServiceException, Exception{
  95.    
  96.         IdTransazioneApplicativoServer idTransazioneApplicativoServer = new IdTransazioneApplicativoServer();
  97.         idTransazioneApplicativoServer.setIdTransazione(transazioneApplicativoServer.getIdTransazione());
  98.         idTransazioneApplicativoServer.setServizioApplicativoErogatore(transazioneApplicativoServer.getServizioApplicativoErogatore());
  99.         return idTransazioneApplicativoServer;
  100.     }
  101.    
  102.     private static boolean efficiente = true;
  103.     public static boolean isEfficiente() {
  104.         return efficiente;
  105.     }
  106.     public static void setEfficiente(boolean efficiente) {
  107.         JDBCTransazioneApplicativoServerServiceSearchImpl.efficiente = efficiente;
  108.     }
  109.     @Override
  110.     public TransazioneApplicativoServer get(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject, IdTransazioneApplicativoServer id, org.openspcoop2.generic_project.beans.IDMappingBehaviour idMappingResolutionBehaviour) throws NotFoundException, MultipleResultException, NotImplementedException, ServiceException,Exception {
  111.        
  112.         long id_long = (id!=null && id.getId()!=null && id.getId()>0) ? id.getId() : -1;
  113.        
  114.         if(id_long<=0 && efficiente){
  115.        
  116.             if(id==null) {
  117.                 throw new ServiceException("Id non definito");
  118.             }
  119.             if(id.getIdTransazione()==null) {
  120.                 throw new ServiceException("IdTransazione non definito");
  121.             }
  122.             if(id.getServizioApplicativoErogatore()==null) {
  123.                 throw new ServiceException("IdServizioApplicativoErogatore non definito");
  124.             }
  125.            
  126.             JDBCPaginatedExpression pagExpr = this.newPaginatedExpression(log);
  127.             pagExpr.equals(TransazioneApplicativoServer.model().ID_TRANSAZIONE, id.getIdTransazione());
  128.             pagExpr.and();
  129.             pagExpr.equals(TransazioneApplicativoServer.model().SERVIZIO_APPLICATIVO_EROGATORE, id.getServizioApplicativoErogatore());
  130.             //pagExpr.limit(2); Inefficiente, per implementare il multipleresult che poi non può succedere
  131.             if(sqlQueryObject==null || !(sqlQueryObject instanceof SQLQueryObjectCore) || !((SQLQueryObjectCore)sqlQueryObject).isSelectForUpdate()) {
  132.                 pagExpr.limit(1);
  133.                 // essendoci lo unique comunque il limit serve a poco, e nello stesso tempo la select for update non lo vuole
  134.             }
  135.                        
  136.             List<TransazioneApplicativoServer> list = findAll(jdbcProperties, log, connection, sqlQueryObject, pagExpr, idMappingResolutionBehaviour);
  137.            
  138.             if(list==null || list.size()<1) {
  139.                 throw new NotFoundException();
  140.             }
  141.             // C'è lo unique sulle due colonne
  142. //          else if(list.size()>1) {
  143. //              throw new MultipleResultException();
  144. //          }
  145.             else {
  146.                 return list.get(0);
  147.             }
  148.            
  149.         }
  150.         else {
  151.        
  152.             Long id_transazioneApplicativoServer = ( (id!=null && id.getId()!=null && id.getId()>0) ? id.getId() : this.findIdTransazioneApplicativoServer(jdbcProperties, log, connection, sqlQueryObject, id, true));
  153.             return this.getEngine(jdbcProperties, log, connection, sqlQueryObject, id_transazioneApplicativoServer,idMappingResolutionBehaviour);
  154.        
  155.         }
  156.     }
  157.    
  158.     @Override
  159.     public boolean exists(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject, IdTransazioneApplicativoServer id) throws MultipleResultException, NotImplementedException, ServiceException,Exception {

  160.         Long id_transazioneApplicativoServer = this.findIdTransazioneApplicativoServer(jdbcProperties, log, connection, sqlQueryObject, id, false);
  161.         return id_transazioneApplicativoServer != null && id_transazioneApplicativoServer > 0;
  162.        
  163.     }
  164.    
  165.     @Override
  166.     public List<IdTransazioneApplicativoServer> findAllIds(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject, JDBCPaginatedExpression expression, org.openspcoop2.generic_project.beans.IDMappingBehaviour idMappingResolutionBehaviour) throws NotImplementedException, ServiceException,Exception {

  167.         List<IdTransazioneApplicativoServer> list = new ArrayList<IdTransazioneApplicativoServer>();

  168.         // TODO: implementazione non efficiente.
  169.         // Per ottenere una implementazione efficiente:
  170.         // 1. Usare metodo select di questa classe indirizzando esattamente i field necessari a create l'ID logico
  171.         // 2. Usare metodo getTransazioneApplicativoServerFetch() sul risultato della select per ottenere un oggetto TransazioneApplicativoServer
  172.         //    La fetch con la map inserirà nell'oggetto solo i valori estratti
  173.         // 3. Usare metodo convertToId per ottenere l'id

  174.         List<Long> ids = this.findAllTableIds(jdbcProperties, log, connection, sqlQueryObject, expression);
  175.        
  176.         for(Long id: ids) {
  177.             TransazioneApplicativoServer transazioneApplicativoServer = this.get(jdbcProperties, log, connection, sqlQueryObject, id, idMappingResolutionBehaviour);
  178.             IdTransazioneApplicativoServer idTransazioneApplicativoServer = this.convertToId(jdbcProperties,log,connection,sqlQueryObject,transazioneApplicativoServer);
  179.             list.add(idTransazioneApplicativoServer);
  180.         }

  181.         return list;
  182.        
  183.     }
  184.    
  185.     private static boolean distinct = false;
  186.    
  187.     public static boolean isDistinct() {
  188.         return distinct;
  189.     }
  190.     public static void setDistinct(boolean distinct) {
  191.         JDBCTransazioneApplicativoServerServiceSearchImpl.distinct = distinct;
  192.     }
  193.     @Override
  194.     public List<TransazioneApplicativoServer> findAll(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject, JDBCPaginatedExpression expression, org.openspcoop2.generic_project.beans.IDMappingBehaviour idMappingResolutionBehaviour) throws NotImplementedException, ServiceException,Exception {

  195.         List<TransazioneApplicativoServer> list = new ArrayList<TransazioneApplicativoServer>();

  196.         if(efficiente){
  197.        
  198.             List<IField> fields = new ArrayList<IField>();
  199.             fields.add(new CustomField("id", Long.class, "id", this.getTransazioneApplicativoServerFieldConverter().toTable(TransazioneApplicativoServer.model())));  
  200.             fields.add(TransazioneApplicativoServer.model().ID_TRANSAZIONE);
  201.             fields.add(TransazioneApplicativoServer.model().SERVIZIO_APPLICATIVO_EROGATORE);
  202.             fields.add(TransazioneApplicativoServer.model().CONNETTORE_NOME);
  203.             fields.add(TransazioneApplicativoServer.model().DATA_REGISTRAZIONE);
  204.             // NONSERIALIZZATO SU DB fields.add(TransazioneApplicativoServer.model().PROTOCOLLO);
  205.             fields.add(TransazioneApplicativoServer.model().CONSEGNA_TERMINATA);
  206.             fields.add(TransazioneApplicativoServer.model().DATA_MESSAGGIO_SCADUTO);
  207.             fields.add(TransazioneApplicativoServer.model().DETTAGLIO_ESITO);
  208.             fields.add(TransazioneApplicativoServer.model().CONSEGNA_TRASPARENTE);
  209.             fields.add(TransazioneApplicativoServer.model().CONSEGNA_INTEGRATION_MANAGER);
  210.             fields.add(TransazioneApplicativoServer.model().IDENTIFICATIVO_MESSAGGIO);
  211.             fields.add(TransazioneApplicativoServer.model().DATA_ACCETTAZIONE_RICHIESTA);
  212.             fields.add(TransazioneApplicativoServer.model().DATA_USCITA_RICHIESTA);
  213.             fields.add(TransazioneApplicativoServer.model().DATA_USCITA_RICHIESTA_STREAM);
  214.             fields.add(TransazioneApplicativoServer.model().DATA_ACCETTAZIONE_RISPOSTA);
  215.             fields.add(TransazioneApplicativoServer.model().DATA_INGRESSO_RISPOSTA);
  216.             fields.add(TransazioneApplicativoServer.model().DATA_INGRESSO_RISPOSTA_STREAM);
  217.             fields.add(TransazioneApplicativoServer.model().RICHIESTA_USCITA_BYTES);
  218.             fields.add(TransazioneApplicativoServer.model().RISPOSTA_INGRESSO_BYTES);
  219.             fields.add(TransazioneApplicativoServer.model().LOCATION_CONNETTORE);
  220.             fields.add(TransazioneApplicativoServer.model().CODICE_RISPOSTA);
  221.             fields.add(TransazioneApplicativoServer.model().FAULT);
  222.             fields.add(TransazioneApplicativoServer.model().FORMATO_FAULT);
  223.             fields.add(TransazioneApplicativoServer.model().DATA_PRIMO_TENTATIVO);
  224.             fields.add(TransazioneApplicativoServer.model().NUMERO_TENTATIVI);
  225.             fields.add(TransazioneApplicativoServer.model().CLUSTER_ID_PRESA_IN_CARICO);
  226.             fields.add(TransazioneApplicativoServer.model().CLUSTER_ID_CONSEGNA);
  227.             fields.add(TransazioneApplicativoServer.model().DATA_ULTIMO_ERRORE);
  228.             fields.add(TransazioneApplicativoServer.model().DETTAGLIO_ESITO_ULTIMO_ERRORE);
  229.             fields.add(TransazioneApplicativoServer.model().CODICE_RISPOSTA_ULTIMO_ERRORE);
  230.             fields.add(TransazioneApplicativoServer.model().ULTIMO_ERRORE);
  231.             fields.add(TransazioneApplicativoServer.model().LOCATION_ULTIMO_ERRORE);
  232.             fields.add(TransazioneApplicativoServer.model().CLUSTER_ID_ULTIMO_ERRORE);
  233.             fields.add(TransazioneApplicativoServer.model().FAULT_ULTIMO_ERRORE);
  234.             fields.add(TransazioneApplicativoServer.model().FORMATO_FAULT_ULTIMO_ERRORE);
  235.             fields.add(TransazioneApplicativoServer.model().DATA_PRIMO_PRELIEVO_IM);
  236.             fields.add(TransazioneApplicativoServer.model().DATA_PRELIEVO_IM);
  237.             fields.add(TransazioneApplicativoServer.model().NUMERO_PRELIEVI_IM);
  238.             fields.add(TransazioneApplicativoServer.model().DATA_ELIMINAZIONE_IM);
  239.             fields.add(TransazioneApplicativoServer.model().CLUSTER_ID_PRELIEVO_IM);
  240.             fields.add(TransazioneApplicativoServer.model().CLUSTER_ID_ELIMINAZIONE_IM);
  241.            
  242.             List<Map<String, Object>> returnMap = null;
  243.             try{
  244.                  // Il distinct serve solo se ci sono le ricerche con contenuto.
  245.                 // NOTA: il distinct rende le ricerce inefficienti (ed inoltre non e' utilizzabile con campi clob in oracle)
  246.                
  247.                
  248.                 // BUG FIX: Siccome tra le colonne lette ci sono dei CLOB, in oracle non e' consentito utilizzare il DISTINCT.
  249.                 // Per questo motivo se c'e' da usare il distinct viene utilizzato il vecchio metodo
  250.                 if(distinct) {
  251.                     //System.out.println("NON EFFICIENTE");
  252.                    
  253.                      List<Long> ids = this.findAllTableIds(jdbcProperties, log, connection, sqlQueryObject, expression);
  254.                    
  255.                     for(Long id: ids) {
  256.                         list.add(this.get(jdbcProperties, log, connection, sqlQueryObject, id, idMappingResolutionBehaviour));
  257.                     }
  258.                    
  259.                 }
  260.                 else {
  261.                
  262.                     //System.out.println("EFFICIENTE");
  263.                    
  264.                     returnMap = this.select(jdbcProperties, log, connection, sqlQueryObject, expression, distinct, fields.toArray(new IField[1]));
  265.        
  266.                     for(Map<String, Object> map: returnMap) {
  267.                         list.add((TransazioneApplicativoServer)this.getTransazioneApplicativoServerFetch().fetch(jdbcProperties.getDatabase(), TransazioneApplicativoServer.model(), map));
  268.                     }
  269.                    
  270.                 }
  271.                    
  272.             }catch(NotFoundException notFound){}
  273.         }
  274.         else {
  275.        
  276.             List<Long> ids = this.findAllTableIds(jdbcProperties, log, connection, sqlQueryObject, expression);
  277.            
  278.             for(Long id: ids) {
  279.                 list.add(this.get(jdbcProperties, log, connection, sqlQueryObject, id, idMappingResolutionBehaviour));
  280.             }
  281.            
  282.         }

  283.         return list;      
  284.        
  285.     }
  286.    
  287.     @Override
  288.     public TransazioneApplicativoServer find(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject, JDBCExpression expression, org.openspcoop2.generic_project.beans.IDMappingBehaviour idMappingResolutionBehaviour)
  289.         throws NotFoundException, MultipleResultException, NotImplementedException, ServiceException,Exception {

  290.         if(efficiente){
  291.        
  292.             JDBCPaginatedExpression pagExpr = this.toPaginatedExpression(expression, log);
  293.             pagExpr.limit(2);
  294.            
  295.             List<TransazioneApplicativoServer> list = findAll(jdbcProperties, log, connection, sqlQueryObject, pagExpr, idMappingResolutionBehaviour);
  296.            
  297.             if(list==null || list.size()<1) {
  298.                 throw new NotFoundException();
  299.             }
  300.             else if(list.size()>1) {
  301.                 throw new MultipleResultException();
  302.             }
  303.             else {
  304.                 return list.get(0);
  305.             }
  306.            
  307.         }
  308.         else {
  309.            
  310.            
  311.             long id = this.findTableId(jdbcProperties, log, connection, sqlQueryObject, expression);
  312.             if(id>0){
  313.                 return this.get(jdbcProperties, log, connection, sqlQueryObject, id, idMappingResolutionBehaviour);
  314.             }else{
  315.                 throw new NotFoundException("Entry with id["+id+"] not found");
  316.             }
  317.            
  318.         }
  319.        
  320.     }
  321.    
  322.     @Override
  323.     public NonNegativeNumber count(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject, JDBCExpression expression) throws NotImplementedException, ServiceException,Exception {
  324.        
  325.         List<Object> listaQuery = org.openspcoop2.generic_project.dao.jdbc.utils.GenericJDBCUtilities.prepareCount(jdbcProperties, log, connection, sqlQueryObject, expression,
  326.                                                 this.getTransazioneApplicativoServerFieldConverter(), TransazioneApplicativoServer.model());
  327.        
  328.         sqlQueryObject.addSelectCountField(this.getTransazioneApplicativoServerFieldConverter().toTable(TransazioneApplicativoServer.model())+".id","tot",true);
  329.        
  330.         joinEngine(expression,sqlQueryObject);
  331.        
  332.         return org.openspcoop2.generic_project.dao.jdbc.utils.GenericJDBCUtilities.count(jdbcProperties, log, connection, sqlQueryObject, expression,
  333.                                                                             this.getTransazioneApplicativoServerFieldConverter(), TransazioneApplicativoServer.model(),listaQuery);
  334.     }

  335.     @Override
  336.     public InUse inUse(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject, IdTransazioneApplicativoServer id) throws NotFoundException, NotImplementedException, ServiceException,Exception {
  337.        
  338.         Long id_transazioneApplicativoServer = this.findIdTransazioneApplicativoServer(jdbcProperties, log, connection, sqlQueryObject, id, true);
  339.         return this.inUseEngine(jdbcProperties, log, connection, sqlQueryObject, id_transazioneApplicativoServer);
  340.        
  341.     }

  342.     @Override
  343.     public List<Object> select(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject,
  344.                                                     JDBCPaginatedExpression paginatedExpression, IField field) throws ServiceException,NotFoundException,NotImplementedException,Exception {
  345.         return this.select(jdbcProperties, log, connection, sqlQueryObject,
  346.                                 paginatedExpression, false, field);
  347.     }
  348.    
  349.     @Override
  350.     public List<Object> select(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject,
  351.                                                     JDBCPaginatedExpression paginatedExpression, boolean distinct, IField field) throws ServiceException,NotFoundException,NotImplementedException,Exception {
  352.         List<Map<String,Object>> map =
  353.             this.select(jdbcProperties, log, connection, sqlQueryObject, paginatedExpression, distinct, new IField[]{field});
  354.         return org.openspcoop2.generic_project.dao.jdbc.utils.GenericJDBCUtilities.selectSingleObject(map);
  355.     }
  356.    
  357.     @Override
  358.     public List<Map<String,Object>> select(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject,
  359.                                                     JDBCPaginatedExpression paginatedExpression, IField ... field) throws ServiceException,NotFoundException,NotImplementedException,Exception {
  360.         return this.select(jdbcProperties, log, connection, sqlQueryObject,
  361.                                 paginatedExpression, false, field);
  362.     }
  363.    
  364.     @Override
  365.     public List<Map<String,Object>> select(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject,
  366.                                                     JDBCPaginatedExpression paginatedExpression, boolean distinct, IField ... field) throws ServiceException,NotFoundException,NotImplementedException,Exception {
  367.        
  368.         org.openspcoop2.generic_project.dao.jdbc.utils.GenericJDBCUtilities.setFields(sqlQueryObject,paginatedExpression,field);
  369.         try{
  370.        
  371.             ISQLQueryObject sqlQueryObjectDistinct =
  372.                         org.openspcoop2.generic_project.dao.jdbc.utils.GenericJDBCUtilities.prepareSqlQueryObjectForSelectDistinct(distinct,sqlQueryObject, paginatedExpression, log,
  373.                                                 this.getTransazioneApplicativoServerFieldConverter(), field);

  374.             return selectEngine(jdbcProperties, log, connection, sqlQueryObject, paginatedExpression, sqlQueryObjectDistinct);
  375.            
  376.         }finally{
  377.             org.openspcoop2.generic_project.dao.jdbc.utils.GenericJDBCUtilities.removeFields(sqlQueryObject,paginatedExpression,field);
  378.         }
  379.     }

  380.     @Override
  381.     public Object aggregate(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject,
  382.                                                     JDBCExpression expression, FunctionField functionField) throws ServiceException,NotFoundException,NotImplementedException,Exception {
  383.         Map<String,Object> map =
  384.             this.aggregate(jdbcProperties, log, connection, sqlQueryObject, expression, new FunctionField[]{functionField});
  385.         return org.openspcoop2.generic_project.dao.jdbc.utils.GenericJDBCUtilities.selectAggregateObject(map,functionField);
  386.     }
  387.    
  388.     @Override
  389.     public Map<String,Object> aggregate(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject,
  390.                                                     JDBCExpression expression, FunctionField ... functionField) throws ServiceException,NotFoundException,NotImplementedException,Exception {                                                  
  391.        
  392.         org.openspcoop2.generic_project.dao.jdbc.utils.GenericJDBCUtilities.setFields(sqlQueryObject,expression,functionField);
  393.         try{
  394.             List<Map<String,Object>> list = selectEngine(jdbcProperties, log, connection, sqlQueryObject, expression);
  395.             return list.get(0);
  396.         }finally{
  397.             org.openspcoop2.generic_project.dao.jdbc.utils.GenericJDBCUtilities.removeFields(sqlQueryObject,expression,functionField);
  398.         }
  399.     }

  400.     @Override
  401.     public List<Map<String,Object>> groupBy(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject,
  402.                                                     JDBCExpression expression, FunctionField ... functionField) throws ServiceException,NotFoundException,NotImplementedException,Exception {
  403.        
  404.         if(expression.getGroupByFields().isEmpty()){
  405.             throw new ServiceException("GroupBy conditions not found in expression");
  406.         }
  407.        
  408.         org.openspcoop2.generic_project.dao.jdbc.utils.GenericJDBCUtilities.setFields(sqlQueryObject,expression,functionField);
  409.         try{
  410.             return selectEngine(jdbcProperties, log, connection, sqlQueryObject, expression);
  411.         }finally{
  412.             org.openspcoop2.generic_project.dao.jdbc.utils.GenericJDBCUtilities.removeFields(sqlQueryObject,expression,functionField);
  413.         }
  414.     }
  415.    

  416.     @Override
  417.     public List<Map<String,Object>> groupBy(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject,
  418.                                                     JDBCPaginatedExpression paginatedExpression, FunctionField ... functionField) throws ServiceException,NotFoundException,NotImplementedException,Exception {
  419.        
  420.         if(paginatedExpression.getGroupByFields().isEmpty()){
  421.             throw new ServiceException("GroupBy conditions not found in expression");
  422.         }
  423.        
  424.         org.openspcoop2.generic_project.dao.jdbc.utils.GenericJDBCUtilities.setFields(sqlQueryObject,paginatedExpression,functionField);
  425.         try{
  426.             return selectEngine(jdbcProperties, log, connection, sqlQueryObject, paginatedExpression);
  427.         }finally{
  428.             org.openspcoop2.generic_project.dao.jdbc.utils.GenericJDBCUtilities.removeFields(sqlQueryObject,paginatedExpression,functionField);
  429.         }
  430.     }
  431.    
  432.     protected List<Map<String,Object>> selectEngine(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject,
  433.                                                 IExpression expression) throws ServiceException,NotFoundException,NotImplementedException,Exception {
  434.         return selectEngine(jdbcProperties, log, connection, sqlQueryObject, expression, null);
  435.     }
  436.     protected List<Map<String,Object>> selectEngine(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject,
  437.                                                 IExpression expression, ISQLQueryObject sqlQueryObjectDistinct) throws ServiceException,NotFoundException,NotImplementedException,Exception {
  438.        
  439.         List<Object> listaQuery = new ArrayList<>();
  440.         List<JDBCObject> listaParams = new ArrayList<>();
  441.         List<Object> returnField = org.openspcoop2.generic_project.dao.jdbc.utils.GenericJDBCUtilities.prepareSelect(jdbcProperties, log, connection, sqlQueryObject,
  442.                                 expression, this.getTransazioneApplicativoServerFieldConverter(), TransazioneApplicativoServer.model(),
  443.                                 listaQuery,listaParams);
  444.        
  445.         joinEngine(expression,sqlQueryObject);
  446.        
  447.         List<Map<String,Object>> list = org.openspcoop2.generic_project.dao.jdbc.utils.GenericJDBCUtilities.select(jdbcProperties, log, connection,
  448.                                         org.openspcoop2.generic_project.dao.jdbc.utils.GenericJDBCUtilities.prepareSqlQueryObjectForSelectDistinct(sqlQueryObject,sqlQueryObjectDistinct),
  449.                                         expression, this.getTransazioneApplicativoServerFieldConverter(), TransazioneApplicativoServer.model(),
  450.                                         listaQuery,listaParams,returnField);
  451.         if(list!=null && !list.isEmpty()){
  452.             return list;
  453.         }
  454.         else{
  455.             throw org.openspcoop2.generic_project.dao.jdbc.utils.GenericJDBCUtilities.newNotFoundException();
  456.         }
  457.     }
  458.    
  459.     @Override
  460.     public List<Map<String,Object>> union(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject,
  461.                                                 Union union, UnionExpression ... unionExpression) throws ServiceException,NotFoundException,NotImplementedException,Exception {    
  462.        
  463.         List<ISQLQueryObject> sqlQueryObjectInnerList = new ArrayList<>();
  464.         List<JDBCObject> jdbcObjects = new ArrayList<>();
  465.         List<Class<?>> returnClassTypes = org.openspcoop2.generic_project.dao.jdbc.utils.GenericJDBCUtilities.prepareUnion(jdbcProperties, log, connection, sqlQueryObject,
  466.                                 this.getTransazioneApplicativoServerFieldConverter(), TransazioneApplicativoServer.model(),
  467.                                 sqlQueryObjectInnerList, jdbcObjects, union, unionExpression);
  468.        
  469.         if(unionExpression!=null){
  470.             for (int i = 0; i < unionExpression.length; i++) {
  471.                 UnionExpression ue = unionExpression[i];
  472.                 IExpression expression = ue.getExpression();
  473.                 joinEngine(expression,sqlQueryObjectInnerList.get(i));
  474.             }
  475.         }
  476.        
  477.         List<Map<String,Object>> list = org.openspcoop2.generic_project.dao.jdbc.utils.GenericJDBCUtilities.union(jdbcProperties, log, connection, sqlQueryObject,
  478.                                         this.getTransazioneApplicativoServerFieldConverter(), TransazioneApplicativoServer.model(),
  479.                                         sqlQueryObjectInnerList, jdbcObjects, returnClassTypes, union, unionExpression);
  480.         if(list!=null && !list.isEmpty()){
  481.             return list;
  482.         }
  483.         else{
  484.             throw org.openspcoop2.generic_project.dao.jdbc.utils.GenericJDBCUtilities.newNotFoundException();
  485.         }                              
  486.     }
  487.    
  488.     @Override
  489.     public NonNegativeNumber unionCount(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject,
  490.                                                 Union union, UnionExpression ... unionExpression) throws ServiceException,NotFoundException,NotImplementedException,Exception {    
  491.        
  492.         List<ISQLQueryObject> sqlQueryObjectInnerList = new ArrayList<>();
  493.         List<JDBCObject> jdbcObjects = new ArrayList<>();
  494.         List<Class<?>> returnClassTypes = org.openspcoop2.generic_project.dao.jdbc.utils.GenericJDBCUtilities.prepareUnionCount(jdbcProperties, log, connection, sqlQueryObject,
  495.                                 this.getTransazioneApplicativoServerFieldConverter(), TransazioneApplicativoServer.model(),
  496.                                 sqlQueryObjectInnerList, jdbcObjects, union, unionExpression);
  497.        
  498.         if(unionExpression!=null){
  499.             for (int i = 0; i < unionExpression.length; i++) {
  500.                 UnionExpression ue = unionExpression[i];
  501.                 IExpression expression = ue.getExpression();
  502.                 joinEngine(expression,sqlQueryObjectInnerList.get(i));
  503.             }
  504.         }
  505.        
  506.         NonNegativeNumber number = org.openspcoop2.generic_project.dao.jdbc.utils.GenericJDBCUtilities.unionCount(jdbcProperties, log, connection, sqlQueryObject,
  507.                                         this.getTransazioneApplicativoServerFieldConverter(), TransazioneApplicativoServer.model(),
  508.                                         sqlQueryObjectInnerList, jdbcObjects, returnClassTypes, union, unionExpression);
  509.         if(number!=null && number.longValue()>=0){
  510.             return number;
  511.         }
  512.         else{
  513.             throw org.openspcoop2.generic_project.dao.jdbc.utils.GenericJDBCUtilities.newNotFoundException();
  514.         }
  515.     }



  516.     // -- ConstructorExpression

  517.     @Override
  518.     public JDBCExpression newExpression(Logger log) throws NotImplementedException, ServiceException {
  519.         try{
  520.             return new JDBCExpression(this.getTransazioneApplicativoServerFieldConverter());
  521.         }catch(Exception e){
  522.             throw new ServiceException(e);
  523.         }
  524.     }


  525.     @Override
  526.     public JDBCPaginatedExpression newPaginatedExpression(Logger log) throws NotImplementedException, ServiceException {
  527.         try{
  528.             return new JDBCPaginatedExpression(this.getTransazioneApplicativoServerFieldConverter());
  529.         }catch(Exception e){
  530.             throw new ServiceException(e);
  531.         }
  532.     }
  533.    
  534.     @Override
  535.     public JDBCExpression toExpression(JDBCPaginatedExpression paginatedExpression, Logger log) throws NotImplementedException, ServiceException {
  536.         try{
  537.             return new JDBCExpression(paginatedExpression);
  538.         }catch(Exception e){
  539.             throw new ServiceException(e);
  540.         }
  541.     }

  542.     @Override
  543.     public JDBCPaginatedExpression toPaginatedExpression(JDBCExpression expression, Logger log) throws NotImplementedException, ServiceException {
  544.         try{
  545.             return new JDBCPaginatedExpression(expression);
  546.         }catch(Exception e){
  547.             throw new ServiceException(e);
  548.         }
  549.     }
  550.    
  551.    
  552.    
  553.     // -- DB

  554.     @Override
  555.     public void mappingTableIds(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject, IdTransazioneApplicativoServer id, TransazioneApplicativoServer obj) throws NotFoundException,NotImplementedException,ServiceException,Exception{
  556.         _mappingTableIds(jdbcProperties,log,connection,sqlQueryObject,obj,
  557.                 this.get(jdbcProperties,log,connection,sqlQueryObject,id,null));
  558.     }
  559.    
  560.     @Override
  561.     public void mappingTableIds(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject, long tableId, TransazioneApplicativoServer obj) throws NotFoundException,NotImplementedException,ServiceException,Exception{
  562.         _mappingTableIds(jdbcProperties,log,connection,sqlQueryObject,obj,
  563.                 this.get(jdbcProperties,log,connection,sqlQueryObject,tableId,null));
  564.     }
  565.     private void _mappingTableIds(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject, TransazioneApplicativoServer obj, TransazioneApplicativoServer imgSaved) throws NotFoundException,NotImplementedException,ServiceException,Exception{
  566.         if(imgSaved==null){
  567.             return;
  568.         }
  569.         obj.setId(imgSaved.getId());

  570.     }
  571.    
  572.     @Override
  573.     public TransazioneApplicativoServer get(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject, long tableId, org.openspcoop2.generic_project.beans.IDMappingBehaviour idMappingResolutionBehaviour) throws NotFoundException, MultipleResultException, NotImplementedException, ServiceException, Exception {
  574.         return this.getEngine(jdbcProperties, log, connection, sqlQueryObject, Long.valueOf(tableId), idMappingResolutionBehaviour);
  575.     }
  576.    
  577.     private TransazioneApplicativoServer getEngine(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject, Long tableId, org.openspcoop2.generic_project.beans.IDMappingBehaviour idMappingResolutionBehaviour) throws NotFoundException, MultipleResultException, NotImplementedException, ServiceException, Exception {
  578.    
  579.         org.openspcoop2.generic_project.dao.jdbc.utils.JDBCPreparedStatementUtilities jdbcUtilities =
  580.                     new org.openspcoop2.generic_project.dao.jdbc.utils.JDBCPreparedStatementUtilities(sqlQueryObject.getTipoDatabaseOpenSPCoop2(), log, connection);
  581.        
  582.         ISQLQueryObject sqlQueryObjectGet = sqlQueryObject.newSQLQueryObject();
  583.                
  584.         TransazioneApplicativoServer transazioneApplicativoServer = new TransazioneApplicativoServer();
  585.        

  586.         // Object transazioneApplicativoServer
  587.         ISQLQueryObject sqlQueryObjectGet_transazioneApplicativoServer = sqlQueryObjectGet.newSQLQueryObject();
  588.         sqlQueryObjectGet_transazioneApplicativoServer.setANDLogicOperator(true);
  589.         sqlQueryObjectGet_transazioneApplicativoServer.addFromTable(this.getTransazioneApplicativoServerFieldConverter().toTable(TransazioneApplicativoServer.model()));
  590.         sqlQueryObjectGet_transazioneApplicativoServer.addSelectField("id");
  591.         sqlQueryObjectGet_transazioneApplicativoServer.addSelectField(this.getTransazioneApplicativoServerFieldConverter().toColumn(TransazioneApplicativoServer.model().ID_TRANSAZIONE,true));
  592.         sqlQueryObjectGet_transazioneApplicativoServer.addSelectField(this.getTransazioneApplicativoServerFieldConverter().toColumn(TransazioneApplicativoServer.model().SERVIZIO_APPLICATIVO_EROGATORE,true));
  593.         sqlQueryObjectGet_transazioneApplicativoServer.addSelectField(this.getTransazioneApplicativoServerFieldConverter().toColumn(TransazioneApplicativoServer.model().CONNETTORE_NOME,true));
  594.         sqlQueryObjectGet_transazioneApplicativoServer.addSelectField(this.getTransazioneApplicativoServerFieldConverter().toColumn(TransazioneApplicativoServer.model().DATA_REGISTRAZIONE,true));
  595.         // NONSERIALIZZATO SU DB sqlQueryObjectGet_transazioneApplicativoServer.addSelectField(this.getTransazioneApplicativoServerFieldConverter().toColumn(TransazioneApplicativoServer.model().PROTOCOLLO,true));
  596.         sqlQueryObjectGet_transazioneApplicativoServer.addSelectField(this.getTransazioneApplicativoServerFieldConverter().toColumn(TransazioneApplicativoServer.model().CONSEGNA_TERMINATA,true));
  597.         sqlQueryObjectGet_transazioneApplicativoServer.addSelectField(this.getTransazioneApplicativoServerFieldConverter().toColumn(TransazioneApplicativoServer.model().DATA_MESSAGGIO_SCADUTO,true));
  598.         sqlQueryObjectGet_transazioneApplicativoServer.addSelectField(this.getTransazioneApplicativoServerFieldConverter().toColumn(TransazioneApplicativoServer.model().DETTAGLIO_ESITO,true));
  599.         sqlQueryObjectGet_transazioneApplicativoServer.addSelectField(this.getTransazioneApplicativoServerFieldConverter().toColumn(TransazioneApplicativoServer.model().CONSEGNA_TRASPARENTE,true));
  600.         sqlQueryObjectGet_transazioneApplicativoServer.addSelectField(this.getTransazioneApplicativoServerFieldConverter().toColumn(TransazioneApplicativoServer.model().CONSEGNA_INTEGRATION_MANAGER,true));
  601.         sqlQueryObjectGet_transazioneApplicativoServer.addSelectField(this.getTransazioneApplicativoServerFieldConverter().toColumn(TransazioneApplicativoServer.model().IDENTIFICATIVO_MESSAGGIO,true));
  602.         sqlQueryObjectGet_transazioneApplicativoServer.addSelectField(this.getTransazioneApplicativoServerFieldConverter().toColumn(TransazioneApplicativoServer.model().DATA_ACCETTAZIONE_RICHIESTA,true));
  603.         sqlQueryObjectGet_transazioneApplicativoServer.addSelectField(this.getTransazioneApplicativoServerFieldConverter().toColumn(TransazioneApplicativoServer.model().DATA_USCITA_RICHIESTA,true));
  604.         sqlQueryObjectGet_transazioneApplicativoServer.addSelectField(this.getTransazioneApplicativoServerFieldConverter().toColumn(TransazioneApplicativoServer.model().DATA_USCITA_RICHIESTA_STREAM,true));
  605.         sqlQueryObjectGet_transazioneApplicativoServer.addSelectField(this.getTransazioneApplicativoServerFieldConverter().toColumn(TransazioneApplicativoServer.model().DATA_ACCETTAZIONE_RISPOSTA,true));
  606.         sqlQueryObjectGet_transazioneApplicativoServer.addSelectField(this.getTransazioneApplicativoServerFieldConverter().toColumn(TransazioneApplicativoServer.model().DATA_INGRESSO_RISPOSTA,true));
  607.         sqlQueryObjectGet_transazioneApplicativoServer.addSelectField(this.getTransazioneApplicativoServerFieldConverter().toColumn(TransazioneApplicativoServer.model().DATA_INGRESSO_RISPOSTA_STREAM,true));
  608.         sqlQueryObjectGet_transazioneApplicativoServer.addSelectField(this.getTransazioneApplicativoServerFieldConverter().toColumn(TransazioneApplicativoServer.model().RICHIESTA_USCITA_BYTES,true));
  609.         sqlQueryObjectGet_transazioneApplicativoServer.addSelectField(this.getTransazioneApplicativoServerFieldConverter().toColumn(TransazioneApplicativoServer.model().RISPOSTA_INGRESSO_BYTES,true));
  610.         sqlQueryObjectGet_transazioneApplicativoServer.addSelectField(this.getTransazioneApplicativoServerFieldConverter().toColumn(TransazioneApplicativoServer.model().LOCATION_CONNETTORE,true));
  611.         sqlQueryObjectGet_transazioneApplicativoServer.addSelectField(this.getTransazioneApplicativoServerFieldConverter().toColumn(TransazioneApplicativoServer.model().CODICE_RISPOSTA,true));
  612.         sqlQueryObjectGet_transazioneApplicativoServer.addSelectField(this.getTransazioneApplicativoServerFieldConverter().toColumn(TransazioneApplicativoServer.model().FAULT,true));
  613.         sqlQueryObjectGet_transazioneApplicativoServer.addSelectField(this.getTransazioneApplicativoServerFieldConverter().toColumn(TransazioneApplicativoServer.model().FORMATO_FAULT,true));
  614.         sqlQueryObjectGet_transazioneApplicativoServer.addSelectField(this.getTransazioneApplicativoServerFieldConverter().toColumn(TransazioneApplicativoServer.model().DATA_PRIMO_TENTATIVO,true));
  615.         sqlQueryObjectGet_transazioneApplicativoServer.addSelectField(this.getTransazioneApplicativoServerFieldConverter().toColumn(TransazioneApplicativoServer.model().NUMERO_TENTATIVI,true));
  616.         sqlQueryObjectGet_transazioneApplicativoServer.addSelectField(this.getTransazioneApplicativoServerFieldConverter().toColumn(TransazioneApplicativoServer.model().CLUSTER_ID_PRESA_IN_CARICO,true));
  617.         sqlQueryObjectGet_transazioneApplicativoServer.addSelectField(this.getTransazioneApplicativoServerFieldConverter().toColumn(TransazioneApplicativoServer.model().CLUSTER_ID_CONSEGNA,true));
  618.         sqlQueryObjectGet_transazioneApplicativoServer.addSelectField(this.getTransazioneApplicativoServerFieldConverter().toColumn(TransazioneApplicativoServer.model().DATA_ULTIMO_ERRORE,true));
  619.         sqlQueryObjectGet_transazioneApplicativoServer.addSelectField(this.getTransazioneApplicativoServerFieldConverter().toColumn(TransazioneApplicativoServer.model().DETTAGLIO_ESITO_ULTIMO_ERRORE,true));
  620.         sqlQueryObjectGet_transazioneApplicativoServer.addSelectField(this.getTransazioneApplicativoServerFieldConverter().toColumn(TransazioneApplicativoServer.model().CODICE_RISPOSTA_ULTIMO_ERRORE,true));
  621.         sqlQueryObjectGet_transazioneApplicativoServer.addSelectField(this.getTransazioneApplicativoServerFieldConverter().toColumn(TransazioneApplicativoServer.model().ULTIMO_ERRORE,true));
  622.         sqlQueryObjectGet_transazioneApplicativoServer.addSelectField(this.getTransazioneApplicativoServerFieldConverter().toColumn(TransazioneApplicativoServer.model().LOCATION_ULTIMO_ERRORE,true));
  623.         sqlQueryObjectGet_transazioneApplicativoServer.addSelectField(this.getTransazioneApplicativoServerFieldConverter().toColumn(TransazioneApplicativoServer.model().CLUSTER_ID_ULTIMO_ERRORE,true));
  624.         sqlQueryObjectGet_transazioneApplicativoServer.addSelectField(this.getTransazioneApplicativoServerFieldConverter().toColumn(TransazioneApplicativoServer.model().FAULT_ULTIMO_ERRORE,true));
  625.         sqlQueryObjectGet_transazioneApplicativoServer.addSelectField(this.getTransazioneApplicativoServerFieldConverter().toColumn(TransazioneApplicativoServer.model().FORMATO_FAULT_ULTIMO_ERRORE,true));
  626.         sqlQueryObjectGet_transazioneApplicativoServer.addSelectField(this.getTransazioneApplicativoServerFieldConverter().toColumn(TransazioneApplicativoServer.model().DATA_PRIMO_PRELIEVO_IM,true));
  627.         sqlQueryObjectGet_transazioneApplicativoServer.addSelectField(this.getTransazioneApplicativoServerFieldConverter().toColumn(TransazioneApplicativoServer.model().DATA_PRELIEVO_IM,true));
  628.         sqlQueryObjectGet_transazioneApplicativoServer.addSelectField(this.getTransazioneApplicativoServerFieldConverter().toColumn(TransazioneApplicativoServer.model().NUMERO_PRELIEVI_IM,true));
  629.         sqlQueryObjectGet_transazioneApplicativoServer.addSelectField(this.getTransazioneApplicativoServerFieldConverter().toColumn(TransazioneApplicativoServer.model().DATA_ELIMINAZIONE_IM,true));
  630.         sqlQueryObjectGet_transazioneApplicativoServer.addSelectField(this.getTransazioneApplicativoServerFieldConverter().toColumn(TransazioneApplicativoServer.model().CLUSTER_ID_PRELIEVO_IM,true));
  631.         sqlQueryObjectGet_transazioneApplicativoServer.addSelectField(this.getTransazioneApplicativoServerFieldConverter().toColumn(TransazioneApplicativoServer.model().CLUSTER_ID_ELIMINAZIONE_IM,true));
  632.         sqlQueryObjectGet_transazioneApplicativoServer.addWhereCondition("id=?");

  633.         // Get transazioneApplicativoServer
  634.         transazioneApplicativoServer = (TransazioneApplicativoServer) jdbcUtilities.executeQuerySingleResult(sqlQueryObjectGet_transazioneApplicativoServer.createSQLQuery(), jdbcProperties.isShowSql(), TransazioneApplicativoServer.model(), this.getTransazioneApplicativoServerFetch(),
  635.             new JDBCObject(tableId,Long.class));



  636.        
  637.         return transazioneApplicativoServer;  
  638.    
  639.     }
  640.    
  641.     @Override
  642.     public boolean exists(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject, long tableId) throws MultipleResultException, NotImplementedException, ServiceException, Exception {
  643.         return this._exists(jdbcProperties, log, connection, sqlQueryObject, Long.valueOf(tableId));
  644.     }
  645.    
  646.     private boolean _exists(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject, Long tableId) throws MultipleResultException, NotImplementedException, ServiceException, Exception {
  647.    
  648.         org.openspcoop2.generic_project.dao.jdbc.utils.JDBCPreparedStatementUtilities jdbcUtilities =
  649.                     new org.openspcoop2.generic_project.dao.jdbc.utils.JDBCPreparedStatementUtilities(sqlQueryObject.getTipoDatabaseOpenSPCoop2(), log, connection);
  650.                
  651.         boolean existsTransazioneApplicativoServer = false;

  652.         sqlQueryObject = sqlQueryObject.newSQLQueryObject();
  653.         sqlQueryObject.setANDLogicOperator(true);

  654.         sqlQueryObject.addFromTable(this.getTransazioneApplicativoServerFieldConverter().toTable(TransazioneApplicativoServer.model()));
  655.         sqlQueryObject.addSelectField(this.getTransazioneApplicativoServerFieldConverter().toColumn(TransazioneApplicativoServer.model().ID_TRANSAZIONE,true));
  656.         sqlQueryObject.addWhereCondition("id=?");


  657.         // Exists transazioneApplicativoServer
  658.         existsTransazioneApplicativoServer = jdbcUtilities.exists(sqlQueryObject.createSQLQuery(), jdbcProperties.isShowSql(),
  659.             new JDBCObject(tableId,Long.class));

  660.        
  661.         return existsTransazioneApplicativoServer;
  662.    
  663.     }
  664.    
  665.     private void joinEngine(IExpression expression, ISQLQueryObject sqlQueryObject) throws NotImplementedException, ServiceException, Exception{
  666.    
  667.         // NOP;
  668.        
  669.     }
  670.    
  671.     protected java.util.List<Object> getRootTablePrimaryKeyValuesEngine(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject, IdTransazioneApplicativoServer id) throws NotFoundException, ServiceException, NotImplementedException, Exception{
  672.         // Identificativi
  673.         java.util.List<Object> rootTableIdValues = new java.util.ArrayList<>();
  674.         Long longId = this.findIdTransazioneApplicativoServer(jdbcProperties, log, connection, sqlQueryObject.newSQLQueryObject(), id, true);
  675.         rootTableIdValues.add(longId);
  676.         return rootTableIdValues;
  677.     }
  678.    
  679.     protected Map<String, List<IField>> getMapTableToPKColumnEngine() throws NotImplementedException, Exception{
  680.    
  681.         TransazioneApplicativoServerFieldConverter converter = this.getTransazioneApplicativoServerFieldConverter();
  682.         Map<String, List<IField>> mapTableToPKColumn = new java.util.HashMap<>();
  683.         UtilsTemplate<IField> utilities = new UtilsTemplate<>();

  684.         // TransazioneApplicativoServer.model()
  685.         mapTableToPKColumn.put(converter.toTable(TransazioneApplicativoServer.model()),
  686.             utilities.newList(
  687.                 new CustomField("id", Long.class, "id", converter.toTable(TransazioneApplicativoServer.model()))
  688.             ));

  689.        
  690.         return mapTableToPKColumn;      
  691.     }
  692.    
  693.     @Override
  694.     public List<Long> findAllTableIds(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject, JDBCPaginatedExpression paginatedExpression) throws ServiceException, NotImplementedException, Exception {
  695.        
  696.         List<Long> list = new ArrayList<Long>();

  697.         sqlQueryObject.setSelectDistinct(true);
  698.         sqlQueryObject.setANDLogicOperator(true);
  699.         sqlQueryObject.addSelectField(this.getTransazioneApplicativoServerFieldConverter().toTable(TransazioneApplicativoServer.model())+".id");
  700.         Class<?> objectIdClass = Long.class;
  701.        
  702.         List<Object> listaQuery = org.openspcoop2.generic_project.dao.jdbc.utils.GenericJDBCUtilities.prepareFindAll(jdbcProperties, log, connection, sqlQueryObject, paginatedExpression,
  703.                                                 this.getTransazioneApplicativoServerFieldConverter(), TransazioneApplicativoServer.model());
  704.        
  705.         joinEngine(paginatedExpression,sqlQueryObject);
  706.        
  707.         List<Object> listObjects = org.openspcoop2.generic_project.dao.jdbc.utils.GenericJDBCUtilities.findAll(jdbcProperties, log, connection, sqlQueryObject, paginatedExpression,
  708.                                                                             this.getTransazioneApplicativoServerFieldConverter(), TransazioneApplicativoServer.model(), objectIdClass, listaQuery);
  709.         for(Object object: listObjects) {
  710.             list.add((Long)object);
  711.         }

  712.         return list;
  713.        
  714.     }
  715.    
  716.     @Override
  717.     public long findTableId(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject, JDBCExpression expression) throws ServiceException, NotFoundException, MultipleResultException, NotImplementedException, Exception {
  718.    
  719.         sqlQueryObject.setSelectDistinct(true);
  720.         sqlQueryObject.setANDLogicOperator(true);
  721.         sqlQueryObject.addSelectField(this.getTransazioneApplicativoServerFieldConverter().toTable(TransazioneApplicativoServer.model())+".id");
  722.         Class<?> objectIdClass = Long.class;
  723.        
  724.         List<Object> listaQuery = org.openspcoop2.generic_project.dao.jdbc.utils.GenericJDBCUtilities.prepareFind(jdbcProperties, log, connection, sqlQueryObject, expression,
  725.                                                 this.getTransazioneApplicativoServerFieldConverter(), TransazioneApplicativoServer.model());
  726.        
  727.         joinEngine(expression,sqlQueryObject);

  728.         Object res = org.openspcoop2.generic_project.dao.jdbc.utils.GenericJDBCUtilities.find(jdbcProperties, log, connection, sqlQueryObject, expression,
  729.                                                         this.getTransazioneApplicativoServerFieldConverter(), TransazioneApplicativoServer.model(), objectIdClass, listaQuery);
  730.         if(res!=null && (((Long) res).longValue()>0) ){
  731.             return ((Long) res).longValue();
  732.         }
  733.         else{
  734.             throw org.openspcoop2.generic_project.dao.jdbc.utils.GenericJDBCUtilities.newNotFoundException();
  735.         }
  736.        
  737.     }

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

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

  743.         InUse inUse = new InUse();
  744.         inUse.setInUse(false);
  745.        
  746.         /*
  747.          * TODO: implement code that checks whether the object identified by the id parameter is used by other objects
  748.         */
  749.        
  750.         // Delete this line when you have implemented the method
  751.         int throwNotImplemented = 1;
  752.         if(throwNotImplemented==1){
  753.                 throw new NotImplementedException("NotImplemented");
  754.         }
  755.         // Delete this line when you have implemented the method

  756.         return inUse;

  757.     }
  758.    
  759.     @Override
  760.     public IdTransazioneApplicativoServer findId(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject, long tableId, boolean throwNotFound)
  761.             throws NotFoundException, ServiceException, NotImplementedException, Exception {
  762.        
  763.         org.openspcoop2.generic_project.dao.jdbc.utils.JDBCPreparedStatementUtilities jdbcUtilities =
  764.             new org.openspcoop2.generic_project.dao.jdbc.utils.JDBCPreparedStatementUtilities(sqlQueryObject.getTipoDatabaseOpenSPCoop2(), log, connection);

  765.         ISQLQueryObject sqlQueryObjectGet = sqlQueryObject.newSQLQueryObject();            

  766.         // Object _transazioneApplicativoServer
  767.         sqlQueryObjectGet.addFromTable(this.getTransazioneApplicativoServerFieldConverter().toTable(TransazioneApplicativoServer.model()));
  768.         sqlQueryObjectGet.addSelectField(this.getTransazioneApplicativoServerFieldConverter().toColumn(TransazioneApplicativoServer.model().ID_TRANSAZIONE,true));
  769.         sqlQueryObjectGet.addSelectField(this.getTransazioneApplicativoServerFieldConverter().toColumn(TransazioneApplicativoServer.model().SERVIZIO_APPLICATIVO_EROGATORE,true));
  770.         sqlQueryObjectGet.setANDLogicOperator(true);
  771.         sqlQueryObjectGet.addWhereCondition("id=?");

  772.         // Recupero _transazioneApplicativoServer
  773.         org.openspcoop2.generic_project.dao.jdbc.utils.JDBCObject [] searchParams_transazioneApplicativoServer = new org.openspcoop2.generic_project.dao.jdbc.utils.JDBCObject [] {
  774.             new org.openspcoop2.generic_project.dao.jdbc.utils.JDBCObject(tableId,Long.class)
  775.         };
  776.         List<Class<?>> listaFieldIdReturnType_transazioneApplicativoServer = new ArrayList<Class<?>>();
  777.         listaFieldIdReturnType_transazioneApplicativoServer.add(String.class);
  778.         listaFieldIdReturnType_transazioneApplicativoServer.add(String.class);
  779.         org.openspcoop2.core.transazioni.IdTransazioneApplicativoServer id_transazioneApplicativoServer = null;
  780.         List<Object> listaFieldId_transazioneApplicativoServer = jdbcUtilities.executeQuerySingleResult(sqlQueryObjectGet.createSQLQuery(), jdbcProperties.isShowSql(),
  781.                 listaFieldIdReturnType_transazioneApplicativoServer, searchParams_transazioneApplicativoServer);
  782.         if(listaFieldId_transazioneApplicativoServer==null || listaFieldId_transazioneApplicativoServer.size()<=0){
  783.             if(throwNotFound){
  784.                 throw org.openspcoop2.generic_project.dao.jdbc.utils.GenericJDBCUtilities.newNotFoundException();
  785.             }
  786.         }
  787.         else{
  788.             // set _transazioneApplicativoServer
  789.             id_transazioneApplicativoServer = new org.openspcoop2.core.transazioni.IdTransazioneApplicativoServer();
  790.             id_transazioneApplicativoServer.setIdTransazione((String)listaFieldId_transazioneApplicativoServer.get(0));
  791.             id_transazioneApplicativoServer.setServizioApplicativoErogatore((String)listaFieldId_transazioneApplicativoServer.get(1));
  792.         }
  793.        
  794.         return id_transazioneApplicativoServer;
  795.        
  796.     }

  797.     @Override
  798.     public Long findTableId(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject, IdTransazioneApplicativoServer id, boolean throwNotFound)
  799.             throws NotFoundException, ServiceException, NotImplementedException, Exception {
  800.    
  801.         return this.findIdTransazioneApplicativoServer(jdbcProperties,log,connection,sqlQueryObject,id,throwNotFound);
  802.            
  803.     }
  804.    
  805.     @Override
  806.     public List<List<Object>> nativeQuery(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject,
  807.                                             String sql,List<Class<?>> returnClassTypes,Object ... param) throws ServiceException,NotFoundException,NotImplementedException,Exception{
  808.        
  809.         return org.openspcoop2.generic_project.dao.jdbc.utils.GenericJDBCUtilities.nativeQuery(jdbcProperties, log, connection, sqlQueryObject,
  810.                                                                                             sql,returnClassTypes,param);
  811.                                                        
  812.     }
  813.    
  814.     protected Long findIdTransazioneApplicativoServer(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject, IdTransazioneApplicativoServer id, boolean throwNotFound) throws NotFoundException, ServiceException, NotImplementedException, Exception {

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

  817.         ISQLQueryObject sqlQueryObjectGet = sqlQueryObject.newSQLQueryObject();

  818.         if(id==null) {
  819.             throw new ServiceException("Id non definito");
  820.         }
  821.         if(id.getIdTransazione()==null) {
  822.             throw new ServiceException("IdTransazione non definito");
  823.         }
  824.         if(id.getServizioApplicativoErogatore()==null) {
  825.             throw new ServiceException("IdServizioApplicativoErogatore non definito");
  826.         }
  827.        
  828.         // Object _transazioneApplicativoServer
  829.         sqlQueryObjectGet.addFromTable(this.getTransazioneApplicativoServerFieldConverter().toTable(TransazioneApplicativoServer.model()));
  830.         sqlQueryObjectGet.addSelectField("id");
  831.         // Devono essere mappati nella where condition i metodi dell'oggetto id.getXXX
  832.         sqlQueryObjectGet.setANDLogicOperator(true);
  833.         sqlQueryObjectGet.setSelectDistinct(true);
  834.         sqlQueryObjectGet.addWhereCondition(this.getTransazioneApplicativoServerFieldConverter().toColumn(TransazioneApplicativoServer.model().ID_TRANSAZIONE,true)+"=?");
  835.         sqlQueryObjectGet.addWhereCondition(this.getTransazioneApplicativoServerFieldConverter().toColumn(TransazioneApplicativoServer.model().SERVIZIO_APPLICATIVO_EROGATORE,true)+"=?");

  836.         // Recupero _transazioneApplicativoServer
  837.         org.openspcoop2.generic_project.dao.jdbc.utils.JDBCObject [] searchParams_transazioneApplicativoServer = new org.openspcoop2.generic_project.dao.jdbc.utils.JDBCObject [] {
  838.             new org.openspcoop2.generic_project.dao.jdbc.utils.JDBCObject(id.getIdTransazione(),String.class),
  839.             new org.openspcoop2.generic_project.dao.jdbc.utils.JDBCObject(id.getServizioApplicativoErogatore(),String.class)
  840.         };
  841.         Long id_transazioneApplicativoServer = null;
  842.         try{
  843.             id_transazioneApplicativoServer = (Long) jdbcUtilities.executeQuerySingleResult(sqlQueryObjectGet.createSQLQuery(), jdbcProperties.isShowSql(),
  844.                         Long.class, searchParams_transazioneApplicativoServer);
  845.         }catch(NotFoundException notFound){
  846.             if(throwNotFound){
  847.                 throw new NotFoundException(notFound);
  848.             }
  849.         }
  850.         if(id_transazioneApplicativoServer==null || id_transazioneApplicativoServer<=0){
  851.             if(throwNotFound){
  852.                 throw org.openspcoop2.generic_project.dao.jdbc.utils.GenericJDBCUtilities.newNotFoundException();
  853.             }
  854.         }
  855.        
  856.         return id_transazioneApplicativoServer;
  857.     }
  858. }