1 7 8 package javax.sql.rowset.serial; 9 10 import java.sql.*; 11 import javax.sql.*; 12 import java.io.*; 13 import java.math.*; 14 import java.util.Map ; 15 16 45 public class SQLInputImpl implements SQLInput { 46 47 51 private boolean lastValueWasNull; 52 53 58 private int idx; 59 60 65 private Object attrib[]; 66 67 76 private Map map; 77 78 79 99 100 public SQLInputImpl(Object [] attributes, Map <String ,Class <?>> map) 101 throws SQLException 102 { 103 if ((attributes == null) || (map == null)) { 104 throw new SQLException("Cannot instantiate a SQLInputImpl " + 105 "object with null parameters"); 106 } 107 attrib = attributes; 109 idx = -1; 111 this.map = map; 113 } 114 115 116 125 private Object getNextAttribute() throws SQLException { 126 if (++idx >= attrib.length) { 127 throw new SQLException("SQLInputImpl exception: Invalid read " + 128 "position"); 129 } else { 130 return attrib[idx]; 131 } 132 } 133 134 135 141 155 public String readString() throws SQLException { 156 157 String attrib = (String )getNextAttribute(); 158 159 if (attrib == null) { 160 lastValueWasNull = true; 161 return null; 162 } else { 163 lastValueWasNull = false; 164 return attrib; 165 } 166 } 167 168 182 public boolean readBoolean() throws SQLException { 183 184 Boolean attrib = (Boolean )getNextAttribute(); 185 186 if (attrib == null) { 187 lastValueWasNull = true; 188 return false; 189 } else { 190 lastValueWasNull = false; 191 return attrib.booleanValue(); 192 } 193 } 194 195 209 public byte readByte() throws SQLException { 210 Byte attrib = (Byte )getNextAttribute(); 211 212 if (attrib == null) { 213 lastValueWasNull = true; 214 return (byte)0; 215 } else { 216 lastValueWasNull = false; 217 return attrib.byteValue(); 218 } 219 } 220 221 234 public short readShort() throws SQLException { 235 Short attrib = (Short )getNextAttribute(); 236 237 if (attrib == null) { 238 lastValueWasNull = true; 239 return (short)0; 240 } else { 241 lastValueWasNull = false; 242 return attrib.shortValue(); 243 } 244 } 245 246 259 public int readInt() throws SQLException { 260 Integer attrib = (Integer )getNextAttribute(); 261 262 if (attrib == null) { 263 lastValueWasNull = true; 264 return (int)0; 265 } else { 266 lastValueWasNull = false; 267 return attrib.intValue(); 268 } 269 } 270 271 284 public long readLong() throws SQLException { 285 Long attrib = (Long )getNextAttribute(); 286 287 if (attrib == null) { 288 lastValueWasNull = true; 289 return (long)0; 290 } else { 291 lastValueWasNull = false; 292 return attrib.longValue(); 293 } 294 } 295 296 309 public float readFloat() throws SQLException { 310 Float attrib = (Float )getNextAttribute(); 311 312 if (attrib == null) { 313 lastValueWasNull = true; 314 return (float)0; 315 } else { 316 lastValueWasNull = false; 317 return attrib.floatValue(); 318 } 319 } 320 321 334 public double readDouble() throws SQLException { 335 Double attrib = (Double )getNextAttribute(); 336 337 if (attrib == null) { 338 lastValueWasNull = true; 339 return (double)0; 340 } else { 341 lastValueWasNull = false; 342 return attrib.doubleValue(); 343 } 344 } 345 346 359 public java.math.BigDecimal readBigDecimal() throws SQLException { 360 java.math.BigDecimal attrib = (java.math.BigDecimal )getNextAttribute(); 361 362 if (attrib == null) { 363 lastValueWasNull = true; 364 return null; 365 } else { 366 lastValueWasNull = false; 367 return attrib; 368 } 369 } 370 371 384 public byte[] readBytes() throws SQLException { 385 byte[] attrib = (byte[])getNextAttribute(); 386 387 if (attrib == null) { 388 lastValueWasNull = true; 389 return null; 390 } else { 391 lastValueWasNull = false; 392 return attrib; 393 } 394 } 395 396 409 public java.sql.Date readDate() throws SQLException { 410 java.sql.Date attrib = (java.sql.Date )getNextAttribute(); 411 412 if (attrib == null) { 413 lastValueWasNull = true; 414 return null; 415 } else { 416 lastValueWasNull = false; 417 return attrib; 418 } 419 } 420 421 435 public java.sql.Time readTime() throws SQLException { 436 java.sql.Time attrib = (java.sql.Time )getNextAttribute(); 437 438 if (attrib == null) { 439 lastValueWasNull = true; 440 return null; 441 } else { 442 lastValueWasNull = false; 443 return attrib; 444 } 445 } 446 447 456 public java.sql.Timestamp readTimestamp() throws SQLException { 457 java.sql.Timestamp attrib = (java.sql.Timestamp )getNextAttribute(); 458 459 if (attrib == null) { 460 lastValueWasNull = true; 461 return null; 462 } else { 463 lastValueWasNull = false; 464 return attrib; 465 } 466 } 467 468 481 public java.io.Reader readCharacterStream() throws SQLException { 482 java.io.Reader attrib = (java.io.Reader )getNextAttribute(); 483 484 if (attrib == null) { 485 lastValueWasNull = true; 486 return null; 487 } else { 488 lastValueWasNull = false; 489 return attrib; 490 } 491 } 492 493 507 public java.io.InputStream readAsciiStream() throws SQLException { 508 java.io.InputStream attrib = (java.io.InputStream )getNextAttribute(); 509 510 if (attrib == null) { 511 lastValueWasNull = true; 512 return null; 513 } else { 514 lastValueWasNull = false; 515 return attrib; 516 } 517 } 518 519 533 public java.io.InputStream readBinaryStream() throws SQLException { 534 java.io.InputStream attrib = (java.io.InputStream )getNextAttribute(); 535 536 if (attrib == null) { 537 lastValueWasNull = true; 538 return null; 539 } else { 540 lastValueWasNull = false; 541 return attrib; 542 } 543 } 544 545 549 575 public Object readObject() throws SQLException { 576 Object attrib = (Object )getNextAttribute(); 577 578 if (attrib == null) { 579 lastValueWasNull = true; 580 return null; 581 } else { 582 lastValueWasNull = false; 583 if (attrib instanceof Struct) { 584 Struct s = (Struct)attrib; 585 Class c = (Class )map.get(s.getSQLTypeName()); 587 if (c != null) { 588 SQLData obj = null; 590 try { 591 obj = (SQLData)c.newInstance(); 592 } catch (java.lang.InstantiationException ex) { 593 throw new SQLException("Unable to instantiate: " + 594 ex.getMessage()); 595 } catch (java.lang.IllegalAccessException ex) { 596 throw new SQLException("Unable to instantiate: " + 597 ex.getMessage()); 598 } 599 Object attribs[] = s.getAttributes(map); 601 SQLInputImpl sqlInput = new SQLInputImpl (attribs, map); 603 obj.readSQL(sqlInput, s.getSQLTypeName()); 605 return (Object )obj; 606 } 607 } 608 return (Object )attrib; 609 } 610 } 611 612 622 public Ref readRef() throws SQLException { 623 Ref attrib = (Ref)getNextAttribute(); 624 625 if (attrib == null) { 626 lastValueWasNull = true; 627 return null; 628 } else { 629 lastValueWasNull = false; 630 return attrib; 631 } 632 } 633 634 651 public Blob readBlob() throws SQLException { 652 Blob attrib = (Blob)getNextAttribute(); 653 654 if (attrib == null) { 655 lastValueWasNull = true; 656 return null; 657 } else { 658 lastValueWasNull = false; 659 return attrib; 660 } 661 } 662 663 680 public Clob readClob() throws SQLException { 681 682 Clob attrib = (Clob)getNextAttribute(); 683 if (attrib == null) { 684 lastValueWasNull = true; 685 return null; 686 } else { 687 lastValueWasNull = false; 688 return attrib; 689 } 690 } 691 692 710 public Array readArray() throws SQLException { 711 Array attrib = (Array)getNextAttribute(); 712 713 if (attrib == null) { 714 lastValueWasNull = true; 715 return null; 716 } else { 717 lastValueWasNull = false; 718 return attrib; 719 } 720 } 721 722 732 public boolean wasNull() throws SQLException { 733 return lastValueWasNull; 734 } 735 736 753 public java.net.URL readURL() throws SQLException { 754 throw new SQLException("Operation not supported"); 755 } 756 757 } 758 | Popular Tags |