EventoFetch.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.eventi.dao.jdbc.fetch;

  21. import org.openspcoop2.generic_project.beans.IModel;
  22. import org.openspcoop2.generic_project.dao.jdbc.utils.AbstractJDBCFetch;
  23. import org.openspcoop2.generic_project.dao.jdbc.utils.GenericJDBCParameterUtilities;
  24. import org.openspcoop2.generic_project.exception.ServiceException;

  25. import java.sql.ResultSet;
  26. import java.util.Map;

  27. import org.openspcoop2.utils.TipiDatabase;
  28. import org.openspcoop2.utils.jdbc.IKeyGeneratorObject;

  29. import org.openspcoop2.core.eventi.Evento;


  30. /**    
  31.  * EventoFetch
  32.  *
  33.  * @author Poli Andrea (poli@link.it)
  34.  * @author $Author$
  35.  * @version $Rev$, $Date$
  36.  */
  37. public class EventoFetch extends AbstractJDBCFetch {

  38.     @Override
  39.     public Object fetch(TipiDatabase tipoDatabase, IModel<?> model , ResultSet rs) throws ServiceException {
  40.        
  41.         try{
  42.             GenericJDBCParameterUtilities jdbcParameterUtilities =  
  43.                     new GenericJDBCParameterUtilities(tipoDatabase);

  44.             if(model.equals(Evento.model())){
  45.                 Evento object = new Evento();
  46.                 setParameter(object, "setId", Long.class,
  47.                     jdbcParameterUtilities.readParameter(rs, "id", Long.class));
  48.                 setParameter(object, "setTipo", Evento.model().TIPO.getFieldType(),
  49.                     jdbcParameterUtilities.readParameter(rs, "tipo", Evento.model().TIPO.getFieldType()));
  50.                 setParameter(object, "setCodice", Evento.model().CODICE.getFieldType(),
  51.                     jdbcParameterUtilities.readParameter(rs, "codice", Evento.model().CODICE.getFieldType()));
  52.                 setParameter(object, "setSeverita", Evento.model().SEVERITA.getFieldType(),
  53.                     jdbcParameterUtilities.readParameter(rs, "severita", Evento.model().SEVERITA.getFieldType()));
  54.                 setParameter(object, "setOraRegistrazione", Evento.model().ORA_REGISTRAZIONE.getFieldType(),
  55.                     jdbcParameterUtilities.readParameter(rs, "ora_registrazione", Evento.model().ORA_REGISTRAZIONE.getFieldType()));
  56.                 setParameter(object, "setDescrizione", Evento.model().DESCRIZIONE.getFieldType(),
  57.                     jdbcParameterUtilities.readParameter(rs, "descrizione", Evento.model().DESCRIZIONE.getFieldType()));
  58.                 setParameter(object, "setIdTransazione", Evento.model().ID_TRANSAZIONE.getFieldType(),
  59.                     jdbcParameterUtilities.readParameter(rs, "id_transazione", Evento.model().ID_TRANSAZIONE.getFieldType()));
  60.                 setParameter(object, "setIdConfigurazione", Evento.model().ID_CONFIGURAZIONE.getFieldType(),
  61.                     jdbcParameterUtilities.readParameter(rs, "id_configurazione", Evento.model().ID_CONFIGURAZIONE.getFieldType()));
  62.                 setParameter(object, "setConfigurazione", Evento.model().CONFIGURAZIONE.getFieldType(),
  63.                     jdbcParameterUtilities.readParameter(rs, "configurazione", Evento.model().CONFIGURAZIONE.getFieldType()));
  64.                 setParameter(object, "setClusterId", Evento.model().CLUSTER_ID.getFieldType(),
  65.                     jdbcParameterUtilities.readParameter(rs, "cluster_id", Evento.model().CLUSTER_ID.getFieldType()));
  66.                 return object;
  67.             }
  68.            
  69.             else{
  70.                 throw new ServiceException("Model ["+model.toString()+"] not supported by fetch: "+this.getClass().getName());
  71.             }  
  72.                    
  73.         }catch(Exception e){
  74.             throw new ServiceException("Model ["+model.toString()+"] occurs error in fetch: "+e.getMessage(),e);
  75.         }
  76.        
  77.     }
  78.    
  79.     @Override
  80.     public Object fetch(TipiDatabase tipoDatabase, IModel<?> model , Map<String,Object> map ) throws ServiceException {
  81.        
  82.         try{

  83.             if(model.equals(Evento.model())){
  84.                 Evento object = new Evento();
  85.                 setParameter(object, "setId", Long.class,
  86.                     this.getObjectFromMap(map,"id"));
  87.                 setParameter(object, "setTipo", Evento.model().TIPO.getFieldType(),
  88.                     this.getObjectFromMap(map,"tipo"));
  89.                 setParameter(object, "setCodice", Evento.model().CODICE.getFieldType(),
  90.                     this.getObjectFromMap(map,"codice"));
  91.                 setParameter(object, "setSeverita", Evento.model().SEVERITA.getFieldType(),
  92.                     this.getObjectFromMap(map,"severita"));
  93.                 setParameter(object, "setOraRegistrazione", Evento.model().ORA_REGISTRAZIONE.getFieldType(),
  94.                     this.getObjectFromMap(map,"ora-registrazione"));
  95.                 setParameter(object, "setDescrizione", Evento.model().DESCRIZIONE.getFieldType(),
  96.                     this.getObjectFromMap(map,"descrizione"));
  97.                 setParameter(object, "setIdTransazione", Evento.model().ID_TRANSAZIONE.getFieldType(),
  98.                     this.getObjectFromMap(map,"id-transazione"));
  99.                 setParameter(object, "setIdConfigurazione", Evento.model().ID_CONFIGURAZIONE.getFieldType(),
  100.                     this.getObjectFromMap(map,"id-configurazione"));
  101.                 setParameter(object, "setConfigurazione", Evento.model().CONFIGURAZIONE.getFieldType(),
  102.                     this.getObjectFromMap(map,"configurazione"));
  103.                 setParameter(object, "setClusterId", Evento.model().CLUSTER_ID.getFieldType(),
  104.                     this.getObjectFromMap(map,"cluster-id"));
  105.                 return object;
  106.             }
  107.            
  108.             else{
  109.                 throw new ServiceException("Model ["+model.toString()+"] not supported by fetch: "+this.getClass().getName());
  110.             }  
  111.                    
  112.         }catch(Exception e){
  113.             throw new ServiceException("Model ["+model.toString()+"] occurs error in fetch: "+e.getMessage(),e);
  114.         }
  115.        
  116.     }
  117.    
  118.    
  119.     @Override
  120.     public IKeyGeneratorObject getKeyGeneratorObject( IModel<?> model )  throws ServiceException {
  121.        
  122.         try{

  123.             if(model.equals(Evento.model())){
  124.                 return new org.openspcoop2.utils.jdbc.CustomKeyGeneratorObject("notifiche_eventi","id","seq_notifiche_eventi","notifiche_eventi_init_seq");
  125.             }
  126.            
  127.             else{
  128.                 throw new ServiceException("Model ["+model.toString()+"] not supported by getKeyGeneratorObject: "+this.getClass().getName());
  129.             }

  130.         }catch(Exception e){
  131.             throw new ServiceException("Model ["+model.toString()+"] occurs error in getKeyGeneratorObject: "+e.getMessage(),e);
  132.         }
  133.        
  134.     }

  135. }