DriverConfigurazioneDB_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.config.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.config.ProtocolProperty;
  27. import org.openspcoop2.core.config.driver.DriverConfigurazioneException;
  28. import org.openspcoop2.core.config.driver.FiltroRicercaProtocolPropertyConfig;
  29. import org.openspcoop2.core.config.driver.FiltroRicercaServiziApplicativi;
  30. import org.openspcoop2.core.constants.ProprietariProtocolProperty;
  31. import org.openspcoop2.core.mapping.DBProtocolPropertiesUtils;
  32. import org.openspcoop2.utils.UtilsException;
  33. import org.openspcoop2.utils.jdbc.JDBCAdapterException;
  34. import org.openspcoop2.utils.sql.ISQLQueryObject;
  35. import org.openspcoop2.utils.sql.SQLQueryObjectException;

  36. /**
  37.  * DriverConfigurazioneDB_protocolPropertiesDriver
  38.  *
  39.  *
  40.  * @author Sandra Giangrandi (sandra@link.it)
  41.  * @author Stefano Corallo (corallo@link.it)
  42.  * @author $Author$
  43.  * @version $Rev$, $Date$
  44.  */
  45. public class DriverConfigurazioneDB_protocolPropertiesDriver {

  46.     private DriverConfigurazioneDB driver = null;
  47.    
  48.     protected DriverConfigurazioneDB_protocolPropertiesDriver(DriverConfigurazioneDB driver) {
  49.         this.driver = driver;
  50.     }
  51.    
  52.     protected boolean existsProtocolProperty(ProprietariProtocolProperty proprietarioProtocolProperty, long idProprietario, String nome) throws DriverConfigurazioneException {

  53.         Connection connection;
  54.         if (this.driver.atomica) {
  55.             try {
  56.                 connection = this.driver.getConnectionFromDatasource("existsProtocolProperty");
  57.             } catch (Exception e) {
  58.                 throw new DriverConfigurazioneException("DriverConfigurazioneDB::existsProtocolProperty] Exception accedendo al datasource :" + e.getMessage());

  59.             }

  60.         } else
  61.             connection = this.driver.globalConnection;

  62.         this.driver.logDebug("operazione atomica = " + this.driver.atomica);
  63.         try {
  64.             return DBProtocolPropertiesUtils.existsProtocolProperty(proprietarioProtocolProperty, idProprietario, nome, connection, this.driver.tipoDB);
  65.         } catch (Exception e) {
  66.             throw new DriverConfigurazioneException(e.getMessage(),e);
  67.         } finally {
  68.             this.driver.closeConnection(connection);
  69.         }

  70.     }

  71.     protected ProtocolProperty getProtocolProperty(ProprietariProtocolProperty proprietarioProtocolProperty, long idProprietario, String nome) throws DriverConfigurazioneException {
  72.         String nomeMetodo = "getProtocolProperty";

  73.         Connection con = null;

  74.         if (this.driver.atomica) {
  75.             try {
  76.                 con = this.driver.getConnectionFromDatasource("getProtocolProperty");

  77.             } catch (Exception e) {
  78.                 throw new DriverConfigurazioneException("[DriverConfigurazioneDB::" + nomeMetodo + "] Exception accedendo al datasource :" + e.getMessage(), e);

  79.             }

  80.         } else {
  81.             con = this.driver.globalConnection;
  82.         }

  83.         try {
  84.             return DBProtocolPropertiesUtils.getProtocolPropertyConfig(proprietarioProtocolProperty, idProprietario, nome, con, this.driver.tipoDB, this.driver.getDriverUnwrapBYOK());
  85.         } catch (Exception se) {
  86.             throw new DriverConfigurazioneException("[DriverConfigurazioneException::" + nomeMetodo + "] Exception: " + se.getMessage());
  87.         } finally {
  88.             this.driver.closeConnection(con);
  89.         }
  90.     }

  91.     protected ProtocolProperty getProtocolProperty(long idProtocolProperty) throws DriverConfigurazioneException {
  92.         String nomeMetodo = "getProtocolProperty";

  93.         Connection con = null;

  94.         if (this.driver.atomica) {
  95.             try {
  96.                 con = this.driver.getConnectionFromDatasource("getProtocolProperty");

  97.             } catch (Exception e) {
  98.                 throw new DriverConfigurazioneException("[DriverConfigurazioneDB::" + nomeMetodo + "] Exception accedendo al datasource :" + e.getMessage(), e);

  99.             }

  100.         } else {
  101.             con = this.driver.globalConnection;
  102.         }

  103.         try {

  104.             return DriverConfigurazioneDBLib.getProtocolProperty(idProtocolProperty, con, this.driver.tipoDB, this.driver.getDriverUnwrapBYOK());

  105.         } catch (Exception se) {
  106.             throw new DriverConfigurazioneException("[DriverConfigurazioneException::" + nomeMetodo + "] Exception: " + se.getMessage());
  107.         } finally {
  108.             this.driver.closeConnection(con);
  109.         }
  110.     }
  111.    
  112.    
  113.     protected void setProtocolPropertiesForSearch(ISQLQueryObject sqlQueryObject, FiltroRicercaServiziApplicativi filtroRicerca, String tabella) throws SQLQueryObjectException{
  114.         if(filtroRicerca!=null){
  115.             this._setProtocolPropertiesForSearch(sqlQueryObject, filtroRicerca.getProtocolProperties(), tabella);
  116.         }
  117.     }
  118.     protected void _setProtocolPropertiesForSearch(ISQLQueryObject sqlQueryObject, List<FiltroRicercaProtocolPropertyConfig> list, String tabella) throws SQLQueryObjectException{
  119.         if(list!=null && !list.isEmpty()){
  120.             List<org.openspcoop2.core.mapping.FiltroRicercaProtocolProperty> l = new ArrayList<>();
  121.             l.addAll(list);
  122.             DBProtocolPropertiesUtils.setProtocolPropertiesForSearch(sqlQueryObject, l, tabella);
  123.         }
  124.     }
  125.    
  126.    
  127.     protected void setProtocolPropertiesForSearch(PreparedStatement stmt, int index, FiltroRicercaServiziApplicativi filtroRicerca, ProprietariProtocolProperty proprietario) throws SQLQueryObjectException, SQLException, JDBCAdapterException, UtilsException{
  128.         if(filtroRicerca!=null){
  129.             this._setProtocolPropertiesForSearch(stmt, index, filtroRicerca.getProtocolProperties(), proprietario);
  130.         }
  131.     }
  132.    
  133.     protected void _setProtocolPropertiesForSearch(PreparedStatement stmt, int index,
  134.             List<FiltroRicercaProtocolPropertyConfig> list, ProprietariProtocolProperty proprietario) throws SQLQueryObjectException, SQLException, JDBCAdapterException, UtilsException{
  135.         if(list!=null && !list.isEmpty()){
  136.             List<org.openspcoop2.core.mapping.FiltroRicercaProtocolProperty> l = new ArrayList<>();
  137.             l.addAll(list);
  138.             DBProtocolPropertiesUtils.setProtocolPropertiesForSearch(stmt, index, l, proprietario, this.driver.tipoDB, this.driver.log);
  139.         }
  140.     }
  141. }