0N/A/*
2362N/A * Copyright (c) 2003, 2006, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
2362N/A * published by the Free Software Foundation. Oracle designates this
0N/A * particular file as subject to the "Classpath" exception as provided
2362N/A * by Oracle in the LICENSE file that accompanied this code.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
0N/A */
0N/A
0N/Apackage javax.sql.rowset.serial;
0N/A
0N/Aimport java.sql.*;
0N/Aimport javax.sql.*;
0N/Aimport java.io.*;
0N/Aimport java.math.*;
0N/Aimport java.util.Map;
0N/A
0N/A/**
0N/A * An input stream used for custom mapping user-defined types (UDTs).
0N/A * An <code>SQLInputImpl</code> object is an input stream that contains a
0N/A * stream of values that are the attributes of a UDT.
0N/A * <p>
0N/A * This class is used by the driver behind the scenes when the method
0N/A * <code>getObject</code> is called on an SQL structured or distinct type
0N/A * that has a custom mapping; a programmer never invokes
0N/A * <code>SQLInputImpl</code> methods directly. They are provided here as a
0N/A * convenience for those who write <code>RowSet</code> implementations.
0N/A * <P>
0N/A * The <code>SQLInputImpl</code> class provides a set of
0N/A * reader methods analogous to the <code>ResultSet</code> getter
0N/A * methods. These methods make it possible to read the values in an
0N/A * <code>SQLInputImpl</code> object.
0N/A * <P>
0N/A * The method <code>wasNull</code> is used to determine whether the
0N/A * the last value read was SQL <code>NULL</code>.
0N/A * <P>When the method <code>getObject</code> is called with an
0N/A * object of a class implementing the interface <code>SQLData</code>,
0N/A * the JDBC driver calls the method <code>SQLData.getSQLType</code>
0N/A * to determine the SQL type of the UDT being custom mapped. The driver
0N/A * creates an instance of <code>SQLInputImpl</code>, populating it with the
0N/A * attributes of the UDT. The driver then passes the input
0N/A * stream to the method <code>SQLData.readSQL</code>, which in turn
0N/A * calls the <code>SQLInputImpl</code> reader methods
0N/A * to read the attributes from the input stream.
0N/A * @see java.sql.SQLData
0N/A */
0N/Apublic class SQLInputImpl implements SQLInput {
0N/A
0N/A /**
0N/A * <code>true</code> if the last value returned was <code>SQL NULL</code>;
0N/A * <code>false</code> otherwise.
0N/A */
0N/A private boolean lastValueWasNull;
0N/A
0N/A /**
0N/A * The current index into the array of SQL structured type attributes
0N/A * that will be read from this <code>SQLInputImpl</code> object and
0N/A * mapped to the fields of a class in the Java programming language.
0N/A */
0N/A private int idx;
0N/A
0N/A /**
0N/A * The array of attributes to be read from this stream. The order
0N/A * of the attributes is the same as the order in which they were
0N/A * listed in the SQL definition of the UDT.
0N/A */
0N/A private Object attrib[];
0N/A
0N/A /**
0N/A * The type map to use when the method <code>readObject</code>
0N/A * is invoked. This is a <code>java.util.Map</code> object in which
0N/A * there may be zero or more entries. Each entry consists of the
0N/A * fully qualified name of a UDT (the value to be mapped) and the
0N/A * <code>Class</code> object for a class that implements
0N/A * <code>SQLData</code> (the Java class that defines how the UDT
0N/A * will be mapped).
0N/A */
0N/A private Map map;
0N/A
0N/A
0N/A /**
0N/A * Creates an <code>SQLInputImpl</code> object initialized with the
0N/A * given array of attributes and the given type map. If any of the
0N/A * attributes is a UDT whose name is in an entry in the type map,
0N/A * the attribute will be mapped according to the corresponding
0N/A * <code>SQLData</code> implementation.
0N/A *
0N/A * @param attributes an array of <code>Object</code> instances in which
0N/A * each element is an attribute of a UDT. The order of the
0N/A * attributes in the array is the same order in which
0N/A * the attributes were defined in the UDT definition.
0N/A * @param map a <code>java.util.Map</code> object containing zero or more
0N/A * entries, with each entry consisting of 1) a <code>String</code>
0N/A * giving the fully
0N/A * qualified name of the UDT and 2) the <code>Class</code> object
0N/A * for the <code>SQLData</code> implementation that defines how
0N/A * the UDT is to be mapped
0N/A * @throws SQLException if the <code>attributes</code> or the <code>map</code>
0N/A * is a <code>null</code> value
0N/A */
0N/A
0N/A public SQLInputImpl(Object[] attributes, Map<String,Class<?>> map)
0N/A throws SQLException
0N/A {
0N/A if ((attributes == null) || (map == null)) {
0N/A throw new SQLException("Cannot instantiate a SQLInputImpl " +
0N/A "object with null parameters");
0N/A }
0N/A // assign our local reference to the attribute stream
0N/A attrib = attributes;
0N/A // init the index point before the head of the stream
0N/A idx = -1;
0N/A // set the map
0N/A this.map = map;
0N/A }
0N/A
0N/A
0N/A /**
0N/A * Retrieves the next attribute in this <code>SQLInputImpl</code> object
0N/A * as an <code>Object</code> in the Java programming language.
0N/A *
0N/A * @return the next value in the input stream
0N/A * as an <code>Object</code> in the Java programming language
0N/A * @throws SQLException if the read position is located at an invalid
0N/A * position or if there are no further values in the stream
0N/A */
0N/A private Object getNextAttribute() throws SQLException {
0N/A if (++idx >= attrib.length) {
0N/A throw new SQLException("SQLInputImpl exception: Invalid read " +
0N/A "position");
0N/A } else {
0N/A return attrib[idx];
0N/A }
0N/A }
0N/A
0N/A
0N/A //================================================================
0N/A // Methods for reading attributes from the stream of SQL data.
0N/A // These methods correspond to the column-accessor methods of
0N/A // java.sql.ResultSet.
0N/A //================================================================
0N/A
0N/A /**
0N/A * Retrieves the next attribute in this <code>SQLInputImpl</code> object as
0N/A * a <code>String</code> in the Java programming language.
0N/A * <p>
0N/A * This method does not perform type-safe checking to determine if the
0N/A * returned type is the expected type; this responsibility is delegated
0N/A * to the UDT mapping as defined by a <code>SQLData</code>
0N/A * implementation.
0N/A * <p>
0N/A * @return the next attribute in this <code>SQLInputImpl</code> object;
0N/A * if the value is <code>SQL NULL</code>, return <code>null</code>
0N/A * @throws SQLException if the read position is located at an invalid
0N/A * position or if there are no further values in the stream.
0N/A */
0N/A public String readString() throws SQLException {
0N/A
0N/A String attrib = (String)getNextAttribute();
0N/A
0N/A if (attrib == null) {
0N/A lastValueWasNull = true;
0N/A return null;
0N/A } else {
0N/A lastValueWasNull = false;
0N/A return attrib;
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Retrieves the next attribute in this <code>SQLInputImpl</code> object as
0N/A * a <code>boolean</code> in the Java programming language.
0N/A * <p>
0N/A * This method does not perform type-safe checking to determine if the
0N/A * returned type is the expected type; this responsibility is delegated
0N/A * to the UDT mapping as defined by a <code>SQLData</code>
0N/A * implementation.
0N/A * <p>
0N/A * @return the next attribute in this <code>SQLInputImpl</code> object;
0N/A * if the value is <code>SQL NULL</code>, return <code>null</code>
0N/A * @throws SQLException if the read position is located at an invalid
0N/A * position or if there are no further values in the stream.
0N/A */
0N/A public boolean readBoolean() throws SQLException {
0N/A
0N/A Boolean attrib = (Boolean)getNextAttribute();
0N/A
0N/A if (attrib == null) {
0N/A lastValueWasNull = true;
0N/A return false;
0N/A } else {
0N/A lastValueWasNull = false;
0N/A return attrib.booleanValue();
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Retrieves the next attribute in this <code>SQLInputImpl</code> object as
0N/A * a <code>byte</code> in the Java programming language.
0N/A * <p>
0N/A * This method does not perform type-safe checking to determine if the
0N/A * returned type is the expected type; this responsibility is delegated
0N/A * to the UDT mapping as defined by a <code>SQLData</code>
0N/A * implementation.
0N/A * <p>
0N/A * @return the next attribute in this <code>SQLInputImpl</code> object;
0N/A * if the value is <code>SQL NULL</code>, return <code>null</code>
0N/A * @throws SQLException if the read position is located at an invalid
0N/A * position or if there are no further values in the stream
0N/A */
0N/A public byte readByte() throws SQLException {
0N/A Byte attrib = (Byte)getNextAttribute();
0N/A
0N/A if (attrib == null) {
0N/A lastValueWasNull = true;
0N/A return (byte)0;
0N/A } else {
0N/A lastValueWasNull = false;
0N/A return attrib.byteValue();
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Retrieves the next attribute in this <code>SQLInputImpl</code> object
0N/A * as a <code>short</code> in the Java programming language.
0N/A * <P>
0N/A * This method does not perform type-safe checking to determine if the
0N/A * returned type is the expected type; this responsibility is delegated
0N/A * to the UDT mapping as defined by a <code>SQLData</code> implementation.
0N/A * <P>
0N/A * @return the next attribute in this <code>SQLInputImpl</code> object;
0N/A * if the value is <code>SQL NULL</code>, return <code>null</code>
0N/A * @throws SQLException if the read position is located at an invalid
0N/A * position or if there are no more values in the stream
0N/A */
0N/A public short readShort() throws SQLException {
0N/A Short attrib = (Short)getNextAttribute();
0N/A
0N/A if (attrib == null) {
0N/A lastValueWasNull = true;
0N/A return (short)0;
0N/A } else {
0N/A lastValueWasNull = false;
0N/A return attrib.shortValue();
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Retrieves the next attribute in this <code>SQLInputImpl</code> object
0N/A * as an <code>int</code> in the Java programming language.
0N/A * <P>
0N/A * This method does not perform type-safe checking to determine if the
0N/A * returned type is the expected type; this responsibility is delegated
0N/A * to the UDT mapping as defined by a <code>SQLData</code> implementation.
0N/A * <P>
0N/A * @return the next attribute in this <code>SQLInputImpl</code> object;
0N/A * if the value is <code>SQL NULL</code>, return <code>null</code>
0N/A * @throws SQLException if the read position is located at an invalid
0N/A * position or if there are no more values in the stream
0N/A */
0N/A public int readInt() throws SQLException {
0N/A Integer attrib = (Integer)getNextAttribute();
0N/A
0N/A if (attrib == null) {
0N/A lastValueWasNull = true;
0N/A return (int)0;
0N/A } else {
0N/A lastValueWasNull = false;
0N/A return attrib.intValue();
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Retrieves the next attribute in this <code>SQLInputImpl</code> object
0N/A * as a <code>long</code> in the Java programming language.
0N/A * <P>
0N/A * This method does not perform type-safe checking to determine if the
0N/A * returned type is the expected type; this responsibility is delegated
0N/A * to the UDT mapping as defined by a <code>SQLData</code> implementation.
0N/A * <P>
0N/A * @return the next attribute in this <code>SQLInputImpl</code> object;
0N/A * if the value is <code>SQL NULL</code>, return <code>null</code>
0N/A * @throws SQLException if the read position is located at an invalid
0N/A * position or if there are no more values in the stream
0N/A */
0N/A public long readLong() throws SQLException {
0N/A Long attrib = (Long)getNextAttribute();
0N/A
0N/A if (attrib == null) {
0N/A lastValueWasNull = true;
0N/A return (long)0;
0N/A } else {
0N/A lastValueWasNull = false;
0N/A return attrib.longValue();
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Retrieves the next attribute in this <code>SQLInputImpl</code> object
0N/A * as a <code>float</code> in the Java programming language.
0N/A * <P>
0N/A * This method does not perform type-safe checking to determine if the
0N/A * returned type is the expected type; this responsibility is delegated
0N/A * to the UDT mapping as defined by a <code>SQLData</code> implementation.
0N/A * <P>
0N/A * @return the next attribute in this <code>SQLInputImpl</code> object;
0N/A * if the value is <code>SQL NULL</code>, return <code>null</code>
0N/A * @throws SQLException if the read position is located at an invalid
0N/A * position or if there are no more values in the stream
0N/A */
0N/A public float readFloat() throws SQLException {
0N/A Float attrib = (Float)getNextAttribute();
0N/A
0N/A if (attrib == null) {
0N/A lastValueWasNull = true;
0N/A return (float)0;
0N/A } else {
0N/A lastValueWasNull = false;
0N/A return attrib.floatValue();
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Retrieves the next attribute in this <code>SQLInputImpl</code> object
0N/A * as a <code>double</code> in the Java programming language.
0N/A * <P>
0N/A * This method does not perform type-safe checking to determine if the
0N/A * returned type is the expected type; this responsibility is delegated
0N/A * to the UDT mapping as defined by a <code>SQLData</code> implementation.
0N/A * <P>
0N/A * @return the next attribute in this <code>SQLInputImpl</code> object;
0N/A * if the value is <code>SQL NULL</code>, return <code>null</code>
0N/A * @throws SQLException if the read position is located at an invalid
0N/A * position or if there are no more values in the stream
0N/A */
0N/A public double readDouble() throws SQLException {
0N/A Double attrib = (Double)getNextAttribute();
0N/A
0N/A if (attrib == null) {
0N/A lastValueWasNull = true;
0N/A return (double)0;
0N/A } else {
0N/A lastValueWasNull = false;
0N/A return attrib.doubleValue();
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Retrieves the next attribute in this <code>SQLInputImpl</code> object
0N/A * as a <code>java.math.BigDecimal</code>.
0N/A * <P>
0N/A * This method does not perform type-safe checking to determine if the
0N/A * returned type is the expected type; this responsibility is delegated
0N/A * to the UDT mapping as defined by a <code>SQLData</code> implementation.
0N/A * <P>
0N/A * @return the next attribute in this <code>SQLInputImpl</code> object;
0N/A * if the value is <code>SQL NULL</code>, return <code>null</code>
0N/A * @throws SQLException if the read position is located at an invalid
0N/A * position or if there are no more values in the stream
0N/A */
0N/A public java.math.BigDecimal readBigDecimal() throws SQLException {
0N/A java.math.BigDecimal attrib = (java.math.BigDecimal)getNextAttribute();
0N/A
0N/A if (attrib == null) {
0N/A lastValueWasNull = true;
0N/A return null;
0N/A } else {
0N/A lastValueWasNull = false;
0N/A return attrib;
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Retrieves the next attribute in this <code>SQLInputImpl</code> object
0N/A * as an array of bytes.
0N/A * <p>
0N/A * This method does not perform type-safe checking to determine if the
0N/A * returned type is the expected type; this responsibility is delegated
0N/A * to the UDT mapping as defined by a <code>SQLData</code> implementation.
0N/A * <P>
0N/A * @return the next attribute in this <code>SQLInputImpl</code> object;
0N/A * if the value is <code>SQL NULL</code>, return <code>null</code>
0N/A * @throws SQLException if the read position is located at an invalid
0N/A * position or if there are no more values in the stream
0N/A */
0N/A public byte[] readBytes() throws SQLException {
0N/A byte[] attrib = (byte[])getNextAttribute();
0N/A
0N/A if (attrib == null) {
0N/A lastValueWasNull = true;
0N/A return null;
0N/A } else {
0N/A lastValueWasNull = false;
0N/A return attrib;
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Retrieves the next attribute in this <code>SQLInputImpl</code> as
0N/A * a <code>java.sql.Date</code> object.
0N/A * <P>
0N/A * This method does not perform type-safe checking to determine if the
0N/A * returned type is the expected type; this responsibility is delegated
0N/A * to the UDT mapping as defined by a <code>SQLData</code> implementation.
0N/A * <P>
0N/A * @return the next attribute in this <code>SQLInputImpl</code> object;
0N/A * if the value is <code>SQL NULL</code>, return <code>null</code>
0N/A * @throws SQLException if the read position is located at an invalid
0N/A * position or if there are no more values in the stream
0N/A */
0N/A public java.sql.Date readDate() throws SQLException {
0N/A java.sql.Date attrib = (java.sql.Date)getNextAttribute();
0N/A
0N/A if (attrib == null) {
0N/A lastValueWasNull = true;
0N/A return null;
0N/A } else {
0N/A lastValueWasNull = false;
0N/A return attrib;
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Retrieves the next attribute in this <code>SQLInputImpl</code> object as
0N/A * a <code>java.sql.Time</code> object.
0N/A * <P>
0N/A * This method does not perform type-safe checking to determine if the
0N/A * returned type is the expected type as this responsibility is delegated
0N/A * to the UDT mapping as implemented by a <code>SQLData</code>
0N/A * implementation.
0N/A *
0N/A * @return the attribute; if the value is <code>SQL NULL</code>, return
0N/A * <code>null</code>
0N/A * @throws SQLException if the read position is located at an invalid
0N/A * position; or if there are no further values in the stream.
0N/A */
0N/A public java.sql.Time readTime() throws SQLException {
0N/A java.sql.Time attrib = (java.sql.Time)getNextAttribute();
0N/A
0N/A if (attrib == null) {
0N/A lastValueWasNull = true;
0N/A return null;
0N/A } else {
0N/A lastValueWasNull = false;
0N/A return attrib;
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Retrieves the next attribute in this <code>SQLInputImpl</code> object as
0N/A * a <code>java.sql.Timestamp</code> object.
0N/A *
0N/A * @return the attribute; if the value is <code>SQL NULL</code>, return
0N/A * <code>null</code>
0N/A * @throws SQLException if the read position is located at an invalid
0N/A * position; or if there are no further values in the stream.
0N/A */
0N/A public java.sql.Timestamp readTimestamp() throws SQLException {
0N/A java.sql.Timestamp attrib = (java.sql.Timestamp)getNextAttribute();
0N/A
0N/A if (attrib == null) {
0N/A lastValueWasNull = true;
0N/A return null;
0N/A } else {
0N/A lastValueWasNull = false;
0N/A return attrib;
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Retrieves the next attribute in this <code>SQLInputImpl</code> object
0N/A * as a stream of Unicode characters.
0N/A * <P>
0N/A * This method does not perform type-safe checking to determine if the
0N/A * returned type is the expected type as this responsibility is delegated
0N/A * to the UDT mapping as implemented by a <code>SQLData</code>
0N/A * implementation.
0N/A *
0N/A * @return the attribute; if the value is <code>SQL NULL</code>, return <code>null</code>
0N/A * @throws SQLException if the read position is located at an invalid
0N/A * position; or if there are no further values in the stream.
0N/A */
0N/A public java.io.Reader readCharacterStream() throws SQLException {
0N/A java.io.Reader attrib = (java.io.Reader)getNextAttribute();
0N/A
0N/A if (attrib == null) {
0N/A lastValueWasNull = true;
0N/A return null;
0N/A } else {
0N/A lastValueWasNull = false;
0N/A return attrib;
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Returns the next attribute in this <code>SQLInputImpl</code> object
0N/A * as a stream of ASCII characters.
0N/A * <P>
0N/A * This method does not perform type-safe checking to determine if the
0N/A * returned type is the expected type as this responsibility is delegated
0N/A * to the UDT mapping as implemented by a <code>SQLData</code>
0N/A * implementation.
0N/A *
0N/A * @return the attribute; if the value is <code>SQL NULL</code>,
0N/A * return <code>null</code>
0N/A * @throws SQLException if the read position is located at an invalid
0N/A * position; or if there are no further values in the stream.
0N/A */
0N/A public java.io.InputStream readAsciiStream() throws SQLException {
0N/A java.io.InputStream attrib = (java.io.InputStream)getNextAttribute();
0N/A
0N/A if (attrib == null) {
0N/A lastValueWasNull = true;
0N/A return null;
0N/A } else {
0N/A lastValueWasNull = false;
0N/A return attrib;
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Returns the next attribute in this <code>SQLInputImpl</code> object
0N/A * as a stream of uninterpreted bytes.
0N/A * <P>
0N/A * This method does not perform type-safe checking to determine if the
0N/A * returned type is the expected type as this responsibility is delegated
0N/A * to the UDT mapping as implemented by a <code>SQLData</code>
0N/A * implementation.
0N/A *
0N/A * @return the attribute; if the value is <code>SQL NULL</code>, return
0N/A * <code>null</code>
0N/A * @throws SQLException if the read position is located at an invalid
0N/A * position; or if there are no further values in the stream.
0N/A */
0N/A public java.io.InputStream readBinaryStream() throws SQLException {
0N/A java.io.InputStream attrib = (java.io.InputStream)getNextAttribute();
0N/A
0N/A if (attrib == null) {
0N/A lastValueWasNull = true;
0N/A return null;
0N/A } else {
0N/A lastValueWasNull = false;
0N/A return attrib;
0N/A }
0N/A }
0N/A
0N/A //================================================================
0N/A // Methods for reading items of SQL user-defined types from the stream.
0N/A //================================================================
0N/A
0N/A /**
0N/A * Retrieves the value at the head of this <code>SQLInputImpl</code>
0N/A * object as an <code>Object</code> in the Java programming language. The
0N/A * actual type of the object returned is determined by the default
0N/A * mapping of SQL types to types in the Java programming language unless
0N/A * there is a custom mapping, in which case the type of the object
0N/A * returned is determined by this stream's type map.
0N/A * <P>
0N/A * The JDBC technology-enabled driver registers a type map with the stream
0N/A * before passing the stream to the application.
0N/A * <P>
0N/A * When the datum at the head of the stream is an SQL <code>NULL</code>,
0N/A * this method returns <code>null</code>. If the datum is an SQL
0N/A * structured or distinct type with a custom mapping, this method
0N/A * determines the SQL type of the datum at the head of the stream,
0N/A * constructs an object of the appropriate class, and calls the method
0N/A * <code>SQLData.readSQL</code> on that object. The <code>readSQL</code>
0N/A * method then calls the appropriate <code>SQLInputImpl.readXXX</code>
0N/A * methods to retrieve the attribute values from the stream.
0N/A *
0N/A * @return the value at the head of the stream as an <code>Object</code>
0N/A * in the Java programming language; <code>null</code> if
0N/A * the value is SQL <code>NULL</code>
0N/A * @throws SQLException if the read position is located at an invalid
0N/A * position; or if there are no further values in the stream.
0N/A */
0N/A public Object readObject() throws SQLException {
0N/A Object attrib = (Object)getNextAttribute();
0N/A
0N/A if (attrib == null) {
0N/A lastValueWasNull = true;
0N/A return null;
0N/A } else {
0N/A lastValueWasNull = false;
0N/A if (attrib instanceof Struct) {
0N/A Struct s = (Struct)attrib;
0N/A // look up the class in the map
0N/A Class c = (Class)map.get(s.getSQLTypeName());
0N/A if (c != null) {
0N/A // create new instance of the class
0N/A SQLData obj = null;
0N/A try {
0N/A obj = (SQLData)c.newInstance();
0N/A } catch (java.lang.InstantiationException ex) {
0N/A throw new SQLException("Unable to instantiate: " +
0N/A ex.getMessage());
0N/A } catch (java.lang.IllegalAccessException ex) {
0N/A throw new SQLException("Unable to instantiate: " +
0N/A ex.getMessage());
0N/A }
0N/A // get the attributes from the struct
0N/A Object attribs[] = s.getAttributes(map);
0N/A // create the SQLInput "stream"
0N/A SQLInputImpl sqlInput = new SQLInputImpl(attribs, map);
0N/A // read the values...
0N/A obj.readSQL(sqlInput, s.getSQLTypeName());
0N/A return (Object)obj;
0N/A }
0N/A }
0N/A return (Object)attrib;
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Retrieves the value at the head of this <code>SQLInputImpl</code> object
0N/A * as a <code>Ref</code> object in the Java programming language.
0N/A *
0N/A * @return a <code>Ref</code> object representing the SQL
0N/A * <code>REF</code> value at the head of the stream; if the value
0N/A * is <code>SQL NULL</code> return <code>null</code>
0N/A * @throws SQLException if the read position is located at an invalid
0N/A * position; or if there are no further values in the stream.
0N/A */
0N/A public Ref readRef() throws SQLException {
0N/A Ref attrib = (Ref)getNextAttribute();
0N/A
0N/A if (attrib == null) {
0N/A lastValueWasNull = true;
0N/A return null;
0N/A } else {
0N/A lastValueWasNull = false;
0N/A return attrib;
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Retrieves the <code>BLOB</code> value at the head of this
0N/A * <code>SQLInputImpl</code> object as a <code>Blob</code> object
0N/A * in the Java programming language.
0N/A * <P>
0N/A * This method does not perform type-safe checking to determine if the
0N/A * returned type is the expected type as this responsibility is delegated
0N/A * to the UDT mapping as implemented by a <code>SQLData</code>
0N/A * implementation.
0N/A *
0N/A * @return a <code>Blob</code> object representing the SQL
0N/A * <code>BLOB</code> value at the head of this stream;
0N/A * if the value is <code>SQL NULL</code>, return
0N/A * <code>null</code>
0N/A * @throws SQLException if the read position is located at an invalid
0N/A * position; or if there are no further values in the stream.
0N/A */
0N/A public Blob readBlob() throws SQLException {
0N/A Blob attrib = (Blob)getNextAttribute();
0N/A
0N/A if (attrib == null) {
0N/A lastValueWasNull = true;
0N/A return null;
0N/A } else {
0N/A lastValueWasNull = false;
0N/A return attrib;
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Retrieves the <code>CLOB</code> value at the head of this
0N/A * <code>SQLInputImpl</code> object as a <code>Clob</code> object
0N/A * in the Java programming language.
0N/A * <P>
0N/A * This method does not perform type-safe checking to determine if the
0N/A * returned type is the expected type as this responsibility is delegated
0N/A * to the UDT mapping as implemented by a <code>SQLData</code>
0N/A * implementation.
0N/A *
0N/A * @return a <code>Clob</code> object representing the SQL
0N/A * <code>CLOB</code> value at the head of the stream;
0N/A * if the value is <code>SQL NULL</code>, return
0N/A * <code>null</code>
0N/A * @throws SQLException if the read position is located at an invalid
0N/A * position; or if there are no further values in the stream.
0N/A */
0N/A public Clob readClob() throws SQLException {
0N/A
0N/A Clob attrib = (Clob)getNextAttribute();
0N/A if (attrib == null) {
0N/A lastValueWasNull = true;
0N/A return null;
0N/A } else {
0N/A lastValueWasNull = false;
0N/A return attrib;
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Reads an SQL <code>ARRAY</code> value from the stream and
0N/A * returns it as an <code>Array</code> object in the Java programming
0N/A * language.
0N/A * <P>
0N/A * This method does not perform type-safe checking to determine if the
0N/A * returned type is the expected type as this responsibility is delegated
0N/A * to the UDT mapping as implemented by a <code>SQLData</code>
0N/A * implementation.
0N/A *
0N/A * @return an <code>Array</code> object representing the SQL
0N/A * <code>ARRAY</code> value at the head of the stream; *
0N/A * if the value is <code>SQL NULL</code>, return
0N/A * <code>null</code>
0N/A * @throws SQLException if the read position is located at an invalid
0N/A * position; or if there are no further values in the stream.
0N/A
0N/A */
0N/A public Array readArray() throws SQLException {
0N/A Array attrib = (Array)getNextAttribute();
0N/A
0N/A if (attrib == null) {
0N/A lastValueWasNull = true;
0N/A return null;
0N/A } else {
0N/A lastValueWasNull = false;
0N/A return attrib;
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Ascertains whether the last value read from this
0N/A * <code>SQLInputImpl</code> object was <code>null</code>.
0N/A *
0N/A * @return <code>true</code> if the SQL value read most recently was
0N/A * <code>null</code>; otherwise, <code>false</code>; by default it
0N/A * will return false
0N/A * @throws SQLException if an error occurs determining the last value
0N/A * read was a <code>null</code> value or not;
0N/A */
0N/A public boolean wasNull() throws SQLException {
0N/A return lastValueWasNull;
0N/A }
0N/A
0N/A /**
0N/A * Reads an SQL <code>DATALINK</code> value from the stream and
0N/A * returns it as an <code>URL</code> object in the Java programming
0N/A * language.
0N/A * <P>
0N/A * This method does not perform type-safe checking to determine if the
0N/A * returned type is the expected type as this responsibility is delegated
0N/A * to the UDT mapping as implemented by a <code>SQLData</code>
0N/A * implementation.
0N/A *
0N/A * @return an <code>URL</code> object representing the SQL
0N/A * <code>DATALINK</code> value at the head of the stream; *
0N/A * if the value is <code>SQL NULL</code>, return
0N/A * <code>null</code>
0N/A * @throws SQLException if the read position is located at an invalid
0N/A * position; or if there are no further values in the stream.
0N/A */
0N/A public java.net.URL readURL() throws SQLException {
0N/A throw new SQLException("Operation not supported");
0N/A }
0N/A
0N/A //---------------------------- JDBC 4.0 -------------------------
0N/A
0N/A /**
0N/A * Reads an SQL <code>NCLOB</code> value from the stream and returns it as a
0N/A * <code>Clob</code> object in the Java programming language.
0N/A *
0N/A * @return a <code>NClob</code> object representing data of the SQL <code>NCLOB</code> value
0N/A * at the head of the stream; <code>null</code> if the value read is
0N/A * SQL <code>NULL</code>
0N/A * @exception SQLException if a database access error occurs
0N/A */
0N/A public NClob readNClob() throws SQLException {
0N/A throw new UnsupportedOperationException("Operation not supported");
0N/A }
0N/A
0N/A /**
0N/A * Reads the next attribute in the stream and returns it as a <code>String</code>
0N/A * in the Java programming language. It is intended for use when
0N/A * accessing <code>NCHAR</code>,<code>NVARCHAR</code>
0N/A * and <code>LONGNVARCHAR</code> columns.
0N/A *
0N/A * @return the attribute; if the value is SQL <code>NULL</code>, returns <code>null</code>
0N/A * @exception SQLException if a database access error occurs
0N/A */
0N/A public String readNString() throws SQLException {
0N/A throw new UnsupportedOperationException("Operation not supported");
0N/A }
0N/A
0N/A /**
0N/A * Reads an SQL <code>XML</code> value from the stream and returns it as a
0N/A * <code>SQLXML</code> object in the Java programming language.
0N/A *
0N/A * @return a <code>SQLXML</code> object representing data of the SQL <code>XML</code> value
0N/A * at the head of the stream; <code>null</code> if the value read is
0N/A * SQL <code>NULL</code>
0N/A * @exception SQLException if a database access error occurs
0N/A */
0N/A public SQLXML readSQLXML() throws SQLException {
0N/A throw new UnsupportedOperationException("Operation not supported");
0N/A }
0N/A
0N/A /**
0N/A * Reads an SQL <code>ROWID</code> value from the stream and returns it as a
0N/A * <code>RowId</code> object in the Java programming language.
0N/A *
0N/A * @return a <code>RowId</code> object representing data of the SQL <code>ROWID</code> value
0N/A * at the head of the stream; <code>null</code> if the value read is
0N/A * SQL <code>NULL</code>
0N/A * @exception SQLException if a database access error occurs
0N/A */
0N/A public RowId readRowId() throws SQLException {
0N/A throw new UnsupportedOperationException("Operation not supported");
0N/A }
0N/A
0N/A
0N/A}