1 30 31 32 package org.hsqldb.jdbc; 33 34 import java.lang.reflect.Method ; 35 import java.lang.reflect.Modifier ; 36 import java.sql.ParameterMetaData ; 37 import java.sql.SQLException ; 38 39 import org.hsqldb.Result; 40 import org.hsqldb.Trace; 41 import org.hsqldb.Types; 42 43 46 54 public class jdbcParameterMetaData implements ParameterMetaData { 55 56 57 Result.ResultMetaData rmd; 58 59 60 int[] types; 61 62 63 int[] modes; 64 65 66 boolean[] isIdentity; 67 68 69 int[] nullability; 70 71 83 String [] classNames; 84 85 86 int parameterCount; 87 88 94 jdbcParameterMetaData(Result r) throws SQLException { 95 96 if (r == null) { 97 parameterCount = 0; 98 99 return; 100 } 101 102 rmd = r.metaData; 103 types = rmd.colTypes; 104 parameterCount = types.length; 105 nullability = rmd.colNullable; 106 isIdentity = rmd.isIdentity; 107 classNames = rmd.classNames; 108 modes = rmd.paramMode; 109 } 110 111 119 void checkRange(int param) throws SQLException { 120 121 if (param < 1 || param > parameterCount) { 122 String msg = param + " is out of range"; 123 124 throw Util.sqlException(Trace.INVALID_JDBC_ARGUMENT, msg); 125 } 126 } 127 128 141 public String getParameterClassName(int param) throws SQLException { 142 143 checkRange(param); 144 145 return classNames[--param]; 146 } 147 148 156 public int getParameterCount() throws SQLException { 157 return parameterCount; 158 } 159 160 172 public int getParameterMode(int param) throws SQLException { 173 174 checkRange(param); 175 176 return modes[--param]; 177 } 178 179 188 public int getParameterType(int param) throws SQLException { 189 190 int t; 191 192 checkRange(param); 193 194 t = types[--param]; 195 196 return t == Types.VARCHAR_IGNORECASE ? Types.VARCHAR 197 : t; 198 } 199 200 211 public String getParameterTypeName(int param) throws SQLException { 212 213 int t; 214 int ts; 215 216 checkRange(param); 217 218 return Types.getTypeName(types[--param]); 219 } 220 221 229 public int getPrecision(int param) throws SQLException { 230 231 checkRange(param); 232 233 return Types.getPrecision(types[--param]); 239 } 240 241 250 public int getScale(int param) throws SQLException { 251 252 checkRange(param); 253 254 return 0; 259 } 260 261 272 public int isNullable(int param) throws SQLException { 273 274 checkRange(param); 275 276 return nullability[--param]; 277 } 278 279 288 public boolean isSigned(int param) throws SQLException { 289 290 checkRange(param); 291 292 Boolean b = Types.isUnsignedAttribute(types[--param]); 293 294 return b != null &&!b.booleanValue() &&!isIdentity[param]; 295 } 296 297 302 public String toString() { 303 304 try { 305 return toStringImpl(); 306 } catch (Throwable t) { 307 return super.toString() + "[toStringImpl_exception=" + t + "]"; 308 } 309 } 310 311 317 private String toStringImpl() throws Exception { 318 319 StringBuffer sb; 320 Method [] methods; 321 Method method; 322 int count; 323 324 sb = new StringBuffer (); 325 326 sb.append(super.toString()); 327 328 count = getParameterCount(); 329 330 if (count == 0) { 331 sb.append("[parameterCount=0]"); 332 333 return sb.toString(); 334 } 335 336 methods = getClass().getDeclaredMethods(); 337 338 sb.append('['); 339 340 int len = methods.length; 341 342 for (int i = 0; i < count; i++) { 343 sb.append('\n'); 344 sb.append(" parameter_"); 345 sb.append(i + 1); 346 sb.append('='); 347 sb.append('['); 348 349 for (int j = 0; j < len; j++) { 350 method = methods[j]; 351 352 if (!Modifier.isPublic(method.getModifiers())) { 353 continue; 354 } 355 356 if (method.getParameterTypes().length != 1) { 357 continue; 358 } 359 360 sb.append(method.getName()); 361 sb.append('='); 362 sb.append(method.invoke(this, 363 new Object []{ new Integer (i + 1) })); 364 365 if (j + 1 < len) { 366 sb.append(','); 367 sb.append(' '); 368 } 369 } 370 371 sb.append(']'); 372 373 if (i + 1 < count) { 374 sb.append(','); 375 sb.append(' '); 376 } 377 } 378 379 sb.append('\n'); 380 sb.append(']'); 381 382 return sb.toString(); 383 } 384 } 385 | Popular Tags |