DriverRegistroServiziDB_accordiExistsDriver.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 org.openspcoop2.core.commons.DBUtils;
  25. import org.openspcoop2.core.constants.CostantiDB;
  26. import org.openspcoop2.core.id.IDAccordo;
  27. import org.openspcoop2.core.id.IDPortType;
  28. import org.openspcoop2.core.registry.constants.ParameterType;
  29. import org.openspcoop2.core.registry.driver.DriverRegistroServiziException;
  30. import org.openspcoop2.utils.jdbc.JDBCUtilities;
  31. import org.openspcoop2.utils.sql.ISQLQueryObject;
  32. import org.openspcoop2.utils.sql.SQLObjectFactory;

  33. /**
  34.  * DriverRegistroServiziDB_accordiExistsDriver
  35.  *
  36.  *
  37.  * @author Sandra Giangrandi (sandra@link.it)
  38.  * @author Stefano Corallo (corallo@link.it)
  39.  * @author $Author$
  40.  * @version $Rev$, $Date$
  41.  */
  42. public class DriverRegistroServiziDB_accordiExistsDriver {

  43.     private DriverRegistroServiziDB driver = null;
  44.    
  45.     protected DriverRegistroServiziDB_accordiExistsDriver(DriverRegistroServiziDB driver) {
  46.         this.driver = driver;
  47.     }
  48.    
  49.     protected boolean existsAccordoServizioParteComune(IDAccordo idAccordo) throws DriverRegistroServiziException {

  50.         Connection connection;
  51.         if (this.driver.atomica) {
  52.             try {
  53.                 connection = this.driver.getConnectionFromDatasource("existsAccordoServizioParteComune(idAccordo)");
  54.             } catch (Exception e) {
  55.                 throw new DriverRegistroServiziException("DriverRegistroServiziDB::existsAccordoServizioParteComune] Exception accedendo al datasource :" + e.getMessage(),e);

  56.             }

  57.         } else
  58.             connection = this.driver.globalConnection;

  59.         this.driver.logDebug("operazione atomica = " + this.driver.atomica);
  60.         try {

  61.             // Check soggetto referente se esiste.
  62.             if(idAccordo.getSoggettoReferente()!=null){
  63.                 if(this.driver.existsSoggetto(connection, idAccordo.getSoggettoReferente())==false){
  64.                     return false;
  65.                 }
  66.             }

  67.             long idAccordoLong = DBUtils.getIdAccordoServizioParteComune(idAccordo, connection, this.driver.tipoDB);
  68.             if (idAccordoLong <= 0)
  69.                 return false;
  70.             else
  71.                 return true;
  72.         } catch (Exception e) {
  73.             throw new DriverRegistroServiziException(e.getMessage(),e);
  74.         } finally {
  75.             this.driver.closeConnection(connection);
  76.         }
  77.     }

  78.     /**
  79.      * Verifica l'esistenza di un accordo registrato.
  80.      *
  81.      * @param idAccordo
  82.      *                dell'accordo da verificare
  83.      * @return true se l'accordo esiste, false altrimenti
  84.      */
  85.     protected boolean existsAccordoServizioParteComune(long idAccordo) throws DriverRegistroServiziException {

  86.         Connection connection = null;
  87.         this.driver.logDebug("operazione atomica = " + this.driver.atomica);
  88.         PreparedStatement stm=null;
  89.         ResultSet rs=null;
  90.         try {
  91.             if (this.driver.atomica) {
  92.                 try {
  93.                     connection = this.driver.getConnectionFromDatasource("existsAccordoServizioParteComune(longId)");
  94.                 } catch (Exception e) {
  95.                     throw new DriverRegistroServiziException("DriverRegistroServiziDB::existsAccordoServizioParteComune] Exception accedendo al datasource :" + e.getMessage(),e);

  96.                 }

  97.             } else
  98.                 connection = this.driver.globalConnection;
  99.            
  100.             ISQLQueryObject sqlQueryObject = SQLObjectFactory.createSQLQueryObject(this.driver.tipoDB);
  101.             sqlQueryObject.addFromTable(CostantiDB.ACCORDI);
  102.             sqlQueryObject.addSelectField("*");
  103.             sqlQueryObject.addWhereCondition("id = ?");
  104.             String sqlQuery = sqlQueryObject.createSQLQuery();
  105.             stm=connection.prepareStatement(sqlQuery);
  106.             stm.setLong(1, idAccordo);
  107.             rs=stm.executeQuery();
  108.             if (rs.next())
  109.                 return true;
  110.             else
  111.                 return false;
  112.         } catch (Exception e) {
  113.             throw new DriverRegistroServiziException(e.getMessage(),e);
  114.         } finally {
  115.             JDBCUtilities.closeResources(rs, stm);
  116.             this.driver.closeConnection(connection);
  117.         }
  118.     }

  119.     /**
  120.      * Verifica l'esistenza di un'azione in un accordo
  121.      *
  122.      * @param nome
  123.      *                dell'azione da verificare
  124.      * @param idAccordo Identificativo dell'accordi di servizio
  125.      *              
  126.      * @return true se l'azione esiste, false altrimenti
  127.      */
  128.     protected boolean existsAccordoServizioParteComuneAzione(String nome, IDAccordo idAccordo) throws DriverRegistroServiziException {

  129.         Connection connection;
  130.         if (this.driver.atomica) {
  131.             try {
  132.                 connection = this.driver.getConnectionFromDatasource("existsAccordoServizioParteComuneAzione(nome,idAccordo)");
  133.             } catch (Exception e) {
  134.                 throw new DriverRegistroServiziException("DriverRegistroServiziDB::existsAccordoServizioParteComuneAzione] Exception accedendo al datasource :" + e.getMessage(),e);

  135.             }

  136.         } else
  137.             connection = this.driver.globalConnection;

  138.         try {
  139.             return existsAccordoServizioParteComuneAzione(nome, DBUtils.getIdAccordoServizioParteComune(idAccordo, connection, this.driver.tipoDB));
  140.         }catch (Exception e) {
  141.             throw new DriverRegistroServiziException(e.getMessage(),e);
  142.         } finally {
  143.             this.driver.closeConnection(connection);
  144.         }

  145.     }

  146.     /**
  147.      * Verifica l'esistenza di un'azione in un accordo
  148.      *
  149.      * @param nome
  150.      *                dell'azione da verificare
  151.      * @param idAccordo
  152.      *                dell'accordo
  153.      * @return true se l'azione esiste, false altrimenti
  154.      */
  155.     protected boolean existsAccordoServizioParteComuneAzione(String nome, long idAccordo) throws DriverRegistroServiziException {

  156.         boolean exist = false;
  157.         Connection connection;
  158.         PreparedStatement stm = null;
  159.         ResultSet rs = null;
  160.         if (this.driver.atomica) {
  161.             try {
  162.                 connection = this.driver.getConnectionFromDatasource("existsAccordoServizioParteComuneAzione(nome,longId)");
  163.             } catch (Exception e) {
  164.                 throw new DriverRegistroServiziException("DriverRegistroServiziDB::existsAccordoServizioParteComuneAzione] Exception accedendo al datasource :" + e.getMessage(),e);

  165.             }

  166.         } else
  167.             connection = this.driver.globalConnection;

  168.         this.driver.logDebug("operazione atomica = " + this.driver.atomica);
  169.         try {
  170.             ISQLQueryObject sqlQueryObject = SQLObjectFactory.createSQLQueryObject(this.driver.tipoDB);
  171.             sqlQueryObject.addFromTable(CostantiDB.ACCORDI_AZIONI);
  172.             sqlQueryObject.addSelectField("*");
  173.             sqlQueryObject.addWhereCondition("id_accordo = ?");
  174.             sqlQueryObject.addWhereCondition("nome = ?");
  175.             sqlQueryObject.setANDLogicOperator(true);
  176.             String sqlQuery = sqlQueryObject.createSQLQuery();
  177.             stm = connection.prepareStatement(sqlQuery);
  178.             stm.setLong(1, idAccordo);
  179.             stm.setString(2, nome);
  180.             rs = stm.executeQuery();
  181.             if (rs.next())
  182.                 exist = true;
  183.             rs.close();
  184.             stm.close();
  185.         } catch (Exception e) {
  186.             exist = false;
  187.             throw new DriverRegistroServiziException(e.getMessage(),e);
  188.         } finally {

  189.             //Chiudo statement and resultset
  190.             JDBCUtilities.closeResources(rs, stm);

  191.             this.driver.closeConnection(connection);
  192.         }

  193.         return exist;
  194.     }

  195.     /**
  196.      * Verifica l'esistenza di un'azione in un accordo
  197.      *
  198.      * @param idAzione dell'azione
  199.      * @return true se l'azione esiste, false altrimenti
  200.      */
  201.     protected boolean existsAccordoServizioParteComuneAzione(long idAzione) throws DriverRegistroServiziException {

  202.         boolean exist = false;
  203.         Connection connection;
  204.         PreparedStatement stm = null;
  205.         ResultSet rs = null;
  206.         if (this.driver.atomica) {
  207.             try {
  208.                 connection = this.driver.getConnectionFromDatasource("existsAccordoServizioParteComuneAzione(longId)");
  209.             } catch (Exception e) {
  210.                 throw new DriverRegistroServiziException("DriverRegistroServiziDB::existsAccordoServizioParteComuneAzione] Exception accedendo al datasource :" + e.getMessage(),e);

  211.             }

  212.         } else
  213.             connection = this.driver.globalConnection;

  214.         this.driver.logDebug("operazione atomica = " + this.driver.atomica);
  215.         try {
  216.             ISQLQueryObject sqlQueryObject = SQLObjectFactory.createSQLQueryObject(this.driver.tipoDB);
  217.             sqlQueryObject.addFromTable(CostantiDB.ACCORDI_AZIONI);
  218.             sqlQueryObject.addSelectField("*");
  219.             sqlQueryObject.addWhereCondition("id = ?");
  220.             String sqlQuery = sqlQueryObject.createSQLQuery();
  221.             stm = connection.prepareStatement(sqlQuery);
  222.             stm.setLong(1, idAzione);
  223.             rs = stm.executeQuery();
  224.             if (rs.next())
  225.                 exist = true;
  226.             rs.close();
  227.             stm.close();
  228.         } catch (Exception e) {
  229.             exist = false;
  230.             throw new DriverRegistroServiziException(e.getMessage(),e);
  231.         } finally {

  232.             //Chiudo statement and resultset
  233.             JDBCUtilities.closeResources(rs, stm);

  234.             this.driver.closeConnection(connection);
  235.         }

  236.         return exist;
  237.     }

  238.     protected boolean existsAccordoServizioParteComunePorttype(String nome, IDAccordo idAccordo) throws DriverRegistroServiziException {
  239.         Connection connection;
  240.         if (this.driver.atomica) {
  241.             try {
  242.                 connection = this.driver.getConnectionFromDatasource("existsAccordoServizioParteComunePorttype(nome,idAccordo)");
  243.             } catch (Exception e) {
  244.                 throw new DriverRegistroServiziException("DriverRegistroServiziDB::existsAccordoServizioParteComunePorttype] Exception accedendo al datasource :" + e.getMessage(),e);

  245.             }

  246.         } else
  247.             connection = this.driver.globalConnection;

  248.         try {
  249.             return existsAccordoServizioParteComunePorttype(nome, DBUtils.getIdAccordoServizioParteComune(idAccordo, connection, this.driver.tipoDB));
  250.         }catch (Exception e) {
  251.             throw new DriverRegistroServiziException(e.getMessage(),e);
  252.         } finally {
  253.             this.driver.closeConnection(connection);
  254.         }
  255.     }



  256.     /**
  257.      * Verifica l'esistenza di un'operation in un accordo
  258.      *
  259.      * @param idAzione dell'azione
  260.      * @return true se l'azione esiste, false altrimenti
  261.      */
  262.     protected boolean existsAccordoServizioParteComuneOperation(long idAzione) throws DriverRegistroServiziException {

  263.         boolean exist = false;
  264.         Connection connection;
  265.         PreparedStatement stm = null;
  266.         ResultSet rs = null;
  267.         if (this.driver.atomica) {
  268.             try {
  269.                 connection = this.driver.getConnectionFromDatasource("existsAccordoServizioParteComuneOperation(longId)");
  270.             } catch (Exception e) {
  271.                 throw new DriverRegistroServiziException("DriverRegistroServiziDB::existsAccordoServizioParteComuneOperation] Exception accedendo al datasource :" + e.getMessage(),e);

  272.             }

  273.         } else
  274.             connection = this.driver.globalConnection;

  275.         this.driver.logDebug("operazione atomica = " + this.driver.atomica);
  276.         try {
  277.             ISQLQueryObject sqlQueryObject = SQLObjectFactory.createSQLQueryObject(this.driver.tipoDB);
  278.             sqlQueryObject.addFromTable(CostantiDB.PORT_TYPE_AZIONI);
  279.             sqlQueryObject.addSelectField("*");
  280.             sqlQueryObject.addWhereCondition("id = ?");
  281.             String sqlQuery = sqlQueryObject.createSQLQuery();
  282.             stm = connection.prepareStatement(sqlQuery);
  283.             stm.setLong(1, idAzione);
  284.             rs = stm.executeQuery();
  285.             if (rs.next())
  286.                 exist = true;
  287.             rs.close();
  288.             stm.close();
  289.         } catch (Exception e) {
  290.             exist = false;
  291.             throw new DriverRegistroServiziException(e.getMessage(),e);
  292.         } finally {

  293.             //Chiudo statement and resultset
  294.             JDBCUtilities.closeResources(rs, stm);

  295.             this.driver.closeConnection(connection);
  296.         }

  297.         return exist;
  298.     }

  299.     /**
  300.      * Verifica l'esistenza di un port-type in un accordo
  301.      *
  302.      * @param nome
  303.      *                del port-type da verificare
  304.      * @param idAccordo
  305.      *                dell'accordo
  306.      * @return true se il port-type esiste, false altrimenti
  307.      */
  308.     protected boolean existsAccordoServizioParteComunePorttype(String nome, long idAccordo) throws DriverRegistroServiziException {

  309.         boolean exist = false;
  310.         Connection connection;
  311.         PreparedStatement stm = null;
  312.         ResultSet rs = null;
  313.         if (this.driver.atomica) {
  314.             try {
  315.                 connection = this.driver.getConnectionFromDatasource("existsAccordoServizioParteComunePorttype(nome,longId)");
  316.             } catch (Exception e) {
  317.                 throw new DriverRegistroServiziException("DriverRegistroServiziDB::existsAccordoServizioParteComunePorttype] Exception accedendo al datasource :" + e.getMessage(),e);

  318.             }

  319.         } else
  320.             connection = this.driver.globalConnection;

  321.         this.driver.logDebug("operazione atomica = " + this.driver.atomica);
  322.         try {
  323.             ISQLQueryObject sqlQueryObject = SQLObjectFactory.createSQLQueryObject(this.driver.tipoDB);
  324.             sqlQueryObject.addFromTable(CostantiDB.PORT_TYPE);
  325.             sqlQueryObject.addSelectField("*");
  326.             sqlQueryObject.addWhereCondition("id_accordo = ?");
  327.             sqlQueryObject.addWhereCondition("nome = ?");
  328.             sqlQueryObject.setANDLogicOperator(true);
  329.             String sqlQuery = sqlQueryObject.createSQLQuery();
  330.             stm = connection.prepareStatement(sqlQuery);
  331.             stm.setLong(1, idAccordo);
  332.             stm.setString(2, nome);
  333.             rs = stm.executeQuery();
  334.             if (rs.next())
  335.                 exist = true;
  336.             rs.close();
  337.             stm.close();
  338.         } catch (Exception e) {
  339.             exist = false;
  340.             throw new DriverRegistroServiziException(e.getMessage(),e);
  341.         } finally {

  342.             //Chiudo statement and resultset
  343.             JDBCUtilities.closeResources(rs, stm);

  344.             this.driver.closeConnection(connection);
  345.         }

  346.         return exist;
  347.     }

  348.     /**
  349.      *
  350.      * @param nome Nome dell'operation
  351.      * @param idPortType L'identificativo del PortType
  352.      * @return true se esiste, false altrimenti.
  353.      * @throws DriverRegistroServiziException
  354.      */
  355.     protected boolean existsAccordoServizioParteComunePorttypeOperation(String nome, IDPortType idPortType) throws DriverRegistroServiziException {
  356.         Connection connection;
  357.         if (this.driver.atomica) {
  358.             try {
  359.                 connection = this.driver.getConnectionFromDatasource("existsAccordoServizioParteComunePorttypeOperation(nome,idPortType)");
  360.             } catch (Exception e) {
  361.                 throw new DriverRegistroServiziException("DriverRegistroServiziDB::existsAccordoServizioParteComunePorttypeOperation] Exception accedendo al datasource :" + e.getMessage(),e);

  362.             }

  363.         } else
  364.             connection = this.driver.globalConnection;

  365.         try {
  366.             long idAccordo = DBUtils.getIdAccordoServizioParteComune(idPortType.getIdAccordo(), connection, this.driver.tipoDB);
  367.             return existsAccordoServizioParteComunePorttypeOperation(nome, DBUtils.getIdPortType(idAccordo,idPortType.getNome(), connection));
  368.         }catch (Exception e) {
  369.             throw new DriverRegistroServiziException(e.getMessage(),e);
  370.         } finally {
  371.             this.driver.closeConnection(connection);
  372.         }
  373.     }

  374.     /**
  375.      * Verifica l'esistenza di un operation in un port-type
  376.      *
  377.      * @param nome
  378.      *                dell'operation da verificare
  379.      * @param idPortType
  380.      *                del port-type
  381.      * @return true se l'operation esiste, false altrimenti
  382.      */
  383.     protected boolean existsAccordoServizioParteComunePorttypeOperation(String nome, long idPortType) throws DriverRegistroServiziException {

  384.         boolean exist = false;
  385.         Connection connection;
  386.         PreparedStatement stm = null;
  387.         ResultSet rs = null;
  388.         if (this.driver.atomica) {
  389.             try {
  390.                 connection = this.driver.getConnectionFromDatasource("existsAccordoServizioParteComunePorttypeOperation(nome,longId)");
  391.             } catch (Exception e) {
  392.                 throw new DriverRegistroServiziException("DriverRegistroServiziDB::existsAccordoServizioParteComunePorttypeOperation] Exception accedendo al datasource :" + e.getMessage(),e);

  393.             }

  394.         } else
  395.             connection = this.driver.globalConnection;

  396.         this.driver.logDebug("operazione atomica = " + this.driver.atomica);
  397.         try {
  398.             ISQLQueryObject sqlQueryObject = SQLObjectFactory.createSQLQueryObject(this.driver.tipoDB);
  399.             sqlQueryObject.addFromTable(CostantiDB.PORT_TYPE_AZIONI);
  400.             sqlQueryObject.addSelectField("*");
  401.             sqlQueryObject.addWhereCondition("id_port_type = ?");
  402.             sqlQueryObject.addWhereCondition("nome = ?");
  403.             sqlQueryObject.setANDLogicOperator(true);
  404.             String sqlQuery = sqlQueryObject.createSQLQuery();
  405.             stm = connection.prepareStatement(sqlQuery);
  406.             stm.setLong(1, idPortType);
  407.             stm.setString(2, nome);
  408.             rs = stm.executeQuery();
  409.             if (rs.next())
  410.                 exist = true;
  411.             rs.close();
  412.             stm.close();
  413.         } catch (Exception e) {
  414.             exist = false;
  415.             throw new DriverRegistroServiziException(e.getMessage(),e);
  416.         } finally {

  417.             //Chiudo statement and resultset
  418.             JDBCUtilities.closeResources(rs, stm);

  419.             this.driver.closeConnection(connection);
  420.         }

  421.         return exist;
  422.     }
  423.    
  424.    
  425.     /**
  426.      * Verifica l'esistenza di un risorsa con determinato nome in un accordo
  427.      *
  428.      * @param nome
  429.      *                del port-type da verificare
  430.      * @param idAccordo
  431.      *                dell'accordo
  432.      * @return true se il port-type esiste, false altrimenti
  433.      */
  434.     protected boolean existsAccordoServizioParteComuneResource(String nome, long idAccordo) throws DriverRegistroServiziException {

  435.         boolean exist = false;
  436.         Connection connection;
  437.         PreparedStatement stm = null;
  438.         ResultSet rs = null;
  439.         if (this.driver.atomica) {
  440.             try {
  441.                 connection = this.driver.getConnectionFromDatasource("existsAccordoServizioParteComuneResource(nome,idAccordo)");
  442.             } catch (Exception e) {
  443.                 throw new DriverRegistroServiziException("DriverRegistroServiziDB::existsAccordoServizioParteComuneResource] Exception accedendo al datasource :" + e.getMessage(),e);

  444.             }

  445.         } else
  446.             connection = this.driver.globalConnection;

  447.         this.driver.logDebug("operazione atomica = " + this.driver.atomica);
  448.         try {
  449.             ISQLQueryObject sqlQueryObject = SQLObjectFactory.createSQLQueryObject(this.driver.tipoDB);
  450.             sqlQueryObject.addFromTable(CostantiDB.API_RESOURCES);
  451.             sqlQueryObject.addSelectField("*");
  452.             sqlQueryObject.addWhereCondition("id_accordo = ?");
  453.             sqlQueryObject.addWhereCondition("nome = ?");
  454.             sqlQueryObject.setANDLogicOperator(true);
  455.             String sqlQuery = sqlQueryObject.createSQLQuery();
  456.             stm = connection.prepareStatement(sqlQuery);
  457.             stm.setLong(1, idAccordo);
  458.             stm.setString(2, nome);
  459.             rs = stm.executeQuery();
  460.             if (rs.next())
  461.                 exist = true;
  462.             rs.close();
  463.             stm.close();
  464.         } catch (Exception e) {
  465.             exist = false;
  466.             throw new DriverRegistroServiziException(e.getMessage(),e);
  467.         } finally {

  468.             //Chiudo statement and resultset
  469.             JDBCUtilities.closeResources(rs, stm);

  470.             this.driver.closeConnection(connection);
  471.         }

  472.         return exist;
  473.     }
  474.    
  475.     protected boolean existsAccordoServizioParteComuneResource(String httpMethod, String path, long idAccordo, String excludeResourceWithName) throws DriverRegistroServiziException {

  476.         boolean exist = false;
  477.         Connection connection;
  478.         PreparedStatement stm = null;
  479.         ResultSet rs = null;
  480.         if (this.driver.atomica) {
  481.             try {
  482.                 connection = this.driver.getConnectionFromDatasource("existsAccordoServizioParteComuneResource(httpMethod,path,idAccordo)");
  483.             } catch (Exception e) {
  484.                 throw new DriverRegistroServiziException("DriverRegistroServiziDB::existsAccordoServizioParteComuneResource] Exception accedendo al datasource :" + e.getMessage(),e);

  485.             }

  486.         } else
  487.             connection = this.driver.globalConnection;

  488.         this.driver.logDebug("operazione atomica = " + this.driver.atomica);
  489.         try {
  490.             ISQLQueryObject sqlQueryObject = SQLObjectFactory.createSQLQueryObject(this.driver.tipoDB);
  491.             sqlQueryObject.addFromTable(CostantiDB.API_RESOURCES);
  492.             sqlQueryObject.addSelectField("*");
  493.             sqlQueryObject.addWhereCondition("id_accordo = ?");
  494.             sqlQueryObject.addWhereCondition("http_method = ?");
  495.             sqlQueryObject.addWhereCondition("path = ?");
  496.             if(excludeResourceWithName!=null && !"".equals(excludeResourceWithName)) {
  497.                 sqlQueryObject.addWhereCondition("nome <> ?");
  498.             }
  499.             sqlQueryObject.setANDLogicOperator(true);
  500.             String sqlQuery = sqlQueryObject.createSQLQuery();
  501.             stm = connection.prepareStatement(sqlQuery);
  502.             stm.setLong(1, idAccordo);
  503.             if(httpMethod==null || "".equals(httpMethod)) {
  504.                 stm.setString(2, CostantiDB.API_RESOURCE_HTTP_METHOD_ALL_VALUE);
  505.             }
  506.             else {
  507.                 stm.setString(2, httpMethod);
  508.             }
  509.             if(path==null || "".equals(path)) {
  510.                 stm.setString(3, CostantiDB.API_RESOURCE_PATH_ALL_VALUE);
  511.             }
  512.             else {
  513.                 stm.setString(3, path);
  514.             }
  515.             if(excludeResourceWithName!=null && !"".equals(excludeResourceWithName)) {
  516.                 stm.setString(4, excludeResourceWithName);
  517.             }
  518.             rs = stm.executeQuery();
  519.             if (rs.next())
  520.                 exist = true;
  521.             rs.close();
  522.             stm.close();
  523.         } catch (Exception e) {
  524.             exist = false;
  525.             throw new DriverRegistroServiziException(e.getMessage(),e);
  526.         } finally {

  527.             //Chiudo statement and resultset
  528.             JDBCUtilities.closeResources(rs, stm);

  529.             this.driver.closeConnection(connection);
  530.         }

  531.         return exist;
  532.     }
  533.    
  534.     /**
  535.      * Verifica l'esistenza di un response con Status in una Resource
  536.      *
  537.      * @param httpStatus
  538.      *                 della response da verificare
  539.      * @param idRisorsa
  540.      *                della resource
  541.      * @return true se la risposta esiste, false altrimenti
  542.      */
  543.     protected boolean existsAccordoServizioResourceResponse(long idRisorsa, int httpStatus) throws DriverRegistroServiziException {

  544.         boolean exist = false;
  545.         Connection connection;
  546.         PreparedStatement stm = null;
  547.         ResultSet rs = null;
  548.         if (this.driver.atomica) {
  549.             try {
  550.                 connection = this.driver.getConnectionFromDatasource("existsAccordoServizioResourceResponse(idRisorsa,httpStatus)");
  551.             } catch (Exception e) {
  552.                 throw new DriverRegistroServiziException("DriverRegistroServiziDB::existsAccordoServizioResourceResponse] Exception accedendo al datasource :" + e.getMessage(),e);

  553.             }

  554.         } else
  555.             connection = this.driver.globalConnection;

  556.         this.driver.logDebug("operazione atomica = " + this.driver.atomica);
  557.         try {
  558.             ISQLQueryObject sqlQueryObject = SQLObjectFactory.createSQLQueryObject(this.driver.tipoDB);
  559.             sqlQueryObject.addFromTable(CostantiDB.API_RESOURCES_RESPONSE);
  560.             sqlQueryObject.addSelectField("*");
  561.             sqlQueryObject.addWhereCondition("id_resource = ?");
  562.             sqlQueryObject.addWhereCondition("status = ?");
  563.             sqlQueryObject.setANDLogicOperator(true);
  564.             String sqlQuery = sqlQueryObject.createSQLQuery();
  565.             stm = connection.prepareStatement(sqlQuery);
  566.             stm.setLong(1, idRisorsa);
  567.             stm.setInt(2, httpStatus);
  568.             rs = stm.executeQuery();
  569.             if (rs.next())
  570.                 exist = true;
  571.             rs.close();
  572.             stm.close();
  573.         } catch (Exception e) {
  574.             exist = false;
  575.             throw new DriverRegistroServiziException(e.getMessage(),e);
  576.         } finally {

  577.             //Chiudo statement and resultset
  578.             JDBCUtilities.closeResources(rs, stm);

  579.             this.driver.closeConnection(connection);
  580.         }

  581.         return exist;
  582.     }
  583.    

  584.     protected boolean existsAccordoServizioResourceRepresentation(Long idRisorsa, boolean isRequest, Long idResponse, String mediaType) throws DriverRegistroServiziException {

  585.         boolean exist = false;
  586.         Connection connection;
  587.         PreparedStatement stm = null;
  588.         ResultSet rs = null;
  589.         if (this.driver.atomica) {
  590.             try {
  591.                 connection = this.driver.getConnectionFromDatasource("existsAccordoServizioResourceRepresentation(idRisorsa,isRequest,idResponse,mediaType)");
  592.             } catch (Exception e) {
  593.                 throw new DriverRegistroServiziException("DriverRegistroServiziDB::existsAccordoServizioResourceRepresentation] Exception accedendo al datasource :" + e.getMessage(),e);

  594.             }

  595.         } else
  596.             connection = this.driver.globalConnection;

  597.         this.driver.logDebug("operazione atomica = " + this.driver.atomica);
  598.         try {
  599.             ISQLQueryObject sqlQueryObject = SQLObjectFactory.createSQLQueryObject(this.driver.tipoDB);
  600.             sqlQueryObject.addFromTable(CostantiDB.API_RESOURCES_MEDIA);
  601.             sqlQueryObject.addSelectField("*");
  602.             if(isRequest)
  603.                 sqlQueryObject.addWhereCondition("id_resource_media = ?");
  604.             else
  605.                 sqlQueryObject.addWhereCondition("id_resource_response_media = ?");
  606.             sqlQueryObject.addWhereCondition("media_type = ?");
  607.             sqlQueryObject.setANDLogicOperator(true);
  608.             String sqlQuery = sqlQueryObject.createSQLQuery();
  609.             stm = connection.prepareStatement(sqlQuery);
  610.             if(isRequest)
  611.                 stm.setLong(1, idRisorsa);
  612.             else
  613.                 stm.setLong(1, idResponse);
  614.             stm.setString(2, mediaType);
  615.             rs = stm.executeQuery();
  616.             if (rs.next())
  617.                 exist = true;
  618.             rs.close();
  619.             stm.close();
  620.         } catch (Exception e) {
  621.             exist = false;
  622.             throw new DriverRegistroServiziException(e.getMessage(),e);
  623.         } finally {

  624.             //Chiudo statement and resultset
  625.             JDBCUtilities.closeResources(rs, stm);

  626.             this.driver.closeConnection(connection);
  627.         }

  628.         return exist;
  629.     }
  630.    
  631.     protected boolean existsAccordoServizioResourceParameter(Long idRisorsa, boolean isRequest, Long idResponse, ParameterType tipo, String nome) throws DriverRegistroServiziException {

  632.         boolean exist = false;
  633.         Connection connection;
  634.         PreparedStatement stm = null;
  635.         ResultSet rs = null;
  636.         if (this.driver.atomica) {
  637.             try {
  638.                 connection = this.driver.getConnectionFromDatasource("existsAccordoServizioResourceRepresentation(idRisorsa,isRequest,idResponse,tipo,nome)");
  639.             } catch (Exception e) {
  640.                 throw new DriverRegistroServiziException("DriverRegistroServiziDB::existsAccordoServizioResourceRepresentation] Exception accedendo al datasource :" + e.getMessage(),e);

  641.             }

  642.         } else
  643.             connection = this.driver.globalConnection;

  644.         this.driver.logDebug("operazione atomica = " + this.driver.atomica);
  645.         try {
  646.             ISQLQueryObject sqlQueryObject = SQLObjectFactory.createSQLQueryObject(this.driver.tipoDB);
  647.             sqlQueryObject.addFromTable(CostantiDB.API_RESOURCES_PARAMETER);
  648.             sqlQueryObject.addSelectField("*");
  649.             if(isRequest)
  650.                 sqlQueryObject.addWhereCondition("id_resource_parameter = ?");
  651.             else
  652.                 sqlQueryObject.addWhereCondition("id_resource_response_par = ?");
  653.             sqlQueryObject.addWhereCondition("tipo_parametro = ?");
  654.             sqlQueryObject.addWhereCondition("nome = ?");
  655.             sqlQueryObject.setANDLogicOperator(true);
  656.             String sqlQuery = sqlQueryObject.createSQLQuery();
  657.             stm = connection.prepareStatement(sqlQuery);
  658.             if(isRequest)
  659.                 stm.setLong(1, idRisorsa);
  660.             else
  661.                 stm.setLong(1, idResponse);
  662.             stm.setString(2, tipo.toString());
  663.             stm.setString(3, nome);
  664.             rs = stm.executeQuery();
  665.             if (rs.next())
  666.                 exist = true;
  667.             rs.close();
  668.             stm.close();
  669.         } catch (Exception e) {
  670.             exist = false;
  671.             throw new DriverRegistroServiziException(e.getMessage(),e);
  672.         } finally {

  673.             //Chiudo statement and resultset
  674.             JDBCUtilities.closeResources(rs, stm);

  675.             this.driver.closeConnection(connection);
  676.         }

  677.         return exist;
  678.     }
  679. }