DriverConfigurazioneDB_porteDriver.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.ResultSet;
  24. import java.sql.SQLException;
  25. import java.util.ArrayList;
  26. import java.util.List;

  27. import org.openspcoop2.core.commons.DBUtils;
  28. import org.openspcoop2.core.commons.ISearch;
  29. import org.openspcoop2.core.commons.Liste;
  30. import org.openspcoop2.core.config.CorsConfigurazione;
  31. import org.openspcoop2.core.config.CorsConfigurazioneHeaders;
  32. import org.openspcoop2.core.config.CorsConfigurazioneMethods;
  33. import org.openspcoop2.core.config.CorsConfigurazioneOrigin;
  34. import org.openspcoop2.core.config.ResponseCachingConfigurazione;
  35. import org.openspcoop2.core.config.ResponseCachingConfigurazioneControl;
  36. import org.openspcoop2.core.config.ResponseCachingConfigurazioneHashGenerator;
  37. import org.openspcoop2.core.config.ResponseCachingConfigurazioneRegola;
  38. import org.openspcoop2.core.config.constants.StatoFunzionalita;
  39. import org.openspcoop2.core.config.constants.StatoFunzionalitaCacheDigestQueryParameter;
  40. import org.openspcoop2.core.config.constants.TipoGestioneCORS;
  41. import org.openspcoop2.core.config.driver.DriverConfigurazioneException;
  42. import org.openspcoop2.core.constants.CostantiDB;
  43. import org.openspcoop2.utils.date.DateManager;
  44. import org.openspcoop2.utils.jdbc.JDBCUtilities;
  45. import org.openspcoop2.utils.sql.ISQLQueryObject;
  46. import org.openspcoop2.utils.sql.SQLObjectFactory;

  47. /**
  48.  * DriverConfigurazioneDB_porteDriver
  49.  *
  50.  *
  51.  * @author Sandra Giangrandi (sandra@link.it)
  52.  * @author Stefano Corallo (corallo@link.it)
  53.  * @author $Author$
  54.  * @version $Rev$, $Date$
  55.  */
  56. public class DriverConfigurazioneDB_porteDriver {

  57.     private DriverConfigurazioneDB driver = null;
  58.    
  59.     protected DriverConfigurazioneDB_porteDriver(DriverConfigurazioneDB driver) {
  60.         this.driver = driver;
  61.     }
  62.    
  63.     protected List<ResponseCachingConfigurazioneRegola> portaApplicativaResponseCachingConfigurazioneRegolaList(long idPA, ISearch ricerca) throws DriverConfigurazioneException {
  64.         int idLista = Liste.PORTE_APPLICATIVE_RESPONSE_CACHING_CONFIGURAZIONE_REGOLA;
  65.         String nomeMetodo = "portaApplicativaResponseCachingConfigurazioneRegolaList";
  66.         boolean delegata = false;
  67.         return getEngineResponseCachingConfigurazioneRegolaList(idPA, ricerca, idLista, nomeMetodo, delegata);
  68.     }
  69.    
  70.     protected List<ResponseCachingConfigurazioneRegola> portaDelegataResponseCachingConfigurazioneRegolaList(long idPD, ISearch ricerca) throws DriverConfigurazioneException {
  71.         String nomeMetodo = "portaDelegataResponseCachingConfigurazioneRegolaList";
  72.         int idLista = Liste.PORTE_DELEGATE_RESPONSE_CACHING_CONFIGURAZIONE_REGOLA;
  73.         boolean delegata = true;
  74.         return getEngineResponseCachingConfigurazioneRegolaList(idPD, ricerca, idLista, nomeMetodo, delegata);
  75.     }
  76.    
  77.     private List<ResponseCachingConfigurazioneRegola> getEngineResponseCachingConfigurazioneRegolaList(long idPA, ISearch ricerca, int idLista, String nomeMetodo, boolean portaDelegata) throws DriverConfigurazioneException {
  78.         int offset;
  79.         int limit;
  80.         String queryString;

  81.         limit = ricerca.getPageSize(idLista);
  82.         offset = ricerca.getIndexIniziale(idLista);
  83.        
  84.         String nomeTabella = portaDelegata ? CostantiDB.PORTE_DELEGATE_CACHE_REGOLE : CostantiDB.PORTE_APPLICATIVE_CACHE_REGOLE;

  85.         Connection con = null;
  86.         PreparedStatement stmt = null;
  87.         ResultSet risultato = null;

  88.         if (this.driver.atomica) {
  89.             try {
  90.                 con = this.driver.getConnectionFromDatasource(nomeMetodo);
  91.             } catch (Exception e) {
  92.                 throw new DriverConfigurazioneException("[DriverConfigurazioneDB::" + nomeMetodo + "] Exception accedendo al datasource :" + e.getMessage(),e);

  93.             }

  94.         } else
  95.             con = this.driver.globalConnection;

  96.         this.driver.logDebug("operazione this.driver.atomica = " + this.driver.atomica);

  97.         List<ResponseCachingConfigurazioneRegola> lista = new ArrayList<>();
  98.         try {
  99.            
  100.             ISQLQueryObject sqlQueryObject = SQLObjectFactory.createSQLQueryObject(this.driver.tipoDB);
  101.             sqlQueryObject.addFromTable(nomeTabella);
  102.             sqlQueryObject.addSelectCountField(nomeTabella+".id", "cont");
  103.             sqlQueryObject.addWhereCondition(nomeTabella+".id_porta=?");
  104.             sqlQueryObject.setSelectDistinct(true);
  105.             sqlQueryObject.setANDLogicOperator(true);
  106.             queryString = sqlQueryObject.createSQLQuery();
  107.             stmt = con.prepareStatement(queryString);
  108.             stmt.setLong(1, idPA);

  109.             risultato = stmt.executeQuery();
  110.             if (risultato.next())
  111.                 ricerca.setNumEntries(idLista,risultato.getInt(1));
  112.             risultato.close();
  113.             stmt.close();

  114.             // ricavo le entries
  115.             if (limit == 0) // con limit
  116.                 limit = ISQLQueryObject.LIMIT_DEFAULT_VALUE;
  117.            
  118.             sqlQueryObject = SQLObjectFactory.createSQLQueryObject(this.driver.tipoDB);
  119.             sqlQueryObject.addFromTable(nomeTabella);
  120.             sqlQueryObject.addSelectField("id");
  121.             sqlQueryObject.addWhereCondition(nomeTabella+".id_porta=?");
  122.             sqlQueryObject.setSelectDistinct(true);
  123.             sqlQueryObject.setANDLogicOperator(true);
  124.             sqlQueryObject.addOrderBy(nomeTabella+".id");
  125.             sqlQueryObject.setSortType(true);
  126.             sqlQueryObject.setLimit(limit);
  127.             sqlQueryObject.setOffset(offset);
  128.             queryString = sqlQueryObject.createSQLQuery();
  129.             stmt = con.prepareStatement(queryString);
  130.             stmt.setLong(1, idPA);

  131.             risultato = stmt.executeQuery();

  132.             List<Long> idLong = new ArrayList<>();
  133.             while (risultato.next()) {
  134.                 idLong.add(risultato.getLong("id"));
  135.             }
  136.             risultato.close();
  137.             stmt.close();
  138.            
  139.             if(!idLong.isEmpty()) {
  140.                
  141.                 for (Long idLongRegola : idLong) {
  142.                    
  143.                     sqlQueryObject = SQLObjectFactory.createSQLQueryObject(this.driver.tipoDB);
  144.                     sqlQueryObject.addFromTable(nomeTabella);
  145.                     sqlQueryObject.addSelectField("*");
  146.                     sqlQueryObject.addWhereCondition(nomeTabella+".id=?");
  147.                     sqlQueryObject.setANDLogicOperator(true);
  148.                     queryString = sqlQueryObject.createSQLQuery();
  149.                     stmt = con.prepareStatement(queryString);
  150.                     stmt.setLong(1, idLongRegola);

  151.                     risultato = stmt.executeQuery();
  152.                    
  153.                     if(risultato.next()) {
  154.                    
  155.                         ResponseCachingConfigurazioneRegola regola = new ResponseCachingConfigurazioneRegola();
  156.                        
  157.                         regola.setId(risultato.getLong("id"));
  158.                         int statusMin = risultato.getInt("status_min");
  159.                         int statusMax = risultato.getInt("status_max");
  160.                         if(statusMin>0) {
  161.                             regola.setReturnCodeMin(statusMin);
  162.                         }
  163.                         if(statusMax>0) {
  164.                             regola.setReturnCodeMax(statusMax);
  165.                         }

  166.                         int fault = risultato.getInt("fault");
  167.                         if(CostantiDB.TRUE == fault) {
  168.                             regola.setFault(true);
  169.                         }
  170.                         else if(CostantiDB.FALSE == fault) {
  171.                             regola.setFault(false);
  172.                         }
  173.                        
  174.                         int cacheSeconds = risultato.getInt("cache_seconds");
  175.                         if(cacheSeconds>0) {
  176.                             regola.setCacheTimeoutSeconds(cacheSeconds);
  177.                         }

  178.                         lista.add(regola);
  179.                        
  180.                     }
  181.                    
  182.                     risultato.close();
  183.                     stmt.close();
  184.                 }
  185.                
  186.             }

  187.         } catch (Exception qe) {
  188.             throw new DriverConfigurazioneException("[DriverConfigurazioneDB::" + nomeMetodo + "] Errore : " + qe.getMessage(),qe);
  189.         } finally {

  190.             //Chiudo statement and resultset
  191.             JDBCUtilities.closeResources(risultato, stmt);

  192.             this.driver.closeConnection(con);
  193.         }
  194.        
  195.         return lista;
  196.     }
  197.    
  198.     protected boolean existsPortaApplicativaResponseCachingConfigurazioneRegola(long idPA, Integer statusMin, Integer statusMax, boolean fault) throws DriverConfigurazioneException {
  199.         String nomeMetodo = "existsPortaApplicativaResponseCachingConfigurazioneRegola";
  200.         boolean delegata = false;
  201.         return existsResponseCachingConfigurazioneRegolaEngine(idPA, statusMin, statusMax, fault, nomeMetodo, delegata);
  202.     }
  203.    
  204.     protected boolean existsPortaDelegataResponseCachingConfigurazioneRegola(long idPA, Integer statusMin, Integer statusMax, boolean fault) throws DriverConfigurazioneException {
  205.         String nomeMetodo = "existsPortaDelegataResponseCachingConfigurazioneRegola";
  206.         boolean delegata = true;
  207.         return existsResponseCachingConfigurazioneRegolaEngine(idPA, statusMin, statusMax, fault, nomeMetodo, delegata);
  208.     }
  209.    
  210.     private boolean existsResponseCachingConfigurazioneRegolaEngine(long idPA, Integer statusMin, Integer statusMax, boolean fault,String nomeMetodo, boolean portaDelegata) throws DriverConfigurazioneException {
  211.         Connection con = null;
  212.         PreparedStatement stmt=null;
  213.         ResultSet risultato=null;
  214.         String queryString;
  215.         String nomeTabella = portaDelegata ? CostantiDB.PORTE_DELEGATE_CACHE_REGOLE : CostantiDB.PORTE_APPLICATIVE_CACHE_REGOLE;

  216.         if (this.driver.atomica) {
  217.             try {
  218.                 con = this.driver.getConnectionFromDatasource(nomeMetodo);
  219.             } catch (Exception e) {
  220.                 throw new DriverConfigurazioneException("[DriverConfigurazioneDB::" + nomeMetodo + "] Exception accedendo al datasource :" + e.getMessage(),e);

  221.             }

  222.         } else
  223.             con = this.driver.globalConnection;

  224.         this.driver.logDebug("operazione this.driver.atomica = " + this.driver.atomica);

  225.         try {

  226.             int count = 0;
  227.             ISQLQueryObject sqlQueryObject = SQLObjectFactory.createSQLQueryObject(this.driver.tipoDB);
  228.             sqlQueryObject.addFromTable(nomeTabella);
  229.             sqlQueryObject.addSelectCountField(nomeTabella+".id", "cont");
  230.             sqlQueryObject.setANDLogicOperator(true);
  231.            
  232.             sqlQueryObject.addWhereCondition("id_porta = ?");
  233.             if(statusMin != null) {
  234.                 sqlQueryObject.addWhereCondition("status_min = ?");
  235.             } else {
  236.                 sqlQueryObject.addWhereIsNullCondition("status_min");
  237.             }
  238.            
  239.             if(statusMax != null) {
  240.                 sqlQueryObject.addWhereCondition("status_max = ?");
  241.             } else {
  242.                 sqlQueryObject.addWhereIsNullCondition("status_max");
  243.             }
  244.            
  245.             sqlQueryObject.addWhereCondition("fault = ?");
  246.            
  247.             queryString = sqlQueryObject.createSQLQuery();
  248.             stmt = con.prepareStatement(queryString);
  249.             int parameterIndex = 1;
  250.             stmt.setLong(parameterIndex ++, idPA);
  251.             if(statusMin != null)
  252.                 stmt.setInt(parameterIndex ++, statusMin);
  253.             if(statusMax != null)
  254.                 stmt.setInt(parameterIndex ++, statusMax);
  255.             if(fault) {
  256.                 stmt.setInt(parameterIndex ++, CostantiDB.TRUE);
  257.             } else {
  258.                 stmt.setInt(parameterIndex ++, CostantiDB.FALSE);
  259.             }
  260.            
  261.             risultato = stmt.executeQuery();
  262.             if (risultato.next())
  263.                 count = risultato.getInt(1);
  264.             risultato.close();
  265.             stmt.close();

  266.             return count > 0;

  267.         } catch (Exception qe) {
  268.             throw new DriverConfigurazioneException("[DriverConfigurazioneDB::" + nomeMetodo + "] Errore : " + qe.getMessage(),qe);
  269.         } finally {

  270.             //Chiudo statement and resultset
  271.             JDBCUtilities.closeResources(risultato, stmt);

  272.             this.driver.closeConnection(con);
  273.         }
  274.     }
  275.    
  276.     protected void readConfigurazioneCors(CorsConfigurazione configurazione, ResultSet rs) throws SQLException {
  277.        
  278.         String corsStato = rs.getString("cors_stato");
  279.         if(corsStato!=null && !"".equals(corsStato)) {
  280.             configurazione.setStato(DriverConfigurazioneDBLib.getEnumStatoFunzionalita(corsStato));
  281.         }
  282.        
  283.         if(StatoFunzionalita.ABILITATO.equals(configurazione.getStato())) {
  284.            
  285.             String corsTipo = rs.getString("cors_tipo");
  286.             if(corsTipo!=null && !"".equals(corsTipo)) {
  287.                 configurazione.setTipo(DriverConfigurazioneDBLib.getEnumTipoGestioneCORS(corsTipo));
  288.             }
  289.            
  290.             if(TipoGestioneCORS.GATEWAY.equals(configurazione.getTipo())) {
  291.                
  292.                 String corsAllAllowOrigins = rs.getString("cors_all_allow_origins");
  293.                 if(corsAllAllowOrigins!=null && !"".equals(corsAllAllowOrigins)) {
  294.                     configurazione.setAccessControlAllAllowOrigins(DriverConfigurazioneDBLib.getEnumStatoFunzionalita(corsAllAllowOrigins));
  295.                 }
  296.                 if(StatoFunzionalita.DISABILITATO.equals(configurazione.getAccessControlAllAllowOrigins())) {
  297.                     List<String> l = DBUtils.convertToList(rs.getString("cors_allow_origins"));
  298.                     if(!l.isEmpty()) {
  299.                         configurazione.setAccessControlAllowOrigins(new CorsConfigurazioneOrigin());
  300.                     }
  301.                     for (String v : l) {
  302.                         configurazione.getAccessControlAllowOrigins().addOrigin(v);
  303.                     }
  304.                 }
  305.            
  306.                 String corsAllowCredentials = rs.getString("cors_allow_credentials");
  307.                 if(corsAllowCredentials!=null && !"".equals(corsAllowCredentials)) {
  308.                     configurazione.setAccessControlAllowCredentials(DriverConfigurazioneDBLib.getEnumStatoFunzionalita(corsAllowCredentials));
  309.                 }
  310.                
  311.                 int corsAllowMaxAge = rs.getInt("cors_allow_max_age");
  312.                 if(CostantiDB.TRUE == corsAllowMaxAge) {
  313.                     int corsAllowMaxAgeSeconds = rs.getInt("cors_allow_max_age_seconds");
  314.                     configurazione.setAccessControlMaxAge(corsAllowMaxAgeSeconds);
  315.                 }
  316.                
  317.                 String corsAllAllowHeader = rs.getString("cors_all_allow_headers");
  318.                 if(corsAllAllowHeader!=null && !"".equals(corsAllAllowHeader)) {
  319.                     configurazione.setAccessControlAllAllowHeaders(DriverConfigurazioneDBLib.getEnumStatoFunzionalita(corsAllAllowHeader));
  320.                 }
  321.                 if(StatoFunzionalita.DISABILITATO.equals(configurazione.getAccessControlAllAllowHeaders())) {
  322.                     List<String> l = DBUtils.convertToList(rs.getString("cors_allow_headers"));
  323.                     if(!l.isEmpty()) {
  324.                         configurazione.setAccessControlAllowHeaders(new CorsConfigurazioneHeaders());
  325.                     }
  326.                     for (String v : l) {
  327.                         configurazione.getAccessControlAllowHeaders().addHeader(v);
  328.                     }
  329.                 }
  330.                
  331.                 String corsAllAllowMethods = rs.getString("cors_all_allow_methods");
  332.                 if(corsAllAllowMethods!=null && !"".equals(corsAllAllowMethods)) {
  333.                     configurazione.setAccessControlAllAllowMethods(DriverConfigurazioneDBLib.getEnumStatoFunzionalita(corsAllAllowMethods));
  334.                 }
  335.                 if(StatoFunzionalita.DISABILITATO.equals(configurazione.getAccessControlAllAllowMethods())) {
  336.                     List<String> l = DBUtils.convertToList(rs.getString("cors_allow_methods"));
  337.                     if(!l.isEmpty()) {
  338.                         configurazione.setAccessControlAllowMethods(new CorsConfigurazioneMethods());
  339.                     }
  340.                     for (String v : l) {
  341.                         configurazione.getAccessControlAllowMethods().addMethod(v);
  342.                     }
  343.                 }
  344.                
  345.                 List<String> l = DBUtils.convertToList(rs.getString("cors_allow_expose_headers"));
  346.                 if(!l.isEmpty()) {
  347.                     configurazione.setAccessControlExposeHeaders(new CorsConfigurazioneHeaders());
  348.                 }
  349.                 for (String v : l) {
  350.                     configurazione.getAccessControlExposeHeaders().addHeader(v);
  351.                 }
  352.             }
  353.            
  354.         }
  355.        
  356.     }
  357.    
  358.     protected void readResponseCaching(Long idPorta, boolean config, boolean portaDelegata, ResponseCachingConfigurazione configurazione, ResultSet rs, Connection con) throws Exception {
  359.        
  360.         String responseCacheStato = rs.getString("response_cache_stato");
  361.         if(responseCacheStato!=null && !"".equals(responseCacheStato)) {
  362.             configurazione.setStato(DriverConfigurazioneDBLib.getEnumStatoFunzionalita(responseCacheStato));
  363.         }
  364.        
  365.         if(StatoFunzionalita.ABILITATO.equals(configurazione.getStato())) {
  366.    
  367.             int responseCacheSeconds = rs.getInt("response_cache_seconds");
  368.             if(responseCacheSeconds>0) {
  369.                 configurazione.setCacheTimeoutSeconds(responseCacheSeconds);
  370.             }
  371.            
  372.             long responseCacheMaxMsgBytes = rs.getLong("response_cache_max_msg_size");
  373.             if(responseCacheMaxMsgBytes>0) {
  374.                 configurazione.setMaxMessageSize(responseCacheMaxMsgBytes);
  375.             }
  376.            
  377.             configurazione.setHashGenerator(new ResponseCachingConfigurazioneHashGenerator());
  378.            
  379.             String responseCacheHashUrl = rs.getString("response_cache_hash_url");
  380.             if(responseCacheHashUrl!=null && !"".equals(responseCacheHashUrl)) {
  381.                 configurazione.getHashGenerator().setRequestUri(DriverConfigurazioneDBLib.getEnumStatoFunzionalita(responseCacheHashUrl));
  382.             }
  383.            
  384.             String responseCacheHashQuery = rs.getString("response_cache_hash_query");
  385.             if(responseCacheHashQuery!=null && !"".equals(responseCacheHashQuery)) {
  386.                 configurazione.getHashGenerator().setQueryParameters(DriverConfigurazioneDBLib.getEnumStatoFunzionalitaCacheDigestQueryParameter(responseCacheHashQuery));
  387.             }
  388.            
  389.             if(StatoFunzionalitaCacheDigestQueryParameter.SELEZIONE_PUNTUALE.equals(configurazione.getHashGenerator().getQueryParameters())) {
  390.                 List<String> l = DBUtils.convertToList(rs.getString("response_cache_hash_query_list"));
  391.                 for (String v : l) {
  392.                     configurazione.getHashGenerator().addQueryParameter(v);
  393.                 }
  394.             }
  395.            
  396.             String responseCacheHashHeaders = rs.getString("response_cache_hash_headers");
  397.             if(responseCacheHashHeaders!=null && !"".equals(responseCacheHashHeaders)) {
  398.                 configurazione.getHashGenerator().setHeaders(DriverConfigurazioneDBLib.getEnumStatoFunzionalita(responseCacheHashHeaders));
  399.             }
  400.            
  401.             if(StatoFunzionalita.ABILITATO.equals(configurazione.getHashGenerator().getHeaders())) {
  402.                 List<String> l = DBUtils.convertToList(rs.getString("response_cache_hash_hdr_list"));
  403.                 for (String v : l) {
  404.                     configurazione.getHashGenerator().addHeader(v);
  405.                 }
  406.             }
  407.            
  408.             String responseCacheHashPayload = rs.getString("response_cache_hash_payload");
  409.             if(responseCacheHashPayload!=null && !"".equals(responseCacheHashPayload)) {
  410.                 configurazione.getHashGenerator().setPayload(DriverConfigurazioneDBLib.getEnumStatoFunzionalita(responseCacheHashPayload));
  411.             }
  412.            
  413.             configurazione.setControl(new ResponseCachingConfigurazioneControl());
  414.            
  415.             int responseCacheControlNoCache = rs.getInt("response_cache_control_nocache");
  416.             if(CostantiDB.TRUE == responseCacheControlNoCache) {
  417.                 configurazione.getControl().setNoCache(true);
  418.             }
  419.             else if(CostantiDB.FALSE == responseCacheControlNoCache) {
  420.                 configurazione.getControl().setNoCache(false);
  421.             }
  422.            
  423.             int responseCacheControlMaxAge = rs.getInt("response_cache_control_maxage");
  424.             if(CostantiDB.TRUE == responseCacheControlMaxAge) {
  425.                 configurazione.getControl().setMaxAge(true);
  426.             }
  427.             else if(CostantiDB.FALSE == responseCacheControlMaxAge) {
  428.                 configurazione.getControl().setMaxAge(false);
  429.             }
  430.            
  431.             int responseCacheControlNoStore = rs.getInt("response_cache_control_nostore");
  432.             if(CostantiDB.TRUE == responseCacheControlNoStore) {
  433.                 configurazione.getControl().setNoStore(true);
  434.             }
  435.             else if(CostantiDB.FALSE == responseCacheControlNoStore) {
  436.                 configurazione.getControl().setNoStore(false);
  437.             }
  438.            
  439.             PreparedStatement stmRegole = null;
  440.             ResultSet rsRegole = null;
  441.             try {
  442.                 String nomeTabella = null;
  443.                 if(config) {
  444.                     nomeTabella = CostantiDB.CONFIGURAZIONE_CACHE_REGOLE;
  445.                 }
  446.                 else {
  447.                     nomeTabella = portaDelegata ? CostantiDB.PORTE_DELEGATE_CACHE_REGOLE : CostantiDB.PORTE_APPLICATIVE_CACHE_REGOLE;
  448.                 }
  449.                 ISQLQueryObject sqlQueryObject = SQLObjectFactory.createSQLQueryObject(this.driver.tipoDB);
  450.                 sqlQueryObject.addFromTable(nomeTabella);
  451.                 sqlQueryObject.addSelectField("*");
  452.                 if(!config) {
  453.                     sqlQueryObject.addWhereCondition("id_porta=?");
  454.                 }
  455.                 String sqlQuery = sqlQueryObject.createSQLQuery();
  456.                 stmRegole = con.prepareStatement(sqlQuery);
  457.                 if(!config) {
  458.                     stmRegole.setLong(1, idPorta);
  459.                 }
  460.        
  461.                 this.driver.logDebug("eseguo query : " + DBUtils.formatSQLString(sqlQuery, idPorta));
  462.                 rsRegole = stmRegole.executeQuery();
  463.        
  464.                 while (rsRegole.next()) {
  465.                
  466.                     ResponseCachingConfigurazioneRegola regola = new ResponseCachingConfigurazioneRegola();
  467.                    
  468.                     regola.setId(rsRegole.getLong("id"));
  469.                     int statusMin = rsRegole.getInt("status_min");
  470.                     int statusMax = rsRegole.getInt("status_max");
  471.                     if(statusMin>0) {
  472.                         regola.setReturnCodeMin(statusMin);
  473.                     }
  474.                     if(statusMax>0) {
  475.                         regola.setReturnCodeMax(statusMax);
  476.                     }

  477.                     int fault = rsRegole.getInt("fault");
  478.                     if(CostantiDB.TRUE == fault) {
  479.                         regola.setFault(true);
  480.                     }
  481.                     else if(CostantiDB.FALSE == fault) {
  482.                         regola.setFault(false);
  483.                     }
  484.                    
  485.                     int cacheSeconds = rsRegole.getInt("cache_seconds");
  486.                     if(cacheSeconds>0) {
  487.                         regola.setCacheTimeoutSeconds(cacheSeconds);
  488.                     }
  489.                    
  490.                     configurazione.addRegola(regola);
  491.                    
  492.                 }
  493.                
  494.                
  495.             }finally {
  496.                 JDBCUtilities.closeResources(rsRegole, stmRegole);
  497.             }
  498.         }

  499.     }
  500.    
  501.    
  502.     protected void updateProprietaOggetto(String nome, String user, String tabella) throws DriverConfigurazioneException {
  503.        
  504.         String nomeMetodo = "updateProprietaOggetto_"+tabella;
  505.        
  506.         Connection con = null;
  507.         if (this.driver.atomica) {
  508.             try {
  509.                 con = this.driver.getConnectionFromDatasource(nomeMetodo);
  510.             } catch (Exception e) {
  511.                 throw new DriverConfigurazioneException("[DriverConfigurazioneDB::" + nomeMetodo + "] Exception accedendo al datasource :" + e.getMessage(),e);

  512.             }

  513.         } else
  514.             con = this.driver.globalConnection;

  515.         this.driver.logDebug("operazione this.driver.atomica = " + this.driver.atomica);
  516.        
  517.         PreparedStatement stm = null;
  518.         try {

  519.             ISQLQueryObject sqlQueryObjectUpdate = SQLObjectFactory.createSQLQueryObject(this.driver.tipoDB);
  520.             sqlQueryObjectUpdate.addUpdateTable(tabella);
  521.             sqlQueryObjectUpdate.addUpdateField("utente_ultima_modifica", "?");
  522.             sqlQueryObjectUpdate.addUpdateField("data_ultima_modifica", "?");
  523.             sqlQueryObjectUpdate.addWhereCondition("nome_porta=?");
  524.             String updateString = sqlQueryObjectUpdate.createSQLUpdate();
  525.             stm = con.prepareStatement(updateString);
  526.             int index = 1;
  527.             stm.setString(index++, user);
  528.             stm.setTimestamp(index++, DateManager.getTimestamp());
  529.             stm.setString(index, nome);
  530.             int n=stm.executeUpdate();
  531.             stm.close();
  532.             this.driver.logDebug("Aggiornata "+n+" entry per l'operazione di ultima modifica della tabella '"+tabella+"' con nome: "+nome);
  533.         } catch (SQLException e) {
  534.             this.driver.logError("Errore SQL", e);
  535.             throw new DriverConfigurazioneException(e);
  536.         }catch (Exception e) {
  537.             this.driver.logError("Errore", e);
  538.             throw new DriverConfigurazioneException(e);
  539.         } finally {
  540.             JDBCUtilities.closeResources(stm);

  541.             this.driver.closeConnection(con);
  542.         }
  543.     }
  544. }