39 * The <code>SerialArray</code> class provides a constructor for creating |
40 * The <code>SerialArray</code> class provides a constructor for creating |
40 * a <code>SerialArray</code> instance from an <code>Array</code> object, |
41 * a <code>SerialArray</code> instance from an <code>Array</code> object, |
41 * methods for getting the base type and the SQL name for the base type, and |
42 * methods for getting the base type and the SQL name for the base type, and |
42 * methods for copying all or part of a <code>SerialArray</code> object. |
43 * methods for copying all or part of a <code>SerialArray</code> object. |
43 * <P> |
44 * <P> |
|
45 * |
44 * Note: In order for this class to function correctly, a connection to the |
46 * Note: In order for this class to function correctly, a connection to the |
45 * data source |
47 * data source |
46 * must be available in order for the SQL <code>Array</code> object to be |
48 * must be available in order for the SQL <code>Array</code> object to be |
47 * materialized (have all of its elements brought to the client server) |
49 * materialized (have all of its elements brought to the client server) |
48 * if necessary. At this time, logical pointers to the data in the data source, |
50 * if necessary. At this time, logical pointers to the data in the data source, |
49 * such as locators, are not currently supported. |
51 * such as locators, are not currently supported. |
|
52 * |
|
53 * <h4> Thread safety </h4> |
|
54 * |
|
55 * A SerialArray is not safe for use by multiple concurrent threads. If a |
|
56 * SerialArray is to be used by more than one thread then access to the |
|
57 * SerialArray should be controlled by appropriate synchronization. |
|
58 * |
50 */ |
59 */ |
51 public class SerialArray implements Array, Serializable, Cloneable { |
60 public class SerialArray implements Array, Serializable, Cloneable { |
52 |
61 |
53 /** |
62 /** |
54 * A serialized array in which each element is an <code>Object</code> |
63 * A serialized array in which each element is an <code>Object</code> |
55 * in the Java programming language that represents an element |
64 * in the Java programming language that represents an element |
56 * in the SQL <code>ARRAY</code> value. |
65 * in the SQL <code>ARRAY</code> value. |
57 * @serial |
66 * @serial |
58 */ |
67 */ |
59 private Object[] elements; |
68 private Object[] elements; |
60 |
69 |
61 /** |
70 /** |
62 * The SQL type of the elements in this <code>SerialArray</code> object. The |
71 * The SQL type of the elements in this <code>SerialArray</code> object. The |
63 * type is expressed as one of the constants from the class |
72 * type is expressed as one of the constants from the class |
64 * <code>java.sql.Types</code>. |
73 * <code>java.sql.Types</code>. |
65 * @serial |
74 * @serial |
66 */ |
75 */ |
67 private int baseType; |
76 private int baseType; |
68 |
77 |
69 /** |
78 /** |
70 * The type name used by the DBMS for the elements in the SQL <code>ARRAY</code> |
79 * The type name used by the DBMS for the elements in the SQL <code>ARRAY</code> |
71 * value that this <code>SerialArray</code> object represents. |
80 * value that this <code>SerialArray</code> object represents. |
72 * @serial |
81 * @serial |
73 */ |
82 */ |
74 private String baseTypeName; |
83 private String baseTypeName; |
75 |
84 |
76 /** |
85 /** |
77 * The number of elements in this <code>SerialArray</code> object, which |
86 * The number of elements in this <code>SerialArray</code> object, which |
78 * is also the number of elements in the SQL <code>ARRAY</code> value |
87 * is also the number of elements in the SQL <code>ARRAY</code> value |
79 * that this <code>SerialArray</code> object represents. |
88 * that this <code>SerialArray</code> object represents. |
80 * @serial |
89 * @serial |
81 */ |
90 */ |
82 private int len; |
91 private int len; |
83 |
92 |
84 /** |
93 /** |
85 * Constructs a new <code>SerialArray</code> object from the given |
94 * Constructs a new <code>SerialArray</code> object from the given |
86 * <code>Array</code> object, using the given type map for the custom |
95 * <code>Array</code> object, using the given type map for the custom |
290 } |
294 } |
291 |
295 |
292 |
296 |
293 } |
297 } |
294 |
298 |
295 /** |
299 /** |
296 * Returns a new array that is a copy of this <code>SerialArray</code> |
300 * Returns a new array that is a copy of this <code>SerialArray</code> |
297 * object. |
301 * object. |
298 * |
302 * |
299 * @return a copy of this <code>SerialArray</code> object as an |
303 * @return a copy of this <code>SerialArray</code> object as an |
300 * <code>Object</code> in the Java programming language |
304 * <code>Object</code> in the Java programming language |
301 * @throws SerialException if an error occurs retrieving a copy of |
305 * @throws SerialException if an error occurs; |
302 * this <code>SerialArray</code> object |
306 * if {@code free} had previously been called on this object |
303 */ |
307 */ |
304 public Object getArray() throws SerialException { |
308 public Object getArray() throws SerialException { |
|
309 isValid(); |
305 Object dst = new Object[len]; |
310 Object dst = new Object[len]; |
306 System.arraycopy((Object)elements, 0, dst, 0, len); |
311 System.arraycopy((Object)elements, 0, dst, 0, len); |
307 return dst; |
312 return dst; |
308 } |
313 } |
309 |
314 |
310 //[if an error occurstype map used??] |
315 //[if an error occurstype map used??] |
311 /** |
316 /** |
312 * Returns a new array that is a copy of this <code>SerialArray</code> |
317 * Returns a new array that is a copy of this <code>SerialArray</code> |
313 * object, using the given type map for the custom |
318 * object, using the given type map for the custom |
314 * mapping of each element when the elements are SQL UDTs. |
319 * mapping of each element when the elements are SQL UDTs. |
315 * <P> |
320 * <P> |
316 * This method does custom mapping if the array elements are a UDT |
321 * This method does custom mapping if the array elements are a UDT |
317 * and the given type map has an entry for that UDT. |
322 * and the given type map has an entry for that UDT. |
318 * Custom mapping is recursive, |
323 * Custom mapping is recursive, |
319 * meaning that if, for instance, an element of an SQL structured type |
324 * meaning that if, for instance, an element of an SQL structured type |
320 * is an SQL structured type that itself has an element that is an SQL |
325 * is an SQL structured type that itself has an element that is an SQL |
321 * structured type, each structured type that has a custom mapping will be |
326 * structured type, each structured type that has a custom mapping will be |
322 * mapped according to the given type map. |
327 * mapped according to the given type map. |
323 * |
328 * |
324 * @param map a <code>java.util.Map</code> object in which |
329 * @param map a <code>java.util.Map</code> object in which |
325 * each entry consists of 1) a <code>String</code> object |
330 * each entry consists of 1) a <code>String</code> object |
326 * giving the fully qualified name of a UDT and 2) the |
331 * giving the fully qualified name of a UDT and 2) the |
327 * <code>Class</code> object for the <code>SQLData</code> implementation |
332 * <code>Class</code> object for the <code>SQLData</code> implementation |
328 * that defines how the UDT is to be mapped |
333 * that defines how the UDT is to be mapped |
329 * @return a copy of this <code>SerialArray</code> object as an |
334 * @return a copy of this <code>SerialArray</code> object as an |
330 * <code>Object</code> in the Java programming language |
335 * <code>Object</code> in the Java programming language |
331 * @throws SerialException if an error occurs |
336 * @throws SerialException if an error occurs; |
332 */ |
337 * if {@code free} had previously been called on this object |
|
338 */ |
333 public Object getArray(Map<String, Class<?>> map) throws SerialException { |
339 public Object getArray(Map<String, Class<?>> map) throws SerialException { |
|
340 isValid(); |
334 Object dst[] = new Object[len]; |
341 Object dst[] = new Object[len]; |
335 System.arraycopy((Object)elements, 0, dst, 0, len); |
342 System.arraycopy((Object)elements, 0, dst, 0, len); |
336 return dst; |
343 return dst; |
337 } |
344 } |
338 |
345 |
339 /** |
346 /** |
340 * Returns a new array that is a copy of a slice |
347 * Returns a new array that is a copy of a slice |
341 * of this <code>SerialArray</code> object, starting with the |
348 * of this <code>SerialArray</code> object, starting with the |
342 * element at the given index and containing the given number |
349 * element at the given index and containing the given number |
343 * of consecutive elements. |
350 * of consecutive elements. |
344 * |
351 * |
345 * @param index the index into this <code>SerialArray</code> object |
352 * @param index the index into this <code>SerialArray</code> object |
346 * of the first element to be copied; |
353 * of the first element to be copied; |
347 * the index of the first element is <code>0</code> |
354 * the index of the first element is <code>0</code> |
348 * @param count the number of consecutive elements to be copied, starting |
355 * @param count the number of consecutive elements to be copied, starting |
349 * at the given index |
356 * at the given index |
350 * @return a copy of the designated elements in this <code>SerialArray</code> |
357 * @return a copy of the designated elements in this <code>SerialArray</code> |
351 * object as an <code>Object</code> in the Java programming language |
358 * object as an <code>Object</code> in the Java programming language |
352 * @throws SerialException if an error occurs |
359 * @throws SerialException if an error occurs; |
353 */ |
360 * if {@code free} had previously been called on this object |
|
361 */ |
354 public Object getArray(long index, int count) throws SerialException { |
362 public Object getArray(long index, int count) throws SerialException { |
|
363 isValid(); |
355 Object dst = new Object[count]; |
364 Object dst = new Object[count]; |
356 System.arraycopy((Object)elements, (int)index, dst, 0, count); |
365 System.arraycopy((Object)elements, (int)index, dst, 0, count); |
357 return dst; |
366 return dst; |
358 } |
367 } |
359 |
368 |
360 /** |
369 /** |
361 * Returns a new array that is a copy of a slice |
370 * Returns a new array that is a copy of a slice |
362 * of this <code>SerialArray</code> object, starting with the |
371 * of this <code>SerialArray</code> object, starting with the |
363 * element at the given index and containing the given number |
372 * element at the given index and containing the given number |
364 * of consecutive elements. |
373 * of consecutive elements. |
365 * <P> |
374 * <P> |
366 * This method does custom mapping if the array elements are a UDT |
375 * This method does custom mapping if the array elements are a UDT |
367 * and the given type map has an entry for that UDT. |
376 * and the given type map has an entry for that UDT. |
368 * Custom mapping is recursive, |
377 * Custom mapping is recursive, |
369 * meaning that if, for instance, an element of an SQL structured type |
378 * meaning that if, for instance, an element of an SQL structured type |
370 * is an SQL structured type that itself has an element that is an SQL |
379 * is an SQL structured type that itself has an element that is an SQL |
371 * structured type, each structured type that has a custom mapping will be |
380 * structured type, each structured type that has a custom mapping will be |
372 * mapped according to the given type map. |
381 * mapped according to the given type map. |
373 * |
382 * |
374 * @param index the index into this <code>SerialArray</code> object |
383 * @param index the index into this <code>SerialArray</code> object |
375 * of the first element to be copied; the index of the |
384 * of the first element to be copied; the index of the |
376 * first element in the array is <code>0</code> |
385 * first element in the array is <code>0</code> |
377 * @param count the number of consecutive elements to be copied, starting |
386 * @param count the number of consecutive elements to be copied, starting |
378 * at the given index |
387 * at the given index |
379 * @param map a <code>java.util.Map</code> object in which |
388 * @param map a <code>java.util.Map</code> object in which |
380 * each entry consists of 1) a <code>String</code> object |
389 * each entry consists of 1) a <code>String</code> object |
381 * giving the fully qualified name of a UDT and 2) the |
390 * giving the fully qualified name of a UDT and 2) the |
382 * <code>Class</code> object for the <code>SQLData</code> implementation |
391 * <code>Class</code> object for the <code>SQLData</code> implementation |
383 * that defines how the UDT is to be mapped |
392 * that defines how the UDT is to be mapped |
384 * @return a copy of the designated elements in this <code>SerialArray</code> |
393 * @return a copy of the designated elements in this <code>SerialArray</code> |
385 * object as an <code>Object</code> in the Java programming language |
394 * object as an <code>Object</code> in the Java programming language |
386 * @throws SerialException if an error occurs |
395 * @throws SerialException if an error occurs; |
387 */ |
396 * if {@code free} had previously been called on this object |
|
397 */ |
388 public Object getArray(long index, int count, Map<String,Class<?>> map) |
398 public Object getArray(long index, int count, Map<String,Class<?>> map) |
389 throws SerialException |
399 throws SerialException |
390 { |
400 { |
|
401 isValid(); |
391 Object dst = new Object[count]; |
402 Object dst = new Object[count]; |
392 System.arraycopy((Object)elements, (int)index, dst, 0, count); |
403 System.arraycopy((Object)elements, (int)index, dst, 0, count); |
393 return dst; |
404 return dst; |
394 } |
405 } |
395 |
406 |
396 /** |
407 /** |
397 * Retrieves the SQL type of the elements in this <code>SerialArray</code> |
408 * Retrieves the SQL type of the elements in this <code>SerialArray</code> |
398 * object. The <code>int</code> returned is one of the constants in the class |
409 * object. The <code>int</code> returned is one of the constants in the class |
399 * <code>java.sql.Types</code>. |
410 * <code>java.sql.Types</code>. |
400 * |
411 * |
401 * @return one of the constants in <code>java.sql.Types</code>, indicating |
412 * @return one of the constants in <code>java.sql.Types</code>, indicating |
402 * the SQL type of the elements in this <code>SerialArray</code> object |
413 * the SQL type of the elements in this <code>SerialArray</code> object |
403 * @throws SerialException if an error occurs |
414 * @throws SerialException if an error occurs; |
404 */ |
415 * if {@code free} had previously been called on this object |
|
416 */ |
405 public int getBaseType() throws SerialException { |
417 public int getBaseType() throws SerialException { |
|
418 isValid(); |
406 return baseType; |
419 return baseType; |
407 } |
420 } |
408 |
421 |
409 /** |
422 /** |
410 * Retrieves the DBMS-specific type name for the elements in this |
423 * Retrieves the DBMS-specific type name for the elements in this |
411 * <code>SerialArray</code> object. |
424 * <code>SerialArray</code> object. |
412 * |
425 * |
413 * @return the SQL type name used by the DBMS for the base type of this |
426 * @return the SQL type name used by the DBMS for the base type of this |
414 * <code>SerialArray</code> object |
427 * <code>SerialArray</code> object |
415 * @throws SerialException if an error occurs |
428 * @throws SerialException if an error occurs; |
416 */ |
429 * if {@code free} had previously been called on this object |
|
430 */ |
417 public String getBaseTypeName() throws SerialException { |
431 public String getBaseTypeName() throws SerialException { |
|
432 isValid(); |
418 return baseTypeName; |
433 return baseTypeName; |
419 } |
434 } |
420 |
435 |
421 /** |
436 /** |
422 * Retrieves a <code>ResultSet</code> object holding the elements of |
437 * Retrieves a <code>ResultSet</code> object holding the elements of |