FileDocCategorySizeDatePackage
SQLInputImpl.javaAPI DocJava SE 5 API30428Fri Aug 26 14:57:52 BST 2005javax.sql.rowset.serial

SQLInputImpl

public class SQLInputImpl extends Object implements SQLInput
An input stream used for custom mapping user-defined types (UDTs). An SQLInputImpl object is an input stream that contains a stream of values that are the attributes of a UDT.

This class is used by the driver behind the scenes when the method getObject is called on an SQL structured or distinct type that has a custom mapping; a programmer never invokes SQLInputImpl methods directly. They are provided here as a convenience for those who write RowSet implementations.

The SQLInputImpl class provides a set of reader methods analogous to the ResultSet getter methods. These methods make it possible to read the values in an SQLInputImpl object.

The method wasNull is used to determine whether the the last value read was SQL NULL.

When the method getObject is called with an object of a class implementing the interface SQLData, the JDBC driver calls the method SQLData.getSQLType to determine the SQL type of the UDT being custom mapped. The driver creates an instance of SQLInputImpl, populating it with the attributes of the UDT. The driver then passes the input stream to the method SQLData.readSQL, which in turn calls the SQLInputImpl reader methods to read the attributes from the input stream.

see
java.sql.SQLData

Fields Summary
private boolean
lastValueWasNull
true if the last value returned was SQL NULL; false otherwise.
private int
idx
The current index into the array of SQL structured type attributes that will be read from this SQLInputImpl object and mapped to the fields of a class in the Java programming language.
private Object[]
attrib
The array of attributes to be read from this stream. The order of the attributes is the same as the order in which they were listed in the SQL definition of the UDT.
private Map
map
The type map to use when the method readObject is invoked. This is a java.util.Map object in which there may be zero or more entries. Each entry consists of the fully qualified name of a UDT (the value to be mapped) and the Class object for a class that implements SQLData (the Java class that defines how the UDT will be mapped).
Constructors Summary
public SQLInputImpl(Object[] attributes, Map map)
Creates an SQLInputImpl object initialized with the given array of attributes and the given type map. If any of the attributes is a UDT whose name is in an entry in the type map, the attribute will be mapped according to the corresponding SQLData implementation.

param
attributes an array of Object instances in which each element is an attribute of a UDT. The order of the attributes in the array is the same order in which the attributes were defined in the UDT definition.
param
map a java.util.Map object containing zero or more entries, with each entry consisting of 1) a String giving the fully qualified name of the UDT and 2) the Class object for the SQLData implementation that defines how the UDT is to be mapped
throws
SQLException if the attributes or the map is a null value

        if ((attributes == null) || (map == null)) {
            throw new SQLException("Cannot instantiate a SQLInputImpl " +
            "object with null parameters");
        }        
        // assign our local reference to the attribute stream
        attrib = attributes;
        // init the index point before the head of the stream
        idx = -1;
        // set the map
        this.map = map;
    
Methods Summary
private java.lang.ObjectgetNextAttribute()
Retrieves the next attribute in this SQLInputImpl object as an Object in the Java programming language.

return
the next value in the input stream as an Object in the Java programming language
throws
SQLException if the read position is located at an invalid position or if there are no further values in the stream

        if (++idx >= attrib.length) {
            throw new SQLException("SQLInputImpl exception: Invalid read " + 
				   "position");
        } else {
            return attrib[idx];
        }
    
public java.sql.ArrayreadArray()
Reads an SQL ARRAY value from the stream and returns it as an Array object in the Java programming language.

This method does not perform type-safe checking to determine if the returned type is the expected type as this responsibility is delegated to the UDT mapping as implemented by a SQLData implementation.

return
an Array object representing the SQL ARRAY value at the head of the stream; * if the value is SQL NULL, return null
throws
SQLException if the read position is located at an invalid position; or if there are no further values in the stream.

        Array attrib = (Array)getNextAttribute();

        if (attrib == null) {
            lastValueWasNull = true;
            return null;
        } else {
            lastValueWasNull = false;
            return attrib;
        }
    
public java.io.InputStreamreadAsciiStream()
Returns the next attribute in this SQLInputImpl object as a stream of ASCII characters.

This method does not perform type-safe checking to determine if the returned type is the expected type as this responsibility is delegated to the UDT mapping as implemented by a SQLData implementation.

return
the attribute; if the value is SQL NULL, return null
throws
SQLException if the read position is located at an invalid position; or if there are no further values in the stream.

        java.io.InputStream attrib = (java.io.InputStream)getNextAttribute();

        if (attrib == null) {
            lastValueWasNull = true;
            return null;
        } else {
            lastValueWasNull = false;
            return attrib;
        }
    
public java.math.BigDecimalreadBigDecimal()
Retrieves the next attribute in this SQLInputImpl object as a java.math.BigDecimal.

This method does not perform type-safe checking to determine if the returned type is the expected type; this responsibility is delegated to the UDT mapping as defined by a SQLData implementation.

return
the next attribute in this SQLInputImpl object; if the value is SQL NULL, return null
throws
SQLException if the read position is located at an invalid position or if there are no more values in the stream

        java.math.BigDecimal attrib = (java.math.BigDecimal)getNextAttribute();

        if (attrib == null) {
            lastValueWasNull = true;
            return null;
        } else {
            lastValueWasNull = false;
            return attrib;
        }
    
public java.io.InputStreamreadBinaryStream()
Returns the next attribute in this SQLInputImpl object as a stream of uninterpreted bytes.

This method does not perform type-safe checking to determine if the returned type is the expected type as this responsibility is delegated to the UDT mapping as implemented by a SQLData implementation.

return
the attribute; if the value is SQL NULL, return null
throws
SQLException if the read position is located at an invalid position; or if there are no further values in the stream.

        java.io.InputStream attrib = (java.io.InputStream)getNextAttribute();

        if (attrib == null) {
            lastValueWasNull = true;
            return null;
        } else {
            lastValueWasNull = false;
            return attrib;
        }        
    
public java.sql.BlobreadBlob()
Retrieves the BLOB value at the head of this SQLInputImpl object as a Blob object in the Java programming language.

This method does not perform type-safe checking to determine if the returned type is the expected type as this responsibility is delegated to the UDT mapping as implemented by a SQLData implementation.

return
a Blob object representing the SQL BLOB value at the head of this stream; if the value is SQL NULL, return null
throws
SQLException if the read position is located at an invalid position; or if there are no further values in the stream.

        Blob attrib = (Blob)getNextAttribute();
        
        if (attrib == null) {
            lastValueWasNull = true;
            return null;
        } else {
            lastValueWasNull = false;
            return attrib;
        }
    
public booleanreadBoolean()
Retrieves the next attribute in this SQLInputImpl object as a boolean in the Java programming language.

This method does not perform type-safe checking to determine if the returned type is the expected type; this responsibility is delegated to the UDT mapping as defined by a SQLData implementation.

return
the next attribute in this SQLInputImpl object; if the value is SQL NULL, return null
throws
SQLException if the read position is located at an invalid position or if there are no further values in the stream.


        Boolean attrib = (Boolean)getNextAttribute();

        if (attrib == null) {
            lastValueWasNull = true;
            return false;
        } else {
            lastValueWasNull = false;
            return attrib.booleanValue();
        }
    
public bytereadByte()
Retrieves the next attribute in this SQLInputImpl object as a byte in the Java programming language.

This method does not perform type-safe checking to determine if the returned type is the expected type; this responsibility is delegated to the UDT mapping as defined by a SQLData implementation.

return
the next attribute in this SQLInputImpl object; if the value is SQL NULL, return null
throws
SQLException if the read position is located at an invalid position or if there are no further values in the stream

        Byte attrib = (Byte)getNextAttribute();

        if (attrib == null) {
            lastValueWasNull = true;
            return (byte)0;
        } else {
            lastValueWasNull = false;
            return attrib.byteValue();
        }
    
public byte[]readBytes()
Retrieves the next attribute in this SQLInputImpl object as an array of bytes.

This method does not perform type-safe checking to determine if the returned type is the expected type; this responsibility is delegated to the UDT mapping as defined by a SQLData implementation.

return
the next attribute in this SQLInputImpl object; if the value is SQL NULL, return null
throws
SQLException if the read position is located at an invalid position or if there are no more values in the stream

        byte[] attrib = (byte[])getNextAttribute();

        if (attrib == null) {
            lastValueWasNull = true;
            return null;
        } else {
            lastValueWasNull = false;
            return attrib;
        }
    
public java.io.ReaderreadCharacterStream()
Retrieves the next attribute in this SQLInputImpl object as a stream of Unicode characters.

This method does not perform type-safe checking to determine if the returned type is the expected type as this responsibility is delegated to the UDT mapping as implemented by a SQLData implementation.

return
the attribute; if the value is SQL NULL, return null
throws
SQLException if the read position is located at an invalid position; or if there are no further values in the stream.

        java.io.Reader attrib = (java.io.Reader)getNextAttribute();

        if (attrib == null) {
            lastValueWasNull = true;
            return null;
        } else {
            lastValueWasNull = false;
            return attrib;
        }
    
public java.sql.ClobreadClob()
Retrieves the CLOB value at the head of this SQLInputImpl object as a Clob object in the Java programming language.

This method does not perform type-safe checking to determine if the returned type is the expected type as this responsibility is delegated to the UDT mapping as implemented by a SQLData implementation.

return
a Clob object representing the SQL CLOB value at the head of the stream; if the value is SQL NULL, return null
throws
SQLException if the read position is located at an invalid position; or if there are no further values in the stream.


        Clob attrib = (Clob)getNextAttribute();
        if (attrib == null) {
            lastValueWasNull = true;
            return null;
        } else {
            lastValueWasNull = false;
            return attrib;
        }
    
public java.sql.DatereadDate()
Retrieves the next attribute in this SQLInputImpl as a java.sql.Date object.

This method does not perform type-safe checking to determine if the returned type is the expected type; this responsibility is delegated to the UDT mapping as defined by a SQLData implementation.

return
the next attribute in this SQLInputImpl object; if the value is SQL NULL, return null
throws
SQLException if the read position is located at an invalid position or if there are no more values in the stream

        java.sql.Date attrib = (java.sql.Date)getNextAttribute();

        if (attrib == null) {
            lastValueWasNull = true;
            return null;
        } else {
            lastValueWasNull = false;
            return attrib;
        }
    
public doublereadDouble()
Retrieves the next attribute in this SQLInputImpl object as a double in the Java programming language.

This method does not perform type-safe checking to determine if the returned type is the expected type; this responsibility is delegated to the UDT mapping as defined by a SQLData implementation.

return
the next attribute in this SQLInputImpl object; if the value is SQL NULL, return null
throws
SQLException if the read position is located at an invalid position or if there are no more values in the stream

        Double attrib = (Double)getNextAttribute();

        if (attrib == null) {
            lastValueWasNull = true;
            return (double)0;
        } else {
            lastValueWasNull = false;
            return attrib.doubleValue();
        }
    
public floatreadFloat()
Retrieves the next attribute in this SQLInputImpl object as a float in the Java programming language.

This method does not perform type-safe checking to determine if the returned type is the expected type; this responsibility is delegated to the UDT mapping as defined by a SQLData implementation.

return
the next attribute in this SQLInputImpl object; if the value is SQL NULL, return null
throws
SQLException if the read position is located at an invalid position or if there are no more values in the stream

        Float attrib = (Float)getNextAttribute();

        if (attrib == null) {
            lastValueWasNull = true;
            return (float)0;
        } else {
            lastValueWasNull = false;
            return attrib.floatValue();
        }
    
public intreadInt()
Retrieves the next attribute in this SQLInputImpl object as an int in the Java programming language.

This method does not perform type-safe checking to determine if the returned type is the expected type; this responsibility is delegated to the UDT mapping as defined by a SQLData implementation.

return
the next attribute in this SQLInputImpl object; if the value is SQL NULL, return null
throws
SQLException if the read position is located at an invalid position or if there are no more values in the stream

        Integer attrib = (Integer)getNextAttribute();
        
        if (attrib == null) {
            lastValueWasNull = true;
            return (int)0;
        } else {
            lastValueWasNull = false;
            return attrib.intValue();
        }
    
public longreadLong()
Retrieves the next attribute in this SQLInputImpl object as a long in the Java programming language.

This method does not perform type-safe checking to determine if the returned type is the expected type; this responsibility is delegated to the UDT mapping as defined by a SQLData implementation.

return
the next attribute in this SQLInputImpl object; if the value is SQL NULL, return null
throws
SQLException if the read position is located at an invalid position or if there are no more values in the stream

        Long attrib = (Long)getNextAttribute();

        if (attrib == null) {
            lastValueWasNull = true;
            return (long)0;
        } else {
            lastValueWasNull = false;
            return attrib.longValue();
        }
    
public java.lang.ObjectreadObject()
Retrieves the value at the head of this SQLInputImpl object as an Object in the Java programming language. The actual type of the object returned is determined by the default mapping of SQL types to types in the Java programming language unless there is a custom mapping, in which case the type of the object returned is determined by this stream's type map.

The JDBC technology-enabled driver registers a type map with the stream before passing the stream to the application.

When the datum at the head of the stream is an SQL NULL, this method returns null. If the datum is an SQL structured or distinct type with a custom mapping, this method determines the SQL type of the datum at the head of the stream, constructs an object of the appropriate class, and calls the method SQLData.readSQL on that object. The readSQL method then calls the appropriate SQLInputImpl.readXXX methods to retrieve the attribute values from the stream.

return
the value at the head of the stream as an Object in the Java programming language; null if the value is SQL NULL
throws
SQLException if the read position is located at an invalid position; or if there are no further values in the stream.

        Object attrib = (Object)getNextAttribute();

        if (attrib == null) {
            lastValueWasNull = true;
            return null;
        } else {
            lastValueWasNull = false;
            if (attrib instanceof Struct) {
                Struct s = (Struct)attrib;
                // look up the class in the map
                Class c = (Class)map.get(s.getSQLTypeName());
                if (c != null) {
                    // create new instance of the class
                    SQLData obj = null;
                    try {
                        obj = (SQLData)c.newInstance();
                    } catch (java.lang.InstantiationException ex) {
                        throw new SQLException("Unable to instantiate: " +
                                               ex.getMessage());
                    } catch (java.lang.IllegalAccessException ex) {
                        throw new SQLException("Unable to instantiate: " +
                                               ex.getMessage());
                    }
                    // get the attributes from the struct
                    Object attribs[] = s.getAttributes(map);
                    // create the SQLInput "stream"
                    SQLInputImpl sqlInput = new SQLInputImpl(attribs, map);
                    // read the values...
                    obj.readSQL(sqlInput, s.getSQLTypeName());
                    return (Object)obj;
                } 
            } 
            return (Object)attrib;
        }
    
public java.sql.RefreadRef()
Retrieves the value at the head of this SQLInputImpl object as a Ref object in the Java programming language.

return
a Ref object representing the SQL REF value at the head of the stream; if the value is SQL NULL return null
throws
SQLException if the read position is located at an invalid position; or if there are no further values in the stream.

        Ref attrib = (Ref)getNextAttribute();

        if (attrib == null) {
            lastValueWasNull = true;
            return null;
        } else {
            lastValueWasNull = false;
            return attrib;
        }
    
public shortreadShort()
Retrieves the next attribute in this SQLInputImpl object as a short in the Java programming language.

This method does not perform type-safe checking to determine if the returned type is the expected type; this responsibility is delegated to the UDT mapping as defined by a SQLData implementation.

return
the next attribute in this SQLInputImpl object; if the value is SQL NULL, return null
throws
SQLException if the read position is located at an invalid position or if there are no more values in the stream

        Short attrib = (Short)getNextAttribute();

        if (attrib == null) {
            lastValueWasNull = true;
            return (short)0;
        } else {
            lastValueWasNull = false;
            return attrib.shortValue();
        }
    
public java.lang.StringreadString()
Retrieves the next attribute in this SQLInputImpl object as a String in the Java programming language.

This method does not perform type-safe checking to determine if the returned type is the expected type; this responsibility is delegated to the UDT mapping as defined by a SQLData implementation.

return
the next attribute in this SQLInputImpl object; if the value is SQL NULL, return null
throws
SQLException if the read position is located at an invalid position or if there are no further values in the stream.


        String attrib = (String)getNextAttribute();   
        
        if (attrib == null) {
            lastValueWasNull = true;
            return null;
        } else {
            lastValueWasNull = false;
            return attrib;
        }
    
public java.sql.TimereadTime()
Retrieves the next attribute in this SQLInputImpl object as a java.sql.Time object.

This method does not perform type-safe checking to determine if the returned type is the expected type as this responsibility is delegated to the UDT mapping as implemented by a SQLData implementation.

return
the attribute; if the value is SQL NULL, return null
throws
SQLException if the read position is located at an invalid position; or if there are no further values in the stream.

        java.sql.Time attrib = (java.sql.Time)getNextAttribute();

        if (attrib == null) {
            lastValueWasNull = true;
            return null;
        } else {
            lastValueWasNull = false;
            return attrib;
        }
    
public java.sql.TimestampreadTimestamp()
Retrieves the next attribute in this SQLInputImpl object as a java.sql.Timestamp object.

return
the attribute; if the value is SQL NULL, return null
throws
SQLException if the read position is located at an invalid position; or if there are no further values in the stream.

        java.sql.Timestamp attrib = (java.sql.Timestamp)getNextAttribute();

        if (attrib == null) {
            lastValueWasNull = true;
            return null;
        } else {
            lastValueWasNull = false;
            return attrib;
        }
    
public java.net.URLreadURL()
Reads an SQL DATALINK value from the stream and returns it as an URL object in the Java programming language.

This method does not perform type-safe checking to determine if the returned type is the expected type as this responsibility is delegated to the UDT mapping as implemented by a SQLData implementation.

return
an URL object representing the SQL DATALINK value at the head of the stream; * if the value is SQL NULL, return null
throws
SQLException if the read position is located at an invalid position; or if there are no further values in the stream.

        throw new SQLException("Operation not supported");    
    
public booleanwasNull()
Ascertains whether the last value read from this SQLInputImpl object was null.

return
true if the SQL value read most recently was null; otherwise, false; by default it will return false
throws
SQLException if an error occurs determining the last value read was a null value or not;

        return lastValueWasNull;