1 /*
2 * Copyright (c) 2003, 2013, 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
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++) {
199 elements[i] = new SerialJavaObject(elements[i]);
200 }
201 }
202 }
203
204 /**
205 * This method frees the {@code SeriableArray} object and releases the
206 * resources that it holds. The object is invalid once the {@code free}
207 * method is called. <p> If {@code free} is called multiple times, the
208 * subsequent calls to {@code free} are treated as a no-op. </P>
209 *
210 * @throws SQLException if an error occurs releasing the SerialArray's resources
211 * @since 1.6
212 */
213 public void free() throws SQLException {
214 if (elements != null) {
215 elements = null;
216 baseTypeName= null;
217 }
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
296
297
298 }
299
300 /**
301 * Returns a new array that is a copy of this <code>SerialArray</code>
302 * object.
303 *
304 * @return a copy of this <code>SerialArray</code> object as an
305 * <code>Object</code> in the Java programming language
306 * @throws SerialException if an error occurs;
307 * if {@code free} had previously been called on this object
308 */
309 public Object getArray() throws SerialException {
310 isValid();
311 Object dst = new Object[len];
312 System.arraycopy((Object)elements, 0, dst, 0, len);
313 return dst;
314 }
315
316 //[if an error occurstype map used??]
317 /**
318 * Returns a new array that is a copy of this <code>SerialArray</code>
319 * object, using the given type map for the custom
320 * mapping of each element when the elements are SQL UDTs.
321 * <P>
322 * This method does custom mapping if the array elements are a UDT
323 * and the given type map has an entry for that UDT.
324 * Custom mapping is recursive,
325 * meaning that if, for instance, an element of an SQL structured type
326 * is an SQL structured type that itself has an element that is an SQL
327 * structured type, each structured type that has a custom mapping will be
328 * mapped according to the given type map.
329 *
330 * @param map a <code>java.util.Map</code> object in which
331 * each entry consists of 1) a <code>String</code> object
332 * giving the fully qualified name of a UDT and 2) the
333 * <code>Class</code> object for the <code>SQLData</code> implementation
334 * that defines how the UDT is to be mapped
335 * @return a copy of this <code>SerialArray</code> object as an
336 * <code>Object</code> in the Java programming language
|
1 /*
2 * Copyright (c) 2003, 2014, 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
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++) {
199 elements[i] = new SerialJavaObject(elements[i]);
200 }
201 }
202 }
203
204 /**
205 * This method frees the {@code SerialArray} object and releases the
206 * resources that it holds. The object is invalid once the {@code free}
207 * method is called. <p> If {@code free} is called multiple times, the
208 * subsequent calls to {@code free} are treated as a no-op. </P>
209 *
210 * @throws SQLException if an error occurs releasing the SerialArray's resources
211 * @since 1.6
212 */
213 public void free() throws SQLException {
214 if (elements != null) {
215 elements = null;
216 baseTypeName= null;
217 }
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
296
297
298 }
299
300 /**
301 * Returns a new array that is a copy of this <code>SerialArray</code>
302 * object.
303 *
304 * @return a copy of this <code>SerialArray</code> object as an
305 * <code>Object</code> in the Java programming language
306 * @throws SerialException if an error occurs;
307 * if {@code free} had previously been called on this object
308 */
309 public Object getArray() throws SerialException {
310 isValid();
311 Object dst = new Object[len];
312 System.arraycopy((Object)elements, 0, dst, 0, len);
313 return dst;
314 }
315
316 /**
317 * Returns a new array that is a copy of this <code>SerialArray</code>
318 * object, using the given type map for the custom
319 * mapping of each element when the elements are SQL UDTs.
320 * <P>
321 * This method does custom mapping if the array elements are a UDT
322 * and the given type map has an entry for that UDT.
323 * Custom mapping is recursive,
324 * meaning that if, for instance, an element of an SQL structured type
325 * is an SQL structured type that itself has an element that is an SQL
326 * structured type, each structured type that has a custom mapping will be
327 * mapped according to the given type map.
328 *
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
334 * @return a copy of this <code>SerialArray</code> object as an
335 * <code>Object</code> in the Java programming language
|