DiagnosticDriverUtilities.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.protocol.basic.diagnostica;

  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.text.SimpleDateFormat;
  27. import java.util.Date;
  28. import java.util.List;

  29. import org.openspcoop2.core.constants.CostantiDB;
  30. import org.openspcoop2.core.id.IDSoggetto;
  31. import org.openspcoop2.protocol.sdk.diagnostica.FiltroRicercaDiagnostici;
  32. import org.openspcoop2.protocol.sdk.diagnostica.FiltroRicercaDiagnosticiConPaginazione;
  33. import org.openspcoop2.protocol.sdk.diagnostica.MsgDiagnostico;
  34. import org.openspcoop2.utils.StringWrapper;
  35. import org.openspcoop2.utils.date.DateUtils;
  36. import org.openspcoop2.utils.sql.ISQLQueryObject;
  37. import org.openspcoop2.utils.sql.SQLObjectFactory;
  38. import org.openspcoop2.utils.sql.SQLQueryObjectException;
  39. import org.slf4j.Logger;

  40. /**
  41.  * DriverMsgDiagnosticiUtilities
  42.  *
  43.  * @author Stefano Corallo (corallo@link.it)
  44.  * @author $Author$
  45.  * @version $Rev$, $Date$
  46.  */
  47. public class DiagnosticDriverUtilities {
  48.    
  49.     private DiagnosticDriverUtilities() {}
  50.    
  51.     public static ISQLQueryObject createSQLQueryObj_searchMessaggiDiagnostici(FiltroRicercaDiagnosticiConPaginazione filter,String tipoDatabase) throws SQLQueryObjectException{
  52.         return DiagnosticDriverUtilities.createSQLQueryObj(filter, tipoDatabase, DiagnosticSearchType.MSGDIAGNOSTICI);
  53.     }
  54.     public static ISQLQueryObject createSQLQueryObj_countMessaggiDiagnostici(FiltroRicercaDiagnostici filter,String tipoDatabase) throws SQLQueryObjectException{
  55.         return DiagnosticDriverUtilities.createSQLQueryObj(filter, tipoDatabase, DiagnosticSearchType.COUNT_MSGDIAGNOSTICI);
  56.     }
  57.     public static ISQLQueryObject createSQLQueryObj_deleteMessaggiDiagnostici(FiltroRicercaDiagnostici filter,String tipoDatabase) throws SQLQueryObjectException{
  58.         ISQLQueryObject from = DiagnosticDriverUtilities.createSQLQueryObj(filter, tipoDatabase, DiagnosticSearchType.DELETE_MSGDIAGNOSTICI);
  59.         ISQLQueryObject sqlQueryObjectDelete = SQLObjectFactory.createSQLQueryObject(tipoDatabase);
  60.         sqlQueryObjectDelete.addDeleteTable(CostantiDB.MSG_DIAGNOSTICI);
  61.         sqlQueryObjectDelete.addWhereINSelectSQLCondition(false, "id", from);
  62.         return sqlQueryObjectDelete;
  63.     }
  64.    
  65.     private static ISQLQueryObject createSQLQueryObj(FiltroRicercaDiagnostici filter,String tipoDatabase,DiagnosticSearchType tipoRicerca) throws SQLQueryObjectException{
  66.        
  67.         ISQLQueryObject sqlQueryObject = SQLObjectFactory.createSQLQueryObject(tipoDatabase);
  68.        
  69.         //select field
  70.         boolean distinct = true;
  71.         switch (tipoRicerca) {
  72.         case MSGDIAGNOSTICI:
  73.             sqlQueryObject.setSelectDistinct(distinct);
  74.             sqlQueryObject.addSelectAliasField(CostantiDB.MSG_DIAGNOSTICI+"."+CostantiDB.MSG_DIAGNOSTICI_COLUMN_ID, "idMsgDiagnostico");
  75.             sqlQueryObject.addSelectField(CostantiDB.MSG_DIAGNOSTICI+"."+CostantiDB.MSG_DIAGNOSTICI_COLUMN_GDO);
  76.             break;
  77.         case COUNT_MSGDIAGNOSTICI:
  78.             sqlQueryObject.addSelectCountField(CostantiDB.MSG_DIAGNOSTICI+"."+CostantiDB.MSG_DIAGNOSTICI_COLUMN_ID, "countMsgDiagnostici",distinct);
  79.             break;
  80.         case DELETE_MSGDIAGNOSTICI:
  81.             sqlQueryObject.setSelectDistinct(distinct);
  82.             sqlQueryObject.addSelectAliasField(CostantiDB.MSG_DIAGNOSTICI+"."+CostantiDB.MSG_DIAGNOSTICI_COLUMN_ID, "idMsgDiagnostico");
  83.             break;
  84.         }
  85.        
  86.        
  87.         //from
  88.         sqlQueryObject.addFromTable(CostantiDB.MSG_DIAGNOSTICI);
  89.        
  90.         sqlQueryObject.setANDLogicOperator(true);
  91.        
  92.        
  93.         //where
  94.        
  95.        
  96.         //data inizio
  97.         if(DiagnosticDriverUtilities.isDefined(filter.getDataInizio())){
  98.             sqlQueryObject.addWhereCondition(CostantiDB.MSG_DIAGNOSTICI+"."+CostantiDB.MSG_DIAGNOSTICI_COLUMN_GDO+">=?");
  99.         }
  100.         //data fine
  101.         if(DiagnosticDriverUtilities.isDefined(filter.getDataFine())){
  102.             sqlQueryObject.addWhereCondition(CostantiDB.MSG_DIAGNOSTICI+"."+CostantiDB.MSG_DIAGNOSTICI_COLUMN_GDO+"<=?");
  103.         }
  104.        
  105.         if(DiagnosticDriverUtilities.isDefined(filter.getIdTransazione())){
  106.             sqlQueryObject.addWhereCondition(CostantiDB.MSG_DIAGNOSTICI+"."+CostantiDB.MSG_DIAGNOSTICI_COLUMN_ID_TRANSAZIONE+"=?");
  107.         }
  108.        
  109.         if(DiagnosticDriverUtilities.isDefined(filter.getIdFunzione())){
  110.             String idF  = filter.getIdFunzione();
  111.             if("RicezioneContenutiApplicativi".equals(idF)
  112.                     ||"Imbustamento".equals(idF)
  113.                     ||"RicezioneBuste".equals(idF)
  114.                     ||"Sbustamento".equals(idF)
  115.             ){
  116.                 sqlQueryObject.addWhereLikeCondition(CostantiDB.MSG_DIAGNOSTICI+"."+CostantiDB.MSG_DIAGNOSTICI_COLUMN_IDFUNZIONE,idF,true,true);
  117.             }
  118.             else if("InoltroBuste".equals(idF)){
  119.                 sqlQueryObject.addWhereCondition(false,
  120.                         sqlQueryObject.getWhereLikeCondition(CostantiDB.MSG_DIAGNOSTICI+"."+CostantiDB.MSG_DIAGNOSTICI_COLUMN_IDFUNZIONE, idF),
  121.                         sqlQueryObject.getWhereLikeCondition(CostantiDB.MSG_DIAGNOSTICI+"."+CostantiDB.MSG_DIAGNOSTICI_COLUMN_IDFUNZIONE, "InoltroRisposte"));
  122.             }
  123.             else if("ConsegnaContenutiApplicativi".equals(idF)){
  124.                 sqlQueryObject.addWhereLikeCondition(CostantiDB.MSG_DIAGNOSTICI+"."+CostantiDB.MSG_DIAGNOSTICI_COLUMN_IDFUNZIONE, idF);
  125.             }
  126.             else{
  127.                 sqlQueryObject.addWhereCondition(CostantiDB.MSG_DIAGNOSTICI+"."+CostantiDB.MSG_DIAGNOSTICI_COLUMN_IDFUNZIONE+"=?");
  128.             }
  129.         }
  130.         if(DiagnosticDriverUtilities.isDefined(filter.getDominio())){
  131.             if(DiagnosticDriverUtilities.isDefined(filter.getDominio().getCodicePorta())){
  132.                 sqlQueryObject.addWhereCondition(CostantiDB.MSG_DIAGNOSTICI+"."+CostantiDB.MSG_DIAGNOSTICI_COLUMN_PDD_CODICE+"=?");
  133.             }
  134.             if(DiagnosticDriverUtilities.isDefined(filter.getDominio().getTipo())){
  135.                 sqlQueryObject.addWhereCondition(CostantiDB.MSG_DIAGNOSTICI+"."+CostantiDB.MSG_DIAGNOSTICI_COLUMN_PDD_TIPO_SOGGETTO+"=?");
  136.             }
  137.             if(DiagnosticDriverUtilities.isDefined(filter.getDominio().getNome())){
  138.                 sqlQueryObject.addWhereCondition(CostantiDB.MSG_DIAGNOSTICI+"."+CostantiDB.MSG_DIAGNOSTICI_COLUMN_PDD_NOME_SOGGETTO+"=?");
  139.             }
  140.         }
  141.        
  142.         if(DiagnosticDriverUtilities.isDefined(filter.getIdBustaRichiesta())){
  143.             sqlQueryObject.addWhereCondition(CostantiDB.MSG_DIAGNOSTICI+"."+CostantiDB.MSG_DIAGNOSTICI_COLUMN_IDMESSAGGIO+"=?");
  144.         }
  145.         if(DiagnosticDriverUtilities.isDefined(filter.getIdBustaRisposta())){
  146.             sqlQueryObject.addWhereCondition(CostantiDB.MSG_DIAGNOSTICI+"."+CostantiDB.MSG_DIAGNOSTICI_COLUMN_IDMESSAGGIO_RISPOSTA+"=?");
  147.         }
  148.        
  149.         if(DiagnosticDriverUtilities.isDefined(filter.getSeverita())){
  150.             sqlQueryObject.addWhereCondition(CostantiDB.MSG_DIAGNOSTICI+"."+CostantiDB.MSG_DIAGNOSTICI_COLUMN_SEVERITA+"<=?");
  151.         }
  152.        
  153.         if(DiagnosticDriverUtilities.isDefined(filter.getCodice())){
  154.             sqlQueryObject.addWhereCondition(CostantiDB.MSG_DIAGNOSTICI+"."+CostantiDB.MSG_DIAGNOSTICI_COLUMN_CODICE+"=?");
  155.         }
  156.        
  157.         if( DiagnosticDriverUtilities.isDefined(filter.getMessaggioCercatoInternamenteTestoDiagnostico()) )
  158.             sqlQueryObject.addWhereLikeCondition(CostantiDB.MSG_DIAGNOSTICI+"."+CostantiDB.MSG_DIAGNOSTICI_COLUMN_MESSAGGIO, filter.getMessaggioCercatoInternamenteTestoDiagnostico(),true,true);
  159.        
  160.         if(DiagnosticDriverUtilities.isDefined(filter.getProtocollo())){
  161.             sqlQueryObject.addWhereCondition(CostantiDB.MSG_DIAGNOSTICI+"."+CostantiDB.MSG_DIAGNOSTICI_COLUMN_PROTOCOLLO+"=?");
  162.         }
  163.        
  164.         if(DiagnosticDriverUtilities.isDefined(filter.getApplicativo())){
  165.             sqlQueryObject.addWhereCondition(CostantiDB.MSG_DIAGNOSTICI+"."+CostantiDB.MSG_DIAGNOSTICI_COLUMN_APPLICATIVO+"=?");
  166.         }
  167.         else if(DiagnosticDriverUtilities.isDefined(filter.getCheckApplicativoIsNull()) && filter.getCheckApplicativoIsNull()!=null && filter.getCheckApplicativoIsNull().booleanValue()){
  168.             sqlQueryObject.addWhereCondition(CostantiDB.MSG_DIAGNOSTICI+"."+CostantiDB.MSG_DIAGNOSTICI_COLUMN_APPLICATIVO+" is null");
  169.         }
  170.        
  171.         if(filter.getProperties()!=null){
  172.             for (String key : filter.getProperties().keySet()) {
  173.                 switch (tipoRicerca) {
  174.                 case MSGDIAGNOSTICI:
  175.                 case COUNT_MSGDIAGNOSTICI:
  176.                 case DELETE_MSGDIAGNOSTICI:
  177.                     if(DiagnosticDriver.IDDIAGNOSTICI.equals(key)){
  178.                         // Caso particolare dell'id long della traccia
  179.                         sqlQueryObject.addWhereCondition(CostantiDB.MSG_DIAGNOSTICI+".id=?");
  180.                     }else{
  181.                         sqlQueryObject.addWhereCondition(CostantiDB.MSG_DIAGNOSTICI+"."+key+"=?");
  182.                     }
  183.                     break;
  184.                 }
  185.             }
  186.         }
  187.        
  188.        
  189.         switch (tipoRicerca) {
  190.         case MSGDIAGNOSTICI:
  191.            
  192.             FiltroRicercaDiagnosticiConPaginazione f = (FiltroRicercaDiagnosticiConPaginazione) filter;
  193.             //limit
  194.             if(f.getLimit()>0)
  195.                 sqlQueryObject.setLimit(f.getLimit());
  196.             /**else
  197.                 sqlQueryObject.setLimit(1000);*/
  198.             // Offset
  199.             if(f.getOffset()>0)
  200.                 sqlQueryObject.setOffset(f.getOffset());
  201.            
  202.             sqlQueryObject.addOrderBy("gdo");
  203.             sqlQueryObject.setSortType(f.isAsc());  
  204.             break;
  205.         case COUNT_MSGDIAGNOSTICI:
  206.         case DELETE_MSGDIAGNOSTICI:
  207.             // Niente da effettuare
  208.             break;
  209.         }
  210.                
  211.         return sqlQueryObject;

  212.     }
  213.    
  214.     public static int setValues_searchMessaggiDiagnostici(FiltroRicercaDiagnostici filter,Object object,int startIndex) throws SQLQueryObjectException, SQLException{
  215.         return DiagnosticDriverUtilities.setValuesSearch(filter, object,startIndex, DiagnosticSearchType.MSGDIAGNOSTICI);
  216.     }
  217.     public static int setValues_countMessaggiDiagnostici(FiltroRicercaDiagnostici filter,Object object,int startIndex) throws SQLQueryObjectException, SQLException{
  218.         return DiagnosticDriverUtilities.setValuesSearch(filter, object,startIndex, DiagnosticSearchType.COUNT_MSGDIAGNOSTICI);
  219.     }
  220.     public static int setValues_deleteMessaggiDiagnostici(FiltroRicercaDiagnostici filter,Object object,int startIndex) throws SQLQueryObjectException, SQLException{
  221.         return DiagnosticDriverUtilities.setValuesSearch(filter, object,startIndex, DiagnosticSearchType.DELETE_MSGDIAGNOSTICI);
  222.     }
  223.        
  224.     private static int setValuesSearch(FiltroRicercaDiagnostici filter,Object object,int startIndex, DiagnosticSearchType tipoRicerca) throws SQLException{
  225.        
  226.         if(tipoRicerca!=null) {
  227.             // nop
  228.         }
  229.        
  230.         SimpleDateFormat dateformat = DateUtils.getSimpleDateFormatMs();
  231.        
  232.         PreparedStatement pstmt = null;
  233.         StringWrapper query = null;
  234.         if(object instanceof PreparedStatement){
  235.             pstmt = (PreparedStatement) object;
  236.         }
  237.         else if(object instanceof StringWrapper){
  238.             query = (StringWrapper) object;
  239.         }
  240.         else{
  241.             throw new SQLException("Tipo di parametro ["+object.getClass().getName()+"] non gestito");
  242.         }
  243.        
  244.        
  245.        
  246.         //where
  247.        
  248.        
  249.         //data inizio
  250.         if(DiagnosticDriverUtilities.isDefined(filter.getDataInizio())){
  251.             if(pstmt!=null)
  252.                 pstmt.setTimestamp(startIndex++, new Timestamp(filter.getDataInizio().getTime()));
  253.             if(query!=null)
  254.                 query.replaceFirst("\\?","'"+dateformat.format(filter.getDataInizio())+"'");
  255.         }
  256.         //data fine
  257.         if(DiagnosticDriverUtilities.isDefined(filter.getDataFine())){
  258.             if(pstmt!=null)
  259.                 pstmt.setTimestamp(startIndex++, new Timestamp(filter.getDataFine().getTime()));
  260.             if(query!=null)
  261.                 query.replaceFirst("\\?","'"+dateformat.format(filter.getDataFine())+"'");
  262.         }
  263.        
  264.         // id transazione
  265.         if(DiagnosticDriverUtilities.isDefined(filter.getIdTransazione())){
  266.             if(pstmt!=null)
  267.                 pstmt.setString(startIndex++, filter.getIdTransazione());
  268.             if(query!=null)
  269.                 query.replaceFirst("\\?","'"+filter.getIdTransazione()+"'");
  270.         }
  271.        
  272.         if(DiagnosticDriverUtilities.isDefined(filter.getIdFunzione())){
  273.             String idF  = filter.getIdFunzione();
  274.             if("RicezioneContenutiApplicativi".equals(idF)
  275.                     ||"Imbustamento".equals(idF)
  276.                     ||"RicezioneBuste".equals(idF)
  277.                     ||"Sbustamento".equals(idF)
  278.             ){
  279.                 // Like impostato in sqlQueryObject
  280.             }
  281.             else if("InoltroBuste".equals(idF)){
  282.                 // Like impostato in sqlQueryObject
  283.             }
  284.             else if("ConsegnaContenutiApplicativi".equals(idF)){
  285.                 // Like impostato in sqlQueryObject
  286.             }
  287.             else{
  288.                 if(pstmt!=null)
  289.                     pstmt.setString(startIndex++, idF);
  290.                 if(query!=null)
  291.                     query.replaceFirst("\\?","'"+idF+"'");
  292.             }
  293.         }
  294.         if(DiagnosticDriverUtilities.isDefined(filter.getDominio())){
  295.             if(DiagnosticDriverUtilities.isDefined(filter.getDominio().getCodicePorta())){
  296.                 if(pstmt!=null)
  297.                     pstmt.setString(startIndex++, filter.getDominio().getCodicePorta());
  298.                 if(query!=null)
  299.                     query.replaceFirst("\\?","'"+filter.getDominio().getCodicePorta()+"'");
  300.             }
  301.             if(DiagnosticDriverUtilities.isDefined(filter.getDominio().getTipo())){
  302.                 if(pstmt!=null)
  303.                     pstmt.setString(startIndex++, filter.getDominio().getTipo());
  304.                 if(query!=null)
  305.                     query.replaceFirst("\\?","'"+filter.getDominio().getTipo()+"'");
  306.             }
  307.             if(DiagnosticDriverUtilities.isDefined(filter.getDominio().getNome())){
  308.                 if(pstmt!=null)
  309.                     pstmt.setString(startIndex++, filter.getDominio().getNome());
  310.                 if(query!=null)
  311.                     query.replaceFirst("\\?","'"+filter.getDominio().getNome()+"'");
  312.             }
  313.         }
  314.        
  315.         if(DiagnosticDriverUtilities.isDefined(filter.getIdBustaRichiesta())){
  316.             if(pstmt!=null)
  317.                 pstmt.setString(startIndex++, filter.getIdBustaRichiesta());
  318.             if(query!=null)
  319.                 query.replaceFirst("\\?","'"+filter.getIdBustaRichiesta()+"'");
  320.         }
  321.         if(DiagnosticDriverUtilities.isDefined(filter.getIdBustaRisposta())){
  322.             if(pstmt!=null)
  323.                 pstmt.setString(startIndex++, filter.getIdBustaRisposta());
  324.             if(query!=null)
  325.                 query.replaceFirst("\\?","'"+filter.getIdBustaRisposta()+"'");
  326.         }
  327.                
  328.         if(DiagnosticDriverUtilities.isDefined(filter.getSeverita())){
  329.             if(pstmt!=null)
  330.                 pstmt.setInt(startIndex++, filter.getSeverita());
  331.             if(query!=null)
  332.                 query.replaceFirst("\\?",filter.getSeverita()+"");
  333.         }
  334.        
  335.         if(DiagnosticDriverUtilities.isDefined(filter.getCodice())){
  336.             if(pstmt!=null)
  337.                 pstmt.setString(startIndex++, filter.getCodice());
  338.             if(query!=null)
  339.                 query.replaceFirst("\\?","'"+filter.getCodice()+"'");
  340.         }
  341.        
  342.         if(DiagnosticDriverUtilities.isDefined(filter.getProtocollo())){
  343.             if(pstmt!=null)
  344.                 pstmt.setString(startIndex++, filter.getProtocollo());
  345.             if(query!=null)
  346.                 query.replaceFirst("\\?","'"+filter.getProtocollo()+"'");
  347.         }
  348.        
  349.         if(DiagnosticDriverUtilities.isDefined(filter.getApplicativo())){
  350.             if(pstmt!=null)
  351.                 pstmt.setString(startIndex++, filter.getApplicativo());
  352.             if(query!=null)
  353.                 query.replaceFirst("\\?","'"+filter.getApplicativo()+"'");
  354.         }
  355.         else if(DiagnosticDriverUtilities.isDefined(filter.getCheckApplicativoIsNull()) && filter.getCheckApplicativoIsNull()!=null && filter.getCheckApplicativoIsNull().booleanValue()){
  356.             // nop
  357.         }
  358.        
  359.         if(filter.getProperties()!=null){
  360.             for (String key : filter.getProperties().keySet()) {
  361.                 String value = filter.getProperties().get(key);
  362.                 if(DiagnosticDriver.IDDIAGNOSTICI.equals(key)){
  363.                     // Caso particolare dell'id long della traccia
  364.                     if(pstmt!=null)
  365.                         pstmt.setLong(startIndex++, Long.parseLong(value));
  366.                     if(query!=null)
  367.                         query.replaceFirst("\\?",value);
  368.                 }else{
  369.                     if(pstmt!=null)
  370.                         pstmt.setString(startIndex++, value);
  371.                     if(query!=null)
  372.                         query.replaceFirst("\\?","'"+value+"'");
  373.                 }
  374.             }
  375.         }
  376.        
  377.        
  378.         return startIndex;
  379.     }
  380.    
  381.    
  382.     public static MsgDiagnostico getMsgDiagnostico(Connection c,String tipoDatabase,
  383.             Logger log,long id,List<String> properties) throws SQLQueryObjectException, SQLException {
  384.        
  385.         ISQLQueryObject sqlQueryObject = SQLObjectFactory.createSQLQueryObject(tipoDatabase);
  386.         sqlQueryObject.addFromTable(CostantiDB.MSG_DIAGNOSTICI);
  387.         sqlQueryObject.addWhereCondition(CostantiDB.MSG_DIAGNOSTICI_COLUMN_ID+"=?");
  388.        
  389.         String msgD = "Eseguo query : "+sqlQueryObject.createSQLQuery().replaceFirst("\\?", id+"");
  390.         log.debug(msgD);
  391.         PreparedStatement stmt=null;
  392.         ResultSet rs= null;
  393.         try{
  394.             stmt=c.prepareStatement(sqlQueryObject.createSQLQuery());
  395.             stmt.setLong(1, id);
  396.             rs=stmt.executeQuery();
  397.             if(rs.next()){
  398.                
  399.                 MsgDiagnostico msg = new MsgDiagnostico();
  400.                
  401.                 msg.setId(rs.getLong(CostantiDB.MSG_DIAGNOSTICI_COLUMN_ID));
  402.                 msg.addProperty(DiagnosticDriver.IDDIAGNOSTICI, msg.getId()+"");
  403.                
  404.                 Timestamp gdo=rs.getTimestamp(CostantiDB.MSG_DIAGNOSTICI_COLUMN_GDO);
  405.                 msg.setGdo(gdo);
  406.                
  407.                 msg.setIdTransazione(rs.getString(CostantiDB.MSG_DIAGNOSTICI_COLUMN_ID_TRANSAZIONE));
  408.                
  409.                 msg.setApplicativo(rs.getString(CostantiDB.MSG_DIAGNOSTICI_COLUMN_APPLICATIVO));
  410.                
  411.                 IDSoggetto idSoggetto = new IDSoggetto();
  412.                 idSoggetto.setCodicePorta(rs.getString(CostantiDB.MSG_DIAGNOSTICI_COLUMN_PDD_CODICE));
  413.                 idSoggetto.setNome(rs.getString(CostantiDB.MSG_DIAGNOSTICI_COLUMN_PDD_NOME_SOGGETTO));
  414.                 idSoggetto.setTipo(rs.getString(CostantiDB.MSG_DIAGNOSTICI_COLUMN_PDD_TIPO_SOGGETTO));
  415.                 msg.setIdSoggetto(idSoggetto);
  416.                
  417.                 msg.setIdFunzione(rs.getString(CostantiDB.MSG_DIAGNOSTICI_COLUMN_IDFUNZIONE));

  418.                 msg.setSeverita(rs.getInt(CostantiDB.MSG_DIAGNOSTICI_COLUMN_SEVERITA));
  419.                
  420.                 msg.setMessaggio(rs.getString(CostantiDB.MSG_DIAGNOSTICI_COLUMN_MESSAGGIO));
  421.                
  422.                 msg.setIdBusta(rs.getString(CostantiDB.MSG_DIAGNOSTICI_COLUMN_IDMESSAGGIO));
  423.                
  424.                 msg.setIdBustaRisposta(rs.getString(CostantiDB.MSG_DIAGNOSTICI_COLUMN_IDMESSAGGIO_RISPOSTA));
  425.                
  426.                 msg.setCodice(rs.getString(CostantiDB.MSG_DIAGNOSTICI_COLUMN_CODICE));
  427.                
  428.                 msg.setProtocollo(rs.getString(CostantiDB.MSG_DIAGNOSTICI_COLUMN_PROTOCOLLO));
  429.                
  430.                 if(properties!=null){
  431.                     for (int i = 0; i < properties.size(); i++) {
  432.                         String key = properties.get(i);
  433.                         msg.addProperty(key, rs.getString(key));
  434.                     }
  435.                 }
  436.                
  437.                 return msg;
  438.                
  439.             }
  440.             else{
  441.                
  442.                 throw new SQLQueryObjectException("MsgDiagnostico con id["+id+"] non trovato");
  443.                
  444.             }
  445.         }finally{
  446.             try{
  447.                 if(rs!=null){
  448.                     rs.close();
  449.                 }
  450.             }catch(Exception eClose){
  451.                 // close
  452.             }
  453.             try{
  454.                 if(stmt!=null){
  455.                     stmt.close();
  456.                 }
  457.             }catch(Exception eClose){
  458.                 // close
  459.             }
  460.         }
  461.     }
  462.    
  463.    
  464.    
  465.     protected static boolean isDefined(String v){
  466.         return v!=null && !"".equals(v);
  467.     }
  468.     protected static boolean isDefined(Boolean v){
  469.         return v!=null;
  470.     }
  471.     protected static boolean isDefined(Integer v){
  472.         return v!=null;
  473.     }
  474.     protected static boolean isDefined(List<?> v){
  475.         return v!=null && !v.isEmpty();
  476.     }
  477.     protected static boolean isDefined(Date v){
  478.         return v!=null;
  479.     }
  480.     protected static boolean isDefined(IDSoggetto v){
  481.         return v!=null;
  482.     }
  483. }