Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/src/java.sql/share/classes/java/sql/SQLData.java
41153 views
1
/*
2
* Copyright (c) 1998, 2020, 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} interface will be entered in the
32
* appropriate {@code Connection} 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} implementation
36
* will define a field for each attribute of an SQL structured type or a
37
* single field for an SQL {@code DISTINCT} type. When the UDT is
38
* retrieved from a data source with the {@code ResultSet.getObject}
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} 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} and
51
* {@code SQLData.writeSQL} methods. The {@code readSQL} method
52
* calls the appropriate {@code SQLInput} methods to read
53
* each attribute from an {@code SQLInput} object, and the
54
* {@code writeSQL} method calls {@code SQLOutput} methods
55
* to write each attribute back to the data source via an
56
* {@code SQLOutput} object.
57
* <P>
58
* An application programmer will not normally call {@code SQLData} methods
59
* directly, and the {@code SQLInput} and {@code SQLOutput} methods
60
* are called internally by {@code SQLData} 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}.
72
*
73
* @return the type name that was passed to the method {@code readSQL}
74
* when this object was constructed and populated
75
* @throws SQLException if there is a database access error
76
* @throws 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} 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 SQLInput.readBigDecimal},
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} reader method on the stream.
103
*
104
* @param stream the {@code SQLInput} 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
* @throws SQLException if there is a database access error
108
* @throws 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} writer
124
* method(s) ({@code writeInt}, {@code writeString}, 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} object to which to write the data for
129
* the value that was custom mapped
130
* @throws SQLException if there is a database access error
131
* @throws 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
}
138
139