AbstractConfigurazionePdDConnectionResourceManager.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.pdd.config;

  21. import java.sql.Connection;

  22. import org.openspcoop2.core.config.driver.DriverConfigurazioneException;
  23. import org.openspcoop2.core.config.driver.db.DriverConfigurazioneDB;
  24. import org.slf4j.Logger;

  25. /**    
  26.  * AbstractConfigurazionePdDConnectionResourceManager
  27.  *
  28.  * @author Poli Andrea (poli@link.it)
  29.  * @author $Author$
  30.  * @version $Rev$, $Date$
  31.  */
  32. public class AbstractConfigurazionePdDConnectionResourceManager {

  33.     protected OpenSPCoop2Properties openspcoopProperties;
  34.     protected boolean configurazioneDinamica = false;
  35.     protected boolean useConnectionPdD = false;
  36.     protected DriverConfigurazioneDB driver;
  37.     protected Logger log;
  38.    
  39.    
  40.     public AbstractConfigurazionePdDConnectionResourceManager(OpenSPCoop2Properties openspcoopProperties, DriverConfigurazioneDB driver, boolean useConnectionPdD, Logger log) {
  41.         this.openspcoopProperties = openspcoopProperties;
  42.         this.configurazioneDinamica = this.openspcoopProperties.isConfigurazioneDinamica();
  43.         this.useConnectionPdD = useConnectionPdD;
  44.         this.driver = driver;
  45.         this.log = log;

  46.     }
  47.    
  48.    
  49.    
  50.    
  51.    
  52.     // IMPL
  53.    
  54.     protected ConfigurazionePdDConnectionResource getConnection(Connection connectionPdD, String methodName) throws DriverConfigurazioneException {
  55.         ConfigurazionePdDConnectionResource cr = new ConfigurazionePdDConnectionResource();
  56.         if(connectionPdD!=null && this.useConnectionPdD){
  57.             cr.connectionDB = connectionPdD;
  58.             cr.connectionPdD = true;
  59.         }
  60.         else{
  61.             cr.connectionDB = this.driver.getConnection(methodName);
  62.             cr.connectionPdD = false;
  63.         }
  64.         return cr;
  65.     }
  66.     protected void releaseConnection(ConfigurazionePdDConnectionResource cr) {
  67.         if(cr!=null && cr.connectionDB!=null && !cr.connectionPdD) {
  68.             this.driver.releaseConnection(cr.connectionDB);
  69.         }
  70.     }
  71.    
  72. }