JDBCTransazioneServiceSearchImpl.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.Transazione;
  26. import org.openspcoop2.core.transazioni.dao.jdbc.converter.TransazioneFieldConverter;
  27. import org.openspcoop2.core.transazioni.dao.jdbc.fetch.TransazioneFetch;
  28. import org.openspcoop2.core.transazioni.utils.AliasTableRicerchePersonalizzate;
  29. import org.openspcoop2.core.transazioni.utils.TransazioniIndexUtils;
  30. import org.openspcoop2.generic_project.beans.CustomField;
  31. import org.openspcoop2.generic_project.beans.FunctionField;
  32. import org.openspcoop2.generic_project.beans.IField;
  33. import org.openspcoop2.generic_project.beans.InUse;
  34. import org.openspcoop2.generic_project.beans.NonNegativeNumber;
  35. import org.openspcoop2.generic_project.beans.Union;
  36. import org.openspcoop2.generic_project.beans.UnionExpression;
  37. import org.openspcoop2.generic_project.dao.jdbc.IJDBCServiceSearchWithId;
  38. import org.openspcoop2.generic_project.dao.jdbc.JDBCExpression;
  39. import org.openspcoop2.generic_project.dao.jdbc.JDBCPaginatedExpression;
  40. import org.openspcoop2.generic_project.dao.jdbc.JDBCServiceManagerProperties;
  41. import org.openspcoop2.generic_project.dao.jdbc.utils.IJDBCFetch;
  42. import org.openspcoop2.generic_project.dao.jdbc.utils.JDBCObject;
  43. import org.openspcoop2.generic_project.exception.MultipleResultException;
  44. import org.openspcoop2.generic_project.exception.NotFoundException;
  45. import org.openspcoop2.generic_project.exception.NotImplementedException;
  46. import org.openspcoop2.generic_project.exception.ServiceException;
  47. import org.openspcoop2.generic_project.expression.IExpression;
  48. import org.openspcoop2.generic_project.expression.impl.sql.ISQLFieldConverter;
  49. import org.openspcoop2.generic_project.utils.UtilsTemplate;
  50. import org.openspcoop2.utils.sql.ISQLQueryObject;
  51. import org.openspcoop2.utils.sql.SQLQueryObjectCore;
  52. import org.slf4j.Logger;

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

  61.     private TransazioneFieldConverter _transazioneFieldConverter = null;
  62.     public TransazioneFieldConverter getTransazioneFieldConverter() {
  63.         if(this._transazioneFieldConverter==null){
  64.             this._transazioneFieldConverter = new TransazioneFieldConverter(this.jdbcServiceManager.getJdbcProperties().getDatabaseType());
  65.         }      
  66.         return this._transazioneFieldConverter;
  67.     }
  68.     @Override
  69.     public ISQLFieldConverter getFieldConverter() {
  70.         return this.getTransazioneFieldConverter();
  71.     }
  72.    
  73.     private TransazioneFetch transazioneFetch = new TransazioneFetch();
  74.     public TransazioneFetch getTransazioneFetch() {
  75.         return this.transazioneFetch;
  76.     }
  77.     @Override
  78.     public IJDBCFetch getFetch() {
  79.         return getTransazioneFetch();
  80.     }
  81.    
  82.    
  83.     private JDBCServiceManager jdbcServiceManager = null;

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

  94.     @Override
  95.     public String convertToId(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject, Transazione transazione) throws NotImplementedException, ServiceException, Exception{

  96.         return transazione.getIdTransazione();
  97.     }
  98.    
  99.     @Override
  100.     public Transazione get(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject, String id, org.openspcoop2.generic_project.beans.IDMappingBehaviour idMappingResolutionBehaviour) throws NotFoundException, MultipleResultException, NotImplementedException, ServiceException,Exception {
  101.         Object id_transazione = this.findIdTransazione(jdbcProperties, log, connection, sqlQueryObject, id, true, true);
  102.         return this.getEngine(jdbcProperties, log, connection, sqlQueryObject, id_transazione,idMappingResolutionBehaviour);
  103.        
  104.        
  105.     }
  106.    
  107.     @Override
  108.     public boolean exists(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject, String id) throws MultipleResultException, NotImplementedException, ServiceException,Exception {

  109.         Object id_transazione = this.findIdTransazione(jdbcProperties, log, connection, sqlQueryObject, id, false, true);
  110.         return id_transazione != null;  
  111.        
  112.     }
  113.    
  114.     @Override
  115.     public List<String> findAllIds(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject, JDBCPaginatedExpression expression, org.openspcoop2.generic_project.beans.IDMappingBehaviour idMappingResolutionBehaviour) throws NotImplementedException, ServiceException,Exception {

  116.         List<String> list = new ArrayList<>();

  117.         List<Object> ids = this._findAllObjectIds(jdbcProperties, log, connection, sqlQueryObject, expression);

  118.         for(Object id: ids) {
  119.             list.add((String)id);
  120.         }

  121.         return list;
  122.        
  123.     }
  124.    
  125.     private static boolean efficiente = true;    
  126.     public static boolean isEfficiente() {
  127.         return efficiente;
  128.     }
  129.     public static void setEfficiente(boolean efficiente) {
  130.         JDBCTransazioneServiceSearchImpl.efficiente = efficiente;
  131.     }
  132.     @Override
  133.     public List<Transazione> findAll(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject, JDBCPaginatedExpression expression, org.openspcoop2.generic_project.beans.IDMappingBehaviour idMappingResolutionBehaviour) throws NotImplementedException, ServiceException,Exception {

  134.         List<Transazione> list = new ArrayList<Transazione>();
  135.        
  136.         boolean soloColonneIndicizzateFullIndexSearch = TransazioniIndexUtils.isEnabledSoloColonneIndicizzateFullIndexSearch(expression);
  137.         boolean soloColonneIndicizzateFullIndexStats = TransazioniIndexUtils.isEnabledSoloColonneIndicizzateFullIndexStats(expression);

  138.         if(efficiente || soloColonneIndicizzateFullIndexSearch || soloColonneIndicizzateFullIndexStats) {
  139.        
  140.             List<IField> fields = new ArrayList<IField>();
  141.             if(soloColonneIndicizzateFullIndexSearch){
  142.                 fields = TransazioniIndexUtils.LISTA_COLONNE_INDEX_TR_SEARCH;
  143.             }
  144.             else if(soloColonneIndicizzateFullIndexStats){
  145.                 fields = TransazioniIndexUtils.LISTA_COLONNE_INDEX_TR_STATS;
  146.             }
  147.             else {
  148.                 fields.add(Transazione.model().ID_TRANSAZIONE);
  149.                 fields.add(Transazione.model().STATO);
  150.                 fields.add(Transazione.model().RUOLO_TRANSAZIONE);
  151.                 fields.add(Transazione.model().ESITO);
  152.                 fields.add(Transazione.model().ESITO_SINCRONO);
  153.                 fields.add(Transazione.model().CONSEGNE_MULTIPLE_IN_CORSO);
  154.                 fields.add(Transazione.model().ESITO_CONTESTO);
  155.                 fields.add(Transazione.model().PROTOCOLLO);
  156.                 fields.add(Transazione.model().TIPO_RICHIESTA);
  157.                 fields.add(Transazione.model().CODICE_RISPOSTA_INGRESSO);
  158.                 fields.add(Transazione.model().CODICE_RISPOSTA_USCITA);
  159.                 fields.add(Transazione.model().DATA_ACCETTAZIONE_RICHIESTA);
  160.                 fields.add(Transazione.model().DATA_INGRESSO_RICHIESTA);
  161.                 fields.add(Transazione.model().DATA_INGRESSO_RICHIESTA_STREAM);
  162.                 fields.add(Transazione.model().DATA_USCITA_RICHIESTA);
  163.                 fields.add(Transazione.model().DATA_USCITA_RICHIESTA_STREAM);
  164.                 fields.add(Transazione.model().DATA_ACCETTAZIONE_RISPOSTA);
  165.                 fields.add(Transazione.model().DATA_INGRESSO_RISPOSTA);
  166.                 fields.add(Transazione.model().DATA_INGRESSO_RISPOSTA_STREAM);
  167.                 fields.add(Transazione.model().DATA_USCITA_RISPOSTA);
  168.                 fields.add(Transazione.model().DATA_USCITA_RISPOSTA_STREAM);
  169.                 fields.add(Transazione.model().RICHIESTA_INGRESSO_BYTES);
  170.                 fields.add(Transazione.model().RICHIESTA_USCITA_BYTES);
  171.                 fields.add(Transazione.model().RISPOSTA_INGRESSO_BYTES);
  172.                 fields.add(Transazione.model().RISPOSTA_USCITA_BYTES);
  173.                 fields.add(Transazione.model().PDD_CODICE);
  174.                 fields.add(Transazione.model().PDD_TIPO_SOGGETTO);
  175.                 fields.add(Transazione.model().PDD_NOME_SOGGETTO);
  176.                 fields.add(Transazione.model().PDD_RUOLO);
  177.                 fields.add(Transazione.model().FAULT_INTEGRAZIONE);
  178.                 fields.add(Transazione.model().FORMATO_FAULT_INTEGRAZIONE);
  179.                 fields.add(Transazione.model().FAULT_COOPERAZIONE);
  180.                 fields.add(Transazione.model().FORMATO_FAULT_COOPERAZIONE);
  181.                 fields.add(Transazione.model().TIPO_SOGGETTO_FRUITORE);
  182.                 fields.add(Transazione.model().NOME_SOGGETTO_FRUITORE);
  183.                 fields.add(Transazione.model().IDPORTA_SOGGETTO_FRUITORE);
  184.                 fields.add(Transazione.model().INDIRIZZO_SOGGETTO_FRUITORE);
  185.                 fields.add(Transazione.model().TIPO_SOGGETTO_EROGATORE);
  186.                 fields.add(Transazione.model().NOME_SOGGETTO_EROGATORE);
  187.                 fields.add(Transazione.model().IDPORTA_SOGGETTO_EROGATORE);
  188.                 fields.add(Transazione.model().INDIRIZZO_SOGGETTO_EROGATORE);
  189.                 fields.add(Transazione.model().ID_MESSAGGIO_RICHIESTA);
  190.                 fields.add(Transazione.model().ID_MESSAGGIO_RISPOSTA);
  191.                 fields.add(Transazione.model().DATA_ID_MSG_RICHIESTA);
  192.                 fields.add(Transazione.model().DATA_ID_MSG_RISPOSTA);
  193.                 fields.add(Transazione.model().PROFILO_COLLABORAZIONE_OP_2);
  194.                 fields.add(Transazione.model().PROFILO_COLLABORAZIONE_PROT);
  195.                 fields.add(Transazione.model().ID_COLLABORAZIONE);
  196.                 fields.add(Transazione.model().URI_ACCORDO_SERVIZIO);
  197.                 fields.add(Transazione.model().TIPO_SERVIZIO);
  198.                 fields.add(Transazione.model().NOME_SERVIZIO);
  199.                 fields.add(Transazione.model().VERSIONE_SERVIZIO);
  200.                 fields.add(Transazione.model().AZIONE);
  201.                 fields.add(Transazione.model().ID_ASINCRONO);
  202.                 fields.add(Transazione.model().TIPO_SERVIZIO_CORRELATO);
  203.                 fields.add(Transazione.model().NOME_SERVIZIO_CORRELATO);
  204.                 fields.add(Transazione.model().HEADER_PROTOCOLLO_RICHIESTA);
  205.                 fields.add(Transazione.model().DIGEST_RICHIESTA);
  206.                 fields.add(Transazione.model().PROTOCOLLO_EXT_INFO_RICHIESTA);
  207.                 fields.add(Transazione.model().HEADER_PROTOCOLLO_RISPOSTA);
  208.                 fields.add(Transazione.model().DIGEST_RISPOSTA);
  209.                 fields.add(Transazione.model().PROTOCOLLO_EXT_INFO_RISPOSTA);
  210.                 fields.add(Transazione.model().TRACCIA_RICHIESTA);
  211.                 fields.add(Transazione.model().TRACCIA_RISPOSTA);
  212.                 fields.add(Transazione.model().DIAGNOSTICI);
  213.                 fields.add(Transazione.model().DIAGNOSTICI_LIST_1);
  214.                 fields.add(Transazione.model().DIAGNOSTICI_LIST_2);
  215.                 fields.add(Transazione.model().DIAGNOSTICI_LIST_EXT);
  216.                 fields.add(Transazione.model().DIAGNOSTICI_EXT);
  217.                 fields.add(Transazione.model().ERROR_LOG);
  218.                 fields.add(Transazione.model().WARNING_LOG);
  219.                 fields.add(Transazione.model().ID_CORRELAZIONE_APPLICATIVA);
  220.                 fields.add(Transazione.model().ID_CORRELAZIONE_APPLICATIVA_RISPOSTA);
  221.                 fields.add(Transazione.model().SERVIZIO_APPLICATIVO_FRUITORE);
  222.                 fields.add(Transazione.model().SERVIZIO_APPLICATIVO_EROGATORE);
  223.                 fields.add(Transazione.model().OPERAZIONE_IM);
  224.                 fields.add(Transazione.model().LOCATION_RICHIESTA);
  225.                 fields.add(Transazione.model().LOCATION_RISPOSTA);
  226.                 fields.add(Transazione.model().NOME_PORTA);
  227.                 fields.add(Transazione.model().CREDENZIALI);
  228.                 fields.add(Transazione.model().LOCATION_CONNETTORE);
  229.                 fields.add(Transazione.model().URL_INVOCAZIONE);
  230.                 fields.add(Transazione.model().TRASPORTO_MITTENTE);
  231.                 fields.add(Transazione.model().TOKEN_ISSUER);
  232.                 fields.add(Transazione.model().TOKEN_CLIENT_ID);
  233.                 fields.add(Transazione.model().TOKEN_SUBJECT);
  234.                 fields.add(Transazione.model().TOKEN_USERNAME);
  235.                 fields.add(Transazione.model().TOKEN_MAIL);
  236.                 fields.add(Transazione.model().TOKEN_INFO);
  237.                 fields.add(Transazione.model().DUPLICATI_RICHIESTA);
  238.                 fields.add(Transazione.model().DUPLICATI_RISPOSTA);
  239.                 fields.add(Transazione.model().CLUSTER_ID);
  240.                 fields.add(Transazione.model().SOCKET_CLIENT_ADDRESS);
  241.                 fields.add(Transazione.model().TRANSPORT_CLIENT_ADDRESS);
  242.                 fields.add(Transazione.model().CLIENT_ADDRESS);
  243.                 fields.add(Transazione.model().EVENTI_GESTIONE);
  244.                 fields.add(Transazione.model().TIPO_API);
  245.                 fields.add(Transazione.model().URI_API);
  246.                 fields.add(Transazione.model().GRUPPI);
  247.             }
  248.            
  249.             List<Map<String, Object>> returnMap = null;
  250.             try{
  251.                  // Il distinct serve solo se ci sono le ricerche con contenuto.
  252.                 // NOTA: il distinct rende le ricerce inefficenti (ed inoltre non e' utilizzabile con campi clob in oracle)
  253.                 boolean distinct = false;
  254.                 ISQLQueryObject sqlQueryObjectCheckJoin = sqlQueryObject.newSQLQueryObject();
  255.                 joinEngine(expression, sqlQueryObjectCheckJoin);
  256.                 distinct = ((SQLQueryObjectCore)sqlQueryObjectCheckJoin).sizeConditions()>0;
  257.                
  258.                 // BUG FIX: Siccome tra le colonne lette ci sono dei CLOB, in oracle non e' consentito utilizzare il DISTINCT.
  259.                 // Per questo motivo se c'e' da usare il distinct viene utilizzato il vecchio metodo
  260.                 if(distinct) {
  261.                     //System.out.println("NON EFFICIENTE");
  262.                    
  263.                     List<Object> ids = this._findAllObjectIds(jdbcProperties, log, connection, sqlQueryObject, expression);
  264.                    
  265.                     for(Object id: ids) {
  266.                         list.add(this.getEngine(jdbcProperties, log, connection, sqlQueryObject, id, idMappingResolutionBehaviour));
  267.                     }
  268.                    
  269.                 }
  270.                 else {
  271.                
  272.                     //System.out.println("EFFICIENTE");
  273.                    
  274.                     returnMap = this.select(jdbcProperties, log, connection, sqlQueryObject, expression, distinct, fields.toArray(new IField[1]));
  275.        
  276.                     for(Map<String, Object> map: returnMap) {
  277.                         list.add((Transazione)this.getTransazioneFetch().fetch(jdbcProperties.getDatabase(), Transazione.model(), map));
  278.                     }
  279.                    
  280.                 }
  281.                    
  282.             }catch(NotFoundException notFound){}
  283.            
  284.         }
  285.         else{
  286.        
  287.             List<Object> ids = this._findAllObjectIds(jdbcProperties, log, connection, sqlQueryObject, expression);
  288.    
  289.             for(Object id: ids) {
  290.                 list.add(this.getEngine(jdbcProperties, log, connection, sqlQueryObject, id, idMappingResolutionBehaviour));
  291.             }
  292.         }
  293.        
  294.         return list;      
  295.        
  296.     }
  297.    
  298.     @Override
  299.     public Transazione find(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject, JDBCExpression expression, org.openspcoop2.generic_project.beans.IDMappingBehaviour idMappingResolutionBehaviour)
  300.         throws NotFoundException, MultipleResultException, NotImplementedException, ServiceException,Exception {

  301.         Object id = this._findObjectId(jdbcProperties, log, connection, sqlQueryObject, expression);
  302.         if(id!=null){
  303.             return this.getEngine(jdbcProperties, log, connection, sqlQueryObject, id, idMappingResolutionBehaviour);
  304.         }else{
  305.             throw new NotFoundException("Entry with id["+id+"] not found");
  306.         }
  307.        
  308.     }
  309.    
  310.     @Override
  311.     public NonNegativeNumber count(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject, JDBCExpression expression) throws NotImplementedException, ServiceException,Exception {
  312.        
  313.         List<Object> listaQuery = org.openspcoop2.generic_project.dao.jdbc.utils.GenericJDBCUtilities.prepareCount(jdbcProperties, log, connection, sqlQueryObject, expression,
  314.                                                 this.getTransazioneFieldConverter(), Transazione.model());
  315.        
  316.         // Il distinct serve solo se ci sono le ricerche con contenuto.
  317.         // NOTA: il distinct rende le ricerce inefficenti (ed inoltre non e' utilizzabile con campi clob in oracle)
  318.         boolean distinct = false;
  319.         ISQLQueryObject sqlQueryObjectCheckJoin = sqlQueryObject.newSQLQueryObject();
  320.         joinEngine(expression, sqlQueryObjectCheckJoin);
  321.         distinct = ((SQLQueryObjectCore)sqlQueryObjectCheckJoin).sizeConditions()>0;
  322.        
  323.         IField countField = Transazione.model().ID_TRANSAZIONE;
  324.         if(!distinct && expression.inUseField(Transazione.model().DATA_INGRESSO_RICHIESTA, true)){
  325.             countField = Transazione.model().DATA_INGRESSO_RICHIESTA; // uso la prima colonna dell'indice (se c'è la data e non è distinct)
  326.         }

  327.         sqlQueryObject.addSelectCountField(this.getTransazioneFieldConverter().toColumn(countField,true),"tot",distinct);
  328.        
  329.         joinEngine(expression,sqlQueryObject);
  330.        
  331.         return org.openspcoop2.generic_project.dao.jdbc.utils.GenericJDBCUtilities.count(jdbcProperties, log, connection, sqlQueryObject, expression,
  332.                                                                             this.getTransazioneFieldConverter(), Transazione.model(),listaQuery);
  333.     }

  334.     @Override
  335.     public InUse inUse(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject, String id) throws NotFoundException, NotImplementedException, ServiceException,Exception {
  336.        
  337.         Object id_transazione = this.findIdTransazione(jdbcProperties, log, connection, sqlQueryObject, id, true, true);
  338.         return this.inUseEngine(jdbcProperties, log, connection, sqlQueryObject, id_transazione);
  339.        
  340.     }

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

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

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

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

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



  515.     // -- ConstructorExpression

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


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

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

  553.     @Override
  554.     public void mappingTableIds(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject, String id, Transazione obj) throws NotFoundException,NotImplementedException,ServiceException,Exception{
  555.         _mappingTableIds(jdbcProperties,log,connection,sqlQueryObject,obj,
  556.                 this.get(jdbcProperties,log,connection,sqlQueryObject,id,null));
  557.     }
  558.    
  559.     @Override
  560.     public void mappingTableIds(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject, long tableId, Transazione obj) throws NotFoundException,NotImplementedException,ServiceException,Exception{
  561.         _mappingTableIds(jdbcProperties,log,connection,sqlQueryObject,obj,
  562.                 this.get(jdbcProperties,log,connection,sqlQueryObject,tableId,null));
  563.     }
  564.     private void _mappingTableIds(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject, Transazione obj, Transazione imgSaved) throws NotFoundException,NotImplementedException,ServiceException,Exception{
  565.         if(imgSaved==null){
  566.             return;
  567.         }
  568.         obj.setId(imgSaved.getId());
  569.         if(obj.getDumpMessaggioList()!=null){
  570.             List<org.openspcoop2.core.transazioni.DumpMessaggio> listObj_ = obj.getDumpMessaggioList();
  571.             for(org.openspcoop2.core.transazioni.DumpMessaggio itemObj_ : listObj_){
  572.                 org.openspcoop2.core.transazioni.DumpMessaggio itemAlreadySaved_ = null;
  573.                 if(imgSaved.getDumpMessaggioList()!=null){
  574.                     List<org.openspcoop2.core.transazioni.DumpMessaggio> listImgSaved_ = imgSaved.getDumpMessaggioList();
  575.                     for(org.openspcoop2.core.transazioni.DumpMessaggio itemImgSaved_ : listImgSaved_){
  576.                         boolean objEqualsToImgSaved_ = false;
  577.                         // TODO verify equals
  578.                         // objEqualsToImgSaved_ = org.openspcoop2.generic_project.utils.Utilities.equals(itemObj_.getXXX(),itemImgSaved_.getXXX()) &&
  579.                         //                                  ...
  580.                         //                                  org.openspcoop2.generic_project.utils.Utilities.equals(itemObj_.getYYY(),itemImgSaved_.getYYY());
  581.                         if(objEqualsToImgSaved_){
  582.                             itemAlreadySaved_=itemImgSaved_;
  583.                             break;
  584.                         }
  585.                     }
  586.                 }
  587.                 if(itemAlreadySaved_!=null){
  588.                     itemObj_.setId(itemAlreadySaved_.getId());
  589.                     if(itemObj_.getMultipartHeaderList()!=null){
  590.                         List<org.openspcoop2.core.transazioni.DumpMultipartHeader> listObj_dumpMessaggio = itemObj_.getMultipartHeaderList();
  591.                         for(org.openspcoop2.core.transazioni.DumpMultipartHeader itemObj_dumpMessaggio : listObj_dumpMessaggio){
  592.                             org.openspcoop2.core.transazioni.DumpMultipartHeader itemAlreadySaved_dumpMessaggio = null;
  593.                             if(itemAlreadySaved_.getMultipartHeaderList()!=null){
  594.                                 List<org.openspcoop2.core.transazioni.DumpMultipartHeader> listImgSaved_dumpMessaggio = itemAlreadySaved_.getMultipartHeaderList();
  595.                                 for(org.openspcoop2.core.transazioni.DumpMultipartHeader itemImgSaved_dumpMessaggio : listImgSaved_dumpMessaggio){
  596.                                     boolean objEqualsToImgSaved_dumpMessaggio = false;
  597.                                     // TODO verify equals
  598.                                     // objEqualsToImgSaved_dumpMessaggio = org.openspcoop2.generic_project.utils.Utilities.equals(itemObj_dumpMessaggio.getXXX(),itemImgSaved_dumpMessaggio.getXXX()) &&
  599.                                     //                                  ...
  600.                                     //                                  org.openspcoop2.generic_project.utils.Utilities.equals(itemObj_dumpMessaggio.getYYY(),itemImgSaved_dumpMessaggio.getYYY());
  601.                                     if(objEqualsToImgSaved_dumpMessaggio){
  602.                                         itemAlreadySaved_dumpMessaggio=itemImgSaved_dumpMessaggio;
  603.                                         break;
  604.                                     }
  605.                                 }
  606.                             }
  607.                             if(itemAlreadySaved_dumpMessaggio!=null){
  608.                                 itemObj_dumpMessaggio.setId(itemAlreadySaved_dumpMessaggio.getId());
  609.                             }
  610.                         }
  611.                     }
  612.                     if(itemObj_.getHeaderTrasportoList()!=null){
  613.                         List<org.openspcoop2.core.transazioni.DumpHeaderTrasporto> listObj_dumpMessaggio = itemObj_.getHeaderTrasportoList();
  614.                         for(org.openspcoop2.core.transazioni.DumpHeaderTrasporto itemObj_dumpMessaggio : listObj_dumpMessaggio){
  615.                             org.openspcoop2.core.transazioni.DumpHeaderTrasporto itemAlreadySaved_dumpMessaggio = null;
  616.                             if(itemAlreadySaved_.getHeaderTrasportoList()!=null){
  617.                                 List<org.openspcoop2.core.transazioni.DumpHeaderTrasporto> listImgSaved_dumpMessaggio = itemAlreadySaved_.getHeaderTrasportoList();
  618.                                 for(org.openspcoop2.core.transazioni.DumpHeaderTrasporto itemImgSaved_dumpMessaggio : listImgSaved_dumpMessaggio){
  619.                                     boolean objEqualsToImgSaved_dumpMessaggio = false;
  620.                                     // TODO verify equals
  621.                                     // objEqualsToImgSaved_dumpMessaggio = org.openspcoop2.generic_project.utils.Utilities.equals(itemObj_dumpMessaggio.getXXX(),itemImgSaved_dumpMessaggio.getXXX()) &&
  622.                                     //                                  ...
  623.                                     //                                  org.openspcoop2.generic_project.utils.Utilities.equals(itemObj_dumpMessaggio.getYYY(),itemImgSaved_dumpMessaggio.getYYY());
  624.                                     if(objEqualsToImgSaved_dumpMessaggio){
  625.                                         itemAlreadySaved_dumpMessaggio=itemImgSaved_dumpMessaggio;
  626.                                         break;
  627.                                     }
  628.                                 }
  629.                             }
  630.                             if(itemAlreadySaved_dumpMessaggio!=null){
  631.                                 itemObj_dumpMessaggio.setId(itemAlreadySaved_dumpMessaggio.getId());
  632.                             }
  633.                         }
  634.                     }
  635.                     if(itemObj_.getAllegatoList()!=null){
  636.                         List<org.openspcoop2.core.transazioni.DumpAllegato> listObj_dumpMessaggio = itemObj_.getAllegatoList();
  637.                         for(org.openspcoop2.core.transazioni.DumpAllegato itemObj_dumpMessaggio : listObj_dumpMessaggio){
  638.                             org.openspcoop2.core.transazioni.DumpAllegato itemAlreadySaved_dumpMessaggio = null;
  639.                             if(itemAlreadySaved_.getAllegatoList()!=null){
  640.                                 List<org.openspcoop2.core.transazioni.DumpAllegato> listImgSaved_dumpMessaggio = itemAlreadySaved_.getAllegatoList();
  641.                                 for(org.openspcoop2.core.transazioni.DumpAllegato itemImgSaved_dumpMessaggio : listImgSaved_dumpMessaggio){
  642.                                     boolean objEqualsToImgSaved_dumpMessaggio = false;
  643.                                     // TODO verify equals
  644.                                     // objEqualsToImgSaved_dumpMessaggio = org.openspcoop2.generic_project.utils.Utilities.equals(itemObj_dumpMessaggio.getXXX(),itemImgSaved_dumpMessaggio.getXXX()) &&
  645.                                     //                                  ...
  646.                                     //                                  org.openspcoop2.generic_project.utils.Utilities.equals(itemObj_dumpMessaggio.getYYY(),itemImgSaved_dumpMessaggio.getYYY());
  647.                                     if(objEqualsToImgSaved_dumpMessaggio){
  648.                                         itemAlreadySaved_dumpMessaggio=itemImgSaved_dumpMessaggio;
  649.                                         break;
  650.                                     }
  651.                                 }
  652.                             }
  653.                             if(itemAlreadySaved_dumpMessaggio!=null){
  654.                                 itemObj_dumpMessaggio.setId(itemAlreadySaved_dumpMessaggio.getId());
  655.                                 if(itemObj_dumpMessaggio.getHeaderList()!=null){
  656.                                     List<org.openspcoop2.core.transazioni.DumpHeaderAllegato> listObj_dumpMessaggio_allegato = itemObj_dumpMessaggio.getHeaderList();
  657.                                     for(org.openspcoop2.core.transazioni.DumpHeaderAllegato itemObj_dumpMessaggio_allegato : listObj_dumpMessaggio_allegato){
  658.                                         org.openspcoop2.core.transazioni.DumpHeaderAllegato itemAlreadySaved_dumpMessaggio_allegato = null;
  659.                                         if(itemAlreadySaved_dumpMessaggio.getHeaderList()!=null){
  660.                                             List<org.openspcoop2.core.transazioni.DumpHeaderAllegato> listImgSaved_dumpMessaggio_allegato = itemAlreadySaved_dumpMessaggio.getHeaderList();
  661.                                             for(org.openspcoop2.core.transazioni.DumpHeaderAllegato itemImgSaved_dumpMessaggio_allegato : listImgSaved_dumpMessaggio_allegato){
  662.                                                 boolean objEqualsToImgSaved_dumpMessaggio_allegato = false;
  663.                                                 // TODO verify equals
  664.                                                 // objEqualsToImgSaved_dumpMessaggio_allegato = org.openspcoop2.generic_project.utils.Utilities.equals(itemObj_dumpMessaggio_allegato.getXXX(),itemImgSaved_dumpMessaggio_allegato.getXXX()) &&
  665.                                                 //                                  ...
  666.                                                 //                                  org.openspcoop2.generic_project.utils.Utilities.equals(itemObj_dumpMessaggio_allegato.getYYY(),itemImgSaved_dumpMessaggio_allegato.getYYY());
  667.                                                 if(objEqualsToImgSaved_dumpMessaggio_allegato){
  668.                                                     itemAlreadySaved_dumpMessaggio_allegato=itemImgSaved_dumpMessaggio_allegato;
  669.                                                     break;
  670.                                                 }
  671.                                             }
  672.                                         }
  673.                                         if(itemAlreadySaved_dumpMessaggio_allegato!=null){
  674.                                             itemObj_dumpMessaggio_allegato.setId(itemAlreadySaved_dumpMessaggio_allegato.getId());
  675.                                         }
  676.                                     }
  677.                                 }
  678.                             }
  679.                         }
  680.                     }
  681.                     if(itemObj_.getContenutoList()!=null){
  682.                         List<org.openspcoop2.core.transazioni.DumpContenuto> listObj_dumpMessaggio = itemObj_.getContenutoList();
  683.                         for(org.openspcoop2.core.transazioni.DumpContenuto itemObj_dumpMessaggio : listObj_dumpMessaggio){
  684.                             org.openspcoop2.core.transazioni.DumpContenuto itemAlreadySaved_dumpMessaggio = null;
  685.                             if(itemAlreadySaved_.getContenutoList()!=null){
  686.                                 List<org.openspcoop2.core.transazioni.DumpContenuto> listImgSaved_dumpMessaggio = itemAlreadySaved_.getContenutoList();
  687.                                 for(org.openspcoop2.core.transazioni.DumpContenuto itemImgSaved_dumpMessaggio : listImgSaved_dumpMessaggio){
  688.                                     boolean objEqualsToImgSaved_dumpMessaggio = false;
  689.                                     // TODO verify equals
  690.                                     // objEqualsToImgSaved_dumpMessaggio = org.openspcoop2.generic_project.utils.Utilities.equals(itemObj_dumpMessaggio.getXXX(),itemImgSaved_dumpMessaggio.getXXX()) &&
  691.                                     //                                  ...
  692.                                     //                                  org.openspcoop2.generic_project.utils.Utilities.equals(itemObj_dumpMessaggio.getYYY(),itemImgSaved_dumpMessaggio.getYYY());
  693.                                     if(objEqualsToImgSaved_dumpMessaggio){
  694.                                         itemAlreadySaved_dumpMessaggio=itemImgSaved_dumpMessaggio;
  695.                                         break;
  696.                                     }
  697.                                 }
  698.                             }
  699.                             if(itemAlreadySaved_dumpMessaggio!=null){
  700.                                 itemObj_dumpMessaggio.setId(itemAlreadySaved_dumpMessaggio.getId());
  701.                             }
  702.                         }
  703.                     }
  704.                 }
  705.             }
  706.         }
  707.         if(obj.getTransazioneApplicativoServerList()!=null){
  708.             List<org.openspcoop2.core.transazioni.TransazioneApplicativoServer> listObj_ = obj.getTransazioneApplicativoServerList();
  709.             for(org.openspcoop2.core.transazioni.TransazioneApplicativoServer itemObj_ : listObj_){
  710.                 org.openspcoop2.core.transazioni.TransazioneApplicativoServer itemAlreadySaved_ = null;
  711.                 if(imgSaved.getTransazioneApplicativoServerList()!=null){
  712.                     List<org.openspcoop2.core.transazioni.TransazioneApplicativoServer> listImgSaved_ = imgSaved.getTransazioneApplicativoServerList();
  713.                     for(org.openspcoop2.core.transazioni.TransazioneApplicativoServer itemImgSaved_ : listImgSaved_){
  714.                         boolean objEqualsToImgSaved_ = false;
  715.                         // TODO verify equals
  716.                         // objEqualsToImgSaved_ = org.openspcoop2.generic_project.utils.Utilities.equals(itemObj_.getXXX(),itemImgSaved_.getXXX()) &&
  717.                         //                                  ...
  718.                         //                                  org.openspcoop2.generic_project.utils.Utilities.equals(itemObj_.getYYY(),itemImgSaved_.getYYY());
  719.                         if(objEqualsToImgSaved_){
  720.                             itemAlreadySaved_=itemImgSaved_;
  721.                             break;
  722.                         }
  723.                     }
  724.                 }
  725.                 if(itemAlreadySaved_!=null){
  726.                     itemObj_.setId(itemAlreadySaved_.getId());
  727.                 }
  728.             }
  729.         }
  730.         if(obj.getTransazioneExtendedInfoList()!=null){
  731.             List<org.openspcoop2.core.transazioni.TransazioneExtendedInfo> listObj_ = obj.getTransazioneExtendedInfoList();
  732.             for(org.openspcoop2.core.transazioni.TransazioneExtendedInfo itemObj_ : listObj_){
  733.                 org.openspcoop2.core.transazioni.TransazioneExtendedInfo itemAlreadySaved_ = null;
  734.                 if(imgSaved.getTransazioneExtendedInfoList()!=null){
  735.                     List<org.openspcoop2.core.transazioni.TransazioneExtendedInfo> listImgSaved_ = imgSaved.getTransazioneExtendedInfoList();
  736.                     for(org.openspcoop2.core.transazioni.TransazioneExtendedInfo itemImgSaved_ : listImgSaved_){
  737.                         boolean objEqualsToImgSaved_ = false;
  738.                         // TODO verify equals
  739.                         // objEqualsToImgSaved_ = org.openspcoop2.generic_project.utils.Utilities.equals(itemObj_.getXXX(),itemImgSaved_.getXXX()) &&
  740.                         //                                  ...
  741.                         //                                  org.openspcoop2.generic_project.utils.Utilities.equals(itemObj_.getYYY(),itemImgSaved_.getYYY());
  742.                         if(objEqualsToImgSaved_){
  743.                             itemAlreadySaved_=itemImgSaved_;
  744.                             break;
  745.                         }
  746.                     }
  747.                 }
  748.                 if(itemAlreadySaved_!=null){
  749.                     itemObj_.setId(itemAlreadySaved_.getId());
  750.                 }
  751.             }
  752.         }

  753.         /*
  754.          * TODO: implement code for id mapping
  755.         */

  756.         // Delete this line when you have implemented the method
  757.         int throwNotImplemented = 1;
  758.         if(throwNotImplemented==1){
  759.                 throw new NotImplementedException("NotImplemented");
  760.         }
  761.         // Delete this line when you have implemented the method                
  762.     }
  763.    
  764.     @Override
  765.     public Transazione get(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject, long tableId, org.openspcoop2.generic_project.beans.IDMappingBehaviour idMappingResolutionBehaviour) throws NotFoundException, MultipleResultException, NotImplementedException, ServiceException, Exception {
  766.         throw new NotImplementedException("Table without long id column PK");
  767.     }
  768.    
  769.     protected Transazione getEngine(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject, Object objectId, org.openspcoop2.generic_project.beans.IDMappingBehaviour idMappingResolutionBehaviour) throws NotFoundException, MultipleResultException, NotImplementedException, ServiceException, Exception {
  770.    
  771.         org.openspcoop2.generic_project.dao.jdbc.utils.JDBCPreparedStatementUtilities jdbcUtilities =
  772.                     new org.openspcoop2.generic_project.dao.jdbc.utils.JDBCPreparedStatementUtilities(sqlQueryObject.getTipoDatabaseOpenSPCoop2(), log, connection);
  773.        
  774.         ISQLQueryObject sqlQueryObjectGet = sqlQueryObject.newSQLQueryObject();
  775.                
  776.         Transazione transazione = new Transazione();
  777.        

  778.         // Object transazione
  779.         ISQLQueryObject sqlQueryObjectGet_transazione = sqlQueryObjectGet.newSQLQueryObject();
  780.         sqlQueryObjectGet_transazione.setANDLogicOperator(true);
  781.         sqlQueryObjectGet_transazione.addFromTable(this.getTransazioneFieldConverter().toTable(Transazione.model()));
  782.         sqlQueryObjectGet_transazione.addSelectField(this.getTransazioneFieldConverter().toColumn(Transazione.model().ID_TRANSAZIONE,true));
  783.         sqlQueryObjectGet_transazione.addSelectField(this.getTransazioneFieldConverter().toColumn(Transazione.model().STATO,true));
  784.         sqlQueryObjectGet_transazione.addSelectField(this.getTransazioneFieldConverter().toColumn(Transazione.model().RUOLO_TRANSAZIONE,true));
  785.         sqlQueryObjectGet_transazione.addSelectField(this.getTransazioneFieldConverter().toColumn(Transazione.model().ESITO,true));
  786.         sqlQueryObjectGet_transazione.addSelectField(this.getTransazioneFieldConverter().toColumn(Transazione.model().ESITO_SINCRONO,true));
  787.         sqlQueryObjectGet_transazione.addSelectField(this.getTransazioneFieldConverter().toColumn(Transazione.model().CONSEGNE_MULTIPLE_IN_CORSO,true));
  788.         sqlQueryObjectGet_transazione.addSelectField(this.getTransazioneFieldConverter().toColumn(Transazione.model().ESITO_CONTESTO,true));
  789.         sqlQueryObjectGet_transazione.addSelectField(this.getTransazioneFieldConverter().toColumn(Transazione.model().PROTOCOLLO,true));
  790.         sqlQueryObjectGet_transazione.addSelectField(this.getTransazioneFieldConverter().toColumn(Transazione.model().TIPO_RICHIESTA,true));
  791.         sqlQueryObjectGet_transazione.addSelectField(this.getTransazioneFieldConverter().toColumn(Transazione.model().CODICE_RISPOSTA_INGRESSO,true));
  792.         sqlQueryObjectGet_transazione.addSelectField(this.getTransazioneFieldConverter().toColumn(Transazione.model().CODICE_RISPOSTA_USCITA,true));
  793.         sqlQueryObjectGet_transazione.addSelectField(this.getTransazioneFieldConverter().toColumn(Transazione.model().DATA_ACCETTAZIONE_RICHIESTA,true));
  794.         sqlQueryObjectGet_transazione.addSelectField(this.getTransazioneFieldConverter().toColumn(Transazione.model().DATA_INGRESSO_RICHIESTA,true));
  795.         sqlQueryObjectGet_transazione.addSelectField(this.getTransazioneFieldConverter().toColumn(Transazione.model().DATA_INGRESSO_RICHIESTA_STREAM,true));
  796.         sqlQueryObjectGet_transazione.addSelectField(this.getTransazioneFieldConverter().toColumn(Transazione.model().DATA_USCITA_RICHIESTA,true));
  797.         sqlQueryObjectGet_transazione.addSelectField(this.getTransazioneFieldConverter().toColumn(Transazione.model().DATA_USCITA_RICHIESTA_STREAM,true));
  798.         sqlQueryObjectGet_transazione.addSelectField(this.getTransazioneFieldConverter().toColumn(Transazione.model().DATA_ACCETTAZIONE_RISPOSTA,true));
  799.         sqlQueryObjectGet_transazione.addSelectField(this.getTransazioneFieldConverter().toColumn(Transazione.model().DATA_INGRESSO_RISPOSTA,true));
  800.         sqlQueryObjectGet_transazione.addSelectField(this.getTransazioneFieldConverter().toColumn(Transazione.model().DATA_INGRESSO_RISPOSTA_STREAM,true));
  801.         sqlQueryObjectGet_transazione.addSelectField(this.getTransazioneFieldConverter().toColumn(Transazione.model().DATA_USCITA_RISPOSTA,true));
  802.         sqlQueryObjectGet_transazione.addSelectField(this.getTransazioneFieldConverter().toColumn(Transazione.model().DATA_USCITA_RISPOSTA_STREAM,true));
  803.         sqlQueryObjectGet_transazione.addSelectField(this.getTransazioneFieldConverter().toColumn(Transazione.model().RICHIESTA_INGRESSO_BYTES,true));
  804.         sqlQueryObjectGet_transazione.addSelectField(this.getTransazioneFieldConverter().toColumn(Transazione.model().RICHIESTA_USCITA_BYTES,true));
  805.         sqlQueryObjectGet_transazione.addSelectField(this.getTransazioneFieldConverter().toColumn(Transazione.model().RISPOSTA_INGRESSO_BYTES,true));
  806.         sqlQueryObjectGet_transazione.addSelectField(this.getTransazioneFieldConverter().toColumn(Transazione.model().RISPOSTA_USCITA_BYTES,true));
  807.         sqlQueryObjectGet_transazione.addSelectField(this.getTransazioneFieldConverter().toColumn(Transazione.model().PDD_CODICE,true));
  808.         sqlQueryObjectGet_transazione.addSelectField(this.getTransazioneFieldConverter().toColumn(Transazione.model().PDD_TIPO_SOGGETTO,true));
  809.         sqlQueryObjectGet_transazione.addSelectField(this.getTransazioneFieldConverter().toColumn(Transazione.model().PDD_NOME_SOGGETTO,true));
  810.         sqlQueryObjectGet_transazione.addSelectField(this.getTransazioneFieldConverter().toColumn(Transazione.model().PDD_RUOLO,true));
  811.         sqlQueryObjectGet_transazione.addSelectField(this.getTransazioneFieldConverter().toColumn(Transazione.model().FAULT_INTEGRAZIONE,true));
  812.         sqlQueryObjectGet_transazione.addSelectField(this.getTransazioneFieldConverter().toColumn(Transazione.model().FORMATO_FAULT_INTEGRAZIONE,true));
  813.         sqlQueryObjectGet_transazione.addSelectField(this.getTransazioneFieldConverter().toColumn(Transazione.model().FAULT_COOPERAZIONE,true));
  814.         sqlQueryObjectGet_transazione.addSelectField(this.getTransazioneFieldConverter().toColumn(Transazione.model().FORMATO_FAULT_COOPERAZIONE,true));
  815.         sqlQueryObjectGet_transazione.addSelectField(this.getTransazioneFieldConverter().toColumn(Transazione.model().TIPO_SOGGETTO_FRUITORE,true));
  816.         sqlQueryObjectGet_transazione.addSelectField(this.getTransazioneFieldConverter().toColumn(Transazione.model().NOME_SOGGETTO_FRUITORE,true));
  817.         sqlQueryObjectGet_transazione.addSelectField(this.getTransazioneFieldConverter().toColumn(Transazione.model().IDPORTA_SOGGETTO_FRUITORE,true));
  818.         sqlQueryObjectGet_transazione.addSelectField(this.getTransazioneFieldConverter().toColumn(Transazione.model().INDIRIZZO_SOGGETTO_FRUITORE,true));
  819.         sqlQueryObjectGet_transazione.addSelectField(this.getTransazioneFieldConverter().toColumn(Transazione.model().TIPO_SOGGETTO_EROGATORE,true));
  820.         sqlQueryObjectGet_transazione.addSelectField(this.getTransazioneFieldConverter().toColumn(Transazione.model().NOME_SOGGETTO_EROGATORE,true));
  821.         sqlQueryObjectGet_transazione.addSelectField(this.getTransazioneFieldConverter().toColumn(Transazione.model().IDPORTA_SOGGETTO_EROGATORE,true));
  822.         sqlQueryObjectGet_transazione.addSelectField(this.getTransazioneFieldConverter().toColumn(Transazione.model().INDIRIZZO_SOGGETTO_EROGATORE,true));
  823.         sqlQueryObjectGet_transazione.addSelectField(this.getTransazioneFieldConverter().toColumn(Transazione.model().ID_MESSAGGIO_RICHIESTA,true));
  824.         sqlQueryObjectGet_transazione.addSelectField(this.getTransazioneFieldConverter().toColumn(Transazione.model().ID_MESSAGGIO_RISPOSTA,true));
  825.         sqlQueryObjectGet_transazione.addSelectField(this.getTransazioneFieldConverter().toColumn(Transazione.model().DATA_ID_MSG_RICHIESTA,true));
  826.         sqlQueryObjectGet_transazione.addSelectField(this.getTransazioneFieldConverter().toColumn(Transazione.model().DATA_ID_MSG_RISPOSTA,true));
  827.         sqlQueryObjectGet_transazione.addSelectField(this.getTransazioneFieldConverter().toColumn(Transazione.model().PROFILO_COLLABORAZIONE_OP_2,true));
  828.         sqlQueryObjectGet_transazione.addSelectField(this.getTransazioneFieldConverter().toColumn(Transazione.model().PROFILO_COLLABORAZIONE_PROT,true));
  829.         sqlQueryObjectGet_transazione.addSelectField(this.getTransazioneFieldConverter().toColumn(Transazione.model().ID_COLLABORAZIONE,true));
  830.         sqlQueryObjectGet_transazione.addSelectField(this.getTransazioneFieldConverter().toColumn(Transazione.model().URI_ACCORDO_SERVIZIO,true));
  831.         sqlQueryObjectGet_transazione.addSelectField(this.getTransazioneFieldConverter().toColumn(Transazione.model().TIPO_SERVIZIO,true));
  832.         sqlQueryObjectGet_transazione.addSelectField(this.getTransazioneFieldConverter().toColumn(Transazione.model().NOME_SERVIZIO,true));
  833.         sqlQueryObjectGet_transazione.addSelectField(this.getTransazioneFieldConverter().toColumn(Transazione.model().VERSIONE_SERVIZIO,true));
  834.         sqlQueryObjectGet_transazione.addSelectField(this.getTransazioneFieldConverter().toColumn(Transazione.model().AZIONE,true));
  835.         sqlQueryObjectGet_transazione.addSelectField(this.getTransazioneFieldConverter().toColumn(Transazione.model().ID_ASINCRONO,true));
  836.         sqlQueryObjectGet_transazione.addSelectField(this.getTransazioneFieldConverter().toColumn(Transazione.model().TIPO_SERVIZIO_CORRELATO,true));
  837.         sqlQueryObjectGet_transazione.addSelectField(this.getTransazioneFieldConverter().toColumn(Transazione.model().NOME_SERVIZIO_CORRELATO,true));
  838.         sqlQueryObjectGet_transazione.addSelectField(this.getTransazioneFieldConverter().toColumn(Transazione.model().HEADER_PROTOCOLLO_RICHIESTA,true));
  839.         sqlQueryObjectGet_transazione.addSelectField(this.getTransazioneFieldConverter().toColumn(Transazione.model().DIGEST_RICHIESTA,true));
  840.         sqlQueryObjectGet_transazione.addSelectField(this.getTransazioneFieldConverter().toColumn(Transazione.model().PROTOCOLLO_EXT_INFO_RICHIESTA,true));
  841.         sqlQueryObjectGet_transazione.addSelectField(this.getTransazioneFieldConverter().toColumn(Transazione.model().HEADER_PROTOCOLLO_RISPOSTA,true));
  842.         sqlQueryObjectGet_transazione.addSelectField(this.getTransazioneFieldConverter().toColumn(Transazione.model().DIGEST_RISPOSTA,true));
  843.         sqlQueryObjectGet_transazione.addSelectField(this.getTransazioneFieldConverter().toColumn(Transazione.model().PROTOCOLLO_EXT_INFO_RISPOSTA,true));
  844.         sqlQueryObjectGet_transazione.addSelectField(this.getTransazioneFieldConverter().toColumn(Transazione.model().TRACCIA_RICHIESTA,true));
  845.         sqlQueryObjectGet_transazione.addSelectField(this.getTransazioneFieldConverter().toColumn(Transazione.model().TRACCIA_RISPOSTA,true));
  846.         sqlQueryObjectGet_transazione.addSelectField(this.getTransazioneFieldConverter().toColumn(Transazione.model().DIAGNOSTICI,true));
  847.         sqlQueryObjectGet_transazione.addSelectField(this.getTransazioneFieldConverter().toColumn(Transazione.model().DIAGNOSTICI_LIST_1,true));
  848.         sqlQueryObjectGet_transazione.addSelectField(this.getTransazioneFieldConverter().toColumn(Transazione.model().DIAGNOSTICI_LIST_2,true));
  849.         sqlQueryObjectGet_transazione.addSelectField(this.getTransazioneFieldConverter().toColumn(Transazione.model().DIAGNOSTICI_LIST_EXT,true));
  850.         sqlQueryObjectGet_transazione.addSelectField(this.getTransazioneFieldConverter().toColumn(Transazione.model().DIAGNOSTICI_EXT,true));
  851.         sqlQueryObjectGet_transazione.addSelectField(this.getTransazioneFieldConverter().toColumn(Transazione.model().ERROR_LOG,true));
  852.         sqlQueryObjectGet_transazione.addSelectField(this.getTransazioneFieldConverter().toColumn(Transazione.model().WARNING_LOG,true));
  853.         sqlQueryObjectGet_transazione.addSelectField(this.getTransazioneFieldConverter().toColumn(Transazione.model().ID_CORRELAZIONE_APPLICATIVA,true));
  854.         sqlQueryObjectGet_transazione.addSelectField(this.getTransazioneFieldConverter().toColumn(Transazione.model().ID_CORRELAZIONE_APPLICATIVA_RISPOSTA,true));
  855.         sqlQueryObjectGet_transazione.addSelectField(this.getTransazioneFieldConverter().toColumn(Transazione.model().SERVIZIO_APPLICATIVO_FRUITORE,true));
  856.         sqlQueryObjectGet_transazione.addSelectField(this.getTransazioneFieldConverter().toColumn(Transazione.model().SERVIZIO_APPLICATIVO_EROGATORE,true));
  857.         sqlQueryObjectGet_transazione.addSelectField(this.getTransazioneFieldConverter().toColumn(Transazione.model().OPERAZIONE_IM,true));
  858.         sqlQueryObjectGet_transazione.addSelectField(this.getTransazioneFieldConverter().toColumn(Transazione.model().LOCATION_RICHIESTA,true));
  859.         sqlQueryObjectGet_transazione.addSelectField(this.getTransazioneFieldConverter().toColumn(Transazione.model().LOCATION_RISPOSTA,true));
  860.         sqlQueryObjectGet_transazione.addSelectField(this.getTransazioneFieldConverter().toColumn(Transazione.model().NOME_PORTA,true));
  861.         sqlQueryObjectGet_transazione.addSelectField(this.getTransazioneFieldConverter().toColumn(Transazione.model().CREDENZIALI,true));
  862.         sqlQueryObjectGet_transazione.addSelectField(this.getTransazioneFieldConverter().toColumn(Transazione.model().LOCATION_CONNETTORE,true));
  863.         sqlQueryObjectGet_transazione.addSelectField(this.getTransazioneFieldConverter().toColumn(Transazione.model().URL_INVOCAZIONE,true));
  864.         sqlQueryObjectGet_transazione.addSelectField(this.getTransazioneFieldConverter().toColumn(Transazione.model().TRASPORTO_MITTENTE,true));
  865.         sqlQueryObjectGet_transazione.addSelectField(this.getTransazioneFieldConverter().toColumn(Transazione.model().TOKEN_ISSUER,true));
  866.         sqlQueryObjectGet_transazione.addSelectField(this.getTransazioneFieldConverter().toColumn(Transazione.model().TOKEN_CLIENT_ID,true));
  867.         sqlQueryObjectGet_transazione.addSelectField(this.getTransazioneFieldConverter().toColumn(Transazione.model().TOKEN_SUBJECT,true));
  868.         sqlQueryObjectGet_transazione.addSelectField(this.getTransazioneFieldConverter().toColumn(Transazione.model().TOKEN_USERNAME,true));
  869.         sqlQueryObjectGet_transazione.addSelectField(this.getTransazioneFieldConverter().toColumn(Transazione.model().TOKEN_MAIL,true));
  870.         sqlQueryObjectGet_transazione.addSelectField(this.getTransazioneFieldConverter().toColumn(Transazione.model().TOKEN_INFO,true));
  871.         sqlQueryObjectGet_transazione.addSelectField(this.getTransazioneFieldConverter().toColumn(Transazione.model().TEMPI_ELABORAZIONE,true));
  872.         sqlQueryObjectGet_transazione.addSelectField(this.getTransazioneFieldConverter().toColumn(Transazione.model().DUPLICATI_RICHIESTA,true));
  873.         sqlQueryObjectGet_transazione.addSelectField(this.getTransazioneFieldConverter().toColumn(Transazione.model().DUPLICATI_RISPOSTA,true));
  874.         sqlQueryObjectGet_transazione.addSelectField(this.getTransazioneFieldConverter().toColumn(Transazione.model().CLUSTER_ID,true));
  875.         sqlQueryObjectGet_transazione.addSelectField(this.getTransazioneFieldConverter().toColumn(Transazione.model().SOCKET_CLIENT_ADDRESS,true));
  876.         sqlQueryObjectGet_transazione.addSelectField(this.getTransazioneFieldConverter().toColumn(Transazione.model().TRANSPORT_CLIENT_ADDRESS,true));
  877.         sqlQueryObjectGet_transazione.addSelectField(this.getTransazioneFieldConverter().toColumn(Transazione.model().CLIENT_ADDRESS,true));
  878.         sqlQueryObjectGet_transazione.addSelectField(this.getTransazioneFieldConverter().toColumn(Transazione.model().EVENTI_GESTIONE,true));
  879.         sqlQueryObjectGet_transazione.addSelectField(this.getTransazioneFieldConverter().toColumn(Transazione.model().TIPO_API,true));
  880.         sqlQueryObjectGet_transazione.addSelectField(this.getTransazioneFieldConverter().toColumn(Transazione.model().URI_API,true));
  881.         sqlQueryObjectGet_transazione.addSelectField(this.getTransazioneFieldConverter().toColumn(Transazione.model().GRUPPI,true));
  882.        
  883.         sqlQueryObjectGet_transazione.addWhereCondition(this.getTransazioneFieldConverter().toColumn(Transazione.model().ID_TRANSAZIONE,true)+"=?");

  884.         // Get transazione
  885.         transazione = (Transazione) jdbcUtilities.executeQuerySingleResult(sqlQueryObjectGet_transazione.createSQLQuery(), jdbcProperties.isShowSql(), Transazione.model(), this.getTransazioneFetch(),
  886.                 new JDBCObject(objectId,String.class));

  887.         return transazione;  
  888.    
  889.     }
  890.    
  891.     @Override
  892.     public boolean exists(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject, long tableId) throws MultipleResultException, NotImplementedException, ServiceException, Exception {
  893.         throw new NotImplementedException("Table without long id column PK");
  894.     }
  895.    
  896.     protected boolean _exists(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject, Object objectId) throws MultipleResultException, NotImplementedException, ServiceException, Exception {
  897.    
  898.         org.openspcoop2.generic_project.dao.jdbc.utils.JDBCPreparedStatementUtilities jdbcUtilities =
  899.                     new org.openspcoop2.generic_project.dao.jdbc.utils.JDBCPreparedStatementUtilities(sqlQueryObject.getTipoDatabaseOpenSPCoop2(), log, connection);
  900.                
  901.         boolean existsTransazione = false;

  902.         sqlQueryObject = sqlQueryObject.newSQLQueryObject();
  903.         sqlQueryObject.setANDLogicOperator(true);

  904.         sqlQueryObject.addFromTable(this.getTransazioneFieldConverter().toTable(Transazione.model()));
  905.         sqlQueryObject.addSelectField(this.getTransazioneFieldConverter().toColumn(Transazione.model().ID_TRANSAZIONE,true));
  906.         sqlQueryObject.addWhereCondition(this.getTransazioneFieldConverter().toColumn(Transazione.model().ID_TRANSAZIONE,true)+"=?");

  907.         // Exists transazione
  908.         existsTransazione = jdbcUtilities.exists(sqlQueryObject.createSQLQuery(), jdbcProperties.isShowSql(),
  909.                 new JDBCObject(objectId,String.class));

  910.         return existsTransazione;
  911.    
  912.     }
  913.    
  914.     private void joinEngine(IExpression expression, ISQLQueryObject sqlQueryObject) throws NotImplementedException, ServiceException, Exception{

  915.         if(expression.inUseModel(Transazione.model().TRANSAZIONE_APPLICATIVO_SERVER,false)){
  916.             String tableName1 = this.getTransazioneFieldConverter().toTable(Transazione.model().TRANSAZIONE_APPLICATIVO_SERVER);
  917.             String tableName2 = this.getTransazioneFieldConverter().toTable(Transazione.model());
  918.             sqlQueryObject.addWhereCondition(tableName1+".id_transazione="+tableName2+".id");
  919.         }
  920.        
  921.        
  922.        
  923.         boolean joinTransazioniRequired = false;
  924.         if(expression.inUseModel(Transazione.model().DUMP_MESSAGGIO.ALLEGATO,false)){
  925.             String tableName1 = this.getTransazioneFieldConverter().toTable(Transazione.model().DUMP_MESSAGGIO.ALLEGATO);
  926.             String tableName2 = this.getTransazioneFieldConverter().toTable(Transazione.model().DUMP_MESSAGGIO);
  927.             sqlQueryObject.addWhereCondition(tableName1+".id_messaggio="+tableName2+".id");
  928.             joinTransazioniRequired = true;
  929.         }
  930.         if(expression.inUseModel(Transazione.model().DUMP_MESSAGGIO.ALLEGATO.HEADER,false)){
  931.             String tableName1 = this.getTransazioneFieldConverter().toTable(Transazione.model().DUMP_MESSAGGIO.ALLEGATO.HEADER);
  932.             String tableName2 = this.getTransazioneFieldConverter().toTable(Transazione.model().DUMP_MESSAGGIO.ALLEGATO);
  933.             sqlQueryObject.addWhereCondition(tableName1+".id_allegato="+tableName2+".id");
  934.             joinTransazioniRequired = true;
  935.         }
  936.         if(expression.inUseModel(Transazione.model().DUMP_MESSAGGIO.HEADER_TRASPORTO,false)){
  937.             String tableName1 = this.getTransazioneFieldConverter().toTable(Transazione.model().DUMP_MESSAGGIO.HEADER_TRASPORTO);
  938.             String tableName2 = this.getTransazioneFieldConverter().toTable(Transazione.model().DUMP_MESSAGGIO);
  939.             sqlQueryObject.addWhereCondition(tableName1+".id_messaggio="+tableName2+".id");
  940.             joinTransazioniRequired = true;
  941.         }
  942.         if(expression.inUseModel(Transazione.model().DUMP_MESSAGGIO.MULTIPART_HEADER,false)){
  943.             String tableName1 = this.getTransazioneFieldConverter().toTable(Transazione.model().DUMP_MESSAGGIO.MULTIPART_HEADER);
  944.             String tableName2 = this.getTransazioneFieldConverter().toTable(Transazione.model().DUMP_MESSAGGIO);
  945.             sqlQueryObject.addWhereCondition(tableName1+".id_messaggio="+tableName2+".id");
  946.             joinTransazioniRequired = true;
  947.         }
  948.        
  949.         List<String> tableWithAlias = AliasTableRicerchePersonalizzate.addFromTable(expression, sqlQueryObject, this.getFieldConverter());
  950.         boolean useDumpContenuto = false;
  951.         if(tableWithAlias!=null && tableWithAlias.size()>0){
  952.             useDumpContenuto = true;
  953.             String tableName2 = this.getTransazioneFieldConverter().toTable(Transazione.model().DUMP_MESSAGGIO);
  954.             for (String aliasTable : tableWithAlias) {
  955.                 sqlQueryObject.addWhereCondition(aliasTable+".id_messaggio="+tableName2+".id");
  956.             }
  957.         }
  958.        
  959.         // per le ricerche puntuali sul tipo/nome
  960.         if(expression.inUseField(Transazione.model().DUMP_MESSAGGIO.CONTENUTO.NOME,false)){
  961.             useDumpContenuto = true;
  962.             String tableName1 = this.getTransazioneFieldConverter().toTable(Transazione.model().DUMP_MESSAGGIO.CONTENUTO);
  963.             String tableName2 = this.getTransazioneFieldConverter().toTable(Transazione.model().DUMP_MESSAGGIO);
  964.             sqlQueryObject.addWhereCondition(tableName1+".id_messaggio="+tableName2+".id");
  965.         }
  966.    


  967.         if(expression.inUseModel(Transazione.model().DUMP_MESSAGGIO.ALLEGATO,false)){
  968.             if(expression.inUseModel(Transazione.model().DUMP_MESSAGGIO,false)==false){
  969.                 sqlQueryObject.addFromTable(this.getTransazioneFieldConverter().toTable(Transazione.model().DUMP_MESSAGGIO));
  970.             }
  971.         }
  972.         if(expression.inUseModel(Transazione.model().DUMP_MESSAGGIO.ALLEGATO.HEADER,false)){
  973.             if(expression.inUseModel(Transazione.model().DUMP_MESSAGGIO.ALLEGATO,false)==false){
  974.                 sqlQueryObject.addFromTable(this.getTransazioneFieldConverter().toTable(Transazione.model().DUMP_MESSAGGIO.ALLEGATO));
  975.             }
  976.         }
  977.         if(expression.inUseModel(Transazione.model().DUMP_MESSAGGIO.HEADER_TRASPORTO,false)){
  978.             if(expression.inUseModel(Transazione.model().DUMP_MESSAGGIO,false)==false){
  979.                 sqlQueryObject.addFromTable(this.getTransazioneFieldConverter().toTable(Transazione.model().DUMP_MESSAGGIO));
  980.             }
  981.         }
  982.         if(expression.inUseModel(Transazione.model().DUMP_MESSAGGIO.MULTIPART_HEADER,false)){
  983.             if(expression.inUseModel(Transazione.model().DUMP_MESSAGGIO,false)==false){
  984.                 sqlQueryObject.addFromTable(this.getTransazioneFieldConverter().toTable(Transazione.model().DUMP_MESSAGGIO));
  985.             }
  986.         }
  987.         if(useDumpContenuto){
  988.             if(expression.inUseModel(Transazione.model().DUMP_MESSAGGIO,false)==false){
  989.                 sqlQueryObject.addFromTable(this.getTransazioneFieldConverter().toTable(Transazione.model().DUMP_MESSAGGIO));
  990.             }
  991.             joinTransazioniRequired = true;
  992.         }
  993.        
  994.         if(joinTransazioniRequired || expression.inUseModel(Transazione.model().DUMP_MESSAGGIO,false)){
  995.             String tableName1 = this.getTransazioneFieldConverter().toTable(Transazione.model().DUMP_MESSAGGIO);
  996.             String tableName2 = this.getTransazioneFieldConverter().toTable(Transazione.model());
  997.             sqlQueryObject.addWhereCondition(tableName1+".id_transazione="+tableName2+".id");
  998.         }

  999.     }

  1000.     protected java.util.List<Object> getRootTablePrimaryKeyValuesEngine(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject, String id) throws NotFoundException, ServiceException, NotImplementedException, Exception{
  1001.         // Identificativi
  1002.         java.util.List<Object> rootTableIdValues = new java.util.ArrayList<>();
  1003.         Object objectId = this.findIdTransazione(jdbcProperties, log, connection, sqlQueryObject.newSQLQueryObject(), id, true, false);
  1004.         rootTableIdValues.add(objectId);
  1005.         return rootTableIdValues;
  1006.     }
  1007.    
  1008.     protected Map<String, List<IField>> getMapTableToPKColumnEngine() throws NotImplementedException, Exception{
  1009.    
  1010.         TransazioneFieldConverter converter = this.getTransazioneFieldConverter();
  1011.         Map<String, List<IField>> mapTableToPKColumn = new java.util.HashMap<>();
  1012.         UtilsTemplate<IField> utilities = new UtilsTemplate<>();

  1013.         // TODO: Define the columns used to identify the primary key
  1014.         //        If a table doesn't have a primary key, don't add it to this map

  1015.         // Transazione.model()
  1016.         mapTableToPKColumn.put(converter.toTable(Transazione.model()),
  1017.             utilities.newList(
  1018.                 new CustomField("id", String.class, "id", converter.toTable(Transazione.model()))
  1019.             ));

  1020.         // Transazione.model().DUMP_MESSAGGIO
  1021.         mapTableToPKColumn.put(converter.toTable(Transazione.model().DUMP_MESSAGGIO),
  1022.             utilities.newList(
  1023.                 new CustomField("id", Long.class, "id", converter.toTable(Transazione.model().DUMP_MESSAGGIO))
  1024.             ));

  1025.         // Transazione.model().DUMP_MESSAGGIO.ALLEGATO
  1026.         mapTableToPKColumn.put(converter.toTable(Transazione.model().DUMP_MESSAGGIO.ALLEGATO),
  1027.             utilities.newList(
  1028.                 new CustomField("id", Long.class, "id", converter.toTable(Transazione.model().DUMP_MESSAGGIO.ALLEGATO))
  1029.             ));

  1030.         // Transazione.model().DUMP_MESSAGGIO.CONTENUTO
  1031.         mapTableToPKColumn.put(converter.toTable(Transazione.model().DUMP_MESSAGGIO.CONTENUTO),
  1032.             utilities.newList(
  1033.                 new CustomField("id", Long.class, "id", converter.toTable(Transazione.model().DUMP_MESSAGGIO.CONTENUTO))
  1034.             ));

  1035.         // Transazione.model().DUMP_MESSAGGIO.HEADER_TRASPORTO
  1036.         mapTableToPKColumn.put(converter.toTable(Transazione.model().DUMP_MESSAGGIO.HEADER_TRASPORTO),
  1037.             utilities.newList(
  1038.                 new CustomField("id", Long.class, "id", converter.toTable(Transazione.model().DUMP_MESSAGGIO.HEADER_TRASPORTO))
  1039.             ));

  1040.         return mapTableToPKColumn;      
  1041.     }
  1042.    
  1043.     @Override
  1044.     public List<Long> findAllTableIds(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject, JDBCPaginatedExpression paginatedExpression) throws ServiceException, NotImplementedException, Exception {
  1045.        
  1046.         throw new NotImplementedException("Table without long id column PK");
  1047.        
  1048.     }
  1049.     public List<Object> _findAllObjectIds(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject, JDBCPaginatedExpression paginatedExpression) throws ServiceException, NotImplementedException, Exception {

  1050.         // Il distinct serve solo se ci sono le ricerche con contenuto.
  1051.         // NOTA: il distinct rende le ricerce inefficenti (ed inoltre non e' utilizzabile con campi clob in oracle)
  1052.         boolean distinct = false;
  1053.         ISQLQueryObject sqlQueryObjectCheckJoin = sqlQueryObject.newSQLQueryObject();
  1054.         joinEngine(paginatedExpression, sqlQueryObjectCheckJoin);
  1055.         distinct = ((SQLQueryObjectCore)sqlQueryObjectCheckJoin).sizeConditions()>0;

  1056.         sqlQueryObject.setSelectDistinct(distinct);
  1057.         sqlQueryObject.setANDLogicOperator(true);
  1058.         sqlQueryObject.addSelectField(this.getTransazioneFieldConverter().toTable(Transazione.model())+".id");
  1059.         Class<?> objectIdClass = String.class;      

  1060.         List<Object> listaQuery = org.openspcoop2.generic_project.dao.jdbc.utils.GenericJDBCUtilities.prepareFindAll(jdbcProperties, log, connection, sqlQueryObject, paginatedExpression,
  1061.                                                 this.getTransazioneFieldConverter(), Transazione.model());
  1062.        
  1063.         joinEngine(paginatedExpression,sqlQueryObject);
  1064.        
  1065.         List<Object> listObjects = org.openspcoop2.generic_project.dao.jdbc.utils.GenericJDBCUtilities.findAll(jdbcProperties, log, connection, sqlQueryObject, paginatedExpression,
  1066.                                                                             this.getTransazioneFieldConverter(), Transazione.model(), objectIdClass, listaQuery);
  1067.         return listObjects;
  1068.        
  1069.     }
  1070.    
  1071.     @Override
  1072.     public long findTableId(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject, JDBCExpression expression) throws ServiceException, NotFoundException, MultipleResultException, NotImplementedException, Exception {
  1073.    
  1074.         throw new NotImplementedException("Table without long id column PK");
  1075.        
  1076.     }
  1077.    
  1078.     public Object _findObjectId(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject, JDBCExpression expression) throws ServiceException, NotFoundException, MultipleResultException, NotImplementedException, Exception {
  1079.        
  1080.         // Il distinct serve solo se ci sono le ricerche con contenuto.
  1081.         // NOTA: il distinct rende le ricerce inefficenti (ed inoltre non e' utilizzabile con campi clob in oracle)
  1082.         boolean distinct = false;
  1083.         ISQLQueryObject sqlQueryObjectCheckJoin = sqlQueryObject.newSQLQueryObject();
  1084.         joinEngine(expression, sqlQueryObjectCheckJoin);
  1085.         distinct = ((SQLQueryObjectCore)sqlQueryObjectCheckJoin).sizeConditions()>0;
  1086.        
  1087.         sqlQueryObject.setSelectDistinct(distinct);
  1088.         sqlQueryObject.setANDLogicOperator(true);
  1089.         sqlQueryObject.addSelectField(this.getTransazioneFieldConverter().toTable(Transazione.model())+".id");
  1090.         Class<?> objectIdClass = String.class;      

  1091.         List<Object> listaQuery = org.openspcoop2.generic_project.dao.jdbc.utils.GenericJDBCUtilities.prepareFind(jdbcProperties, log, connection, sqlQueryObject, expression,
  1092.                                                 this.getTransazioneFieldConverter(), Transazione.model());
  1093.        
  1094.         joinEngine(expression,sqlQueryObject);

  1095.         Object res = org.openspcoop2.generic_project.dao.jdbc.utils.GenericJDBCUtilities.find(jdbcProperties, log, connection, sqlQueryObject, expression,
  1096.                                                         this.getTransazioneFieldConverter(), Transazione.model(), objectIdClass, listaQuery);
  1097.         if(res!=null){
  1098.             return res;
  1099.         }
  1100.         else{
  1101.             throw org.openspcoop2.generic_project.dao.jdbc.utils.GenericJDBCUtilities.newNotFoundException();
  1102.         }
  1103.        
  1104.     }

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

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

  1110.         InUse inUse = new InUse();
  1111.         inUse.setInUse(false);
  1112.        
  1113.         /*
  1114.          * TODO: implement code that checks whether the object identified by the id parameter is used by other objects
  1115.         */
  1116.        
  1117.         // Delete this line when you have implemented the method
  1118.         int throwNotImplemented = 1;
  1119.         if(throwNotImplemented==1){
  1120.                 throw new NotImplementedException("NotImplemented");
  1121.         }
  1122.         // Delete this line when you have implemented the method

  1123.         return inUse;

  1124.     }
  1125.    
  1126.     @Override
  1127.     public String findId(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject, long tableId, boolean throwNotFound)
  1128.             throws NotFoundException, ServiceException, NotImplementedException, Exception {
  1129.        
  1130.         throw new NotImplementedException("Table without long id column PK");
  1131.        
  1132.     }

  1133.     @Override
  1134.     public Long findTableId(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject, String id, boolean throwNotFound)
  1135.             throws NotFoundException, ServiceException, NotImplementedException, Exception {
  1136.    
  1137.         throw new NotImplementedException("Table without long id column PK");
  1138.            
  1139.     }
  1140.    
  1141.     @Override
  1142.     public List<List<Object>> nativeQuery(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject,
  1143.                                             String sql,List<Class<?>> returnClassTypes,Object ... param) throws ServiceException,NotFoundException,NotImplementedException,Exception{
  1144.        
  1145.         return org.openspcoop2.generic_project.dao.jdbc.utils.GenericJDBCUtilities.nativeQuery(jdbcProperties, log, connection, sqlQueryObject,
  1146.                                                                                             sql,returnClassTypes,param);
  1147.                                                        
  1148.     }
  1149.    
  1150.     protected Object findIdTransazione(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject,
  1151.             String id, boolean throwNotFound, boolean executeQueryForFound) throws NotFoundException, ServiceException, NotImplementedException, Exception {

  1152.         if(executeQueryForFound){
  1153.        
  1154.             // utile per metodo exists
  1155.            
  1156.             org.openspcoop2.generic_project.dao.jdbc.utils.JDBCPreparedStatementUtilities jdbcUtilities =
  1157.                 new org.openspcoop2.generic_project.dao.jdbc.utils.JDBCPreparedStatementUtilities(sqlQueryObject.getTipoDatabaseOpenSPCoop2(), log, connection);

  1158.             ISQLQueryObject sqlQueryObjectGet = sqlQueryObject.newSQLQueryObject();

  1159.             // Object _transazione
  1160.             sqlQueryObjectGet.addFromTable(this.getTransazioneFieldConverter().toTable(Transazione.model()));
  1161.             sqlQueryObjectGet.addSelectField("id");
  1162.             sqlQueryObjectGet.setANDLogicOperator(true);
  1163.             sqlQueryObjectGet.setSelectDistinct(false); // non serve il distinct, vado gia' puntuale con id di transazione
  1164.             sqlQueryObjectGet.addWhereCondition(this.getTransazioneFieldConverter().toColumn(Transazione.model().ID_TRANSAZIONE,true)+"=?");

  1165.             // Recupero _transazione
  1166.             org.openspcoop2.generic_project.dao.jdbc.utils.JDBCObject [] searchParams_transazione = new org.openspcoop2.generic_project.dao.jdbc.utils.JDBCObject [] {
  1167.                 new org.openspcoop2.generic_project.dao.jdbc.utils.JDBCObject(id,String.class)
  1168.             };
  1169.             String id_transazione = null;
  1170.             try{
  1171.                 id_transazione = (String) jdbcUtilities.executeQuerySingleResult(sqlQueryObjectGet.createSQLQuery(), jdbcProperties.isShowSql(),
  1172.                         String.class, searchParams_transazione);
  1173.             }catch(NotFoundException notFound){
  1174.                 if(throwNotFound){
  1175.                     throw new NotFoundException(notFound);
  1176.                 }
  1177.             }
  1178.             if(id_transazione==null){
  1179.                 if(throwNotFound){
  1180.                     throw org.openspcoop2.generic_project.dao.jdbc.utils.GenericJDBCUtilities.newNotFoundException();
  1181.                 }
  1182.             }
  1183.            
  1184.             return id_transazione;
  1185.            
  1186.         }
  1187.         else{
  1188.             return id; // L'id e' anche la PK
  1189.         }
  1190.     }

  1191. }