DriverRegistroServiziDB_gruppiDriver.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.registry.driver.db;

  21. import java.sql.Connection;
  22. import java.sql.Date;
  23. import java.sql.PreparedStatement;
  24. import java.sql.ResultSet;
  25. import java.sql.SQLException;
  26. import java.sql.Timestamp;
  27. import java.util.ArrayList;
  28. import java.util.List;

  29. import org.openspcoop2.core.commons.Filtri;
  30. import org.openspcoop2.core.commons.ISearch;
  31. import org.openspcoop2.core.commons.Liste;
  32. import org.openspcoop2.core.commons.SearchUtils;
  33. import org.openspcoop2.core.constants.CostantiDB;
  34. import org.openspcoop2.core.id.IDGruppo;
  35. import org.openspcoop2.core.registry.Gruppo;
  36. import org.openspcoop2.core.registry.constants.ServiceBinding;
  37. import org.openspcoop2.core.registry.driver.DriverRegistroServiziException;
  38. import org.openspcoop2.core.registry.driver.DriverRegistroServiziNotFound;
  39. import org.openspcoop2.core.registry.driver.FiltroRicercaGruppi;
  40. import org.openspcoop2.utils.jdbc.JDBCUtilities;
  41. import org.openspcoop2.utils.sql.ISQLQueryObject;
  42. import org.openspcoop2.utils.sql.SQLObjectFactory;

  43. /**
  44.  * DriverRegistroServiziDB_gruppiDriver
  45.  *
  46.  *
  47.  * @author Sandra Giangrandi (sandra@link.it)
  48.  * @author Stefano Corallo (corallo@link.it)
  49.  * @author $Author$
  50.  * @version $Rev$, $Date$
  51.  */
  52. public class DriverRegistroServiziDB_gruppiDriver {

  53.     private DriverRegistroServiziDB driver = null;
  54.    
  55.     protected DriverRegistroServiziDB_gruppiDriver(DriverRegistroServiziDB driver) {
  56.         this.driver = driver;
  57.     }
  58.    
  59.     protected Gruppo getGruppo(
  60.             IDGruppo idGruppo) throws DriverRegistroServiziException, DriverRegistroServiziNotFound{

  61.         this.driver.logDebug("richiesto getGruppo: " + idGruppo);
  62.         // conrollo consistenza
  63.         if (idGruppo == null)
  64.             throw new DriverRegistroServiziException("[getGruppo] Parametro idGruppo is null");
  65.         if (idGruppo.getNome()==null || idGruppo.getNome().trim().equals(""))
  66.             throw new DriverRegistroServiziException("[getGruppo] Parametro idGruppo.nome non e' definito");

  67.         Connection con = null;
  68.         PreparedStatement stm = null;
  69.         ResultSet rs = null;

  70.         if (this.driver.atomica) {
  71.             try {
  72.                 con = this.driver.getConnectionFromDatasource("getGruppo(nome)");

  73.             } catch (Exception e) {
  74.                 throw new DriverRegistroServiziException("DriverRegistroServiziDB::getGruppo] Exception accedendo al datasource :" + e.getMessage(),e);

  75.             }

  76.         } else
  77.             con = this.driver.globalConnection;

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

  79.         try {

  80.             ISQLQueryObject sqlQueryObject = SQLObjectFactory.createSQLQueryObject(this.driver.tipoDB);
  81.             sqlQueryObject.addFromTable(CostantiDB.GRUPPI);
  82.             sqlQueryObject.addSelectField("*");
  83.             sqlQueryObject.addWhereCondition("nome = ?");
  84.             String queryString = sqlQueryObject
  85.                     .createSQLQuery();
  86.             stm = con.prepareStatement(queryString);
  87.             stm.setString(1, idGruppo.getNome());
  88.             rs = stm.executeQuery();
  89.             Gruppo gruppo = null;
  90.             if (rs.next()) {
  91.                 gruppo = new Gruppo();
  92.                 gruppo.setId(rs.getLong("id"));
  93.                 gruppo.setNome(rs.getString("nome"));
  94.                 gruppo.setDescrizione(rs.getString("descrizione"));
  95.                 String serviceBinding = rs.getString("service_binding");
  96.                 if(serviceBinding!=null){
  97.                     gruppo.setServiceBinding(ServiceBinding.toEnumConstant(serviceBinding));
  98.                 }
  99.                 gruppo.setSuperUser(rs.getString("superuser"));

  100.                 // Ora Registrazione
  101.                 if(rs.getTimestamp("ora_registrazione")!=null){
  102.                     gruppo.setOraRegistrazione(new Date(rs.getTimestamp("ora_registrazione").getTime()));
  103.                 }

  104.                 // Proprieta Oggetto
  105.                 gruppo.setProprietaOggetto(DriverRegistroServiziDB_utilsDriver.readProprietaOggetto(rs,false));
  106.                
  107.             } else {
  108.                 throw new DriverRegistroServiziNotFound("[DriverRegistroServiziDB::getGruppo] rs.next non ha restituito valori con la seguente interrogazione :\n" +
  109.                         DriverRegistroServiziDB_LIB.formatSQLString(queryString, idGruppo.getNome()));
  110.             }

  111.             return gruppo;

  112.         }catch (DriverRegistroServiziNotFound e) {
  113.             throw e;
  114.         } catch (SQLException se) {

  115.             throw new DriverRegistroServiziException("[DriverRegistroServiziDB::getGruppo] SqlException: " + se.getMessage(),se);
  116.         }catch (Exception se) {

  117.             throw new DriverRegistroServiziException("[DriverRegistroServiziDB::getGruppo] Exception: " + se.getMessage(),se);
  118.         } finally {
  119.             JDBCUtilities.closeResources(rs, stm);
  120.             this.driver.closeConnection(con);
  121.         }
  122.     }

  123.     protected Gruppo getGruppo(
  124.             long idGruppo) throws DriverRegistroServiziException, DriverRegistroServiziNotFound{

  125.         this.driver.logDebug("richiesto getGruppo: " + idGruppo);
  126.         // conrollo consistenza
  127.         if (idGruppo <=0)
  128.             throw new DriverRegistroServiziException("[getGruppo] Parametro idGruppo non valido");

  129.         Connection con = null;
  130.         PreparedStatement stm = null;
  131.         ResultSet rs = null;

  132.         if (this.driver.atomica) {
  133.             try {
  134.                 con = this.driver.getConnectionFromDatasource("getGruppo(id)");

  135.             } catch (Exception e) {
  136.                 throw new DriverRegistroServiziException("DriverRegistroServiziDB::getGruppo] Exception accedendo al datasource :" + e.getMessage(),e);

  137.             }

  138.         } else
  139.             con = this.driver.globalConnection;

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

  141.         IDGruppo idGruppoObject = null;
  142.         try {

  143.             ISQLQueryObject sqlQueryObject = SQLObjectFactory.createSQLQueryObject(this.driver.tipoDB);
  144.             sqlQueryObject.addFromTable(CostantiDB.GRUPPI);
  145.             sqlQueryObject.addSelectField("nome");
  146.             sqlQueryObject.addWhereCondition("id = ?");
  147.             String queryString = sqlQueryObject.createSQLQuery();
  148.             stm = con.prepareStatement(queryString);
  149.             stm.setLong(1, idGruppo);
  150.             rs = stm.executeQuery();
  151.             if (rs.next()) {
  152.                 idGruppoObject = new IDGruppo(rs.getString("nome"));
  153.             } else {
  154.                 throw new DriverRegistroServiziNotFound("[DriverRegistroServiziDB::getGruppo] rs.next non ha restituito valori con la seguente interrogazione :\n" +
  155.                         DriverRegistroServiziDB_LIB.formatSQLString(queryString, idGruppo));
  156.             }

  157.         }catch (DriverRegistroServiziNotFound e) {
  158.             throw e;
  159.         } catch (SQLException se) {

  160.             throw new DriverRegistroServiziException("[DriverRegistroServiziDB::getGruppo] SqlException: " + se.getMessage(),se);
  161.         }catch (Exception se) {

  162.             throw new DriverRegistroServiziException("[DriverRegistroServiziDB::getGruppo] Exception: " + se.getMessage(),se);
  163.         } finally {
  164.             JDBCUtilities.closeResources(rs, stm);
  165.             this.driver.closeConnection(con);
  166.         }
  167.        
  168.         return this.getGruppo(idGruppoObject);
  169.     }

  170.     protected List<IDGruppo> getAllIdGruppi(
  171.             FiltroRicercaGruppi filtroRicerca) throws DriverRegistroServiziException, DriverRegistroServiziNotFound{

  172.         Connection con = null;
  173.         PreparedStatement stm = null;
  174.         ResultSet rs = null;

  175.         boolean filtroRicercaTipo = false;
  176.         if(filtroRicerca!=null){
  177.             filtroRicercaTipo = filtroRicerca.getServiceBinding()!=null;
  178.         }
  179.        
  180.         List<String> tipoSoggettiProtocollo = null;
  181.         try {
  182.             if(filtroRicerca!=null && (filtroRicerca.getProtocollo()!=null || (filtroRicerca.getProtocolli()!=null && !filtroRicerca.getProtocolli().isEmpty()))){
  183.                 tipoSoggettiProtocollo = Filtri.convertToTipiSoggetti(filtroRicerca.getProtocollo(), Filtri.convertToString(filtroRicerca.getProtocolli()));
  184.             }
  185.         }catch(Exception e) {
  186.             throw new DriverRegistroServiziException(e.getMessage(),e);
  187.         }
  188.         boolean searchByTipoSoggetto = (tipoSoggettiProtocollo!=null && !tipoSoggettiProtocollo.isEmpty());
  189.        
  190.         this.driver.logDebug("getAllIdGruppi...");

  191.         try {
  192.             this.driver.logDebug("operazione atomica = " + this.driver.atomica);
  193.             // prendo la connessione dal pool
  194.             if (this.driver.atomica)
  195.                 con = this.driver.getConnectionFromDatasource("getAllIdGruppi");
  196.             else
  197.                 con = this.driver.globalConnection;

  198.             ISQLQueryObject sqlQueryObject = SQLObjectFactory.createSQLQueryObject(this.driver.tipoDB);
  199.             sqlQueryObject.addFromTable(CostantiDB.GRUPPI);
  200.             if(searchByTipoSoggetto) {
  201.                 sqlQueryObject.addFromTable(CostantiDB.ACCORDI_GRUPPI);
  202.                 sqlQueryObject.addFromTable(CostantiDB.ACCORDI);
  203.                 sqlQueryObject.addFromTable(CostantiDB.SOGGETTI);
  204.             }
  205.             sqlQueryObject.addSelectField(CostantiDB.GRUPPI, "nome");
  206.             if(searchByTipoSoggetto) {
  207.                 sqlQueryObject.setSelectDistinct(true);
  208.             }
  209.             if(filtroRicerca!=null){
  210.                 // Filtro By Data
  211.                 if(filtroRicerca.getMinDate()!=null)
  212.                     sqlQueryObject.addWhereCondition(CostantiDB.GRUPPI+".ora_registrazione > ?");
  213.                 if(filtroRicerca.getMaxDate()!=null)
  214.                     sqlQueryObject.addWhereCondition(CostantiDB.GRUPPI+".ora_registrazione < ?");
  215.                 if(filtroRicerca.getNome()!=null)
  216.                     sqlQueryObject.addWhereCondition(CostantiDB.GRUPPI+".nome = ?");
  217.                 if(filtroRicercaTipo){
  218.                    
  219.                     ISQLQueryObject sqlQueryObjectServiceBinding = SQLObjectFactory.createSQLQueryObject(this.driver.tipoDB);
  220.                     sqlQueryObjectServiceBinding.addWhereIsNullCondition(CostantiDB.GRUPPI+".service_binding");
  221.                     sqlQueryObjectServiceBinding.addWhereCondition(CostantiDB.GRUPPI+".service_binding= ?");
  222.                     sqlQueryObjectServiceBinding.setANDLogicOperator(false);
  223.                     sqlQueryObject.addWhereCondition(sqlQueryObjectServiceBinding.createSQLConditions());
  224.                    
  225.                 }
  226.                 if(searchByTipoSoggetto) {
  227.                     sqlQueryObject.addWhereCondition(CostantiDB.ACCORDI_GRUPPI+".id_gruppo="+CostantiDB.GRUPPI+".id");
  228.                     sqlQueryObject.addWhereCondition(CostantiDB.ACCORDI_GRUPPI+".id_accordo="+CostantiDB.ACCORDI+".id");
  229.                     sqlQueryObject.addWhereCondition(CostantiDB.ACCORDI+".id_referente="+CostantiDB.SOGGETTI+".id");
  230.                     sqlQueryObject.addWhereINCondition(CostantiDB.SOGGETTI+".tipo_soggetto", true, tipoSoggettiProtocollo.toArray(new String[1]));
  231.                 }
  232.                
  233.                 if(filtroRicerca.isOrdinaDataRegistrazione())
  234.                     sqlQueryObject.addOrderBy(CostantiDB.GRUPPI+".ora_registrazione");
  235.                
  236.                 sqlQueryObject.addOrderBy(CostantiDB.GRUPPI+".nome");
  237.             }

  238.             sqlQueryObject.setANDLogicOperator(true);
  239.             String sqlQuery = sqlQueryObject.createSQLQuery();
  240.             this.driver.logDebug("eseguo query : " + sqlQuery );
  241.             stm = con.prepareStatement(sqlQuery);
  242.             int indexStmt = 1;
  243.             if(filtroRicerca!=null){
  244.                 if(filtroRicerca.getMinDate()!=null){
  245.                     this.driver.logDebug("minDate stmt.setTimestamp("+filtroRicerca.getMinDate()+")");
  246.                     stm.setTimestamp(indexStmt, new Timestamp(filtroRicerca.getMinDate().getTime()));
  247.                     indexStmt++;
  248.                 }
  249.                 if(filtroRicerca.getMaxDate()!=null){
  250.                     this.driver.logDebug("maxDate stmt.setTimestamp("+filtroRicerca.getMaxDate()+")");
  251.                     stm.setTimestamp(indexStmt, new Timestamp(filtroRicerca.getMaxDate().getTime()));
  252.                     indexStmt++;
  253.                 }  
  254.                 if(filtroRicerca.getNome()!=null){
  255.                     this.driver.logDebug("nome stmt.setString("+filtroRicerca.getNome()+")");
  256.                     stm.setString(indexStmt, filtroRicerca.getNome());
  257.                     indexStmt++;
  258.                 }  
  259.                 if(filtroRicercaTipo){
  260.                     this.driver.logDebug("serviceBinding stmt.setString("+filtroRicerca.getServiceBinding().getValue()+")");
  261.                     stm.setString(indexStmt, filtroRicerca.getServiceBinding().getValue());
  262.                     indexStmt++;
  263.                 }
  264.             }
  265.             rs = stm.executeQuery();
  266.             List<IDGruppo> nomiGruppi = new ArrayList<>();
  267.             while (rs.next()) {
  268.                 nomiGruppi.add(new IDGruppo(rs.getString("nome")));
  269.             }
  270.             if(nomiGruppi.isEmpty()){
  271.                 if(filtroRicerca!=null)
  272.                     throw new DriverRegistroServiziNotFound("Gruppi non trovati che rispettano il filtro di ricerca selezionato: "+filtroRicerca.toString());
  273.                 else
  274.                     throw new DriverRegistroServiziNotFound("Gruppi non trovati");
  275.             }else{
  276.                 return nomiGruppi;
  277.             }
  278.         }catch(DriverRegistroServiziNotFound de){
  279.             throw de;
  280.         }
  281.         catch(Exception e){
  282.             throw new DriverRegistroServiziException("getAllIdGruppi error",e);
  283.         } finally {

  284.             //Chiudo statement and resultset
  285.             JDBCUtilities.closeResources(rs, stm);
  286.             this.driver.closeConnection(con);

  287.         }
  288.     }



  289.     protected void createGruppo(Gruppo gruppo) throws DriverRegistroServiziException{
  290.         if (gruppo == null)
  291.             throw new DriverRegistroServiziException("[DriverRegistroServiziDB::createGruppo] Parametro non valido.");

  292.         Connection con = null;
  293.         boolean error = false;

  294.         if (this.driver.atomica) {
  295.             try {
  296.                 con = this.driver.getConnectionFromDatasource("createGruppo");
  297.                 con.setAutoCommit(false);
  298.             } catch (Exception e) {
  299.                 throw new DriverRegistroServiziException("[DriverRegistroServiziDB::createGruppo] Exception accedendo al datasource :" + e.getMessage(),e);

  300.             }

  301.         } else
  302.             con = this.driver.globalConnection;

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

  304.         try {
  305.             this.driver.logDebug("CRUDGruppo type = 1");
  306.             DriverRegistroServiziDB_LIB.CRUDGruppo(CostantiDB.CREATE, gruppo, con);

  307.         } catch (Exception qe) {
  308.             error = true;
  309.             throw new DriverRegistroServiziException("[DriverRegistroServiziDB::createGruppo] Errore durante la creazione del gruppo : " + qe.getMessage(), qe);
  310.         } finally {

  311.             this.driver.closeConnection(error,con);
  312.         }
  313.     }

  314.     protected boolean existsGruppo(IDGruppo idGruppo) throws DriverRegistroServiziException{
  315.         boolean exist = false;
  316.         Connection con = null;
  317.         PreparedStatement stm = null;
  318.         ResultSet rs = null;

  319.         if (idGruppo == null)
  320.             throw new DriverRegistroServiziException("Parametro non valido");

  321.         if (idGruppo.getNome()==null || idGruppo.getNome().equals(""))
  322.             throw new DriverRegistroServiziException("Parametro vuoto non valido");

  323.         if (this.driver.atomica) {
  324.             try {
  325.                 con = this.driver.getConnectionFromDatasource("existsGruppo");
  326.             } catch (Exception e) {
  327.                 throw new DriverRegistroServiziException("[DriverRegistroServiziDB::existsGruppo] Exception accedendo al datasource :" + e.getMessage(),e);

  328.             }

  329.         } else
  330.             con = this.driver.globalConnection;

  331.         try {
  332.             ISQLQueryObject sqlQueryObject = SQLObjectFactory.createSQLQueryObject(this.driver.tipoDB);
  333.             sqlQueryObject.addFromTable(CostantiDB.GRUPPI);
  334.             sqlQueryObject.addSelectField("*");
  335.             sqlQueryObject.addWhereCondition("nome = ?");
  336.             sqlQueryObject.setANDLogicOperator(true);
  337.             String sqlQuery = sqlQueryObject.createSQLQuery();
  338.             stm = con.prepareStatement(sqlQuery);
  339.             stm.setString(1, idGruppo.getNome());
  340.             rs = stm.executeQuery();
  341.             if (rs.next())
  342.                 exist = true;
  343.             rs.close();
  344.             stm.close();

  345.         } catch (Exception e) {
  346.             exist = false;
  347.             this.driver.log.error("Errore durante verifica esistenza gruppo: "+e.getMessage(), e);
  348.         } finally {

  349.             //Chiudo statement and resultset
  350.             JDBCUtilities.closeResources(rs, stm);

  351.             this.driver.closeConnection(con);
  352.         }

  353.         return exist;
  354.     }

  355.     protected void updateGruppo(Gruppo gruppo) throws DriverRegistroServiziException{
  356.         if (gruppo == null)
  357.             throw new DriverRegistroServiziException("[DriverRegistroServiziDB::updateGruppo] Parametro non valido.");

  358.         Connection con = null;
  359.         boolean error = false;

  360.         if (this.driver.atomica) {
  361.             try {
  362.                 con = this.driver.getConnectionFromDatasource("updateGruppo");
  363.                 con.setAutoCommit(false);
  364.             } catch (Exception e) {
  365.                 throw new DriverRegistroServiziException("[DriverRegistroServiziDB::updateGruppo] Exception accedendo al datasource :" + e.getMessage(),e);

  366.             }

  367.         } else
  368.             con = this.driver.globalConnection;

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

  370.         try {

  371.             this.driver.logDebug("CRUDGruppo type = 2");
  372.             DriverRegistroServiziDB_LIB.CRUDGruppo(CostantiDB.UPDATE, gruppo, con);

  373.         } catch (Exception qe) {
  374.             error = true;
  375.             throw new DriverRegistroServiziException("[DriverRegistroServiziDB::updateGruppo] Errore durante l'aggiornamento del gruppo : " + qe.getMessage(),qe);
  376.         } finally {

  377.             this.driver.closeConnection(error,con);
  378.         }
  379.     }  

  380.     protected void deleteGruppo(Gruppo gruppo) throws DriverRegistroServiziException{
  381.         if (gruppo == null)
  382.             throw new DriverRegistroServiziException("[DriverRegistroServiziDB::deleteGruppo] Parametro non valido.");

  383.         Connection con = null;
  384.         boolean error = false;

  385.         if (this.driver.atomica) {
  386.             try {
  387.                 con = this.driver.getConnectionFromDatasource("deleteGruppo");
  388.                 con.setAutoCommit(false);
  389.             } catch (Exception e) {
  390.                 throw new DriverRegistroServiziException("[DriverRegistroServiziDB::deleteGruppo] Exception accedendo al datasource :" + e.getMessage(),e);

  391.             }

  392.         } else
  393.             con = this.driver.globalConnection;

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

  395.         try {
  396.             this.driver.logDebug("CRUDGruppo type = 3");
  397.             DriverRegistroServiziDB_LIB.CRUDGruppo(CostantiDB.DELETE, gruppo, con);

  398.         } catch (Exception qe) {
  399.             error = true;
  400.             throw new DriverRegistroServiziException("[DriverRegistroServiziDB::deleteGruppo] Errore durante l'eliminazione del gruppo : " + qe.getMessage(),qe);
  401.         } finally {

  402.             this.driver.closeConnection(error,con);
  403.         }
  404.     }
  405.    
  406.    
  407.     protected List<Gruppo> gruppiList(String superuser, ISearch ricerca) throws DriverRegistroServiziException {
  408.         String nomeMetodo = "gruppiList";
  409.         int idLista = Liste.GRUPPI;
  410.         int offset;
  411.         int limit;
  412.         String search;
  413.         String queryString;

  414.         limit = ricerca.getPageSize(idLista);
  415.         offset = ricerca.getIndexIniziale(idLista);
  416.         search = (org.openspcoop2.core.constants.Costanti.SESSION_ATTRIBUTE_VALUE_RICERCA_UNDEFINED.equals(ricerca.getSearchString(idLista)) ? "" : ricerca.getSearchString(idLista));

  417.         String filterServiceBinding = SearchUtils.getFilter(ricerca, idLista, Filtri.FILTRO_SERVICE_BINDING);
  418.         ServiceBinding serviceBinding = null;
  419.         if(filterServiceBinding!=null) {
  420.             serviceBinding = ServiceBinding.toEnumConstant(filterServiceBinding);
  421.         }
  422.                
  423.         Connection con = null;
  424.         PreparedStatement stmt = null;
  425.         ResultSet risultato = null;
  426.         ArrayList<Gruppo> lista = new ArrayList<>();

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

  432.             }

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

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

  436.         List<IDGruppo> listIdGruppi = null;
  437.         try {

  438.             ISQLQueryObject sqlQueryObjectServiceBinding = null;
  439.             if(serviceBinding!=null) {
  440.                 sqlQueryObjectServiceBinding = SQLObjectFactory.createSQLQueryObject(this.driver.tipoDB);
  441.                 sqlQueryObjectServiceBinding.addWhereIsNullCondition("service_binding");
  442.                 sqlQueryObjectServiceBinding.addWhereCondition("service_binding= ?");
  443.                 sqlQueryObjectServiceBinding.setANDLogicOperator(false);
  444.             }
  445.            
  446.             if (!search.equals("")) {
  447.                 //query con search
  448.                 ISQLQueryObject sqlQueryObject = SQLObjectFactory.createSQLQueryObject(this.driver.tipoDB);
  449.                 sqlQueryObject.addFromTable(CostantiDB.GRUPPI);
  450.                 sqlQueryObject.addSelectCountField("*", "cont");
  451.                 if(this.driver.useSuperUser && superuser!=null && (!superuser.equals("")))
  452.                     sqlQueryObject.addWhereCondition("superuser = ?");
  453.                 sqlQueryObject.addWhereLikeCondition("nome", search, true, true);  
  454.                 if(serviceBinding!=null) {
  455.                     sqlQueryObject.addWhereCondition(sqlQueryObjectServiceBinding.createSQLConditions());
  456.                 }
  457.                 sqlQueryObject.setANDLogicOperator(true);
  458.                 queryString = sqlQueryObject.createSQLQuery();
  459.             } else {
  460.                 ISQLQueryObject sqlQueryObject = SQLObjectFactory.createSQLQueryObject(this.driver.tipoDB);
  461.                 sqlQueryObject.addFromTable(CostantiDB.GRUPPI);
  462.                 sqlQueryObject.addSelectCountField("*", "cont");
  463.                 if(this.driver.useSuperUser && superuser!=null && (!superuser.equals("")))
  464.                     sqlQueryObject.addWhereCondition("superuser = ?");
  465.                 if(serviceBinding!=null) {
  466.                     sqlQueryObject.addWhereCondition(sqlQueryObjectServiceBinding.createSQLConditions());
  467.                 }
  468.                 sqlQueryObject.setANDLogicOperator(true);
  469.                 queryString = sqlQueryObject.createSQLQuery();
  470.             }
  471.             stmt = con.prepareStatement(queryString);
  472.             int index = 1;
  473.             if(this.driver.useSuperUser && superuser!=null && (!superuser.equals(""))){
  474.                 stmt.setString(index++, superuser);
  475.             }
  476.             if(serviceBinding!=null) {
  477.                 stmt.setString(index++, serviceBinding.getValue());
  478.             }

  479.             risultato = stmt.executeQuery();
  480.             if (risultato.next())
  481.                 ricerca.setNumEntries(idLista,risultato.getInt(1));
  482.             risultato.close();
  483.             stmt.close();

  484.             // ricavo le entries
  485.             if (limit == 0) // con limit
  486.                 limit = ISQLQueryObject.LIMIT_DEFAULT_VALUE;
  487.             if (!search.equals("")) { // con search
  488.                 ISQLQueryObject sqlQueryObject = SQLObjectFactory.createSQLQueryObject(this.driver.tipoDB);
  489.                 sqlQueryObject.addFromTable(CostantiDB.GRUPPI);
  490.                 sqlQueryObject.addSelectField("nome");
  491.                 if(this.driver.useSuperUser && superuser!=null && (!superuser.equals("")))
  492.                     sqlQueryObject.addWhereCondition("superuser = ?");
  493.                 sqlQueryObject.addWhereLikeCondition("nome", search, true, true);
  494.                 if(serviceBinding!=null) {
  495.                     sqlQueryObject.addWhereCondition(sqlQueryObjectServiceBinding.createSQLConditions());
  496.                 }
  497.                 sqlQueryObject.setANDLogicOperator(true);
  498.                 sqlQueryObject.addOrderBy("nome");
  499.                 sqlQueryObject.setSortType(true);
  500.                 sqlQueryObject.setLimit(limit);
  501.                 sqlQueryObject.setOffset(offset);
  502.                 queryString = sqlQueryObject.createSQLQuery();
  503.             } else {
  504.                 // senza search
  505.                 ISQLQueryObject sqlQueryObject = SQLObjectFactory.createSQLQueryObject(this.driver.tipoDB);
  506.                 sqlQueryObject.addFromTable(CostantiDB.GRUPPI);
  507.                 sqlQueryObject.addSelectField("nome");
  508.                 if(this.driver.useSuperUser && superuser!=null && (!superuser.equals("")))
  509.                     sqlQueryObject.addWhereCondition("superuser = ?");
  510.                 if(serviceBinding!=null) {
  511.                     sqlQueryObject.addWhereCondition(sqlQueryObjectServiceBinding.createSQLConditions());
  512.                 }
  513.                 sqlQueryObject.setANDLogicOperator(true);
  514.                 sqlQueryObject.addOrderBy("nome");
  515.                 sqlQueryObject.setSortType(true);
  516.                 sqlQueryObject.setLimit(limit);
  517.                 sqlQueryObject.setOffset(offset);
  518.                 queryString = sqlQueryObject.createSQLQuery();
  519.             }
  520.             stmt = con.prepareStatement(queryString);
  521.             index = 1;
  522.             if(this.driver.useSuperUser && superuser!=null && (!superuser.equals(""))){
  523.                 stmt.setString(index++, superuser);
  524.             }
  525.             if(serviceBinding!=null) {
  526.                 stmt.setString(index++, serviceBinding.getValue());
  527.             }
  528.             risultato = stmt.executeQuery();

  529.             listIdGruppi = new ArrayList<>();
  530.             while (risultato.next()) {

  531.                 listIdGruppi.add(new IDGruppo(risultato.getString("nome")));

  532.             }

  533.         } catch (Exception qe) {
  534.             throw new DriverRegistroServiziException("[DriverRegistroServiziDB::" + nomeMetodo + "] Errore : " + qe.getMessage(),qe);
  535.         } finally {

  536.             //Chiudo statement and resultset
  537.             JDBCUtilities.closeResources(risultato, stmt);

  538.             this.driver.closeConnection(con);
  539.         }
  540.        
  541.        
  542.         if(listIdGruppi!=null){
  543.             for (IDGruppo idGruppo : listIdGruppi) {
  544.                 try{
  545.                     lista.add(this.getGruppo(idGruppo));
  546.                 }catch(DriverRegistroServiziNotFound notFound){
  547.                     // non può capitare
  548.                     throw new DriverRegistroServiziException(notFound.getMessage(),notFound);
  549.                 }
  550.             }
  551.         }
  552.        
  553.         return lista;
  554.     }
  555. }