Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/src/share/classes/java/sql/SQLInput.java
38829 views
/*1* Copyright (c) 1998, 2013, 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</code> methods. The <i>reader</i> methods33* (<code>readLong</code>, <code>readBytes</code>, and so on)34* provide a way for an implementation of the <code>SQLData</code>35* interface to read the values in an <code>SQLInput</code> object.36* And as described in <code>SQLData</code>, 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</code> is used to determine whether40* the last value read was SQL <code>NULL</code>.41* <P>When the method <code>getObject</code> is called with an42* object of a class implementing the interface <code>SQLData</code>,43* the JDBC driver calls the method <code>SQLData.getSQLType</code>44* to determine the SQL type of the user-defined type (UDT)45* being custom mapped. The driver46* creates an instance of <code>SQLInput</code>, populating it with the47* attributes of the UDT. The driver then passes the input48* stream to the method <code>SQLData.readSQL</code>, which in turn49* calls the <code>SQLInput</code> 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</code>66* in the Java programming language.67*68* @return the attribute; if the value is SQL <code>NULL</code>, returns <code>null</code>69* @exception SQLException if a database access error occurs70* @exception 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</code>78* in the Java programming language.79*80* @return the attribute; if the value is SQL <code>NULL</code>, returns <code>false</code>81* @exception SQLException if a database access error occurs82* @exception 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</code>90* in the Java programming language.91*92* @return the attribute; if the value is SQL <code>NULL</code>, returns <code>0</code>93* @exception SQLException if a database access error occurs94* @exception 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</code>102* in the Java programming language.103*104* @return the attribute; if the value is SQL <code>NULL</code>, returns <code>0</code>105* @exception SQLException if a database access error occurs106* @exception 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</code>114* in the Java programming language.115*116* @return the attribute; if the value is SQL <code>NULL</code>, returns <code>0</code>117* @exception SQLException if a database access error occurs118* @exception 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</code>126* in the Java programming language.127*128* @return the attribute; if the value is SQL <code>NULL</code>, returns <code>0</code>129* @exception SQLException if a database access error occurs130* @exception 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</code>138* in the Java programming language.139*140* @return the attribute; if the value is SQL <code>NULL</code>, returns <code>0</code>141* @exception SQLException if a database access error occurs142* @exception 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</code>150* in the Java programming language.151*152* @return the attribute; if the value is SQL <code>NULL</code>, returns <code>0</code>153* @exception SQLException if a database access error occurs154* @exception 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</code>162* object in the Java programming language.163*164* @return the attribute; if the value is SQL <code>NULL</code>, returns <code>null</code>165* @exception SQLException if a database access error occurs166* @exception 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</code>, returns <code>null</code>177* @exception SQLException if a database access error occurs178* @exception 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</code> object.186*187* @return the attribute; if the value is SQL <code>NULL</code>, returns <code>null</code>188* @exception SQLException if a database access error occurs189* @exception 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</code> object.197*198* @return the attribute; if the value is SQL <code>NULL</code>, returns <code>null</code>199* @exception SQLException if a database access error occurs200* @exception 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</code> object.208*209* @return the attribute; if the value is SQL <code>NULL</code>, returns <code>null</code>210* @exception SQLException if a database access error occurs211* @exception 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</code>, returns <code>null</code>221* @exception SQLException if a database access error occurs222* @exception 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</code>, returns <code>null</code>232* @exception SQLException if a database access error occurs233* @exception 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</code>, returns <code>null</code>244* @exception SQLException if a database access error occurs245* @exception 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</code> 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</code>,265* the method returns <code>null</code>. 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</code> 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</code> in the273* Java programming language;<code>null</code> if the datum is SQL <code>NULL</code>274* @exception SQLException if a database access error occurs275* @exception SQLFeatureNotSupportedException if the JDBC driver does not support276* this method277* @since 1.2278*/279Object readObject() throws SQLException;280281/**282* Reads an SQL <code>REF</code> value from the stream and returns it as a283* <code>Ref</code> object in the Java programming language.284*285* @return a <code>Ref</code> object representing the SQL <code>REF</code> value286* at the head of the stream; <code>null</code> if the value read is287* SQL <code>NULL</code>288* @exception SQLException if a database access error occurs289* @exception SQLFeatureNotSupportedException if the JDBC driver does not support290* this method291* @since 1.2292*/293Ref readRef() throws SQLException;294295/**296* Reads an SQL <code>BLOB</code> value from the stream and returns it as a297* <code>Blob</code> object in the Java programming language.298*299* @return a <code>Blob</code> object representing data of the SQL <code>BLOB</code> value300* at the head of the stream; <code>null</code> if the value read is301* SQL <code>NULL</code>302* @exception SQLException if a database access error occurs303* @exception SQLFeatureNotSupportedException if the JDBC driver does not support304* this method305* @since 1.2306*/307Blob readBlob() throws SQLException;308309/**310* Reads an SQL <code>CLOB</code> value from the stream and returns it as a311* <code>Clob</code> object in the Java programming language.312*313* @return a <code>Clob</code> object representing data of the SQL <code>CLOB</code> value314* at the head of the stream; <code>null</code> if the value read is315* SQL <code>NULL</code>316* @exception SQLException if a database access error occurs317* @exception SQLFeatureNotSupportedException if the JDBC driver does not support318* this method319* @since 1.2320*/321Clob readClob() throws SQLException;322323/**324* Reads an SQL <code>ARRAY</code> value from the stream and returns it as an325* <code>Array</code> object in the Java programming language.326*327* @return an <code>Array</code> object representing data of the SQL328* <code>ARRAY</code> value at the head of the stream; <code>null</code>329* if the value read is SQL <code>NULL</code>330* @exception SQLException if a database access error occurs331* @exception 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</code>.339*340* @return <code>true</code> if the most recently read SQL value was SQL341* <code>NULL</code>; <code>false</code> otherwise342* @exception SQLException if a database access error occurs343*344* @exception 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</code> value from the stream and returns it as a354* <code>java.net.URL</code> object in the Java programming language.355*356* @return a <code>java.net.URL</code> object.357* @exception SQLException if a database access error occurs,358* or if a URL is malformed359* @exception 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</code> value from the stream and returns it as a369* <code>NClob</code> object in the Java programming language.370*371* @return a <code>NClob</code> object representing data of the SQL <code>NCLOB</code> value372* at the head of the stream; <code>null</code> if the value read is373* SQL <code>NULL</code>374* @exception SQLException if a database access error occurs375* @exception 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</code>383* in the Java programming language. It is intended for use when384* accessing <code>NCHAR</code>,<code>NVARCHAR</code>385* and <code>LONGNVARCHAR</code> columns.386*387* @return the attribute; if the value is SQL <code>NULL</code>, returns <code>null</code>388* @exception SQLException if a database access error occurs389* @exception SQLFeatureNotSupportedException if the JDBC driver does not support390* this method391* @since 1.6392*/393String readNString() throws SQLException;394395/**396* Reads an SQL <code>XML</code> value from the stream and returns it as a397* <code>SQLXML</code> object in the Java programming language.398*399* @return a <code>SQLXML</code> object representing data of the SQL <code>XML</code> value400* at the head of the stream; <code>null</code> if the value read is401* SQL <code>NULL</code>402* @exception SQLException if a database access error occurs403* @exception SQLFeatureNotSupportedException if the JDBC driver does not support404* this method405* @since 1.6406*/407SQLXML readSQLXML() throws SQLException;408409/**410* Reads an SQL <code>ROWID</code> value from the stream and returns it as a411* <code>RowId</code> object in the Java programming language.412*413* @return a <code>RowId</code> object representing data of the SQL <code>ROWID</code> value414* at the head of the stream; <code>null</code> if the value read is415* SQL <code>NULL</code>416* @exception SQLException if a database access error occurs417* @exception 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* @exception SQLException if a database access error occurs451* @exception 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