GenericJDBCParameterUtilities.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.sql.PreparedStatement;
  22. import java.sql.SQLException;

  23. import org.openspcoop2.generic_project.beans.IEnumeration;
  24. import org.openspcoop2.utils.TipiDatabase;
  25. import org.openspcoop2.utils.UtilsException;
  26. import org.openspcoop2.utils.jdbc.JDBCAdapterException;
  27. import org.openspcoop2.utils.sql.SQLQueryObjectException;

  28. /**
  29.  * JDBCParameterUtilities
  30.  *
  31.  * @author Poli Andrea (apoli@link.it)
  32.  * @author $Author$
  33.  * @version $Rev$, $Date$
  34.  */
  35. public class GenericJDBCParameterUtilities extends org.openspcoop2.utils.jdbc.JDBCParameterUtilities {

  36.     public GenericJDBCParameterUtilities(TipiDatabase tipoDatabaseOpenSPCoop2) throws SQLQueryObjectException, JDBCAdapterException{
  37.         super(tipoDatabaseOpenSPCoop2);
  38.     }
  39.    
  40.    
  41.     public void setParameters(PreparedStatement pstmt,JDBCObject ... params) throws SQLException, JDBCAdapterException, UtilsException{
  42.         if(params!=null){
  43.             for (int i = 0; i < params.length; i++) {
  44.                 setParameter(pstmt, (i+1), params[i]);
  45.             }
  46.         }
  47.     }
  48.    
  49.     public void setParameter(PreparedStatement pstmt,int index,JDBCObject param) throws SQLException, JDBCAdapterException, UtilsException{
  50.        
  51.         Object value = param.getObject();
  52.         Class<?> type = param.getTypeObject();
  53.        
  54.         //System.out.println("SET PARAMETER VALUE["+value+"] TYPE["+type.getName()+"]");
  55.        
  56.         if( (value!=null) && (value instanceof IEnumeration) ){
  57.             IEnumeration enumObject = (IEnumeration) value;
  58.             Object valueEnum = enumObject.getValue();
  59.             Class<?> cValueEnum = null;
  60.             if(valueEnum!=null){
  61.                 cValueEnum = valueEnum.getClass();
  62.             }
  63.             JDBCObject jdbcObject = new JDBCObject(valueEnum, cValueEnum);
  64.             setParameter(pstmt,index, jdbcObject); // ricorsione sul tipo semplice
  65.         }
  66.        
  67.         else {
  68.            
  69.             super.setParameter(pstmt, index, value, type);
  70.            
  71.         }
  72.                
  73.     }
  74.    
  75. }