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