author | gromero |
Tue, 04 Sep 2018 11:46:23 -0400 | |
changeset 51629 | 78c7f0c7827d |
parent 47216 | 71c04702a3d5 |
child 54106 | 9a90236ab64c |
permissions | -rw-r--r-- |
2 | 1 |
/* |
24197 | 2 |
* Copyright (c) 2003, 2014, Oracle and/or its affiliates. All rights reserved. |
2 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
5506 | 7 |
* published by the Free Software Foundation. Oracle designates this |
2 | 8 |
* particular file as subject to the "Classpath" exception as provided |
5506 | 9 |
* by Oracle in the LICENSE file that accompanied this code. |
2 | 10 |
* |
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
15 |
* accompanied this code). |
|
16 |
* |
|
17 |
* You should have received a copy of the GNU General Public License version |
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
20 |
* |
|
5506 | 21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
22 |
* or visit www.oracle.com if you need additional information or have any |
|
23 |
* questions. |
|
2 | 24 |
*/ |
25 |
||
26 |
package javax.sql.rowset.serial; |
|
27 |
||
28 |
import java.sql.*; |
|
29 |
import java.io.*; |
|
30 |
import java.net.URL; |
|
31 |
||
32 |
||
33 |
/** |
|
34 |
* A serialized mapping in the Java programming language of an SQL |
|
35 |
* <code>DATALINK</code> value. A <code>DATALINK</code> value |
|
36 |
* references a file outside of the underlying data source that the |
|
37 |
* data source manages. |
|
38 |
* <P> |
|
39 |
* <code>RowSet</code> implementations can use the method <code>RowSet.getURL</code> |
|
40 |
* to retrieve a <code>java.net.URL</code> object, which can be used |
|
41 |
* to manipulate the external data. |
|
42 |
* <pre> |
|
43 |
* java.net.URL url = rowset.getURL(1); |
|
44 |
* </pre> |
|
14781
701d0765f75f
8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents:
14409
diff
changeset
|
45 |
* |
18564 | 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. |
24968
3308660aa3f2
8046389: Add missing @since tag under javax.sql.**
henryjen
parents:
24197
diff
changeset
|
51 |
* |
3308660aa3f2
8046389: Add missing @since tag under javax.sql.**
henryjen
parents:
24197
diff
changeset
|
52 |
* @since 1.5 |
2 | 53 |
*/ |
54 |
public class SerialDatalink implements Serializable, Cloneable { |
|
55 |
||
56 |
/** |
|
57 |
* The extracted URL field retrieved from the DATALINK field. |
|
58 |
* @serial |
|
59 |
*/ |
|
60 |
private URL url; |
|
61 |
||
62 |
/** |
|
63 |
* The SQL type of the elements in this <code>SerialDatalink</code> |
|
25976
4de01a56e3ee
8054555: javadoc cleanup for java.sql and javax.sql
lancea
parents:
24968
diff
changeset
|
64 |
* object. The type is expressed as one of the constants from the |
2 | 65 |
* class <code>java.sql.Types</code>. |
66 |
* @serial |
|
67 |
*/ |
|
68 |
private int baseType; |
|
69 |
||
70 |
/** |
|
71 |
* The type name used by the DBMS for the elements in the SQL |
|
72 |
* <code>DATALINK</code> value that this SerialDatalink object |
|
73 |
* represents. |
|
74 |
* @serial |
|
75 |
*/ |
|
76 |
private String baseTypeName; |
|
77 |
||
78 |
/** |
|
79 |
* Constructs a new <code>SerialDatalink</code> object from the given |
|
80 |
* <code>java.net.URL</code> object. |
|
24197 | 81 |
* |
18564 | 82 |
* @param url the {@code URL} to create the {@code SerialDataLink} from |
2 | 83 |
* @throws SerialException if url parameter is a null |
84 |
*/ |
|
85 |
public SerialDatalink(URL url) throws SerialException { |
|
86 |
if (url == null) { |
|
87 |
throw new SerialException("Cannot serialize empty URL instance"); |
|
88 |
} |
|
89 |
this.url = url; |
|
90 |
} |
|
91 |
||
92 |
/** |
|
93 |
* Returns a new URL that is a copy of this <code>SerialDatalink</code> |
|
94 |
* object. |
|
95 |
* |
|
96 |
* @return a copy of this <code>SerialDatalink</code> object as a |
|
97 |
* <code>URL</code> object in the Java programming language. |
|
98 |
* @throws SerialException if the <code>URL</code> object cannot be de-serialized |
|
99 |
*/ |
|
100 |
public URL getDatalink() throws SerialException { |
|
101 |
||
102 |
URL aURL = null; |
|
103 |
||
104 |
try { |
|
105 |
aURL = new URL((this.url).toString()); |
|
106 |
} catch (java.net.MalformedURLException e) { |
|
107 |
throw new SerialException("MalformedURLException: " + e.getMessage()); |
|
108 |
} |
|
109 |
return aURL; |
|
110 |
} |
|
111 |
||
14409
d879c92507ec
8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents:
5506
diff
changeset
|
112 |
/** |
d879c92507ec
8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents:
5506
diff
changeset
|
113 |
* Compares this {@code SerialDatalink} to the specified object. |
d879c92507ec
8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents:
5506
diff
changeset
|
114 |
* 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
|
115 |
* {@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
|
116 |
* identical to this object's URL |
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 |
* @param obj The object to compare this {@code SerialDatalink} against |
d879c92507ec
8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents:
5506
diff
changeset
|
119 |
* |
d879c92507ec
8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents:
5506
diff
changeset
|
120 |
* @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
|
121 |
* equivalent to this SerialDatalink, {@code false} otherwise |
d879c92507ec
8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents:
5506
diff
changeset
|
122 |
* |
d879c92507ec
8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents:
5506
diff
changeset
|
123 |
*/ |
d879c92507ec
8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents:
5506
diff
changeset
|
124 |
public boolean equals(Object obj) { |
d879c92507ec
8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents:
5506
diff
changeset
|
125 |
if (this == obj) { |
d879c92507ec
8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents:
5506
diff
changeset
|
126 |
return true; |
d879c92507ec
8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents:
5506
diff
changeset
|
127 |
} |
d879c92507ec
8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents:
5506
diff
changeset
|
128 |
if (obj instanceof SerialDatalink) { |
d879c92507ec
8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents:
5506
diff
changeset
|
129 |
SerialDatalink sdl = (SerialDatalink) obj; |
d879c92507ec
8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents:
5506
diff
changeset
|
130 |
return url.equals(sdl.url); |
d879c92507ec
8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents:
5506
diff
changeset
|
131 |
} |
d879c92507ec
8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents:
5506
diff
changeset
|
132 |
return false; |
d879c92507ec
8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents:
5506
diff
changeset
|
133 |
} |
2 | 134 |
|
135 |
/** |
|
14409
d879c92507ec
8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents:
5506
diff
changeset
|
136 |
* 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
|
137 |
* {@code SerialDatalink} object is taken as the hash code of |
d879c92507ec
8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents:
5506
diff
changeset
|
138 |
* the {@code URL} it stores |
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 |
* @return a hash code value for this object. |
d879c92507ec
8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents:
5506
diff
changeset
|
141 |
*/ |
d879c92507ec
8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents:
5506
diff
changeset
|
142 |
public int hashCode() { |
d879c92507ec
8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents:
5506
diff
changeset
|
143 |
return 31 + url.hashCode(); |
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 |
|
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 |
* Returns a clone of this {@code 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 |
* @return a clone of this SerialDatalink |
d879c92507ec
8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents:
5506
diff
changeset
|
150 |
*/ |
d879c92507ec
8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents:
5506
diff
changeset
|
151 |
public Object clone() { |
d879c92507ec
8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents:
5506
diff
changeset
|
152 |
try { |
d879c92507ec
8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents:
5506
diff
changeset
|
153 |
SerialDatalink sdl = (SerialDatalink) super.clone(); |
d879c92507ec
8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents:
5506
diff
changeset
|
154 |
return sdl; |
d879c92507ec
8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents:
5506
diff
changeset
|
155 |
} catch (CloneNotSupportedException ex) { |
d879c92507ec
8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents:
5506
diff
changeset
|
156 |
// this shouldn't happen, since we are Cloneable |
d879c92507ec
8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents:
5506
diff
changeset
|
157 |
throw new InternalError(); |
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 |
|
d879c92507ec
8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents:
5506
diff
changeset
|
161 |
/** |
d879c92507ec
8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents:
5506
diff
changeset
|
162 |
* readObject and writeObject are called to restore the state |
d879c92507ec
8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents:
5506
diff
changeset
|
163 |
* of the {@code SerialDatalink} |
d879c92507ec
8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents:
5506
diff
changeset
|
164 |
* from a stream. Note: we leverage the default Serialized form |
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 |
|
d879c92507ec
8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents:
5506
diff
changeset
|
167 |
/** |
d879c92507ec
8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents:
5506
diff
changeset
|
168 |
* The identifier that assists in the serialization of this |
d879c92507ec
8002212: adding read/writeObject to additional SerialXXX classes
lancea
parents:
5506
diff
changeset
|
169 |
* {@code SerialDatalink} object. |
2 | 170 |
*/ |
171 |
static final long serialVersionUID = 2826907821828733626L; |
|
172 |
} |