DriverRegistroServiziDB_accordiFindAllDriver.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.registry.driver.db;

  21. import java.sql.Connection;
  22. import java.sql.PreparedStatement;
  23. import java.sql.ResultSet;
  24. import java.sql.Timestamp;
  25. import java.util.ArrayList;
  26. import java.util.List;

  27. import org.openspcoop2.core.commons.DBUtils;
  28. import org.openspcoop2.core.commons.Filtri;
  29. import org.openspcoop2.core.constants.CostantiDB;
  30. import org.openspcoop2.core.constants.ProprietariProtocolProperty;
  31. import org.openspcoop2.core.id.IDAccordo;
  32. import org.openspcoop2.core.id.IDAccordoAzione;
  33. import org.openspcoop2.core.id.IDPortType;
  34. import org.openspcoop2.core.id.IDPortTypeAzione;
  35. import org.openspcoop2.core.id.IDResource;
  36. import org.openspcoop2.core.id.IDSoggetto;
  37. import org.openspcoop2.core.registry.driver.DriverRegistroServiziException;
  38. import org.openspcoop2.core.registry.driver.DriverRegistroServiziNotFound;
  39. import org.openspcoop2.core.registry.driver.FiltroRicercaAccordi;
  40. import org.openspcoop2.core.registry.driver.FiltroRicercaAzioni;
  41. import org.openspcoop2.core.registry.driver.FiltroRicercaOperations;
  42. import org.openspcoop2.core.registry.driver.FiltroRicercaPortTypes;
  43. import org.openspcoop2.core.registry.driver.FiltroRicercaResources;
  44. import org.openspcoop2.utils.jdbc.JDBCUtilities;
  45. import org.openspcoop2.utils.sql.ISQLQueryObject;
  46. import org.openspcoop2.utils.sql.SQLObjectFactory;

  47. /**
  48.  * DriverRegistroServiziDB_accordiFindAllDriver
  49.  *
  50.  *
  51.  * @author Sandra Giangrandi (sandra@link.it)
  52.  * @author Stefano Corallo (corallo@link.it)
  53.  * @author $Author$
  54.  * @version $Rev$, $Date$
  55.  */
  56. public class DriverRegistroServiziDB_accordiFindAllDriver {

  57.     private DriverRegistroServiziDB driver = null;
  58.     private DriverRegistroServiziDB_protocolPropertiesDriver protocolPropertiesDriver = null;
  59.    
  60.     protected DriverRegistroServiziDB_accordiFindAllDriver(DriverRegistroServiziDB driver) {
  61.         this.driver = driver;
  62.         this.protocolPropertiesDriver = new DriverRegistroServiziDB_protocolPropertiesDriver(driver);
  63.     }
  64.    

  65.     protected List<IDAccordo> getAllIdAccordiServizioParteComune(FiltroRicercaAccordi filtroRicerca) throws DriverRegistroServiziException,DriverRegistroServiziNotFound{

  66.         List<IDAccordo> list = new ArrayList<IDAccordo>();
  67.         _fillAllIdAccordiServizioParteComuneEngine("getAllIdAccordiServizioParteComune", filtroRicerca, null, null, null, null, list);
  68.         return list;
  69.    
  70.     }
  71.    
  72.     protected List<IDPortType> getAllIdPortType(FiltroRicercaPortTypes filtroRicerca) throws DriverRegistroServiziException,DriverRegistroServiziNotFound{
  73.        
  74.         List<IDPortType> list = new ArrayList<IDPortType>();
  75.         _fillAllIdAccordiServizioParteComuneEngine("getAllIdPortType", filtroRicerca, filtroRicerca, null, null, null, list);
  76.         return list;
  77.        
  78.     }
  79.    
  80.     protected List<IDPortTypeAzione> getAllIdAzionePortType(FiltroRicercaOperations filtroRicerca) throws DriverRegistroServiziException,DriverRegistroServiziNotFound{
  81.    
  82.         List<IDPortTypeAzione> list = new ArrayList<IDPortTypeAzione>();
  83.         _fillAllIdAccordiServizioParteComuneEngine("getAllIdAzionePortType", filtroRicerca, null, filtroRicerca, null, null, list);
  84.         return list;
  85.        
  86.     }
  87.    
  88.     protected List<IDAccordoAzione> getAllIdAzioneAccordo(FiltroRicercaAzioni filtroRicerca) throws DriverRegistroServiziException,DriverRegistroServiziNotFound{
  89.        
  90.         List<IDAccordoAzione> list = new ArrayList<IDAccordoAzione>();
  91.         _fillAllIdAccordiServizioParteComuneEngine("getAllIdAzioneAccordo", filtroRicerca, null, null, filtroRicerca, null, list);
  92.         return list;
  93.        
  94.     }
  95.    
  96.     protected List<IDResource> getAllIdResource(FiltroRicercaResources filtroRicerca) throws DriverRegistroServiziException,DriverRegistroServiziNotFound{
  97.        
  98.         List<IDResource> list = new ArrayList<IDResource>();
  99.         _fillAllIdAccordiServizioParteComuneEngine("getAllIdResource", filtroRicerca, null, null, null, filtroRicerca, list);
  100.         return list;
  101.        
  102.     }
  103.    
  104.     @SuppressWarnings("unchecked")
  105.     private <T> void _fillAllIdAccordiServizioParteComuneEngine(String nomeMetodo,
  106.             FiltroRicercaAccordi filtroRicercaBase,
  107.             FiltroRicercaPortTypes filtroPT, FiltroRicercaOperations filtroOP, FiltroRicercaAzioni filtroAZ,
  108.             FiltroRicercaResources filtroResource,
  109.             List<T> listReturn) throws DriverRegistroServiziException,DriverRegistroServiziNotFound{

  110.         Connection con = null;
  111.         PreparedStatement stm = null;
  112.         ResultSet rs = null;

  113.         this.driver.logDebug(nomeMetodo+"...");

  114.         if(listReturn==null){
  115.             throw new DriverRegistroServiziException("Lista per collezionare i risultati non definita");
  116.         }
  117.        
  118.         try {
  119.             this.driver.logDebug("operazione atomica = " + this.driver.atomica);
  120.             // prendo la connessione dal pool
  121.             if (this.driver.atomica)
  122.                 con = this.driver.getConnectionFromDatasource(nomeMetodo);
  123.             else
  124.                 con = this.driver.globalConnection;

  125.             ISQLQueryObject sqlQueryObject = SQLObjectFactory.createSQLQueryObject(this.driver.tipoDB);
  126.            
  127.             List<String> tipoSoggettiProtocollo = null;
  128.             try {
  129.                 if(filtroRicercaBase!=null && (filtroRicercaBase.getProtocollo()!=null || (filtroRicercaBase.getProtocolli()!=null && !filtroRicercaBase.getProtocolli().isEmpty()))){
  130.                     tipoSoggettiProtocollo = Filtri.convertToTipiSoggetti(filtroRicercaBase.getProtocollo(), Filtri.convertToString(filtroRicercaBase.getProtocolli()));
  131.                 }
  132.             }catch(Exception e) {
  133.                 throw new DriverRegistroServiziException(e.getMessage(),e);
  134.             }
  135.             boolean searchByTipoSoggetto = (tipoSoggettiProtocollo!=null && tipoSoggettiProtocollo.size()>0);
  136.            
  137.             // from
  138.             sqlQueryObject.addFromTable(CostantiDB.ACCORDI);
  139.             if(filtroRicercaBase!=null){
  140.                 if( searchByTipoSoggetto || filtroRicercaBase.getTipoSoggettoReferente()!=null || filtroRicercaBase.getNomeSoggettoReferente()!=null){
  141.                     sqlQueryObject.addFromTable(this.driver.tabellaSoggetti);
  142.                 }
  143.             }
  144.             if(filtroPT!=null){
  145.                 sqlQueryObject.addFromTable(CostantiDB.PORT_TYPE);
  146.                 sqlQueryObject.addWhereCondition(CostantiDB.ACCORDI+".id="+CostantiDB.PORT_TYPE+".id_accordo");
  147.             }
  148.             if(filtroOP!=null){
  149.                 sqlQueryObject.addFromTable(CostantiDB.PORT_TYPE);
  150.                 sqlQueryObject.addWhereCondition(CostantiDB.ACCORDI+".id="+CostantiDB.PORT_TYPE+".id_accordo");
  151.                 sqlQueryObject.addFromTable(CostantiDB.PORT_TYPE_AZIONI);
  152.                 sqlQueryObject.addWhereCondition(CostantiDB.PORT_TYPE+".id="+CostantiDB.PORT_TYPE_AZIONI+".id_port_type");
  153.             }
  154.             if(filtroAZ!=null){
  155.                 sqlQueryObject.addFromTable(CostantiDB.ACCORDI_AZIONI);
  156.                 sqlQueryObject.addWhereCondition(CostantiDB.ACCORDI+".id="+CostantiDB.ACCORDI_AZIONI+".id_accordo");
  157.             }
  158.             if(filtroResource!=null){
  159.                 sqlQueryObject.addFromTable(CostantiDB.API_RESOURCES);
  160.                 sqlQueryObject.addWhereCondition(CostantiDB.ACCORDI+".id="+CostantiDB.API_RESOURCES+".id_accordo");
  161.             }
  162.             if(filtroRicercaBase!=null){
  163.                 if(filtroRicercaBase.getIdGruppo()!=null && filtroRicercaBase.getIdGruppo().getNome()!=null) {
  164.                     sqlQueryObject.addFromTable(CostantiDB.GRUPPI);
  165.                     sqlQueryObject.addFromTable(CostantiDB.ACCORDI_GRUPPI);
  166.                     sqlQueryObject.addWhereCondition(CostantiDB.GRUPPI+".id="+CostantiDB.ACCORDI_GRUPPI+".id_gruppo");
  167.                     sqlQueryObject.addWhereCondition(CostantiDB.ACCORDI+".id="+CostantiDB.ACCORDI_GRUPPI+".id_accordo");
  168.                 }
  169.             }
  170.            
  171.             // select field
  172.             sqlQueryObject.addSelectAliasField(CostantiDB.ACCORDI,"nome","nomeAccordo");
  173.             sqlQueryObject.addSelectField(CostantiDB.ACCORDI,"versione");
  174.             sqlQueryObject.addSelectField(CostantiDB.ACCORDI,"id_referente");
  175.             if(filtroPT!=null){
  176.                 sqlQueryObject.addSelectAliasField(CostantiDB.PORT_TYPE,"nome","nomePT");
  177.             }
  178.             if(filtroOP!=null){
  179.                 sqlQueryObject.addSelectAliasField(CostantiDB.PORT_TYPE,"nome","nomePT");
  180.                 sqlQueryObject.addSelectAliasField(CostantiDB.PORT_TYPE_AZIONI,"nome","nomeOP");
  181.             }
  182.             if(filtroAZ!=null){
  183.                 sqlQueryObject.addSelectAliasField(CostantiDB.ACCORDI_AZIONI,"nome","nomeAZ");
  184.             }
  185.             if(filtroResource!=null){
  186.                 sqlQueryObject.addSelectAliasField(CostantiDB.API_RESOURCES,"nome","nomeResource");
  187.             }
  188.             sqlQueryObject.setSelectDistinct(true);
  189.            
  190.             // order
  191.             if(filtroRicercaBase!=null && filtroRicercaBase.isOrder()) {
  192.                 sqlQueryObject.addOrderBy("nomeAccordo");
  193.                 sqlQueryObject.addOrderBy("versione");
  194.                 if(searchByTipoSoggetto){
  195.                     sqlQueryObject.addSelectAliasField(this.driver.tabellaSoggetti,"tipo_soggetto","tipoSoggettoReferente");
  196.                     sqlQueryObject.addSelectAliasField(this.driver.tabellaSoggetti,"nome_soggetto","nomeSoggettoReferente");
  197.                     sqlQueryObject.addOrderBy("tipoSoggettoReferente");
  198.                     sqlQueryObject.addOrderBy("nomeSoggettoReferente");
  199.                 }
  200.                 if(filtroPT!=null){
  201.                     sqlQueryObject.addOrderBy("nomePT");
  202.                 }
  203.                 else if(filtroOP!=null){
  204.                     sqlQueryObject.addOrderBy("nomePT");
  205.                     sqlQueryObject.addOrderBy("nomeOP");
  206.                 }
  207.                 else if(filtroAZ!=null){
  208.                     sqlQueryObject.addOrderBy("nomeAZ");
  209.                 }
  210.                 else if(filtroResource!=null){
  211.                     sqlQueryObject.addOrderBy("nomeResource");
  212.                 }
  213.             }
  214.            
  215.             if(filtroRicercaBase!=null){
  216.                 // Filtro Base
  217.                 if(filtroRicercaBase.getMinDate()!=null)
  218.                     sqlQueryObject.addWhereCondition(CostantiDB.ACCORDI+".ora_registrazione > ?");
  219.                 if(filtroRicercaBase.getMaxDate()!=null)
  220.                     sqlQueryObject.addWhereCondition(CostantiDB.ACCORDI+".ora_registrazione < ?");
  221.                 if(filtroRicercaBase.getNomeAccordo()!=null)
  222.                     sqlQueryObject.addWhereCondition(CostantiDB.ACCORDI+".nome = ?");
  223.                 if(filtroRicercaBase.getVersione()!=null)
  224.                     sqlQueryObject.addWhereCondition(CostantiDB.ACCORDI+".versione = ?");
  225.                 if(searchByTipoSoggetto || filtroRicercaBase.getTipoSoggettoReferente()!=null || filtroRicercaBase.getNomeSoggettoReferente()!=null){
  226.                     sqlQueryObject.addWhereCondition(CostantiDB.ACCORDI+".id_referente="+this.driver.tabellaSoggetti+".id");
  227.                     if(filtroRicercaBase.getTipoSoggettoReferente()!=null) {
  228.                         sqlQueryObject.addWhereCondition(this.driver.tabellaSoggetti+".tipo_soggetto=?");
  229.                     }
  230.                     else if(searchByTipoSoggetto) {
  231.                         sqlQueryObject.addWhereINCondition(this.driver.tabellaSoggetti+".tipo_soggetto", true, tipoSoggettiProtocollo.toArray(new String[1]));
  232.                     }
  233.                     if(filtroRicercaBase.getNomeSoggettoReferente()!=null)
  234.                         sqlQueryObject.addWhereCondition(this.driver.tabellaSoggetti+".nome_soggetto=?");
  235.                 }
  236.                 if(filtroRicercaBase.getServiceBinding()!=null)
  237.                     sqlQueryObject.addWhereCondition(CostantiDB.ACCORDI+".service_binding = ?");
  238.                 if(filtroRicercaBase.getIdGruppo()!=null && filtroRicercaBase.getIdGruppo().getNome()!=null) {
  239.                     sqlQueryObject.addWhereCondition(CostantiDB.GRUPPI+".nome = ?");
  240.                 }
  241.                
  242.                 if( (filtroRicercaBase.getIdAccordoCooperazione()!=null &&
  243.                         (filtroRicercaBase.getIdAccordoCooperazione().getNome()!=null ||
  244.                         filtroRicercaBase.getIdAccordoCooperazione().getSoggettoReferente()!=null ||
  245.                         filtroRicercaBase.getIdAccordoCooperazione().getVersione()!=null)) ){
  246.                     ISQLQueryObject sqlQueryObjectASComposti = sqlQueryObject.newSQLQueryObject();
  247.                     sqlQueryObjectASComposti.addFromTable(CostantiDB.ACCORDI_SERVIZI_COMPOSTO);
  248.                     sqlQueryObjectASComposti.addFromTable(CostantiDB.ACCORDI_COOPERAZIONE);
  249.                     sqlQueryObjectASComposti.addSelectField(CostantiDB.ACCORDI_SERVIZI_COMPOSTO+".id");
  250.                     sqlQueryObjectASComposti.setANDLogicOperator(true);
  251.                     sqlQueryObjectASComposti.addWhereCondition(CostantiDB.ACCORDI+".id="+CostantiDB.ACCORDI_SERVIZI_COMPOSTO+".id_accordo");
  252.                     sqlQueryObjectASComposti.addWhereCondition(CostantiDB.ACCORDI_COOPERAZIONE+".id="+CostantiDB.ACCORDI_SERVIZI_COMPOSTO+".id_accordo_cooperazione");
  253.                     if(filtroRicercaBase.getIdAccordoCooperazione().getNome()!=null){
  254.                         sqlQueryObjectASComposti.addWhereCondition(CostantiDB.ACCORDI_COOPERAZIONE+".nome=?");
  255.                     }
  256.                     if(filtroRicercaBase.getIdAccordoCooperazione().getSoggettoReferente()!=null){
  257.                         sqlQueryObjectASComposti.addWhereCondition(CostantiDB.ACCORDI_COOPERAZIONE+".id_referente=?");
  258.                     }
  259.                     if(filtroRicercaBase.getIdAccordoCooperazione().getVersione()!=null){
  260.                         sqlQueryObjectASComposti.addWhereCondition(CostantiDB.ACCORDI_COOPERAZIONE+".versione=?");
  261.                     }
  262.                     sqlQueryObject.addWhereExistsCondition(false, sqlQueryObjectASComposti);
  263.                 }
  264.                 else if(filtroRicercaBase.isServizioComposto()!=null){
  265.                     ISQLQueryObject sqlQueryObjectASComposti = sqlQueryObject.newSQLQueryObject();
  266.                     sqlQueryObjectASComposti.addFromTable(CostantiDB.ACCORDI_SERVIZI_COMPOSTO);
  267.                     sqlQueryObjectASComposti.addSelectField("id");
  268.                     sqlQueryObjectASComposti.setANDLogicOperator(true);
  269.                     sqlQueryObjectASComposti.addWhereCondition(CostantiDB.ACCORDI+".id="+CostantiDB.ACCORDI_SERVIZI_COMPOSTO+".id_accordo");
  270.                     sqlQueryObject.addWhereExistsCondition(!filtroRicercaBase.isServizioComposto(), sqlQueryObjectASComposti);
  271.                 }
  272.                 this.protocolPropertiesDriver.setProtocolPropertiesForSearch(sqlQueryObject, filtroRicercaBase, CostantiDB.ACCORDI);
  273.             }
  274.            
  275.             if(filtroPT!=null){
  276.                 if(filtroPT.getNomePortType()!=null)
  277.                     sqlQueryObject.addWhereCondition(CostantiDB.PORT_TYPE+".nome=?");
  278.                 this.protocolPropertiesDriver.setProtocolPropertiesForSearch(sqlQueryObject, filtroPT, CostantiDB.PORT_TYPE);
  279.             }
  280.            
  281.             if(filtroOP!=null){
  282.                 if(filtroOP.getNomePortType()!=null)
  283.                     sqlQueryObject.addWhereCondition(CostantiDB.PORT_TYPE+".nome=?");
  284.                 this.protocolPropertiesDriver.setProtocolPropertiesForSearch(sqlQueryObject, filtroOP, CostantiDB.PORT_TYPE);
  285.                
  286.                 if(filtroOP.getNomeAzione()!=null)
  287.                     sqlQueryObject.addWhereCondition(CostantiDB.PORT_TYPE_AZIONI+".nome=?");
  288.                 this.protocolPropertiesDriver.setProtocolPropertiesForSearch(sqlQueryObject, filtroOP, CostantiDB.PORT_TYPE_AZIONI);
  289.             }
  290.            
  291.             if(filtroAZ!=null){
  292.                 if(filtroAZ.getNomeAzione()!=null)
  293.                     sqlQueryObject.addWhereCondition(CostantiDB.ACCORDI_AZIONI+".nome=?");
  294.                 this.protocolPropertiesDriver.setProtocolPropertiesForSearch(sqlQueryObject, filtroAZ, CostantiDB.ACCORDI_AZIONI);
  295.             }
  296.            
  297.             if(filtroResource!=null){
  298.                 if(filtroResource.getResourceName()!=null)
  299.                     sqlQueryObject.addWhereCondition(CostantiDB.API_RESOURCES+".nome=?");
  300.                 this.protocolPropertiesDriver.setProtocolPropertiesForSearch(sqlQueryObject, filtroResource, CostantiDB.API_RESOURCES);
  301.             }

  302.             sqlQueryObject.setANDLogicOperator(true);
  303.             String sqlQuery = sqlQueryObject.createSQLQuery();
  304.             this.driver.logDebug("eseguo query : " + sqlQuery );
  305.             stm = con.prepareStatement(sqlQuery);
  306.             int indexStmt = 1;
  307.             if(filtroRicercaBase!=null){
  308.                 if(filtroRicercaBase.getMinDate()!=null){
  309.                     this.driver.logDebug("minDate stmt.setTimestamp("+filtroRicercaBase.getMinDate()+")");
  310.                     stm.setTimestamp(indexStmt, new Timestamp(filtroRicercaBase.getMinDate().getTime()));
  311.                     indexStmt++;
  312.                 }
  313.                 if(filtroRicercaBase.getMaxDate()!=null){
  314.                     this.driver.logDebug("maxDate stmt.setTimestamp("+filtroRicercaBase.getMaxDate()+")");
  315.                     stm.setTimestamp(indexStmt, new Timestamp(filtroRicercaBase.getMaxDate().getTime()));
  316.                     indexStmt++;
  317.                 }  
  318.                 if(filtroRicercaBase.getNomeAccordo()!=null){
  319.                     this.driver.logDebug("nomeAccordo stmt.setString("+filtroRicercaBase.getNomeAccordo()+")");
  320.                     stm.setString(indexStmt, filtroRicercaBase.getNomeAccordo());
  321.                     indexStmt++;
  322.                 }  
  323.                 if(filtroRicercaBase.getVersione()!=null){
  324.                     this.driver.logDebug("versioneAccordo stmt.setString("+filtroRicercaBase.getVersione()+")");
  325.                     stm.setInt(indexStmt, filtroRicercaBase.getVersione());
  326.                     indexStmt++;
  327.                 }  
  328.                 if(filtroRicercaBase.getTipoSoggettoReferente()!=null || filtroRicercaBase.getNomeSoggettoReferente()!=null){
  329.                     if(filtroRicercaBase.getTipoSoggettoReferente()!=null){
  330.                         this.driver.logDebug("tipoSoggettoReferenteAccordo stmt.setString("+filtroRicercaBase.getTipoSoggettoReferente()+")");
  331.                         stm.setString(indexStmt, filtroRicercaBase.getTipoSoggettoReferente());
  332.                         indexStmt++;
  333.                     }
  334.                     if(filtroRicercaBase.getNomeSoggettoReferente()!=null){
  335.                         this.driver.logDebug("nomeSoggettoReferenteAccordo stmt.setString("+filtroRicercaBase.getNomeSoggettoReferente()+")");
  336.                         stm.setString(indexStmt, filtroRicercaBase.getNomeSoggettoReferente());
  337.                         indexStmt++;
  338.                     }
  339.                 }
  340.                 if(filtroRicercaBase.getServiceBinding()!=null) {
  341.                     this.driver.logDebug("serviceBinding stmt.setString("+filtroRicercaBase.getServiceBinding().getValue()+")");
  342.                     stm.setString(indexStmt, filtroRicercaBase.getServiceBinding().getValue());
  343.                     indexStmt++;
  344.                 }
  345.                 if(filtroRicercaBase.getIdGruppo()!=null && filtroRicercaBase.getIdGruppo().getNome()!=null) {
  346.                     this.driver.logDebug("gruppo stmt.setString("+filtroRicercaBase.getIdGruppo().getNome()+")");
  347.                     stm.setString(indexStmt, filtroRicercaBase.getIdGruppo().getNome());
  348.                     indexStmt++;
  349.                 }  
  350.                
  351.                 if(filtroRicercaBase.getIdAccordoCooperazione()!=null &&
  352.                         (filtroRicercaBase.getIdAccordoCooperazione().getNome()!=null ||
  353.                         filtroRicercaBase.getIdAccordoCooperazione().getSoggettoReferente()!=null ||
  354.                         filtroRicercaBase.getIdAccordoCooperazione().getVersione()!=null) ){
  355.                     if(filtroRicercaBase.getIdAccordoCooperazione().getNome()!=null){
  356.                         this.driver.logDebug("nomeAccordoCooperazione stmt.setString("+filtroRicercaBase.getIdAccordoCooperazione().getNome()+")");
  357.                         stm.setString(indexStmt, filtroRicercaBase.getIdAccordoCooperazione().getNome());
  358.                         indexStmt++;
  359.                     }
  360.                     if(filtroRicercaBase.getIdAccordoCooperazione().getSoggettoReferente()!=null){
  361.                         long idReferenteAccordoCooperazione = DBUtils.getIdSoggetto(filtroRicercaBase.getIdAccordoCooperazione().getSoggettoReferente().getNome(),
  362.                                 filtroRicercaBase.getIdAccordoCooperazione().getSoggettoReferente().getTipo(), con, this.driver.tipoDB, this.driver.tabellaSoggetti);
  363.                         this.driver.logDebug("referenteAccordoCooperazione stmt.setLong("+idReferenteAccordoCooperazione+")");
  364.                         stm.setLong(indexStmt, idReferenteAccordoCooperazione);
  365.                         indexStmt++;
  366.                     }
  367.                     if(filtroRicercaBase.getIdAccordoCooperazione().getVersione()!=null){
  368.                         this.driver.logDebug("versioneAccordoCooperazione stmt.setString("+filtroRicercaBase.getIdAccordoCooperazione().getVersione()+")");
  369.                         stm.setInt(indexStmt, filtroRicercaBase.getIdAccordoCooperazione().getVersione());
  370.                         indexStmt++;
  371.                     }
  372.                 }
  373.                
  374.                 this.protocolPropertiesDriver.setProtocolPropertiesForSearch(stm, indexStmt, filtroRicercaBase, ProprietariProtocolProperty.ACCORDO_SERVIZIO_PARTE_COMUNE);
  375.             }
  376.            
  377.             if(filtroPT!=null){
  378.                 if(filtroPT.getNomePortType()!=null){
  379.                     stm.setString(indexStmt, filtroPT.getNomePortType());
  380.                     indexStmt++;
  381.                 }
  382.                 this.protocolPropertiesDriver.setProtocolPropertiesForSearch(stm, indexStmt, filtroPT, ProprietariProtocolProperty.PORT_TYPE);
  383.             }
  384.            
  385.             if(filtroOP!=null){
  386.                 if(filtroOP.getNomePortType()!=null){
  387.                     stm.setString(indexStmt, filtroOP.getNomePortType());
  388.                     indexStmt++;
  389.                 }
  390.                 this.protocolPropertiesDriver.setProtocolPropertiesForSearch(stm, indexStmt, filtroOP, ProprietariProtocolProperty.PORT_TYPE);
  391.                
  392.                 if(filtroOP.getNomeAzione()!=null){
  393.                     stm.setString(indexStmt, filtroOP.getNomeAzione());
  394.                     indexStmt++;
  395.                 }
  396.                 this.protocolPropertiesDriver.setProtocolPropertiesForSearch(stm, indexStmt, filtroOP, ProprietariProtocolProperty.OPERATION);
  397.             }
  398.            
  399.             if(filtroAZ!=null){
  400.                 if(filtroAZ.getNomeAzione()!=null){
  401.                     stm.setString(indexStmt, filtroAZ.getNomeAzione());
  402.                     indexStmt++;
  403.                 }
  404.                 this.protocolPropertiesDriver.setProtocolPropertiesForSearch(stm, indexStmt, filtroAZ, ProprietariProtocolProperty.AZIONE_ACCORDO);
  405.             }
  406.            
  407.             if(filtroResource!=null){
  408.                 if(filtroResource.getResourceName()!=null){
  409.                     stm.setString(indexStmt, filtroResource.getResourceName());
  410.                     indexStmt++;
  411.                 }
  412.                 this.protocolPropertiesDriver.setProtocolPropertiesForSearch(stm, indexStmt, filtroResource, ProprietariProtocolProperty.RESOURCE);
  413.             }
  414.            
  415.             rs = stm.executeQuery();
  416.             while (rs.next()) {
  417.                 long idReferente = rs.getLong("id_referente");
  418.                 IDSoggetto idSoggettoReferente = null;
  419.                 Exception excp = null;
  420.                 if(idReferente>0){
  421.                     try {
  422.                         idSoggettoReferente = this.driver.getIdSoggetto(idReferente,con);
  423.                         if(idSoggettoReferente==null){
  424.                             throw new DriverRegistroServiziNotFound ("non esiste");
  425.                         }
  426.                     }catch(DriverRegistroServiziNotFound notFound) {
  427.                         try{
  428.                             excp = new Exception("Soggetto referente ["+idReferente+"] presente nell'accordo ["+rs.getString("nome")+"] (versione ["+rs.getInt("versione")+"]) non presente?");
  429.                         }finally{
  430.                             try{
  431.                                 if(rs!=null){
  432.                                     rs.close();
  433.                                     rs = null;
  434.                                 }
  435.                             }catch (Exception e) {
  436.                                 // close
  437.                             }
  438.                             try{
  439.                                 if(stm!=null){
  440.                                     stm.close();
  441.                                     stm=null;
  442.                                 }
  443.                             }catch (Exception e) {
  444.                                 // close
  445.                             }
  446.                         }
  447.                     }
  448.                 }
  449.                
  450.                 if(excp!=null) {
  451.                     throw excp;
  452.                 }
  453.                 if(rs==null) {
  454.                     throw new Exception("Ricerca referente non riuscita");
  455.                 }

  456.                 IDAccordo idAccordo = this.driver.idAccordoFactory.getIDAccordoFromValues(rs.getString("nomeAccordo"),idSoggettoReferente,rs.getInt("versione"));
  457.                 if(filtroPT!=null){
  458.                     IDPortType idPT = new IDPortType();
  459.                     idPT.setIdAccordo(idAccordo);
  460.                     idPT.setNome(rs.getString("nomePT"));
  461.                     listReturn.add((T) idPT);  
  462.                 }
  463.                 else if(filtroOP!=null){
  464.                     IDPortTypeAzione idAzione = new IDPortTypeAzione();
  465.                     IDPortType idPT = new IDPortType();
  466.                     idPT.setIdAccordo(idAccordo);
  467.                     idPT.setNome(rs.getString("nomePT"));
  468.                     idAzione.setIdPortType(idPT);
  469.                     idAzione.setNome(rs.getString("nomeOP"));
  470.                     listReturn.add((T) idAzione);  
  471.                 }
  472.                 else if(filtroAZ!=null){
  473.                     IDAccordoAzione idAzione = new IDAccordoAzione();
  474.                     idAzione.setIdAccordo(idAccordo);
  475.                     idAzione.setNome(rs.getString("nomeAZ"));
  476.                     listReturn.add((T) idAzione);  
  477.                 }
  478.                 else if(filtroResource!=null){
  479.                     IDResource idResource = new IDResource();
  480.                     idResource.setIdAccordo(idAccordo);
  481.                     idResource.setNome(rs.getString("nomeResource"));
  482.                     listReturn.add((T) idResource);    
  483.                 }
  484.                 else{
  485.                     listReturn.add((T) idAccordo);  
  486.                 }
  487.             }
  488.             if(listReturn.size()<=0){
  489.                 String msgFiltro = "Elementi non trovati che rispettano il filtro di ricerca selezionato: ";
  490.                 if(filtroPT!=null){
  491.                     throw new DriverRegistroServiziNotFound(msgFiltro+filtroPT.toString());
  492.                 }
  493.                 else if(filtroOP!=null){
  494.                     throw new DriverRegistroServiziNotFound(msgFiltro+filtroOP.toString());
  495.                 }
  496.                 else if(filtroAZ!=null){
  497.                     throw new DriverRegistroServiziNotFound(msgFiltro+filtroAZ.toString());
  498.                 }
  499.                 else if(filtroResource!=null){
  500.                     throw new DriverRegistroServiziNotFound(msgFiltro+filtroResource.toString());
  501.                 }
  502.                 else if(filtroRicercaBase!=null){
  503.                     throw new DriverRegistroServiziNotFound(msgFiltro+filtroRicercaBase.toString());
  504.                 }
  505.                 else{
  506.                     throw new DriverRegistroServiziNotFound("Elementi non trovati");
  507.                 }
  508.             }
  509.         }catch(DriverRegistroServiziNotFound de){
  510.             throw de;
  511.         }
  512.         catch(Exception e){
  513.             throw new DriverRegistroServiziException(nomeMetodo+" error",e);
  514.         } finally {

  515.             JDBCUtilities.closeResources(rs, stm);

  516.             this.driver.closeConnection(con);

  517.         }
  518.     }
  519. }