author | gromero |
Tue, 04 Sep 2018 11:46:23 -0400 | |
changeset 51629 | 78c7f0c7827d |
parent 51181 | 01b8120f867a |
child 54106 | 9a90236ab64c |
permissions | -rw-r--r-- |
2 | 1 |
/* |
25976
4de01a56e3ee
8054555: javadoc cleanup for java.sql and javax.sql
lancea
parents:
24968
diff
changeset
|
2 |
* Copyright (c) 2003, 2014, Oracle and/or its affiliates. All rights reserved. |
2 | 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 |
|
5506 | 7 |
* published by the Free Software Foundation. Oracle designates this |
2 | 8 |
* particular file as subject to the "Classpath" exception as provided |
5506 | 9 |
* by Oracle in the LICENSE file that accompanied this code. |
2 | 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 |
* |
|
5506 | 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. |
|
2 | 24 |
*/ |
25 |
||
26 |
package javax.sql.rowset.serial; |
|
27 |
||
28 |
import java.sql.*; |
|
29 |
import java.io.*; |
|
30 |
import java.util.Map; |
|
31 |
import java.net.URL; |
|
14409
d879c92507ec
8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents:
14342
diff
changeset
|
32 |
import java.util.Arrays; |
2 | 33 |
|
14781
701d0765f75f
8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents:
14409
diff
changeset
|
34 |
|
2 | 35 |
/** |
36 |
* A serialized version of an <code>Array</code> |
|
37 |
* object, which is the mapping in the Java programming language of an SQL |
|
38 |
* <code>ARRAY</code> value. |
|
39 |
* <P> |
|
40 |
* The <code>SerialArray</code> class provides a constructor for creating |
|
41 |
* a <code>SerialArray</code> instance from an <code>Array</code> object, |
|
42 |
* methods for getting the base type and the SQL name for the base type, and |
|
43 |
* methods for copying all or part of a <code>SerialArray</code> object. |
|
44 |
* <P> |
|
14781
701d0765f75f
8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents:
14409
diff
changeset
|
45 |
* |
2 | 46 |
* Note: In order for this class to function correctly, a connection to the |
47 |
* data source |
|
48 |
* must be available in order for the SQL <code>Array</code> object to be |
|
49 |
* materialized (have all of its elements brought to the client server) |
|
50 |
* if necessary. At this time, logical pointers to the data in the data source, |
|
51 |
* such as locators, are not currently supported. |
|
14781
701d0765f75f
8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents:
14409
diff
changeset
|
52 |
* |
18564 | 53 |
* <h3> Thread safety </h3> |
14781
701d0765f75f
8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents:
14409
diff
changeset
|
54 |
* |
701d0765f75f
8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents:
14409
diff
changeset
|
55 |
* A SerialArray is not safe for use by multiple concurrent threads. If a |
701d0765f75f
8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents:
14409
diff
changeset
|
56 |
* SerialArray is to be used by more than one thread then access to the |
701d0765f75f
8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents:
14409
diff
changeset
|
57 |
* SerialArray should be controlled by appropriate synchronization. |
701d0765f75f
8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents:
14409
diff
changeset
|
58 |
* |
24968
3308660aa3f2
8046389: Add missing @since tag under javax.sql.**
henryjen
parents:
18564
diff
changeset
|
59 |
* @since 1.5 |
2 | 60 |
*/ |
61 |
public class SerialArray implements Array, Serializable, Cloneable { |
|
62 |
||
14781
701d0765f75f
8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents:
14409
diff
changeset
|
63 |
/** |
701d0765f75f
8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents:
14409
diff
changeset
|
64 |
* A serialized array in which each element is an <code>Object</code> |
701d0765f75f
8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents:
14409
diff
changeset
|
65 |
* in the Java programming language that represents an element |
701d0765f75f
8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents:
14409
diff
changeset
|
66 |
* in the SQL <code>ARRAY</code> value. |
701d0765f75f
8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents:
14409
diff
changeset
|
67 |
* @serial |
701d0765f75f
8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents:
14409
diff
changeset
|
68 |
*/ |
2 | 69 |
private Object[] elements; |
70 |
||
14781
701d0765f75f
8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents:
14409
diff
changeset
|
71 |
/** |
701d0765f75f
8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents:
14409
diff
changeset
|
72 |
* The SQL type of the elements in this <code>SerialArray</code> object. The |
701d0765f75f
8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents:
14409
diff
changeset
|
73 |
* type is expressed as one of the constants from the class |
701d0765f75f
8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents:
14409
diff
changeset
|
74 |
* <code>java.sql.Types</code>. |
701d0765f75f
8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents:
14409
diff
changeset
|
75 |
* @serial |
701d0765f75f
8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents:
14409
diff
changeset
|
76 |
*/ |
2 | 77 |
private int baseType; |
78 |
||
14781
701d0765f75f
8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents:
14409
diff
changeset
|
79 |
/** |
701d0765f75f
8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents:
14409
diff
changeset
|
80 |
* The type name used by the DBMS for the elements in the SQL <code>ARRAY</code> |
701d0765f75f
8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents:
14409
diff
changeset
|
81 |
* value that this <code>SerialArray</code> object represents. |
701d0765f75f
8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents:
14409
diff
changeset
|
82 |
* @serial |
701d0765f75f
8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents:
14409
diff
changeset
|
83 |
*/ |
2 | 84 |
private String baseTypeName; |
85 |
||
14781
701d0765f75f
8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents:
14409
diff
changeset
|
86 |
/** |
701d0765f75f
8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents:
14409
diff
changeset
|
87 |
* The number of elements in this <code>SerialArray</code> object, which |
701d0765f75f
8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents:
14409
diff
changeset
|
88 |
* is also the number of elements in the SQL <code>ARRAY</code> value |
701d0765f75f
8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents:
14409
diff
changeset
|
89 |
* that this <code>SerialArray</code> object represents. |
701d0765f75f
8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents:
14409
diff
changeset
|
90 |
* @serial |
701d0765f75f
8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents:
14409
diff
changeset
|
91 |
*/ |
2 | 92 |
private int len; |
93 |
||
94 |
/** |
|
95 |
* Constructs a new <code>SerialArray</code> object from the given |
|
96 |
* <code>Array</code> object, using the given type map for the custom |
|
97 |
* mapping of each element when the elements are SQL UDTs. |
|
98 |
* <P> |
|
99 |
* This method does custom mapping if the array elements are a UDT |
|
100 |
* and the given type map has an entry for that UDT. |
|
101 |
* Custom mapping is recursive, |
|
102 |
* meaning that if, for instance, an element of an SQL structured type |
|
103 |
* is an SQL structured type that itself has an element that is an SQL |
|
104 |
* structured type, each structured type that has a custom mapping will be |
|
105 |
* mapped according to the given type map. |
|
106 |
* <P> |
|
107 |
* The new <code>SerialArray</code> |
|
108 |
* object contains the same elements as the <code>Array</code> object |
|
109 |
* from which it is built, except when the base type is the SQL type |
|
110 |
* <code>STRUCT</code>, <code>ARRAY</code>, <code>BLOB</code>, |
|
111 |
* <code>CLOB</code>, <code>DATALINK</code> or <code>JAVA_OBJECT</code>. |
|
112 |
* In this case, each element in the new |
|
113 |
* <code>SerialArray</code> object is the appropriate serialized form, |
|
114 |
* that is, a <code>SerialStruct</code>, <code>SerialArray</code>, |
|
115 |
* <code>SerialBlob</code>, <code>SerialClob</code>, |
|
116 |
* <code>SerialDatalink</code>, or <code>SerialJavaObject</code> object. |
|
117 |
* <P> |
|
118 |
* Note: (1) The <code>Array</code> object from which a <code>SerialArray</code> |
|
119 |
* object is created must have materialized the SQL <code>ARRAY</code> value's |
|
120 |
* data on the client before it is passed to the constructor. Otherwise, |
|
121 |
* the new <code>SerialArray</code> object will contain no data. |
|
122 |
* <p> |
|
123 |
* Note: (2) If the <code>Array</code> contains <code>java.sql.Types.JAVA_OBJECT</code> |
|
124 |
* types, the <code>SerialJavaObject</code> constructor is called where checks |
|
125 |
* are made to ensure this object is serializable. |
|
126 |
* <p> |
|
127 |
* Note: (3) The <code>Array</code> object supplied to this constructor cannot |
|
128 |
* return <code>null</code> for any <code>Array.getArray()</code> methods. |
|
129 |
* <code>SerialArray</code> cannot serialize null array values. |
|
130 |
* |
|
131 |
* |
|
132 |
* @param array the <code>Array</code> object to be serialized |
|
133 |
* @param map a <code>java.util.Map</code> object in which |
|
134 |
* each entry consists of 1) a <code>String</code> object |
|
135 |
* giving the fully qualified name of a UDT (an SQL structured type or |
|
136 |
* distinct type) and 2) the |
|
137 |
* <code>Class</code> object for the <code>SQLData</code> implementation |
|
138 |
* that defines how the UDT is to be mapped. The <i>map</i> |
|
139 |
* parameter does not have any effect for <code>Blob</code>, |
|
140 |
* <code>Clob</code>, <code>DATALINK</code>, or |
|
141 |
* <code>JAVA_OBJECT</code> types. |
|
142 |
* @throws SerialException if an error occurs serializing the |
|
143 |
* <code>Array</code> object |
|
144 |
* @throws SQLException if a database access error occurs or if the |
|
145 |
* <i>array</i> or the <i>map</i> values are <code>null</code> |
|
146 |
*/ |
|
147 |
public SerialArray(Array array, Map<String,Class<?>> map) |
|
148 |
throws SerialException, SQLException |
|
149 |
{ |
|
150 |
||
151 |
if ((array == null) || (map == null)) { |
|
152 |
throw new SQLException("Cannot instantiate a SerialArray " + |
|
153 |
"object with null parameters"); |
|
154 |
} |
|
155 |
||
156 |
if ((elements = (Object[])array.getArray()) == null) { |
|
157 |
throw new SQLException("Invalid Array object. Calls to Array.getArray() " + |
|
158 |
"return null value which cannot be serialized"); |
|
159 |
} |
|
160 |
||
161 |
elements = (Object[])array.getArray(map); |
|
162 |
baseType = array.getBaseType(); |
|
163 |
baseTypeName = array.getBaseTypeName(); |
|
164 |
len = elements.length; |
|
165 |
||
166 |
switch (baseType) { |
|
167 |
case java.sql.Types.STRUCT: |
|
168 |
for (int i = 0; i < len; i++) { |
|
169 |
elements[i] = new SerialStruct((Struct)elements[i], map); |
|
170 |
} |
|
171 |
break; |
|
172 |
||
173 |
case java.sql.Types.ARRAY: |
|
174 |
for (int i = 0; i < len; i++) { |
|
175 |
elements[i] = new SerialArray((Array)elements[i], map); |
|
176 |
} |
|
177 |
break; |
|
178 |
||
179 |
case java.sql.Types.BLOB: |
|
180 |
for (int i = 0; i < len; i++) { |
|
181 |
elements[i] = new SerialBlob((Blob)elements[i]); |
|
182 |
} |
|
183 |
break; |
|
184 |
||
185 |
case java.sql.Types.CLOB: |
|
186 |
for (int i = 0; i < len; i++) { |
|
187 |
elements[i] = new SerialClob((Clob)elements[i]); |
|
188 |
} |
|
189 |
break; |
|
190 |
||
191 |
case java.sql.Types.DATALINK: |
|
192 |
for (int i = 0; i < len; i++) { |
|
193 |
elements[i] = new SerialDatalink((URL)elements[i]); |
|
194 |
} |
|
195 |
break; |
|
196 |
||
197 |
case java.sql.Types.JAVA_OBJECT: |
|
198 |
for (int i = 0; i < len; i++) { |
|
11129
f9ad1aadf3fa
7116445: Miscellaneous warnings in the JDBC/RowSet classes
lancea
parents:
5506
diff
changeset
|
199 |
elements[i] = new SerialJavaObject(elements[i]); |
2 | 200 |
} |
201 |
} |
|
202 |
} |
|
203 |
||
204 |
/** |
|
25976
4de01a56e3ee
8054555: javadoc cleanup for java.sql and javax.sql
lancea
parents:
24968
diff
changeset
|
205 |
* This method frees the {@code SerialArray} object and releases the |
14781
701d0765f75f
8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents:
14409
diff
changeset
|
206 |
* resources that it holds. The object is invalid once the {@code free} |
701d0765f75f
8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents:
14409
diff
changeset
|
207 |
* method is called. <p> If {@code free} is called multiple times, the |
701d0765f75f
8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents:
14409
diff
changeset
|
208 |
* subsequent calls to {@code free} are treated as a no-op. </P> |
2 | 209 |
* |
14781
701d0765f75f
8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents:
14409
diff
changeset
|
210 |
* @throws SQLException if an error occurs releasing the SerialArray's resources |
2 | 211 |
* @since 1.6 |
212 |
*/ |
|
213 |
public void free() throws SQLException { |
|
14781
701d0765f75f
8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents:
14409
diff
changeset
|
214 |
if (elements != null) { |
701d0765f75f
8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents:
14409
diff
changeset
|
215 |
elements = null; |
701d0765f75f
8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents:
14409
diff
changeset
|
216 |
baseTypeName= null; |
701d0765f75f
8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents:
14409
diff
changeset
|
217 |
} |
2 | 218 |
} |
219 |
||
220 |
/** |
|
221 |
* Constructs a new <code>SerialArray</code> object from the given |
|
222 |
* <code>Array</code> object. |
|
223 |
* <P> |
|
224 |
* This constructor does not do custom mapping. If the base type of the array |
|
225 |
* is an SQL structured type and custom mapping is desired, the constructor |
|
226 |
* <code>SerialArray(Array array, Map map)</code> should be used. |
|
227 |
* <P> |
|
228 |
* The new <code>SerialArray</code> |
|
229 |
* object contains the same elements as the <code>Array</code> object |
|
230 |
* from which it is built, except when the base type is the SQL type |
|
231 |
* <code>BLOB</code>, |
|
232 |
* <code>CLOB</code>, <code>DATALINK</code> or <code>JAVA_OBJECT</code>. |
|
233 |
* In this case, each element in the new |
|
234 |
* <code>SerialArray</code> object is the appropriate serialized form, |
|
235 |
* that is, a <code>SerialBlob</code>, <code>SerialClob</code>, |
|
236 |
* <code>SerialDatalink</code>, or <code>SerialJavaObject</code> object. |
|
237 |
* <P> |
|
238 |
* Note: (1) The <code>Array</code> object from which a <code>SerialArray</code> |
|
239 |
* object is created must have materialized the SQL <code>ARRAY</code> value's |
|
240 |
* data on the client before it is passed to the constructor. Otherwise, |
|
241 |
* the new <code>SerialArray</code> object will contain no data. |
|
242 |
* <p> |
|
243 |
* Note: (2) The <code>Array</code> object supplied to this constructor cannot |
|
244 |
* return <code>null</code> for any <code>Array.getArray()</code> methods. |
|
245 |
* <code>SerialArray</code> cannot serialize <code>null</code> array values. |
|
246 |
* |
|
247 |
* @param array the <code>Array</code> object to be serialized |
|
248 |
* @throws SerialException if an error occurs serializing the |
|
249 |
* <code>Array</code> object |
|
250 |
* @throws SQLException if a database access error occurs or the |
|
251 |
* <i>array</i> parameter is <code>null</code>. |
|
252 |
*/ |
|
253 |
public SerialArray(Array array) throws SerialException, SQLException { |
|
254 |
if (array == null) { |
|
255 |
throw new SQLException("Cannot instantiate a SerialArray " + |
|
256 |
"object with a null Array object"); |
|
257 |
} |
|
258 |
||
259 |
if ((elements = (Object[])array.getArray()) == null) { |
|
260 |
throw new SQLException("Invalid Array object. Calls to Array.getArray() " + |
|
261 |
"return null value which cannot be serialized"); |
|
262 |
} |
|
263 |
||
264 |
//elements = (Object[])array.getArray(); |
|
265 |
baseType = array.getBaseType(); |
|
266 |
baseTypeName = array.getBaseTypeName(); |
|
267 |
len = elements.length; |
|
268 |
||
269 |
switch (baseType) { |
|
270 |
||
271 |
case java.sql.Types.BLOB: |
|
272 |
for (int i = 0; i < len; i++) { |
|
273 |
elements[i] = new SerialBlob((Blob)elements[i]); |
|
274 |
} |
|
275 |
break; |
|
276 |
||
277 |
case java.sql.Types.CLOB: |
|
278 |
for (int i = 0; i < len; i++) { |
|
279 |
elements[i] = new SerialClob((Clob)elements[i]); |
|
280 |
} |
|
281 |
break; |
|
282 |
||
283 |
case java.sql.Types.DATALINK: |
|
284 |
for (int i = 0; i < len; i++) { |
|
285 |
elements[i] = new SerialDatalink((URL)elements[i]); |
|
286 |
} |
|
287 |
break; |
|
288 |
||
289 |
case java.sql.Types.JAVA_OBJECT: |
|
290 |
for (int i = 0; i < len; i++) { |
|
11129
f9ad1aadf3fa
7116445: Miscellaneous warnings in the JDBC/RowSet classes
lancea
parents:
5506
diff
changeset
|
291 |
elements[i] = new SerialJavaObject(elements[i]); |
2 | 292 |
} |
11129
f9ad1aadf3fa
7116445: Miscellaneous warnings in the JDBC/RowSet classes
lancea
parents:
5506
diff
changeset
|
293 |
break; |
2 | 294 |
|
295 |
} |
|
296 |
||
297 |
||
298 |
} |
|
299 |
||
14781
701d0765f75f
8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents:
14409
diff
changeset
|
300 |
/** |
701d0765f75f
8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents:
14409
diff
changeset
|
301 |
* Returns a new array that is a copy of this <code>SerialArray</code> |
701d0765f75f
8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents:
14409
diff
changeset
|
302 |
* object. |
701d0765f75f
8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents:
14409
diff
changeset
|
303 |
* |
701d0765f75f
8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents:
14409
diff
changeset
|
304 |
* @return a copy of this <code>SerialArray</code> object as an |
701d0765f75f
8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents:
14409
diff
changeset
|
305 |
* <code>Object</code> in the Java programming language |
701d0765f75f
8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents:
14409
diff
changeset
|
306 |
* @throws SerialException if an error occurs; |
701d0765f75f
8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents:
14409
diff
changeset
|
307 |
* if {@code free} had previously been called on this object |
701d0765f75f
8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents:
14409
diff
changeset
|
308 |
*/ |
2 | 309 |
public Object getArray() throws SerialException { |
14781
701d0765f75f
8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents:
14409
diff
changeset
|
310 |
isValid(); |
2 | 311 |
Object dst = new Object[len]; |
312 |
System.arraycopy((Object)elements, 0, dst, 0, len); |
|
313 |
return dst; |
|
314 |
} |
|
315 |
||
14781
701d0765f75f
8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents:
14409
diff
changeset
|
316 |
/** |
701d0765f75f
8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents:
14409
diff
changeset
|
317 |
* Returns a new array that is a copy of this <code>SerialArray</code> |
701d0765f75f
8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents:
14409
diff
changeset
|
318 |
* object, using the given type map for the custom |
701d0765f75f
8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents:
14409
diff
changeset
|
319 |
* mapping of each element when the elements are SQL UDTs. |
701d0765f75f
8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents:
14409
diff
changeset
|
320 |
* <P> |
701d0765f75f
8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents:
14409
diff
changeset
|
321 |
* This method does custom mapping if the array elements are a UDT |
701d0765f75f
8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents:
14409
diff
changeset
|
322 |
* and the given type map has an entry for that UDT. |
2 | 323 |
* Custom mapping is recursive, |
14781
701d0765f75f
8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents:
14409
diff
changeset
|
324 |
* meaning that if, for instance, an element of an SQL structured type |
701d0765f75f
8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents:
14409
diff
changeset
|
325 |
* is an SQL structured type that itself has an element that is an SQL |
701d0765f75f
8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents:
14409
diff
changeset
|
326 |
* structured type, each structured type that has a custom mapping will be |
701d0765f75f
8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents:
14409
diff
changeset
|
327 |
* mapped according to the given type map. |
701d0765f75f
8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents:
14409
diff
changeset
|
328 |
* |
2 | 329 |
* @param map a <code>java.util.Map</code> object in which |
330 |
* each entry consists of 1) a <code>String</code> object |
|
331 |
* giving the fully qualified name of a UDT and 2) the |
|
332 |
* <code>Class</code> object for the <code>SQLData</code> implementation |
|
333 |
* that defines how the UDT is to be mapped |
|
14781
701d0765f75f
8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents:
14409
diff
changeset
|
334 |
* @return a copy of this <code>SerialArray</code> object as an |
701d0765f75f
8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents:
14409
diff
changeset
|
335 |
* <code>Object</code> in the Java programming language |
701d0765f75f
8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents:
14409
diff
changeset
|
336 |
* @throws SerialException if an error occurs; |
701d0765f75f
8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents:
14409
diff
changeset
|
337 |
* if {@code free} had previously been called on this object |
701d0765f75f
8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents:
14409
diff
changeset
|
338 |
*/ |
2 | 339 |
public Object getArray(Map<String, Class<?>> map) throws SerialException { |
14781
701d0765f75f
8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents:
14409
diff
changeset
|
340 |
isValid(); |
2 | 341 |
Object dst[] = new Object[len]; |
342 |
System.arraycopy((Object)elements, 0, dst, 0, len); |
|
343 |
return dst; |
|
344 |
} |
|
345 |
||
14781
701d0765f75f
8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents:
14409
diff
changeset
|
346 |
/** |
701d0765f75f
8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents:
14409
diff
changeset
|
347 |
* Returns a new array that is a copy of a slice |
701d0765f75f
8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents:
14409
diff
changeset
|
348 |
* of this <code>SerialArray</code> object, starting with the |
701d0765f75f
8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents:
14409
diff
changeset
|
349 |
* element at the given index and containing the given number |
701d0765f75f
8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents:
14409
diff
changeset
|
350 |
* of consecutive elements. |
701d0765f75f
8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents:
14409
diff
changeset
|
351 |
* |
701d0765f75f
8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents:
14409
diff
changeset
|
352 |
* @param index the index into this <code>SerialArray</code> object |
701d0765f75f
8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents:
14409
diff
changeset
|
353 |
* of the first element to be copied; |
701d0765f75f
8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents:
14409
diff
changeset
|
354 |
* the index of the first element is <code>0</code> |
701d0765f75f
8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents:
14409
diff
changeset
|
355 |
* @param count the number of consecutive elements to be copied, starting |
701d0765f75f
8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents:
14409
diff
changeset
|
356 |
* at the given index |
701d0765f75f
8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents:
14409
diff
changeset
|
357 |
* @return a copy of the designated elements in this <code>SerialArray</code> |
701d0765f75f
8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents:
14409
diff
changeset
|
358 |
* object as an <code>Object</code> in the Java programming language |
701d0765f75f
8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents:
14409
diff
changeset
|
359 |
* @throws SerialException if an error occurs; |
701d0765f75f
8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents:
14409
diff
changeset
|
360 |
* if {@code free} had previously been called on this object |
701d0765f75f
8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents:
14409
diff
changeset
|
361 |
*/ |
2 | 362 |
public Object getArray(long index, int count) throws SerialException { |
14781
701d0765f75f
8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents:
14409
diff
changeset
|
363 |
isValid(); |
2 | 364 |
Object dst = new Object[count]; |
365 |
System.arraycopy((Object)elements, (int)index, dst, 0, count); |
|
366 |
return dst; |
|
367 |
} |
|
368 |
||
14781
701d0765f75f
8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents:
14409
diff
changeset
|
369 |
/** |
701d0765f75f
8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents:
14409
diff
changeset
|
370 |
* Returns a new array that is a copy of a slice |
701d0765f75f
8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents:
14409
diff
changeset
|
371 |
* of this <code>SerialArray</code> object, starting with the |
701d0765f75f
8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents:
14409
diff
changeset
|
372 |
* element at the given index and containing the given number |
701d0765f75f
8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents:
14409
diff
changeset
|
373 |
* of consecutive elements. |
701d0765f75f
8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents:
14409
diff
changeset
|
374 |
* <P> |
701d0765f75f
8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents:
14409
diff
changeset
|
375 |
* This method does custom mapping if the array elements are a UDT |
701d0765f75f
8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents:
14409
diff
changeset
|
376 |
* and the given type map has an entry for that UDT. |
2 | 377 |
* Custom mapping is recursive, |
14781
701d0765f75f
8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents:
14409
diff
changeset
|
378 |
* meaning that if, for instance, an element of an SQL structured type |
701d0765f75f
8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents:
14409
diff
changeset
|
379 |
* is an SQL structured type that itself has an element that is an SQL |
701d0765f75f
8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents:
14409
diff
changeset
|
380 |
* structured type, each structured type that has a custom mapping will be |
701d0765f75f
8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents:
14409
diff
changeset
|
381 |
* mapped according to the given type map. |
701d0765f75f
8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents:
14409
diff
changeset
|
382 |
* |
701d0765f75f
8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents:
14409
diff
changeset
|
383 |
* @param index the index into this <code>SerialArray</code> object |
701d0765f75f
8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents:
14409
diff
changeset
|
384 |
* of the first element to be copied; the index of the |
701d0765f75f
8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents:
14409
diff
changeset
|
385 |
* first element in the array is <code>0</code> |
701d0765f75f
8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents:
14409
diff
changeset
|
386 |
* @param count the number of consecutive elements to be copied, starting |
701d0765f75f
8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents:
14409
diff
changeset
|
387 |
* at the given index |
2 | 388 |
* @param map a <code>java.util.Map</code> object in which |
389 |
* each entry consists of 1) a <code>String</code> object |
|
390 |
* giving the fully qualified name of a UDT and 2) the |
|
391 |
* <code>Class</code> object for the <code>SQLData</code> implementation |
|
392 |
* that defines how the UDT is to be mapped |
|
14781
701d0765f75f
8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents:
14409
diff
changeset
|
393 |
* @return a copy of the designated elements in this <code>SerialArray</code> |
701d0765f75f
8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents:
14409
diff
changeset
|
394 |
* object as an <code>Object</code> in the Java programming language |
701d0765f75f
8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents:
14409
diff
changeset
|
395 |
* @throws SerialException if an error occurs; |
701d0765f75f
8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents:
14409
diff
changeset
|
396 |
* if {@code free} had previously been called on this object |
701d0765f75f
8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents:
14409
diff
changeset
|
397 |
*/ |
2 | 398 |
public Object getArray(long index, int count, Map<String,Class<?>> map) |
399 |
throws SerialException |
|
400 |
{ |
|
14781
701d0765f75f
8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents:
14409
diff
changeset
|
401 |
isValid(); |
2 | 402 |
Object dst = new Object[count]; |
403 |
System.arraycopy((Object)elements, (int)index, dst, 0, count); |
|
404 |
return dst; |
|
405 |
} |
|
406 |
||
14781
701d0765f75f
8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents:
14409
diff
changeset
|
407 |
/** |
701d0765f75f
8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents:
14409
diff
changeset
|
408 |
* Retrieves the SQL type of the elements in this <code>SerialArray</code> |
701d0765f75f
8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents:
14409
diff
changeset
|
409 |
* object. The <code>int</code> returned is one of the constants in the class |
701d0765f75f
8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents:
14409
diff
changeset
|
410 |
* <code>java.sql.Types</code>. |
701d0765f75f
8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents:
14409
diff
changeset
|
411 |
* |
701d0765f75f
8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents:
14409
diff
changeset
|
412 |
* @return one of the constants in <code>java.sql.Types</code>, indicating |
701d0765f75f
8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents:
14409
diff
changeset
|
413 |
* the SQL type of the elements in this <code>SerialArray</code> object |
701d0765f75f
8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents:
14409
diff
changeset
|
414 |
* @throws SerialException if an error occurs; |
701d0765f75f
8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents:
14409
diff
changeset
|
415 |
* if {@code free} had previously been called on this object |
701d0765f75f
8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents:
14409
diff
changeset
|
416 |
*/ |
2 | 417 |
public int getBaseType() throws SerialException { |
14781
701d0765f75f
8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents:
14409
diff
changeset
|
418 |
isValid(); |
2 | 419 |
return baseType; |
420 |
} |
|
421 |
||
14781
701d0765f75f
8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents:
14409
diff
changeset
|
422 |
/** |
701d0765f75f
8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents:
14409
diff
changeset
|
423 |
* Retrieves the DBMS-specific type name for the elements in this |
701d0765f75f
8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents:
14409
diff
changeset
|
424 |
* <code>SerialArray</code> object. |
701d0765f75f
8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents:
14409
diff
changeset
|
425 |
* |
701d0765f75f
8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents:
14409
diff
changeset
|
426 |
* @return the SQL type name used by the DBMS for the base type of this |
2 | 427 |
* <code>SerialArray</code> object |
14781
701d0765f75f
8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents:
14409
diff
changeset
|
428 |
* @throws SerialException if an error occurs; |
701d0765f75f
8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents:
14409
diff
changeset
|
429 |
* if {@code free} had previously been called on this object |
701d0765f75f
8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents:
14409
diff
changeset
|
430 |
*/ |
2 | 431 |
public String getBaseTypeName() throws SerialException { |
14781
701d0765f75f
8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents:
14409
diff
changeset
|
432 |
isValid(); |
2 | 433 |
return baseTypeName; |
434 |
} |
|
435 |
||
436 |
/** |
|
437 |
* Retrieves a <code>ResultSet</code> object holding the elements of |
|
438 |
* the subarray that starts at |
|
439 |
* index <i>index</i> and contains up to <i>count</i> successive elements. |
|
440 |
* This method uses the connection's type map to map the elements of |
|
441 |
* the array if the map contains |
|
442 |
* an entry for the base type. Otherwise, the standard mapping is used. |
|
443 |
* |
|
444 |
* @param index the index into this <code>SerialArray</code> object |
|
445 |
* of the first element to be copied; the index of the |
|
446 |
* first element in the array is <code>0</code> |
|
447 |
* @param count the number of consecutive elements to be copied, starting |
|
448 |
* at the given index |
|
449 |
* @return a <code>ResultSet</code> object containing the designated |
|
450 |
* elements in this <code>SerialArray</code> object, with a |
|
451 |
* separate row for each element |
|
14781
701d0765f75f
8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents:
14409
diff
changeset
|
452 |
* @throws SerialException if called with the cause set to |
701d0765f75f
8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents:
14409
diff
changeset
|
453 |
* {@code UnsupportedOperationException} |
2 | 454 |
*/ |
455 |
public ResultSet getResultSet(long index, int count) throws SerialException { |
|
14781
701d0765f75f
8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents:
14409
diff
changeset
|
456 |
SerialException se = new SerialException(); |
701d0765f75f
8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents:
14409
diff
changeset
|
457 |
se.initCause(new UnsupportedOperationException()); |
701d0765f75f
8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents:
14409
diff
changeset
|
458 |
throw se; |
2 | 459 |
} |
460 |
||
461 |
/** |
|
462 |
* |
|
463 |
* Retrieves a <code>ResultSet</code> object that contains all of |
|
464 |
* the elements of the SQL <code>ARRAY</code> |
|
465 |
* value represented by this <code>SerialArray</code> object. This method uses |
|
466 |
* the specified map for type map customizations unless the base type of the |
|
467 |
* array does not match a user-defined type (UDT) in <i>map</i>, in |
|
468 |
* which case it uses the |
|
469 |
* standard mapping. This version of the method <code>getResultSet</code> |
|
470 |
* uses either the given type map or the standard mapping; it never uses the |
|
471 |
* type map associated with the connection. |
|
472 |
* |
|
473 |
* @param map a <code>java.util.Map</code> object in which |
|
474 |
* each entry consists of 1) a <code>String</code> object |
|
475 |
* giving the fully qualified name of a UDT and 2) the |
|
476 |
* <code>Class</code> object for the <code>SQLData</code> implementation |
|
477 |
* that defines how the UDT is to be mapped |
|
478 |
* @return a <code>ResultSet</code> object containing all of the |
|
479 |
* elements in this <code>SerialArray</code> object, with a |
|
480 |
* separate row for each element |
|
14781
701d0765f75f
8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents:
14409
diff
changeset
|
481 |
* @throws SerialException if called with the cause set to |
701d0765f75f
8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents:
14409
diff
changeset
|
482 |
* {@code UnsupportedOperationException} |
2 | 483 |
*/ |
484 |
public ResultSet getResultSet(Map<String, Class<?>> map) |
|
485 |
throws SerialException |
|
486 |
{ |
|
14781
701d0765f75f
8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents:
14409
diff
changeset
|
487 |
SerialException se = new SerialException(); |
701d0765f75f
8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents:
14409
diff
changeset
|
488 |
se.initCause(new UnsupportedOperationException()); |
701d0765f75f
8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents:
14409
diff
changeset
|
489 |
throw se; |
2 | 490 |
} |
491 |
||
492 |
/** |
|
493 |
* Retrieves a <code>ResultSet</code> object that contains all of |
|
494 |
* the elements in the <code>ARRAY</code> value that this |
|
495 |
* <code>SerialArray</code> object represents. |
|
496 |
* If appropriate, the elements of the array are mapped using the connection's |
|
497 |
* type map; otherwise, the standard mapping is used. |
|
498 |
* |
|
499 |
* @return a <code>ResultSet</code> object containing all of the |
|
500 |
* elements in this <code>SerialArray</code> object, with a |
|
501 |
* separate row for each element |
|
14781
701d0765f75f
8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents:
14409
diff
changeset
|
502 |
* @throws SerialException if called with the cause set to |
701d0765f75f
8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents:
14409
diff
changeset
|
503 |
* {@code UnsupportedOperationException} |
2 | 504 |
*/ |
505 |
public ResultSet getResultSet() throws SerialException { |
|
14781
701d0765f75f
8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents:
14409
diff
changeset
|
506 |
SerialException se = new SerialException(); |
701d0765f75f
8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents:
14409
diff
changeset
|
507 |
se.initCause(new UnsupportedOperationException()); |
701d0765f75f
8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents:
14409
diff
changeset
|
508 |
throw se; |
2 | 509 |
} |
510 |
||
511 |
||
512 |
/** |
|
513 |
* Retrieves a result set holding the elements of the subarray that starts at |
|
514 |
* Retrieves a <code>ResultSet</code> object that contains a subarray of the |
|
515 |
* elements in this <code>SerialArray</code> object, starting at |
|
516 |
* index <i>index</i> and containing up to <i>count</i> successive |
|
517 |
* elements. This method uses |
|
518 |
* the specified map for type map customizations unless the base type of the |
|
519 |
* array does not match a user-defined type (UDT) in <i>map</i>, in |
|
520 |
* which case it uses the |
|
521 |
* standard mapping. This version of the method <code>getResultSet</code> uses |
|
522 |
* either the given type map or the standard mapping; it never uses the type |
|
523 |
* map associated with the connection. |
|
524 |
* |
|
525 |
* @param index the index into this <code>SerialArray</code> object |
|
526 |
* of the first element to be copied; the index of the |
|
527 |
* first element in the array is <code>0</code> |
|
528 |
* @param count the number of consecutive elements to be copied, starting |
|
529 |
* at the given index |
|
530 |
* @param map a <code>java.util.Map</code> object in which |
|
531 |
* each entry consists of 1) a <code>String</code> object |
|
532 |
* giving the fully qualified name of a UDT and 2) the |
|
533 |
* <code>Class</code> object for the <code>SQLData</code> implementation |
|
534 |
* that defines how the UDT is to be mapped |
|
535 |
* @return a <code>ResultSet</code> object containing the designated |
|
536 |
* elements in this <code>SerialArray</code> object, with a |
|
537 |
* separate row for each element |
|
14781
701d0765f75f
8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents:
14409
diff
changeset
|
538 |
* @throws SerialException if called with the cause set to |
701d0765f75f
8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents:
14409
diff
changeset
|
539 |
* {@code UnsupportedOperationException} |
2 | 540 |
*/ |
541 |
public ResultSet getResultSet(long index, int count, |
|
542 |
Map<String,Class<?>> map) |
|
543 |
throws SerialException |
|
544 |
{ |
|
14781
701d0765f75f
8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents:
14409
diff
changeset
|
545 |
SerialException se = new SerialException(); |
701d0765f75f
8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents:
14409
diff
changeset
|
546 |
se.initCause(new UnsupportedOperationException()); |
701d0765f75f
8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents:
14409
diff
changeset
|
547 |
throw se; |
2 | 548 |
} |
549 |
||
14781
701d0765f75f
8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents:
14409
diff
changeset
|
550 |
|
2 | 551 |
/** |
14409
d879c92507ec
8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents:
14342
diff
changeset
|
552 |
* Compares this SerialArray to the specified object. The result is {@code |
d879c92507ec
8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents:
14342
diff
changeset
|
553 |
* true} if and only if the argument is not {@code null} and is a {@code |
d879c92507ec
8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents:
14342
diff
changeset
|
554 |
* SerialArray} object whose elements are identical to this object's elements |
d879c92507ec
8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents:
14342
diff
changeset
|
555 |
* |
d879c92507ec
8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents:
14342
diff
changeset
|
556 |
* @param obj The object to compare this {@code SerialArray} against |
d879c92507ec
8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents:
14342
diff
changeset
|
557 |
* |
d879c92507ec
8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents:
14342
diff
changeset
|
558 |
* @return {@code true} if the given object represents a {@code SerialArray} |
d879c92507ec
8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents:
14342
diff
changeset
|
559 |
* equivalent to this SerialArray, {@code false} otherwise |
d879c92507ec
8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents:
14342
diff
changeset
|
560 |
* |
d879c92507ec
8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents:
14342
diff
changeset
|
561 |
*/ |
d879c92507ec
8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents:
14342
diff
changeset
|
562 |
public boolean equals(Object obj) { |
d879c92507ec
8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents:
14342
diff
changeset
|
563 |
if (this == obj) { |
d879c92507ec
8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents:
14342
diff
changeset
|
564 |
return true; |
d879c92507ec
8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents:
14342
diff
changeset
|
565 |
} |
d879c92507ec
8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents:
14342
diff
changeset
|
566 |
|
d879c92507ec
8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents:
14342
diff
changeset
|
567 |
if (obj instanceof SerialArray) { |
d879c92507ec
8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents:
14342
diff
changeset
|
568 |
SerialArray sa = (SerialArray)obj; |
d879c92507ec
8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents:
14342
diff
changeset
|
569 |
return baseType == sa.baseType && |
d879c92507ec
8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents:
14342
diff
changeset
|
570 |
baseTypeName.equals(sa.baseTypeName) && |
d879c92507ec
8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents:
14342
diff
changeset
|
571 |
Arrays.equals(elements, sa.elements); |
d879c92507ec
8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents:
14342
diff
changeset
|
572 |
} |
d879c92507ec
8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents:
14342
diff
changeset
|
573 |
return false; |
d879c92507ec
8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents:
14342
diff
changeset
|
574 |
} |
d879c92507ec
8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents:
14342
diff
changeset
|
575 |
|
d879c92507ec
8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents:
14342
diff
changeset
|
576 |
/** |
d879c92507ec
8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents:
14342
diff
changeset
|
577 |
* Returns a hash code for this SerialArray. The hash code for a |
d879c92507ec
8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents:
14342
diff
changeset
|
578 |
* {@code SerialArray} object is computed using the hash codes |
d879c92507ec
8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents:
14342
diff
changeset
|
579 |
* of the elements of the {@code SerialArray} object |
d879c92507ec
8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents:
14342
diff
changeset
|
580 |
* |
d879c92507ec
8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents:
14342
diff
changeset
|
581 |
* @return a hash code value for this object. |
d879c92507ec
8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents:
14342
diff
changeset
|
582 |
*/ |
d879c92507ec
8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents:
14342
diff
changeset
|
583 |
public int hashCode() { |
d879c92507ec
8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents:
14342
diff
changeset
|
584 |
return (((31 + Arrays.hashCode(elements)) * 31 + len) * 31 + |
d879c92507ec
8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents:
14342
diff
changeset
|
585 |
baseType) * 31 + baseTypeName.hashCode(); |
d879c92507ec
8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents:
14342
diff
changeset
|
586 |
} |
d879c92507ec
8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents:
14342
diff
changeset
|
587 |
|
d879c92507ec
8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents:
14342
diff
changeset
|
588 |
/** |
d879c92507ec
8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents:
14342
diff
changeset
|
589 |
* Returns a clone of this {@code SerialArray}. The copy will contain a |
d879c92507ec
8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents:
14342
diff
changeset
|
590 |
* reference to a clone of the underlying objects array, not a reference |
d879c92507ec
8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents:
14342
diff
changeset
|
591 |
* to the original underlying object array of this {@code SerialArray} object. |
d879c92507ec
8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents:
14342
diff
changeset
|
592 |
* |
14781
701d0765f75f
8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents:
14409
diff
changeset
|
593 |
* @return a clone of this SerialArray |
14409
d879c92507ec
8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents:
14342
diff
changeset
|
594 |
*/ |
d879c92507ec
8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents:
14342
diff
changeset
|
595 |
public Object clone() { |
d879c92507ec
8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents:
14342
diff
changeset
|
596 |
try { |
d879c92507ec
8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents:
14342
diff
changeset
|
597 |
SerialArray sa = (SerialArray) super.clone(); |
14781
701d0765f75f
8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents:
14409
diff
changeset
|
598 |
sa.elements = (elements != null) ? Arrays.copyOf(elements, len) : null; |
14409
d879c92507ec
8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents:
14342
diff
changeset
|
599 |
return sa; |
d879c92507ec
8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents:
14342
diff
changeset
|
600 |
} catch (CloneNotSupportedException ex) { |
d879c92507ec
8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents:
14342
diff
changeset
|
601 |
// this shouldn't happen, since we are Cloneable |
d879c92507ec
8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents:
14342
diff
changeset
|
602 |
throw new InternalError(); |
d879c92507ec
8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents:
14342
diff
changeset
|
603 |
} |
d879c92507ec
8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents:
14342
diff
changeset
|
604 |
|
d879c92507ec
8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents:
14342
diff
changeset
|
605 |
} |
d879c92507ec
8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents:
14342
diff
changeset
|
606 |
|
d879c92507ec
8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents:
14342
diff
changeset
|
607 |
/** |
d879c92507ec
8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents:
14342
diff
changeset
|
608 |
* readObject is called to restore the state of the {@code SerialArray} from |
d879c92507ec
8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents:
14342
diff
changeset
|
609 |
* a stream. |
d879c92507ec
8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents:
14342
diff
changeset
|
610 |
*/ |
d879c92507ec
8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents:
14342
diff
changeset
|
611 |
private void readObject(ObjectInputStream s) |
d879c92507ec
8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents:
14342
diff
changeset
|
612 |
throws IOException, ClassNotFoundException { |
d879c92507ec
8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents:
14342
diff
changeset
|
613 |
|
d879c92507ec
8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents:
14342
diff
changeset
|
614 |
ObjectInputStream.GetField fields = s.readFields(); |
d879c92507ec
8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents:
14342
diff
changeset
|
615 |
Object[] tmp = (Object[])fields.get("elements", null); |
d879c92507ec
8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents:
14342
diff
changeset
|
616 |
if (tmp == null) |
d879c92507ec
8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents:
14342
diff
changeset
|
617 |
throw new InvalidObjectException("elements is null and should not be!"); |
d879c92507ec
8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents:
14342
diff
changeset
|
618 |
elements = tmp.clone(); |
d879c92507ec
8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents:
14342
diff
changeset
|
619 |
len = fields.get("len", 0); |
d879c92507ec
8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents:
14342
diff
changeset
|
620 |
if(elements.length != len) |
d879c92507ec
8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents:
14342
diff
changeset
|
621 |
throw new InvalidObjectException("elements is not the expected size"); |
d879c92507ec
8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents:
14342
diff
changeset
|
622 |
|
d879c92507ec
8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents:
14342
diff
changeset
|
623 |
baseType = fields.get("baseType", 0); |
d879c92507ec
8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents:
14342
diff
changeset
|
624 |
baseTypeName = (String)fields.get("baseTypeName", null); |
d879c92507ec
8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents:
14342
diff
changeset
|
625 |
} |
d879c92507ec
8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents:
14342
diff
changeset
|
626 |
|
d879c92507ec
8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents:
14342
diff
changeset
|
627 |
/** |
d879c92507ec
8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents:
14342
diff
changeset
|
628 |
* writeObject is called to save the state of the {@code SerialArray} |
d879c92507ec
8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents:
14342
diff
changeset
|
629 |
* to a stream. |
d879c92507ec
8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents:
14342
diff
changeset
|
630 |
*/ |
d879c92507ec
8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents:
14342
diff
changeset
|
631 |
private void writeObject(ObjectOutputStream s) |
51181
01b8120f867a
8208060: Additional corrections of serial-related declarations
darcy
parents:
47216
diff
changeset
|
632 |
throws IOException { |
14409
d879c92507ec
8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents:
14342
diff
changeset
|
633 |
|
d879c92507ec
8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents:
14342
diff
changeset
|
634 |
ObjectOutputStream.PutField fields = s.putFields(); |
d879c92507ec
8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents:
14342
diff
changeset
|
635 |
fields.put("elements", elements); |
d879c92507ec
8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents:
14342
diff
changeset
|
636 |
fields.put("len", len); |
d879c92507ec
8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents:
14342
diff
changeset
|
637 |
fields.put("baseType", baseType); |
d879c92507ec
8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents:
14342
diff
changeset
|
638 |
fields.put("baseTypeName", baseTypeName); |
d879c92507ec
8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents:
14342
diff
changeset
|
639 |
s.writeFields(); |
d879c92507ec
8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents:
14342
diff
changeset
|
640 |
} |
d879c92507ec
8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents:
14342
diff
changeset
|
641 |
|
d879c92507ec
8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents:
14342
diff
changeset
|
642 |
/** |
14781
701d0765f75f
8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents:
14409
diff
changeset
|
643 |
* Check to see if this object had previously had its {@code free} method |
701d0765f75f
8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents:
14409
diff
changeset
|
644 |
* called |
701d0765f75f
8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents:
14409
diff
changeset
|
645 |
* |
701d0765f75f
8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents:
14409
diff
changeset
|
646 |
* @throws SerialException |
701d0765f75f
8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents:
14409
diff
changeset
|
647 |
*/ |
701d0765f75f
8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents:
14409
diff
changeset
|
648 |
private void isValid() throws SerialException { |
701d0765f75f
8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents:
14409
diff
changeset
|
649 |
if (elements == null) { |
701d0765f75f
8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents:
14409
diff
changeset
|
650 |
throw new SerialException("Error: You cannot call a method on a " |
701d0765f75f
8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents:
14409
diff
changeset
|
651 |
+ "SerialArray instance once free() has been called."); |
701d0765f75f
8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents:
14409
diff
changeset
|
652 |
} |
701d0765f75f
8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents:
14409
diff
changeset
|
653 |
} |
701d0765f75f
8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents:
14409
diff
changeset
|
654 |
|
701d0765f75f
8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents:
14409
diff
changeset
|
655 |
/** |
2 | 656 |
* The identifier that assists in the serialization of this <code>SerialArray</code> |
657 |
* object. |
|
658 |
*/ |
|
659 |
static final long serialVersionUID = -8466174297270688520L; |
|
660 |
} |