DriverRegistroServiziDB_protocolPropertiesDriver.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.SQLException;
  24. import java.util.ArrayList;
  25. import java.util.List;

  26. import org.openspcoop2.core.constants.CostantiDB;
  27. import org.openspcoop2.core.constants.ProprietariProtocolProperty;
  28. import org.openspcoop2.core.mapping.DBProtocolPropertiesUtils;
  29. import org.openspcoop2.core.registry.ProtocolProperty;
  30. import org.openspcoop2.core.registry.driver.DriverRegistroServiziException;
  31. import org.openspcoop2.core.registry.driver.FiltroRicerca;
  32. import org.openspcoop2.core.registry.driver.FiltroRicercaAccordi;
  33. import org.openspcoop2.core.registry.driver.FiltroRicercaAzioni;
  34. import org.openspcoop2.core.registry.driver.FiltroRicercaFruizioniServizio;
  35. import org.openspcoop2.core.registry.driver.FiltroRicercaOperations;
  36. import org.openspcoop2.core.registry.driver.FiltroRicercaPortTypes;
  37. import org.openspcoop2.core.registry.driver.FiltroRicercaProtocolPropertyRegistry;
  38. import org.openspcoop2.core.registry.driver.FiltroRicercaResources;
  39. import org.openspcoop2.utils.UtilsException;
  40. import org.openspcoop2.utils.jdbc.JDBCAdapterException;
  41. import org.openspcoop2.utils.sql.ISQLQueryObject;
  42. import org.openspcoop2.utils.sql.SQLQueryObjectException;

  43. /**
  44.  * DriverRegistroServiziDB_protocolPropertiesDriver
  45.  *
  46.  *
  47.  * @author Sandra Giangrandi (sandra@link.it)
  48.  * @author Stefano Corallo (corallo@link.it)
  49.  * @author $Author$
  50.  * @version $Rev$, $Date$
  51.  */
  52. public class DriverRegistroServiziDB_protocolPropertiesDriver {

  53.     private DriverRegistroServiziDB driver = null;
  54.    
  55.     protected DriverRegistroServiziDB_protocolPropertiesDriver(DriverRegistroServiziDB driver) {
  56.         this.driver = driver;
  57.     }
  58.    
  59.     protected boolean existsProtocolProperty(ProprietariProtocolProperty proprietarioProtocolProperty, long idProprietario, String nome) throws DriverRegistroServiziException {

  60.         Connection connection;
  61.         if (this.driver.atomica) {
  62.             try {
  63.                 connection = this.driver.getConnectionFromDatasource("existsProtocolProperty");
  64.             } catch (Exception e) {
  65.                 throw new DriverRegistroServiziException("DriverRegistroServiziDB::existsProtocolProperty] Exception accedendo al datasource :" + e.getMessage());

  66.             }

  67.         } else
  68.             connection = this.driver.globalConnection;

  69.         this.driver.logDebug("operazione atomica = " + this.driver.atomica);
  70.         try {
  71.             return DBProtocolPropertiesUtils.existsProtocolProperty(proprietarioProtocolProperty, idProprietario, nome, connection, this.driver.tipoDB);
  72.         } catch (Exception e) {
  73.             throw new DriverRegistroServiziException(e.getMessage(),e);
  74.         } finally {

  75.             this.driver.closeConnection(connection);
  76.         }

  77.     }

  78.     protected ProtocolProperty getProtocolProperty(ProprietariProtocolProperty proprietarioProtocolProperty, long idProprietario, String nome) throws DriverRegistroServiziException {
  79.         String nomeMetodo = "getProtocolProperty";

  80.         Connection con = null;

  81.         if (this.driver.atomica) {
  82.             try {
  83.                 con = this.driver.getConnectionFromDatasource("getProtocolProperty");

  84.             } catch (Exception e) {
  85.                 throw new DriverRegistroServiziException("[DriverRegistroServiziDB::" + nomeMetodo + "] Exception accedendo al datasource :" + e.getMessage(), e);

  86.             }

  87.         } else {
  88.             con = this.driver.globalConnection;
  89.         }

  90.         try {
  91.             return DBProtocolPropertiesUtils.getProtocolPropertyRegistry(proprietarioProtocolProperty, idProprietario, nome, con, this.driver.tipoDB, this.driver.getDriverUnwrapBYOK());
  92.         } catch (Exception se) {
  93.             throw new DriverRegistroServiziException("[DriverRegistroServiziException::" + nomeMetodo + "] Exception: " + se.getMessage());
  94.         } finally {
  95.             this.driver.closeConnection(con);
  96.         }
  97.     }

  98.     protected ProtocolProperty getProtocolProperty(long idProtocolProperty) throws DriverRegistroServiziException {
  99.         String nomeMetodo = "getProtocolProperty";

  100.         Connection con = null;

  101.         if (this.driver.atomica) {
  102.             try {
  103.                 con = this.driver.getConnectionFromDatasource("getProtocolProperty");

  104.             } catch (Exception e) {
  105.                 throw new DriverRegistroServiziException("[DriverRegistroServiziDB::" + nomeMetodo + "] Exception accedendo al datasource :" + e.getMessage(), e);

  106.             }

  107.         } else {
  108.             con = this.driver.globalConnection;
  109.         }

  110.         try {

  111.             return DriverRegistroServiziDB_LIB.getProtocolProperty(idProtocolProperty, con, this.driver.tipoDB, this.driver.getDriverUnwrapBYOK());

  112.         } catch (Exception se) {
  113.             throw new DriverRegistroServiziException("[DriverRegistroServiziException::" + nomeMetodo + "] Exception: " + se.getMessage());
  114.         } finally {
  115.             this.driver.closeConnection(con);
  116.         }
  117.     }
  118.    
  119.     protected void setProtocolPropertiesForSearch(ISQLQueryObject sqlQueryObject, FiltroRicercaFruizioniServizio filtroRicerca, String tabella) throws SQLQueryObjectException{
  120.         if(filtroRicerca!=null){
  121.             this._setProtocolPropertiesForSearch(sqlQueryObject, filtroRicerca.getProtocolPropertiesFruizione(), tabella);
  122.         }
  123.     }
  124.     protected void setProtocolPropertiesForSearch(ISQLQueryObject sqlQueryObject, FiltroRicercaAzioni filtroRicerca, String tabella) throws SQLQueryObjectException{
  125.         if(filtroRicerca!=null){
  126.             this._setProtocolPropertiesForSearch(sqlQueryObject, filtroRicerca.getProtocolPropertiesAzione(), tabella);
  127.         }
  128.     }
  129.     protected void setProtocolPropertiesForSearch(ISQLQueryObject sqlQueryObject, FiltroRicercaOperations filtroRicerca, String tabella) throws SQLQueryObjectException{
  130.         if(filtroRicerca!=null){
  131.             if(CostantiDB.PORT_TYPE.equals(tabella)){
  132.                 this._setProtocolPropertiesForSearch(sqlQueryObject, filtroRicerca.getProtocolPropertiesPortType(), tabella);
  133.             }
  134.             else{
  135.                 this._setProtocolPropertiesForSearch(sqlQueryObject, filtroRicerca.getProtocolPropertiesAzione(), tabella);
  136.             }
  137.         }
  138.     }
  139.     protected void setProtocolPropertiesForSearch(ISQLQueryObject sqlQueryObject, FiltroRicercaPortTypes filtroRicerca, String tabella) throws SQLQueryObjectException{
  140.         if(filtroRicerca!=null){
  141.             this._setProtocolPropertiesForSearch(sqlQueryObject, filtroRicerca.getProtocolPropertiesPortType(), tabella);
  142.         }
  143.     }
  144.     protected void setProtocolPropertiesForSearch(ISQLQueryObject sqlQueryObject, FiltroRicercaResources filtroRicerca, String tabella) throws SQLQueryObjectException{
  145.         if(filtroRicerca!=null){
  146.             this._setProtocolPropertiesForSearch(sqlQueryObject, filtroRicerca.getProtocolPropertiesResources(), tabella);
  147.         }
  148.     }
  149.     protected void setProtocolPropertiesForSearch(ISQLQueryObject sqlQueryObject, FiltroRicercaAccordi filtroRicerca, String tabella) throws SQLQueryObjectException{
  150.         if(filtroRicerca!=null){
  151.             this._setProtocolPropertiesForSearch(sqlQueryObject, filtroRicerca.getProtocolPropertiesAccordo(), tabella);
  152.         }
  153.     }
  154.     protected void setProtocolPropertiesForSearch(ISQLQueryObject sqlQueryObject, FiltroRicerca filtroRicerca, String tabella) throws SQLQueryObjectException{
  155.         if(filtroRicerca!=null){
  156.             this._setProtocolPropertiesForSearch(sqlQueryObject, filtroRicerca.getProtocolProperties(), tabella);
  157.         }
  158.     }
  159.     private void _setProtocolPropertiesForSearch(ISQLQueryObject sqlQueryObject, List<FiltroRicercaProtocolPropertyRegistry> list, String tabella) throws SQLQueryObjectException{
  160.         if(list!=null && !list.isEmpty()){
  161.             List<org.openspcoop2.core.mapping.FiltroRicercaProtocolProperty> l = new ArrayList<>();
  162.             l.addAll(list);
  163.             DBProtocolPropertiesUtils.setProtocolPropertiesForSearch(sqlQueryObject, l, tabella);
  164.         }
  165.     }
  166.    
  167.     protected void setProtocolPropertiesForSearch(PreparedStatement stmt, int index, FiltroRicercaFruizioniServizio filtroRicerca, ProprietariProtocolProperty proprietario) throws SQLQueryObjectException, SQLException, JDBCAdapterException, UtilsException{
  168.         if(filtroRicerca!=null){
  169.             this._setProtocolPropertiesForSearch(stmt, index, filtroRicerca.getProtocolPropertiesFruizione(), proprietario);
  170.         }
  171.     }
  172.     protected void setProtocolPropertiesForSearch(PreparedStatement stmt, int index, FiltroRicercaAzioni filtroRicerca, ProprietariProtocolProperty proprietario) throws SQLQueryObjectException, SQLException, JDBCAdapterException, UtilsException{
  173.         if(filtroRicerca!=null){
  174.             this._setProtocolPropertiesForSearch(stmt, index, filtroRicerca.getProtocolPropertiesAzione(), proprietario);
  175.         }
  176.     }
  177.     protected void setProtocolPropertiesForSearch(PreparedStatement stmt, int index, FiltroRicercaOperations filtroRicerca, ProprietariProtocolProperty proprietario) throws SQLQueryObjectException, SQLException, JDBCAdapterException, UtilsException{
  178.         if(filtroRicerca!=null){
  179.             if(ProprietariProtocolProperty.PORT_TYPE.equals(proprietario)){
  180.                 this._setProtocolPropertiesForSearch(stmt, index, filtroRicerca.getProtocolPropertiesPortType(), proprietario);
  181.             }
  182.             else{
  183.                 this._setProtocolPropertiesForSearch(stmt, index, filtroRicerca.getProtocolPropertiesAzione(), proprietario);
  184.             }
  185.         }
  186.     }
  187.     protected void setProtocolPropertiesForSearch(PreparedStatement stmt, int index, FiltroRicercaPortTypes filtroRicerca, ProprietariProtocolProperty proprietario) throws SQLQueryObjectException, SQLException, JDBCAdapterException, UtilsException{
  188.         if(filtroRicerca!=null){
  189.             this._setProtocolPropertiesForSearch(stmt, index, filtroRicerca.getProtocolPropertiesPortType(), proprietario);
  190.         }
  191.     }
  192.     protected void setProtocolPropertiesForSearch(PreparedStatement stmt, int index, FiltroRicercaResources filtroRicerca, ProprietariProtocolProperty proprietario) throws SQLQueryObjectException, SQLException, JDBCAdapterException, UtilsException{
  193.         if(filtroRicerca!=null){
  194.             this._setProtocolPropertiesForSearch(stmt, index, filtroRicerca.getProtocolPropertiesResources(), proprietario);
  195.         }
  196.     }
  197.     protected void setProtocolPropertiesForSearch(PreparedStatement stmt, int index, FiltroRicercaAccordi filtroRicerca, ProprietariProtocolProperty proprietario) throws SQLQueryObjectException, SQLException, JDBCAdapterException, UtilsException{
  198.         if(filtroRicerca!=null){
  199.             this._setProtocolPropertiesForSearch(stmt, index, filtroRicerca.getProtocolPropertiesAccordo(), proprietario);
  200.         }
  201.     }
  202.     protected void setProtocolPropertiesForSearch(PreparedStatement stmt, int index, FiltroRicerca filtroRicerca, ProprietariProtocolProperty proprietario) throws SQLQueryObjectException, SQLException, JDBCAdapterException, UtilsException{
  203.         if(filtroRicerca!=null){
  204.             this._setProtocolPropertiesForSearch(stmt, index, filtroRicerca.getProtocolProperties(), proprietario);
  205.         }
  206.     }
  207.    
  208.     private void _setProtocolPropertiesForSearch(PreparedStatement stmt, int index,
  209.             List<FiltroRicercaProtocolPropertyRegistry> list, ProprietariProtocolProperty proprietario) throws SQLQueryObjectException, SQLException, JDBCAdapterException, UtilsException{
  210.         if(list!=null && !list.isEmpty()){
  211.             List<org.openspcoop2.core.mapping.FiltroRicercaProtocolProperty> l = new ArrayList<>();
  212.             l.addAll(list);
  213.             DBProtocolPropertiesUtils.setProtocolPropertiesForSearch(stmt, index, l, proprietario, this.driver.tipoDB, this.driver.log);
  214.         }
  215.     }
  216. }