src/java.sql.rowset/share/classes/javax/sql/rowset/serial/SerialStruct.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 javax.sql.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.io.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.math.*;
11683
5e02efd89af6 7133815: address the findbug errors in CachedRowSetImpl, SerialStruct, BaseRow, SerialInputImpl, SerialOutputImpl
lancea
parents: 11129
diff changeset
    32
import java.util.Arrays;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import java.util.Map;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import java.util.Vector;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import javax.sql.rowset.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 * A serialized mapping in the Java programming language of an SQL
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 * structured type. Each attribute that is not already serialized
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 * is mapped to a serialized form, and if an attribute is itself
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 * a structured type, each of its attributes that is not already
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 * serialized is mapped to a serialized form.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 * <P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 * In addition, the structured type is custom mapped to a class in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 * Java programming language if there is such a mapping, as are
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 * its attributes, if appropriate.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 * <P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 * The <code>SerialStruct</code> class provides a constructor for creating
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 * an instance from a <code>Struct</code> object, a method for retrieving
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 * the SQL type name of the SQL structured type in the database, and methods
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 * for retrieving its attribute values.
14781
701d0765f75f 8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents: 14409
diff changeset
    53
 *
54106
9a90236ab64c 8220253: Fix Headings in java.sql.rowset
lancea
parents: 51181
diff changeset
    54
 * <h2> Thread safety </h2>
14781
701d0765f75f 8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents: 14409
diff changeset
    55
 *
701d0765f75f 8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents: 14409
diff changeset
    56
 * A SerialStruct 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
    57
 * SerialStruct 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
    58
 * SerialStruct should be controlled by appropriate synchronization.
701d0765f75f 8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents: 14409
diff changeset
    59
 *
24968
3308660aa3f2 8046389: Add missing @since tag under javax.sql.**
henryjen
parents: 18564
diff changeset
    60
 * @since 1.5
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
public class SerialStruct implements Struct, Serializable, Cloneable {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
     * The SQL type name for the structured type that this
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
     * <code>SerialStruct</code> object represents.  This is the name
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
     * used in the SQL definition of the SQL structured type.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
    private String SQLTypeName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
     * An array of <code>Object</code> instances in  which each
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
     * element is an attribute of the SQL structured type that this
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
     * <code>SerialStruct</code> object represents.  The attributes are
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
     * ordered according to their order in the definition of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
     * SQL structured type.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
     */
58338
faf791c5a710 8231442: Suppress warnings on non-serializable instance fields in java.sql.* modules
darcy
parents: 54106
diff changeset
    83
    @SuppressWarnings("serial") // Not statically typed as Serializable
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
    private Object attribs[];
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
     * Constructs a <code>SerialStruct</code> object from the given
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
     * <code>Struct</code> object, using the given <code>java.util.Map</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
     * object for custom mapping the SQL structured type or any of its
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
     * attributes that are SQL structured types.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
     *
18149
5997c9aedb0e 8016101: Fix typo in SerialRef and missing @param in SerialStruct
lancea
parents: 14781
diff changeset
    92
     * @param in an instance of {@code Struct}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
     * @param map a <code>java.util.Map</code> object in which
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
     *        each entry consists of 1) a <code>String</code> object
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
     *        giving the fully qualified name of a UDT and 2) the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
     *        <code>Class</code> object for the <code>SQLData</code> implementation
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
     *        that defines how the UDT is to be mapped
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
     * @throws SerialException if an error occurs
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
     * @see java.sql.Struct
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
     public SerialStruct(Struct in, Map<String,Class<?>> map)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
         throws SerialException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
     {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
        // get the type name
6692
aef4e294026f 6988993: Address Findbugs warnings for the use of String Constructor
lancea
parents: 5506
diff changeset
   108
        SQLTypeName = in.getSQLTypeName();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
        System.out.println("SQLTypeName: " + SQLTypeName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
        // get the attributes of the struct
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
        attribs = in.getAttributes(map);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
         * the array may contain further Structs
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
         * and/or classes that have been mapped,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
         * other types that we have to serialize
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
        mapToSerial(map);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
        } catch (SQLException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
            throw new SerialException(e.getMessage());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
     /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
      * Constructs a <code>SerialStruct</code> object from the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
      * given <code>SQLData</code> object, using the given type
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
      * map to custom map it to a class in the Java programming
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
      * language.  The type map gives the SQL type and the class
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
      * to which it is mapped.  The <code>SQLData</code> object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
      * defines the class to which the SQL type will be mapped.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
      *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
      * @param in an instance of the <code>SQLData</code> class
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
      *           that defines the mapping of the SQL structured
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
      *           type to one or more objects in the Java programming language
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
      * @param map a <code>java.util.Map</code> object in which
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
      *        each entry consists of 1) a <code>String</code> object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
      *        giving the fully qualified name of a UDT and 2) the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
      *        <code>Class</code> object for the <code>SQLData</code> implementation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
      *        that defines how the UDT is to be mapped
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
      * @throws SerialException if an error occurs
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
      */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
    public SerialStruct(SQLData in, Map<String,Class<?>> map)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
        throws SerialException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
        //set the type name
6692
aef4e294026f 6988993: Address Findbugs warnings for the use of String Constructor
lancea
parents: 5506
diff changeset
   151
        SQLTypeName = in.getSQLTypeName();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
11129
f9ad1aadf3fa 7116445: Miscellaneous warnings in the JDBC/RowSet classes
lancea
parents: 6692
diff changeset
   153
        Vector<Object> tmp = new Vector<>();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
        in.writeSQL(new SQLOutputImpl(tmp, map));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
        attribs = tmp.toArray();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
        } catch (SQLException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
            throw new SerialException(e.getMessage());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
     * Retrieves the SQL type name for this <code>SerialStruct</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
     * object. This is the name used in the SQL definition of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
     * structured type
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
     * @return a <code>String</code> object representing the SQL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
     *         type name for the SQL structured type that this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
     *         <code>SerialStruct</code> object represents
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
     * @throws SerialException if an error occurs
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
    public String getSQLTypeName() throws SerialException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
        return SQLTypeName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
     * Retrieves an array of <code>Object</code> values containing the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
     * attributes of the SQL structured type that this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
     * <code>SerialStruct</code> object represents.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
     * @return an array of <code>Object</code> values, with each
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
     *         element being an attribute of the SQL structured type
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
     *         that this <code>SerialStruct</code> object represents
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
     * @throws SerialException if an error occurs
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
    public Object[]  getAttributes() throws SerialException {
11683
5e02efd89af6 7133815: address the findbug errors in CachedRowSetImpl, SerialStruct, BaseRow, SerialInputImpl, SerialOutputImpl
lancea
parents: 11129
diff changeset
   188
        Object[] val = this.attribs;
5e02efd89af6 7133815: address the findbug errors in CachedRowSetImpl, SerialStruct, BaseRow, SerialInputImpl, SerialOutputImpl
lancea
parents: 11129
diff changeset
   189
        return (val == null) ? null : Arrays.copyOf(val, val.length);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
     * Retrieves the attributes for the SQL structured type that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
     * this <code>SerialStruct</code> represents as an array of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
     * <code>Object</code> values, using the given type map for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
     * custom mapping if appropriate.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
     * @param map a <code>java.util.Map</code> object in which
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
     *        each entry consists of 1) a <code>String</code> object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
     *        giving the fully qualified name of a UDT and 2) the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
     *        <code>Class</code> object for the <code>SQLData</code> implementation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
     *        that defines how the UDT is to be mapped
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
     * @return an array of <code>Object</code> values, with each
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
     *         element being an attribute of the SQL structured
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
     *         type that this <code>SerialStruct</code> object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
     *         represents
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
     * @throws SerialException if an error occurs
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
    public Object[] getAttributes(Map<String,Class<?>> map)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
        throws SerialException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
    {
11683
5e02efd89af6 7133815: address the findbug errors in CachedRowSetImpl, SerialStruct, BaseRow, SerialInputImpl, SerialOutputImpl
lancea
parents: 11129
diff changeset
   212
        Object[] val = this.attribs;
5e02efd89af6 7133815: address the findbug errors in CachedRowSetImpl, SerialStruct, BaseRow, SerialInputImpl, SerialOutputImpl
lancea
parents: 11129
diff changeset
   213
        return (val == null) ? null : Arrays.copyOf(val, val.length);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
     * Maps attributes of an SQL structured type that are not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
     * serialized to a serialized form, using the given type map
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
     * for custom mapping when appropriate.  The following types
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
     * in the Java programming language are mapped to their
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
     * serialized forms:  <code>Struct</code>, <code>SQLData</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
     * <code>Ref</code>, <code>Blob</code>, <code>Clob</code>, and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
     * <code>Array</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
     * <P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
     * This method is called internally and is not used by an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
     * application programmer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
     * @param map a <code>java.util.Map</code> object in which
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
     *        each entry consists of 1) a <code>String</code> object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
     *        giving the fully qualified name of a UDT and 2) the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
     *        <code>Class</code> object for the <code>SQLData</code> implementation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
     *        that defines how the UDT is to be mapped
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
     * @throws SerialException if an error occurs
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
     */
11129
f9ad1aadf3fa 7116445: Miscellaneous warnings in the JDBC/RowSet classes
lancea
parents: 6692
diff changeset
   236
    private void mapToSerial(Map<String,Class<?>> map) throws SerialException {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
        for (int i = 0; i < attribs.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
            if (attribs[i] instanceof Struct) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
                attribs[i] = new SerialStruct((Struct)attribs[i], map);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
            } else if (attribs[i] instanceof SQLData) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
                attribs[i] = new SerialStruct((SQLData)attribs[i], map);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
            } else if (attribs[i] instanceof Blob) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
                attribs[i] = new SerialBlob((Blob)attribs[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
            } else if (attribs[i] instanceof Clob) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
                attribs[i] = new SerialClob((Clob)attribs[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
            } else if (attribs[i] instanceof Ref) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
                attribs[i] = new SerialRef((Ref)attribs[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
            } else if (attribs[i] instanceof java.sql.Array) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
                attribs[i] = new SerialArray((java.sql.Array)attribs[i], map);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
        } catch (SQLException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
            throw new SerialException(e.getMessage());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
    /**
14409
d879c92507ec 8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents: 11683
diff changeset
   263
     * Compares this SerialStruct to the specified object.  The result is
d879c92507ec 8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents: 11683
diff changeset
   264
     * {@code true} if and only if the argument is not {@code null} and is a
d879c92507ec 8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents: 11683
diff changeset
   265
     * {@code SerialStruct} object whose attributes are identical to this
d879c92507ec 8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents: 11683
diff changeset
   266
     * object's attributes
d879c92507ec 8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents: 11683
diff changeset
   267
     *
d879c92507ec 8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents: 11683
diff changeset
   268
     * @param  obj The object to compare this {@code SerialStruct} against
d879c92507ec 8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents: 11683
diff changeset
   269
     *
d879c92507ec 8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents: 11683
diff changeset
   270
     * @return {@code true} if the given object represents a {@code SerialStruct}
d879c92507ec 8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents: 11683
diff changeset
   271
     *          equivalent to this SerialStruct, {@code false} otherwise
d879c92507ec 8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents: 11683
diff changeset
   272
     *
d879c92507ec 8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents: 11683
diff changeset
   273
     */
d879c92507ec 8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents: 11683
diff changeset
   274
    public boolean equals(Object obj) {
d879c92507ec 8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents: 11683
diff changeset
   275
        if (this == obj) {
d879c92507ec 8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents: 11683
diff changeset
   276
            return true;
d879c92507ec 8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents: 11683
diff changeset
   277
        }
d879c92507ec 8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents: 11683
diff changeset
   278
        if (obj instanceof SerialStruct) {
d879c92507ec 8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents: 11683
diff changeset
   279
            SerialStruct ss = (SerialStruct)obj;
d879c92507ec 8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents: 11683
diff changeset
   280
            return SQLTypeName.equals(ss.SQLTypeName) &&
d879c92507ec 8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents: 11683
diff changeset
   281
                    Arrays.equals(attribs, ss.attribs);
d879c92507ec 8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents: 11683
diff changeset
   282
        }
d879c92507ec 8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents: 11683
diff changeset
   283
        return false;
d879c92507ec 8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents: 11683
diff changeset
   284
    }
d879c92507ec 8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents: 11683
diff changeset
   285
d879c92507ec 8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents: 11683
diff changeset
   286
    /**
d879c92507ec 8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents: 11683
diff changeset
   287
     * Returns a hash code for this {@code SerialStruct}. The hash code for a
d879c92507ec 8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents: 11683
diff changeset
   288
     * {@code SerialStruct} object is computed using the hash codes
d879c92507ec 8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents: 11683
diff changeset
   289
     * of the attributes of the {@code SerialStruct} object and its
d879c92507ec 8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents: 11683
diff changeset
   290
     * {@code SQLTypeName}
d879c92507ec 8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents: 11683
diff changeset
   291
     *
d879c92507ec 8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents: 11683
diff changeset
   292
     * @return  a hash code value for this object.
d879c92507ec 8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents: 11683
diff changeset
   293
     */
d879c92507ec 8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents: 11683
diff changeset
   294
    public int hashCode() {
d879c92507ec 8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents: 11683
diff changeset
   295
        return ((31 + Arrays.hashCode(attribs)) * 31) * 31
d879c92507ec 8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents: 11683
diff changeset
   296
                + SQLTypeName.hashCode();
d879c92507ec 8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents: 11683
diff changeset
   297
    }
d879c92507ec 8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents: 11683
diff changeset
   298
d879c92507ec 8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents: 11683
diff changeset
   299
    /**
d879c92507ec 8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents: 11683
diff changeset
   300
     * Returns a clone of this {@code SerialStruct}. The copy will contain a
d879c92507ec 8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents: 11683
diff changeset
   301
     * reference to a clone of the underlying attribs array, not a reference
d879c92507ec 8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents: 11683
diff changeset
   302
     * to the original underlying attribs array of this {@code SerialStruct} object.
d879c92507ec 8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents: 11683
diff changeset
   303
     *
d879c92507ec 8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents: 11683
diff changeset
   304
     * @return  a clone of this SerialStruct
d879c92507ec 8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents: 11683
diff changeset
   305
     */
d879c92507ec 8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents: 11683
diff changeset
   306
    public Object clone() {
d879c92507ec 8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents: 11683
diff changeset
   307
        try {
d879c92507ec 8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents: 11683
diff changeset
   308
            SerialStruct ss = (SerialStruct) super.clone();
d879c92507ec 8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents: 11683
diff changeset
   309
            ss.attribs = Arrays.copyOf(attribs, attribs.length);
d879c92507ec 8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents: 11683
diff changeset
   310
            return ss;
d879c92507ec 8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents: 11683
diff changeset
   311
        } catch (CloneNotSupportedException ex) {
d879c92507ec 8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents: 11683
diff changeset
   312
            // this shouldn't happen, since we are Cloneable
d879c92507ec 8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents: 11683
diff changeset
   313
            throw new InternalError();
d879c92507ec 8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents: 11683
diff changeset
   314
        }
d879c92507ec 8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents: 11683
diff changeset
   315
d879c92507ec 8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents: 11683
diff changeset
   316
    }
d879c92507ec 8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents: 11683
diff changeset
   317
d879c92507ec 8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents: 11683
diff changeset
   318
    /**
d879c92507ec 8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents: 11683
diff changeset
   319
     * readObject is called to restore the state of the {@code SerialStruct} from
d879c92507ec 8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents: 11683
diff changeset
   320
     * a stream.
d879c92507ec 8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents: 11683
diff changeset
   321
     */
d879c92507ec 8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents: 11683
diff changeset
   322
    private void readObject(ObjectInputStream s)
d879c92507ec 8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents: 11683
diff changeset
   323
            throws IOException, ClassNotFoundException {
d879c92507ec 8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents: 11683
diff changeset
   324
d879c92507ec 8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents: 11683
diff changeset
   325
       ObjectInputStream.GetField fields = s.readFields();
d879c92507ec 8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents: 11683
diff changeset
   326
       Object[] tmp = (Object[])fields.get("attribs", null);
d879c92507ec 8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents: 11683
diff changeset
   327
       attribs = tmp == null ? null : tmp.clone();
d879c92507ec 8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents: 11683
diff changeset
   328
       SQLTypeName = (String)fields.get("SQLTypeName", null);
d879c92507ec 8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents: 11683
diff changeset
   329
    }
d879c92507ec 8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents: 11683
diff changeset
   330
d879c92507ec 8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents: 11683
diff changeset
   331
    /**
d879c92507ec 8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents: 11683
diff changeset
   332
     * writeObject is called to save the state of the {@code SerialStruct}
d879c92507ec 8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents: 11683
diff changeset
   333
     * to a stream.
d879c92507ec 8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents: 11683
diff changeset
   334
     */
d879c92507ec 8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents: 11683
diff changeset
   335
    private void writeObject(ObjectOutputStream s)
51181
01b8120f867a 8208060: Additional corrections of serial-related declarations
darcy
parents: 47216
diff changeset
   336
            throws IOException {
14409
d879c92507ec 8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents: 11683
diff changeset
   337
d879c92507ec 8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents: 11683
diff changeset
   338
        ObjectOutputStream.PutField fields = s.putFields();
d879c92507ec 8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents: 11683
diff changeset
   339
        fields.put("attribs", attribs);
d879c92507ec 8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents: 11683
diff changeset
   340
        fields.put("SQLTypeName", SQLTypeName);
d879c92507ec 8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents: 11683
diff changeset
   341
        s.writeFields();
d879c92507ec 8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents: 11683
diff changeset
   342
    }
d879c92507ec 8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents: 11683
diff changeset
   343
d879c92507ec 8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents: 11683
diff changeset
   344
    /**
6692
aef4e294026f 6988993: Address Findbugs warnings for the use of String Constructor
lancea
parents: 5506
diff changeset
   345
     * The identifier that assists in the serialization of this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
     * <code>SerialStruct</code> object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
    static final long serialVersionUID = -8322445504027483372L;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
}