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().TOKEN_PURPOSE_ID);              
  238.                 fields.add(Transazione.model().DUPLICATI_RICHIESTA);
  239.                 fields.add(Transazione.model().DUPLICATI_RISPOSTA);
  240.                 fields.add(Transazione.model().CLUSTER_ID);
  241.                 fields.add(Transazione.model().SOCKET_CLIENT_ADDRESS);
  242.                 fields.add(Transazione.model().TRANSPORT_CLIENT_ADDRESS);
  243.                 fields.add(Transazione.model().CLIENT_ADDRESS);
  244.                 fields.add(Transazione.model().EVENTI_GESTIONE);
  245.                 fields.add(Transazione.model().TIPO_API);
  246.                 fields.add(Transazione.model().URI_API);
  247.                 fields.add(Transazione.model().GRUPPI);
  248.             }
  249.            
  250.             List<Map<String, Object>> returnMap = null;
  251.             try{
  252.                  // Il distinct serve solo se ci sono le ricerche con contenuto.
  253.                 // NOTA: il distinct rende le ricerce inefficenti (ed inoltre non e' utilizzabile con campi clob in oracle)
  254.                 boolean distinct = false;
  255.                 ISQLQueryObject sqlQueryObjectCheckJoin = sqlQueryObject.newSQLQueryObject();
  256.                 joinEngine(expression, sqlQueryObjectCheckJoin);
  257.                 distinct = ((SQLQueryObjectCore)sqlQueryObjectCheckJoin).sizeConditions()>0;
  258.                
  259.                 // BUG FIX: Siccome tra le colonne lette ci sono dei CLOB, in oracle non e' consentito utilizzare il DISTINCT.
  260.                 // Per questo motivo se c'e' da usare il distinct viene utilizzato il vecchio metodo
  261.                 if(distinct) {
  262.                     //System.out.println("NON EFFICIENTE");
  263.                    
  264.                     List<Object> ids = this._findAllObjectIds(jdbcProperties, log, connection, sqlQueryObject, expression);
  265.                    
  266.                     for(Object id: ids) {
  267.                         list.add(this.getEngine(jdbcProperties, log, connection, sqlQueryObject, id, idMappingResolutionBehaviour));
  268.                     }
  269.                    
  270.                 }
  271.                 else {
  272.                
  273.                     //System.out.println("EFFICIENTE");
  274.                    
  275.                     returnMap = this.select(jdbcProperties, log, connection, sqlQueryObject, expression, distinct, fields.toArray(new IField[1]));
  276.        
  277.                     for(Map<String, Object> map: returnMap) {
  278.                         list.add((Transazione)this.getTransazioneFetch().fetch(jdbcProperties.getDatabase(), Transazione.model(), map));
  279.                     }
  280.                    
  281.                 }
  282.                    
  283.             }catch(NotFoundException notFound){}
  284.            
  285.         }
  286.         else{
  287.        
  288.             List<Object> ids = this._findAllObjectIds(jdbcProperties, log, connection, sqlQueryObject, expression);
  289.    
  290.             for(Object id: ids) {
  291.                 list.add(this.getEngine(jdbcProperties, log, connection, sqlQueryObject, id, idMappingResolutionBehaviour));
  292.             }
  293.         }
  294.        
  295.         return list;      
  296.        
  297.     }
  298.    
  299.     @Override
  300.     public Transazione find(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject, JDBCExpression expression, org.openspcoop2.generic_project.beans.IDMappingBehaviour idMappingResolutionBehaviour)
  301.         throws NotFoundException, MultipleResultException, NotImplementedException, ServiceException,Exception {

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

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

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

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

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

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

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

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



  516.     // -- ConstructorExpression

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


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

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

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

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

  757.         // Delete this line when you have implemented the method
  758.         int throwNotImplemented = 1;
  759.         if(throwNotImplemented==1){
  760.                 throw new NotImplementedException("NotImplemented");
  761.         }
  762.         // Delete this line when you have implemented the method                
  763.     }
  764.    
  765.     @Override
  766.     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 {
  767.         throw new NotImplementedException("Table without long id column PK");
  768.     }
  769.    
  770.     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 {
  771.    
  772.         org.openspcoop2.generic_project.dao.jdbc.utils.JDBCPreparedStatementUtilities jdbcUtilities =
  773.                     new org.openspcoop2.generic_project.dao.jdbc.utils.JDBCPreparedStatementUtilities(sqlQueryObject.getTipoDatabaseOpenSPCoop2(), log, connection);
  774.        
  775.         ISQLQueryObject sqlQueryObjectGet = sqlQueryObject.newSQLQueryObject();
  776.                
  777.         Transazione transazione = new Transazione();
  778.        

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

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

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

  904.         sqlQueryObject = sqlQueryObject.newSQLQueryObject();
  905.         sqlQueryObject.setANDLogicOperator(true);

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

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

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

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


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

  1001.     }

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

  1125.         return inUse;

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

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

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

  1160.             ISQLQueryObject sqlQueryObjectGet = sqlQueryObject.newSQLQueryObject();

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

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

  1193. }