Path: blob/master/src/java.sql/share/classes/java/sql/SQLInput.java
41153 views
/*1* Copyright (c) 1998, 2020, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425package java.sql;2627/**28* An input stream that contains a stream of values representing an29* instance of an SQL structured type or an SQL distinct type.30* This interface, used only for custom mapping, is used by the driver31* behind the scenes, and a programmer never directly invokes32* {@code SQLInput} methods. The <i>reader</i> methods33* ({@code readLong}, {@code readBytes}, and so on)34* provide a way for an implementation of the {@code SQLData}35* interface to read the values in an {@code SQLInput} object.36* And as described in {@code SQLData}, calls to reader methods must37* be made in the order that their corresponding attributes appear in the38* SQL definition of the type.39* The method {@code wasNull} is used to determine whether40* the last value read was SQL {@code NULL}.41* <P>When the method {@code getObject} is called with an42* object of a class implementing the interface {@code SQLData},43* the JDBC driver calls the method {@code SQLData.getSQLType}44* to determine the SQL type of the user-defined type (UDT)45* being custom mapped. The driver46* creates an instance of {@code SQLInput}, populating it with the47* attributes of the UDT. The driver then passes the input48* stream to the method {@code SQLData.readSQL}, which in turn49* calls the {@code SQLInput} reader methods50* in its implementation for reading the51* attributes from the input stream.52* @since 1.253*/5455public interface SQLInput {565758//================================================================59// Methods for reading attributes from the stream of SQL data.60// These methods correspond to the column-accessor methods of61// java.sql.ResultSet.62//================================================================6364/**65* Reads the next attribute in the stream and returns it as a {@code String}66* in the Java programming language.67*68* @return the attribute; if the value is SQL {@code NULL}, returns {@code null}69* @throws SQLException if a database access error occurs70* @throws SQLFeatureNotSupportedException if the JDBC driver does not support71* this method72* @since 1.273*/74String readString() throws SQLException;7576/**77* Reads the next attribute in the stream and returns it as a {@code boolean}78* in the Java programming language.79*80* @return the attribute; if the value is SQL {@code NULL}, returns {@code false}81* @throws SQLException if a database access error occurs82* @throws SQLFeatureNotSupportedException if the JDBC driver does not support83* this method84* @since 1.285*/86boolean readBoolean() throws SQLException;8788/**89* Reads the next attribute in the stream and returns it as a {@code byte}90* in the Java programming language.91*92* @return the attribute; if the value is SQL {@code NULL}, returns {@code 0}93* @throws SQLException if a database access error occurs94* @throws SQLFeatureNotSupportedException if the JDBC driver does not support95* this method96* @since 1.297*/98byte readByte() throws SQLException;99100/**101* Reads the next attribute in the stream and returns it as a {@code short}102* in the Java programming language.103*104* @return the attribute; if the value is SQL {@code NULL}, returns {@code 0}105* @throws SQLException if a database access error occurs106* @throws SQLFeatureNotSupportedException if the JDBC driver does not support107* this method108* @since 1.2109*/110short readShort() throws SQLException;111112/**113* Reads the next attribute in the stream and returns it as an {@code int}114* in the Java programming language.115*116* @return the attribute; if the value is SQL {@code NULL}, returns {@code 0}117* @throws SQLException if a database access error occurs118* @throws SQLFeatureNotSupportedException if the JDBC driver does not support119* this method120* @since 1.2121*/122int readInt() throws SQLException;123124/**125* Reads the next attribute in the stream and returns it as a {@code long}126* in the Java programming language.127*128* @return the attribute; if the value is SQL {@code NULL}, returns {@code 0}129* @throws SQLException if a database access error occurs130* @throws SQLFeatureNotSupportedException if the JDBC driver does not support131* this method132* @since 1.2133*/134long readLong() throws SQLException;135136/**137* Reads the next attribute in the stream and returns it as a {@code float}138* in the Java programming language.139*140* @return the attribute; if the value is SQL {@code NULL}, returns {@code 0}141* @throws SQLException if a database access error occurs142* @throws SQLFeatureNotSupportedException if the JDBC driver does not support143* this method144* @since 1.2145*/146float readFloat() throws SQLException;147148/**149* Reads the next attribute in the stream and returns it as a {@code double}150* in the Java programming language.151*152* @return the attribute; if the value is SQL {@code NULL}, returns {@code 0}153* @throws SQLException if a database access error occurs154* @throws SQLFeatureNotSupportedException if the JDBC driver does not support155* this method156* @since 1.2157*/158double readDouble() throws SQLException;159160/**161* Reads the next attribute in the stream and returns it as a {@code java.math.BigDecimal}162* object in the Java programming language.163*164* @return the attribute; if the value is SQL {@code NULL}, returns {@code null}165* @throws SQLException if a database access error occurs166* @throws SQLFeatureNotSupportedException if the JDBC driver does not support167* this method168* @since 1.2169*/170java.math.BigDecimal readBigDecimal() throws SQLException;171172/**173* Reads the next attribute in the stream and returns it as an array of bytes174* in the Java programming language.175*176* @return the attribute; if the value is SQL {@code NULL}, returns {@code null}177* @throws SQLException if a database access error occurs178* @throws SQLFeatureNotSupportedException if the JDBC driver does not support179* this method180* @since 1.2181*/182byte[] readBytes() throws SQLException;183184/**185* Reads the next attribute in the stream and returns it as a {@code java.sql.Date} object.186*187* @return the attribute; if the value is SQL {@code NULL}, returns {@code null}188* @throws SQLException if a database access error occurs189* @throws SQLFeatureNotSupportedException if the JDBC driver does not support190* this method191* @since 1.2192*/193java.sql.Date readDate() throws SQLException;194195/**196* Reads the next attribute in the stream and returns it as a {@code java.sql.Time} object.197*198* @return the attribute; if the value is SQL {@code NULL}, returns {@code null}199* @throws SQLException if a database access error occurs200* @throws SQLFeatureNotSupportedException if the JDBC driver does not support201* this method202* @since 1.2203*/204java.sql.Time readTime() throws SQLException;205206/**207* Reads the next attribute in the stream and returns it as a {@code java.sql.Timestamp} object.208*209* @return the attribute; if the value is SQL {@code NULL}, returns {@code null}210* @throws SQLException if a database access error occurs211* @throws SQLFeatureNotSupportedException if the JDBC driver does not support212* this method213* @since 1.2214*/215java.sql.Timestamp readTimestamp() throws SQLException;216217/**218* Reads the next attribute in the stream and returns it as a stream of Unicode characters.219*220* @return the attribute; if the value is SQL {@code NULL}, returns {@code null}221* @throws SQLException if a database access error occurs222* @throws SQLFeatureNotSupportedException if the JDBC driver does not support223* this method224* @since 1.2225*/226java.io.Reader readCharacterStream() throws SQLException;227228/**229* Reads the next attribute in the stream and returns it as a stream of ASCII characters.230*231* @return the attribute; if the value is SQL {@code NULL}, returns {@code null}232* @throws SQLException if a database access error occurs233* @throws SQLFeatureNotSupportedException if the JDBC driver does not support234* this method235* @since 1.2236*/237java.io.InputStream readAsciiStream() throws SQLException;238239/**240* Reads the next attribute in the stream and returns it as a stream of uninterpreted241* bytes.242*243* @return the attribute; if the value is SQL {@code NULL}, returns {@code null}244* @throws SQLException if a database access error occurs245* @throws SQLFeatureNotSupportedException if the JDBC driver does not support246* this method247* @since 1.2248*/249java.io.InputStream readBinaryStream() throws SQLException;250251//================================================================252// Methods for reading items of SQL user-defined types from the stream.253//================================================================254255/**256* Reads the datum at the head of the stream and returns it as an257* {@code Object} in the Java programming language. The258* actual type of the object returned is determined by the default type259* mapping, and any customizations present in this stream's type map.260*261* <P>A type map is registered with the stream by the JDBC driver before the262* stream is passed to the application.263*264* <P>When the datum at the head of the stream is an SQL {@code NULL},265* the method returns {@code null}. If the datum is an SQL structured or distinct266* type, it determines the SQL type of the datum at the head of the stream.267* If the stream's type map has an entry for that SQL type, the driver268* constructs an object of the appropriate class and calls the method269* {@code SQLData.readSQL} on that object, which reads additional data from the270* stream, using the protocol described for that method.271*272* @return the datum at the head of the stream as an {@code Object} in the273* Java programming language;{@code null} if the datum is SQL {@code NULL}274* @throws SQLException if a database access error occurs275* @throws SQLFeatureNotSupportedException if the JDBC driver does not support276* this method277* @since 1.2278*/279Object readObject() throws SQLException;280281/**282* Reads an SQL {@code REF} value from the stream and returns it as a283* {@code Ref} object in the Java programming language.284*285* @return a {@code Ref} object representing the SQL {@code REF} value286* at the head of the stream; {@code null} if the value read is287* SQL {@code NULL}288* @throws SQLException if a database access error occurs289* @throws SQLFeatureNotSupportedException if the JDBC driver does not support290* this method291* @since 1.2292*/293Ref readRef() throws SQLException;294295/**296* Reads an SQL {@code BLOB} value from the stream and returns it as a297* {@code Blob} object in the Java programming language.298*299* @return a {@code Blob} object representing data of the SQL {@code BLOB} value300* at the head of the stream; {@code null} if the value read is301* SQL {@code NULL}302* @throws SQLException if a database access error occurs303* @throws SQLFeatureNotSupportedException if the JDBC driver does not support304* this method305* @since 1.2306*/307Blob readBlob() throws SQLException;308309/**310* Reads an SQL {@code CLOB} value from the stream and returns it as a311* {@code Clob} object in the Java programming language.312*313* @return a {@code Clob} object representing data of the SQL {@code CLOB} value314* at the head of the stream; {@code null} if the value read is315* SQL {@code NULL}316* @throws SQLException if a database access error occurs317* @throws SQLFeatureNotSupportedException if the JDBC driver does not support318* this method319* @since 1.2320*/321Clob readClob() throws SQLException;322323/**324* Reads an SQL {@code ARRAY} value from the stream and returns it as an325* {@code Array} object in the Java programming language.326*327* @return an {@code Array} object representing data of the SQL328* {@code ARRAY} value at the head of the stream; {@code null}329* if the value read is SQL {@code NULL}330* @throws SQLException if a database access error occurs331* @throws SQLFeatureNotSupportedException if the JDBC driver does not support332* this method333* @since 1.2334*/335Array readArray() throws SQLException;336337/**338* Retrieves whether the last value read was SQL {@code NULL}.339*340* @return {@code true} if the most recently read SQL value was SQL341* {@code NULL}; {@code false} otherwise342* @throws SQLException if a database access error occurs343*344* @throws SQLFeatureNotSupportedException if the JDBC driver does not support345* this method346* @since 1.2347*/348boolean wasNull() throws SQLException;349350//---------------------------- JDBC 3.0 -------------------------351352/**353* Reads an SQL {@code DATALINK} value from the stream and returns it as a354* {@code java.net.URL} object in the Java programming language.355*356* @return a {@code java.net.URL} object.357* @throws SQLException if a database access error occurs,358* or if a URL is malformed359* @throws SQLFeatureNotSupportedException if the JDBC driver does not support360* this method361* @since 1.4362*/363java.net.URL readURL() throws SQLException;364365//---------------------------- JDBC 4.0 -------------------------366367/**368* Reads an SQL {@code NCLOB} value from the stream and returns it as a369* {@code NClob} object in the Java programming language.370*371* @return a {@code NClob} object representing data of the SQL {@code NCLOB} value372* at the head of the stream; {@code null} if the value read is373* SQL {@code NULL}374* @throws SQLException if a database access error occurs375* @throws SQLFeatureNotSupportedException if the JDBC driver does not support376* this method377* @since 1.6378*/379NClob readNClob() throws SQLException;380381/**382* Reads the next attribute in the stream and returns it as a {@code String}383* in the Java programming language. It is intended for use when384* accessing {@code NCHAR},{@code NVARCHAR}385* and {@code LONGNVARCHAR} columns.386*387* @return the attribute; if the value is SQL {@code NULL}, returns {@code null}388* @throws SQLException if a database access error occurs389* @throws SQLFeatureNotSupportedException if the JDBC driver does not support390* this method391* @since 1.6392*/393String readNString() throws SQLException;394395/**396* Reads an SQL {@code XML} value from the stream and returns it as a397* {@code SQLXML} object in the Java programming language.398*399* @return a {@code SQLXML} object representing data of the SQL {@code XML} value400* at the head of the stream; {@code null} if the value read is401* SQL {@code NULL}402* @throws SQLException if a database access error occurs403* @throws SQLFeatureNotSupportedException if the JDBC driver does not support404* this method405* @since 1.6406*/407SQLXML readSQLXML() throws SQLException;408409/**410* Reads an SQL {@code ROWID} value from the stream and returns it as a411* {@code RowId} object in the Java programming language.412*413* @return a {@code RowId} object representing data of the SQL {@code ROWID} value414* at the head of the stream; {@code null} if the value read is415* SQL {@code NULL}416* @throws SQLException if a database access error occurs417* @throws SQLFeatureNotSupportedException if the JDBC driver does not support418* this method419* @since 1.6420*/421RowId readRowId() throws SQLException;422423//--------------------------JDBC 4.2 -----------------------------424425/**426* Reads the next attribute in the stream and returns it as an427* {@code Object} in the Java programming language. The428* actual type of the object returned is determined by the specified429* Java data type, and any customizations present in this430* stream's type map.431*432* <P>A type map is registered with the stream by the JDBC driver before the433* stream is passed to the application.434*435* <P>When the attribute at the head of the stream is an SQL {@code NULL}436* the method returns {@code null}. If the attribute is an SQL437* structured or distinct438* type, it determines the SQL type of the attribute at the head of the stream.439* If the stream's type map has an entry for that SQL type, the driver440* constructs an object of the appropriate class and calls the method441* {@code SQLData.readSQL} on that object, which reads additional data from the442* stream, using the protocol described for that method.443*<p>444* The default implementation will throw {@code SQLFeatureNotSupportedException}445*446* @param <T> the type of the class modeled by this Class object447* @param type Class representing the Java data type to convert the attribute to.448* @return the attribute at the head of the stream as an {@code Object} in the449* Java programming language;{@code null} if the attribute is SQL {@code NULL}450* @throws SQLException if a database access error occurs451* @throws SQLFeatureNotSupportedException if the JDBC driver does not support452* this method453* @since 1.8454*/455default <T> T readObject(Class<T> type) throws SQLException {456throw new SQLFeatureNotSupportedException();457}458}459460461