ConfigurazioneRicercaFetch.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.monitor.engine.config.ricerche.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.monitor.engine.config.ricerche.ConfigurazioneRicerca;


  30. /**    
  31.  * ConfigurazioneRicercaFetch
  32.  *
  33.  * @author Poli Andrea (poli@link.it)
  34.  * @author $Author$
  35.  * @version $Rev$, $Date$
  36.  */
  37. public class ConfigurazioneRicercaFetch 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(ConfigurazioneRicerca.model())){
  45.                 ConfigurazioneRicerca object = new ConfigurazioneRicerca();
  46.                 setParameter(object, "setId", Long.class,
  47.                     jdbcParameterUtilities.readParameter(rs, "pid", Long.class));
  48.                 setParameter(object, "setIdConfigurazioneRicerca", ConfigurazioneRicerca.model().ID_CONFIGURAZIONE_RICERCA.getFieldType(),
  49.                     jdbcParameterUtilities.readParameter(rs, "id", ConfigurazioneRicerca.model().ID_CONFIGURAZIONE_RICERCA.getFieldType()));
  50.                 setParameter(object, "setEnabled", ConfigurazioneRicerca.model().ENABLED.getFieldType(),
  51.                     jdbcParameterUtilities.readParameter(rs, "enabled", ConfigurazioneRicerca.model().ENABLED.getFieldType()));
  52.                 setParameter(object, "setLabel", ConfigurazioneRicerca.model().LABEL.getFieldType(),
  53.                     jdbcParameterUtilities.readParameter(rs, "label", ConfigurazioneRicerca.model().LABEL.getFieldType()));
  54.                 return object;
  55.             }
  56.            
  57.             else{
  58.                 throw new ServiceException("Model ["+model.toString()+"] not supported by fetch: "+this.getClass().getName());
  59.             }  
  60.                    
  61.         }catch(Exception e){
  62.             throw new ServiceException("Model ["+model.toString()+"] occurs error in fetch: "+e.getMessage(),e);
  63.         }
  64.        
  65.     }
  66.    
  67.     @Override
  68.     public Object fetch(TipiDatabase tipoDatabase, IModel<?> model , Map<String,Object> map ) throws ServiceException {
  69.        
  70.         try{

  71.             if(model.equals(ConfigurazioneRicerca.model())){
  72.                 ConfigurazioneRicerca object = new ConfigurazioneRicerca();
  73.                 setParameter(object, "setId", Long.class,
  74.                     this.getObjectFromMap(map,"id"));
  75.                 setParameter(object, "setIdConfigurazioneRicerca", ConfigurazioneRicerca.model().ID_CONFIGURAZIONE_RICERCA.getFieldType(),
  76.                     this.getObjectFromMap(map,"id-configurazione-ricerca"));
  77.                 setParameter(object, "setEnabled", ConfigurazioneRicerca.model().ENABLED.getFieldType(),
  78.                     this.getObjectFromMap(map,"enabled"));
  79.                 setParameter(object, "setLabel", ConfigurazioneRicerca.model().LABEL.getFieldType(),
  80.                     this.getObjectFromMap(map,"label"));
  81.                 return object;
  82.             }
  83.            
  84.             else{
  85.                 throw new ServiceException("Model ["+model.toString()+"] not supported by fetch: "+this.getClass().getName());
  86.             }  
  87.                    
  88.         }catch(Exception e){
  89.             throw new ServiceException("Model ["+model.toString()+"] occurs error in fetch: "+e.getMessage(),e);
  90.         }
  91.        
  92.     }
  93.    
  94.    
  95.     @Override
  96.     public IKeyGeneratorObject getKeyGeneratorObject( IModel<?> model )  throws ServiceException {
  97.        
  98.         try{

  99.             if(model.equals(ConfigurazioneRicerca.model())){
  100.                 return new org.openspcoop2.utils.jdbc.CustomKeyGeneratorObject("ricerche_personalizzate","pid","seq_ricerche_personalizzate","ricerche_personalizzate_init_seq");
  101.             }
  102.            
  103.             else{
  104.                 throw new ServiceException("Model ["+model.toString()+"] not supported by getKeyGeneratorObject: "+this.getClass().getName());
  105.             }

  106.         }catch(Exception e){
  107.             throw new ServiceException("Model ["+model.toString()+"] occurs error in getKeyGeneratorObject: "+e.getMessage(),e);
  108.         }
  109.        
  110.     }

  111. }