DriverConfigurazioneDB_pluginsDriver.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.sql.Timestamp;
  26. import java.util.ArrayList;
  27. import java.util.Arrays;
  28. import java.util.Date;
  29. import java.util.List;

  30. import org.openspcoop2.core.commons.DBUtils;
  31. import org.openspcoop2.core.commons.ISearch;
  32. import org.openspcoop2.core.commons.Liste;
  33. import org.openspcoop2.core.config.RegistroPlugin;
  34. import org.openspcoop2.core.config.RegistroPluginArchivio;
  35. import org.openspcoop2.core.config.RegistroPlugins;
  36. import org.openspcoop2.core.config.constants.PluginSorgenteArchivio;
  37. import org.openspcoop2.core.config.constants.StatoFunzionalita;
  38. import org.openspcoop2.core.config.driver.DriverConfigurazioneException;
  39. import org.openspcoop2.core.config.driver.DriverConfigurazioneNotFound;
  40. import org.openspcoop2.core.constants.CostantiDB;
  41. import org.openspcoop2.utils.jdbc.IJDBCAdapter;
  42. import org.openspcoop2.utils.jdbc.JDBCAdapterFactory;
  43. import org.openspcoop2.utils.jdbc.JDBCUtilities;
  44. import org.openspcoop2.utils.sql.ISQLQueryObject;
  45. import org.openspcoop2.utils.sql.SQLObjectFactory;

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

  56.     private DriverConfigurazioneDB driver = null;
  57.    
  58.     protected DriverConfigurazioneDB_pluginsDriver(DriverConfigurazioneDB driver) {
  59.         this.driver = driver;
  60.     }
  61.    
  62.     protected RegistroPlugins getRegistroPlugins() throws DriverConfigurazioneException, DriverConfigurazioneNotFound{
  63.        
  64.         Connection con = null;
  65.         PreparedStatement stm = null;
  66.         ResultSet rs = null;
  67.        
  68.         String sqlQuery = "";

  69.         if (this.driver.atomica) {
  70.             try {
  71.                 con = this.driver.getConnectionFromDatasource("getRegistroPlugins");
  72.             } catch (Exception e) {
  73.                 throw new DriverConfigurazioneException("[getRegistroPlugins] Exception accedendo al datasource :" + e.getMessage(),e);

  74.             }
  75.         } else
  76.             con = this.driver.globalConnection;

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

  78.         RegistroPlugins registro = null;
  79.        
  80.         try {
  81.            
  82.             ISQLQueryObject sqlQueryObject = SQLObjectFactory.createSQLQueryObject(this.driver.tipoDB);
  83.             sqlQueryObject.addFromTable(CostantiDB.REGISTRO_PLUGINS);
  84.             sqlQueryObject.addSelectField("nome");
  85.             sqlQueryObject.setANDLogicOperator(true);
  86.             sqlQueryObject.addOrderBy("posizione", true);
  87.             sqlQuery = sqlQueryObject.createSQLQuery();
  88.              
  89.             stm = con.prepareStatement(sqlQuery);
  90.             rs = stm.executeQuery();
  91.             List<String> nomi = new ArrayList<>();
  92.             while(rs.next()) {
  93.                 nomi.add(rs.getString("nome"));
  94.             }
  95.             rs.close();
  96.             stm.close();
  97.             rs=null;
  98.             stm=null;
  99.            
  100.             if(!nomi.isEmpty()) {
  101.                 if(registro==null) {
  102.                     registro = new RegistroPlugins();
  103.                 }
  104.                 for (String nome : nomi) {
  105.                     registro.addPlugin(this.getRegistroPlugin(con, nome));
  106.                 }
  107.             }
  108.            
  109.         } catch (SQLException se) {
  110.             throw new DriverConfigurazioneException("[getRegistroPlugins]  SqlException: " + se.getMessage(),se);
  111.         }catch (Exception se) {
  112.             throw new DriverConfigurazioneException("[getRegistroPlugins]  Exception: " + se.getMessage(),se);
  113.         } finally {
  114.             JDBCUtilities.closeResources(rs, stm);
  115.             this.driver.closeConnection(con);
  116.         }

  117.         if(registro==null || registro.sizePluginList()<=0) {
  118.             throw new DriverConfigurazioneNotFound("Nessun plugin registrato");
  119.         }
  120.         return registro;
  121.        
  122.     }
  123.    
  124.    
  125.    
  126.     protected RegistroPlugin getRegistroPlugin(String nome) throws DriverConfigurazioneException, DriverConfigurazioneNotFound{
  127.         return getRegistroPlugin(nome, false);
  128.     }
  129.     protected RegistroPlugin getDatiRegistroPlugin(String nome) throws DriverConfigurazioneException, DriverConfigurazioneNotFound{
  130.         return getRegistroPlugin(nome, true);
  131.     }
  132.     private RegistroPlugin getRegistroPlugin(String nome, boolean soloDati) throws DriverConfigurazioneException, DriverConfigurazioneNotFound{
  133.         Connection con = null;
  134.        
  135.         if (this.driver.atomica) {
  136.             try {
  137.                 con = this.driver.getConnectionFromDatasource("getRegistroPlugin");
  138.             } catch (Exception e) {
  139.                 throw new DriverConfigurazioneException("[getRegistroPlugin] Exception accedendo al datasource :" + e.getMessage(),e);

  140.             }
  141.         } else
  142.             con = this.driver.globalConnection;

  143.             try {
  144.            
  145.             return getRegistroPlugin(con, nome, soloDati);
  146.            
  147.         } finally {
  148.             this.driver.closeConnection(con);
  149.         }

  150.     }

  151.     protected RegistroPlugin getRegistroPlugin(Connection conParam, String nome) throws DriverConfigurazioneException, DriverConfigurazioneNotFound{
  152.         return getRegistroPlugin(conParam, nome, false);
  153.     }
  154.     protected RegistroPlugin getDatiRegistroPlugin(Connection conParam, String nome) throws DriverConfigurazioneException, DriverConfigurazioneNotFound{
  155.         return getRegistroPlugin(conParam, nome, true);
  156.     }
  157.     private RegistroPlugin getRegistroPlugin(Connection conParam, String nome, boolean soloDati) throws DriverConfigurazioneException, DriverConfigurazioneNotFound{
  158.         PreparedStatement stm = null;
  159.         ResultSet rs = null;
  160.        
  161.         String sqlQuery = "";

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

  163.         RegistroPlugin plugin = null;
  164.        
  165.         try {
  166.            
  167.             ISQLQueryObject sqlQueryObject = SQLObjectFactory.createSQLQueryObject(this.driver.tipoDB);
  168.             sqlQueryObject.addFromTable(CostantiDB.REGISTRO_PLUGINS);
  169.             sqlQueryObject.addWhereCondition("nome=?");
  170.             sqlQueryObject.setANDLogicOperator(true);
  171.             sqlQuery = sqlQueryObject.createSQLQuery();
  172.              
  173.             stm = conParam.prepareStatement(sqlQuery);
  174.             stm.setString(1, nome);
  175.             rs = stm.executeQuery();
  176.             if(rs.next()) {
  177.                
  178.                 plugin = new RegistroPlugin();
  179.                
  180.                 plugin.setId(rs.getLong("id"));
  181.                 plugin.setNome(rs.getString("nome"));
  182.                 plugin.setPosizione(rs.getInt("posizione"));
  183.                 StatoFunzionalita stato = DriverConfigurazioneDBLib.getEnumStatoFunzionalita(rs.getString("stato"));
  184.                 plugin.setStato(stato);
  185.                 plugin.setDescrizione(rs.getString("descrizione"));
  186.                 plugin.setData(rs.getTimestamp("data"));
  187.                
  188.                 String compatibilita = rs.getString("compatibilita");
  189.                 if( (compatibilita!=null && !"".equals(compatibilita)) ) {
  190.                     if(compatibilita.contains(",")) {
  191.                         String [] tmp = compatibilita.split(",");
  192.                         for (int i = 0; i < tmp.length; i++) {
  193.                             plugin.addCompatibilita(tmp[i].trim());
  194.                         }
  195.                     }
  196.                     else {
  197.                         plugin.addCompatibilita(compatibilita);
  198.                     }
  199.                 }
  200.                
  201.             }
  202.             rs.close();
  203.             stm.close();
  204.             rs=null;
  205.             stm=null;
  206.            
  207.             if(plugin!=null && !soloDati) {
  208.                
  209.                 // archive jar
  210.                 sqlQueryObject = SQLObjectFactory.createSQLQueryObject(this.driver.tipoDB);
  211.                 sqlQueryObject.addFromTable(CostantiDB.REGISTRO_PLUGINS_ARCHIVE);
  212.                 sqlQueryObject.addWhereCondition("id_plugin=?");
  213.                 sqlQueryObject.setANDLogicOperator(true);
  214.                 sqlQuery = sqlQueryObject.createSQLQuery();
  215.                  
  216.                 stm = conParam.prepareStatement(sqlQuery);
  217.                 stm.setLong(1, plugin.getId());
  218.                 rs = stm.executeQuery();
  219.                 while(rs.next()) {
  220.                    
  221.                     RegistroPluginArchivio archivio = new RegistroPluginArchivio();
  222.                     archivio.setNome(rs.getString("nome"));
  223.                     archivio.setData(rs.getTimestamp("data"));
  224.                     IJDBCAdapter jdbcAdapter = JDBCAdapterFactory.createJDBCAdapter(this.driver.tipoDB);
  225.                     archivio.setSorgente( DriverConfigurazioneDBLib.getEnumPluginSorgenteArchivio(rs.getString("sorgente")));
  226.                     switch (archivio.getSorgente()) {
  227.                     case JAR:
  228.                         archivio.setContenuto(jdbcAdapter.getBinaryData(rs, "contenuto"));
  229.                         break;
  230.                     case URL:
  231.                         archivio.setUrl(rs.getString("url"));
  232.                         break;
  233.                     case DIR:
  234.                         archivio.setDir(rs.getString("dir"));
  235.                         break;
  236.                     }
  237.                     plugin.addArchivio(archivio);
  238.                    
  239.                 }
  240.                 rs.close();
  241.                 stm.close();
  242.                 rs=null;
  243.                 stm=null;

  244.             }
  245.            
  246.         } catch (SQLException se) {
  247.             throw new DriverConfigurazioneException("[getRegistroPlugin]  SqlException: " + se.getMessage(),se);
  248.         }catch (Exception se) {
  249.             throw new DriverConfigurazioneException("[getRegistroPlugin]  Exception: " + se.getMessage(),se);
  250.         } finally {
  251.             JDBCUtilities.closeResources(rs, stm);
  252.         }

  253.         if(plugin!=null) {
  254.             return plugin;
  255.         }
  256.         throw new DriverConfigurazioneNotFound("Plugin '"+nome+"' non esistente");
  257.     }
  258.    
  259.     protected RegistroPlugin getRegistroPluginFromPosizione(int posizione) throws DriverConfigurazioneException, DriverConfigurazioneNotFound{
  260.         return getRegistroPluginFromPosizione(posizione, false);
  261.     }
  262.     protected RegistroPlugin getDatiRegistroPluginFromPosizione(int posizione) throws DriverConfigurazioneException, DriverConfigurazioneNotFound{
  263.         return getRegistroPluginFromPosizione(posizione, true);
  264.     }
  265.     private RegistroPlugin getRegistroPluginFromPosizione(int posizione, boolean soloDati) throws DriverConfigurazioneException, DriverConfigurazioneNotFound{
  266.         Connection con = null;
  267.         PreparedStatement stm = null;
  268.         ResultSet rs = null;
  269.        
  270.         String sqlQuery = "";

  271.         if (this.driver.atomica) {
  272.             try {
  273.                 con = this.driver.getConnectionFromDatasource("getRegistroPlugin");
  274.             } catch (Exception e) {
  275.                 throw new DriverConfigurazioneException("[getRegistroPlugin] Exception accedendo al datasource :" + e.getMessage(),e);

  276.             }
  277.         } else
  278.             con = this.driver.globalConnection;

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

  280.         RegistroPlugin plugin = null;
  281.        
  282.         try {
  283.            
  284.             ISQLQueryObject sqlQueryObject = SQLObjectFactory.createSQLQueryObject(this.driver.tipoDB);
  285.             sqlQueryObject.addFromTable(CostantiDB.REGISTRO_PLUGINS);
  286.             sqlQueryObject.addWhereCondition("posizione=?");
  287.             sqlQueryObject.setANDLogicOperator(true);
  288.             sqlQuery = sqlQueryObject.createSQLQuery();
  289.              
  290.             stm = con.prepareStatement(sqlQuery);
  291.             stm.setInt(1, posizione);
  292.             rs = stm.executeQuery();
  293.             if(rs.next()) {
  294.                
  295.                 plugin = new RegistroPlugin();
  296.                
  297.                 plugin.setId(rs.getLong("id"));
  298.                 plugin.setNome(rs.getString("nome"));
  299.                 plugin.setPosizione(rs.getInt("posizione"));
  300.                 StatoFunzionalita stato = DriverConfigurazioneDBLib.getEnumStatoFunzionalita(rs.getString("stato"));
  301.                 plugin.setStato(stato);
  302.                 plugin.setDescrizione(rs.getString("descrizione"));
  303.                 plugin.setData(rs.getTimestamp("data"));
  304.                
  305.                 String compatibilita = rs.getString("compatibilita");
  306.                 if( (compatibilita!=null && !"".equals(compatibilita)) ) {
  307.                     if(compatibilita.contains(",")) {
  308.                         String [] tmp = compatibilita.split(",");
  309.                         for (int i = 0; i < tmp.length; i++) {
  310.                             plugin.addCompatibilita(tmp[i].trim());
  311.                         }
  312.                     }
  313.                     else {
  314.                         plugin.addCompatibilita(compatibilita);
  315.                     }
  316.                 }
  317.                
  318.             }
  319.             rs.close();
  320.             stm.close();
  321.             rs=null;
  322.             stm=null;
  323.            
  324.             if(plugin!=null && !soloDati) {
  325.                
  326.                 // archive jar
  327.                 sqlQueryObject = SQLObjectFactory.createSQLQueryObject(this.driver.tipoDB);
  328.                 sqlQueryObject.addFromTable(CostantiDB.REGISTRO_PLUGINS_ARCHIVE);
  329.                 sqlQueryObject.addWhereCondition("id_plugin=?");
  330.                 sqlQueryObject.setANDLogicOperator(true);
  331.                 sqlQuery = sqlQueryObject.createSQLQuery();
  332.                  
  333.                 stm = con.prepareStatement(sqlQuery);
  334.                 stm.setLong(1, plugin.getId());
  335.                 rs = stm.executeQuery();
  336.                 while(rs.next()) {
  337.                    
  338.                     RegistroPluginArchivio archivio = new RegistroPluginArchivio();
  339.                     archivio.setNome(rs.getString("nome"));
  340.                     archivio.setData(rs.getTimestamp("data"));
  341.                     IJDBCAdapter jdbcAdapter = JDBCAdapterFactory.createJDBCAdapter(this.driver.tipoDB);
  342.                     archivio.setSorgente( DriverConfigurazioneDBLib.getEnumPluginSorgenteArchivio(rs.getString("sorgente")));
  343.                     switch (archivio.getSorgente()) {
  344.                     case JAR:
  345.                         archivio.setContenuto(jdbcAdapter.getBinaryData(rs, "contenuto"));
  346.                         break;
  347.                     case URL:
  348.                         archivio.setUrl(rs.getString("url"));
  349.                         break;
  350.                     case DIR:
  351.                         archivio.setDir(rs.getString("dir"));
  352.                         break;
  353.                     }
  354.                     plugin.addArchivio(archivio);
  355.                    
  356.                 }
  357.                 rs.close();
  358.                 stm.close();
  359.                 rs=null;
  360.                 stm=null;

  361.             }
  362.            
  363.         } catch (SQLException se) {
  364.             throw new DriverConfigurazioneException("[getRegistroPlugin]  SqlException: " + se.getMessage(),se);
  365.         }catch (Exception se) {
  366.             throw new DriverConfigurazioneException("[getRegistroPlugin]  Exception: " + se.getMessage(),se);
  367.         } finally {
  368.             JDBCUtilities.closeResources(rs, stm);
  369.             this.driver.closeConnection(con);
  370.         }

  371.         if(plugin!=null) {
  372.             return plugin;
  373.         }
  374.         throw new DriverConfigurazioneNotFound("Plugin in posizione '"+posizione+"' non esistente");
  375.     }
  376.    
  377.     protected boolean existsRegistroPlugin(String nome) throws DriverConfigurazioneException, DriverConfigurazioneNotFound{

  378.         Connection con = null;
  379.         PreparedStatement stm = null;
  380.         ResultSet rs = null;
  381.        
  382.         String sqlQuery = "";

  383.         if (this.driver.atomica) {
  384.             try {
  385.                 con = this.driver.getConnectionFromDatasource("existsRegistroPlugin");
  386.             } catch (Exception e) {
  387.                 throw new DriverConfigurazioneException("[existsRegistroPlugin] Exception accedendo al datasource :" + e.getMessage(),e);

  388.             }
  389.         } else
  390.             con = this.driver.globalConnection;

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

  392.         int count = -1;
  393.        
  394.         try {
  395.            
  396.             ISQLQueryObject sqlQueryObject = SQLObjectFactory.createSQLQueryObject(this.driver.tipoDB);
  397.             sqlQueryObject.addSelectCountField(CostantiDB.REGISTRO_PLUGINS+".id", "cont");
  398.             sqlQueryObject.addFromTable(CostantiDB.REGISTRO_PLUGINS);
  399.             sqlQueryObject.addWhereCondition("nome=?");
  400.             sqlQueryObject.setANDLogicOperator(true);
  401.             sqlQuery = sqlQueryObject.createSQLQuery();
  402.              
  403.             stm = con.prepareStatement(sqlQuery);
  404.             stm.setString(1, nome);
  405.             rs = stm.executeQuery();
  406.            
  407.             if(rs.next()) {
  408.                 count = rs.getInt(1);
  409.             }
  410.            
  411.             return count > 0;
  412.         } catch (SQLException se) {
  413.             throw new DriverConfigurazioneException("[existsRegistroPlugin]  SqlException: " + se.getMessage(),se);
  414.         }catch (Exception se) {
  415.             throw new DriverConfigurazioneException("[existsRegistroPlugin]  Exception: " + se.getMessage(),se);
  416.         } finally {
  417.             JDBCUtilities.closeResources(rs, stm);
  418.             this.driver.closeConnection(con);
  419.         }
  420.     }
  421.    
  422.     protected int getMaxPosizioneRegistroPlugin() throws DriverConfigurazioneException, DriverConfigurazioneNotFound{

  423.         Connection con = null;
  424.         PreparedStatement stm = null;
  425.         ResultSet rs = null;
  426.        
  427.         String sqlQuery = "";

  428.         if (this.driver.atomica) {
  429.             try {
  430.                 con = this.driver.getConnectionFromDatasource("getMaxPosizioneRegistroPlugin");
  431.             } catch (Exception e) {
  432.                 throw new DriverConfigurazioneException("[getMaxPosizioneRegistroPlugin] Exception accedendo al datasource :" + e.getMessage(),e);

  433.             }
  434.         } else
  435.             con = this.driver.globalConnection;

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

  437.         try {
  438.            
  439.             ISQLQueryObject sqlQueryObject = SQLObjectFactory.createSQLQueryObject(this.driver.tipoDB);
  440.             sqlQueryObject.addSelectMaxField(CostantiDB.REGISTRO_PLUGINS+".posizione", "max");
  441.             sqlQueryObject.addFromTable(CostantiDB.REGISTRO_PLUGINS);
  442.             sqlQueryObject.setANDLogicOperator(true);
  443.             sqlQuery = sqlQueryObject.createSQLQuery();
  444.              
  445.             stm = con.prepareStatement(sqlQuery);
  446.             rs = stm.executeQuery();
  447.            
  448.             if(rs.next()) {
  449.                 return rs.getInt(1);
  450.             }
  451.            
  452.             return 0;
  453.         } catch (SQLException se) {
  454.             throw new DriverConfigurazioneException("[getMaxPosizioneRegistroPlugin]  SqlException: " + se.getMessage(),se);
  455.         }catch (Exception se) {
  456.             throw new DriverConfigurazioneException("[getMaxPosizioneRegistroPlugin]  Exception: " + se.getMessage(),se);
  457.         } finally {
  458.             JDBCUtilities.closeResources(rs, stm);
  459.             this.driver.closeConnection(con);
  460.         }
  461.     }
  462.    
  463.     protected int getNumeroArchiviJarRegistroPlugin(String nome) throws DriverConfigurazioneException, DriverConfigurazioneNotFound{

  464.         Connection con = null;
  465.         PreparedStatement stm = null;
  466.         ResultSet rs = null;
  467.        
  468.         String sqlQuery = "";

  469.         if (this.driver.atomica) {
  470.             try {
  471.                 con = this.driver.getConnectionFromDatasource("getNumeroArchiviJarRegistroPlugin");
  472.             } catch (Exception e) {
  473.                 throw new DriverConfigurazioneException("[existsRegistroPlugin] Exception accedendo al datasource :" + e.getMessage(),e);

  474.             }
  475.         } else
  476.             con = this.driver.globalConnection;

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

  478.         int count = -1;
  479.        
  480.         try {
  481.            
  482.             ISQLQueryObject sqlQueryObject = SQLObjectFactory.createSQLQueryObject(this.driver.tipoDB);
  483.             sqlQueryObject.addSelectCountField(CostantiDB.REGISTRO_PLUGINS_ARCHIVE+".id", "cont");
  484.             sqlQueryObject.addFromTable(CostantiDB.REGISTRO_PLUGINS_ARCHIVE);
  485.             sqlQueryObject.addFromTable(CostantiDB.REGISTRO_PLUGINS);
  486.             sqlQueryObject.addWhereCondition(CostantiDB.REGISTRO_PLUGINS_ARCHIVE + ".id_plugin = " + CostantiDB.REGISTRO_PLUGINS + ".id");
  487.             sqlQueryObject.addWhereCondition(CostantiDB.REGISTRO_PLUGINS + ".nome=?");
  488.             sqlQueryObject.setANDLogicOperator(true);
  489.             sqlQuery = sqlQueryObject.createSQLQuery();
  490.              
  491.             stm = con.prepareStatement(sqlQuery);
  492.             stm.setString(1, nome);
  493.             rs = stm.executeQuery();
  494.            
  495.             if(rs.next()) {
  496.                 count = rs.getInt(1);
  497.             }
  498.            
  499.             return count;
  500.         } catch (SQLException se) {
  501.             throw new DriverConfigurazioneException("[getNumeroArchiviJarRegistroPlugin]  SqlException: " + se.getMessage(),se);
  502.         }catch (Exception se) {
  503.             throw new DriverConfigurazioneException("[getNumeroArchiviJarRegistroPlugin]  Exception: " + se.getMessage(),se);
  504.         } finally {
  505.             JDBCUtilities.closeResources(rs, stm);
  506.             this.driver.closeConnection(con);
  507.         }
  508.     }
  509.    
  510.     protected void createRegistroPlugin(RegistroPlugin plugin) throws DriverConfigurazioneException{
  511.         Connection con = null;
  512.         boolean error = false;

  513.         if (this.driver.atomica) {
  514.             try {
  515.                 con = this.driver.getConnectionFromDatasource("createRegistroPlugin");
  516.                 con.setAutoCommit(false);
  517.             } catch (Exception e) {
  518.                 throw new DriverConfigurazioneException("[DriverConfigurazioneDB::createRegistroPlugin] Exception accedendo al datasource :" + e.getMessage(),e);

  519.             }

  520.         } else
  521.             con = this.driver.globalConnection;

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

  523.         try {
  524.             this.driver.logDebug("CRUDRegistroPlugin type = 1");
  525.             DriverConfigurazioneDB_pluginsLIB.CRUDRegistroPlugin(1, plugin, con);

  526.         } catch (Exception qe) {
  527.             error = true;
  528.             throw new DriverConfigurazioneException("[DriverConfigurazioneDB::createRegistroPlugin] Errore durante la createRegistroPlugin : " + qe.getMessage(),qe);
  529.         } finally {

  530.             this.driver.closeConnection(error,con);
  531.         }
  532.     }
  533.    
  534.     protected void updateRegistroPlugin(RegistroPlugin plugin) throws DriverConfigurazioneException{
  535.         Connection con = null;
  536.         boolean error = false;

  537.         if (this.driver.atomica) {
  538.             try {
  539.                 con = this.driver.getConnectionFromDatasource("updateRegistroPlugin");
  540.                 con.setAutoCommit(false);
  541.             } catch (Exception e) {
  542.                 throw new DriverConfigurazioneException("[DriverConfigurazioneDB::updateRegistroPlugin] Exception accedendo al datasource :" + e.getMessage(),e);

  543.             }

  544.         } else
  545.             con = this.driver.globalConnection;

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

  547.         try {
  548.             this.driver.logDebug("CRUDRegistroPlugin type = 2");
  549.             DriverConfigurazioneDB_pluginsLIB.CRUDRegistroPlugin(2, plugin, con);

  550.         } catch (Exception qe) {
  551.             error = true;
  552.             throw new DriverConfigurazioneException("[DriverConfigurazioneDB::updateRegistroPlugin] Errore durante la updateRegistroPlugin : " + qe.getMessage(),qe);
  553.         } finally {

  554.             this.driver.closeConnection(error,con);
  555.         }
  556.     }
  557.    
  558.     protected void deleteRegistroPlugin(RegistroPlugin plugin) throws DriverConfigurazioneException{
  559.         Connection con = null;
  560.         boolean error = false;

  561.         if (this.driver.atomica) {
  562.             try {
  563.                 con = this.driver.getConnectionFromDatasource("deleteRegistroPlugin");
  564.                 con.setAutoCommit(false);
  565.             } catch (Exception e) {
  566.                 throw new DriverConfigurazioneException("[DriverConfigurazioneDB::deleteRegistroPlugin] Exception accedendo al datasource :" + e.getMessage(),e);

  567.             }

  568.         } else
  569.             con = this.driver.globalConnection;

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

  571.         try {
  572.             this.driver.logDebug("CRUDRegistroPlugin type = 3");
  573.             DriverConfigurazioneDB_pluginsLIB.CRUDRegistroPlugin(3, plugin, con);

  574.         } catch (Exception qe) {
  575.             error = true;
  576.             throw new DriverConfigurazioneException("[DriverConfigurazioneDB::deleteRegistroPlugin] Errore durante la deleteRegistroPlugin : " + qe.getMessage(),qe);
  577.         } finally {

  578.             this.driver.closeConnection(error,con);
  579.         }
  580.     }
  581.    
  582.     protected void updateDatiRegistroPlugin(String nomePlugin, RegistroPlugin plugin) throws DriverConfigurazioneException{
  583.         Connection con = null;
  584.         boolean error = false;

  585.         if (this.driver.atomica) {
  586.             try {
  587.                 con = this.driver.getConnectionFromDatasource("updateDatiRegistroPlugin");
  588.                 con.setAutoCommit(false);
  589.             } catch (Exception e) {
  590.                 throw new DriverConfigurazioneException("[DriverConfigurazioneDB::updateDatiRegistroPlugin] Exception accedendo al datasource :" + e.getMessage(),e);

  591.             }

  592.         } else
  593.             con = this.driver.globalConnection;

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

  595.         try {
  596.             this.driver.logDebug("updateDatiRegistroPlugin");
  597.             DriverConfigurazioneDB_pluginsLIB.updateDatiRegistroPlugin(nomePlugin, plugin, con);

  598.         } catch (Exception qe) {
  599.             error = true;
  600.             throw new DriverConfigurazioneException("[DriverConfigurazioneDB::updateDatiRegistroPlugin] Errore durante la updateDatiRegistroPlugin : " + qe.getMessage(),qe);
  601.         } finally {

  602.             this.driver.closeConnection(error,con);
  603.         }
  604.     }
  605.    
  606.     protected RegistroPluginArchivio getRegistroPluginArchivio(String nomePlugin, String nome) throws DriverConfigurazioneException, DriverConfigurazioneNotFound{
  607.         Connection con = null;
  608.         PreparedStatement stm = null;
  609.         ResultSet rs = null;
  610.        
  611.         String sqlQuery = "";

  612.         if (this.driver.atomica) {
  613.             try {
  614.                 con = this.driver.getConnectionFromDatasource("getRegistroPluginArchivio");
  615.             } catch (Exception e) {
  616.                 throw new DriverConfigurazioneException("[getRegistroPluginArchivio] Exception accedendo al datasource :" + e.getMessage(),e);

  617.             }
  618.         } else
  619.             con = this.driver.globalConnection;

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

  621.         RegistroPluginArchivio archivio = null;
  622.        
  623.         try {
  624.            
  625.             long idPlugin = DBUtils.getIdRegistroPlugin(nomePlugin, con, this.driver.tipoDB);
  626.             if(idPlugin<=0) {
  627.                 throw new DriverConfigurazioneNotFound("Plugin '"+nomePlugin+"' non esistente");
  628.             }
  629.            
  630.             if(nome==null) {
  631.                 throw new DriverConfigurazioneException("Nome archivio non indicato");
  632.             }
  633.            
  634.             // archive jar
  635.             ISQLQueryObject sqlQueryObject = SQLObjectFactory.createSQLQueryObject(this.driver.tipoDB);
  636.             sqlQueryObject.addFromTable(CostantiDB.REGISTRO_PLUGINS_ARCHIVE);
  637.             sqlQueryObject.addWhereCondition("id_plugin=?");
  638.             sqlQueryObject.addWhereCondition("nome=?");
  639.             sqlQueryObject.setANDLogicOperator(true);
  640.             sqlQuery = sqlQueryObject.createSQLQuery();
  641.            
  642.             stm = con.prepareStatement(sqlQuery);
  643.             stm.setLong(1, idPlugin);
  644.             stm.setString(2, nome);
  645.             rs = stm.executeQuery();
  646.             if(rs.next()) {
  647.                    
  648.                 archivio = new RegistroPluginArchivio();
  649.                 archivio.setNome(rs.getString("nome"));
  650.                 archivio.setData(rs.getTimestamp("data"));
  651.                 IJDBCAdapter jdbcAdapter = JDBCAdapterFactory.createJDBCAdapter(this.driver.tipoDB);
  652.                 archivio.setSorgente( DriverConfigurazioneDBLib.getEnumPluginSorgenteArchivio(rs.getString("sorgente")));
  653.                 switch (archivio.getSorgente()) {
  654.                 case JAR:
  655.                     archivio.setContenuto(jdbcAdapter.getBinaryData(rs, "contenuto"));
  656.                     break;
  657.                 case URL:
  658.                     archivio.setUrl(rs.getString("url"));
  659.                     break;
  660.                 case DIR:
  661.                     archivio.setDir(rs.getString("dir"));
  662.                     break;
  663.                 }
  664.    
  665.             }
  666.             rs.close();
  667.             stm.close();
  668.             rs=null;
  669.             stm=null;

  670.    
  671.         }catch (DriverConfigurazioneNotFound notFound) {
  672.             throw notFound;
  673.         }catch (SQLException se) {
  674.             throw new DriverConfigurazioneException("[getRegistroPluginArchivio]  SqlException: " + se.getMessage(),se);
  675.         }catch (Exception se) {
  676.             throw new DriverConfigurazioneException("[getRegistroPluginArchivio]  Exception: " + se.getMessage(),se);
  677.         }
  678.         finally {
  679.             JDBCUtilities.closeResources(rs, stm);
  680.             this.driver.closeConnection(con);
  681.         }

  682.         if(archivio!=null) {
  683.             archivio.setNomePlugin(nomePlugin);
  684.             return archivio;
  685.         }
  686.         throw new DriverConfigurazioneNotFound("Archivio '"+nome+"' non esistente nel plugin '"+nomePlugin+"'");
  687.     }
  688.    
  689.     protected boolean existsRegistroPluginArchivio(String nomePlugin, String nome) throws DriverConfigurazioneException, DriverConfigurazioneNotFound{

  690.         Connection con = null;
  691.         PreparedStatement stm = null;
  692.         ResultSet rs = null;
  693.        
  694.         String sqlQuery = "";

  695.         if (this.driver.atomica) {
  696.             try {
  697.                 con = this.driver.getConnectionFromDatasource("existsRegistroPluginArchivio");
  698.             } catch (Exception e) {
  699.                 throw new DriverConfigurazioneException("[existsRegistroPluginArchivio] Exception accedendo al datasource :" + e.getMessage(),e);

  700.             }
  701.         } else
  702.             con = this.driver.globalConnection;

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

  704.         int count = -1;
  705.        
  706.         try {
  707.             long idPlugin = DBUtils.getIdRegistroPlugin(nomePlugin, con, this.driver.tipoDB);
  708.             if(idPlugin<=0) {
  709.                 throw new DriverConfigurazioneNotFound("Plugin '"+nomePlugin+"' non esistente");
  710.             }
  711.            
  712.             if(nome==null) {
  713.                 throw new DriverConfigurazioneException("Nome archivio non indicato");
  714.             }
  715.            
  716.             // archive jar
  717.             ISQLQueryObject sqlQueryObject = SQLObjectFactory.createSQLQueryObject(this.driver.tipoDB);
  718.             sqlQueryObject.addSelectCountField(CostantiDB.REGISTRO_PLUGINS_ARCHIVE+".id", "cont");
  719.             sqlQueryObject.addFromTable(CostantiDB.REGISTRO_PLUGINS_ARCHIVE);
  720.             sqlQueryObject.addWhereCondition("id_plugin=?");
  721.             sqlQueryObject.addWhereCondition("nome=?");
  722.             sqlQueryObject.setANDLogicOperator(true);
  723.             sqlQuery = sqlQueryObject.createSQLQuery();
  724.            
  725.             stm = con.prepareStatement(sqlQuery);
  726.             stm.setLong(1, idPlugin);
  727.             stm.setString(2, nome);
  728.             rs = stm.executeQuery();
  729.             if(rs.next()) {
  730.                    
  731.                 count = rs.getInt(1);
  732.    
  733.             }
  734.             rs.close();
  735.             stm.close();
  736.             rs=null;
  737.             stm=null;
  738.            
  739.             return count > 0;
  740.         } catch (SQLException se) {
  741.             throw new DriverConfigurazioneException("[existsRegistroPluginArchivio]  SqlException: " + se.getMessage(),se);
  742.         }catch (Exception se) {
  743.             throw new DriverConfigurazioneException("[existsRegistroPluginArchivio]  Exception: " + se.getMessage(),se);
  744.         } finally {
  745.             JDBCUtilities.closeResources(rs, stm);
  746.             this.driver.closeConnection(con);
  747.         }
  748.     }
  749.    
  750.     protected boolean existsRegistroPluginArchivio(String nomePlugin, PluginSorgenteArchivio tipoSorgente, String sorgente) throws DriverConfigurazioneException, DriverConfigurazioneNotFound{

  751.         Connection con = null;
  752.         PreparedStatement stm = null;
  753.         ResultSet rs = null;
  754.        
  755.         String sqlQuery = "";

  756.         if (this.driver.atomica) {
  757.             try {
  758.                 con = this.driver.getConnectionFromDatasource("existsRegistroPluginArchivio");
  759.             } catch (Exception e) {
  760.                 throw new DriverConfigurazioneException("[existsRegistroPluginArchivio] Exception accedendo al datasource :" + e.getMessage(),e);

  761.             }
  762.         } else
  763.             con = this.driver.globalConnection;

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

  765.         int count = -1;
  766.        
  767.         try {
  768.             long idPlugin = DBUtils.getIdRegistroPlugin(nomePlugin, con, this.driver.tipoDB);
  769.             if(idPlugin<=0) {
  770.                 throw new DriverConfigurazioneNotFound("Plugin '"+nomePlugin+"' non esistente");
  771.             }
  772.            
  773.             if(tipoSorgente==null) {
  774.                 throw new DriverConfigurazioneException("TipoSorgente non indicata");
  775.             }
  776.             if(sorgente==null) {
  777.                 throw new DriverConfigurazioneException("Sorgente non indicata");
  778.             }
  779.            
  780.             // archive jar
  781.             ISQLQueryObject sqlQueryObject = SQLObjectFactory.createSQLQueryObject(this.driver.tipoDB);
  782.             sqlQueryObject.addSelectCountField(CostantiDB.REGISTRO_PLUGINS_ARCHIVE+".id", "cont");
  783.             sqlQueryObject.addFromTable(CostantiDB.REGISTRO_PLUGINS_ARCHIVE);
  784.             sqlQueryObject.addWhereCondition("id_plugin=?");
  785.             switch (tipoSorgente) {
  786.             case JAR:
  787.                 sqlQueryObject.addWhereCondition("nome=?");
  788.                 break;
  789.             case DIR:
  790.                 sqlQueryObject.addWhereCondition("dir=?");
  791.                 break;
  792.             case URL:
  793.                 sqlQueryObject.addWhereCondition("url=?");
  794.                 break;
  795.             default:
  796.                 break;
  797.             }
  798.            
  799.             sqlQueryObject.setANDLogicOperator(true);
  800.             sqlQuery = sqlQueryObject.createSQLQuery();
  801.            
  802.             stm = con.prepareStatement(sqlQuery);
  803.             stm.setLong(1, idPlugin);
  804.             stm.setString(2, sorgente);
  805.             rs = stm.executeQuery();
  806.             if(rs.next()) {
  807.                    
  808.                 count = rs.getInt(1);
  809.    
  810.             }
  811.             rs.close();
  812.             stm.close();
  813.             rs=null;
  814.             stm=null;
  815.            
  816.             return count > 0;
  817.         } catch (SQLException se) {
  818.             throw new DriverConfigurazioneException("[existsRegistroPluginArchivio]  SqlException: " + se.getMessage(),se);
  819.         }catch (Exception se) {
  820.             throw new DriverConfigurazioneException("[existsRegistroPluginArchivio]  Exception: " + se.getMessage(),se);
  821.         } finally {
  822.             JDBCUtilities.closeResources(rs, stm);
  823.             this.driver.closeConnection(con);
  824.         }
  825.     }
  826.    
  827.     protected void createRegistroPluginArchivio(String nomePlugin, RegistroPluginArchivio plugin) throws DriverConfigurazioneException{
  828.         Connection con = null;
  829.         boolean error = false;

  830.         if (this.driver.atomica) {
  831.             try {
  832.                 con = this.driver.getConnectionFromDatasource("createRegistroPluginArchivio");
  833.                 con.setAutoCommit(false);
  834.             } catch (Exception e) {
  835.                 throw new DriverConfigurazioneException("[DriverConfigurazioneDB::createRegistroPluginArchivio] Exception accedendo al datasource :" + e.getMessage(),e);

  836.             }

  837.         } else
  838.             con = this.driver.globalConnection;

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

  840.         try {
  841.             this.driver.logDebug("CRUDRegistroPlugin type = 1");
  842.             DriverConfigurazioneDB_pluginsLIB.CRUDRegistroPluginArchivio(1, nomePlugin, plugin, con);

  843.         } catch (Exception qe) {
  844.             error = true;
  845.             throw new DriverConfigurazioneException("[DriverConfigurazioneDB::createRegistroPluginArchivio] Errore durante la createRegistroPluginArchivio : " + qe.getMessage(),qe);
  846.         } finally {

  847.             this.driver.closeConnection(error,con);
  848.         }
  849.     }
  850.    
  851.     protected void updateRegistroPluginArchivio(String nomePlugin, RegistroPluginArchivio plugin) throws DriverConfigurazioneException{
  852.         Connection con = null;
  853.         boolean error = false;

  854.         if (this.driver.atomica) {
  855.             try {
  856.                 con = this.driver.getConnectionFromDatasource("updateRegistroPluginArchivio");
  857.                 con.setAutoCommit(false);
  858.             } catch (Exception e) {
  859.                 throw new DriverConfigurazioneException("[DriverConfigurazioneDB::updateRegistroPluginArchivio] Exception accedendo al datasource :" + e.getMessage(),e);

  860.             }

  861.         } else
  862.             con = this.driver.globalConnection;

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

  864.         try {
  865.             this.driver.logDebug("CRUDRegistroPlugin type = 2");
  866.             DriverConfigurazioneDB_pluginsLIB.CRUDRegistroPluginArchivio(2, nomePlugin, plugin, con);

  867.         } catch (Exception qe) {
  868.             error = true;
  869.             throw new DriverConfigurazioneException("[DriverConfigurazioneDB::updateRegistroPluginArchivio] Errore durante la updateRegistroPluginArchivio : " + qe.getMessage(),qe);
  870.         } finally {

  871.             this.driver.closeConnection(error,con);
  872.         }
  873.     }
  874.    
  875.     protected void deleteRegistroPluginArchivio(String nomePlugin, RegistroPluginArchivio plugin) throws DriverConfigurazioneException{
  876.         Connection con = null;
  877.         boolean error = false;

  878.         if (this.driver.atomica) {
  879.             try {
  880.                 con = this.driver.getConnectionFromDatasource("deleteRegistroPluginArchivio");
  881.                 con.setAutoCommit(false);
  882.             } catch (Exception e) {
  883.                 throw new DriverConfigurazioneException("[DriverConfigurazioneDB::deleteRegistroPluginArchivio] Exception accedendo al datasource :" + e.getMessage(),e);

  884.             }

  885.         } else
  886.             con = this.driver.globalConnection;

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

  888.         try {
  889.             this.driver.logDebug("CRUDRegistroPlugin type = 3");
  890.             DriverConfigurazioneDB_pluginsLIB.CRUDRegistroPluginArchivio(3, nomePlugin, plugin, con);

  891.         } catch (Exception qe) {
  892.             error = true;
  893.             throw new DriverConfigurazioneException("[DriverConfigurazioneDB::deleteRegistroPluginArchivio] Errore durante la deleteRegistroPluginArchivio : " + qe.getMessage(),qe);
  894.         } finally {

  895.             this.driver.closeConnection(error,con);
  896.         }
  897.     }
  898.    
  899.     protected List<RegistroPlugin> pluginsArchiviList(ISearch ricerca) throws DriverConfigurazioneException {
  900.         String nomeMetodo = "pluginsArchiviList";
  901.         int idLista = Liste.CONFIGURAZIONE_PLUGINS_ARCHIVI;
  902.         int offset;
  903.         int limit;
  904.         String queryString;
  905.         String search;

  906.         limit = ricerca.getPageSize(idLista);
  907.         offset = ricerca.getIndexIniziale(idLista);
  908.         search = (org.openspcoop2.core.constants.Costanti.SESSION_ATTRIBUTE_VALUE_RICERCA_UNDEFINED.equals(ricerca.getSearchString(idLista)) ? "" : ricerca.getSearchString(idLista));

  909.         Connection con = null;
  910.         PreparedStatement stmt=null;
  911.         ResultSet risultato=null;
  912.         ArrayList<RegistroPlugin> lista = new ArrayList<>();

  913.         if (this.driver.atomica) {
  914.             try {
  915.                 con = this.driver.getConnectionFromDatasource("pluginsArchiviList");
  916.             } catch (Exception e) {
  917.                 throw new DriverConfigurazioneException("[DriverConfigurazioneDB::" + nomeMetodo + "] Exception accedendo al datasource :" + e.getMessage(),e);

  918.             }

  919.         } else
  920.             con = this.driver.globalConnection;

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

  922.         try {

  923.             ISQLQueryObject sqlQueryObject = SQLObjectFactory.createSQLQueryObject(this.driver.tipoDB);
  924.             sqlQueryObject.addFromTable(CostantiDB.REGISTRO_PLUGINS);
  925.             sqlQueryObject.addSelectCountField("id", "cont");
  926.            
  927.             if (!search.equals("")) {
  928.                 sqlQueryObject.addWhereLikeCondition("nome", search, true, true);
  929.             }
  930.            
  931.             queryString = sqlQueryObject.createSQLQuery();
  932.             stmt = con.prepareStatement(queryString);
  933.             risultato = stmt.executeQuery();
  934.             if (risultato.next())
  935.                 ricerca.setNumEntries(idLista,risultato.getInt(1));
  936.             risultato.close();
  937.             stmt.close();

  938.             // ricavo le entries
  939.             if (limit == 0) // con limit
  940.                 limit = ISQLQueryObject.LIMIT_DEFAULT_VALUE;

  941.             sqlQueryObject = SQLObjectFactory.createSQLQueryObject(this.driver.tipoDB);
  942.             sqlQueryObject.addFromTable(CostantiDB.REGISTRO_PLUGINS);
  943.             sqlQueryObject.addSelectField("id");
  944.             sqlQueryObject.addSelectField("nome");            
  945.             sqlQueryObject.addSelectField("posizione");      
  946.             sqlQueryObject.addSelectField("stato");          
  947.             sqlQueryObject.addSelectField("descrizione");    
  948.             sqlQueryObject.addSelectField("data");        
  949.             sqlQueryObject.addSelectField("compatibilita");          
  950.            
  951.             if (!search.equals("")) {
  952.                 sqlQueryObject.addWhereLikeCondition("nome", search, true, true);
  953.             }
  954.             sqlQueryObject.addOrderBy("posizione");
  955.             sqlQueryObject.addOrderBy("nome");
  956.             sqlQueryObject.setSortType(true);
  957.             sqlQueryObject.setLimit(limit);
  958.             sqlQueryObject.setOffset(offset);
  959.             queryString = sqlQueryObject.createSQLQuery();
  960.             stmt = con.prepareStatement(queryString);
  961.             risultato = stmt.executeQuery();

  962.            
  963.             while (risultato.next()) {
  964.                 RegistroPlugin regola = new RegistroPlugin();
  965.                 regola.setId(risultato.getLong("id"));
  966.                 regola.setNome(risultato.getString("nome"));
  967.                 regola.setPosizione(risultato.getInt("posizione"));
  968.                 regola.setStato(DriverConfigurazioneDBLib.getEnumStatoFunzionalita(risultato.getString("stato")));
  969.                 regola.setDescrizione(risultato.getString("descrizione"));
  970.                 Timestamp timestamp = risultato.getTimestamp("data");
  971.                 regola.setData(new Date(timestamp.getTime()));
  972.                
  973.                 String compatibilita = risultato.getString("compatibilita");
  974.                 if(compatibilita != null)
  975.                     regola.setCompatibilitaList(Arrays.asList(compatibilita.split(",")));
  976.                
  977.                 lista.add(regola);
  978.            
  979.             }
  980.             risultato.close();
  981.             stmt.close();
  982.            
  983.             return lista;

  984.         } catch (Exception qe) {
  985.             throw new DriverConfigurazioneException("[DriverConfigurazioneDB::" + nomeMetodo + "] Errore : " + qe.getMessage(),qe);
  986.         } finally {

  987.             //Chiudo statement and resultset
  988.             JDBCUtilities.closeResources(risultato, stmt);

  989.             this.driver.closeConnection(con);
  990.         }
  991.     }
  992.     protected List<RegistroPluginArchivio> pluginsArchiviJarList(String nome, ISearch ricerca) throws DriverConfigurazioneException {
  993.         return this.pluginsArchiviJarList(nome, ricerca, true);
  994.     }
  995.    
  996.     private List<RegistroPluginArchivio> pluginsArchiviJarList(String nome, ISearch ricerca, boolean escludiContenuto) throws DriverConfigurazioneException {
  997.         String nomeMetodo = "pluginsArchiviList";
  998.         int idLista = Liste.CONFIGURAZIONE_PLUGINS_ARCHIVI_JAR;
  999.         int offset;
  1000.         int limit;
  1001.         String queryString;
  1002.         String search;

  1003.         limit = ricerca.getPageSize(idLista);
  1004.         offset = ricerca.getIndexIniziale(idLista);
  1005.         search = (org.openspcoop2.core.constants.Costanti.SESSION_ATTRIBUTE_VALUE_RICERCA_UNDEFINED.equals(ricerca.getSearchString(idLista)) ? "" : ricerca.getSearchString(idLista));

  1006.         Connection con = null;
  1007.         PreparedStatement stmt=null;
  1008.         ResultSet risultato=null;
  1009.         ArrayList<RegistroPluginArchivio> lista = new ArrayList<>();

  1010.         if (this.driver.atomica) {
  1011.             try {
  1012.                 con = this.driver.getConnectionFromDatasource("pluginsArchiviList");
  1013.             } catch (Exception e) {
  1014.                 throw new DriverConfigurazioneException("[DriverConfigurazioneDB::" + nomeMetodo + "] Exception accedendo al datasource :" + e.getMessage(),e);

  1015.             }

  1016.         } else
  1017.             con = this.driver.globalConnection;

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

  1019.         try {

  1020.             ISQLQueryObject sqlQueryObjectOr = null;
  1021.             if (!search.equals("")) {
  1022.                 ISQLQueryObject sqlQueryObjectJar = SQLObjectFactory.createSQLQueryObject(this.driver.tipoDB);
  1023.                 sqlQueryObjectJar.addWhereLikeCondition(CostantiDB.REGISTRO_PLUGINS_ARCHIVE + ".nome", search, true, true);
  1024.                 sqlQueryObjectJar.addWhereCondition(CostantiDB.REGISTRO_PLUGINS_ARCHIVE + ".sorgente = ?");
  1025.                 sqlQueryObjectJar.setANDLogicOperator(true);    
  1026.                
  1027.                 ISQLQueryObject sqlQueryObjectUrl = SQLObjectFactory.createSQLQueryObject(this.driver.tipoDB);
  1028.                 sqlQueryObjectUrl.addWhereLikeCondition(CostantiDB.REGISTRO_PLUGINS_ARCHIVE + ".url", search, true, true);
  1029.                 sqlQueryObjectUrl.addWhereCondition(CostantiDB.REGISTRO_PLUGINS_ARCHIVE + ".sorgente = ?");
  1030.                 sqlQueryObjectUrl.setANDLogicOperator(true);    
  1031.                
  1032.                 ISQLQueryObject sqlQueryObjectDir = SQLObjectFactory.createSQLQueryObject(this.driver.tipoDB);
  1033.                 sqlQueryObjectDir.addWhereLikeCondition(CostantiDB.REGISTRO_PLUGINS_ARCHIVE + ".dir", search, true, true);
  1034.                 sqlQueryObjectDir.addWhereCondition(CostantiDB.REGISTRO_PLUGINS_ARCHIVE + ".sorgente = ?");
  1035.                 sqlQueryObjectDir.setANDLogicOperator(true);    
  1036.                
  1037.                 sqlQueryObjectOr = SQLObjectFactory.createSQLQueryObject(this.driver.tipoDB);
  1038.                 sqlQueryObjectOr.setANDLogicOperator(false);    
  1039.                 sqlQueryObjectOr.addWhereCondition(sqlQueryObjectJar.createSQLConditions());
  1040.                 sqlQueryObjectOr.addWhereCondition(sqlQueryObjectUrl.createSQLConditions());
  1041.                 sqlQueryObjectOr.addWhereCondition(sqlQueryObjectDir.createSQLConditions());
  1042.             }
  1043.            
  1044.            
  1045.             ISQLQueryObject sqlQueryObject = SQLObjectFactory.createSQLQueryObject(this.driver.tipoDB);
  1046.             sqlQueryObject.addSelectCountField(CostantiDB.REGISTRO_PLUGINS_ARCHIVE+".id", "cont");
  1047.             sqlQueryObject.addFromTable(CostantiDB.REGISTRO_PLUGINS_ARCHIVE);
  1048.             sqlQueryObject.addFromTable(CostantiDB.REGISTRO_PLUGINS);
  1049.             sqlQueryObject.addWhereCondition(CostantiDB.REGISTRO_PLUGINS_ARCHIVE + ".id_plugin = " + CostantiDB.REGISTRO_PLUGINS + ".id");
  1050.             sqlQueryObject.addWhereCondition(CostantiDB.REGISTRO_PLUGINS + ".nome=?");
  1051.             sqlQueryObject.setANDLogicOperator(true);
  1052.            
  1053.             if (sqlQueryObjectOr!=null) {
  1054.                 sqlQueryObject.addWhereCondition(sqlQueryObjectOr.createSQLConditions());
  1055.             }
  1056.            
  1057.             queryString = sqlQueryObject.createSQLQuery();
  1058.             stmt = con.prepareStatement(queryString);
  1059.             int parameterIndex = 1;
  1060.             stmt.setString(parameterIndex ++, nome);
  1061.             if (sqlQueryObjectOr!=null) {
  1062.                 stmt.setString(parameterIndex ++, DriverConfigurazioneDBLib.getValue(PluginSorgenteArchivio.JAR));
  1063.                 stmt.setString(parameterIndex ++, DriverConfigurazioneDBLib.getValue(PluginSorgenteArchivio.URL));
  1064.                 stmt.setString(parameterIndex ++, DriverConfigurazioneDBLib.getValue(PluginSorgenteArchivio.DIR));
  1065.             }
  1066.             risultato = stmt.executeQuery();
  1067.             if (risultato.next())
  1068.                 ricerca.setNumEntries(idLista,risultato.getInt(1));
  1069.             risultato.close();
  1070.             stmt.close();

  1071.             // ricavo le entries
  1072.             if (limit == 0) // con limit
  1073.                 limit = ISQLQueryObject.LIMIT_DEFAULT_VALUE;

  1074.             sqlQueryObject = SQLObjectFactory.createSQLQueryObject(this.driver.tipoDB);
  1075.             sqlQueryObject.addFromTable(CostantiDB.REGISTRO_PLUGINS_ARCHIVE);
  1076.             sqlQueryObject.addFromTable(CostantiDB.REGISTRO_PLUGINS);
  1077.             sqlQueryObject.addWhereCondition(CostantiDB.REGISTRO_PLUGINS_ARCHIVE + ".id_plugin = " + CostantiDB.REGISTRO_PLUGINS + ".id");
  1078.             sqlQueryObject.addWhereCondition(CostantiDB.REGISTRO_PLUGINS + ".nome=?");
  1079.             sqlQueryObject.setANDLogicOperator(true);
  1080.            
  1081.             if (sqlQueryObjectOr!=null) {
  1082.                 sqlQueryObject.addWhereCondition(sqlQueryObjectOr.createSQLConditions());
  1083.             }
  1084.            
  1085.             sqlQueryObject.addSelectField(CostantiDB.REGISTRO_PLUGINS_ARCHIVE + ".id");
  1086.             sqlQueryObject.addSelectField(CostantiDB.REGISTRO_PLUGINS_ARCHIVE + ".nome");            
  1087.             sqlQueryObject.addSelectField(CostantiDB.REGISTRO_PLUGINS_ARCHIVE + ".data");      
  1088.             sqlQueryObject.addSelectField(CostantiDB.REGISTRO_PLUGINS_ARCHIVE + ".sorgente");  
  1089.            
  1090.             if(!escludiContenuto) {
  1091.                 sqlQueryObject.addSelectField(CostantiDB.REGISTRO_PLUGINS_ARCHIVE + ".contenuto");    
  1092.             }
  1093.             sqlQueryObject.addSelectField(CostantiDB.REGISTRO_PLUGINS_ARCHIVE + ".url");        
  1094.             sqlQueryObject.addSelectField(CostantiDB.REGISTRO_PLUGINS_ARCHIVE + ".dir");
  1095.                        
  1096.             sqlQueryObject.addOrderBy(CostantiDB.REGISTRO_PLUGINS_ARCHIVE + ".data");
  1097.             sqlQueryObject.setSortType(true);
  1098.             sqlQueryObject.setLimit(limit);
  1099.             sqlQueryObject.setOffset(offset);
  1100.             queryString = sqlQueryObject.createSQLQuery();
  1101.             stmt = con.prepareStatement(queryString);
  1102.             parameterIndex = 1;
  1103.             stmt.setString(parameterIndex ++, nome);
  1104.             if (sqlQueryObjectOr!=null) {
  1105.                 stmt.setString(parameterIndex ++, DriverConfigurazioneDBLib.getValue(PluginSorgenteArchivio.JAR));
  1106.                 stmt.setString(parameterIndex ++, DriverConfigurazioneDBLib.getValue(PluginSorgenteArchivio.URL));
  1107.                 stmt.setString(parameterIndex ++, DriverConfigurazioneDBLib.getValue(PluginSorgenteArchivio.DIR));
  1108.             }
  1109.             risultato = stmt.executeQuery();

  1110.            
  1111.             while (risultato.next()) {
  1112.                 RegistroPluginArchivio archivio = new RegistroPluginArchivio();
  1113.                 archivio.setNome(risultato.getString("nome"));
  1114.                 archivio.setNomePlugin(nome);
  1115.                 Timestamp timestamp = risultato.getTimestamp("data");
  1116.                 archivio.setData(new Date(timestamp.getTime()));
  1117.                 IJDBCAdapter jdbcAdapter = JDBCAdapterFactory.createJDBCAdapter(this.driver.tipoDB);
  1118.                 archivio.setSorgente( DriverConfigurazioneDBLib.getEnumPluginSorgenteArchivio(risultato.getString("sorgente")));
  1119.                 switch (archivio.getSorgente()) {
  1120.                 case JAR:
  1121.                     if(!escludiContenuto) {
  1122.                         archivio.setContenuto(jdbcAdapter.getBinaryData(risultato, "contenuto"));
  1123.                     }
  1124.                     break;
  1125.                 case URL:
  1126.                     archivio.setUrl(risultato.getString("url"));
  1127.                     break;
  1128.                 case DIR:
  1129.                     archivio.setDir(risultato.getString("dir"));
  1130.                     break;
  1131.                 }
  1132.                 lista.add(archivio);
  1133.             }
  1134.             risultato.close();
  1135.             stmt.close();
  1136.            
  1137.             return lista;

  1138.         } catch (Exception qe) {
  1139.             throw new DriverConfigurazioneException("[DriverConfigurazioneDB::" + nomeMetodo + "] Errore : " + qe.getMessage(),qe);
  1140.         } finally {

  1141.             //Chiudo statement and resultset
  1142.             JDBCUtilities.closeResources(risultato, stmt);

  1143.             this.driver.closeConnection(con);
  1144.         }
  1145.     }
  1146. }