GruppoFetch.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.commons.search.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.commons.search.Gruppo;
  30. import org.openspcoop2.core.constants.CostantiDB;


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

  70.             if(model.equals(Gruppo.model())){
  71.                 Gruppo object = new Gruppo();
  72.                 setParameter(object, "setId", Long.class,
  73.                     this.getObjectFromMap(map,"id"));
  74.                 setParameter(object, "setNome", Gruppo.model().NOME.getFieldType(),
  75.                     this.getObjectFromMap(map,"nome"));
  76.                 setParameter(object, "setServiceBinding", Gruppo.model().SERVICE_BINDING.getFieldType(),
  77.                     this.getObjectFromMap(map,"service-binding"));
  78.                 return object;
  79.             }
  80.            
  81.             else{
  82.                 throw new ServiceException("Model ["+model.toString()+"] not supported by fetch: "+this.getClass().getName());
  83.             }  
  84.                    
  85.         }catch(Exception e){
  86.             throw new ServiceException("Model ["+model.toString()+"] occurs error in fetch: "+e.getMessage(),e);
  87.         }
  88.        
  89.     }
  90.    
  91.    
  92.     @Override
  93.     public IKeyGeneratorObject getKeyGeneratorObject( IModel<?> model )  throws ServiceException {
  94.        
  95.         try{

  96.             if(model.equals(Gruppo.model())){
  97.                 return new org.openspcoop2.utils.jdbc.CustomKeyGeneratorObject(CostantiDB.GRUPPI,"id","seq_"+CostantiDB.GRUPPI,CostantiDB.GRUPPI+"_init_seq");
  98.             }
  99.            
  100.             else{
  101.                 throw new ServiceException("Model ["+model.toString()+"] not supported by getKeyGeneratorObject: "+this.getClass().getName());
  102.             }

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

  108. }