Path: blob/master/src/java.sql.rowset/share/classes/javax/sql/rowset/serial/package-info.java
40948 views
/*1* Copyright (c) 2003, 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*/2425/**26* Provides utility classes to allow serializable mappings between SQL types27* and data types in the Java programming language.28* <p> Standard JDBC {@code RowSet} implementations may use these utility29* classes to30* assist in the serialization of disconnected {@code RowSet} objects.31* This is useful32* when transmitting a disconnected {@code RowSet} object over the wire to33* a different VM or across layers within an application.<br>34* </p>35*36* <h2>1.0 SerialArray</h2>37* A serializable mapping in the Java programming language of an SQL ARRAY38* value. <br>39* <br>40* The {@code SerialArray} class provides a constructor for creating a {@code SerialArray}41* instance from an Array object, methods for getting the base type and42* the SQL name for the base type, and methods for copying all or part of a43* {@code SerialArray} object. <br>44*45* <h2>2.0 SerialBlob</h2>46* A serializable mapping in the Java programming language of an SQL BLOB47* value. <br>48* <br>49* The {@code SerialBlob} class provides a constructor for creating an instance50* from a Blob object. Note that the Blob object should have brought the SQL51* BLOB value's data over to the client before a {@code SerialBlob} object52* is constructed from it. The data of an SQL BLOB value can be materialized53* on the client as an array of bytes (using the method {@code Blob.getBytes})54* or as a stream of uninterpreted bytes (using the method {@code Blob.getBinaryStream}).55* <br>56* <br>57* {@code SerialBlob} methods make it possible to make a copy of a {@code SerialBlob}58* object as an array of bytes or as a stream. They also make it possible59* to locate a given pattern of bytes or a {@code Blob} object within a {@code SerialBlob}60* object. <br>61*62* <h2>3.0 SerialClob</h2>63* A serializable mapping in the Java programming language of an SQL CLOB64* value. <br>65* <br>66* The {@code SerialClob} class provides a constructor for creating an instance67* from a {@code Clob} object. Note that the {@code Clob} object should have68* brought the SQL CLOB value's data over to the client before a {@code SerialClob}69* object is constructed from it. The data of an SQL CLOB value can be70* materialized on the client as a stream of Unicode characters. <br>71* <br>72* {@code SerialClob} methods make it possible to get a substring from a73* {@code SerialClob} object or to locate the start of a pattern of characters.74* <br>75*76* <h2>5.0 SerialDatalink</h2>77* A serializable mapping in the Java programming language of an SQL DATALINK78* value. A DATALINK value references a file outside of the underlying data source79* that the originating data source manages. <br>80* <br>81* {@code RowSet} implementations can use the method {@code RowSet.getURL()} to retrieve82* a {@code java.net.URL} object, which can be used to manipulate the external data.83* <br>84* <PRE>85* java.net.URL url = rowset.getURL(1);86* </PRE>87*88* <h2>6.0 SerialJavaObject</h2>89* A serializable mapping in the Java programming language of an SQL JAVA_OBJECT90* value. Assuming the Java object instance implements the Serializable interface,91* this simply wraps the serialization process. <br>92* <br>93* If however, the serialization is not possible in the case where the Java94* object is not immediately serializable, this class will attempt to serialize95* all non static members to permit the object instance state to be serialized.96* Static or transient fields cannot be serialized and attempting to do so97* will result in a {@code SerialException} being thrown. <br>98*99* <h2>7.0 SerialRef</h2>100* A serializable mapping between the SQL REF type and the Java programming101* language. <br>102* <br>103* The {@code SerialRef} class provides a constructor for creating a {@code SerialRef}104* instance from a {@code Ref} type and provides methods for getting105* and setting the {@code Ref} object type. <br>106*107* <h2>8.0 SerialStruct</h2>108* A serializable mapping in the Java programming language of an SQL structured109* type. Each attribute that is not already serializable is mapped to a serializable110* form, and if an attribute is itself a structured type, each of its attributes111* that is not already serializable is mapped to a serializable form. <br>112* <br>113* In addition, if a {@code Map} object is passed to one of the constructors or114* to the method {@code getAttributes}, the structured type is custom mapped115* according to the mapping specified in the {@code Map} object.116* <br>117* The {@code SerialStruct} class provides a constructor for creating an118* instance from a {@code Struct} object, a method for retrieving the SQL119* type name of the SQL structured type in the database, and methods for retrieving120* its attribute values. <br>121*122* <h2>9.0 SQLInputImpl</h2>123* An input stream used for custom mapping user-defined types (UDTs). An124* {@code SQLInputImpl} object is an input stream that contains a stream of125* values that are126* the attributes of a UDT. This class is used by the driver behind the scenes127* when the method {@code getObject} is called on an SQL structured or distinct128* type that has a custom mapping; a programmer never invokes {@code SQLInputImpl}129* methods directly. <br>130* <br>131* The {@code SQLInputImpl} class provides a set of reader methods132* analogous to the {@code ResultSet} getter methods. These methods make it133* possible to read the values in an {@code SQLInputImpl} object. The method134* {@code wasNull} is used to determine whether the last value read was SQL NULL.135* <br>136* <br>137* When a constructor or getter method that takes a {@code Map} object is called,138* the JDBC driver calls the method139* {@code SQLData.getSQLType} to determine the SQL type of the UDT being custom140* mapped. The driver creates an instance of {@code SQLInputImpl}, populating it with141* the attributes of the UDT. The driver then passes the input stream to the142* method {@code SQLData.readSQL}, which in turn calls the {@code SQLInputImpl}143* methods to read the attributes from the input stream. <br>144*145* <h2>10.0 SQLOutputImpl</h2>146* The output stream for writing the attributes of a custom mapped user-defined147* type (UDT) back to the database. The driver uses this interface internally,148* and its methods are never directly invoked by an application programmer.149* <br>150* <br>151* When an application calls the method {@code PreparedStatement.setObject}, the152* driver checks to see whether the value to be written is a UDT with a custom153* mapping. If it is, there will be an entry in a type map containing the Class154* object for the class that implements {@code SQLData} for this UDT. If the155* value to be written is an instance of {@code SQLData}, the driver will156* create an instance of {@code SQLOutputImpl} and pass it to the method157* {@code SQLData.writeSQL}.158* The method {@code writeSQL} in turn calls the appropriate {@code SQLOutputImpl}159* writer methods to write data from the {@code SQLData} object to the160* {@code SQLOutputImpl}161* output stream as the representation of an SQL user-defined type.162*163* <h2>Custom Mapping</h2>164* The JDBC API provides mechanisms for mapping an SQL structured type or DISTINCT165* type to the Java programming language. Typically, a structured type is mapped166* to a class, and its attributes are mapped to fields in the class.167* (A DISTINCT type can thought of as having one attribute.) However, there are168* many other possibilities, and there may be any number of different mappings.169* <P>170* A programmer defines the mapping by implementing the interface {@code SQLData}.171* For example, if an SQL structured type named AUTHORS has the attributes NAME,172* TITLE, and PUBLISHER, it could be mapped to a Java class named Authors. The173* Authors class could have the fields name, title, and publisher, to which the174* attributes of AUTHORS are mapped. In such a case, the implementation of175* {@code SQLData} could look like the following:176* <PRE>177* public class Authors implements SQLData {178* public String name;179* public String title;180* public String publisher;181*182* private String sql_type;183* public String getSQLTypeName() {184* return sql_type;185* }186*187* public void readSQL(SQLInput stream, String type)188* throws SQLException {189* sql_type = type;190* name = stream.readString();191* title = stream.readString();192* publisher = stream.readString();193* }194*195* public void writeSQL(SQLOutput stream) throws SQLException {196* stream.writeString(name);197* stream.writeString(title);198* stream.writeString(publisher);199* }200* }201* </PRE>202*203* A {@code java.util.Map} object is used to associate the SQL structured204* type with its mapping to the class {@code Authors}. The following code fragment shows205* how a {@code Map} object might be created and given an entry associating206* {@code AUTHORS} and {@code Authors}.207* <PRE>208* java.util.Map map = new java.util.HashMap();209* map.put("SCHEMA_NAME.AUTHORS", Class.forName("Authors");210* </PRE>211*212* The {@code Map} object <i>map</i> now contains an entry with the213* fully qualified name of the SQL structured type and the {@code Class}214* object for the class {@code Authors}. It can be passed to a method215* to tell the driver how to map {@code AUTHORS} to {@code Authors}.216* <P>217* For a disconnected {@code RowSet} object, custom mapping can be done218* only when a {@code Map} object is passed to the method or constructor219* that will be doing the custom mapping. The situation is different for220* connected {@code RowSet} objects because they maintain a connection221* with the data source. A method that does custom mapping and is called by222* a disconnected {@code RowSet} object may use the {@code Map}223* object that is associated with the {@code Connection} object being224* used. So, in other words, if no map is specified, the connection's type225* map can be used by default.226*/227package javax.sql.rowset.serial;228229230