Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/src/share/classes/javax/sql/rowset/serial/SerialDatalink.java
38918 views
/*1* Copyright (c) 2003, 2013, 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* <h3> Thread safety </h3>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*/51public class SerialDatalink implements Serializable, Cloneable {5253/**54* The extracted URL field retrieved from the DATALINK field.55* @serial56*/57private URL url;5859/**60* The SQL type of the elements in this <code>SerialDatalink</code>61* object. The type is expressed as one of the contants from the62* class <code>java.sql.Types</code>.63* @serial64*/65private int baseType;6667/**68* The type name used by the DBMS for the elements in the SQL69* <code>DATALINK</code> value that this SerialDatalink object70* represents.71* @serial72*/73private String baseTypeName;7475/**76* Constructs a new <code>SerialDatalink</code> object from the given77* <code>java.net.URL</code> object.78* <P>79* @param url the {@code URL} to create the {@code SerialDataLink} from80* @throws SerialException if url parameter is a null81*/82public SerialDatalink(URL url) throws SerialException {83if (url == null) {84throw new SerialException("Cannot serialize empty URL instance");85}86this.url = url;87}8889/**90* Returns a new URL that is a copy of this <code>SerialDatalink</code>91* object.92*93* @return a copy of this <code>SerialDatalink</code> object as a94* <code>URL</code> object in the Java programming language.95* @throws SerialException if the <code>URL</code> object cannot be de-serialized96*/97public URL getDatalink() throws SerialException {9899URL aURL = null;100101try {102aURL = new URL((this.url).toString());103} catch (java.net.MalformedURLException e) {104throw new SerialException("MalformedURLException: " + e.getMessage());105}106return aURL;107}108109/**110* Compares this {@code SerialDatalink} to the specified object.111* The result is {@code true} if and only if the argument is not112* {@code null} and is a {@code SerialDatalink} object whose URL is113* identical to this object's URL114*115* @param obj The object to compare this {@code SerialDatalink} against116*117* @return {@code true} if the given object represents a {@code SerialDatalink}118* equivalent to this SerialDatalink, {@code false} otherwise119*120*/121public boolean equals(Object obj) {122if (this == obj) {123return true;124}125if (obj instanceof SerialDatalink) {126SerialDatalink sdl = (SerialDatalink) obj;127return url.equals(sdl.url);128}129return false;130}131132/**133* Returns a hash code for this {@code SerialDatalink}. The hash code for a134* {@code SerialDatalink} object is taken as the hash code of135* the {@code URL} it stores136*137* @return a hash code value for this object.138*/139public int hashCode() {140return 31 + url.hashCode();141}142143/**144* Returns a clone of this {@code SerialDatalink}.145*146* @return a clone of this SerialDatalink147*/148public Object clone() {149try {150SerialDatalink sdl = (SerialDatalink) super.clone();151return sdl;152} catch (CloneNotSupportedException ex) {153// this shouldn't happen, since we are Cloneable154throw new InternalError();155}156}157158/**159* readObject and writeObject are called to restore the state160* of the {@code SerialDatalink}161* from a stream. Note: we leverage the default Serialized form162*/163164/**165* The identifier that assists in the serialization of this166* {@code SerialDatalink} object.167*/168static final long serialVersionUID = 2826907821828733626L;169}170171172