AllarmeNotificaFetch.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.allarmi.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.allarmi.AllarmeNotifica;
  30. import org.openspcoop2.core.constants.CostantiDB;


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

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

  45.             if(model.equals(AllarmeNotifica.model())){
  46.                 AllarmeNotifica object = new AllarmeNotifica();
  47.                 setParameter(object, "setId", Long.class,
  48.                     jdbcParameterUtilities.readParameter(rs, "id", Long.class));
  49.                 setParameter(object, "setDataNotifica", AllarmeNotifica.model().DATA_NOTIFICA.getFieldType(),
  50.                     jdbcParameterUtilities.readParameter(rs, "data_notifica", AllarmeNotifica.model().DATA_NOTIFICA.getFieldType()));
  51.                 setParameter(object, "setOldStato", AllarmeNotifica.model().OLD_STATO.getFieldType(),
  52.                     jdbcParameterUtilities.readParameter(rs, "old_stato", AllarmeNotifica.model().OLD_STATO.getFieldType()));
  53.                 setParameter(object, "setOldDettaglioStato", AllarmeNotifica.model().OLD_DETTAGLIO_STATO.getFieldType(),
  54.                     jdbcParameterUtilities.readParameter(rs, "old_stato_dettaglio", AllarmeNotifica.model().OLD_DETTAGLIO_STATO.getFieldType()));
  55.                 setParameter(object, "setNuovoStato", AllarmeNotifica.model().NUOVO_STATO.getFieldType(),
  56.                     jdbcParameterUtilities.readParameter(rs, "nuovo_stato", AllarmeNotifica.model().NUOVO_STATO.getFieldType()));
  57.                 setParameter(object, "setNuovoDettaglioStato", AllarmeNotifica.model().NUOVO_DETTAGLIO_STATO.getFieldType(),
  58.                     jdbcParameterUtilities.readParameter(rs, "nuovo_stato_dettaglio", AllarmeNotifica.model().NUOVO_DETTAGLIO_STATO.getFieldType()));
  59.                 setParameter(object, "setHistoryEntry", AllarmeNotifica.model().HISTORY_ENTRY.getFieldType(),
  60.                     jdbcParameterUtilities.readParameter(rs, "history_entry", AllarmeNotifica.model().HISTORY_ENTRY.getFieldType()));
  61.                 return object;
  62.             }
  63.            
  64.             else{
  65.                 throw new ServiceException("Model ["+model.toString()+"] not supported by fetch: "+this.getClass().getName());
  66.             }  
  67.                    
  68.         }catch(Exception e){
  69.             throw new ServiceException("Model ["+model.toString()+"] occurs error in fetch: "+e.getMessage(),e);
  70.         }
  71.        
  72.     }
  73.    
  74.     @Override
  75.     public Object fetch(TipiDatabase tipoDatabase, IModel<?> model , Map<String,Object> map ) throws ServiceException {
  76.        
  77.         try{

  78.             if(model.equals(AllarmeNotifica.model())){
  79.                 AllarmeNotifica object = new AllarmeNotifica();
  80.                 setParameter(object, "setId", Long.class,
  81.                     this.getObjectFromMap(map,"id"));
  82.                 setParameter(object, "setDataNotifica", AllarmeNotifica.model().DATA_NOTIFICA.getFieldType(),
  83.                     this.getObjectFromMap(map,"data-notifica"));
  84.                 setParameter(object, "setOldStato", AllarmeNotifica.model().OLD_STATO.getFieldType(),
  85.                     this.getObjectFromMap(map,"old-stato"));
  86.                 setParameter(object, "setOldDettaglioStato", AllarmeNotifica.model().OLD_DETTAGLIO_STATO.getFieldType(),
  87.                     this.getObjectFromMap(map,"old-dettaglio-stato"));
  88.                 setParameter(object, "setNuovoStato", AllarmeNotifica.model().NUOVO_STATO.getFieldType(),
  89.                     this.getObjectFromMap(map,"nuovo-stato"));
  90.                 setParameter(object, "setNuovoDettaglioStato", AllarmeNotifica.model().NUOVO_DETTAGLIO_STATO.getFieldType(),
  91.                     this.getObjectFromMap(map,"nuovo-dettaglio-stato"));
  92.                 setParameter(object, "setHistoryEntry", AllarmeNotifica.model().HISTORY_ENTRY.getFieldType(),
  93.                     this.getObjectFromMap(map,"history-entry"));
  94.                 return object;
  95.             }
  96.            
  97.             else{
  98.                 throw new ServiceException("Model ["+model.toString()+"] not supported by fetch: "+this.getClass().getName());
  99.             }  
  100.                    
  101.         }catch(Exception e){
  102.             throw new ServiceException("Model ["+model.toString()+"] occurs error in fetch: "+e.getMessage(),e);
  103.         }
  104.        
  105.     }
  106.    
  107.    
  108.     @Override
  109.     public IKeyGeneratorObject getKeyGeneratorObject( IModel<?> model )  throws ServiceException {
  110.        
  111.         try{

  112.             if(model.equals(AllarmeNotifica.model())){
  113.                 return new org.openspcoop2.utils.jdbc.CustomKeyGeneratorObject(CostantiDB.ALLARMI_NOTIFICHE,"id","seq_"+CostantiDB.ALLARMI_NOTIFICHE,CostantiDB.ALLARMI_NOTIFICHE+"_init_seq");
  114.             }
  115.            
  116.             else{
  117.                 throw new ServiceException("Model ["+model.toString()+"] not supported by getKeyGeneratorObject: "+this.getClass().getName());
  118.             }

  119.         }catch(Exception e){
  120.             throw new ServiceException("Model ["+model.toString()+"] occurs error in getKeyGeneratorObject: "+e.getMessage(),e);
  121.         }
  122.        
  123.     }

  124. }