Path: blob/master/src/java.sql.rowset/share/classes/javax/sql/rowset/serial/SerialDatalink.java
40948 views
/*1* Copyright (c) 2003, 2019, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425package javax.sql.rowset.serial;2627import java.sql.*;28import java.io.*;29import java.net.URL;303132/**33* A serialized mapping in the Java programming language of an SQL34* <code>DATALINK</code> value. A <code>DATALINK</code> value35* references a file outside of the underlying data source that the36* data source manages.37* <P>38* <code>RowSet</code> implementations can use the method <code>RowSet.getURL</code>39* to retrieve a <code>java.net.URL</code> object, which can be used40* to manipulate the external data.41* <pre>42* java.net.URL url = rowset.getURL(1);43* </pre>44*45* <h2> Thread safety </h2>46*47* A SerialDatalink is not safe for use by multiple concurrent threads. If a48* SerialDatalink is to be used by more than one thread then access to the49* SerialDatalink should be controlled by appropriate synchronization.50*51* @since 1.552*/53public class SerialDatalink implements Serializable, Cloneable {5455/**56* The extracted URL field retrieved from the DATALINK field.57* @serial58*/59private URL url;6061/**62* The SQL type of the elements in this <code>SerialDatalink</code>63* object. The type is expressed as one of the constants from the64* class <code>java.sql.Types</code>.65* @serial66*/67private int baseType;6869/**70* The type name used by the DBMS for the elements in the SQL71* <code>DATALINK</code> value that this SerialDatalink object72* represents.73* @serial74*/75private String baseTypeName;7677/**78* Constructs a new <code>SerialDatalink</code> object from the given79* <code>java.net.URL</code> object.80*81* @param url the {@code URL} to create the {@code SerialDataLink} from82* @throws SerialException if url parameter is a null83*/84public SerialDatalink(URL url) throws SerialException {85if (url == null) {86throw new SerialException("Cannot serialize empty URL instance");87}88this.url = url;89}9091/**92* Returns a new URL that is a copy of this <code>SerialDatalink</code>93* object.94*95* @return a copy of this <code>SerialDatalink</code> object as a96* <code>URL</code> object in the Java programming language.97* @throws SerialException if the <code>URL</code> object cannot be de-serialized98*/99public URL getDatalink() throws SerialException {100101URL aURL = null;102103try {104aURL = new URL((this.url).toString());105} catch (java.net.MalformedURLException e) {106throw new SerialException("MalformedURLException: " + e.getMessage());107}108return aURL;109}110111/**112* Compares this {@code SerialDatalink} to the specified object.113* The result is {@code true} if and only if the argument is not114* {@code null} and is a {@code SerialDatalink} object whose URL is115* identical to this object's URL116*117* @param obj The object to compare this {@code SerialDatalink} against118*119* @return {@code true} if the given object represents a {@code SerialDatalink}120* equivalent to this SerialDatalink, {@code false} otherwise121*122*/123public boolean equals(Object obj) {124if (this == obj) {125return true;126}127if (obj instanceof SerialDatalink) {128SerialDatalink sdl = (SerialDatalink) obj;129return url.equals(sdl.url);130}131return false;132}133134/**135* Returns a hash code for this {@code SerialDatalink}. The hash code for a136* {@code SerialDatalink} object is taken as the hash code of137* the {@code URL} it stores138*139* @return a hash code value for this object.140*/141public int hashCode() {142return 31 + url.hashCode();143}144145/**146* Returns a clone of this {@code SerialDatalink}.147*148* @return a clone of this SerialDatalink149*/150public Object clone() {151try {152SerialDatalink sdl = (SerialDatalink) super.clone();153return sdl;154} catch (CloneNotSupportedException ex) {155// this shouldn't happen, since we are Cloneable156throw new InternalError();157}158}159160/**161* readObject and writeObject are called to restore the state162* of the {@code SerialDatalink}163* from a stream. Note: we leverage the default Serialized form164*/165166/**167* The identifier that assists in the serialization of this168* {@code SerialDatalink} object.169*/170static final long serialVersionUID = 2826907821828733626L;171}172173174