CredenzialeMittenteFetch.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.transazioni.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.transazioni.CredenzialeMittente;


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

  73.             if(model.equals(CredenzialeMittente.model())){
  74.                 CredenzialeMittente object = new CredenzialeMittente();
  75.                 setParameter(object, "setId", Long.class,
  76.                     this.getObjectFromMap(map,"id"));
  77.                 setParameter(object, "setTipo", CredenzialeMittente.model().TIPO.getFieldType(),
  78.                     this.getObjectFromMap(map,"tipo"));
  79.                 setParameter(object, "setCredenziale", CredenzialeMittente.model().CREDENZIALE.getFieldType(),
  80.                     this.getObjectFromMap(map,"credenziale"));
  81.                 setParameter(object, "setOraRegistrazione", CredenzialeMittente.model().ORA_REGISTRAZIONE.getFieldType(),
  82.                     this.getObjectFromMap(map,"ora-registrazione"));
  83.                 setParameter(object, "setRefCredenziale", CredenzialeMittente.model().REF_CREDENZIALE.getFieldType(),
  84.                     this.getObjectFromMap(map,"ref-credenziale"));
  85.                 return object;
  86.             }
  87.            
  88.             else{
  89.                 throw new ServiceException("Model ["+model.toString()+"] not supported by fetch: "+this.getClass().getName());
  90.             }  
  91.                    
  92.         }catch(Exception e){
  93.             throw new ServiceException("Model ["+model.toString()+"] occurs error in fetch: "+e.getMessage(),e);
  94.         }
  95.        
  96.     }
  97.    
  98.    
  99.     @Override
  100.     public IKeyGeneratorObject getKeyGeneratorObject( IModel<?> model )  throws ServiceException {
  101.        
  102.         try{

  103.             if(model.equals(CredenzialeMittente.model())){
  104.                 return new org.openspcoop2.utils.jdbc.CustomKeyGeneratorObject("credenziale_mittente","id","seq_credenziale_mittente","credenziale_mittente_init_seq");
  105.             }
  106.            
  107.             else{
  108.                 throw new ServiceException("Model ["+model.toString()+"] not supported by getKeyGeneratorObject: "+this.getClass().getName());
  109.             }

  110.         }catch(Exception e){
  111.             throw new ServiceException("Model ["+model.toString()+"] occurs error in getKeyGeneratorObject: "+e.getMessage(),e);
  112.         }
  113.        
  114.     }

  115. }