AbstractJDBCFetch.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.generic_project.dao.jdbc.utils;


  21. import java.lang.reflect.Method;
  22. import java.util.Map;

  23. /**
  24.  * AbstractJDBCFetch
  25.  *
  26.  * @author Poli Andrea (apoli@link.it)
  27.  * @author $Author$
  28.  * @version $Rev$, $Date$
  29.  */
  30. public abstract class AbstractJDBCFetch implements IJDBCFetch {

  31.     private char charDefault;
  32.     private boolean booleanDefault;
  33.     private byte byteDefault;
  34.     private short shortDefault;
  35.     private int intDefault;
  36.     private long longDefault;
  37.     private double doubleDefault;
  38.     private float floatDefault;
  39.    
  40.     protected Object getObjectFromMap(Map<String,Object> map,String name){
  41.         if(map==null){
  42.             return null;
  43.         }
  44.         else if(map.containsKey(name)){
  45.             Object o = map.get(name);
  46.             if(o instanceof org.apache.commons.lang.ObjectUtils.Null){
  47.                 return null;
  48.             }
  49.             else{
  50.                 return o;
  51.             }
  52.         }
  53.         else{
  54.             return null;
  55.         }
  56.     }
  57.    
  58.     protected void setParameter(Object o,String nomeMetodo,Class<?> tipoParametroMetodo,Object value) throws Exception{
  59. //      if(value!=null)
  60. //          System.out.println("Get Metodo ["+nomeMetodo+"] Object["+o.getClass().getName()+"] valore["+value.getClass().getName()+"]");
  61. //      else{
  62. //          System.out.println("Get Metodo ["+nomeMetodo+"] Object["+o.getClass().getName()+"] valore["+null+"]");
  63. //      }
  64.         Method m = o.getClass().getMethod(nomeMetodo, tipoParametroMetodo);
  65. //      System.out.println("Invoco Metodo ["+nomeMetodo+"] Object["+o.getClass().getName()+"] valore["+value+"]");
  66.        
  67.         if(value!=null){
  68.             m.invoke(o, value);
  69.         }
  70.         else{
  71.            
  72.             // NOTA: il set va fatto comunque per annullare il valore precedente.
  73.        
  74.             String tipoParametroMetodoName = tipoParametroMetodo.getName()+"";
  75.            
  76.             if(tipoParametroMetodoName.equals(char.class.getName())){
  77.                 m.invoke(o, this.charDefault);
  78.             }
  79.             else if(tipoParametroMetodoName.equals(boolean.class.getName())){
  80.                 m.invoke(o, this.booleanDefault);
  81.             }
  82.             else if(tipoParametroMetodoName.equals(byte.class.getName())){
  83.                 m.invoke(o, this.byteDefault);      
  84.             }
  85.             else if(tipoParametroMetodoName.equals(short.class.getName())){
  86.                 m.invoke(o, this.shortDefault);    
  87.             }
  88.             else if(tipoParametroMetodoName.equals(int.class.getName())){
  89.                 m.invoke(o, this.intDefault);      
  90.             }
  91.             else if(tipoParametroMetodoName.equals(long.class.getName())){
  92.                 m.invoke(o, this.longDefault);      
  93.             }
  94.             else if(tipoParametroMetodoName.equals(double.class.getName())){
  95.                 m.invoke(o, this.doubleDefault);    
  96.             }
  97.             else if(tipoParametroMetodoName.equals(float.class.getName())){
  98.                 m.invoke(o, this.floatDefault);
  99.             }
  100.             else{
  101.                 m.invoke(o, value);
  102.             }
  103.            
  104.         }
  105.        
  106.     }

  107. }