1 package in.co.daffodil.db.jdbc; 2 3 import java.sql.*; 4 import com.daffodilwoods.database.general.*; 5 import com.daffodilwoods.database.resource.*; 6 import com.daffodilwoods.daffodildb.server.sql99.common.ParameterInfo; 7 import com.daffodilwoods.database.general.ParameterMetaData; 8 9 15 16 public class DaffodilDBParameterMetaData 17 implements java.sql.ParameterMetaData { 18 19 final static int PARAMETER_OFFSET = 1; 20 DaffodilDBConnection connection; 21 _ParameterMetaData serverParameterMetaData; 22 int parameterCount; 23 private boolean isUDFParameterMetaData ; 24 25 26 27 public DaffodilDBParameterMetaData(DaffodilDBConnection con, 28 _ParameterMetaData parameterMetaData , Boolean isUDF) throws 29 SQLException { 30 connection = con; 31 serverParameterMetaData = parameterMetaData; 32 isUDFParameterMetaData = isUDF.booleanValue(); 33 try { 34 if (isUDFParameterMetaData) 35 populateParameterMataDataForUDF(); 36 parameterCount = serverParameterMetaData.getParameterCount(); 37 } 38 catch (DException ex) { 39 throw ex.getSqlException(connection.getLocale()); 40 } 41 } 42 43 52 public int getParameterCount() throws SQLException { 53 return parameterCount; 54 } 55 56 67 public int isNullable(int param) throws SQLException { 68 checkParameterIndex(param); 69 return parameterNullableUnknown; 70 } 71 72 76 77 81 82 86 87 95 public boolean isSigned(int param) throws SQLException{ 96 checkParameterIndex(param); 97 return false; 98 } 99 100 108 public int getPrecision(int param) throws SQLException { 109 checkParameterIndex(param); 110 return -1; 111 } 112 113 121 public int getScale(int param) throws SQLException { 122 checkParameterIndex(param); 123 return -1; 124 } 125 126 135 public int getParameterType(int param) throws SQLException { 136 checkParameterIndex(param); 137 try { 138 139 int dbType = serverParameterMetaData.getParameterDataType(param-PARAMETER_OFFSET); 140 return Utilities.getCorrespondingSqlTypeOfDatabaseType(dbType); 141 } 142 catch (DException ex) { 143 throw ex.getSqlException(connection.getLocale()); 144 } 145 } 146 147 156 public String getParameterTypeName(int param) throws SQLException { 157 checkParameterIndex(param); 158 try { 159 160 int dbType = serverParameterMetaData.getParameterDataType(param-PARAMETER_OFFSET); 161 return Utilities.getDataBaseTypeName(dbType); 162 } 163 catch (DException ex) { 164 throw ex.getSqlException(connection.getLocale()); 165 } 166 } 167 168 181 public String getParameterClassName(int param) throws SQLException { 182 return Utilities.getCorrespondingJavaClassesOfSqlTypes( 183 getParameterType(param)); 184 } 185 186 189 190 193 194 197 198 201 202 214 215 public int getParameterMode(int param) throws SQLException { 216 try { 217 218 ParameterInfo[] pi = serverParameterMetaData.getParameterInfo(); 219 String mode = pi[param - 1].getParameterMode(); 220 if (mode != null) { 221 if (mode.equalsIgnoreCase("in")) 222 return parameterModeIn; 223 if (mode.equalsIgnoreCase("out")) 224 return parameterModeOut; 225 if (mode.equalsIgnoreCase("inout")) 226 return parameterModeInOut; 227 } 228 229 } catch (DException ex) { 230 throw ex.getSqlException(connection.getLocale()); 231 } 232 return parameterModeUnknown; 233 } 234 235 239 240 private void checkParameterIndex(int paramIndex) throws SQLException { 241 if(paramIndex < 1 || paramIndex > parameterCount ) { 242 DException dex = new DException("DSE479", new Object []{new Integer (paramIndex), new Integer (parameterCount)}); 243 throw dex.getSqlException(connection.getLocale()); 244 } 245 } 246 250 private void populateParameterMataDataForUDF() throws DException{ 251 ParameterInfo udfParamInfo[] = serverParameterMetaData.getParameterInfo(); 252 if(udfParamInfo.length == 1){ 253 return ; 254 } 255 ParameterInfo []paramInfo = new ParameterInfo[udfParamInfo.length]; 256 System.arraycopy(udfParamInfo,udfParamInfo.length,paramInfo,0,1); System.arraycopy(udfParamInfo,0,paramInfo,1,udfParamInfo.length -1 ); serverParameterMetaData = new com.daffodilwoods.database.general.ParameterMetaData(serverParameterMetaData.getQuery(),paramInfo); 259 } 260 } 261 | Popular Tags |