1 /*
   2  * Copyright (c) 2003, 2013, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 package javax.sql.rowset.serial;
  26 
  27 import java.net.URL;
  28 import java.sql.*;
  29 import java.util.Arrays;
  30 import java.util.Map;
  31 
  32 /**
  33  * An input stream used for custom mapping user-defined types (UDTs).
  34  * An <code>SQLInputImpl</code> object is an input stream that contains a
  35  * stream of values that are the attributes of a UDT.
  36  * <p>
  37  * This class is used by the driver behind the scenes when the method
  38  * <code>getObject</code> is called on an SQL structured or distinct type
  39  * that has a custom mapping; a programmer never invokes
  40  * <code>SQLInputImpl</code> methods directly. They are provided here as a
  41  * convenience for those who write <code>RowSet</code> implementations.
  42  * <P>
  43  * The <code>SQLInputImpl</code> class provides a set of
  44  * reader methods analogous to the <code>ResultSet</code> getter
  45  * methods.  These methods make it possible to read the values in an
  46  * <code>SQLInputImpl</code> object.
  47  * <P>
  48  * The method <code>wasNull</code> is used to determine whether the
  49  * the last value read was SQL <code>NULL</code>.
  50  * <P>When the method <code>getObject</code> is called with an
  51  * object of a class implementing the interface <code>SQLData</code>,
  52  * the JDBC driver calls the method <code>SQLData.getSQLType</code>
  53  * to determine the SQL type of the UDT being custom mapped. The driver
  54  * creates an instance of <code>SQLInputImpl</code>, populating it with the
  55  * attributes of the UDT.  The driver then passes the input
  56  * stream to the method <code>SQLData.readSQL</code>, which in turn
  57  * calls the <code>SQLInputImpl</code> reader methods
  58  * to read the attributes from the input stream.
  59  * @see java.sql.SQLData
  60  */
  61 public class SQLInputImpl implements SQLInput {
  62 
  63     /**
  64      * <code>true</code> if the last value returned was <code>SQL NULL</code>;
  65      * <code>false</code> otherwise.
  66      */
  67     private boolean lastValueWasNull;
  68 
  69     /**
  70      * The current index into the array of SQL structured type attributes
  71      * that will be read from this <code>SQLInputImpl</code> object and
  72      * mapped to the fields of a class in the Java programming language.
  73      */
  74     private int idx;
  75 
  76     /**
  77      * The array of attributes to be read from this stream.  The order
  78      * of the attributes is the same as the order in which they were
  79      * listed in the SQL definition of the UDT.
  80      */
  81     private Object attrib[];
  82 
  83     /**
  84      * The type map to use when the method <code>readObject</code>
  85      * is invoked. This is a <code>java.util.Map</code> object in which
  86      * there may be zero or more entries.  Each entry consists of the
  87      * fully qualified name of a UDT (the value to be mapped) and the
  88      * <code>Class</code> object for a class that implements
  89      * <code>SQLData</code> (the Java class that defines how the UDT
  90      * will be mapped).
  91      */
  92     private Map<String,Class<?>> map;
  93 
  94 
  95     /**
  96      * Creates an <code>SQLInputImpl</code> object initialized with the
  97      * given array of attributes and the given type map. If any of the
  98      * attributes is a UDT whose name is in an entry in the type map,
  99      * the attribute will be mapped according to the corresponding
 100      * <code>SQLData</code> implementation.
 101      *
 102      * @param attributes an array of <code>Object</code> instances in which
 103      *        each element is an attribute of a UDT. The order of the
 104      *        attributes in the array is the same order in which
 105      *        the attributes were defined in the UDT definition.
 106      * @param map a <code>java.util.Map</code> object containing zero or more
 107      *        entries, with each entry consisting of 1) a <code>String</code>
 108      *        giving the fully
 109      *        qualified name of the UDT and 2) the <code>Class</code> object
 110      *        for the <code>SQLData</code> implementation that defines how
 111      *        the UDT is to be mapped
 112      * @throws SQLException if the <code>attributes</code> or the <code>map</code>
 113      *        is a <code>null</code> value
 114      */
 115 
 116     public SQLInputImpl(Object[] attributes, Map<String,Class<?>> map)
 117         throws SQLException
 118     {
 119         if ((attributes == null) || (map == null)) {
 120             throw new SQLException("Cannot instantiate a SQLInputImpl " +
 121             "object with null parameters");
 122         }
 123         // assign our local reference to the attribute stream
 124         attrib = Arrays.copyOf(attributes, attributes.length);
 125         // init the index point before the head of the stream
 126         idx = -1;
 127         // set the map
 128         this.map = map;
 129     }
 130 
 131 
 132     /**
 133      * Retrieves the next attribute in this <code>SQLInputImpl</code> object
 134      * as an <code>Object</code> in the Java programming language.
 135      *
 136      * @return the next value in the input stream
 137      *         as an <code>Object</code> in the Java programming language
 138      * @throws SQLException if the read position is located at an invalid
 139      *         position or if there are no further values in the stream
 140      */
 141     private Object getNextAttribute() throws SQLException {
 142         if (++idx >= attrib.length) {
 143             throw new SQLException("SQLInputImpl exception: Invalid read " +
 144                                    "position");
 145         } else {
 146             return attrib[idx];
 147         }
 148     }
 149 
 150 
 151     //================================================================
 152     // Methods for reading attributes from the stream of SQL data.
 153     // These methods correspond to the column-accessor methods of
 154     // java.sql.ResultSet.
 155     //================================================================
 156 
 157     /**
 158      * Retrieves the next attribute in this <code>SQLInputImpl</code> object as
 159      * a <code>String</code> in the Java programming language.
 160      * <p>
 161      * This method does not perform type-safe checking to determine if the
 162      * returned type is the expected type; this responsibility is delegated
 163      * to the UDT mapping as defined by a <code>SQLData</code>
 164      * implementation.
 165      * <p>
 166      * @return the next attribute in this <code>SQLInputImpl</code> object;
 167      *     if the value is <code>SQL NULL</code>, return <code>null</code>
 168      * @throws SQLException if the read position is located at an invalid
 169      *     position or if there are no further values in the stream.
 170      */
 171     public String readString() throws SQLException {
 172 
 173         String attrib = (String)getNextAttribute();
 174 
 175         if (attrib == null) {
 176             lastValueWasNull = true;
 177             return null;
 178         } else {
 179             lastValueWasNull = false;
 180             return attrib;
 181         }
 182     }
 183 
 184     /**
 185      * Retrieves the next attribute in this <code>SQLInputImpl</code> object as
 186      * a <code>boolean</code> in the Java programming language.
 187      * <p>
 188      * This method does not perform type-safe checking to determine if the
 189      * returned type is the expected type; this responsibility is delegated
 190      * to the UDT mapping as defined by a <code>SQLData</code>
 191      * implementation.
 192      * <p>
 193      * @return the next attribute in this <code>SQLInputImpl</code> object;
 194      *     if the value is <code>SQL NULL</code>, return <code>null</code>
 195      * @throws SQLException if the read position is located at an invalid
 196      *     position or if there are no further values in the stream.
 197      */
 198     public boolean readBoolean() throws SQLException {
 199 
 200         Boolean attrib = (Boolean)getNextAttribute();
 201 
 202         if (attrib == null) {
 203             lastValueWasNull = true;
 204             return false;
 205         } else {
 206             lastValueWasNull = false;
 207             return attrib.booleanValue();
 208         }
 209     }
 210 
 211     /**
 212      * Retrieves the next attribute in this <code>SQLInputImpl</code> object as
 213      * a <code>byte</code> in the Java programming language.
 214      * <p>
 215      * This method does not perform type-safe checking to determine if the
 216      * returned type is the expected type; this responsibility is delegated
 217      * to the UDT mapping as defined by a <code>SQLData</code>
 218      * implementation.
 219      * <p>
 220      * @return the next attribute in this <code>SQLInputImpl</code> object;
 221      *     if the value is <code>SQL NULL</code>, return <code>null</code>
 222      * @throws SQLException if the read position is located at an invalid
 223      *     position or if there are no further values in the stream
 224      */
 225     public byte readByte() throws SQLException {
 226         Byte attrib = (Byte)getNextAttribute();
 227 
 228         if (attrib == null) {
 229             lastValueWasNull = true;
 230             return (byte)0;
 231         } else {
 232             lastValueWasNull = false;
 233             return attrib.byteValue();
 234         }
 235     }
 236 
 237     /**
 238      * Retrieves the next attribute in this <code>SQLInputImpl</code> object
 239      * as a <code>short</code> in the Java programming language.
 240      * <P>
 241      * This method does not perform type-safe checking to determine if the
 242      * returned type is the expected type; this responsibility is delegated
 243      * to the UDT mapping as defined by a <code>SQLData</code> implementation.
 244      * <P>
 245      * @return the next attribute in this <code>SQLInputImpl</code> object;
 246      *       if the value is <code>SQL NULL</code>, return <code>null</code>
 247      * @throws SQLException if the read position is located at an invalid
 248      *       position or if there are no more values in the stream
 249      */
 250     public short readShort() throws SQLException {
 251         Short attrib = (Short)getNextAttribute();
 252 
 253         if (attrib == null) {
 254             lastValueWasNull = true;
 255             return (short)0;
 256         } else {
 257             lastValueWasNull = false;
 258             return attrib.shortValue();
 259         }
 260     }
 261 
 262     /**
 263      * Retrieves the next attribute in this <code>SQLInputImpl</code> object
 264      * as an <code>int</code> in the Java programming language.
 265      * <P>
 266      * This method does not perform type-safe checking to determine if the
 267      * returned type is the expected type; this responsibility is delegated
 268      * to the UDT mapping as defined by a <code>SQLData</code> implementation.
 269      * <P>
 270      * @return the next attribute in this <code>SQLInputImpl</code> object;
 271      *       if the value is <code>SQL NULL</code>, return <code>null</code>
 272      * @throws SQLException if the read position is located at an invalid
 273      *       position or if there are no more values in the stream
 274      */
 275     public int readInt() throws SQLException {
 276         Integer attrib = (Integer)getNextAttribute();
 277 
 278         if (attrib == null) {
 279             lastValueWasNull = true;
 280             return 0;
 281         } else {
 282             lastValueWasNull = false;
 283             return attrib.intValue();
 284         }
 285     }
 286 
 287     /**
 288      * Retrieves the next attribute in this <code>SQLInputImpl</code> object
 289      * as a <code>long</code> in the Java programming language.
 290      * <P>
 291      * This method does not perform type-safe checking to determine if the
 292      * returned type is the expected type; this responsibility is delegated
 293      * to the UDT mapping as defined by a <code>SQLData</code> implementation.
 294      * <P>
 295      * @return the next attribute in this <code>SQLInputImpl</code> object;
 296      *       if the value is <code>SQL NULL</code>, return <code>null</code>
 297      * @throws SQLException if the read position is located at an invalid
 298      *       position or if there are no more values in the stream
 299      */
 300     public long readLong() throws SQLException {
 301         Long attrib = (Long)getNextAttribute();
 302 
 303         if (attrib == null) {
 304             lastValueWasNull = true;
 305             return (long)0;
 306         } else {
 307             lastValueWasNull = false;
 308             return attrib.longValue();
 309         }
 310     }
 311 
 312     /**
 313      * Retrieves the next attribute in this <code>SQLInputImpl</code> object
 314      * as a <code>float</code> in the Java programming language.
 315      * <P>
 316      * This method does not perform type-safe checking to determine if the
 317      * returned type is the expected type; this responsibility is delegated
 318      * to the UDT mapping as defined by a <code>SQLData</code> implementation.
 319      * <P>
 320      * @return the next attribute in this <code>SQLInputImpl</code> object;
 321      *       if the value is <code>SQL NULL</code>, return <code>null</code>
 322      * @throws SQLException if the read position is located at an invalid
 323      *       position or if there are no more values in the stream
 324      */
 325     public float readFloat() throws SQLException {
 326         Float attrib = (Float)getNextAttribute();
 327 
 328         if (attrib == null) {
 329             lastValueWasNull = true;
 330             return (float)0;
 331         } else {
 332             lastValueWasNull = false;
 333             return attrib.floatValue();
 334         }
 335     }
 336 
 337     /**
 338      * Retrieves the next attribute in this <code>SQLInputImpl</code> object
 339      * as a <code>double</code> in the Java programming language.
 340      * <P>
 341      * This method does not perform type-safe checking to determine if the
 342      * returned type is the expected type; this responsibility is delegated
 343      * to the UDT mapping as defined by a <code>SQLData</code> implementation.
 344      * <P>
 345      * @return the next attribute in this <code>SQLInputImpl</code> object;
 346      *       if the value is <code>SQL NULL</code>, return <code>null</code>
 347      * @throws SQLException if the read position is located at an invalid
 348      *       position or if there are no more values in the stream
 349      */
 350     public double readDouble() throws SQLException {
 351         Double attrib = (Double)getNextAttribute();
 352 
 353         if (attrib == null) {
 354             lastValueWasNull = true;
 355             return (double)0;
 356         } else {
 357             lastValueWasNull = false;
 358             return attrib.doubleValue();
 359         }
 360     }
 361 
 362     /**
 363      * Retrieves the next attribute in this <code>SQLInputImpl</code> object
 364      * as a <code>java.math.BigDecimal</code>.
 365      * <P>
 366      * This method does not perform type-safe checking to determine if the
 367      * returned type is the expected type; this responsibility is delegated
 368      * to the UDT mapping as defined by a <code>SQLData</code> implementation.
 369      * <P>
 370      * @return the next attribute in this <code>SQLInputImpl</code> object;
 371      *       if the value is <code>SQL NULL</code>, return <code>null</code>
 372      * @throws SQLException if the read position is located at an invalid
 373      *       position or if there are no more values in the stream
 374      */
 375     public java.math.BigDecimal readBigDecimal() throws SQLException {
 376         java.math.BigDecimal attrib = (java.math.BigDecimal)getNextAttribute();
 377 
 378         if (attrib == null) {
 379             lastValueWasNull = true;
 380             return null;
 381         } else {
 382             lastValueWasNull = false;
 383             return attrib;
 384         }
 385     }
 386 
 387     /**
 388      * Retrieves the next attribute in this <code>SQLInputImpl</code> object
 389      * as an array of bytes.
 390      * <p>
 391      * This method does not perform type-safe checking to determine if the
 392      * returned type is the expected type; this responsibility is delegated
 393      * to the UDT mapping as defined by a <code>SQLData</code> implementation.
 394      * <P>
 395      * @return the next attribute in this <code>SQLInputImpl</code> object;
 396      *       if the value is <code>SQL NULL</code>, return <code>null</code>
 397      * @throws SQLException if the read position is located at an invalid
 398      *       position or if there are no more values in the stream
 399      */
 400     public byte[] readBytes() throws SQLException {
 401         byte[] attrib = (byte[])getNextAttribute();
 402 
 403         if (attrib == null) {
 404             lastValueWasNull = true;
 405             return null;
 406         } else {
 407             lastValueWasNull = false;
 408             return attrib;
 409         }
 410     }
 411 
 412     /**
 413      * Retrieves the next attribute in this <code>SQLInputImpl</code> as
 414      * a <code>java.sql.Date</code> object.
 415      * <P>
 416      * This method does not perform type-safe checking to determine if the
 417      * returned type is the expected type; this responsibility is delegated
 418      * to the UDT mapping as defined by a <code>SQLData</code> implementation.
 419      * <P>
 420      * @return the next attribute in this <code>SQLInputImpl</code> object;
 421      *       if the value is <code>SQL NULL</code>, return <code>null</code>
 422      * @throws SQLException if the read position is located at an invalid
 423      *       position or if there are no more values in the stream
 424      */
 425     public java.sql.Date readDate() throws SQLException {
 426         java.sql.Date attrib = (java.sql.Date)getNextAttribute();
 427 
 428         if (attrib == null) {
 429             lastValueWasNull = true;
 430             return null;
 431         } else {
 432             lastValueWasNull = false;
 433             return attrib;
 434         }
 435     }
 436 
 437     /**
 438      * Retrieves the next attribute in this <code>SQLInputImpl</code> object as
 439      * a <code>java.sql.Time</code> object.
 440      * <P>
 441      * This method does not perform type-safe checking to determine if the
 442      * returned type is the expected type as this responsibility is delegated
 443      * to the UDT mapping as implemented by a <code>SQLData</code>
 444      * implementation.
 445      *
 446      * @return the attribute; if the value is <code>SQL NULL</code>, return
 447      * <code>null</code>
 448      * @throws SQLException if the read position is located at an invalid
 449      * position; or if there are no further values in the stream.
 450      */
 451     public java.sql.Time readTime() throws SQLException {
 452         java.sql.Time attrib = (java.sql.Time)getNextAttribute();
 453 
 454         if (attrib == null) {
 455             lastValueWasNull = true;
 456             return null;
 457         } else {
 458             lastValueWasNull = false;
 459             return attrib;
 460         }
 461     }
 462 
 463     /**
 464      * Retrieves the next attribute in this <code>SQLInputImpl</code> object as
 465      * a <code>java.sql.Timestamp</code> object.
 466      *
 467      * @return the attribute; if the value is <code>SQL NULL</code>, return
 468      * <code>null</code>
 469      * @throws SQLException if the read position is located at an invalid
 470      * position; or if there are no further values in the stream.
 471      */
 472     public java.sql.Timestamp readTimestamp() throws SQLException {
 473         java.sql.Timestamp attrib = (java.sql.Timestamp)getNextAttribute();
 474 
 475         if (attrib == null) {
 476             lastValueWasNull = true;
 477             return null;
 478         } else {
 479             lastValueWasNull = false;
 480             return attrib;
 481         }
 482     }
 483 
 484     /**
 485      * Retrieves the next attribute in this <code>SQLInputImpl</code> object
 486      * as a stream of Unicode characters.
 487      * <P>
 488      * This method does not perform type-safe checking to determine if the
 489      * returned type is the expected type as this responsibility is delegated
 490      * to the UDT mapping as implemented by a <code>SQLData</code>
 491      * implementation.
 492      *
 493      * @return the attribute; if the value is <code>SQL NULL</code>, return <code>null</code>
 494      * @throws SQLException if the read position is located at an invalid
 495      * position; or if there are no further values in the stream.
 496      */
 497     public java.io.Reader readCharacterStream() throws SQLException {
 498         java.io.Reader attrib = (java.io.Reader)getNextAttribute();
 499 
 500         if (attrib == null) {
 501             lastValueWasNull = true;
 502             return null;
 503         } else {
 504             lastValueWasNull = false;
 505             return attrib;
 506         }
 507     }
 508 
 509     /**
 510      * Returns the next attribute in this <code>SQLInputImpl</code> object
 511      * as a stream of ASCII characters.
 512      * <P>
 513      * This method does not perform type-safe checking to determine if the
 514      * returned type is the expected type as this responsibility is delegated
 515      * to the UDT mapping as implemented by a <code>SQLData</code>
 516      * implementation.
 517      *
 518      * @return the attribute; if the value is <code>SQL NULL</code>,
 519      * return <code>null</code>
 520      * @throws SQLException if the read position is located at an invalid
 521      * position; or if there are no further values in the stream.
 522      */
 523     public java.io.InputStream readAsciiStream() throws SQLException {
 524         java.io.InputStream attrib = (java.io.InputStream)getNextAttribute();
 525 
 526         if (attrib == null) {
 527             lastValueWasNull = true;
 528             return null;
 529         } else {
 530             lastValueWasNull = false;
 531             return attrib;
 532         }
 533     }
 534 
 535     /**
 536      * Returns the next attribute in this <code>SQLInputImpl</code> object
 537      * as a stream of uninterpreted bytes.
 538      * <P>
 539      * This method does not perform type-safe checking to determine if the
 540      * returned type is the expected type as this responsibility is delegated
 541      * to the UDT mapping as implemented by a <code>SQLData</code>
 542      * implementation.
 543      *
 544      * @return the attribute; if the value is <code>SQL NULL</code>, return
 545      * <code>null</code>
 546      * @throws SQLException if the read position is located at an invalid
 547      * position; or if there are no further values in the stream.
 548      */
 549     public java.io.InputStream readBinaryStream() throws SQLException {
 550         java.io.InputStream attrib = (java.io.InputStream)getNextAttribute();
 551 
 552         if (attrib == null) {
 553             lastValueWasNull = true;
 554             return null;
 555         } else {
 556             lastValueWasNull = false;
 557             return attrib;
 558         }
 559     }
 560 
 561     //================================================================
 562     // Methods for reading items of SQL user-defined types from the stream.
 563     //================================================================
 564 
 565     /**
 566      * Retrieves the value at the head of this <code>SQLInputImpl</code>
 567      * object as an <code>Object</code> in the Java programming language.  The
 568      * actual type of the object returned is determined by the default
 569      * mapping of SQL types to types in the Java programming language unless
 570      * there is a custom mapping, in which case the type of the object
 571      * returned is determined by this stream's type map.
 572      * <P>
 573      * The JDBC technology-enabled driver registers a type map with the stream
 574      * before passing the stream to the application.
 575      * <P>
 576      * When the datum at the head of the stream is an SQL <code>NULL</code>,
 577      * this method returns <code>null</code>.  If the datum is an SQL
 578      * structured or distinct type with a custom mapping, this method
 579      * determines the SQL type of the datum at the head of the stream,
 580      * constructs an object of the appropriate class, and calls the method
 581      * <code>SQLData.readSQL</code> on that object. The <code>readSQL</code>
 582      * method then calls the appropriate <code>SQLInputImpl.readXXX</code>
 583      * methods to retrieve the attribute values from the stream.
 584      *
 585      * @return the value at the head of the stream as an <code>Object</code>
 586      *         in the Java programming language; <code>null</code> if
 587      *         the value is SQL <code>NULL</code>
 588      * @throws SQLException if the read position is located at an invalid
 589      * position; or if there are no further values in the stream.
 590      */
 591     public Object readObject() throws SQLException {
 592         Object attrib = getNextAttribute();
 593 
 594         if (attrib == null) {
 595             lastValueWasNull = true;
 596             return null;
 597         } else {
 598             lastValueWasNull = false;
 599             if (attrib instanceof Struct) {
 600                 Struct s = (Struct)attrib;
 601                 // look up the class in the map
 602                 Class<?> c = map.get(s.getSQLTypeName());
 603                 if (c != null) {
 604                     // create new instance of the class
 605                     SQLData obj = null;
 606                     try {
 607                         obj = (SQLData)c.newInstance();
 608                     } catch (java.lang.InstantiationException ex) {
 609                         throw new SQLException("Unable to instantiate: " +
 610                                                ex.getMessage());
 611                     } catch (java.lang.IllegalAccessException ex) {
 612                         throw new SQLException("Unable to instantiate: " +
 613                                                ex.getMessage());
 614                     }
 615                     // get the attributes from the struct
 616                     Object attribs[] = s.getAttributes(map);
 617                     // create the SQLInput "stream"
 618                     SQLInputImpl sqlInput = new SQLInputImpl(attribs, map);
 619                     // read the values...
 620                     obj.readSQL(sqlInput, s.getSQLTypeName());
 621                     return obj;
 622                 }
 623             }
 624             return attrib;
 625         }
 626     }
 627 
 628     /**
 629      * Retrieves the value at the head of this <code>SQLInputImpl</code> object
 630      * as a <code>Ref</code> object in the Java programming language.
 631      *
 632      * @return a <code>Ref</code> object representing the SQL
 633      *         <code>REF</code> value at the head of the stream; if the value
 634      *         is <code>SQL NULL</code> return <code>null</code>
 635      * @throws SQLException if the read position is located at an invalid
 636      *         position; or if there are no further values in the stream.
 637      */
 638     public Ref readRef() throws SQLException {
 639         Ref attrib = (Ref)getNextAttribute();
 640 
 641         if (attrib == null) {
 642             lastValueWasNull = true;
 643             return null;
 644         } else {
 645             lastValueWasNull = false;
 646             return attrib;
 647         }
 648     }
 649 
 650     /**
 651      * Retrieves the <code>BLOB</code> value at the head of this
 652      * <code>SQLInputImpl</code> object as a <code>Blob</code> object
 653      * in the Java programming language.
 654      * <P>
 655      * This method does not perform type-safe checking to determine if the
 656      * returned type is the expected type as this responsibility is delegated
 657      * to the UDT mapping as implemented by a <code>SQLData</code>
 658      * implementation.
 659      *
 660      * @return a <code>Blob</code> object representing the SQL
 661      *         <code>BLOB</code> value at the head of this stream;
 662      *         if the value is <code>SQL NULL</code>, return
 663      *         <code>null</code>
 664      * @throws SQLException if the read position is located at an invalid
 665      * position; or if there are no further values in the stream.
 666      */
 667     public Blob readBlob() throws SQLException {
 668         Blob attrib = (Blob)getNextAttribute();
 669 
 670         if (attrib == null) {
 671             lastValueWasNull = true;
 672             return null;
 673         } else {
 674             lastValueWasNull = false;
 675             return attrib;
 676         }
 677     }
 678 
 679     /**
 680      * Retrieves the <code>CLOB</code> value at the head of this
 681      * <code>SQLInputImpl</code> object as a <code>Clob</code> object
 682      * in the Java programming language.
 683      * <P>
 684      * This method does not perform type-safe checking to determine if the
 685      * returned type is the expected type as this responsibility is delegated
 686      * to the UDT mapping as implemented by a <code>SQLData</code>
 687      * implementation.
 688      *
 689      * @return a <code>Clob</code> object representing the SQL
 690      *         <code>CLOB</code> value at the head of the stream;
 691      *         if the value is <code>SQL NULL</code>, return
 692      *         <code>null</code>
 693      * @throws SQLException if the read position is located at an invalid
 694      * position; or if there are no further values in the stream.
 695      */
 696     public Clob readClob() throws SQLException {
 697 
 698         Clob attrib = (Clob)getNextAttribute();
 699         if (attrib == null) {
 700             lastValueWasNull = true;
 701             return null;
 702         } else {
 703             lastValueWasNull = false;
 704             return attrib;
 705         }
 706     }
 707 
 708     /**
 709      * Reads an SQL <code>ARRAY</code> value from the stream and
 710      * returns it as an <code>Array</code> object in the Java programming
 711      * language.
 712      * <P>
 713      * This method does not perform type-safe checking to determine if the
 714      * returned type is the expected type as this responsibility is delegated
 715      * to the UDT mapping as implemented by a <code>SQLData</code>
 716      * implementation.
 717      *
 718      * @return an <code>Array</code> object representing the SQL
 719      *         <code>ARRAY</code> value at the head of the stream; *
 720      *         if the value is <code>SQL NULL</code>, return
 721      *         <code>null</code>
 722      * @throws SQLException if the read position is located at an invalid
 723      * position; or if there are no further values in the stream.
 724 
 725      */
 726     public Array readArray() throws SQLException {
 727         Array attrib = (Array)getNextAttribute();
 728 
 729         if (attrib == null) {
 730             lastValueWasNull = true;
 731             return null;
 732         } else {
 733             lastValueWasNull = false;
 734             return attrib;
 735         }
 736     }
 737 
 738     /**
 739      * Ascertains whether the last value read from this
 740      * <code>SQLInputImpl</code> object was <code>null</code>.
 741      *
 742      * @return <code>true</code> if the SQL value read most recently was
 743      *         <code>null</code>; otherwise, <code>false</code>; by default it
 744      *         will return false
 745      * @throws SQLException if an error occurs determining the last value
 746      *         read was a <code>null</code> value or not;
 747      */
 748     public boolean wasNull() throws SQLException {
 749         return lastValueWasNull;
 750     }
 751 
 752     /**
 753      * Reads an SQL <code>DATALINK</code> value from the stream and
 754      * returns it as an <code>URL</code> object in the Java programming
 755      * language.
 756      * <P>
 757      * This method does not perform type-safe checking to determine if the
 758      * returned type is the expected type as this responsibility is delegated
 759      * to the UDT mapping as implemented by a <code>SQLData</code>
 760      * implementation.
 761      *
 762      * @return an <code>URL</code> object representing the SQL
 763      *         <code>DATALINK</code> value at the head of the stream; *
 764      *         if the value is <code>SQL NULL</code>, return
 765      *         <code>null</code>
 766      * @throws SQLException if the read position is located at an invalid
 767      * position; or if there are no further values in the stream.
 768      */
 769     public java.net.URL readURL() throws SQLException {
 770         URL attrib = (URL)getNextAttribute();
 771 
 772         if (attrib == null) {
 773             lastValueWasNull = true;
 774             return null;
 775         } else {
 776             lastValueWasNull = false;
 777             return attrib;
 778         }
 779     }
 780 
 781     //---------------------------- JDBC 4.0 -------------------------
 782    
 783     /**
 784      * Reads an SQL <code>NCLOB</code> value from the stream and returns it as a
 785      * <code>Clob</code> object in the Java programming language.
 786      *
 787      * @return a <code>NClob</code> object representing data of the SQL <code>NCLOB</code> value
 788      * at the head of the stream; <code>null</code> if the value read is
 789      * SQL <code>NULL</code>
 790      * @exception SQLException if a database access error occurs
 791      */
 792      public NClob readNClob() throws SQLException {
 793         NClob attrib = (NClob)getNextAttribute();
 794         if (attrib == null) {
 795             lastValueWasNull = true;
 796             return null;
 797         } else {
 798             lastValueWasNull = false;
 799             return attrib;
 800         }    }
 801 
 802     /**
 803      * Reads the next attribute in the stream and returns it as a <code>String</code>
 804      * in the Java programming language. It is intended for use when
 805      * accessing  <code>NCHAR</code>,<code>NVARCHAR</code>
 806      * and <code>LONGNVARCHAR</code> columns.
 807      *
 808      * @return the attribute; if the value is SQL <code>NULL</code>, returns <code>null</code>
 809      * @exception SQLException if a database access error occurs
 810      */
 811     public String readNString() throws SQLException {
 812         String attrib = (String)getNextAttribute();
 813 
 814         if (attrib == null) {
 815             lastValueWasNull = true;
 816             return null;
 817         } else {
 818             lastValueWasNull = false;
 819             return attrib;
 820         }    }
 821 
 822     /**
 823      * Reads an SQL <code>XML</code> value from the stream and returns it as a
 824      * <code>SQLXML</code> object in the Java programming language.
 825      *
 826      * @return a <code>SQLXML</code> object representing data of the SQL <code>XML</code> value
 827      * at the head of the stream; <code>null</code> if the value read is
 828      * SQL <code>NULL</code>
 829      * @exception SQLException if a database access error occurs
 830      */
 831     public SQLXML readSQLXML() throws SQLException {
 832         SQLXML attrib = (SQLXML)getNextAttribute();
 833         if (attrib == null) {
 834             lastValueWasNull = true;
 835             return null;
 836         } else {
 837             lastValueWasNull = false;
 838             return attrib;
 839         }    }
 840 
 841     /**
 842      * Reads an SQL <code>ROWID</code> value from the stream and returns it as a
 843      * <code>RowId</code> object in the Java programming language.
 844      *
 845      * @return a <code>RowId</code> object representing data of the SQL <code>ROWID</code> value
 846      * at the head of the stream; <code>null</code> if the value read is
 847      * SQL <code>NULL</code>
 848      * @exception SQLException if a database access error occurs
 849      */
 850     public RowId readRowId() throws SQLException {
 851         RowId attrib = (RowId)getNextAttribute();
 852         if (attrib == null) {
 853             lastValueWasNull = true;
 854             return null;
 855         } else {
 856             lastValueWasNull = false;
 857             return attrib;
 858         }
 859     }
 860 
 861 
 862 }