AllarmeHistoryFetch.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.AllarmeHistory;
  30. import org.openspcoop2.core.constants.CostantiDB;


  31. /**    
  32.  * AllarmeHistoryFetch
  33.  *
  34.  * @author Poli Andrea (poli@link.it)
  35.  * @author $Author$
  36.  * @version $Rev$, $Date$
  37.  */
  38. public class AllarmeHistoryFetch 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(AllarmeHistory.model())){
  46.                 AllarmeHistory object = new AllarmeHistory();
  47.                 setParameter(object, "setId", Long.class,
  48.                     jdbcParameterUtilities.readParameter(rs, "id", Long.class));
  49.                 setParameter(object, "setEnabled", AllarmeHistory.model().ENABLED.getFieldType(),
  50.                     jdbcParameterUtilities.readParameter(rs, "enabled", AllarmeHistory.model().ENABLED.getFieldType()));
  51.                 setParameter(object, "setStato", AllarmeHistory.model().STATO.getFieldType(),
  52.                     jdbcParameterUtilities.readParameter(rs, "stato", AllarmeHistory.model().STATO.getFieldType()));
  53.                 setParameter(object, "setDettaglioStato", AllarmeHistory.model().DETTAGLIO_STATO.getFieldType(),
  54.                     jdbcParameterUtilities.readParameter(rs, "stato_dettaglio", AllarmeHistory.model().DETTAGLIO_STATO.getFieldType()));
  55.                 setParameter(object, "setAcknowledged", AllarmeHistory.model().ACKNOWLEDGED.getFieldType(),
  56.                     jdbcParameterUtilities.readParameter(rs, "acknowledged", AllarmeHistory.model().ACKNOWLEDGED.getFieldType()));
  57.                 setParameter(object, "setTimestampUpdate", AllarmeHistory.model().TIMESTAMP_UPDATE.getFieldType(),
  58.                     jdbcParameterUtilities.readParameter(rs, "timestamp_update", AllarmeHistory.model().TIMESTAMP_UPDATE.getFieldType()));
  59.                 setParameter(object, "setUtente", AllarmeHistory.model().UTENTE.getFieldType(),
  60.                     jdbcParameterUtilities.readParameter(rs, "utente", AllarmeHistory.model().UTENTE.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(AllarmeHistory.model())){
  79.                 AllarmeHistory object = new AllarmeHistory();
  80.                 setParameter(object, "setId", Long.class,
  81.                     this.getObjectFromMap(map,"id"));
  82.                 setParameter(object, "setEnabled", AllarmeHistory.model().ENABLED.getFieldType(),
  83.                     this.getObjectFromMap(map,"enabled"));
  84.                 setParameter(object, "setStato", AllarmeHistory.model().STATO.getFieldType(),
  85.                     this.getObjectFromMap(map,"stato"));
  86.                 setParameter(object, "setDettaglioStato", AllarmeHistory.model().DETTAGLIO_STATO.getFieldType(),
  87.                     this.getObjectFromMap(map,"dettaglio-stato"));
  88.                 setParameter(object, "setAcknowledged", AllarmeHistory.model().ACKNOWLEDGED.getFieldType(),
  89.                     this.getObjectFromMap(map,"acknowledged"));
  90.                 setParameter(object, "setTimestampUpdate", AllarmeHistory.model().TIMESTAMP_UPDATE.getFieldType(),
  91.                     this.getObjectFromMap(map,"timestamp-update"));
  92.                 setParameter(object, "setUtente", AllarmeHistory.model().UTENTE.getFieldType(),
  93.                     this.getObjectFromMap(map,"utente"));
  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(AllarmeHistory.model())){
  113.                 return new org.openspcoop2.utils.jdbc.CustomKeyGeneratorObject(CostantiDB.ALLARMI_HISTORY,"id","seq_allarmi_history","allarmi_history_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. }