ConfigurazioneServizioFetch.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.plugins.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.plugins.ConfigurazioneServizio;


  30. /**    
  31.  * ConfigurazioneServizioFetch
  32.  *
  33.  * @author Poli Andrea (poli@link.it)
  34.  * @author $Author$
  35.  * @version $Rev$, $Date$
  36.  */
  37. public class ConfigurazioneServizioFetch 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(ConfigurazioneServizio.model())){
  45.                 ConfigurazioneServizio object = new ConfigurazioneServizio();
  46.                 setParameter(object, "setId", Long.class,
  47.                     jdbcParameterUtilities.readParameter(rs, "id", Long.class));
  48.                 setParameter(object, "setAccordo", ConfigurazioneServizio.model().ACCORDO.getFieldType(),
  49.                     jdbcParameterUtilities.readParameter(rs, "accordo", ConfigurazioneServizio.model().ACCORDO.getFieldType()));
  50.                 setParameter(object, "setTipoSoggettoReferente", ConfigurazioneServizio.model().TIPO_SOGGETTO_REFERENTE.getFieldType(),
  51.                     jdbcParameterUtilities.readParameter(rs, "tipo_soggetto_referente", ConfigurazioneServizio.model().TIPO_SOGGETTO_REFERENTE.getFieldType()));
  52.                 setParameter(object, "setNomeSoggettoReferente", ConfigurazioneServizio.model().NOME_SOGGETTO_REFERENTE.getFieldType(),
  53.                     jdbcParameterUtilities.readParameter(rs, "nome_soggetto_referente", ConfigurazioneServizio.model().NOME_SOGGETTO_REFERENTE.getFieldType()));
  54.                 setParameter(object, "setVersione", ConfigurazioneServizio.model().VERSIONE.getFieldType(),
  55.                     jdbcParameterUtilities.readParameter(rs, "versione", ConfigurazioneServizio.model().VERSIONE.getFieldType()));
  56.                 setParameter(object, "setServizio", ConfigurazioneServizio.model().SERVIZIO.getFieldType(),
  57.                     jdbcParameterUtilities.readParameter(rs, "servizio", ConfigurazioneServizio.model().SERVIZIO.getFieldType()));
  58.                 return object;
  59.             }
  60.            
  61.             else{
  62.                 throw new ServiceException("Model ["+model.toString()+"] not supported by fetch: "+this.getClass().getName());
  63.             }  
  64.                    
  65.         }catch(Exception e){
  66.             throw new ServiceException("Model ["+model.toString()+"] occurs error in fetch: "+e.getMessage(),e);
  67.         }
  68.        
  69.     }
  70.    
  71.     @Override
  72.     public Object fetch(TipiDatabase tipoDatabase, IModel<?> model , Map<String,Object> map ) throws ServiceException {
  73.        
  74.         try{

  75.             if(model.equals(ConfigurazioneServizio.model())){
  76.                 ConfigurazioneServizio object = new ConfigurazioneServizio();
  77.                 setParameter(object, "setId", Long.class,
  78.                     this.getObjectFromMap(map,"id"));
  79.                 setParameter(object, "setAccordo", ConfigurazioneServizio.model().ACCORDO.getFieldType(),
  80.                     this.getObjectFromMap(map,"accordo"));
  81.                 setParameter(object, "setTipoSoggettoReferente", ConfigurazioneServizio.model().TIPO_SOGGETTO_REFERENTE.getFieldType(),
  82.                     this.getObjectFromMap(map,"tipo-soggetto-referente"));
  83.                 setParameter(object, "setNomeSoggettoReferente", ConfigurazioneServizio.model().NOME_SOGGETTO_REFERENTE.getFieldType(),
  84.                     this.getObjectFromMap(map,"nome-soggetto-referente"));
  85.                 setParameter(object, "setVersione", ConfigurazioneServizio.model().VERSIONE.getFieldType(),
  86.                     this.getObjectFromMap(map,"versione"));
  87.                 setParameter(object, "setServizio", ConfigurazioneServizio.model().SERVIZIO.getFieldType(),
  88.                     this.getObjectFromMap(map,"servizio"));
  89.                 return object;
  90.             }
  91.            
  92.             else{
  93.                 throw new ServiceException("Model ["+model.toString()+"] not supported by fetch: "+this.getClass().getName());
  94.             }  
  95.                    
  96.         }catch(Exception e){
  97.             throw new ServiceException("Model ["+model.toString()+"] occurs error in fetch: "+e.getMessage(),e);
  98.         }
  99.        
  100.     }
  101.    
  102.    
  103.     @Override
  104.     public IKeyGeneratorObject getKeyGeneratorObject( IModel<?> model )  throws ServiceException {
  105.        
  106.         try{

  107.             if(model.equals(ConfigurazioneServizio.model())){
  108.                 return new org.openspcoop2.utils.jdbc.CustomKeyGeneratorObject("plugins_conf_servizi","id","seq_plugins_conf_servizi","plugins_conf_servizi_init_seq");
  109.             }
  110.            
  111.             else{
  112.                 throw new ServiceException("Model ["+model.toString()+"] not supported by getKeyGeneratorObject: "+this.getClass().getName());
  113.             }

  114.         }catch(Exception e){
  115.             throw new ServiceException("Model ["+model.toString()+"] occurs error in getKeyGeneratorObject: "+e.getMessage(),e);
  116.         }
  117.        
  118.     }

  119. }