History

My first initial commit with all of mine experimental changes.

Dmitry Kabak (userdima committed 13 years ago

Commit d37b88d1 parent 3f5b46618352 files · +2598093 −-8690Browse files

Showing the changes to java/pkg/java/sql/SQLData.java (1 of 18352 files). Show all

Unified · Split

java/pkg/java/sql/SQLData.java+137−0
@@ -0,0 +1,137 @@
1+/*
2+ * Copyright (c) 1998, 2006, Oracle and/or its affiliates. All rights reserved.
3+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4+ *
5+ * This code is free software; you can redistribute it and/or modify it
6+ * under the terms of the GNU General Public License version 2 only, as
7+ * published by the Free Software Foundation. Oracle designates this
8+ * particular file as subject to the "Classpath" exception as provided
9+ * by Oracle in the LICENSE file that accompanied this code.
10+ *
11+ * This code is distributed in the hope that it will be useful, but WITHOUT
12+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14+ * version 2 for more details (a copy is included in the LICENSE file that
15+ * accompanied this code).
16+ *
17+ * You should have received a copy of the GNU General Public License version
18+ * 2 along with this work; if not, write to the Free Software Foundation,
19+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20+ *
21+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22+ * or visit www.oracle.com if you need additional information or have any
23+ * questions.
24+ */
25+
26+package java.sql;
27+
28+/**
29+ * The interface used for the custom mapping of an SQL user-defined type (UDT) to
30+ * a class in the Java programming language. The class object for a class
31+ * implementing the <code>SQLData</code> interface will be entered in the
32+ * appropriate <code>Connection</code> object's type map along with the SQL
33+ * name of the UDT for which it is a custom mapping.
34+ * <P>
35+ * Typically, a <code>SQLData</code> implementation
36+ * will define a field for each attribute of an SQL structured type or a
37+ * single field for an SQL <code>DISTINCT</code> type. When the UDT is
38+ * retrieved from a data source with the <code>ResultSet.getObject</code>
39+ * method, it will be mapped as an instance of this class. A programmer
40+ * can operate on this class instance just as on any other object in the
41+ * Java programming language and then store any changes made to it by
42+ * calling the <code>PreparedStatement.setObject</code> method,
43+ * which will map it back to the SQL type.
44+ * <p>
45+ * It is expected that the implementation of the class for a custom
46+ * mapping will be done by a tool. In a typical implementation, the
47+ * programmer would simply supply the name of the SQL UDT, the name of
48+ * the class to which it is being mapped, and the names of the fields to
49+ * which each of the attributes of the UDT is to be mapped. The tool will use
50+ * this information to implement the <code>SQLData.readSQL</code> and
51+ * <code>SQLData.writeSQL</code> methods. The <code>readSQL</code> method
52+ * calls the appropriate <code>SQLInput</code> methods to read
53+ * each attribute from an <code>SQLInput</code> object, and the
54+ * <code>writeSQL</code> method calls <code>SQLOutput</code> methods
55+ * to write each attribute back to the data source via an
56+ * <code>SQLOutput</code> object.
57+ * <P>
58+ * An application programmer will not normally call <code>SQLData</code> methods
59+ * directly, and the <code>SQLInput</code> and <code>SQLOutput</code> methods
60+ * are called internally by <code>SQLData</code> methods, not by application code.
61+ *
62+ * @since 1.2
63+ */
64+public interface SQLData {
65+
66+ /**
67+ * Returns the fully-qualified
68+ * name of the SQL user-defined type that this object represents.
69+ * This method is called by the JDBC driver to get the name of the
70+ * UDT instance that is being mapped to this instance of
71+ * <code>SQLData</code>.
72+ *
73+ * @return the type name that was passed to the method <code>readSQL</code>
74+ * when this object was constructed and populated
75+ * @exception SQLException if there is a database access error
76+ * @exception SQLFeatureNotSupportedException if the JDBC driver does not support
77+ * this method
78+ * @since 1.2
79+ */
80+ String getSQLTypeName() throws SQLException;
81+
82+ /**
83+ * Populates this object with data read from the database.
84+ * The implementation of the method must follow this protocol:
85+ * <UL>
86+ * <LI>It must read each of the attributes or elements of the SQL
87+ * type from the given input stream. This is done
88+ * by calling a method of the input stream to read each
89+ * item, in the order that they appear in the SQL definition
90+ * of the type.
91+ * <LI>The method <code>readSQL</code> then
92+ * assigns the data to appropriate fields or
93+ * elements (of this or other objects).
94+ * Specifically, it must call the appropriate <i>reader</i> method
95+ * (<code>SQLInput.readString</code>, <code>SQLInput.readBigDecimal</code>,
96+ * and so on) method(s) to do the following:
97+ * for a distinct type, read its single data element;
98+ * for a structured type, read a value for each attribute of the SQL type.
99+ * </UL>
100+ * The JDBC driver initializes the input stream with a type map
101+ * before calling this method, which is used by the appropriate
102+ * <code>SQLInput</code> reader method on the stream.
103+ *
104+ * @param stream the <code>SQLInput</code> object from which to read the data for
105+ * the value that is being custom mapped
106+ * @param typeName the SQL type name of the value on the data stream
107+ * @exception SQLException if there is a database access error
108+ * @exception SQLFeatureNotSupportedException if the JDBC driver does not support
109+ * this method
110+ * @see SQLInput
111+ * @since 1.2
112+ */
113+ void readSQL (SQLInput stream, String typeName) throws SQLException;
114+
115+ /**
116+ * Writes this object to the given SQL data stream, converting it back to
117+ * its SQL value in the data source.
118+ * The implementation of the method must follow this protocol:<BR>
119+ * It must write each of the attributes of the SQL type
120+ * to the given output stream. This is done by calling a
121+ * method of the output stream to write each item, in the order that
122+ * they appear in the SQL definition of the type.
123+ * Specifically, it must call the appropriate <code>SQLOutput</code> writer
124+ * method(s) (<code>writeInt</code>, <code>writeString</code>, and so on)
125+ * to do the following: for a Distinct Type, write its single data element;
126+ * for a Structured Type, write a value for each attribute of the SQL type.
127+ *
128+ * @param stream the <code>SQLOutput</code> object to which to write the data for
129+ * the value that was custom mapped
130+ * @exception SQLException if there is a database access error
131+ * @exception SQLFeatureNotSupportedException if the JDBC driver does not support
132+ * this method
133+ * @see SQLOutput
134+ * @since 1.2
135+ */
136+ void writeSQL (SQLOutput stream) throws SQLException;
137+}