author | gromero |
Tue, 04 Sep 2018 11:46:23 -0400 | |
changeset 51629 | 78c7f0c7827d |
parent 51310 | a694574b2def |
child 54106 | 9a90236ab64c |
permissions | -rw-r--r-- |
2 | 1 |
/* |
51310
a694574b2def
8208782: Remove extra type in throws clause of SerialClob.writeObject
darcy
parents:
47216
diff
changeset
|
2 |
* Copyright (c) 2003, 2018, 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.*; |
|
14337
a003c6a54cb6
8001536: Added readObject,writeObject,clone, equals, hashcode to SerialXLob
lancea
parents:
10323
diff
changeset
|
30 |
import java.util.Arrays; |
2 | 31 |
|
32 |
/** |
|
33 |
* A serialized mapping in the Java programming language of an SQL |
|
34 |
* <code>CLOB</code> value. |
|
35 |
* <P> |
|
36 |
* The <code>SerialClob</code> class provides a constructor for creating |
|
37 |
* an instance from a <code>Clob</code> object. Note that the <code>Clob</code> |
|
38 |
* object should have brought the SQL <code>CLOB</code> value's data over |
|
39 |
* to the client before a <code>SerialClob</code> object |
|
40 |
* is constructed from it. The data of an SQL <code>CLOB</code> value can |
|
41 |
* be materialized on the client as a stream of Unicode characters. |
|
42 |
* <P> |
|
43 |
* <code>SerialClob</code> methods make it possible to get a substring |
|
44 |
* from a <code>SerialClob</code> object or to locate the start of |
|
45 |
* a pattern of characters. |
|
46 |
* |
|
18564 | 47 |
* <h3> Thread safety </h3> |
14781
701d0765f75f
8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents:
14337
diff
changeset
|
48 |
* |
701d0765f75f
8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents:
14337
diff
changeset
|
49 |
* <p> A SerialClob 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:
14337
diff
changeset
|
50 |
* SerialClob is to be used by more than one thread then access to the SerialClob |
701d0765f75f
8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents:
14337
diff
changeset
|
51 |
* should be controlled by appropriate synchronization. |
24968
3308660aa3f2
8046389: Add missing @since tag under javax.sql.**
henryjen
parents:
18564
diff
changeset
|
52 |
* |
2 | 53 |
* @author Jonathan Bruce |
24968
3308660aa3f2
8046389: Add missing @since tag under javax.sql.**
henryjen
parents:
18564
diff
changeset
|
54 |
* @since 1.5 |
2 | 55 |
*/ |
56 |
public class SerialClob implements Clob, Serializable, Cloneable { |
|
57 |
||
58 |
/** |
|
59 |
* A serialized array of characters containing the data of the SQL |
|
60 |
* <code>CLOB</code> value that this <code>SerialClob</code> object |
|
61 |
* represents. |
|
62 |
* |
|
63 |
* @serial |
|
64 |
*/ |
|
65 |
private char buf[]; |
|
66 |
||
67 |
/** |
|
8405
bafd7b441d80
7018385: update javax.sql classes to use try-with-resources
smarks
parents:
5506
diff
changeset
|
68 |
* Internal Clob representation if SerialClob is initialized with a |
bafd7b441d80
7018385: update javax.sql classes to use try-with-resources
smarks
parents:
5506
diff
changeset
|
69 |
* Clob. Null if SerialClob is initialized with a char[]. |
2 | 70 |
*/ |
14337
a003c6a54cb6
8001536: Added readObject,writeObject,clone, equals, hashcode to SerialXLob
lancea
parents:
10323
diff
changeset
|
71 |
private Clob clob; |
2 | 72 |
|
73 |
/** |
|
74 |
* The length in characters of this <code>SerialClob</code> object's |
|
75 |
* internal array of characters. |
|
76 |
* |
|
77 |
* @serial |
|
78 |
*/ |
|
79 |
private long len; |
|
80 |
||
81 |
/** |
|
8405
bafd7b441d80
7018385: update javax.sql classes to use try-with-resources
smarks
parents:
5506
diff
changeset
|
82 |
* The original length in characters of this <code>SerialClob</code> |
bafd7b441d80
7018385: update javax.sql classes to use try-with-resources
smarks
parents:
5506
diff
changeset
|
83 |
* object's internal array of characters. |
2 | 84 |
* |
85 |
* @serial |
|
86 |
*/ |
|
14337
a003c6a54cb6
8001536: Added readObject,writeObject,clone, equals, hashcode to SerialXLob
lancea
parents:
10323
diff
changeset
|
87 |
private long origLen; |
2 | 88 |
|
89 |
/** |
|
90 |
* Constructs a <code>SerialClob</code> object that is a serialized version of |
|
91 |
* the given <code>char</code> array. |
|
92 |
* <p> |
|
93 |
* The new <code>SerialClob</code> object is initialized with the data from the |
|
94 |
* <code>char</code> array, thus allowing disconnected <code>RowSet</code> |
|
95 |
* objects to establish a serialized <code>Clob</code> object without touching |
|
96 |
* the data source. |
|
97 |
* |
|
98 |
* @param ch the char array representing the <code>Clob</code> object to be |
|
99 |
* serialized |
|
100 |
* @throws SerialException if an error occurs during serialization |
|
101 |
* @throws SQLException if a SQL error occurs |
|
102 |
*/ |
|
103 |
public SerialClob(char ch[]) throws SerialException, SQLException { |
|
104 |
||
105 |
// %%% JMB. Agreed. Add code here to throw a SQLException if no |
|
106 |
// support is available for locatorsUpdateCopy=false |
|
107 |
// Serializing locators is not supported. |
|
108 |
||
109 |
len = ch.length; |
|
110 |
buf = new char[(int)len]; |
|
111 |
for (int i = 0; i < len ; i++){ |
|
112 |
buf[i] = ch[i]; |
|
113 |
} |
|
114 |
origLen = len; |
|
8405
bafd7b441d80
7018385: update javax.sql classes to use try-with-resources
smarks
parents:
5506
diff
changeset
|
115 |
clob = null; |
2 | 116 |
} |
117 |
||
118 |
/** |
|
119 |
* Constructs a <code>SerialClob</code> object that is a serialized |
|
120 |
* version of the given <code>Clob</code> object. |
|
121 |
* <P> |
|
122 |
* The new <code>SerialClob</code> object is initialized with the |
|
123 |
* data from the <code>Clob</code> object; therefore, the |
|
124 |
* <code>Clob</code> object should have previously brought the |
|
125 |
* SQL <code>CLOB</code> value's data over to the client from |
|
126 |
* the database. Otherwise, the new <code>SerialClob</code> object |
|
127 |
* object will contain no data. |
|
128 |
* <p> |
|
8405
bafd7b441d80
7018385: update javax.sql classes to use try-with-resources
smarks
parents:
5506
diff
changeset
|
129 |
* Note: The <code>Clob</code> object supplied to this constructor must |
bafd7b441d80
7018385: update javax.sql classes to use try-with-resources
smarks
parents:
5506
diff
changeset
|
130 |
* return non-null for both the <code>Clob.getCharacterStream()</code> |
2 | 131 |
* and <code>Clob.getAsciiStream</code> methods. This <code>SerialClob</code> |
8405
bafd7b441d80
7018385: update javax.sql classes to use try-with-resources
smarks
parents:
5506
diff
changeset
|
132 |
* constructor cannot serialize a <code>Clob</code> object in this instance |
2 | 133 |
* and will throw an <code>SQLException</code> object. |
134 |
* |
|
135 |
* @param clob the <code>Clob</code> object from which this |
|
136 |
* <code>SerialClob</code> object is to be constructed; cannot be null |
|
137 |
* @throws SerialException if an error occurs during serialization |
|
138 |
* @throws SQLException if a SQL error occurs in capturing the CLOB; |
|
8405
bafd7b441d80
7018385: update javax.sql classes to use try-with-resources
smarks
parents:
5506
diff
changeset
|
139 |
* if the <code>Clob</code> object is a null; or if either of the |
2 | 140 |
* <code>Clob.getCharacterStream()</code> and <code>Clob.getAsciiStream()</code> |
8405
bafd7b441d80
7018385: update javax.sql classes to use try-with-resources
smarks
parents:
5506
diff
changeset
|
141 |
* methods on the <code>Clob</code> returns a null |
2 | 142 |
* @see java.sql.Clob |
143 |
*/ |
|
144 |
public SerialClob(Clob clob) throws SerialException, SQLException { |
|
145 |
||
146 |
if (clob == null) { |
|
147 |
throw new SQLException("Cannot instantiate a SerialClob " + |
|
148 |
"object with a null Clob object"); |
|
149 |
} |
|
150 |
len = clob.length(); |
|
151 |
this.clob = clob; |
|
152 |
buf = new char[(int)len]; |
|
153 |
int read = 0; |
|
154 |
int offset = 0; |
|
155 |
||
8405
bafd7b441d80
7018385: update javax.sql classes to use try-with-resources
smarks
parents:
5506
diff
changeset
|
156 |
try (Reader charStream = clob.getCharacterStream()) { |
bafd7b441d80
7018385: update javax.sql classes to use try-with-resources
smarks
parents:
5506
diff
changeset
|
157 |
if (charStream == null) { |
bafd7b441d80
7018385: update javax.sql classes to use try-with-resources
smarks
parents:
5506
diff
changeset
|
158 |
throw new SQLException("Invalid Clob object. The call to getCharacterStream " + |
bafd7b441d80
7018385: update javax.sql classes to use try-with-resources
smarks
parents:
5506
diff
changeset
|
159 |
"returned null which cannot be serialized."); |
bafd7b441d80
7018385: update javax.sql classes to use try-with-resources
smarks
parents:
5506
diff
changeset
|
160 |
} |
2 | 161 |
|
8405
bafd7b441d80
7018385: update javax.sql classes to use try-with-resources
smarks
parents:
5506
diff
changeset
|
162 |
// Note: get an ASCII stream in order to null-check it, |
bafd7b441d80
7018385: update javax.sql classes to use try-with-resources
smarks
parents:
5506
diff
changeset
|
163 |
// even though we don't do anything with it. |
bafd7b441d80
7018385: update javax.sql classes to use try-with-resources
smarks
parents:
5506
diff
changeset
|
164 |
try (InputStream asciiStream = clob.getAsciiStream()) { |
bafd7b441d80
7018385: update javax.sql classes to use try-with-resources
smarks
parents:
5506
diff
changeset
|
165 |
if (asciiStream == null) { |
bafd7b441d80
7018385: update javax.sql classes to use try-with-resources
smarks
parents:
5506
diff
changeset
|
166 |
throw new SQLException("Invalid Clob object. The call to getAsciiStream " + |
bafd7b441d80
7018385: update javax.sql classes to use try-with-resources
smarks
parents:
5506
diff
changeset
|
167 |
"returned null which cannot be serialized."); |
bafd7b441d80
7018385: update javax.sql classes to use try-with-resources
smarks
parents:
5506
diff
changeset
|
168 |
} |
bafd7b441d80
7018385: update javax.sql classes to use try-with-resources
smarks
parents:
5506
diff
changeset
|
169 |
} |
2 | 170 |
|
8405
bafd7b441d80
7018385: update javax.sql classes to use try-with-resources
smarks
parents:
5506
diff
changeset
|
171 |
try (Reader reader = new BufferedReader(charStream)) { |
bafd7b441d80
7018385: update javax.sql classes to use try-with-resources
smarks
parents:
5506
diff
changeset
|
172 |
do { |
bafd7b441d80
7018385: update javax.sql classes to use try-with-resources
smarks
parents:
5506
diff
changeset
|
173 |
read = reader.read(buf, offset, (int)(len - offset)); |
bafd7b441d80
7018385: update javax.sql classes to use try-with-resources
smarks
parents:
5506
diff
changeset
|
174 |
offset += read; |
bafd7b441d80
7018385: update javax.sql classes to use try-with-resources
smarks
parents:
5506
diff
changeset
|
175 |
} while (read > 0); |
bafd7b441d80
7018385: update javax.sql classes to use try-with-resources
smarks
parents:
5506
diff
changeset
|
176 |
} |
2 | 177 |
} catch (java.io.IOException ex) { |
178 |
throw new SerialException("SerialClob: " + ex.getMessage()); |
|
179 |
} |
|
180 |
||
181 |
origLen = len; |
|
182 |
} |
|
183 |
||
184 |
/** |
|
185 |
* Retrieves the number of characters in this <code>SerialClob</code> |
|
186 |
* object's array of characters. |
|
187 |
* |
|
188 |
* @return a <code>long</code> indicating the length in characters of this |
|
189 |
* <code>SerialClob</code> object's array of character |
|
14781
701d0765f75f
8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents:
14337
diff
changeset
|
190 |
* @throws SerialException if an error occurs; |
701d0765f75f
8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents:
14337
diff
changeset
|
191 |
* if {@code free} had previously been called on this object |
2 | 192 |
*/ |
193 |
public long length() throws SerialException { |
|
14781
701d0765f75f
8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents:
14337
diff
changeset
|
194 |
isValid(); |
2 | 195 |
return len; |
196 |
} |
|
197 |
||
198 |
/** |
|
199 |
* Returns this <code>SerialClob</code> object's data as a stream |
|
200 |
* of Unicode characters. Unlike the related method, <code>getAsciiStream</code>, |
|
201 |
* a stream is produced regardless of whether the <code>SerialClob</code> object |
|
202 |
* was created with a <code>Clob</code> object or a <code>char</code> array. |
|
203 |
* |
|
204 |
* @return a <code>java.io.Reader</code> object containing this |
|
205 |
* <code>SerialClob</code> object's data |
|
14781
701d0765f75f
8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents:
14337
diff
changeset
|
206 |
* @throws SerialException if an error occurs; |
701d0765f75f
8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents:
14337
diff
changeset
|
207 |
* if {@code free} had previously been called on this object |
2 | 208 |
*/ |
209 |
public java.io.Reader getCharacterStream() throws SerialException { |
|
14781
701d0765f75f
8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents:
14337
diff
changeset
|
210 |
isValid(); |
2 | 211 |
return (java.io.Reader) new CharArrayReader(buf); |
212 |
} |
|
213 |
||
214 |
/** |
|
215 |
* Retrieves the <code>CLOB</code> value designated by this <code>SerialClob</code> |
|
216 |
* object as an ascii stream. This method forwards the <code>getAsciiStream</code> |
|
217 |
* call to the underlying <code>Clob</code> object in the event that this |
|
218 |
* <code>SerialClob</code> object is instantiated with a <code>Clob</code> |
|
219 |
* object. If this <code>SerialClob</code> object is instantiated with |
|
220 |
* a <code>char</code> array, a <code>SerialException</code> object is thrown. |
|
221 |
* |
|
222 |
* @return a <code>java.io.InputStream</code> object containing |
|
223 |
* this <code>SerialClob</code> object's data |
|
14781
701d0765f75f
8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents:
14337
diff
changeset
|
224 |
* @throws SerialException if this {@code SerialClob} object was not |
701d0765f75f
8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents:
14337
diff
changeset
|
225 |
* instantiated with a <code>Clob</code> object; |
701d0765f75f
8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents:
14337
diff
changeset
|
226 |
* if {@code free} had previously been called on this object |
2 | 227 |
* @throws SQLException if there is an error accessing the |
14781
701d0765f75f
8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents:
14337
diff
changeset
|
228 |
* <code>CLOB</code> value represented by the <code>Clob</code> object |
701d0765f75f
8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents:
14337
diff
changeset
|
229 |
* that was used to create this <code>SerialClob</code> object |
2 | 230 |
*/ |
231 |
public java.io.InputStream getAsciiStream() throws SerialException, SQLException { |
|
14781
701d0765f75f
8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents:
14337
diff
changeset
|
232 |
isValid(); |
8405
bafd7b441d80
7018385: update javax.sql classes to use try-with-resources
smarks
parents:
5506
diff
changeset
|
233 |
if (this.clob != null) { |
bafd7b441d80
7018385: update javax.sql classes to use try-with-resources
smarks
parents:
5506
diff
changeset
|
234 |
return this.clob.getAsciiStream(); |
bafd7b441d80
7018385: update javax.sql classes to use try-with-resources
smarks
parents:
5506
diff
changeset
|
235 |
} else { |
bafd7b441d80
7018385: update javax.sql classes to use try-with-resources
smarks
parents:
5506
diff
changeset
|
236 |
throw new SerialException("Unsupported operation. SerialClob cannot " + |
2 | 237 |
"return a the CLOB value as an ascii stream, unless instantiated " + |
238 |
"with a fully implemented Clob object."); |
|
8405
bafd7b441d80
7018385: update javax.sql classes to use try-with-resources
smarks
parents:
5506
diff
changeset
|
239 |
} |
2 | 240 |
} |
241 |
||
242 |
/** |
|
243 |
* Returns a copy of the substring contained in this |
|
244 |
* <code>SerialClob</code> object, starting at the given position |
|
245 |
* and continuing for the specified number or characters. |
|
246 |
* |
|
247 |
* @param pos the position of the first character in the substring |
|
248 |
* to be copied; the first character of the |
|
249 |
* <code>SerialClob</code> object is at position |
|
250 |
* <code>1</code>; must not be less than <code>1</code>, |
|
251 |
* and the sum of the starting position and the length |
|
252 |
* of the substring must be less than the length of this |
|
253 |
* <code>SerialClob</code> object |
|
254 |
* @param length the number of characters in the substring to be |
|
255 |
* returned; must not be greater than the length of |
|
256 |
* this <code>SerialClob</code> object, and the |
|
257 |
* sum of the starting position and the length |
|
258 |
* of the substring must be less than the length of this |
|
259 |
* <code>SerialClob</code> object |
|
260 |
* @return a <code>String</code> object containing a substring of |
|
261 |
* this <code>SerialClob</code> object beginning at the |
|
262 |
* given position and containing the specified number of |
|
263 |
* consecutive characters |
|
14781
701d0765f75f
8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents:
14337
diff
changeset
|
264 |
* @throws SerialException if either of the arguments is out of bounds; |
701d0765f75f
8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents:
14337
diff
changeset
|
265 |
* if {@code free} had previously been called on this object |
2 | 266 |
*/ |
267 |
public String getSubString(long pos, int length) throws SerialException { |
|
268 |
||
14781
701d0765f75f
8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents:
14337
diff
changeset
|
269 |
isValid(); |
2 | 270 |
if (pos < 1 || pos > this.length()) { |
14781
701d0765f75f
8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents:
14337
diff
changeset
|
271 |
throw new SerialException("Invalid position in SerialClob object set"); |
2 | 272 |
} |
273 |
||
274 |
if ((pos-1) + length > this.length()) { |
|
275 |
throw new SerialException("Invalid position and substring length"); |
|
276 |
} |
|
277 |
||
278 |
try { |
|
279 |
return new String(buf, (int)pos - 1, length); |
|
280 |
||
281 |
} catch (StringIndexOutOfBoundsException e) { |
|
282 |
throw new SerialException("StringIndexOutOfBoundsException: " + |
|
283 |
e.getMessage()); |
|
284 |
} |
|
285 |
||
286 |
} |
|
287 |
||
288 |
/** |
|
289 |
* Returns the position in this <code>SerialClob</code> object |
|
290 |
* where the given <code>String</code> object begins, starting |
|
291 |
* the search at the specified position. This method returns |
|
292 |
* <code>-1</code> if the pattern is not found. |
|
293 |
* |
|
294 |
* @param searchStr the <code>String</code> object for which to |
|
295 |
* search |
|
296 |
* @param start the position in this <code>SerialClob</code> object |
|
297 |
* at which to start the search; the first position is |
|
298 |
* <code>1</code>; must not be less than <code>1</code> nor |
|
299 |
* greater than the length of this <code>SerialClob</code> object |
|
300 |
* @return the position at which the given <code>String</code> object |
|
301 |
* begins, starting the search at the specified position; |
|
302 |
* <code>-1</code> if the given <code>String</code> object is |
|
303 |
* not found or the starting position is out of bounds; position |
|
304 |
* numbering for the return value starts at <code>1</code> |
|
14781
701d0765f75f
8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents:
14337
diff
changeset
|
305 |
* @throws SerialException if the {@code free} method had been |
701d0765f75f
8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents:
14337
diff
changeset
|
306 |
* previously called on this object |
701d0765f75f
8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents:
14337
diff
changeset
|
307 |
* @throws SQLException if there is an error accessing the Clob value |
2 | 308 |
* from the database. |
309 |
*/ |
|
310 |
public long position(String searchStr, long start) |
|
311 |
throws SerialException, SQLException { |
|
14781
701d0765f75f
8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents:
14337
diff
changeset
|
312 |
isValid(); |
2 | 313 |
if (start < 1 || start > len) { |
314 |
return -1; |
|
315 |
} |
|
316 |
||
317 |
char pattern[] = searchStr.toCharArray(); |
|
318 |
||
319 |
int pos = (int)start-1; |
|
320 |
int i = 0; |
|
321 |
long patlen = pattern.length; |
|
322 |
||
323 |
while (pos < len) { |
|
324 |
if (pattern[i] == buf[pos]) { |
|
325 |
if (i + 1 == patlen) { |
|
326 |
return (pos + 1) - (patlen - 1); |
|
327 |
} |
|
328 |
i++; pos++; // increment pos, and i |
|
329 |
||
330 |
} else if (pattern[i] != buf[pos]) { |
|
331 |
pos++; // increment pos only |
|
332 |
} |
|
333 |
} |
|
334 |
return -1; // not found |
|
335 |
} |
|
336 |
||
337 |
/** |
|
338 |
* Returns the position in this <code>SerialClob</code> object |
|
339 |
* where the given <code>Clob</code> signature begins, starting |
|
340 |
* the search at the specified position. This method returns |
|
341 |
* <code>-1</code> if the pattern is not found. |
|
342 |
* |
|
343 |
* @param searchStr the <code>Clob</code> object for which to search |
|
344 |
* @param start the position in this <code>SerialClob</code> object |
|
345 |
* at which to begin the search; the first position is |
|
346 |
* <code>1</code>; must not be less than <code>1</code> nor |
|
347 |
* greater than the length of this <code>SerialClob</code> object |
|
348 |
* @return the position at which the given <code>Clob</code> |
|
349 |
* object begins in this <code>SerialClob</code> object, |
|
350 |
* at or after the specified starting position |
|
14781
701d0765f75f
8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents:
14337
diff
changeset
|
351 |
* @throws SerialException if an error occurs locating the Clob signature; |
701d0765f75f
8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents:
14337
diff
changeset
|
352 |
* if the {@code free} method had been previously called on this object |
701d0765f75f
8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents:
14337
diff
changeset
|
353 |
* @throws SQLException if there is an error accessing the Clob value |
2 | 354 |
* from the database |
355 |
*/ |
|
356 |
public long position(Clob searchStr, long start) |
|
357 |
throws SerialException, SQLException { |
|
14781
701d0765f75f
8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents:
14337
diff
changeset
|
358 |
isValid(); |
2 | 359 |
return position(searchStr.getSubString(1,(int)searchStr.length()), start); |
360 |
} |
|
361 |
||
362 |
/** |
|
363 |
* Writes the given Java <code>String</code> to the <code>CLOB</code> |
|
364 |
* value that this <code>SerialClob</code> object represents, at the position |
|
365 |
* <code>pos</code>. |
|
366 |
* |
|
367 |
* @param pos the position at which to start writing to the <code>CLOB</code> |
|
368 |
* value that this <code>SerialClob</code> object represents; the first |
|
369 |
* position is <code>1</code>; must not be less than <code>1</code> nor |
|
370 |
* greater than the length of this <code>SerialClob</code> object |
|
371 |
* @param str the string to be written to the <code>CLOB</code> |
|
372 |
* value that this <code>SerialClob</code> object represents |
|
373 |
* @return the number of characters written |
|
374 |
* @throws SerialException if there is an error accessing the |
|
375 |
* <code>CLOB</code> value; if an invalid position is set; if an |
|
376 |
* invalid offset value is set; if number of bytes to be written |
|
377 |
* is greater than the <code>SerialClob</code> length; or the combined |
|
14781
701d0765f75f
8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents:
14337
diff
changeset
|
378 |
* values of the length and offset is greater than the Clob buffer; |
701d0765f75f
8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents:
14337
diff
changeset
|
379 |
* if the {@code free} method had been previously called on this object |
2 | 380 |
*/ |
381 |
public int setString(long pos, String str) throws SerialException { |
|
382 |
return (setString(pos, str, 0, str.length())); |
|
383 |
} |
|
384 |
||
385 |
/** |
|
386 |
* Writes <code>len</code> characters of <code>str</code>, starting |
|
387 |
* at character <code>offset</code>, to the <code>CLOB</code> value |
|
388 |
* that this <code>Clob</code> represents. |
|
389 |
* |
|
390 |
* @param pos the position at which to start writing to the <code>CLOB</code> |
|
391 |
* value that this <code>SerialClob</code> object represents; the first |
|
392 |
* position is <code>1</code>; must not be less than <code>1</code> nor |
|
393 |
* greater than the length of this <code>SerialClob</code> object |
|
394 |
* @param str the string to be written to the <code>CLOB</code> |
|
395 |
* value that this <code>Clob</code> object represents |
|
396 |
* @param offset the offset into <code>str</code> to start reading |
|
397 |
* the characters to be written |
|
398 |
* @param length the number of characters to be written |
|
399 |
* @return the number of characters written |
|
400 |
* @throws SerialException if there is an error accessing the |
|
401 |
* <code>CLOB</code> value; if an invalid position is set; if an |
|
402 |
* invalid offset value is set; if number of bytes to be written |
|
403 |
* is greater than the <code>SerialClob</code> length; or the combined |
|
14781
701d0765f75f
8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents:
14337
diff
changeset
|
404 |
* values of the length and offset is greater than the Clob buffer; |
701d0765f75f
8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents:
14337
diff
changeset
|
405 |
* if the {@code free} method had been previously called on this object |
2 | 406 |
*/ |
407 |
public int setString(long pos, String str, int offset, int length) |
|
408 |
throws SerialException { |
|
14781
701d0765f75f
8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents:
14337
diff
changeset
|
409 |
isValid(); |
2 | 410 |
String temp = str.substring(offset); |
411 |
char cPattern[] = temp.toCharArray(); |
|
412 |
||
413 |
if (offset < 0 || offset > str.length()) { |
|
414 |
throw new SerialException("Invalid offset in byte array set"); |
|
415 |
} |
|
416 |
||
417 |
if (pos < 1 || pos > this.length()) { |
|
14781
701d0765f75f
8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents:
14337
diff
changeset
|
418 |
throw new SerialException("Invalid position in Clob object set"); |
2 | 419 |
} |
420 |
||
421 |
if ((long)(length) > origLen) { |
|
422 |
throw new SerialException("Buffer is not sufficient to hold the value"); |
|
423 |
} |
|
424 |
||
425 |
if ((length + offset) > str.length()) { |
|
426 |
// need check to ensure length + offset !> bytes.length |
|
427 |
throw new SerialException("Invalid OffSet. Cannot have combined offset " + |
|
428 |
" and length that is greater that the Blob buffer"); |
|
429 |
} |
|
430 |
||
431 |
int i = 0; |
|
432 |
pos--; //values in the array are at position one less |
|
433 |
while ( i < length || (offset + i +1) < (str.length() - offset ) ) { |
|
434 |
this.buf[(int)pos + i ] = cPattern[offset + i ]; |
|
435 |
i++; |
|
436 |
} |
|
437 |
return i; |
|
438 |
} |
|
439 |
||
440 |
/** |
|
441 |
* Retrieves a stream to be used to write Ascii characters to the |
|
442 |
* <code>CLOB</code> value that this <code>SerialClob</code> object represents, |
|
443 |
* starting at position <code>pos</code>. This method forwards the |
|
444 |
* <code>setAsciiStream()</code> call to the underlying <code>Clob</code> object in |
|
445 |
* the event that this <code>SerialClob</code> object is instantiated with a |
|
446 |
* <code>Clob</code> object. If this <code>SerialClob</code> object is instantiated |
|
447 |
* with a <code>char</code> array, a <code>SerialException</code> object is thrown. |
|
448 |
* |
|
449 |
* @param pos the position at which to start writing to the |
|
450 |
* <code>CLOB</code> object |
|
451 |
* @return the stream to which ASCII encoded characters can be written |
|
452 |
* @throws SerialException if SerialClob is not instantiated with a |
|
14781
701d0765f75f
8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents:
14337
diff
changeset
|
453 |
* Clob object; |
701d0765f75f
8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents:
14337
diff
changeset
|
454 |
* if the {@code free} method had been previously called on this object |
2 | 455 |
* @throws SQLException if there is an error accessing the |
456 |
* <code>CLOB</code> value |
|
457 |
* @see #getAsciiStream |
|
458 |
*/ |
|
459 |
public java.io.OutputStream setAsciiStream(long pos) |
|
460 |
throws SerialException, SQLException { |
|
14781
701d0765f75f
8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents:
14337
diff
changeset
|
461 |
isValid(); |
10323
48d695d1e966
7077451: SerialLob, SerialClob have the wrong checks for setStream methods
lancea
parents:
9035
diff
changeset
|
462 |
if (this.clob != null) { |
2 | 463 |
return this.clob.setAsciiStream(pos); |
464 |
} else { |
|
465 |
throw new SerialException("Unsupported operation. SerialClob cannot " + |
|
466 |
"return a writable ascii stream\n unless instantiated with a Clob object " + |
|
467 |
"that has a setAsciiStream() implementation"); |
|
468 |
} |
|
469 |
} |
|
470 |
||
471 |
/** |
|
472 |
* Retrieves a stream to be used to write a stream of Unicode characters |
|
473 |
* to the <code>CLOB</code> value that this <code>SerialClob</code> object |
|
474 |
* represents, at position <code>pos</code>. This method forwards the |
|
475 |
* <code>setCharacterStream()</code> call to the underlying <code>Clob</code> |
|
476 |
* object in the event that this <code>SerialClob</code> object is instantiated with a |
|
477 |
* <code>Clob</code> object. If this <code>SerialClob</code> object is instantiated with |
|
478 |
* a <code>char</code> array, a <code>SerialException</code> is thrown. |
|
479 |
* |
|
480 |
* @param pos the position at which to start writing to the |
|
481 |
* <code>CLOB</code> value |
|
482 |
* |
|
483 |
* @return a stream to which Unicode encoded characters can be written |
|
484 |
* @throws SerialException if the SerialClob is not instantiated with |
|
14781
701d0765f75f
8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents:
14337
diff
changeset
|
485 |
* a Clob object; |
701d0765f75f
8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents:
14337
diff
changeset
|
486 |
* if the {@code free} method had been previously called on this object |
2 | 487 |
* @throws SQLException if there is an error accessing the |
488 |
* <code>CLOB</code> value |
|
489 |
* @see #getCharacterStream |
|
490 |
*/ |
|
491 |
public java.io.Writer setCharacterStream(long pos) |
|
492 |
throws SerialException, SQLException { |
|
14781
701d0765f75f
8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents:
14337
diff
changeset
|
493 |
isValid(); |
10323
48d695d1e966
7077451: SerialLob, SerialClob have the wrong checks for setStream methods
lancea
parents:
9035
diff
changeset
|
494 |
if (this.clob != null) { |
2 | 495 |
return this.clob.setCharacterStream(pos); |
496 |
} else { |
|
497 |
throw new SerialException("Unsupported operation. SerialClob cannot " + |
|
498 |
"return a writable character stream\n unless instantiated with a Clob object " + |
|
499 |
"that has a setCharacterStream implementation"); |
|
500 |
} |
|
501 |
} |
|
502 |
||
503 |
/** |
|
504 |
* Truncates the <code>CLOB</code> value that this <code>SerialClob</code> |
|
505 |
* object represents so that it has a length of <code>len</code> |
|
506 |
* characters. |
|
507 |
* <p> |
|
508 |
* Truncating a <code>SerialClob</code> object to length 0 has the effect of |
|
509 |
* clearing its contents. |
|
510 |
* |
|
511 |
* @param length the length, in bytes, to which the <code>CLOB</code> |
|
512 |
* value should be truncated |
|
16732 | 513 |
* @throws SerialException if there is an error accessing the |
14781
701d0765f75f
8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents:
14337
diff
changeset
|
514 |
* <code>CLOB</code> value; |
701d0765f75f
8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents:
14337
diff
changeset
|
515 |
* if the {@code free} method had been previously called on this object |
2 | 516 |
*/ |
517 |
public void truncate(long length) throws SerialException { |
|
14781
701d0765f75f
8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents:
14337
diff
changeset
|
518 |
isValid(); |
701d0765f75f
8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents:
14337
diff
changeset
|
519 |
if (length > len) { |
701d0765f75f
8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents:
14337
diff
changeset
|
520 |
throw new SerialException |
701d0765f75f
8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents:
14337
diff
changeset
|
521 |
("Length more than what can be truncated"); |
701d0765f75f
8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents:
14337
diff
changeset
|
522 |
} else { |
701d0765f75f
8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents:
14337
diff
changeset
|
523 |
len = length; |
701d0765f75f
8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents:
14337
diff
changeset
|
524 |
// re-size the buffer |
2 | 525 |
|
14781
701d0765f75f
8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents:
14337
diff
changeset
|
526 |
if (len == 0) { |
701d0765f75f
8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents:
14337
diff
changeset
|
527 |
buf = new char[] {}; |
701d0765f75f
8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents:
14337
diff
changeset
|
528 |
} else { |
2 | 529 |
buf = (this.getSubString(1, (int)len)).toCharArray(); |
14781
701d0765f75f
8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents:
14337
diff
changeset
|
530 |
} |
701d0765f75f
8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents:
14337
diff
changeset
|
531 |
} |
2 | 532 |
} |
533 |
||
534 |
||
14781
701d0765f75f
8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents:
14337
diff
changeset
|
535 |
/** |
701d0765f75f
8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents:
14337
diff
changeset
|
536 |
* Returns a {@code Reader} object that contains a partial |
701d0765f75f
8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents:
14337
diff
changeset
|
537 |
* {@code SerialClob} value, starting |
701d0765f75f
8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents:
14337
diff
changeset
|
538 |
* with the character specified by pos, which is length characters in length. |
701d0765f75f
8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents:
14337
diff
changeset
|
539 |
* |
701d0765f75f
8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents:
14337
diff
changeset
|
540 |
* @param pos the offset to the first character of the partial value to |
701d0765f75f
8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents:
14337
diff
changeset
|
541 |
* be retrieved. The first character in the {@code SerialClob} is at position 1. |
701d0765f75f
8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents:
14337
diff
changeset
|
542 |
* @param length the length in characters of the partial value to be retrieved. |
701d0765f75f
8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents:
14337
diff
changeset
|
543 |
* @return {@code Reader} through which the partial {@code SerialClob} |
701d0765f75f
8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents:
14337
diff
changeset
|
544 |
* value can be read. |
701d0765f75f
8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents:
14337
diff
changeset
|
545 |
* @throws SQLException if pos is less than 1 or if pos is greater than the |
701d0765f75f
8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents:
14337
diff
changeset
|
546 |
* number of characters in the {@code SerialClob} or if pos + length |
701d0765f75f
8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents:
14337
diff
changeset
|
547 |
* is greater than the number of characters in the {@code SerialClob}; |
701d0765f75f
8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents:
14337
diff
changeset
|
548 |
* @throws SerialException if the {@code free} method had been previously |
701d0765f75f
8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents:
14337
diff
changeset
|
549 |
* called on this object |
701d0765f75f
8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents:
14337
diff
changeset
|
550 |
* @since 1.6 |
701d0765f75f
8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents:
14337
diff
changeset
|
551 |
*/ |
2 | 552 |
public Reader getCharacterStream(long pos, long length) throws SQLException { |
14781
701d0765f75f
8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents:
14337
diff
changeset
|
553 |
isValid(); |
701d0765f75f
8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents:
14337
diff
changeset
|
554 |
if (pos < 1 || pos > len) { |
701d0765f75f
8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents:
14337
diff
changeset
|
555 |
throw new SerialException("Invalid position in Clob object set"); |
701d0765f75f
8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents:
14337
diff
changeset
|
556 |
} |
701d0765f75f
8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents:
14337
diff
changeset
|
557 |
|
701d0765f75f
8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents:
14337
diff
changeset
|
558 |
if ((pos-1) + length > len) { |
701d0765f75f
8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents:
14337
diff
changeset
|
559 |
throw new SerialException("Invalid position and substring length"); |
701d0765f75f
8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents:
14337
diff
changeset
|
560 |
} |
701d0765f75f
8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents:
14337
diff
changeset
|
561 |
if (length <= 0) { |
701d0765f75f
8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents:
14337
diff
changeset
|
562 |
throw new SerialException("Invalid length specified"); |
701d0765f75f
8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents:
14337
diff
changeset
|
563 |
} |
701d0765f75f
8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents:
14337
diff
changeset
|
564 |
return new CharArrayReader(buf, (int)pos, (int)length); |
2 | 565 |
} |
566 |
||
14781
701d0765f75f
8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents:
14337
diff
changeset
|
567 |
/** |
25976
4de01a56e3ee
8054555: javadoc cleanup for java.sql and javax.sql
lancea
parents:
24968
diff
changeset
|
568 |
* This method frees the {@code SerialClob} object and releases the |
14781
701d0765f75f
8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents:
14337
diff
changeset
|
569 |
* resources that it holds. |
701d0765f75f
8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents:
14337
diff
changeset
|
570 |
* The object is invalid once the {@code free} method is called. |
701d0765f75f
8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents:
14337
diff
changeset
|
571 |
* <p> |
701d0765f75f
8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents:
14337
diff
changeset
|
572 |
* If {@code free} is called multiple times, the subsequent |
701d0765f75f
8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents:
14337
diff
changeset
|
573 |
* calls to {@code free} are treated as a no-op. |
701d0765f75f
8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents:
14337
diff
changeset
|
574 |
* </P> |
701d0765f75f
8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents:
14337
diff
changeset
|
575 |
* @throws SQLException if an error occurs releasing |
701d0765f75f
8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents:
14337
diff
changeset
|
576 |
* the Clob's resources |
701d0765f75f
8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents:
14337
diff
changeset
|
577 |
* @since 1.6 |
701d0765f75f
8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents:
14337
diff
changeset
|
578 |
*/ |
2 | 579 |
public void free() throws SQLException { |
14781
701d0765f75f
8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents:
14337
diff
changeset
|
580 |
if (buf != null) { |
701d0765f75f
8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents:
14337
diff
changeset
|
581 |
buf = null; |
701d0765f75f
8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents:
14337
diff
changeset
|
582 |
if (clob != null) { |
701d0765f75f
8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents:
14337
diff
changeset
|
583 |
clob.free(); |
701d0765f75f
8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents:
14337
diff
changeset
|
584 |
} |
701d0765f75f
8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents:
14337
diff
changeset
|
585 |
clob = null; |
701d0765f75f
8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents:
14337
diff
changeset
|
586 |
} |
2 | 587 |
} |
588 |
||
589 |
/** |
|
14337
a003c6a54cb6
8001536: Added readObject,writeObject,clone, equals, hashcode to SerialXLob
lancea
parents:
10323
diff
changeset
|
590 |
* Compares this SerialClob to the specified object. The result is {@code |
a003c6a54cb6
8001536: Added readObject,writeObject,clone, equals, hashcode to SerialXLob
lancea
parents:
10323
diff
changeset
|
591 |
* true} if and only if the argument is not {@code null} and is a {@code |
a003c6a54cb6
8001536: Added readObject,writeObject,clone, equals, hashcode to SerialXLob
lancea
parents:
10323
diff
changeset
|
592 |
* SerialClob} object that represents the same sequence of characters as this |
a003c6a54cb6
8001536: Added readObject,writeObject,clone, equals, hashcode to SerialXLob
lancea
parents:
10323
diff
changeset
|
593 |
* object. |
a003c6a54cb6
8001536: Added readObject,writeObject,clone, equals, hashcode to SerialXLob
lancea
parents:
10323
diff
changeset
|
594 |
* |
a003c6a54cb6
8001536: Added readObject,writeObject,clone, equals, hashcode to SerialXLob
lancea
parents:
10323
diff
changeset
|
595 |
* @param obj The object to compare this {@code SerialClob} against |
a003c6a54cb6
8001536: Added readObject,writeObject,clone, equals, hashcode to SerialXLob
lancea
parents:
10323
diff
changeset
|
596 |
* |
a003c6a54cb6
8001536: Added readObject,writeObject,clone, equals, hashcode to SerialXLob
lancea
parents:
10323
diff
changeset
|
597 |
* @return {@code true} if the given object represents a {@code SerialClob} |
a003c6a54cb6
8001536: Added readObject,writeObject,clone, equals, hashcode to SerialXLob
lancea
parents:
10323
diff
changeset
|
598 |
* equivalent to this SerialClob, {@code false} otherwise |
a003c6a54cb6
8001536: Added readObject,writeObject,clone, equals, hashcode to SerialXLob
lancea
parents:
10323
diff
changeset
|
599 |
* |
a003c6a54cb6
8001536: Added readObject,writeObject,clone, equals, hashcode to SerialXLob
lancea
parents:
10323
diff
changeset
|
600 |
*/ |
a003c6a54cb6
8001536: Added readObject,writeObject,clone, equals, hashcode to SerialXLob
lancea
parents:
10323
diff
changeset
|
601 |
public boolean equals(Object obj) { |
a003c6a54cb6
8001536: Added readObject,writeObject,clone, equals, hashcode to SerialXLob
lancea
parents:
10323
diff
changeset
|
602 |
if (this == obj) { |
a003c6a54cb6
8001536: Added readObject,writeObject,clone, equals, hashcode to SerialXLob
lancea
parents:
10323
diff
changeset
|
603 |
return true; |
a003c6a54cb6
8001536: Added readObject,writeObject,clone, equals, hashcode to SerialXLob
lancea
parents:
10323
diff
changeset
|
604 |
} |
a003c6a54cb6
8001536: Added readObject,writeObject,clone, equals, hashcode to SerialXLob
lancea
parents:
10323
diff
changeset
|
605 |
if (obj instanceof SerialClob) { |
a003c6a54cb6
8001536: Added readObject,writeObject,clone, equals, hashcode to SerialXLob
lancea
parents:
10323
diff
changeset
|
606 |
SerialClob sc = (SerialClob)obj; |
a003c6a54cb6
8001536: Added readObject,writeObject,clone, equals, hashcode to SerialXLob
lancea
parents:
10323
diff
changeset
|
607 |
if (this.len == sc.len) { |
a003c6a54cb6
8001536: Added readObject,writeObject,clone, equals, hashcode to SerialXLob
lancea
parents:
10323
diff
changeset
|
608 |
return Arrays.equals(buf, sc.buf); |
a003c6a54cb6
8001536: Added readObject,writeObject,clone, equals, hashcode to SerialXLob
lancea
parents:
10323
diff
changeset
|
609 |
} |
a003c6a54cb6
8001536: Added readObject,writeObject,clone, equals, hashcode to SerialXLob
lancea
parents:
10323
diff
changeset
|
610 |
} |
a003c6a54cb6
8001536: Added readObject,writeObject,clone, equals, hashcode to SerialXLob
lancea
parents:
10323
diff
changeset
|
611 |
return false; |
a003c6a54cb6
8001536: Added readObject,writeObject,clone, equals, hashcode to SerialXLob
lancea
parents:
10323
diff
changeset
|
612 |
} |
a003c6a54cb6
8001536: Added readObject,writeObject,clone, equals, hashcode to SerialXLob
lancea
parents:
10323
diff
changeset
|
613 |
|
a003c6a54cb6
8001536: Added readObject,writeObject,clone, equals, hashcode to SerialXLob
lancea
parents:
10323
diff
changeset
|
614 |
/** |
a003c6a54cb6
8001536: Added readObject,writeObject,clone, equals, hashcode to SerialXLob
lancea
parents:
10323
diff
changeset
|
615 |
* Returns a hash code for this {@code SerialClob}. |
a003c6a54cb6
8001536: Added readObject,writeObject,clone, equals, hashcode to SerialXLob
lancea
parents:
10323
diff
changeset
|
616 |
* @return a hash code value for this object. |
a003c6a54cb6
8001536: Added readObject,writeObject,clone, equals, hashcode to SerialXLob
lancea
parents:
10323
diff
changeset
|
617 |
*/ |
a003c6a54cb6
8001536: Added readObject,writeObject,clone, equals, hashcode to SerialXLob
lancea
parents:
10323
diff
changeset
|
618 |
public int hashCode() { |
a003c6a54cb6
8001536: Added readObject,writeObject,clone, equals, hashcode to SerialXLob
lancea
parents:
10323
diff
changeset
|
619 |
return ((31 + Arrays.hashCode(buf)) * 31 + (int)len) * 31 + (int)origLen; |
a003c6a54cb6
8001536: Added readObject,writeObject,clone, equals, hashcode to SerialXLob
lancea
parents:
10323
diff
changeset
|
620 |
} |
a003c6a54cb6
8001536: Added readObject,writeObject,clone, equals, hashcode to SerialXLob
lancea
parents:
10323
diff
changeset
|
621 |
|
a003c6a54cb6
8001536: Added readObject,writeObject,clone, equals, hashcode to SerialXLob
lancea
parents:
10323
diff
changeset
|
622 |
/** |
a003c6a54cb6
8001536: Added readObject,writeObject,clone, equals, hashcode to SerialXLob
lancea
parents:
10323
diff
changeset
|
623 |
* Returns a clone of this {@code SerialClob}. The copy will contain a |
a003c6a54cb6
8001536: Added readObject,writeObject,clone, equals, hashcode to SerialXLob
lancea
parents:
10323
diff
changeset
|
624 |
* reference to a clone of the internal character array, not a reference |
a003c6a54cb6
8001536: Added readObject,writeObject,clone, equals, hashcode to SerialXLob
lancea
parents:
10323
diff
changeset
|
625 |
* to the original internal character array of this {@code SerialClob} object. |
a003c6a54cb6
8001536: Added readObject,writeObject,clone, equals, hashcode to SerialXLob
lancea
parents:
10323
diff
changeset
|
626 |
* The underlying {@code Clob} object will be set to null. |
a003c6a54cb6
8001536: Added readObject,writeObject,clone, equals, hashcode to SerialXLob
lancea
parents:
10323
diff
changeset
|
627 |
* |
a003c6a54cb6
8001536: Added readObject,writeObject,clone, equals, hashcode to SerialXLob
lancea
parents:
10323
diff
changeset
|
628 |
* @return a clone of this SerialClob |
a003c6a54cb6
8001536: Added readObject,writeObject,clone, equals, hashcode to SerialXLob
lancea
parents:
10323
diff
changeset
|
629 |
*/ |
a003c6a54cb6
8001536: Added readObject,writeObject,clone, equals, hashcode to SerialXLob
lancea
parents:
10323
diff
changeset
|
630 |
public Object clone() { |
a003c6a54cb6
8001536: Added readObject,writeObject,clone, equals, hashcode to SerialXLob
lancea
parents:
10323
diff
changeset
|
631 |
try { |
a003c6a54cb6
8001536: Added readObject,writeObject,clone, equals, hashcode to SerialXLob
lancea
parents:
10323
diff
changeset
|
632 |
SerialClob sc = (SerialClob) super.clone(); |
14781
701d0765f75f
8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents:
14337
diff
changeset
|
633 |
sc.buf = (buf != null) ? Arrays.copyOf(buf, (int)len) : null; |
14337
a003c6a54cb6
8001536: Added readObject,writeObject,clone, equals, hashcode to SerialXLob
lancea
parents:
10323
diff
changeset
|
634 |
sc.clob = null; |
a003c6a54cb6
8001536: Added readObject,writeObject,clone, equals, hashcode to SerialXLob
lancea
parents:
10323
diff
changeset
|
635 |
return sc; |
a003c6a54cb6
8001536: Added readObject,writeObject,clone, equals, hashcode to SerialXLob
lancea
parents:
10323
diff
changeset
|
636 |
} catch (CloneNotSupportedException ex) { |
a003c6a54cb6
8001536: Added readObject,writeObject,clone, equals, hashcode to SerialXLob
lancea
parents:
10323
diff
changeset
|
637 |
// this shouldn't happen, since we are Cloneable |
a003c6a54cb6
8001536: Added readObject,writeObject,clone, equals, hashcode to SerialXLob
lancea
parents:
10323
diff
changeset
|
638 |
throw new InternalError(); |
a003c6a54cb6
8001536: Added readObject,writeObject,clone, equals, hashcode to SerialXLob
lancea
parents:
10323
diff
changeset
|
639 |
} |
a003c6a54cb6
8001536: Added readObject,writeObject,clone, equals, hashcode to SerialXLob
lancea
parents:
10323
diff
changeset
|
640 |
} |
a003c6a54cb6
8001536: Added readObject,writeObject,clone, equals, hashcode to SerialXLob
lancea
parents:
10323
diff
changeset
|
641 |
|
a003c6a54cb6
8001536: Added readObject,writeObject,clone, equals, hashcode to SerialXLob
lancea
parents:
10323
diff
changeset
|
642 |
/** |
a003c6a54cb6
8001536: Added readObject,writeObject,clone, equals, hashcode to SerialXLob
lancea
parents:
10323
diff
changeset
|
643 |
* readObject is called to restore the state of the SerialClob from |
a003c6a54cb6
8001536: Added readObject,writeObject,clone, equals, hashcode to SerialXLob
lancea
parents:
10323
diff
changeset
|
644 |
* a stream. |
a003c6a54cb6
8001536: Added readObject,writeObject,clone, equals, hashcode to SerialXLob
lancea
parents:
10323
diff
changeset
|
645 |
*/ |
a003c6a54cb6
8001536: Added readObject,writeObject,clone, equals, hashcode to SerialXLob
lancea
parents:
10323
diff
changeset
|
646 |
private void readObject(ObjectInputStream s) |
a003c6a54cb6
8001536: Added readObject,writeObject,clone, equals, hashcode to SerialXLob
lancea
parents:
10323
diff
changeset
|
647 |
throws IOException, ClassNotFoundException { |
a003c6a54cb6
8001536: Added readObject,writeObject,clone, equals, hashcode to SerialXLob
lancea
parents:
10323
diff
changeset
|
648 |
|
a003c6a54cb6
8001536: Added readObject,writeObject,clone, equals, hashcode to SerialXLob
lancea
parents:
10323
diff
changeset
|
649 |
ObjectInputStream.GetField fields = s.readFields(); |
a003c6a54cb6
8001536: Added readObject,writeObject,clone, equals, hashcode to SerialXLob
lancea
parents:
10323
diff
changeset
|
650 |
char[] tmp = (char[])fields.get("buf", null); |
a003c6a54cb6
8001536: Added readObject,writeObject,clone, equals, hashcode to SerialXLob
lancea
parents:
10323
diff
changeset
|
651 |
if (tmp == null) |
a003c6a54cb6
8001536: Added readObject,writeObject,clone, equals, hashcode to SerialXLob
lancea
parents:
10323
diff
changeset
|
652 |
throw new InvalidObjectException("buf is null and should not be!"); |
a003c6a54cb6
8001536: Added readObject,writeObject,clone, equals, hashcode to SerialXLob
lancea
parents:
10323
diff
changeset
|
653 |
buf = tmp.clone(); |
a003c6a54cb6
8001536: Added readObject,writeObject,clone, equals, hashcode to SerialXLob
lancea
parents:
10323
diff
changeset
|
654 |
len = fields.get("len", 0L); |
a003c6a54cb6
8001536: Added readObject,writeObject,clone, equals, hashcode to SerialXLob
lancea
parents:
10323
diff
changeset
|
655 |
if (buf.length != len) |
a003c6a54cb6
8001536: Added readObject,writeObject,clone, equals, hashcode to SerialXLob
lancea
parents:
10323
diff
changeset
|
656 |
throw new InvalidObjectException("buf is not the expected size"); |
a003c6a54cb6
8001536: Added readObject,writeObject,clone, equals, hashcode to SerialXLob
lancea
parents:
10323
diff
changeset
|
657 |
origLen = fields.get("origLen", 0L); |
a003c6a54cb6
8001536: Added readObject,writeObject,clone, equals, hashcode to SerialXLob
lancea
parents:
10323
diff
changeset
|
658 |
clob = (Clob) fields.get("clob", null); |
a003c6a54cb6
8001536: Added readObject,writeObject,clone, equals, hashcode to SerialXLob
lancea
parents:
10323
diff
changeset
|
659 |
} |
a003c6a54cb6
8001536: Added readObject,writeObject,clone, equals, hashcode to SerialXLob
lancea
parents:
10323
diff
changeset
|
660 |
|
a003c6a54cb6
8001536: Added readObject,writeObject,clone, equals, hashcode to SerialXLob
lancea
parents:
10323
diff
changeset
|
661 |
/** |
a003c6a54cb6
8001536: Added readObject,writeObject,clone, equals, hashcode to SerialXLob
lancea
parents:
10323
diff
changeset
|
662 |
* writeObject is called to save the state of the SerialClob |
a003c6a54cb6
8001536: Added readObject,writeObject,clone, equals, hashcode to SerialXLob
lancea
parents:
10323
diff
changeset
|
663 |
* to a stream. |
a003c6a54cb6
8001536: Added readObject,writeObject,clone, equals, hashcode to SerialXLob
lancea
parents:
10323
diff
changeset
|
664 |
*/ |
a003c6a54cb6
8001536: Added readObject,writeObject,clone, equals, hashcode to SerialXLob
lancea
parents:
10323
diff
changeset
|
665 |
private void writeObject(ObjectOutputStream s) |
51310
a694574b2def
8208782: Remove extra type in throws clause of SerialClob.writeObject
darcy
parents:
47216
diff
changeset
|
666 |
throws IOException { |
14337
a003c6a54cb6
8001536: Added readObject,writeObject,clone, equals, hashcode to SerialXLob
lancea
parents:
10323
diff
changeset
|
667 |
|
a003c6a54cb6
8001536: Added readObject,writeObject,clone, equals, hashcode to SerialXLob
lancea
parents:
10323
diff
changeset
|
668 |
ObjectOutputStream.PutField fields = s.putFields(); |
a003c6a54cb6
8001536: Added readObject,writeObject,clone, equals, hashcode to SerialXLob
lancea
parents:
10323
diff
changeset
|
669 |
fields.put("buf", buf); |
a003c6a54cb6
8001536: Added readObject,writeObject,clone, equals, hashcode to SerialXLob
lancea
parents:
10323
diff
changeset
|
670 |
fields.put("len", len); |
a003c6a54cb6
8001536: Added readObject,writeObject,clone, equals, hashcode to SerialXLob
lancea
parents:
10323
diff
changeset
|
671 |
fields.put("origLen", origLen); |
a003c6a54cb6
8001536: Added readObject,writeObject,clone, equals, hashcode to SerialXLob
lancea
parents:
10323
diff
changeset
|
672 |
// Note: this check to see if it is an instance of Serializable |
25976
4de01a56e3ee
8054555: javadoc cleanup for java.sql and javax.sql
lancea
parents:
24968
diff
changeset
|
673 |
// is for backwards compatibility |
14337
a003c6a54cb6
8001536: Added readObject,writeObject,clone, equals, hashcode to SerialXLob
lancea
parents:
10323
diff
changeset
|
674 |
fields.put("clob", clob instanceof Serializable ? clob : null); |
a003c6a54cb6
8001536: Added readObject,writeObject,clone, equals, hashcode to SerialXLob
lancea
parents:
10323
diff
changeset
|
675 |
s.writeFields(); |
a003c6a54cb6
8001536: Added readObject,writeObject,clone, equals, hashcode to SerialXLob
lancea
parents:
10323
diff
changeset
|
676 |
} |
a003c6a54cb6
8001536: Added readObject,writeObject,clone, equals, hashcode to SerialXLob
lancea
parents:
10323
diff
changeset
|
677 |
|
a003c6a54cb6
8001536: Added readObject,writeObject,clone, equals, hashcode to SerialXLob
lancea
parents:
10323
diff
changeset
|
678 |
/** |
14781
701d0765f75f
8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents:
14337
diff
changeset
|
679 |
* Check to see if this object had previously had its {@code free} method |
701d0765f75f
8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents:
14337
diff
changeset
|
680 |
* called |
701d0765f75f
8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents:
14337
diff
changeset
|
681 |
* |
701d0765f75f
8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents:
14337
diff
changeset
|
682 |
* @throws SerialException |
701d0765f75f
8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents:
14337
diff
changeset
|
683 |
*/ |
701d0765f75f
8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents:
14337
diff
changeset
|
684 |
private void isValid() throws SerialException { |
701d0765f75f
8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents:
14337
diff
changeset
|
685 |
if (buf == null) { |
701d0765f75f
8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents:
14337
diff
changeset
|
686 |
throw new SerialException("Error: You cannot call a method on a " |
701d0765f75f
8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents:
14337
diff
changeset
|
687 |
+ "SerialClob instance once free() has been called."); |
701d0765f75f
8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents:
14337
diff
changeset
|
688 |
} |
701d0765f75f
8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents:
14337
diff
changeset
|
689 |
} |
701d0765f75f
8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents:
14337
diff
changeset
|
690 |
|
701d0765f75f
8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents:
14337
diff
changeset
|
691 |
/** |
701d0765f75f
8004357: Implement various methods in SerialBlob/Clob/Array and specify Thread Safety
lancea
parents:
14337
diff
changeset
|
692 |
* The identifier that assists in the serialization of this {@code SerialClob} |
2 | 693 |
* object. |
694 |
*/ |
|
695 |
static final long serialVersionUID = -1662519690087375313L; |
|
696 |
} |