DriverConfigurazioneDB_gestioneErroreLIB.java

  1. /*
  2.  * GovWay - A customizable API Gateway
  3.  * https://govway.org
  4.  *
  5.  * Copyright (c) 2005-2025 Link.it srl (https://link.it).
  6.  *
  7.  * This program is free software: you can redistribute it and/or modify
  8.  * it under the terms of the GNU General Public License version 3, as published by
  9.  * the Free Software Foundation.
  10.  *
  11.  * This program is distributed in the hope that it will be useful,
  12.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14.  * GNU General Public License for more details.
  15.  *
  16.  * You should have received a copy of the GNU General Public License
  17.  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  18.  *
  19.  */
  20. package org.openspcoop2.core.config.driver.db;

  21. import static org.openspcoop2.core.constants.CostantiDB.CREATE;
  22. import static org.openspcoop2.core.constants.CostantiDB.DELETE;
  23. import static org.openspcoop2.core.constants.CostantiDB.UPDATE;

  24. import java.sql.Connection;
  25. import java.sql.PreparedStatement;
  26. import java.sql.ResultSet;
  27. import java.sql.SQLException;

  28. import org.openspcoop2.core.commons.DBUtils;
  29. import org.openspcoop2.core.config.GestioneErrore;
  30. import org.openspcoop2.core.config.GestioneErroreCodiceTrasporto;
  31. import org.openspcoop2.core.config.GestioneErroreSoapFault;
  32. import org.openspcoop2.core.config.constants.GestioneErroreComportamento;
  33. import org.openspcoop2.core.config.driver.DriverConfigurazioneException;
  34. import org.openspcoop2.core.config.driver.DriverConfigurazioneNotFound;
  35. import org.openspcoop2.core.constants.CostantiDB;
  36. import org.openspcoop2.utils.jdbc.JDBCUtilities;
  37. import org.openspcoop2.utils.sql.ISQLQueryObject;
  38. import org.openspcoop2.utils.sql.SQLObjectFactory;

  39. /**
  40.  * DriverConfigurazioneDB_gestioneErroreLIB
  41.  *
  42.  * @author Stefano Corallo - corallo@link.it
  43.  * @author $Author$
  44.  * @version $Rev$, $Date$
  45.  */
  46. public class DriverConfigurazioneDB_gestioneErroreLIB {


  47.    
  48.     public static GestioneErrore getGestioneErrore(long idGestioneErrore,Connection con) throws DriverConfigurazioneException,DriverConfigurazioneNotFound{
  49.        
  50.         GestioneErrore gestioneErrore = null;
  51.        
  52.         PreparedStatement stm = null;
  53.         ResultSet rs = null;
  54.         PreparedStatement stm1 = null;
  55.         ResultSet rs1 = null;
  56.        
  57.         try {
  58.             ISQLQueryObject sqlQueryObject = SQLObjectFactory.createSQLQueryObject(DriverConfigurazioneDBLib.tipoDB);
  59.            
  60.             // Get gestione errore generale
  61.             sqlQueryObject.addFromTable(CostantiDB.GESTIONE_ERRORE);
  62.             sqlQueryObject.addSelectField("comportamento_default");
  63.             sqlQueryObject.addSelectField("cadenza_rispedizione");
  64.             sqlQueryObject.addSelectField("nome");
  65.             sqlQueryObject.addWhereCondition("id=?");
  66.             String sqlQuery = sqlQueryObject.createSQLQuery();

  67.             DriverConfigurazioneDBLib.log.debug("eseguo query: " + DBUtils.formatSQLString(sqlQuery));
  68.             stm = con.prepareStatement(sqlQuery);
  69.             stm.setLong(1, idGestioneErrore);
  70.             rs = stm.executeQuery();

  71.             if (rs.next()) {
  72.                 gestioneErrore = new GestioneErrore();
  73.                 gestioneErrore.setId(idGestioneErrore);
  74.                 gestioneErrore.setComportamento(GestioneErroreComportamento.toEnumConstant(rs.getString("comportamento_default")));
  75.                 gestioneErrore.setCadenzaRispedizione(rs.getString("cadenza_rispedizione"));
  76.                 gestioneErrore.setNome(rs.getString("nome"));

  77.                 //trasporto
  78.                 sqlQueryObject = SQLObjectFactory.createSQLQueryObject(DriverConfigurazioneDBLib.tipoDB);
  79.                 sqlQueryObject.addFromTable(CostantiDB.GESTIONE_ERRORE_TRASPORTO);
  80.                 sqlQueryObject.addSelectField("*");
  81.                 sqlQueryObject.addWhereCondition("id_gestione_errore = ?");
  82.                 sqlQuery = sqlQueryObject.createSQLQuery();
  83.                 stm1 = con.prepareStatement(sqlQuery);
  84.                 stm1.setLong(1, gestioneErrore.getId());
  85.                 rs1 = stm1.executeQuery();
  86.                 while(rs1.next())
  87.                 {
  88.                     GestioneErroreCodiceTrasporto trasporto = new GestioneErroreCodiceTrasporto();
  89.                     trasporto.setComportamento(GestioneErroreComportamento.toEnumConstant(rs1.getString("comportamento")));
  90.                     trasporto.setCadenzaRispedizione(rs1.getString("cadenza_rispedizione"));
  91.                     if(rs1.getLong("valore_massimo")>0){
  92.                         String maxVal = ""+rs1.getLong("valore_massimo");
  93.                         trasporto.setValoreMassimo(!maxVal.equals("") ? Integer.valueOf(maxVal) : null);
  94.                     }
  95.                     if(rs1.getLong("valore_minimo")>0){
  96.                         String minVal = ""+rs1.getLong("valore_minimo");
  97.                         trasporto.setValoreMinimo(!minVal.equals("") ? Integer.valueOf(minVal) : null);
  98.                     }
  99.                     gestioneErrore.addCodiceTrasporto(trasporto);
  100.                 }
  101.                 rs1.close();
  102.                 stm1.close();

  103.                 //soap
  104.                 sqlQueryObject = SQLObjectFactory.createSQLQueryObject(DriverConfigurazioneDBLib.tipoDB);
  105.                 sqlQueryObject.addFromTable(CostantiDB.GESTIONE_ERRORE_SOAP);
  106.                 sqlQueryObject.addSelectField("*");
  107.                 sqlQueryObject.addWhereCondition("id_gestione_errore = ?");
  108.                 sqlQuery = sqlQueryObject.createSQLQuery();
  109.                 stm1 = con.prepareStatement(sqlQuery);
  110.                 stm1.setLong(1, gestioneErrore.getId());
  111.                 rs1 = stm1.executeQuery();
  112.                 while(rs1.next())
  113.                 {
  114.                     GestioneErroreSoapFault soap = new GestioneErroreSoapFault();
  115.                     soap.setComportamento(GestioneErroreComportamento.toEnumConstant(rs1.getString("comportamento")));
  116.                     soap.setCadenzaRispedizione(rs1.getString("cadenza_rispedizione"));
  117.                     soap.setFaultActor(rs1.getString("fault_actor"));
  118.                     soap.setFaultCode(rs1.getString("fault_code"));
  119.                     soap.setFaultString(rs1.getString("fault_string"));
  120.                     gestioneErrore.addSoapFault(soap);
  121.                 }
  122.                 rs1.close();
  123.                 stm1.close();

  124.             } else {
  125.                 throw new DriverConfigurazioneNotFound("Gestione errore con id["+idGestioneErrore+"] non presente");
  126.             }
  127.             rs.close();
  128.             stm.close();

  129.             return gestioneErrore;

  130.         } catch (SQLException se) {
  131.             throw new DriverConfigurazioneException(" SqlException: " + se.getMessage(),se);
  132.         }catch (DriverConfigurazioneNotFound e) {
  133.             throw new DriverConfigurazioneNotFound(e);
  134.         }catch (Exception se) {
  135.             throw new DriverConfigurazioneException(" Exception: " + se.getMessage(),se);
  136.         } finally {
  137.             //Chiudo statement and resultset
  138.             JDBCUtilities.closeResources(rs1, stm1);
  139.             JDBCUtilities.closeResources(rs, stm);
  140.         }
  141.     }
  142.    
  143.     public static long getIdGestioneErrore(String nomeGestioneErrore,Connection con) throws DriverConfigurazioneException
  144.     {
  145.         PreparedStatement stm = null;
  146.         ResultSet rs = null;
  147.         long idGestioneErrore=-1;
  148.         try
  149.         {
  150.             ISQLQueryObject sqlQueryObject = SQLObjectFactory.createSQLQueryObject(DriverConfigurazioneDBLib.tipoDB);
  151.             sqlQueryObject.addFromTable(CostantiDB.GESTIONE_ERRORE);
  152.             sqlQueryObject.addSelectField("id");
  153.             sqlQueryObject.addWhereCondition("nome = ?");
  154.             String query = sqlQueryObject.createSQLQuery();
  155.             stm=con.prepareStatement(query);
  156.             stm.setString(1, nomeGestioneErrore);
  157.             rs=stm.executeQuery();

  158.             if(rs.next()){
  159.                 idGestioneErrore = rs.getLong("id");
  160.             }

  161.             return idGestioneErrore;

  162.         }catch (SQLException e) {
  163.             throw new DriverConfigurazioneException(e);
  164.         }catch (Exception e) {
  165.             throw new DriverConfigurazioneException(e);
  166.         }finally
  167.         {
  168.             //Chiudo statement and resultset
  169.             JDBCUtilities.closeResources(rs, stm);

  170.         }
  171.     }
  172.    
  173.    
  174.    
  175.     public static long CRUDGestioneErroreServizioApplicativo(int type, org.openspcoop2.core.config.GestioneErrore gestioneErrore,
  176.             long idSoggettoProprietario,long idServizioApplicativo,boolean invocazioneServizio,
  177.             Connection con)throws DriverConfigurazioneException{
  178.         if(invocazioneServizio)
  179.             return CRUDGestioneErrore(type, gestioneErrore, idSoggettoProprietario, idServizioApplicativo,1,con);
  180.         else
  181.             return CRUDGestioneErrore(type, gestioneErrore, idSoggettoProprietario, idServizioApplicativo,2,con);
  182.     }
  183.     public static long CRUDGestioneErroreComponenteCooperazione(int type, org.openspcoop2.core.config.GestioneErrore gestioneErrore,
  184.             Connection con) throws DriverConfigurazioneException{
  185.         return CRUDGestioneErrore(type, gestioneErrore, -1,-1,3,con) ;
  186.     }
  187.     public static long CRUDGestioneErroreComponenteIntegrazione(int type, org.openspcoop2.core.config.GestioneErrore gestioneErrore,
  188.             Connection con) throws DriverConfigurazioneException{
  189.         return CRUDGestioneErrore(type, gestioneErrore,-1,-1,4,con) ;
  190.     }
  191.    
  192.     private static long CRUDGestioneErrore(int type, org.openspcoop2.core.config.GestioneErrore gestioneErrore,
  193.             long idSoggettoProprietario,long idServizioApplicativo,
  194.             int tipoCRUD,Connection con) throws DriverConfigurazioneException {

  195.         if (gestioneErrore == null)
  196.             throw new DriverConfigurazioneException("[DriverConfigurazioneDB_LIB::CRUDGestioneErrore] Parametro non valido.");
  197.        
  198.         String nomeGestioneErrore = null; // Costruito obbligatoriamente dal driver
  199.         if(tipoCRUD==1 || tipoCRUD==2){
  200.             // crud servizioApplicativo invocazioneServizio(1) o rispostaAsincrona(2)
  201.             if(idSoggettoProprietario<=0){
  202.                 throw new DriverConfigurazioneException("[DriverConfigurazioneDB_LIB::CRUDGestioneErrore] Soggetto proprietario non fornito.");
  203.             }
  204.             if(idServizioApplicativo<=0){
  205.                 throw new DriverConfigurazioneException("[DriverConfigurazioneDB_LIB::CRUDGestioneErrore] Servizio applicativo non fornito.");
  206.             }
  207.             nomeGestioneErrore = "Soggetto("+idSoggettoProprietario+")_SA("+idServizioApplicativo+")_";
  208.             if(tipoCRUD==1)
  209.                 nomeGestioneErrore = nomeGestioneErrore + "INV";
  210.             else
  211.                 nomeGestioneErrore = nomeGestioneErrore + "RISP";
  212.         }else if(tipoCRUD==3){
  213.             // componente cooperazione
  214.             nomeGestioneErrore = "componenteCooperazioneGestioneErroreDefaultPdD";
  215.         }else if(tipoCRUD==4){
  216.             // componente integrazione
  217.             nomeGestioneErrore = "componenteIntegrazioneGestioneErroreDefaultPdD";
  218.         }

  219.         // updateNome
  220.         gestioneErrore.setNome(nomeGestioneErrore);

  221.         // Type
  222.         int tipoOperazione = type;
  223.         // Recupero id gestione errore se presente
  224.         long idGestioneErroreChange = -1;
  225.         if (type == CostantiDB.UPDATE){
  226.             try{
  227.                 idGestioneErroreChange = getIdGestioneErrore(nomeGestioneErrore, con);
  228.             }catch (Exception e) {
  229.                 throw new DriverConfigurazioneException(e.getMessage(),e);
  230.             }
  231.             if(idGestioneErroreChange<=0){
  232.                 tipoOperazione = CostantiDB.CREATE;
  233.             }
  234.         }
  235.        
  236.        
  237.         PreparedStatement updateStmt = null;
  238.         PreparedStatement selectStmt = null;
  239.         String updateQuery = "";
  240.         String selectQuery = "";
  241.         ResultSet selectRS = null;
  242.         int n = 0;
  243.         try {

  244.             // preparo lo statement in base al tipo di operazione
  245.             switch (tipoOperazione) {
  246.             case CREATE:
  247.                 // CREATE
  248.                 ISQLQueryObject sqlQueryObject = SQLObjectFactory.createSQLQueryObject(DriverConfigurazioneDBLib.tipoDB);
  249.                 sqlQueryObject.addInsertTable(CostantiDB.GESTIONE_ERRORE);
  250.                 sqlQueryObject.addInsertField("comportamento_default", "?");
  251.                 sqlQueryObject.addInsertField("cadenza_rispedizione", "?");
  252.                 sqlQueryObject.addInsertField("nome", "?");
  253.                 updateQuery = sqlQueryObject.createSQLInsert();
  254.                 updateStmt = con.prepareStatement(updateQuery);

  255.                 updateStmt.setString(1, DriverConfigurazioneDBLib.getValue(gestioneErrore.getComportamento()));
  256.                 updateStmt.setString(2, gestioneErrore.getCadenzaRispedizione());
  257.                 updateStmt.setString(3, gestioneErrore.getNome());
  258.                 // eseguo lo statement
  259.                 n = updateStmt.executeUpdate();
  260.                 updateStmt.close();

  261.                 DriverConfigurazioneDBLib.log.debug("CRUDGestioneErrore CREATE : \n" + DBUtils.formatSQLString(updateQuery,
  262.                         gestioneErrore.getComportamento(),gestioneErrore.getCadenzaRispedizione(),gestioneErrore.getNome()));
  263.                 DriverConfigurazioneDBLib.log.debug("CRUDGestioneErrore type = " + type + " row affected =" + n);

  264.                 // Recupero id
  265.                 sqlQueryObject = SQLObjectFactory.createSQLQueryObject(DriverConfigurazioneDBLib.tipoDB);
  266.                 sqlQueryObject.addFromTable(CostantiDB.GESTIONE_ERRORE);
  267.                 sqlQueryObject.addSelectField("id");
  268.                 sqlQueryObject.addWhereCondition("nome = ?");
  269.                 selectQuery = sqlQueryObject.createSQLQuery();
  270.                 selectStmt = con.prepareStatement(selectQuery);
  271.                 selectStmt.setString(1, gestioneErrore.getNome());
  272.                 selectRS = selectStmt.executeQuery();
  273.                 if (selectRS.next()) {
  274.                     gestioneErrore.setId(selectRS.getLong("id"));
  275.                 }else{
  276.                     throw new Exception("id gestione errore non trovato dopo inserimento con nome ["+gestioneErrore.getNome()+"]");
  277.                 }
  278.                 selectRS.close();
  279.                 selectStmt.close();
  280.                
  281.                 // Insert gestione errore trasporto
  282.                 for(int i=0; i<gestioneErrore.sizeCodiceTrasportoList(); i++){
  283.                     GestioneErroreCodiceTrasporto tr = gestioneErrore.getCodiceTrasporto(i);
  284.                    
  285.                     int valoreMassimo = -1;
  286.                     int valoreMinimo = -1;
  287.                     if(tr.getValoreMassimo()!=null){
  288.                         valoreMassimo = tr.getValoreMassimo().intValue();
  289.                     }
  290.                     if(tr.getValoreMinimo()!=null){
  291.                         valoreMinimo = tr.getValoreMinimo().intValue();
  292.                     }
  293.                    
  294.                    
  295.                     sqlQueryObject = SQLObjectFactory.createSQLQueryObject(DriverConfigurazioneDBLib.tipoDB);
  296.                     sqlQueryObject.addInsertTable(CostantiDB.GESTIONE_ERRORE_TRASPORTO);
  297.                     sqlQueryObject.addInsertField("id_gestione_errore", "?");
  298.                     if(valoreMassimo>=0)
  299.                         sqlQueryObject.addInsertField("valore_massimo", "?");
  300.                     if(valoreMinimo>=0)
  301.                         sqlQueryObject.addInsertField("valore_minimo", "?");
  302.                     sqlQueryObject.addInsertField("comportamento", "?");
  303.                     sqlQueryObject.addInsertField("cadenza_rispedizione", "?");
  304.                     updateQuery = sqlQueryObject.createSQLInsert();
  305.                     updateStmt = con.prepareStatement(updateQuery);

  306.                     int index = 1;
  307.                     updateStmt.setLong(index, gestioneErrore.getId()); index++;
  308.                     if(valoreMassimo>=0){
  309.                         updateStmt.setInt(index, valoreMassimo); index++;
  310.                     }
  311.                     if(valoreMinimo>=0){
  312.                         updateStmt.setInt(index, valoreMinimo); index++;
  313.                     }
  314.                     updateStmt.setString(index, DriverConfigurazioneDBLib.getValue(tr.getComportamento())); index++;
  315.                     updateStmt.setString(index, tr.getCadenzaRispedizione()); index++;

  316.                     // eseguo lo statement
  317.                     n = updateStmt.executeUpdate();
  318.                     updateStmt.close();
  319.                    
  320.                     if(valoreMassimo>=0 && valoreMinimo>=0){
  321.                         DriverConfigurazioneDBLib.log.debug("CRUDGestioneErrore_Trasporto("+i+") CREATE : \n" + DBUtils.formatSQLString(updateQuery,
  322.                                 gestioneErrore.getId(),valoreMassimo,valoreMinimo,tr.getComportamento(),tr.getCadenzaRispedizione()));
  323.                     }else if(valoreMassimo>=0){
  324.                         DriverConfigurazioneDBLib.log.debug("CRUDGestioneErrore_Trasporto("+i+") CREATE : \n" + DBUtils.formatSQLString(updateQuery,
  325.                                 gestioneErrore.getId(),valoreMassimo,tr.getComportamento(),tr.getCadenzaRispedizione()));
  326.                     }else if(valoreMinimo>=0){
  327.                         DriverConfigurazioneDBLib.log.debug("CRUDGestioneErrore_Trasporto("+i+") CREATE : \n" + DBUtils.formatSQLString(updateQuery,
  328.                                 gestioneErrore.getId(),valoreMinimo,tr.getComportamento(),tr.getCadenzaRispedizione()));
  329.                     }else{
  330.                         DriverConfigurazioneDBLib.log.debug("CRUDGestioneErrore_Trasporto("+i+") CREATE : \n" + DBUtils.formatSQLString(updateQuery,
  331.                                 gestioneErrore.getId(),tr.getComportamento(),tr.getCadenzaRispedizione()));
  332.                     }
  333.                     DriverConfigurazioneDBLib.log.debug("CRUDGestioneErrore_Trasporto("+i+") type = " + type + " row affected =" + n);
  334.                 }
  335.                
  336.                 // Insert gestione errore SOAP FAULT
  337.                 for(int i=0; i<gestioneErrore.sizeSoapFaultList(); i++){
  338.                     GestioneErroreSoapFault sf = gestioneErrore.getSoapFault(i);
  339.                                        
  340.                     sqlQueryObject = SQLObjectFactory.createSQLQueryObject(DriverConfigurazioneDBLib.tipoDB);
  341.                     sqlQueryObject.addInsertTable(CostantiDB.GESTIONE_ERRORE_SOAP);
  342.                     sqlQueryObject.addInsertField("id_gestione_errore", "?");
  343.                     sqlQueryObject.addInsertField("fault_actor", "?");
  344.                     sqlQueryObject.addInsertField("fault_code", "?");
  345.                     sqlQueryObject.addInsertField("fault_string", "?");
  346.                     sqlQueryObject.addInsertField("comportamento", "?");
  347.                     sqlQueryObject.addInsertField("cadenza_rispedizione", "?");
  348.                     updateQuery = sqlQueryObject.createSQLInsert();
  349.                     updateStmt = con.prepareStatement(updateQuery);

  350.                     updateStmt.setLong(1, gestioneErrore.getId());
  351.                     updateStmt.setString(2, sf.getFaultActor());
  352.                     updateStmt.setString(3,sf.getFaultCode());
  353.                     updateStmt.setString(4,sf.getFaultString());
  354.                     updateStmt.setString(5,DriverConfigurazioneDBLib.getValue(sf.getComportamento()));
  355.                     updateStmt.setString(6, sf.getCadenzaRispedizione());

  356.                     // eseguo lo statement
  357.                     n = updateStmt.executeUpdate();
  358.                     updateStmt.close();
  359.                    
  360.                     DriverConfigurazioneDBLib.log.debug("CRUDGestioneErrore_SoapFault("+i+") CREATE : \n" + DBUtils.formatSQLString(updateQuery,
  361.                                 gestioneErrore.getId(),sf.getFaultActor(),sf.getFaultCode(),sf.getFaultString(),sf.getComportamento(),sf.getCadenzaRispedizione()));
  362.                     DriverConfigurazioneDBLib.log.debug("CRUDGestioneErrore_SoapFault("+i+") type = " + type + " row affected =" + n);
  363.                 }
  364.                
  365.                 break;

  366.             case UPDATE:
  367.            
  368.                 // UPDATE (ci entro solo se prima ho trovato un gestore errore inserito (idGestioneErroreChange) )
  369.                    
  370.                 // Set idGestionErrore
  371.                 gestioneErrore.setId(idGestioneErroreChange);
  372.                
  373.                 // Update gestion errore
  374.                 sqlQueryObject = SQLObjectFactory.createSQLQueryObject(DriverConfigurazioneDBLib.tipoDB);
  375.                 sqlQueryObject.addUpdateTable(CostantiDB.GESTIONE_ERRORE);
  376.                 sqlQueryObject.addUpdateField("comportamento_default", "?");
  377.                 sqlQueryObject.addUpdateField("cadenza_rispedizione", "?");
  378.                 sqlQueryObject.addWhereCondition("id=?");
  379.                 sqlQueryObject.setANDLogicOperator(true);
  380.                 updateQuery = sqlQueryObject.createSQLUpdate();
  381.                 updateStmt = con.prepareStatement(updateQuery);
  382.                
  383.                 updateStmt.setString(1, DriverConfigurazioneDBLib.getValue(gestioneErrore.getComportamento()));
  384.                 updateStmt.setString(2, gestioneErrore.getCadenzaRispedizione());
  385.                 updateStmt.setLong(3, idGestioneErroreChange);
  386.                 n = updateStmt.executeUpdate();
  387.                 updateStmt.close();
  388.            
  389.                 DriverConfigurazioneDBLib.log.debug("CRUDGestioneErrore UPDATE : \n" + DBUtils.formatSQLString(updateQuery,
  390.                         gestioneErrore.getComportamento(),gestioneErrore.getCadenzaRispedizione(),idGestioneErroreChange));
  391.                 DriverConfigurazioneDBLib.log.debug("CRUGestioneErrore type = " + type + " row affected =" + n);
  392.                
  393.                 // Delete vecchie gestione errore trasporto
  394.                 sqlQueryObject = SQLObjectFactory.createSQLQueryObject(DriverConfigurazioneDBLib.tipoDB);
  395.                 sqlQueryObject.addDeleteTable(CostantiDB.GESTIONE_ERRORE_TRASPORTO);
  396.                 sqlQueryObject.addWhereCondition("id_gestione_errore=?");
  397.                 updateQuery = sqlQueryObject.createSQLDelete();
  398.                 updateStmt = con.prepareStatement(updateQuery);
  399.                 updateStmt.setLong(1, idGestioneErroreChange);
  400.                 n = updateStmt.executeUpdate();
  401.                 updateStmt.close();
  402.                 DriverConfigurazioneDBLib.log.debug("CRUDGestioneErrore (Delete old trasporto) UPDATE : \n" + DBUtils.formatSQLString(updateQuery,
  403.                         idGestioneErroreChange));
  404.                 DriverConfigurazioneDBLib.log.debug("CRUGestioneErrore (Delete old trasporto) type = " + type + " row affected =" + n);
  405.                
  406.                 // Delete vecchie gestione errore soap fault
  407.                 sqlQueryObject = SQLObjectFactory.createSQLQueryObject(DriverConfigurazioneDBLib.tipoDB);
  408.                 sqlQueryObject.addDeleteTable(CostantiDB.GESTIONE_ERRORE_SOAP);
  409.                 sqlQueryObject.addWhereCondition("id_gestione_errore=?");
  410.                 updateQuery = sqlQueryObject.createSQLDelete();
  411.                 updateStmt = con.prepareStatement(updateQuery);
  412.                 updateStmt.setLong(1, idGestioneErroreChange);
  413.                 n = updateStmt.executeUpdate();
  414.                 updateStmt.close();
  415.                 DriverConfigurazioneDBLib.log.debug("CRUDGestioneErrore (Delete old soap fault) UPDATE : \n" + DBUtils.formatSQLString(updateQuery,
  416.                         idGestioneErroreChange));
  417.                 DriverConfigurazioneDBLib.log.debug("CRUGestioneErrore (Delete old soap fault) type = " + type + " row affected =" + n);
  418.                
  419.                 //  Insert gestione errore trasporto
  420.                 for(int i=0; i<gestioneErrore.sizeCodiceTrasportoList(); i++){
  421.                     GestioneErroreCodiceTrasporto tr = gestioneErrore.getCodiceTrasporto(i);
  422.                    
  423.                     int valoreMassimo = -1;
  424.                     int valoreMinimo = -1;
  425.                     if(tr.getValoreMassimo()!=null){
  426.                         valoreMassimo = tr.getValoreMassimo().intValue();
  427.                     }
  428.                     if(tr.getValoreMinimo()!=null){
  429.                         valoreMinimo = tr.getValoreMinimo().intValue();
  430.                     }
  431.                    
  432.                    
  433.                     sqlQueryObject = SQLObjectFactory.createSQLQueryObject(DriverConfigurazioneDBLib.tipoDB);
  434.                     sqlQueryObject.addInsertTable(CostantiDB.GESTIONE_ERRORE_TRASPORTO);
  435.                     sqlQueryObject.addInsertField("id_gestione_errore", "?");
  436.                     if(valoreMassimo>=0)
  437.                         sqlQueryObject.addInsertField("valore_massimo", "?");
  438.                     if(valoreMinimo>=0)
  439.                         sqlQueryObject.addInsertField("valore_minimo", "?");
  440.                     sqlQueryObject.addInsertField("comportamento", "?");
  441.                     sqlQueryObject.addInsertField("cadenza_rispedizione", "?");
  442.                     updateQuery = sqlQueryObject.createSQLInsert();
  443.                     updateStmt = con.prepareStatement(updateQuery);

  444.                     int index = 1;
  445.                     updateStmt.setLong(index, gestioneErrore.getId()); index++;
  446.                     if(valoreMassimo>=0){
  447.                         updateStmt.setInt(index, valoreMassimo); index++;
  448.                     }
  449.                     if(valoreMinimo>=0){
  450.                         updateStmt.setInt(index, valoreMinimo); index++;
  451.                     }
  452.                     updateStmt.setString(index, DriverConfigurazioneDBLib.getValue(tr.getComportamento())); index++;
  453.                     updateStmt.setString(index, tr.getCadenzaRispedizione()); index++;

  454.                     // eseguo lo statement
  455.                     n = updateStmt.executeUpdate();
  456.                     updateStmt.close();
  457.                    
  458.                     if(valoreMassimo>=0 && valoreMinimo>=0){
  459.                         DriverConfigurazioneDBLib.log.debug("CRUDGestioneErrore_Trasporto("+i+") CREATE : \n" + DBUtils.formatSQLString(updateQuery,
  460.                                 gestioneErrore.getId(),valoreMassimo,valoreMinimo,tr.getComportamento(),tr.getCadenzaRispedizione()));
  461.                     }else if(valoreMassimo>=0){
  462.                         DriverConfigurazioneDBLib.log.debug("CRUDGestioneErrore_Trasporto("+i+") CREATE : \n" + DBUtils.formatSQLString(updateQuery,
  463.                                 gestioneErrore.getId(),valoreMassimo,tr.getComportamento(),tr.getCadenzaRispedizione()));
  464.                     }else if(valoreMinimo>=0){
  465.                         DriverConfigurazioneDBLib.log.debug("CRUDGestioneErrore_Trasporto("+i+") CREATE : \n" + DBUtils.formatSQLString(updateQuery,
  466.                                 gestioneErrore.getId(),valoreMinimo,tr.getComportamento(),tr.getCadenzaRispedizione()));
  467.                     }else{
  468.                         DriverConfigurazioneDBLib.log.debug("CRUDGestioneErrore_Trasporto("+i+") CREATE : \n" + DBUtils.formatSQLString(updateQuery,
  469.                                 gestioneErrore.getId(),tr.getComportamento(),tr.getCadenzaRispedizione()));
  470.                     }
  471.                     DriverConfigurazioneDBLib.log.debug("CRUDGestioneErrore_Trasporto("+i+") type = " + type + " row affected =" + n);
  472.                 }
  473.                
  474.                 // Insert gestione errore SOAP FAULT
  475.                 for(int i=0; i<gestioneErrore.sizeSoapFaultList(); i++){
  476.                     GestioneErroreSoapFault sf = gestioneErrore.getSoapFault(i);
  477.                                        
  478.                     sqlQueryObject = SQLObjectFactory.createSQLQueryObject(DriverConfigurazioneDBLib.tipoDB);
  479.                     sqlQueryObject.addInsertTable(CostantiDB.GESTIONE_ERRORE_SOAP);
  480.                     sqlQueryObject.addInsertField("id_gestione_errore", "?");
  481.                     sqlQueryObject.addInsertField("fault_actor", "?");
  482.                     sqlQueryObject.addInsertField("fault_code", "?");
  483.                     sqlQueryObject.addInsertField("fault_string", "?");
  484.                     sqlQueryObject.addInsertField("comportamento", "?");
  485.                     sqlQueryObject.addInsertField("cadenza_rispedizione", "?");
  486.                     updateQuery = sqlQueryObject.createSQLInsert();
  487.                     updateStmt = con.prepareStatement(updateQuery);

  488.                     updateStmt.setLong(1, gestioneErrore.getId());
  489.                     updateStmt.setString(2, sf.getFaultActor());
  490.                     updateStmt.setString(3,sf.getFaultCode());
  491.                     updateStmt.setString(4,sf.getFaultString());
  492.                     updateStmt.setString(5,DriverConfigurazioneDBLib.getValue(sf.getComportamento()));
  493.                     updateStmt.setString(6, sf.getCadenzaRispedizione());

  494.                     // eseguo lo statement
  495.                     n = updateStmt.executeUpdate();
  496.                     updateStmt.close();
  497.                    
  498.                     DriverConfigurazioneDBLib.log.debug("CRUDGestioneErrore_SoapFault("+i+") CREATE : \n" + DBUtils.formatSQLString(updateQuery,
  499.                                 gestioneErrore.getId(),sf.getFaultActor(),sf.getFaultCode(),sf.getFaultString(),sf.getComportamento(),sf.getCadenzaRispedizione()));
  500.                     DriverConfigurazioneDBLib.log.debug("CRUDGestioneErrore_SoapFault("+i+") type = " + type + " row affected =" + n);
  501.                 }
  502.                
  503.                 break;

  504.             case DELETE:
  505.                 // DELETE
  506.                
  507.                 long idGestioneErrore = getIdGestioneErrore(nomeGestioneErrore, con);
  508.                
  509.                 gestioneErrore.setId(idGestioneErrore);
  510.                
  511.                 if(idGestioneErrore>0){
  512.                    
  513.                     // Delete gestione errore trasporto
  514.                     sqlQueryObject = SQLObjectFactory.createSQLQueryObject(DriverConfigurazioneDBLib.tipoDB);
  515.                     sqlQueryObject.addDeleteTable(CostantiDB.GESTIONE_ERRORE_TRASPORTO);
  516.                     sqlQueryObject.addWhereCondition("id_gestione_errore=?");
  517.                     updateQuery = sqlQueryObject.createSQLDelete();
  518.                     updateStmt = con.prepareStatement(updateQuery);
  519.                     updateStmt.setLong(1, idGestioneErrore);
  520.                     n = updateStmt.executeUpdate();
  521.                     updateStmt.close();
  522.                     DriverConfigurazioneDBLib.log.debug("CRUDGestioneErrore (Delete trasporto) UPDATE : \n" + DBUtils.formatSQLString(updateQuery,
  523.                             idGestioneErrore));
  524.                     DriverConfigurazioneDBLib.log.debug("CRUGestioneErrore (Delete trasporto) type = " + type + " row affected =" + n);
  525.                    
  526.                     // Delete gestione errore soap fault
  527.                     sqlQueryObject = SQLObjectFactory.createSQLQueryObject(DriverConfigurazioneDBLib.tipoDB);
  528.                     sqlQueryObject.addDeleteTable(CostantiDB.GESTIONE_ERRORE_SOAP);
  529.                     sqlQueryObject.addWhereCondition("id_gestione_errore=?");
  530.                     updateQuery = sqlQueryObject.createSQLDelete();
  531.                     updateStmt = con.prepareStatement(updateQuery);
  532.                     updateStmt.setLong(1, idGestioneErrore);
  533.                     n = updateStmt.executeUpdate();
  534.                     updateStmt.close();
  535.                     DriverConfigurazioneDBLib.log.debug("CRUDGestioneErrore (Delete soap fault) UPDATE : \n" + DBUtils.formatSQLString(updateQuery,
  536.                             idGestioneErrore));
  537.                     DriverConfigurazioneDBLib.log.debug("CRUGestioneErrore (Delete soap fault) type = " + type + " row affected =" + n);

  538.                     // Delete gestione errore
  539.                     sqlQueryObject = SQLObjectFactory.createSQLQueryObject(DriverConfigurazioneDBLib.tipoDB);
  540.                     sqlQueryObject.addDeleteTable(CostantiDB.GESTIONE_ERRORE);
  541.                     sqlQueryObject.addWhereCondition("id=?");
  542.                     updateQuery = sqlQueryObject.createSQLDelete();
  543.                     updateStmt = con.prepareStatement(updateQuery);
  544.                     updateStmt.setLong(1, idGestioneErrore);
  545.                     n = updateStmt.executeUpdate();
  546.                     updateStmt.close();
  547.    
  548.                     DriverConfigurazioneDBLib.log.debug("CRUDGestioneErrore type = " + type + " row affected =" + n);
  549.                     DriverConfigurazioneDBLib.log.debug("CRUDGestioneErrore DELETE : \n" + DBUtils.formatSQLString(updateQuery,
  550.                             idGestioneErrore));
  551.                    
  552.                 }
  553.                 break;
  554.             }


  555.             return n;

  556.         } catch (SQLException se) {
  557.             throw new DriverConfigurazioneException("[DriverConfigurazioneDB_LIB::CRUDGestioneErrore] SQLException [" + se.getMessage() + "].",se);
  558.         }catch (Exception se) {
  559.             throw new DriverConfigurazioneException("[DriverConfigurazioneDB_LIB::CRUDGestioneErrore] Exception [" + se.getMessage() + "].",se);
  560.         } finally {        
  561.             JDBCUtilities.closeResources(selectRS, selectStmt);
  562.             JDBCUtilities.closeResources(updateStmt);
  563.         }
  564.     }

  565.    
  566. }