jdk/src/share/classes/javax/sql/rowset/serial/SerialDatalink.java
author yan
Wed, 30 Apr 2014 15:13:44 +0400
changeset 24197 a5c2cff81e25
parent 18564 f9db68ff2cbb
child 24968 3308660aa3f2
permissions -rw-r--r--
8039488: Tidy warnings cleanup for javax.sql Reviewed-by: lancea Contributed-by: Alexander Stepanov <alexander.v.stepanov@oracle.com>
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
24197
a5c2cff81e25 8039488: Tidy warnings cleanup for javax.sql
yan
parents: 18564
diff changeset
     2
 * Copyright (c) 2003, 2014, 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.net.URL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 * A serialized mapping in the Java programming language of an SQL
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 * <code>DATALINK</code> value. A <code>DATALINK</code> value
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 * references a file outside of the underlying data source that the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 * data source manages.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 * <P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 * <code>RowSet</code> implementations can use the method <code>RowSet.getURL</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 * to retrieve a <code>java.net.URL</code> object, which can be used
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 * to manipulate the external data.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 *      java.net.URL url = rowset.getURL(1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 * </pre>
14781
701d0765f75f 8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents: 14409
diff changeset
    45
 *
18564
f9db68ff2cbb 8017471: Fix JDBC -Xdoclint public errors
lancea
parents: 14781
diff changeset
    46
 * <h3> Thread safety </h3>
14781
701d0765f75f 8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents: 14409
diff changeset
    47
 *
701d0765f75f 8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents: 14409
diff changeset
    48
 * A SerialDatalink 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
    49
 * SerialDatalink 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
    50
 * SerialDatalink should be controlled by appropriate synchronization.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
public class SerialDatalink implements Serializable, Cloneable {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
     * The extracted URL field retrieved from the DATALINK field.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
    private URL url;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
     * The SQL type of the elements in this <code>SerialDatalink</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
     * object.  The type is expressed as one of the contants from the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
     * class <code>java.sql.Types</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
    private int baseType;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
     * The type name used by the DBMS for the elements in the SQL
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
     * <code>DATALINK</code> value that this SerialDatalink object
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
     * represents.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
    private String baseTypeName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
      * Constructs a new <code>SerialDatalink</code> object from the given
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
      * <code>java.net.URL</code> object.
24197
a5c2cff81e25 8039488: Tidy warnings cleanup for javax.sql
yan
parents: 18564
diff changeset
    79
      *
18564
f9db68ff2cbb 8017471: Fix JDBC -Xdoclint public errors
lancea
parents: 14781
diff changeset
    80
      * @param url the {@code URL} to create the {@code SerialDataLink} from
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
      * @throws SerialException if url parameter is a null
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
      */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
    public SerialDatalink(URL url) throws SerialException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
        if (url == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
            throw new SerialException("Cannot serialize empty URL instance");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
        this.url = url;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
     * Returns a new URL that is a copy of this <code>SerialDatalink</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
     * object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
     * @return a copy of this <code>SerialDatalink</code> object as a
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
     * <code>URL</code> object in the Java programming language.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
     * @throws SerialException if the <code>URL</code> object cannot be de-serialized
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
    public URL getDatalink() throws SerialException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
        URL aURL = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
            aURL = new URL((this.url).toString());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
        } catch (java.net.MalformedURLException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
            throw new SerialException("MalformedURLException: " + e.getMessage());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
        return aURL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
14409
d879c92507ec 8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents: 5506
diff changeset
   110
    /**
d879c92507ec 8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents: 5506
diff changeset
   111
     * Compares this {@code SerialDatalink} to the specified object.
d879c92507ec 8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents: 5506
diff changeset
   112
     * The result is {@code true} if and only if the argument is not
d879c92507ec 8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents: 5506
diff changeset
   113
     * {@code null} and is a {@code SerialDatalink} object whose URL is
d879c92507ec 8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents: 5506
diff changeset
   114
     * identical to this object's URL
d879c92507ec 8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents: 5506
diff changeset
   115
     *
d879c92507ec 8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents: 5506
diff changeset
   116
     * @param  obj The object to compare this {@code SerialDatalink} against
d879c92507ec 8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents: 5506
diff changeset
   117
     *
d879c92507ec 8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents: 5506
diff changeset
   118
     * @return  {@code true} if the given object represents a {@code SerialDatalink}
d879c92507ec 8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents: 5506
diff changeset
   119
     *          equivalent to this SerialDatalink, {@code false} otherwise
d879c92507ec 8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents: 5506
diff changeset
   120
     *
d879c92507ec 8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents: 5506
diff changeset
   121
     */
d879c92507ec 8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents: 5506
diff changeset
   122
    public boolean equals(Object obj) {
d879c92507ec 8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents: 5506
diff changeset
   123
        if (this == obj) {
d879c92507ec 8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents: 5506
diff changeset
   124
            return true;
d879c92507ec 8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents: 5506
diff changeset
   125
        }
d879c92507ec 8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents: 5506
diff changeset
   126
        if (obj instanceof SerialDatalink) {
d879c92507ec 8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents: 5506
diff changeset
   127
            SerialDatalink sdl = (SerialDatalink) obj;
d879c92507ec 8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents: 5506
diff changeset
   128
            return url.equals(sdl.url);
d879c92507ec 8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents: 5506
diff changeset
   129
        }
d879c92507ec 8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents: 5506
diff changeset
   130
        return false;
d879c92507ec 8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents: 5506
diff changeset
   131
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
    /**
14409
d879c92507ec 8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents: 5506
diff changeset
   134
     * Returns a hash code for this {@code SerialDatalink}. The hash code for a
d879c92507ec 8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents: 5506
diff changeset
   135
     * {@code SerialDatalink} object is taken as the hash code of
d879c92507ec 8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents: 5506
diff changeset
   136
     * the {@code URL} it stores
d879c92507ec 8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents: 5506
diff changeset
   137
     *
d879c92507ec 8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents: 5506
diff changeset
   138
     * @return  a hash code value for this object.
d879c92507ec 8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents: 5506
diff changeset
   139
     */
d879c92507ec 8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents: 5506
diff changeset
   140
    public int hashCode() {
d879c92507ec 8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents: 5506
diff changeset
   141
        return 31 + url.hashCode();
d879c92507ec 8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents: 5506
diff changeset
   142
    }
d879c92507ec 8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents: 5506
diff changeset
   143
d879c92507ec 8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents: 5506
diff changeset
   144
    /**
d879c92507ec 8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents: 5506
diff changeset
   145
     * Returns a clone of this {@code SerialDatalink}.
d879c92507ec 8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents: 5506
diff changeset
   146
     *
d879c92507ec 8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents: 5506
diff changeset
   147
     * @return  a clone of this SerialDatalink
d879c92507ec 8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents: 5506
diff changeset
   148
     */
d879c92507ec 8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents: 5506
diff changeset
   149
    public Object clone() {
d879c92507ec 8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents: 5506
diff changeset
   150
        try {
d879c92507ec 8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents: 5506
diff changeset
   151
            SerialDatalink sdl = (SerialDatalink) super.clone();
d879c92507ec 8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents: 5506
diff changeset
   152
            return sdl;
d879c92507ec 8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents: 5506
diff changeset
   153
        } catch (CloneNotSupportedException ex) {
d879c92507ec 8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents: 5506
diff changeset
   154
            // this shouldn't happen, since we are Cloneable
d879c92507ec 8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents: 5506
diff changeset
   155
            throw new InternalError();
d879c92507ec 8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents: 5506
diff changeset
   156
        }
d879c92507ec 8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents: 5506
diff changeset
   157
    }
d879c92507ec 8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents: 5506
diff changeset
   158
d879c92507ec 8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents: 5506
diff changeset
   159
    /**
d879c92507ec 8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents: 5506
diff changeset
   160
     * readObject and writeObject are called to restore the state
d879c92507ec 8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents: 5506
diff changeset
   161
     * of the {@code SerialDatalink}
d879c92507ec 8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents: 5506
diff changeset
   162
     * from a stream. Note: we leverage the default Serialized form
d879c92507ec 8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents: 5506
diff changeset
   163
     */
d879c92507ec 8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents: 5506
diff changeset
   164
d879c92507ec 8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents: 5506
diff changeset
   165
    /**
d879c92507ec 8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents: 5506
diff changeset
   166
     * The identifier that assists in the serialization of this
d879c92507ec 8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents: 5506
diff changeset
   167
     *  {@code SerialDatalink} object.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
    static final long serialVersionUID = 2826907821828733626L;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
}