1 23 24 package org.objectweb.jorm.mapper.rdb.genclass; 25 26 import org.objectweb.jorm.api.PExceptionIO; 27 import org.objectweb.jorm.api.PException; 28 import org.objectweb.jorm.mapper.rdb.adapter.api.RdbAdapter; 29 import org.objectweb.jorm.naming.api.PNameGetter; 30 import org.objectweb.jorm.genclass.api.FieldDesc; 31 import org.objectweb.jorm.type.api.PExceptionTyping; 32 import org.objectweb.jorm.type.api.PType; 33 34 import java.sql.ResultSet ; 35 import java.sql.SQLException ; 36 import java.sql.PreparedStatement ; 37 import java.util.Date ; 38 import java.math.BigInteger ; 39 import java.math.BigDecimal ; 40 41 47 48 class RdbGenClassNameGetter implements PNameGetter { 49 53 protected ResultSet resultSet; 54 57 protected FieldDesc[] elemFields; 58 59 protected PreparedStatement ps; 60 61 protected RdbAdapter adapter; 62 63 protected int startIndex = 0; 64 65 69 RdbGenClassNameGetter(PreparedStatement ps, 70 ResultSet rs, 71 FieldDesc[] rfds, 72 int startIndex, 73 RdbAdapter adapter) { 74 resultSet = rs; 75 elemFields = rfds; 76 this.ps = ps; 77 this.startIndex = startIndex; 78 this.adapter = adapter; 79 } 80 81 protected void finalize() throws Throwable { 82 if (resultSet != null) 83 resultSet.close(); 84 if (ps != null) 85 ps.close(); 86 super.finalize(); 87 } 88 89 98 public byte pngetByteField(String fn, Object ctx) 99 throws PExceptionTyping, PExceptionIO { 100 try { 101 for (short i = 1; i < elemFields.length; i++) 102 if (fn.equals(elemFields[i].compositeName)) 103 if (elemFields[i].type.getTypeCode() == PType.TYPECODE_BYTE) 104 return adapter.getByte(resultSet, startIndex + i, (byte) -1); 105 else 106 break; 107 } catch (SQLException e) { 108 throw new PExceptionIO(e, "Problem while retreiving PNameGetter field from ResultSet: field <" + fn + ">"); 109 } 110 throw new PExceptionTyping("Wrong composite name field " + fn + " in a GenClass."); 111 } 112 113 123 public Byte pngetObyteField(String fn, Object context) throws PExceptionTyping, PExceptionIO { 124 try { 125 for (short i = 1; i < elemFields.length; i++) 126 if (fn.equals(elemFields[i].compositeName)) 127 if (elemFields[i].type.getTypeCode() 128 == PType.TYPECODE_OBJBYTE) { 129 return adapter.getObyte(resultSet, startIndex + i, null); 130 } else 131 break; 132 } catch (SQLException e) { 133 throw new PExceptionIO(e, "Problem while retreiving PNameGetter field from ResultSet: field <" + fn + ">"); 134 } 135 throw new PExceptionTyping("Wrong composite name field " + fn + " in a GenClass."); 136 } 137 138 147 public char pngetCharField(String fn, Object ctx) 148 throws PExceptionTyping, PExceptionIO { 149 try { 150 for (short i = 1; i < elemFields.length; i++) 151 if (fn.equals(elemFields[i].compositeName)) 152 if (elemFields[i].type.getTypeCode() == PType.TYPECODE_CHAR) 153 return adapter.getChar(resultSet, startIndex + i, (char) -1); 154 else 155 break; 156 } catch (SQLException e) { 157 throw new PExceptionIO(e, "Problem while retreiving PNameGetter field from ResultSet: field <" + fn + ">"); 158 } 159 throw new PExceptionTyping("Wrong composite name field " + fn + " in a GenClass."); 160 } 161 162 172 public Character pngetOcharField(String fn, Object context) throws PExceptionTyping, PExceptionIO { 173 try { 174 for (short i = 1; i < elemFields.length; i++) 175 if (fn.equals(elemFields[i].compositeName)) 176 if (elemFields[i].type.getTypeCode() 177 == PType.TYPECODE_OBJCHAR) { 178 return adapter.getOchar(resultSet, startIndex + i, null); 179 } else 180 break; 181 } catch (SQLException e) { 182 throw new PExceptionIO(e, "Problem while retreiving PNameGetter field from ResultSet: field <" + fn + ">"); 183 } 184 throw new PExceptionTyping("Wrong composite name field " + fn + " in a GenClass."); 185 } 186 187 196 public short pngetShortField(String fn, Object ctx) 197 throws PExceptionTyping, PExceptionIO { 198 try { 199 for (short i = 1; i < elemFields.length; i++) 200 if (fn.equals(elemFields[i].compositeName)) 201 if (elemFields[i].type.getTypeCode() 202 == PType.TYPECODE_SHORT) 203 return adapter.getShort(resultSet, startIndex + i, (short) -1); 204 else 205 break; 206 } catch (SQLException e) { 207 throw new PExceptionIO(e, "Problem while retreiving PNameGetter field from ResultSet: field <" + fn + ">"); 208 } 209 throw new PExceptionTyping("Wrong composite name field " + fn + " in a GenClass."); 210 } 211 212 222 public Short pngetOshortField(String fn, Object context) throws PExceptionTyping, PExceptionIO { 223 try { 224 for (short i = 1; i < elemFields.length; i++) 225 if (fn.equals(elemFields[i].compositeName)) 226 if (elemFields[i].type.getTypeCode() 227 == PType.TYPECODE_OBJSHORT) { 228 return adapter.getOshort(resultSet, startIndex + i, null); 229 } else 230 break; 231 } catch (SQLException e) { 232 throw new PExceptionIO(e, "Problem while retreiving PNameGetter field from ResultSet: field <" + fn + ">"); 233 } 234 throw new PExceptionTyping("Wrong composite name field " + fn + " in a GenClass."); 235 } 236 237 246 public int pngetIntField(String fn, Object ctx) 247 throws PExceptionTyping, PExceptionIO { 248 try { 249 for (short i = 1; i < elemFields.length; i++) 250 if (fn.equals(elemFields[i].compositeName)) 251 if (elemFields[i].type.getTypeCode() == PType.TYPECODE_INT) 252 return adapter.getInt(resultSet, startIndex + i, -1); 253 else 254 break; 255 } catch (SQLException e) { 256 throw new PExceptionIO(e, "Problem while retreiving PNameGetter field from ResultSet: field <" + fn + ">"); 257 } 258 throw new PExceptionTyping("Wrong composite name field " + fn + " in a GenClass."); 259 } 260 261 271 public Integer pngetOintField(String fn, Object ctxt) throws PExceptionTyping, PExceptionIO { 272 try { 273 for (short i = 1; i < elemFields.length; i++) 274 if (fn.equals(elemFields[i].compositeName)) 275 if (elemFields[i].type.getTypeCode() 276 == PType.TYPECODE_OBJINT) { 277 return adapter.getOint(resultSet, startIndex + i, null); 278 } else 279 break; 280 } catch (SQLException e) { 281 throw new PExceptionIO(e, "Problem while retreiving PNameGetter field from ResultSet: field <" + fn + ">"); 282 } 283 throw new PExceptionTyping("Wrong composite name field " + fn + " in a GenClass."); 284 } 285 286 295 public long pngetLongField(String fn, Object ctx) 296 throws PExceptionTyping, PExceptionIO { 297 try { 298 for (short i = 1; i < elemFields.length; i++) 299 if (fn.equals(elemFields[i].compositeName)) 300 if (elemFields[i].type.getTypeCode() == PType.TYPECODE_LONG) 301 return adapter.getLong(resultSet, startIndex + i, -1); 302 else 303 break; 304 } catch (SQLException e) { 305 throw new PExceptionIO(e, "Problem while retreiving PNameGetter field from ResultSet: field <" + fn + ">"); 306 } 307 throw new PExceptionTyping("Wrong composite name field " + fn + " in a GenClass."); 308 } 309 310 320 public Long pngetOlongField(String fn, Object ctxt) throws PExceptionTyping, PExceptionIO { 321 try { 322 for (short i = 1; i < elemFields.length; i++) 323 if (fn.equals(elemFields[i].compositeName)) 324 if (elemFields[i].type.getTypeCode() 325 == PType.TYPECODE_OBJLONG) { 326 return adapter.getOlong(resultSet, startIndex + i, null); 327 } else 328 break; 329 } catch (SQLException e) { 330 throw new PExceptionIO(e, "Problem while retreiving PNameGetter field from ResultSet: field <" + fn + ">"); 331 } 332 throw new PExceptionTyping("Wrong composite name field " + fn + " in a GenClass."); 333 } 334 335 344 public String pngetStringField(String fn, Object ctx) 345 throws PExceptionTyping, PExceptionIO { 346 try { 347 for (short i = 1; i < elemFields.length; i++) 348 if (fn.equals(elemFields[i].compositeName)) 349 if (elemFields[i].type.getTypeCode() == PType.TYPECODE_STRING) { 350 return adapter.getString(resultSet, startIndex + i, null); 351 } else 352 break; 353 } catch (SQLException e) { 354 throw new PExceptionIO(e, "Problem while retreiving PNameGetter field from ResultSet: field <" + fn + ">"); 355 } 356 throw new PExceptionTyping("Wrong composite name field " + fn + " in a GenClass."); 357 } 358 359 368 public byte[] pngetByteArrayField(String fn, Object ctx) 369 throws PExceptionTyping, PExceptionIO { 370 try { 371 for (short i = 1; i < elemFields.length; i++) 372 if (fn.equals(elemFields[i].compositeName)) 373 if (elemFields[i].type.getTypeCode() == PType.TYPECODE_BYTEARRAY) { 374 return adapter.getByteArray(resultSet, startIndex + i, null); 375 } else 376 break; 377 } catch (SQLException e) { 378 throw new PExceptionIO(e, "Problem while retreiving PNameGetter field from ResultSet: field <" + fn + ">"); 379 } 380 throw new PExceptionTyping("Wrong composite name field " + fn + " in a GenClass."); 381 } 382 383 392 public char[] pngetCharArrayField(String fn, Object ctx) 393 throws PExceptionTyping, PExceptionIO { 394 try { 395 for (short i = 1; i < elemFields.length; i++) 396 if (fn.equals(elemFields[i].compositeName)) 397 if (elemFields[i].type.getTypeCode() == PType.TYPECODE_CHARARRAY) { 398 return adapter.getCharArray(resultSet, startIndex + i, null); 399 } else 400 break; 401 } catch (Exception e) { 402 throw new PExceptionIO(e, "Problem while retreiving PNameGetter field from ResultSet: field <" + fn + ">"); 403 } 404 throw new PExceptionTyping("Wrong composite name field " + fn + " in a GenClass."); 405 } 406 407 417 public Date pngetDateField(String fn, Object ctxt) throws PExceptionTyping, PExceptionIO { 418 try { 419 for (short i = 1; i < elemFields.length; i++) 420 if (fn.equals(elemFields[i].compositeName)) 421 if (elemFields[i].type.getTypeCode() 422 == PType.TYPECODE_DATE) { 423 return adapter.getDate(resultSet, startIndex + i, null); 424 } else 425 break; 426 } catch (SQLException e) { 427 throw new PExceptionIO(e, "Problem while retreiving PNameGetter field from ResultSet: field <" + fn + ">"); 428 } 429 throw new PExceptionTyping("Wrong composite name field " + fn + " in a GenClass."); 430 } 431 432 443 public BigInteger pngetBigIntegerField(String fn, Object ctxt) throws PException { 444 try { 445 for (short i = 1; i < elemFields.length; i++) 446 if (fn.equals(elemFields[i].compositeName)) 447 if (elemFields[i].type.getTypeCode() 448 == PType.TYPECODE_BIGINTEGER) { 449 return adapter.getBigInteger(resultSet, startIndex + i, null); 450 } else 451 break; 452 } catch (SQLException e) { 453 throw new PExceptionIO(e, "Problem while retreiving PNameGetter field from ResultSet: field <" + fn + ">"); 454 } 455 throw new PExceptionTyping("Wrong composite name field " + fn + " in a GenClass."); 456 } 457 458 469 public BigDecimal pngetBigDecimalField(String fn, Object ctxt) throws PException { 470 try { 471 for (short i = 1; i < elemFields.length; i++) 472 if (fn.equals(elemFields[i].compositeName)) 473 if (elemFields[i].type.getTypeCode() 474 == PType.TYPECODE_BIGDECIMAL) { 475 return adapter.getBigDecimal(resultSet, startIndex + i, null); 476 } else 477 break; 478 } catch (SQLException e) { 479 throw new PExceptionIO(e, "Problem while retreiving PNameGetter field from ResultSet: field <" + fn + ">"); 480 } 481 throw new PExceptionTyping("Wrong composite name field " + fn + " in a GenClass."); 482 } 483 } 484 | Popular Tags |