DriverConfigurazioneDB_connettoriLIB.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 static org.openspcoop2.core.constants.CostantiDB.CREATE;
  22. import static org.openspcoop2.core.constants.CostantiDB.DELETE;
  23. import static org.openspcoop2.core.constants.CostantiDB.UPDATE;

  24. import java.sql.Connection;
  25. import java.sql.PreparedStatement;
  26. import java.sql.ResultSet;
  27. import java.sql.SQLException;
  28. import java.sql.Types;
  29. import java.util.ArrayList;
  30. import java.util.HashMap;
  31. import java.util.List;
  32. import java.util.Map;

  33. import org.apache.commons.lang.StringUtils;
  34. import org.openspcoop2.core.byok.BYOKWrappedValue;
  35. import org.openspcoop2.core.byok.IDriverBYOK;
  36. import org.openspcoop2.core.commons.DBUtils;
  37. import org.openspcoop2.core.config.Connettore;
  38. import org.openspcoop2.core.config.Property;
  39. import org.openspcoop2.core.config.driver.ConnettorePropertiesUtilities;
  40. import org.openspcoop2.core.config.driver.DriverConfigurazioneException;
  41. import org.openspcoop2.core.constants.CostantiConnettori;
  42. import org.openspcoop2.core.constants.CostantiDB;
  43. import org.openspcoop2.core.constants.TipiConnettore;
  44. import org.openspcoop2.utils.UtilsException;
  45. import org.openspcoop2.utils.jdbc.JDBCUtilities;
  46. import org.openspcoop2.utils.sql.ISQLQueryObject;
  47. import org.openspcoop2.utils.sql.SQLObjectFactory;

  48. /**
  49.  * DriverConfigurazioneDB_connettoriLIB
  50.  *
  51.  * @author Stefano Corallo - corallo@link.it
  52.  * @author $Author$
  53.  * @version $Rev$, $Date$
  54.  */
  55. public class DriverConfigurazioneDB_connettoriLIB {


  56.     /**
  57.      * CRUD oggetto Connettore. In caso di CREATE inserisce nel db il dati del
  58.      * connettore passato e ritorna l'id dell'oggetto creato Non si occupa di
  59.      * chiudere la connessione con il db in caso di errore in quanto verra'
  60.      * gestita dal metodo chiamante
  61.      *
  62.      * @param type
  63.      *            Tipo operazione {1 (CREATE),2 (UPDATE),3 (DELETE)}
  64.      * @param connettore
  65.      * @return id del connettore in caso di type 1 (CREATE)
  66.      */
  67.     public static long CRUDConnettore(int type, Connettore connettore, Connection connection, IDriverBYOK driverBYOK) throws DriverConfigurazioneException {
  68.         PreparedStatement stm = null;
  69.         ResultSet rs=null;
  70.         String sqlQuery;

  71.         if(connettore == null) throw new DriverConfigurazioneException("[DriverConfigurazioneDB_LIB::CRUDConnettore] L'oggetto Connettore non puo essere null");
  72.         if (type!=CostantiDB.DELETE &&
  73.             (connettore.getNome() == null || connettore.getNome().trim().equals(""))
  74.             ){
  75.             throw new DriverConfigurazioneException("[DriverConfigurazioneDB_LIB::CRUDConnettore]Il nome Connettore non puo essere null");
  76.         }
  77.         // il tipo di connettore (http, jms, disabilitato o altro)
  78.         String nomeConnettore = connettore.getNome();
  79.         String endpointtype = connettore.getTipo();

  80.         if (endpointtype == null || endpointtype.trim().equals(""))
  81.             endpointtype = TipiConnettore.DISABILITATO.getNome();

  82.         String url = null;// in caso di tipo http
  83.         boolean debug = false;
  84.         String nome = null; // jms
  85.         String tipo = null; // jms
  86.         String utente = null;// jms
  87.         String password = null;// jms
  88.         String initcont = null;// jms
  89.         String urlpkg = null;// jms
  90.         String provurl = null;// jms
  91.         String connectionfactory = null;// jms
  92.         String sendas = null;// jms

  93.         String transferMode = null; // in caso di tipo http e https
  94.         Integer transferModeChunkSize = null; // in caso di tipo http e https

  95.         boolean proxy = false;
  96.         String proxyType = null;
  97.         String proxyHostname = null;
  98.         String proxyPort = null;
  99.         String proxyUsername = null;
  100.         String proxyPassword = null;
  101.        
  102.         Integer tempiRispostaConnectionTimeout = null;
  103.         Integer tempiRispostaReadTimeout = null;
  104.         Integer tempiRispostaAvgResponseTime = null;

  105.         String redirectMode = null; // in caso di tipo http e https
  106.         Integer redirectMaxHop = null; // in caso di tipo http e https
  107.        
  108.         String tokenPolicy = null;
  109.        
  110.         String apiKey = null;
  111.         String apiKeyHeader = null;
  112.         String appId = null;
  113.         String appIdHeader = null;
  114.        
  115.         boolean isAbilitato = false;

  116.         Map<String, String> extendedProperties = new HashMap<>();
  117.        
  118.         List<String> propertiesGestiteAttraversoColonneAdHoc = new ArrayList<>();
  119.        
  120.         // setto i dati, se le property non sono presenti il loro valore rimarra
  121.         // a null e verra settato come tale nel DB
  122.         String nomeProperty = null;
  123.         String valoreProperty = null;
  124.         for (int i = 0; i < connettore.sizePropertyList(); i++) {
  125.             nomeProperty = connettore.getProperty(i).getNome();

  126.             valoreProperty = connettore.getProperty(i).getValore();
  127.             if (valoreProperty != null && valoreProperty.equals(""))
  128.                 valoreProperty = null;

  129.             // Debug
  130.             if (nomeProperty.equals(CostantiDB.CONNETTORE_DEBUG) &&
  131.                 "true".equals(valoreProperty)){
  132.                 debug=true;
  133.             }
  134.            
  135.             // Proxy
  136.             if (nomeProperty.equals(CostantiDB.CONNETTORE_PROXY_TYPE)){
  137.                 proxy = true;
  138.                 proxyType = valoreProperty;
  139.                
  140.                 propertiesGestiteAttraversoColonneAdHoc.add(nomeProperty);
  141.                
  142.                 // cerco altri valori del proxy
  143.                 for (Property propertyCheck: connettore.getPropertyList()) {
  144.                     if (propertyCheck.getNome().equals(CostantiDB.CONNETTORE_PROXY_HOSTNAME)){
  145.                         propertiesGestiteAttraversoColonneAdHoc.add(propertyCheck.getNome());
  146.                         proxyHostname = propertyCheck.getValore();
  147.                     }
  148.                     if (propertyCheck.getNome().equals(CostantiDB.CONNETTORE_PROXY_PORT)){
  149.                         propertiesGestiteAttraversoColonneAdHoc.add(propertyCheck.getNome());
  150.                         proxyPort = propertyCheck.getValore();
  151.                     }
  152.                     if (propertyCheck.getNome().equals(CostantiDB.CONNETTORE_PROXY_USERNAME)){
  153.                         propertiesGestiteAttraversoColonneAdHoc.add(propertyCheck.getNome());
  154.                         proxyUsername = propertyCheck.getValore();
  155.                     }
  156.                     if (propertyCheck.getNome().equals(CostantiDB.CONNETTORE_PROXY_PASSWORD)){
  157.                         propertiesGestiteAttraversoColonneAdHoc.add(propertyCheck.getNome());
  158.                         proxyPassword = propertyCheck.getValore();
  159.                     }
  160.                 }
  161.             }
  162.            
  163.             // Tempi Risposta
  164.             if (nomeProperty.equals(CostantiDB.CONNETTORE_CONNECTION_TIMEOUT)){
  165.                 propertiesGestiteAttraversoColonneAdHoc.add(nomeProperty);
  166.                 tempiRispostaConnectionTimeout = Integer.parseInt(valoreProperty);
  167.             }
  168.             if (nomeProperty.equals(CostantiDB.CONNETTORE_READ_CONNECTION_TIMEOUT)){
  169.                 propertiesGestiteAttraversoColonneAdHoc.add(nomeProperty);
  170.                 tempiRispostaReadTimeout = Integer.parseInt(valoreProperty);
  171.             }
  172.             if (nomeProperty.equals(CostantiDB.CONNETTORE_TEMPO_MEDIO_RISPOSTA)){
  173.                 propertiesGestiteAttraversoColonneAdHoc.add(nomeProperty);
  174.                 tempiRispostaAvgResponseTime = Integer.parseInt(valoreProperty);
  175.             }
  176.            
  177.             // TransferMode
  178.             if (nomeProperty.equals(CostantiDB.CONNETTORE_HTTP_DATA_TRANSFER_MODE)){
  179.                 propertiesGestiteAttraversoColonneAdHoc.add(nomeProperty);
  180.                 transferMode = valoreProperty;
  181.             }
  182.             if (nomeProperty.equals(CostantiDB.CONNETTORE_HTTP_DATA_TRANSFER_MODE_CHUNK_SIZE)){
  183.                 propertiesGestiteAttraversoColonneAdHoc.add(nomeProperty);
  184.                 transferModeChunkSize = Integer.parseInt(valoreProperty);
  185.             }
  186.            
  187.             // RedirectMode
  188.             if (nomeProperty.equals(CostantiDB.CONNETTORE_HTTP_REDIRECT_FOLLOW)){
  189.                 propertiesGestiteAttraversoColonneAdHoc.add(nomeProperty);
  190.                 redirectMode = valoreProperty;
  191.             }
  192.             if (nomeProperty.equals(CostantiDB.CONNETTORE_HTTP_REDIRECT_MAX_HOP)){
  193.                 propertiesGestiteAttraversoColonneAdHoc.add(nomeProperty);
  194.                 redirectMaxHop = Integer.parseInt(valoreProperty);
  195.             }
  196.            
  197.             // TokenPolicy
  198.             if (nomeProperty.equals(CostantiDB.CONNETTORE_TOKEN_POLICY)){
  199.                 propertiesGestiteAttraversoColonneAdHoc.add(nomeProperty);
  200.                 tokenPolicy = valoreProperty;
  201.             }
  202.            
  203.             // ApiKey
  204.             if (nomeProperty.equals(CostantiDB.CONNETTORE_APIKEY)){
  205.                 propertiesGestiteAttraversoColonneAdHoc.add(nomeProperty);
  206.                 apiKey = valoreProperty;
  207.             }
  208.             if (nomeProperty.equals(CostantiDB.CONNETTORE_APIKEY_HEADER)){
  209.                 propertiesGestiteAttraversoColonneAdHoc.add(nomeProperty);
  210.                 apiKeyHeader = valoreProperty;
  211.             }
  212.             if (nomeProperty.equals(CostantiDB.CONNETTORE_APIKEY_APPID)){
  213.                 propertiesGestiteAttraversoColonneAdHoc.add(nomeProperty);
  214.                 appId = valoreProperty;
  215.             }
  216.             if (nomeProperty.equals(CostantiDB.CONNETTORE_APIKEY_APPID_HEADER)){
  217.                 propertiesGestiteAttraversoColonneAdHoc.add(nomeProperty);
  218.                 appIdHeader = valoreProperty;
  219.             }

  220.             if(TipiConnettore.HTTP.getNome().equals(endpointtype)){
  221.                 if (nomeProperty.equals(CostantiDB.CONNETTORE_HTTP_LOCATION))
  222.                     url = valoreProperty;
  223.             }
  224.             else if(TipiConnettore.JMS.getNome().equals(endpointtype)){
  225.                 if (nomeProperty.equals(CostantiDB.CONNETTORE_JMS_NOME))
  226.                     nome = valoreProperty;
  227.                 else if (nomeProperty.equals(CostantiDB.CONNETTORE_JMS_TIPO))
  228.                     tipo = valoreProperty;
  229.                 else if (nomeProperty.equals(CostantiDB.CONNETTORE_USER))
  230.                     utente = valoreProperty;
  231.                 else if (nomeProperty.equals(CostantiDB.CONNETTORE_PWD))
  232.                     password = valoreProperty;
  233.                 else if (nomeProperty.equals(CostantiDB.CONNETTORE_JMS_CONTEXT_JAVA_NAMING_FACTORY_INITIAL))
  234.                     initcont = valoreProperty;
  235.                 else if (nomeProperty.equals(CostantiDB.CONNETTORE_JMS_CONTEXT_JAVA_NAMING_FACTORY_URL_PKG))
  236.                     urlpkg = valoreProperty;
  237.                 else if (nomeProperty.equals(CostantiDB.CONNETTORE_JMS_CONTEXT_JAVA_NAMING_PROVIDER_URL))
  238.                     provurl = valoreProperty;
  239.                 else if (nomeProperty.equals(CostantiDB.CONNETTORE_JMS_CONNECTION_FACTORY))
  240.                     connectionfactory = valoreProperty;
  241.                 else if (nomeProperty.equals(CostantiDB.CONNETTORE_JMS_SEND_AS))
  242.                     sendas = valoreProperty;
  243.             }

  244.             // se endpointype != disabilitato allora lo setto abilitato
  245.             if (!endpointtype.equalsIgnoreCase(TipiConnettore.DISABILITATO.getNome()))
  246.                 isAbilitato = true;
  247.            
  248.             // extendedProperties
  249.             if(nomeProperty.startsWith(CostantiConnettori.CONNETTORE_EXTENDED_PREFIX)){
  250.                 extendedProperties.put(nomeProperty, valoreProperty);
  251.             }

  252.         }

  253.         try {

  254.             long idConnettore = 0;
  255.             int n = 0;
  256.             switch (type) {
  257.             case CREATE:

  258.                 // create
  259.                 ISQLQueryObject sqlQueryObject = SQLObjectFactory.createSQLQueryObject(DriverConfigurazioneDBLib.tipoDB);
  260.                 sqlQueryObject.addInsertTable(CostantiDB.CONNETTORI);
  261.                 sqlQueryObject.addInsertField(CostantiDB.CONNETTORI_COLUMN_ENDPOINT_TYPE, "?");
  262.                 sqlQueryObject.addInsertField("url", "?");
  263.                 sqlQueryObject.addInsertField("transfer_mode", "?");
  264.                 sqlQueryObject.addInsertField("transfer_mode_chunk_size", "?");
  265.                 sqlQueryObject.addInsertField("redirect_mode", "?");
  266.                 sqlQueryObject.addInsertField("redirect_max_hop", "?");
  267.                 sqlQueryObject.addInsertField("nome", "?");
  268.                 sqlQueryObject.addInsertField("tipo", "?");
  269.                 sqlQueryObject.addInsertField("utente", "?");
  270.                 sqlQueryObject.addInsertField("password", "?");
  271.                 sqlQueryObject.addInsertField("enc_password", "?");
  272.                 sqlQueryObject.addInsertField("initcont", "?");
  273.                 sqlQueryObject.addInsertField("urlpkg", "?");
  274.                 sqlQueryObject.addInsertField("provurl", "?");
  275.                 sqlQueryObject.addInsertField("connection_factory", "?");
  276.                 sqlQueryObject.addInsertField("send_as", "?");
  277.                 sqlQueryObject.addInsertField(CostantiDB.CONNETTORI_COLUMN_NOME, "?");
  278.                 sqlQueryObject.addInsertField("debug", "?");                
  279.                 sqlQueryObject.addInsertField("proxy", "?");        
  280.                 sqlQueryObject.addInsertField("proxy_type", "?");      
  281.                 sqlQueryObject.addInsertField("proxy_hostname", "?");      
  282.                 sqlQueryObject.addInsertField("proxy_port", "?");      
  283.                 sqlQueryObject.addInsertField("proxy_username", "?");      
  284.                 sqlQueryObject.addInsertField("proxy_password", "?");  
  285.                 sqlQueryObject.addInsertField("enc_proxy_password", "?");
  286.                 sqlQueryObject.addInsertField("connection_timeout", "?");      
  287.                 sqlQueryObject.addInsertField("read_timeout", "?");    
  288.                 sqlQueryObject.addInsertField("avg_response_time", "?");        
  289.                 sqlQueryObject.addInsertField("custom", "?");
  290.                 sqlQueryObject.addInsertField("token_policy", "?");
  291.                 sqlQueryObject.addInsertField("api_key", "?");
  292.                 sqlQueryObject.addInsertField("api_key_header", "?");
  293.                 sqlQueryObject.addInsertField("app_id", "?");
  294.                 sqlQueryObject.addInsertField("app_id_header", "?");
  295.                 sqlQuery = sqlQueryObject.createSQLInsert();
  296.                 stm = connection.prepareStatement(sqlQuery);

  297.                 int index = 1;
  298.                 stm.setString(index++, endpointtype);
  299.                 stm.setString(index++, (isAbilitato ? url : null));
  300.                 stm.setString(index++, (isAbilitato ? transferMode : null));
  301.                 if(isAbilitato && transferModeChunkSize!=null){
  302.                     stm.setInt(index++, transferModeChunkSize);
  303.                 }
  304.                 else{
  305.                     stm.setNull(index++, Types.INTEGER);
  306.                 }
  307.                 stm.setString(index++, (isAbilitato ? redirectMode : null));
  308.                 if(isAbilitato && redirectMaxHop!=null){
  309.                     stm.setInt(index++, redirectMaxHop);
  310.                 }
  311.                 else{
  312.                     stm.setNull(index++, Types.INTEGER);
  313.                 }
  314.                 stm.setString(index++, isAbilitato ? nome : null);
  315.                 stm.setString(index++, isAbilitato ? tipo : null);
  316.                 stm.setString(index++, (isAbilitato ? utente : null));
  317.                
  318.                 String plainPassword = isAbilitato ? password : null;
  319.                 String encPassword = null;
  320.                 if(isAbilitato && driverBYOK!=null && plainPassword!=null) {
  321.                     BYOKWrappedValue byokValue = driverBYOK.wrap(plainPassword);
  322.                     if(byokValue!=null) {
  323.                         encPassword = byokValue.getWrappedValue();
  324.                         plainPassword = byokValue.getWrappedPlainValue();
  325.                     }
  326.                 }
  327.                 stm.setString(index++, plainPassword);
  328.                 stm.setString(index++, encPassword);
  329.                
  330.                 stm.setString(index++, (isAbilitato ? initcont : null));
  331.                 stm.setString(index++, (isAbilitato ? urlpkg : null));
  332.                 stm.setString(index++, (isAbilitato ? provurl : null));
  333.                 stm.setString(index++, (isAbilitato ? connectionfactory : null));
  334.                 stm.setString(index++, (isAbilitato ? sendas : null));
  335.                 stm.setString(index++, nomeConnettore);
  336.                 if(debug){
  337.                     stm.setInt(index++, 1);
  338.                 }else{
  339.                     stm.setInt(index++, 0);
  340.                 }
  341.                 if(proxy){
  342.                     stm.setInt(index++, 1);
  343.                 }else{
  344.                     stm.setInt(index++, 0);
  345.                 }
  346.                 stm.setString(index++, isAbilitato && proxy ? proxyType : null);
  347.                 stm.setString(index++, isAbilitato && proxy ? proxyHostname : null);
  348.                 stm.setString(index++, isAbilitato && proxy ? proxyPort : null);
  349.                 stm.setString(index++, isAbilitato && proxy ? proxyUsername : null);

  350.                 String plainProxyPassword = isAbilitato ? proxyPassword : null;
  351.                 String encProxyPassword = null;
  352.                 if(isAbilitato && driverBYOK!=null && plainProxyPassword!=null) {
  353.                     BYOKWrappedValue byokValue = driverBYOK.wrap(plainProxyPassword);
  354.                     if(byokValue!=null) {
  355.                         encProxyPassword = byokValue.getWrappedValue();
  356.                         plainProxyPassword = byokValue.getWrappedPlainValue();
  357.                     }
  358.                 }
  359.                 stm.setString(index++, plainProxyPassword);
  360.                 stm.setString(index++, encProxyPassword);
  361.                
  362.                 if(tempiRispostaConnectionTimeout!=null) {
  363.                     stm.setInt(index++, tempiRispostaConnectionTimeout);
  364.                 }
  365.                 else {
  366.                     stm.setNull(index++, Types.INTEGER);
  367.                 }
  368.                 if(tempiRispostaReadTimeout!=null) {
  369.                     stm.setInt(index++, tempiRispostaReadTimeout);
  370.                 }
  371.                 else {
  372.                     stm.setNull(index++, Types.INTEGER);
  373.                 }
  374.                 if(tempiRispostaAvgResponseTime!=null) {
  375.                     stm.setInt(index++, tempiRispostaAvgResponseTime);
  376.                 }
  377.                 else {
  378.                     stm.setNull(index++, Types.INTEGER);
  379.                 }
  380.                 if(connettore.getCustom()!=null && connettore.getCustom()){
  381.                     stm.setInt(index++, 1);
  382.                 }else{
  383.                     stm.setInt(index++, 0);
  384.                 }
  385.                 stm.setString(index++, tokenPolicy);
  386.                
  387.                 String apiKeyInsert = isAbilitato ? apiKey : null;
  388.                 if(isAbilitato && apiKey!=null && StringUtils.isNotEmpty(apiKey) && driverBYOK!=null && CostantiConnettori.isConfidential(CostantiDB.CONNETTORE_APIKEY)) {
  389.                     BYOKWrappedValue byokValue = driverBYOK.wrap(apiKey);
  390.                     if(byokValue!=null) {
  391.                         apiKeyInsert = byokValue.getWrappedValue();
  392.                         stm.setString(index++, byokValue.getWrappedValue());
  393.                     }
  394.                     else {
  395.                         stm.setString(index++, apiKey);
  396.                     }
  397.                 }
  398.                 else {
  399.                     stm.setString(index++, apiKey);
  400.                 }
  401.                 stm.setString(index++, isAbilitato ? apiKeyHeader : null);
  402.                 stm.setString(index++, isAbilitato ? appId : null);
  403.                 stm.setString(index++, isAbilitato ? appIdHeader : null);

  404.                 DriverConfigurazioneDBLib.logDebug("CRUDConnettore CREATE : \n" + DBUtils.formatSQLString(sqlQuery, endpointtype, url,
  405.                         transferMode, transferModeChunkSize, redirectMode, redirectMaxHop,
  406.                         nome, tipo, utente, plainPassword, encPassword,
  407.                         initcont, urlpkg, provurl, connectionfactory, sendas, nomeConnettore,debug,
  408.                         proxy, proxyType, proxyHostname, proxyPort, proxyUsername, plainProxyPassword, encProxyPassword,
  409.                         tempiRispostaConnectionTimeout, tempiRispostaReadTimeout, tempiRispostaAvgResponseTime,
  410.                         (connettore.getCustom()!=null && connettore.getCustom()),
  411.                         tokenPolicy,
  412.                         apiKeyInsert, apiKeyHeader, appId, appIdHeader));

  413.                 n = stm.executeUpdate();
  414.                 stm.close();
  415.                 DriverConfigurazioneDBLib.logDebug("Inserted " + n + " row(s)");


  416.                 sqlQueryObject = SQLObjectFactory.createSQLQueryObject(DriverConfigurazioneDBLib.tipoDB);
  417.                 sqlQueryObject.addFromTable(CostantiDB.CONNETTORI);
  418.                 sqlQueryObject.addSelectField("*");
  419.                 sqlQueryObject.addWhereCondition("endpointtype = ?");
  420.                 sqlQueryObject.addWhereCondition("nome_connettore = ?");
  421.                 sqlQueryObject.setANDLogicOperator(true);
  422.                 sqlQuery = sqlQueryObject.createSQLQuery();
  423.                 stm = connection.prepareStatement(sqlQuery);

  424.                 stm.setString(1, endpointtype);
  425.                 stm.setString(2, nomeConnettore);

  426.                 DriverConfigurazioneDBLib.logDebug("Recupero idConnettore inserito : \n" + DBUtils.formatSQLString(sqlQuery, endpointtype, nomeConnettore));

  427.                 rs = stm.executeQuery();

  428.                 if (rs.next()) {
  429.                     idConnettore = rs.getLong("id");
  430.                     connettore.setId(idConnettore);
  431.                 } else {
  432.                     throw new DriverConfigurazioneException("[DriverConfigurazioneDB_LIB::CRUDConnettore] Errore tentanto di effettuare la select dopo una create, non riesco a recuperare l'id!");
  433.                 }

  434.                 rs.close();
  435.                 stm.close();                
  436.                
  437.                 // Custom properties
  438.                 if(connettore.getCustom()!=null && connettore.getCustom()){                
  439.                     sqlQueryObject = SQLObjectFactory.createSQLQueryObject(DriverConfigurazioneDBLib.tipoDB);
  440.                     sqlQueryObject.addInsertTable(CostantiDB.CONNETTORI_CUSTOM);
  441.                     sqlQueryObject.addInsertField(CostantiDB.CONNETTORI_CUSTOM_COLUMN_NAME, "?");
  442.                     sqlQueryObject.addInsertField(CostantiDB.CONNETTORI_CUSTOM_COLUMN_VALUE, "?");
  443.                     sqlQueryObject.addInsertField(CostantiDB.CONNETTORI_CUSTOM_COLUMN_ENC_VALUE, "?");
  444.                     sqlQueryObject.addInsertField(CostantiDB.CONNETTORI_CUSTOM_COLUMN_ID_CONNETTORE, "?");
  445.                     sqlQuery = sqlQueryObject.createSQLInsert();
  446.                    
  447.                     for (int i = 0; i < connettore.sizePropertyList(); i++) {
  448.                         nomeProperty = connettore.getProperty(i).getNome();
  449.                         if(propertiesGestiteAttraversoColonneAdHoc.contains(nomeProperty)){
  450.                             continue;
  451.                         }
  452.                         valoreProperty = connettore.getProperty(i).getValore();
  453.                         if (valoreProperty != null && valoreProperty.equals(""))
  454.                             valoreProperty = null;
  455.                    
  456.                         if(valoreProperty==null){
  457.                             throw new DriverConfigurazioneException("Property ["+nomeProperty+"] without value");
  458.                         }
  459.                        
  460.                         String plainValue = valoreProperty;
  461.                         String encValue = null;
  462.                         if(driverBYOK!=null && CostantiConnettori.isConfidential(nomeProperty)) {
  463.                             BYOKWrappedValue byokValue = driverBYOK.wrap(valoreProperty);
  464.                             if(byokValue!=null) {
  465.                                 encValue = byokValue.getWrappedValue();
  466.                                 plainValue = byokValue.getWrappedPlainValue();
  467.                             }
  468.                         }
  469.                        
  470.                         stm = connection.prepareStatement(sqlQuery);
  471.                         stm.setString(1, nomeProperty);
  472.                         stm.setString(2, plainValue);
  473.                         stm.setString(3, encValue);
  474.                         stm.setLong(4, connettore.getId());
  475.                         stm.executeUpdate();
  476.                         stm.close();
  477.                     }              
  478.                 }
  479.                 else if(extendedProperties.size()>0){
  480.                     sqlQueryObject = SQLObjectFactory.createSQLQueryObject(DriverConfigurazioneDBLib.tipoDB);
  481.                     sqlQueryObject.addInsertTable(CostantiDB.CONNETTORI_CUSTOM);
  482.                     sqlQueryObject.addInsertField(CostantiDB.CONNETTORI_CUSTOM_COLUMN_NAME, "?");
  483.                     sqlQueryObject.addInsertField(CostantiDB.CONNETTORI_CUSTOM_COLUMN_VALUE, "?");
  484.                     sqlQueryObject.addInsertField(CostantiDB.CONNETTORI_CUSTOM_COLUMN_ENC_VALUE, "?");
  485.                     sqlQueryObject.addInsertField(CostantiDB.CONNETTORI_CUSTOM_COLUMN_ID_CONNETTORE, "?");
  486.                     sqlQuery = sqlQueryObject.createSQLInsert();
  487.                    
  488.                     for (String nomeP : extendedProperties.keySet()) {
  489.                         valoreProperty = extendedProperties.get(nomeP);
  490.                         if (valoreProperty != null && valoreProperty.equals(""))
  491.                             valoreProperty = null;
  492.                    
  493.                         if(valoreProperty==null){
  494.                             throw new DriverConfigurazioneException("Property ["+nomeP+"] without value");
  495.                         }
  496.                        
  497.                         String plainValue = valoreProperty;
  498.                         String encValue = null;
  499.                         if(driverBYOK!=null && CostantiConnettori.isConfidential(nomeProperty)) {
  500.                             BYOKWrappedValue byokValue = driverBYOK.wrap(valoreProperty);
  501.                             if(byokValue!=null) {
  502.                                 encValue = byokValue.getWrappedValue();
  503.                                 plainValue = byokValue.getWrappedPlainValue();
  504.                             }
  505.                         }
  506.                        
  507.                         stm = connection.prepareStatement(sqlQuery);
  508.                         stm.setString(1, nomeP);
  509.                         stm.setString(2, plainValue);
  510.                         stm.setString(3, encValue);
  511.                         stm.setLong(4, connettore.getId());
  512.                         stm.executeUpdate();
  513.                         stm.close();
  514.                     }              
  515.                 }

  516.                 break;

  517.             case UPDATE:
  518.                 // update
  519.                 idConnettore = connettore.getId();

  520.                 if (idConnettore < 0)
  521.                     throw new DriverConfigurazioneException("[DriverConfigurazioneDB_LIB::CRUDConnettore] L'id del connettore non puo essere 0 tentando di fare una operazione di update.");

  522.                 sqlQueryObject = SQLObjectFactory.createSQLQueryObject(DriverConfigurazioneDBLib.tipoDB);
  523.                 sqlQueryObject.addUpdateTable(CostantiDB.CONNETTORI);
  524.                 sqlQueryObject.addUpdateField(CostantiDB.CONNETTORI_COLUMN_ENDPOINT_TYPE, "?");
  525.                 sqlQueryObject.addUpdateField("url", "?");
  526.                 sqlQueryObject.addUpdateField("transfer_mode", "?");
  527.                 sqlQueryObject.addUpdateField("transfer_mode_chunk_size", "?");
  528.                 sqlQueryObject.addUpdateField("redirect_mode", "?");
  529.                 sqlQueryObject.addUpdateField("redirect_max_hop", "?");
  530.                 sqlQueryObject.addUpdateField("nome", "?");
  531.                 sqlQueryObject.addUpdateField("tipo", "?");
  532.                 sqlQueryObject.addUpdateField("utente", "?");
  533.                 sqlQueryObject.addUpdateField("password", "?");
  534.                 sqlQueryObject.addUpdateField("enc_password", "?");
  535.                 sqlQueryObject.addUpdateField("initcont", "?");
  536.                 sqlQueryObject.addUpdateField("urlpkg", "?");
  537.                 sqlQueryObject.addUpdateField("provurl", "?");
  538.                 sqlQueryObject.addUpdateField("connection_factory", "?");
  539.                 sqlQueryObject.addUpdateField("send_as", "?");
  540.                 sqlQueryObject.addUpdateField(CostantiDB.CONNETTORI_COLUMN_NOME, "?");
  541.                 sqlQueryObject.addUpdateField("debug", "?");
  542.                 sqlQueryObject.addUpdateField("proxy", "?");        
  543.                 sqlQueryObject.addUpdateField("proxy_type", "?");      
  544.                 sqlQueryObject.addUpdateField("proxy_hostname", "?");      
  545.                 sqlQueryObject.addUpdateField("proxy_port", "?");      
  546.                 sqlQueryObject.addUpdateField("proxy_username", "?");      
  547.                 sqlQueryObject.addUpdateField("proxy_password", "?");
  548.                 sqlQueryObject.addUpdateField("enc_proxy_password", "?");
  549.                 sqlQueryObject.addUpdateField("connection_timeout", "?");      
  550.                 sqlQueryObject.addUpdateField("read_timeout", "?");    
  551.                 sqlQueryObject.addUpdateField("avg_response_time", "?");
  552.                 sqlQueryObject.addUpdateField("custom", "?");
  553.                 sqlQueryObject.addUpdateField("token_policy", "?");
  554.                 sqlQueryObject.addUpdateField("api_key", "?");
  555.                 sqlQueryObject.addUpdateField("api_key_header", "?");
  556.                 sqlQueryObject.addUpdateField("app_id", "?");
  557.                 sqlQueryObject.addUpdateField("app_id_header", "?");
  558.                 sqlQueryObject.addWhereCondition("id=?");
  559.                 sqlQuery = sqlQueryObject.createSQLUpdate();
  560.                 stm = connection.prepareStatement(sqlQuery);

  561.                 index = 1;
  562.                 stm.setString(index++, endpointtype);
  563.                 stm.setString(index++, url);
  564.                 stm.setString(index++, (isAbilitato ? transferMode : null));
  565.                 if(isAbilitato && transferModeChunkSize!=null){
  566.                     stm.setInt(index++, transferModeChunkSize);
  567.                 }
  568.                 else{
  569.                     stm.setNull(index++, Types.INTEGER);
  570.                 }
  571.                 stm.setString(index++, (isAbilitato ? redirectMode : null));
  572.                 if(isAbilitato && redirectMaxHop!=null){
  573.                     stm.setInt(index++, redirectMaxHop);
  574.                 }
  575.                 else{
  576.                     stm.setNull(index++, Types.INTEGER);
  577.                 }
  578.                 stm.setString(index++, isAbilitato ? nome : null);
  579.                 stm.setString(index++, isAbilitato ? tipo: null);
  580.                 stm.setString(index++, (isAbilitato ? utente : null));
  581.                
  582.                 plainPassword = isAbilitato ? password : null;
  583.                 encPassword = null;
  584.                 if(isAbilitato && driverBYOK!=null && plainPassword!=null) {
  585.                     BYOKWrappedValue byokValue = driverBYOK.wrap(plainPassword);
  586.                     if(byokValue!=null) {
  587.                         encPassword = byokValue.getWrappedValue();
  588.                         plainPassword = byokValue.getWrappedPlainValue();
  589.                     }
  590.                 }
  591.                 stm.setString(index++, plainPassword);
  592.                 stm.setString(index++, encPassword);
  593.                
  594.                 stm.setString(index++, (isAbilitato ? initcont : null));
  595.                 stm.setString(index++, (isAbilitato ? urlpkg : null));
  596.                 stm.setString(index++, (isAbilitato ? provurl : null));
  597.                 stm.setString(index++, (isAbilitato ? connectionfactory : null));
  598.                 stm.setString(index++, (isAbilitato ? sendas : null));
  599.                 stm.setString(index++, nomeConnettore);
  600.                 if(debug){
  601.                     stm.setInt(index++, 1);
  602.                 }else{
  603.                     stm.setInt(index++, 0);
  604.                 }
  605.                 if(proxy){
  606.                     stm.setInt(index++, 1);
  607.                 }else{
  608.                     stm.setInt(index++, 0);
  609.                 }
  610.                 stm.setString(index++, isAbilitato && proxy ? proxyType : null);
  611.                 stm.setString(index++, isAbilitato && proxy ? proxyHostname : null);
  612.                 stm.setString(index++, isAbilitato && proxy ? proxyPort : null);
  613.                 stm.setString(index++, isAbilitato && proxy ? proxyUsername : null);

  614.                 plainProxyPassword = isAbilitato ? proxyPassword : null;
  615.                 encProxyPassword = null;
  616.                 if(isAbilitato && driverBYOK!=null && plainProxyPassword!=null) {
  617.                     BYOKWrappedValue byokValue = driverBYOK.wrap(plainProxyPassword);
  618.                     if(byokValue!=null) {
  619.                         encProxyPassword = byokValue.getWrappedValue();
  620.                         plainProxyPassword = byokValue.getWrappedPlainValue();
  621.                     }
  622.                 }
  623.                 stm.setString(index++, plainProxyPassword);
  624.                 stm.setString(index++, encProxyPassword);
  625.                
  626.                 if(tempiRispostaConnectionTimeout!=null) {
  627.                     stm.setInt(index++, tempiRispostaConnectionTimeout);
  628.                 }
  629.                 else {
  630.                     stm.setNull(index++, Types.INTEGER);
  631.                 }
  632.                 if(tempiRispostaReadTimeout!=null) {
  633.                     stm.setInt(index++, tempiRispostaReadTimeout);
  634.                 }
  635.                 else {
  636.                     stm.setNull(index++, Types.INTEGER);
  637.                 }
  638.                 if(tempiRispostaAvgResponseTime!=null) {
  639.                     stm.setInt(index++, tempiRispostaAvgResponseTime);
  640.                 }
  641.                 else {
  642.                     stm.setNull(index++, Types.INTEGER);
  643.                 }
  644.                 if(connettore.getCustom()!=null && connettore.getCustom()){
  645.                     stm.setInt(index++, 1);
  646.                 }else{
  647.                     stm.setInt(index++, 0);
  648.                 }
  649.                 stm.setString(index++, tokenPolicy);
  650.                
  651.                 apiKeyInsert = isAbilitato ? apiKey : null;
  652.                 if(isAbilitato && apiKey!=null && StringUtils.isNotEmpty(apiKey) && driverBYOK!=null && CostantiConnettori.isConfidential(CostantiDB.CONNETTORE_APIKEY)) {
  653.                     BYOKWrappedValue byokValue = driverBYOK.wrap(apiKey);
  654.                     if(byokValue!=null) {
  655.                         apiKeyInsert = byokValue.getWrappedValue();
  656.                         stm.setString(index++, byokValue.getWrappedValue());
  657.                     }
  658.                     else {
  659.                         stm.setString(index++, apiKey);
  660.                     }
  661.                 }
  662.                 else {
  663.                     stm.setString(index++, apiKey);
  664.                 }
  665.                 stm.setString(index++, isAbilitato ? apiKeyHeader : null);
  666.                 stm.setString(index++, isAbilitato ? appId : null);
  667.                 stm.setString(index++, isAbilitato ? appIdHeader : null);
  668.                
  669.                 stm.setLong(index++, idConnettore);

  670.                 stm.executeUpdate();
  671.                 stm.close();
  672.                 DriverConfigurazioneDBLib.logDebug("CRUDConnettore UPDATE : \n" + DBUtils.formatSQLString(sqlQuery, endpointtype, url,
  673.                         transferMode, transferModeChunkSize, redirectMode, redirectMaxHop,
  674.                         nome, tipo, utente, plainPassword, encPassword,
  675.                         initcont, urlpkg, provurl, connectionfactory, sendas,nomeConnettore, debug,
  676.                         proxy, proxyType, proxyHostname, proxyPort, proxyUsername, plainProxyPassword, encProxyPassword,
  677.                         tempiRispostaConnectionTimeout, tempiRispostaReadTimeout, tempiRispostaAvgResponseTime,
  678.                         (connettore.getCustom()!=null && connettore.getCustom()),
  679.                         tokenPolicy,
  680.                         apiKeyInsert, apiKeyHeader, appId, appIdHeader,
  681.                         idConnettore));

  682.                 // Custom properties
  683.                 // Delete eventuali vecchie properties
  684.                 sqlQueryObject = SQLObjectFactory.createSQLQueryObject(DriverConfigurazioneDBLib.tipoDB);
  685.                 sqlQueryObject.addDeleteTable(CostantiDB.CONNETTORI_CUSTOM);
  686.                 sqlQueryObject.addWhereCondition("id_connettore=?");
  687.                 sqlQuery = sqlQueryObject.createSQLDelete();
  688.                 stm = connection.prepareStatement(sqlQuery);
  689.                 stm.setLong(1, idConnettore);
  690.                 stm.executeUpdate();
  691.                 stm.close();
  692.                 // Aggiungo attuali
  693.                 if(connettore.getCustom()!=null && connettore.getCustom()){                
  694.                     sqlQueryObject = SQLObjectFactory.createSQLQueryObject(DriverConfigurazioneDBLib.tipoDB);
  695.                     sqlQueryObject.addInsertTable(CostantiDB.CONNETTORI_CUSTOM);
  696.                     sqlQueryObject.addInsertField(CostantiDB.CONNETTORI_CUSTOM_COLUMN_NAME, "?");
  697.                     sqlQueryObject.addInsertField(CostantiDB.CONNETTORI_CUSTOM_COLUMN_VALUE, "?");
  698.                     sqlQueryObject.addInsertField(CostantiDB.CONNETTORI_CUSTOM_COLUMN_ENC_VALUE, "?");
  699.                     sqlQueryObject.addInsertField(CostantiDB.CONNETTORI_CUSTOM_COLUMN_ID_CONNETTORE, "?");
  700.                     sqlQuery = sqlQueryObject.createSQLInsert();
  701.                    
  702.                     for (int i = 0; i < connettore.sizePropertyList(); i++) {
  703.                         nomeProperty = connettore.getProperty(i).getNome();
  704.                         if(propertiesGestiteAttraversoColonneAdHoc.contains(nomeProperty)){
  705.                             continue;
  706.                         }
  707.                         valoreProperty = connettore.getProperty(i).getValore();
  708.                         if (valoreProperty != null && valoreProperty.equals(""))
  709.                             valoreProperty = null;
  710.                    
  711.                         if(valoreProperty==null){
  712.                             throw new DriverConfigurazioneException("Property ["+nomeProperty+"] without value");
  713.                         }
  714.                        
  715.                         String plainValue = valoreProperty;
  716.                         String encValue = null;
  717.                         if(driverBYOK!=null && CostantiConnettori.isConfidential(nomeProperty)) {
  718.                             BYOKWrappedValue byokValue = driverBYOK.wrap(valoreProperty);
  719.                             if(byokValue!=null) {
  720.                                 encValue = byokValue.getWrappedValue();
  721.                                 plainValue = byokValue.getWrappedPlainValue();
  722.                             }
  723.                         }
  724.                        
  725.                         stm = connection.prepareStatement(sqlQuery);
  726.                         stm.setString(1, nomeProperty);
  727.                         stm.setString(2, plainValue);
  728.                         stm.setString(3, encValue);
  729.                         stm.setLong(4, idConnettore);
  730.                         stm.executeUpdate();
  731.                         stm.close();
  732.                     }              
  733.                 }
  734.                 else if(extendedProperties.size()>0){
  735.                     sqlQueryObject = SQLObjectFactory.createSQLQueryObject(DriverConfigurazioneDBLib.tipoDB);
  736.                     sqlQueryObject.addInsertTable(CostantiDB.CONNETTORI_CUSTOM);
  737.                     sqlQueryObject.addInsertField(CostantiDB.CONNETTORI_CUSTOM_COLUMN_NAME, "?");
  738.                     sqlQueryObject.addInsertField(CostantiDB.CONNETTORI_CUSTOM_COLUMN_VALUE, "?");
  739.                     sqlQueryObject.addInsertField(CostantiDB.CONNETTORI_CUSTOM_COLUMN_ENC_VALUE, "?");
  740.                     sqlQueryObject.addInsertField(CostantiDB.CONNETTORI_CUSTOM_COLUMN_ID_CONNETTORE, "?");
  741.                     sqlQuery = sqlQueryObject.createSQLInsert();
  742.                    
  743.                     for (String nomeP : extendedProperties.keySet()) {
  744.                         valoreProperty = extendedProperties.get(nomeP);
  745.                         if (valoreProperty != null && valoreProperty.equals(""))
  746.                             valoreProperty = null;
  747.                    
  748.                         if(valoreProperty==null){
  749.                             throw new DriverConfigurazioneException("Property ["+nomeP+"] without value");
  750.                         }
  751.                        
  752.                         String plainValue = valoreProperty;
  753.                         String encValue = null;
  754.                         if(driverBYOK!=null && CostantiConnettori.isConfidential(nomeProperty)) {
  755.                             BYOKWrappedValue byokValue = driverBYOK.wrap(valoreProperty);
  756.                             if(byokValue!=null) {
  757.                                 encValue = byokValue.getWrappedValue();
  758.                                 plainValue = byokValue.getWrappedPlainValue();
  759.                             }
  760.                         }
  761.                        
  762.                         stm = connection.prepareStatement(sqlQuery);
  763.                         stm.setString(1, nomeP);
  764.                         stm.setString(2, plainValue);
  765.                         stm.setString(3, encValue);
  766.                         stm.setLong(4, idConnettore);
  767.                         stm.executeUpdate();
  768.                         stm.close();
  769.                     }          
  770.                 }
  771.                
  772.                 break;

  773.             case DELETE:
  774.                 // delete
  775.                 idConnettore = connettore.getId();

  776.                 if (idConnettore < 0)
  777.                     throw new DriverConfigurazioneException("[DriverConfigurazioneDB_LIB::CRUDConnettore] L'id del connettore non puo essere 0 tentando di fare una operazione di delete.");

  778.                 // Delete eventuali vecchie properties
  779.                 sqlQueryObject = SQLObjectFactory.createSQLQueryObject(DriverConfigurazioneDBLib.tipoDB);
  780.                 sqlQueryObject.addDeleteTable(CostantiDB.CONNETTORI_CUSTOM);
  781.                 sqlQueryObject.addWhereCondition("id_connettore=?");
  782.                 sqlQuery = sqlQueryObject.createSQLDelete();
  783.                 stm = connection.prepareStatement(sqlQuery);
  784.                 stm.setLong(1, idConnettore);
  785.                 stm.executeUpdate();
  786.                 stm.close();
  787.                
  788.                 // Delete connettori
  789.                 sqlQueryObject = SQLObjectFactory.createSQLQueryObject(DriverConfigurazioneDBLib.tipoDB);
  790.                 sqlQueryObject.addDeleteTable(CostantiDB.CONNETTORI);
  791.                 sqlQueryObject.addWhereCondition("id=?");
  792.                 sqlQuery = sqlQueryObject.createSQLDelete();
  793.                 stm = connection.prepareStatement(sqlQuery);
  794.                 stm.setLong(1, idConnettore);
  795.                 stm.executeUpdate();
  796.                 stm.close();
  797.                 DriverConfigurazioneDBLib.logDebug("CRUDConnettore DELETE : \n" + DBUtils.formatSQLString(sqlQuery, idConnettore));

  798.                 break;
  799.             }

  800.             // ritorno l id del connettore questo e' utile in caso di create
  801.             return idConnettore;

  802.         } catch (SQLException se) {
  803.             throw new DriverConfigurazioneException("[DriverConfigurazioneDB_LIB::CRUDConnettore] SQLException : " + se.getMessage(),se);
  804.         }catch (Exception se) {
  805.             throw new DriverConfigurazioneException("[DriverConfigurazioneDB_LIB::CRUDConnettore] Exception : " + se.getMessage(),se);
  806.         } finally {
  807.             JDBCUtilities.closeResources(rs, stm);
  808.         }
  809.     }

  810.     /**
  811.      * Ritorna il connettore con idConnettore, null se il connettore non esiste
  812.      */
  813.     protected static Connettore getConnettore(long idConnettore, Connection connection, IDriverBYOK driverBYOK) throws DriverConfigurazioneException {

  814.         Connettore connettore = null;

  815.         PreparedStatement stm = null;
  816.         ResultSet rs = null;

  817.         try {
  818.             ISQLQueryObject sqlQueryObject = SQLObjectFactory.createSQLQueryObject(DriverConfigurazioneDBLib.tipoDB);
  819.             sqlQueryObject.addFromTable(CostantiDB.CONNETTORI);
  820.             sqlQueryObject.addSelectField("*");
  821.             sqlQueryObject.addWhereCondition("id = ?");
  822.             String sqlQuery = sqlQueryObject.createSQLQuery();

  823.             stm = connection.prepareStatement(sqlQuery);
  824.             stm.setLong(1, idConnettore);

  825.             DriverConfigurazioneDBLib.logDebug("eseguo query : " + DBUtils.formatSQLString(sqlQuery, idConnettore));

  826.             rs = stm.executeQuery();

  827.             if (rs.next()) {
  828.                 String endpoint = rs.getString(CostantiDB.CONNETTORI_COLUMN_ENDPOINT_TYPE);
  829.                 if (endpoint == null || endpoint.equals("") || endpoint.equals(TipiConnettore.DISABILITATO.getNome())) {
  830.                     connettore = new Connettore();
  831.                     connettore.setNome(rs.getString(CostantiDB.CONNETTORI_COLUMN_NOME));
  832.                     connettore.setTipo(TipiConnettore.DISABILITATO.getNome());
  833.                     connettore.setId(idConnettore);

  834.                 } else {
  835.                     Property prop = null;
  836.                     connettore = new Connettore();
  837.                     connettore.setNome(rs.getString(CostantiDB.CONNETTORI_COLUMN_NOME));
  838.                     connettore.setTipo(endpoint);
  839.                     // l'id del connettore e' quello passato come parametro
  840.                     connettore.setId(idConnettore);

  841.                     // Debug
  842.                     if(rs.getInt("debug")==1){
  843.                         prop = new Property();
  844.                         prop.setNome(CostantiDB.CONNETTORE_DEBUG);
  845.                         prop.setValore("true");
  846.                         connettore.addProperty(prop);
  847.                     }
  848.                    
  849.                     // Proxy
  850.                     readConnettoreProxy(rs, connettore, driverBYOK);
  851.                    
  852.                     // Tempi Risposta
  853.                     readConnettoreTempiRisposta(rs, connettore);
  854.                    
  855.                     // transfer_mode
  856.                     readConnettoreTransferMode(rs, connettore);
  857.                    
  858.                     // redirect_mode
  859.                     readConnettoreRedirectMode(rs, connettore);                
  860.                    
  861.                     // token policy
  862.                     String tokenPolicy = rs.getString("token_policy");
  863.                     if(tokenPolicy!=null && !"".equals(tokenPolicy)){
  864.                         prop = new Property();
  865.                         prop.setNome(CostantiDB.CONNETTORE_TOKEN_POLICY);
  866.                         prop.setValore(tokenPolicy.trim());
  867.                         connettore.addProperty(prop);
  868.                     }

  869.                     // api key
  870.                     readAutenticazioneApiKey(rs, connettore, driverBYOK);

  871.                     if (endpoint.equals(CostantiDB.CONNETTORE_TIPO_HTTP)) {
  872.                         readConnettoreHttp(rs, connettore);
  873.                     } else if (endpoint.equals(TipiConnettore.JMS.getNome())){//jms
  874.                         readConnettoreJms(rs, connettore, driverBYOK);
  875.                     }else if(endpoint.equals(TipiConnettore.NULL.getNome())){
  876.                         //nessuna proprieta per connettore null
  877.                     }else if(endpoint.equals(TipiConnettore.NULLECHO.getNome())){
  878.                         //nessuna proprieta per connettore nullEcho
  879.                     }else if (!endpoint.equals(TipiConnettore.DISABILITATO.getNome())) {
  880.                         if(rs.getLong("custom")==1){
  881.                             // connettore custom
  882.                             readPropertiesConnettoreCustom(idConnettore,connettore,connection,driverBYOK);
  883.                             connettore.setCustom(true);
  884.                         }
  885.                         else{
  886.                             // legge da file properties
  887.                             connettore.setPropertyList(ConnettorePropertiesUtilities.getPropertiesConnettore(endpoint,connection,DriverConfigurazioneDBLib.tipoDB));
  888.                         }
  889.                     }

  890.                 }
  891.             }
  892.            
  893.             // Extended Info
  894.             readPropertiesConnettoreExtendedInfo(idConnettore,connettore,connection,driverBYOK);
  895.            
  896.             return connettore;
  897.         } catch (SQLException sqle) {

  898.             throw new DriverConfigurazioneException("[DriverConfigurazioneDB_LIB::getConnettore] SQLException : " + sqle.getMessage(),sqle);
  899.         }catch (DriverConfigurazioneException e) {
  900.             throw e;
  901.         }catch (Exception sqle) {

  902.             throw new DriverConfigurazioneException("[DriverConfigurazioneDB_LIB::getConnettore] Exception : " + sqle.getMessage(),sqle);
  903.         } finally {
  904.             //Chiudo statement and resultset
  905.             JDBCUtilities.closeResources(rs, stm);
  906.         }
  907.     }
  908.    
  909.     private static void readConnettoreProxy(ResultSet rs, Connettore connettore, IDriverBYOK driverBYOK) throws SQLException, UtilsException {
  910.         if(rs.getInt("proxy")==1){
  911.            
  912.             String tmp = rs.getString("proxy_type");
  913.             if(tmp!=null && !"".equals(tmp)){
  914.                 Property prop = new Property();
  915.                 prop.setNome(CostantiDB.CONNETTORE_PROXY_TYPE);
  916.                 prop.setValore(tmp.trim());
  917.                 connettore.addProperty(prop);
  918.             }
  919.            
  920.             tmp = rs.getString("proxy_hostname");
  921.             if(tmp!=null && !"".equals(tmp)){
  922.                 Property prop = new Property();
  923.                 prop.setNome(CostantiDB.CONNETTORE_PROXY_HOSTNAME);
  924.                 prop.setValore(tmp.trim());
  925.                 connettore.addProperty(prop);
  926.             }
  927.            
  928.             tmp = rs.getString("proxy_port");
  929.             if(tmp!=null && !"".equals(tmp)){
  930.                 Property prop = new Property();
  931.                 prop.setNome(CostantiDB.CONNETTORE_PROXY_PORT);
  932.                 prop.setValore(tmp.trim());
  933.                 connettore.addProperty(prop);
  934.             }
  935.            
  936.             readConnettoreProxyCredentials(rs, connettore, driverBYOK);
  937.         }
  938.     }
  939.     private static void readConnettoreProxyCredentials(ResultSet rs, Connettore connettore, IDriverBYOK driverBYOK) throws SQLException, UtilsException {
  940.         String tmp = rs.getString("proxy_username");
  941.         if(tmp!=null && !"".equals(tmp)){
  942.             Property prop = new Property();
  943.             prop.setNome(CostantiDB.CONNETTORE_PROXY_USERNAME);
  944.             prop.setValore(tmp.trim());
  945.             connettore.addProperty(prop);
  946.         }
  947.        
  948.         tmp = rs.getString("proxy_password");
  949.         String encValue = rs.getString("enc_proxy_password");
  950.         if(tmp!=null && !"".equals(tmp)){
  951.             Property prop = new Property();
  952.             prop.setNome(CostantiDB.CONNETTORE_PROXY_PASSWORD);
  953.            
  954.             if(encValue!=null && StringUtils.isNotEmpty(encValue)) {
  955.                 if(driverBYOK!=null) {
  956.                     prop.setValore(driverBYOK.unwrapAsString(encValue));
  957.                 }
  958.                 else {
  959.                     prop.setValore(encValue);
  960.                 }
  961.             }
  962.             else {
  963.                 prop.setValore(tmp.trim());
  964.             }
  965.            
  966.             connettore.addProperty(prop);
  967.         }
  968.     }
  969.    
  970.     private static void readConnettoreTempiRisposta(ResultSet rs, Connettore connettore) throws SQLException {
  971.         int connectionTimeout = rs.getInt("connection_timeout");
  972.         if(connectionTimeout>0){
  973.             Property prop = new Property();
  974.             prop.setNome(CostantiDB.CONNETTORE_CONNECTION_TIMEOUT);
  975.             prop.setValore(connectionTimeout+"");
  976.             connettore.addProperty(prop);
  977.         }
  978.         int readTimeout = rs.getInt("read_timeout");
  979.         if(readTimeout>0){
  980.             Property prop = new Property();
  981.             prop.setNome(CostantiDB.CONNETTORE_READ_CONNECTION_TIMEOUT);
  982.             prop.setValore(readTimeout+"");
  983.             connettore.addProperty(prop);
  984.         }
  985.         int avgResponseTime = rs.getInt("avg_response_time");
  986.         if(avgResponseTime>0){
  987.             Property prop = new Property();
  988.             prop.setNome(CostantiDB.CONNETTORE_TEMPO_MEDIO_RISPOSTA);
  989.             prop.setValore(avgResponseTime+"");
  990.             connettore.addProperty(prop);
  991.         }
  992.     }
  993.    
  994.     private static void readConnettoreTransferMode(ResultSet rs, Connettore connettore) throws SQLException {
  995.         String transferMode = rs.getString("transfer_mode");
  996.         if(transferMode!=null && !"".equals(transferMode)){
  997.            
  998.             Property prop = new Property();
  999.             prop.setNome(CostantiDB.CONNETTORE_HTTP_DATA_TRANSFER_MODE);
  1000.             prop.setValore(transferMode.trim());
  1001.             connettore.addProperty(prop);
  1002.            
  1003.             transferMode = rs.getString("transfer_mode_chunk_size");
  1004.             if(transferMode!=null && !"".equals(transferMode)){
  1005.                 prop = new Property();
  1006.                 prop.setNome(CostantiDB.CONNETTORE_HTTP_DATA_TRANSFER_MODE_CHUNK_SIZE);
  1007.                 prop.setValore(transferMode.trim());
  1008.                 connettore.addProperty(prop);
  1009.             }
  1010.         }
  1011.     }
  1012.    
  1013.     private static void readConnettoreRedirectMode(ResultSet rs, Connettore connettore) throws SQLException {
  1014.         String redirectMode = rs.getString("redirect_mode");
  1015.         if(redirectMode!=null && !"".equals(redirectMode)){
  1016.            
  1017.             Property prop = new Property();
  1018.             prop.setNome(CostantiDB.CONNETTORE_HTTP_REDIRECT_FOLLOW);
  1019.             prop.setValore(redirectMode.trim());
  1020.             connettore.addProperty(prop);
  1021.            
  1022.             redirectMode = rs.getString("redirect_max_hop");
  1023.             if(redirectMode!=null && !"".equals(redirectMode)){
  1024.                 prop = new Property();
  1025.                 prop.setNome(CostantiDB.CONNETTORE_HTTP_REDIRECT_MAX_HOP);
  1026.                 prop.setValore(redirectMode.trim());
  1027.                 connettore.addProperty(prop);
  1028.             }
  1029.         }
  1030.     }
  1031.    
  1032.     private static void readAutenticazioneApiKey(ResultSet rs, Connettore connettore, IDriverBYOK driverBYOK) throws SQLException, UtilsException {
  1033.         String apiKey = rs.getString("api_key");
  1034.         if(apiKey!=null && !"".equals(apiKey)){
  1035.            
  1036.             Property prop = new Property();
  1037.             prop.setNome(CostantiDB.CONNETTORE_APIKEY);
  1038.             if(driverBYOK!=null) {
  1039.                 prop.setValore(driverBYOK.unwrapAsString(apiKey));
  1040.             }
  1041.             else {
  1042.                 prop.setValore(apiKey);
  1043.             }
  1044.             connettore.addProperty(prop);
  1045.            
  1046.             String apiKeyHeader = rs.getString("api_key_header");
  1047.             if(apiKeyHeader!=null && !"".equals(apiKeyHeader)){
  1048.                 prop = new Property();
  1049.                 prop.setNome(CostantiDB.CONNETTORE_APIKEY_HEADER);
  1050.                 prop.setValore(apiKeyHeader.trim());
  1051.                 connettore.addProperty(prop);
  1052.             }
  1053.            
  1054.            
  1055.             String appId = rs.getString("app_id");
  1056.             if(appId!=null && !"".equals(appId)){
  1057.                
  1058.                 prop = new Property();
  1059.                 prop.setNome(CostantiDB.CONNETTORE_APIKEY_APPID);
  1060.                 prop.setValore(appId);
  1061.                 connettore.addProperty(prop);
  1062.                
  1063.                 String appIdHeader = rs.getString("app_id_header");
  1064.                 if(appIdHeader!=null && !"".equals(appIdHeader)){
  1065.                     prop = new Property();
  1066.                     prop.setNome(CostantiDB.CONNETTORE_APIKEY_APPID_HEADER);
  1067.                     prop.setValore(appIdHeader.trim());
  1068.                     connettore.addProperty(prop);
  1069.                 }
  1070.             }
  1071.         }
  1072.     }
  1073.    
  1074.     private static void readConnettoreHttp(ResultSet rs, Connettore connettore) throws DriverConfigurazioneException, SQLException {
  1075.         //  url
  1076.         String value = rs.getString("url");
  1077.         if(value!=null)
  1078.             value = value.trim();
  1079.         if(value == null || "".equals(value) || " ".equals(value)){
  1080.             throw new DriverConfigurazioneException("Connettore di tipo http possiede una url non definita");
  1081.         }
  1082.         Property prop = new Property();
  1083.         prop.setNome(CostantiDB.CONNETTORE_HTTP_LOCATION);
  1084.         prop.setValore(value);
  1085.         connettore.addProperty(prop);
  1086.     }
  1087.    
  1088.     private static void readConnettoreJms(ResultSet rs, Connettore connettore, IDriverBYOK driverBYOK) throws DriverConfigurazioneException, SQLException, UtilsException {
  1089.         // nome coda/topic
  1090.         String value = rs.getString("nome");
  1091.         if(value!=null)
  1092.             value = value.trim();
  1093.         if(value == null || "".equals(value) || " ".equals(value)){
  1094.             throw new DriverConfigurazioneException("Connettore di tipo jms possiede il nome della coda/topic non definito");
  1095.         }
  1096.         Property prop = new Property();
  1097.         prop.setNome(CostantiDB.CONNETTORE_JMS_NOME);
  1098.         prop.setValore(value);
  1099.         connettore.addProperty(prop);

  1100.         // tipo
  1101.         value = rs.getString("tipo");
  1102.         if(value!=null)
  1103.             value = value.trim();
  1104.         if(value == null || "".equals(value) || " ".equals(value)){
  1105.             throw new DriverConfigurazioneException("Connettore di tipo jms possiede il tipo della coda non definito");
  1106.         }
  1107.         prop = new Property();
  1108.         prop.setNome(CostantiDB.CONNETTORE_JMS_TIPO);
  1109.         prop.setValore(value);
  1110.         connettore.addProperty(prop);

  1111.         // connection-factory
  1112.         value = rs.getString("connection_factory");
  1113.         if(value!=null)
  1114.             value = value.trim();
  1115.         if(value == null || "".equals(value) || " ".equals(value)){
  1116.             throw new DriverConfigurazioneException("Connettore di tipo jms non possiede la definizione di una Connection Factory");
  1117.         }
  1118.         prop = new Property();
  1119.         prop.setNome(CostantiDB.CONNETTORE_JMS_CONNECTION_FACTORY);
  1120.         prop.setValore(value);
  1121.         connettore.addProperty(prop);

  1122.         // send_as
  1123.         value = rs.getString("send_as");
  1124.         if(value!=null)
  1125.             value = value.trim();
  1126.         if(value == null || "".equals(value) || " ".equals(value)){
  1127.             throw new DriverConfigurazioneException("Connettore di tipo jms possiede il tipo dell'oggetto JMS non definito");
  1128.         }
  1129.         prop = new Property();
  1130.         prop.setNome(CostantiDB.CONNETTORE_JMS_SEND_AS);
  1131.         prop.setValore(value);
  1132.         connettore.addProperty(prop);

  1133.         readConnettoreJmsCredentials(rs, connettore, driverBYOK);
  1134.        
  1135.         readConnettoreJmsContext(rs, connettore);
  1136.     }
  1137.     private static void readConnettoreJmsCredentials(ResultSet rs, Connettore connettore, IDriverBYOK driverBYOK) throws SQLException, UtilsException {
  1138.         // user
  1139.         String usr = rs.getString("utente");
  1140.         if (usr != null && !usr.trim().equals("")) {
  1141.             Property prop = new Property();
  1142.             prop.setNome(CostantiDB.CONNETTORE_USER);
  1143.             prop.setValore(usr);
  1144.             connettore.addProperty(prop);
  1145.         }
  1146.         // password
  1147.         String pwd = rs.getString("password");
  1148.         String encValue = rs.getString("enc_password");
  1149.         if (pwd != null && !pwd.trim().equals("")) {
  1150.             Property prop = new Property();
  1151.             prop.setNome(CostantiDB.CONNETTORE_PWD);
  1152.            
  1153.             if(encValue!=null && StringUtils.isNotEmpty(encValue)) {
  1154.                 if(driverBYOK!=null) {
  1155.                     prop.setValore(driverBYOK.unwrapAsString(encValue));
  1156.                 }
  1157.                 else {
  1158.                     prop.setValore(encValue);
  1159.                 }
  1160.             }
  1161.             else {
  1162.                 prop.setValore(pwd);
  1163.             }
  1164.            
  1165.             connettore.addProperty(prop);
  1166.         }
  1167.     }
  1168.     private static void readConnettoreJmsContext(ResultSet rs, Connettore connettore) throws SQLException {
  1169.         // context-java.naming.factory.initial
  1170.         String initcont = rs.getString("initcont");
  1171.         if (initcont != null && !initcont.trim().equals("")) {
  1172.             Property prop = new Property();
  1173.             prop.setNome(CostantiDB.CONNETTORE_JMS_CONTEXT_JAVA_NAMING_FACTORY_INITIAL);
  1174.             prop.setValore(initcont);
  1175.             connettore.addProperty(prop);
  1176.         }
  1177.         // context-java.naming.factory.url.pkgs
  1178.         String urlpkg = rs.getString("urlpkg");
  1179.         if (urlpkg != null && !urlpkg.trim().equals("")) {
  1180.             Property prop = new Property();
  1181.             prop.setNome(CostantiDB.CONNETTORE_JMS_CONTEXT_JAVA_NAMING_FACTORY_URL_PKG);
  1182.             prop.setValore(urlpkg);
  1183.             connettore.addProperty(prop);
  1184.         }
  1185.         // context-java.naming.provider.url
  1186.         String provurl = rs.getString("provurl");
  1187.         if (provurl != null && !provurl.trim().equals("")) {
  1188.             Property prop = new Property();
  1189.             prop.setNome(CostantiDB.CONNETTORE_JMS_CONTEXT_JAVA_NAMING_PROVIDER_URL);
  1190.             prop.setValore(provurl);
  1191.             connettore.addProperty(prop);
  1192.         }
  1193.     }
  1194.    
  1195.     protected static void readPropertiesConnettoreCustom(long idConnettore, Connettore connettore, Connection connection,
  1196.             IDriverBYOK driverBYOK) throws DriverConfigurazioneException {

  1197.         PreparedStatement stm = null;
  1198.         ResultSet rs = null;

  1199.         try {
  1200.             ISQLQueryObject sqlQueryObject = SQLObjectFactory.createSQLQueryObject(DriverConfigurazioneDBLib.tipoDB);
  1201.             sqlQueryObject.addFromTable(CostantiDB.CONNETTORI_CUSTOM);
  1202.             sqlQueryObject.addSelectField("*");
  1203.             sqlQueryObject.addWhereCondition("id_connettore = ?");
  1204.             String sqlQuery = sqlQueryObject.createSQLQuery();

  1205.             stm = connection.prepareStatement(sqlQuery);
  1206.             stm.setLong(1, idConnettore);

  1207.             DriverConfigurazioneDBLib.logDebug("eseguo query : " + DBUtils.formatSQLString(sqlQuery, idConnettore));

  1208.             rs = stm.executeQuery();
  1209.            
  1210.             while (rs.next()) {
  1211.                 processPropertiesConnettoreCustom(rs, connettore, driverBYOK);
  1212.             }
  1213.            
  1214.             rs.close();
  1215.             stm.close();

  1216.         } catch (SQLException sqle) {

  1217.             throw new DriverConfigurazioneException("[DriverConfigurazioneDB_LIB::readPropertiesConnettoreCustom] SQLException : " + sqle.getMessage(),sqle);
  1218.         }catch (Exception sqle) {

  1219.             throw new DriverConfigurazioneException("[DriverConfigurazioneDB_LIB::readPropertiesConnettoreCustom] Exception : " + sqle.getMessage(),sqle);
  1220.         } finally {
  1221.             //Chiudo statement and resultset
  1222.             JDBCUtilities.closeResources(rs, stm);
  1223.         }
  1224.     }
  1225.     private static void processPropertiesConnettoreCustom(ResultSet rs, Connettore connettore,
  1226.             IDriverBYOK driverBYOK) throws SQLException, UtilsException {
  1227.         String nome = rs.getString(CostantiDB.CONNETTORI_CUSTOM_COLUMN_NAME);
  1228.         String valore = rs.getString(CostantiDB.CONNETTORI_CUSTOM_COLUMN_VALUE);
  1229.         String encValue = rs.getString(CostantiDB.CONNETTORI_CUSTOM_COLUMN_ENC_VALUE);
  1230.        
  1231.         if(CostantiDB.CONNETTORE_DEBUG.equals(nome)){ // lo posso aver aggiunto prima
  1232.             boolean found = false;
  1233.             for (int i = 0; i < connettore.sizePropertyList(); i++) {
  1234.                 if(CostantiDB.CONNETTORE_DEBUG.equals(connettore.getProperty(i).getNome())){
  1235.                     // already exists
  1236.                     found = true;
  1237.                     break;
  1238.                 }
  1239.             }
  1240.             if(found){
  1241.                 return; // è gia stato aggiunto.
  1242.             }
  1243.         }
  1244.        
  1245.         Property prop = new Property();
  1246.         prop.setNome(nome);
  1247.         if(encValue!=null && StringUtils.isNotEmpty(encValue)) {
  1248.             if(driverBYOK!=null) {
  1249.                 prop.setValore(driverBYOK.unwrapAsString(encValue));
  1250.             }
  1251.             else {
  1252.                 prop.setValore(encValue);
  1253.             }
  1254.         }
  1255.         else {
  1256.             prop.setValore(valore);
  1257.         }
  1258.         connettore.addProperty(prop);
  1259.     }
  1260.    
  1261.     private static void readPropertiesConnettoreExtendedInfo(long idConnettore, Connettore connettore, Connection connection,
  1262.             IDriverBYOK driverBYOK) throws DriverConfigurazioneException {

  1263.         PreparedStatement stm = null;
  1264.         ResultSet rs = null;

  1265.         try {
  1266.             ISQLQueryObject sqlQueryObject = SQLObjectFactory.createSQLQueryObject(DriverConfigurazioneDBLib.tipoDB);
  1267.             sqlQueryObject.addFromTable(CostantiDB.CONNETTORI_CUSTOM);
  1268.             sqlQueryObject.addSelectField("*");
  1269.             sqlQueryObject.addWhereCondition("id_connettore = ?");
  1270.             sqlQueryObject.addWhereLikeCondition(CostantiDB.CONNETTORI_CUSTOM_COLUMN_NAME, CostantiConnettori.CONNETTORE_EXTENDED_PREFIX+"%");
  1271.             String sqlQuery = sqlQueryObject.createSQLQuery();

  1272.             stm = connection.prepareStatement(sqlQuery);
  1273.             stm.setLong(1, idConnettore);

  1274.             DriverConfigurazioneDBLib.logDebug("eseguo query : " + DBUtils.formatSQLString(sqlQuery, idConnettore));

  1275.             rs = stm.executeQuery();

  1276.             while (rs.next()) {
  1277.                 processPropertiesConnettoreExtendedInfo(rs, connettore,
  1278.                         driverBYOK);
  1279.             }
  1280.            
  1281.             rs.close();
  1282.             stm.close();

  1283.         } catch (SQLException sqle) {

  1284.             throw new DriverConfigurazioneException("[DriverConfigurazioneDB_LIB::readPropertiesConnettoreExtendedInfo] SQLException : " + sqle.getMessage(),sqle);
  1285.         }catch (Exception sqle) {

  1286.             throw new DriverConfigurazioneException("[DriverConfigurazioneDB_LIB::readPropertiesConnettoreExtendedInfo] Exception : " + sqle.getMessage(),sqle);
  1287.         } finally {
  1288.             //Chiudo statement and resultset
  1289.             JDBCUtilities.closeResources(rs, stm);
  1290.         }
  1291.     }
  1292.     private static void processPropertiesConnettoreExtendedInfo(ResultSet rs, Connettore connettore,
  1293.             IDriverBYOK driverBYOK) throws SQLException, UtilsException {
  1294.         String nome = rs.getString(CostantiDB.CONNETTORI_CUSTOM_COLUMN_NAME);
  1295.         String valore = rs.getString(CostantiDB.CONNETTORI_CUSTOM_COLUMN_VALUE);
  1296.         String encValue = rs.getString(CostantiDB.CONNETTORI_CUSTOM_COLUMN_ENC_VALUE);
  1297.        
  1298.         // Le proprietà sono già state inserite in caso di connettore custom
  1299.         boolean found = false;
  1300.         for (int i = 0; i < connettore.sizePropertyList(); i++) {
  1301.             if(nome.equals(connettore.getProperty(i).getNome())){
  1302.                 // already exists
  1303.                 found = true;
  1304.                 break;
  1305.             }
  1306.         }
  1307.         if(found){
  1308.             return; // è gia stato aggiunto.
  1309.         }
  1310.        
  1311.         Property prop = new Property();
  1312.         prop.setNome(nome);
  1313.         if(encValue!=null && StringUtils.isNotEmpty(encValue)) {
  1314.             if(driverBYOK!=null) {
  1315.                 prop.setValore(driverBYOK.unwrapAsString(encValue));
  1316.             }
  1317.             else {
  1318.                 prop.setValore(encValue);
  1319.             }
  1320.         }
  1321.         else {
  1322.             prop.setValore(valore);
  1323.         }
  1324.         connettore.addProperty(prop);
  1325.     }

  1326.     /**
  1327.      * Se il connettore e' null lo considero disabilitato
  1328.      * @param connettore
  1329.      * @return true se il connettore e' abilitato
  1330.      */
  1331.     protected static boolean isConnettoreAbilitato(Connettore connettore) {

  1332.         //Se connettore null oppure il tipo e' null o "" o DISABILITATO allora connettore disabilitato
  1333.         //altrimenti e' abilitato.
  1334.         if (connettore == null)
  1335.             return false;

  1336.         String tipo = connettore.getTipo();
  1337.         return !TipiConnettore.DISABILITATO.getNome().equals(tipo);
  1338.     }

  1339.     protected static long getIdConnettoreSARISP(long idServizioApplicativo,Connection con) throws DriverConfigurazioneException
  1340.     {
  1341.         PreparedStatement stm = null;
  1342.         ResultSet rs = null;
  1343.         long idConnettore=-1;
  1344.         try
  1345.         {
  1346.             ISQLQueryObject sqlQueryObject = SQLObjectFactory.createSQLQueryObject(DriverConfigurazioneDBLib.tipoDB);
  1347.             sqlQueryObject.addFromTable(CostantiDB.SERVIZI_APPLICATIVI);
  1348.             sqlQueryObject.addSelectField("*");
  1349.             sqlQueryObject.addWhereCondition("id = ?");
  1350.             String query = sqlQueryObject.createSQLQuery();
  1351.             stm=con.prepareStatement(query);
  1352.             stm.setLong(1, idServizioApplicativo);
  1353.             rs=stm.executeQuery();

  1354.             if(rs.next()){
  1355.                 idConnettore = rs.getLong("id_connettore_risp");
  1356.             }

  1357.             return idConnettore;

  1358.         }catch (Exception e) {
  1359.             throw new DriverConfigurazioneException(e);
  1360.         }finally
  1361.         {
  1362.             //Chiudo statement and resultset
  1363.             JDBCUtilities.closeResources(rs, stm);

  1364.         }
  1365.     }

  1366.     protected static long getIdConnettoreSAINV(long idServizioApplicativo,Connection con) throws DriverConfigurazioneException
  1367.     {
  1368.         PreparedStatement stm = null;
  1369.         ResultSet rs = null;
  1370.         long idConnettore=-1;
  1371.         try
  1372.         {
  1373.             ISQLQueryObject sqlQueryObject = SQLObjectFactory.createSQLQueryObject(DriverConfigurazioneDBLib.tipoDB);
  1374.             sqlQueryObject.addFromTable(CostantiDB.SERVIZI_APPLICATIVI);
  1375.             sqlQueryObject.addSelectField("*");
  1376.             sqlQueryObject.addWhereCondition("id = ?");
  1377.             String query = sqlQueryObject.createSQLQuery();
  1378.             stm=con.prepareStatement(query);
  1379.             stm.setLong(1, idServizioApplicativo);
  1380.             rs=stm.executeQuery();

  1381.             if(rs.next()){
  1382.                 idConnettore = rs.getLong("id_connettore_inv");
  1383.             }

  1384.             return idConnettore;

  1385.         }catch (Exception e) {
  1386.             throw new DriverConfigurazioneException(e);
  1387.         }finally
  1388.         {
  1389.             //Chiudo statement and resultset
  1390.             JDBCUtilities.closeResources(rs,stm);

  1391.         }
  1392.     }

  1393.    
  1394. }