annotate src/main/java/nl/cwi/monetdb/jdbc/MonetClob.java @ 316:d479475888e3

Replace StringBuilder methods sb.delete(0, sb.length()) with faster sb.setLength(0). In MonetBlob create(hexString) optimized the conversion by eliminating the creation of many 2 char substrings. Small enhancements and optimizations and added/updated comments.
author Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
date Thu, 29 Aug 2019 20:22:10 +0200 (2019-08-29)
parents 003ae6d881db
children ca6a4b02d418
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
1 /*
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
2 * This Source Code Form is subject to the terms of the Mozilla Public
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
5 *
261
d4baf8a4b43a Update Copyright year to 2019
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 209
diff changeset
6 * Copyright 1997 - July 2008 CWI, August 2008 - 2019 MonetDB B.V.
0
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
7 */
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
8
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
9 package nl.cwi.monetdb.jdbc;
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
10
69
e092fa8d9ab7 Expand import java.*.* statements
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 0
diff changeset
11 import java.io.InputStream;
e092fa8d9ab7 Expand import java.*.* statements
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 0
diff changeset
12 import java.io.Reader;
149
1e49fc74dba4 Implemented methods getCharacterStream() and getCharacterStream(long pos, long length) in class MonetClob.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 147
diff changeset
13 import java.io.StringReader;
69
e092fa8d9ab7 Expand import java.*.* statements
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 0
diff changeset
14 import java.sql.Clob;
e092fa8d9ab7 Expand import java.*.* statements
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 0
diff changeset
15 import java.sql.SQLException;
266
eefa7f625673 Resolve javadoc errors:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 262
diff changeset
16 import java.sql.SQLFeatureNotSupportedException;
0
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
17
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
18 /**
209
94131372ad0b Improved implementation of MonetClob and MonetBlob classes by adding checks on validity of input parameters of methods of those classes.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 200
diff changeset
19 * The MonetClob class implements the {@link java.sql.Clob} interface.
94131372ad0b Improved implementation of MonetClob and MonetBlob classes by adding checks on validity of input parameters of methods of those classes.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 200
diff changeset
20 *
94131372ad0b Improved implementation of MonetClob and MonetBlob classes by adding checks on validity of input parameters of methods of those classes.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 200
diff changeset
21 * Because MonetDB/SQL currently has no support for streams, this class is a
0
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
22 * shallow wrapper of a {@link StringBuilder}. It is more or less supplied to
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
23 * enable an application that depends on it to run. It may be obvious
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
24 * that it is a real resource expensive workaround that contradicts the
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
25 * sole reason for a Clob: avoidance of huge resource consumption.
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
26 * <b>Use of this class is highly discouraged.</b>
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
27 *
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
28 * @author Fabian Groffen
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
29 */
209
94131372ad0b Improved implementation of MonetClob and MonetBlob classes by adding checks on validity of input parameters of methods of those classes.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 200
diff changeset
30 public final class MonetClob implements Clob {
0
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
31 private StringBuilder buf;
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
32
295
003ae6d881db Add "final" keyword to method arguments and local variables where possible.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 289
diff changeset
33 protected MonetClob(final String in) {
0
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
34 buf = new StringBuilder(in);
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
35 }
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
36
147
ad0fe5b04fd4 Improve MonetClob implementatin.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 90
diff changeset
37 /* internal utility method */
316
d479475888e3 Replace StringBuilder methods sb.delete(0, sb.length()) with faster sb.setLength(0).
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 295
diff changeset
38 private final void checkBufIsNotNull() throws SQLException {
147
ad0fe5b04fd4 Improve MonetClob implementatin.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 90
diff changeset
39 if (buf == null)
149
1e49fc74dba4 Implemented methods getCharacterStream() and getCharacterStream(long pos, long length) in class MonetClob.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 147
diff changeset
40 throw new SQLException("This MonetClob has been freed", "M1M20");
147
ad0fe5b04fd4 Improve MonetClob implementatin.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 90
diff changeset
41 }
ad0fe5b04fd4 Improve MonetClob implementatin.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 90
diff changeset
42
0
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
43 //== begin interface Clob
147
ad0fe5b04fd4 Improve MonetClob implementatin.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 90
diff changeset
44
0
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
45 /**
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
46 * This method frees the Clob object and releases the resources the
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
47 * resources that it holds. The object is invalid once the free
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
48 * method is called.
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
49 *
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
50 * After free has been called, any attempt to invoke a method other
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
51 * than free will result in a SQLException being thrown. If free is
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
52 * called multiple times, the subsequent calls to free are treated
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
53 * as a no-op.
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
54 */
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
55 @Override
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
56 public void free() {
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
57 buf = null;
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
58 }
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
59
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
60 /**
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
61 * Retrieves the CLOB value designated by this Clob object as an
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
62 * ascii stream.
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
63 *
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
64 * @return a java.io.InputStream object containing the CLOB data
209
94131372ad0b Improved implementation of MonetClob and MonetBlob classes by adding checks on validity of input parameters of methods of those classes.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 200
diff changeset
65 * @throws SQLException - if there is an error accessing the CLOB value
0
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
66 */
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
67 @Override
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
68 public InputStream getAsciiStream() throws SQLException {
289
cce8a1803f68 Implemented method MonetClob.getAsciiStream()
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 266
diff changeset
69 checkBufIsNotNull();
295
003ae6d881db Add "final" keyword to method arguments and local variables where possible.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 289
diff changeset
70 return new java.io.ByteArrayInputStream(buf.toString().getBytes());
0
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
71 }
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
72
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
73 /**
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
74 * Retrieves the CLOB value designated by this Clob object as a
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
75 * java.io.Reader object (or as a stream of characters).
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
76 *
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
77 * @return a java.io.Reader object containing the CLOB data
209
94131372ad0b Improved implementation of MonetClob and MonetBlob classes by adding checks on validity of input parameters of methods of those classes.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 200
diff changeset
78 * @throws SQLException - if there is an error accessing the CLOB value
0
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
79 */
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
80 @Override
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
81 public Reader getCharacterStream() throws SQLException {
149
1e49fc74dba4 Implemented methods getCharacterStream() and getCharacterStream(long pos, long length) in class MonetClob.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 147
diff changeset
82 checkBufIsNotNull();
1e49fc74dba4 Implemented methods getCharacterStream() and getCharacterStream(long pos, long length) in class MonetClob.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 147
diff changeset
83 return new StringReader(buf.toString());
0
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
84 }
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
85
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
86 /**
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
87 * Returns a Reader object that contains a partial Clob value,
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
88 * starting with the character specified by pos, which is length
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
89 * characters in length.
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
90 *
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
91 * @param pos the offset to the first character of the partial value
289
cce8a1803f68 Implemented method MonetClob.getAsciiStream()
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 266
diff changeset
92 * to be retrieved. The first character in the Clob is at position 1.
cce8a1803f68 Implemented method MonetClob.getAsciiStream()
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 266
diff changeset
93 * @param length the length in characters of the partial value to be retrieved.
0
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
94 * @return Reader through which the partial Clob value can be read.
209
94131372ad0b Improved implementation of MonetClob and MonetBlob classes by adding checks on validity of input parameters of methods of those classes.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 200
diff changeset
95 * @throws SQLException - if pos is less than 1
94131372ad0b Improved implementation of MonetClob and MonetBlob classes by adding checks on validity of input parameters of methods of those classes.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 200
diff changeset
96 * or if pos is greater than the number of characters in the Clob
94131372ad0b Improved implementation of MonetClob and MonetBlob classes by adding checks on validity of input parameters of methods of those classes.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 200
diff changeset
97 * or if pos + length is greater than the number of characters in the Clob
0
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
98 */
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
99 @Override
295
003ae6d881db Add "final" keyword to method arguments and local variables where possible.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 289
diff changeset
100 public Reader getCharacterStream(final long pos, final long length) throws SQLException {
316
d479475888e3 Replace StringBuilder methods sb.delete(0, sb.length()) with faster sb.setLength(0).
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 295
diff changeset
101 // as length will be casted to int, check it for too big value first
289
cce8a1803f68 Implemented method MonetClob.getAsciiStream()
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 266
diff changeset
102 if (length < 0 || length > Integer.MAX_VALUE) {
209
94131372ad0b Improved implementation of MonetClob and MonetBlob classes by adding checks on validity of input parameters of methods of those classes.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 200
diff changeset
103 throw new SQLException("Invalid length value: " + length, "M1M05");
94131372ad0b Improved implementation of MonetClob and MonetBlob classes by adding checks on validity of input parameters of methods of those classes.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 200
diff changeset
104 }
316
d479475888e3 Replace StringBuilder methods sb.delete(0, sb.length()) with faster sb.setLength(0).
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 295
diff changeset
105 // buf and input argument pos will be checked in method getSubString(long, int)
149
1e49fc74dba4 Implemented methods getCharacterStream() and getCharacterStream(long pos, long length) in class MonetClob.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 147
diff changeset
106 return new StringReader(getSubString(pos, (int)length));
0
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
107 }
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
108
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
109 /**
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
110 * Retrieves a copy of the specified substring in the CLOB value
295
003ae6d881db Add "final" keyword to method arguments and local variables where possible.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 289
diff changeset
111 * designated by this Clob object. The substring begins at
0
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
112 * position pos and has up to length consecutive characters.
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
113 *
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
114 * @param pos the first character of the substring to be
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
115 * extracted. The first character is at position 1.
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
116 * @param length the number of consecutive characters to be copied
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
117 * @return a String that is the specified substring in the
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
118 * CLOB value designated by this Clob object
209
94131372ad0b Improved implementation of MonetClob and MonetBlob classes by adding checks on validity of input parameters of methods of those classes.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 200
diff changeset
119 * @throws SQLException - if pos is less than 1
94131372ad0b Improved implementation of MonetClob and MonetBlob classes by adding checks on validity of input parameters of methods of those classes.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 200
diff changeset
120 * or if pos is greater than the number of characters in the Clob
94131372ad0b Improved implementation of MonetClob and MonetBlob classes by adding checks on validity of input parameters of methods of those classes.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 200
diff changeset
121 * or if pos + length is greater than the number of characters in the Clob
94131372ad0b Improved implementation of MonetClob and MonetBlob classes by adding checks on validity of input parameters of methods of those classes.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 200
diff changeset
122 * @throws SQLException - if there is an error accessing the CLOB value
0
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
123 */
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
124 @Override
295
003ae6d881db Add "final" keyword to method arguments and local variables where possible.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 289
diff changeset
125 public String getSubString(final long pos, final int length) throws SQLException {
147
ad0fe5b04fd4 Improve MonetClob implementatin.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 90
diff changeset
126 checkBufIsNotNull();
209
94131372ad0b Improved implementation of MonetClob and MonetBlob classes by adding checks on validity of input parameters of methods of those classes.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 200
diff changeset
127 if (pos < 1 || pos > buf.length()) {
94131372ad0b Improved implementation of MonetClob and MonetBlob classes by adding checks on validity of input parameters of methods of those classes.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 200
diff changeset
128 throw new SQLException("Invalid pos value: " + pos, "M1M05");
94131372ad0b Improved implementation of MonetClob and MonetBlob classes by adding checks on validity of input parameters of methods of those classes.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 200
diff changeset
129 }
94131372ad0b Improved implementation of MonetClob and MonetBlob classes by adding checks on validity of input parameters of methods of those classes.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 200
diff changeset
130 if (length < 0 || pos -1 + length > buf.length()) {
94131372ad0b Improved implementation of MonetClob and MonetBlob classes by adding checks on validity of input parameters of methods of those classes.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 200
diff changeset
131 throw new SQLException("Invalid length value: " + length, "M1M05");
94131372ad0b Improved implementation of MonetClob and MonetBlob classes by adding checks on validity of input parameters of methods of those classes.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 200
diff changeset
132 }
0
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
133 try {
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
134 return buf.substring((int)(pos - 1), (int)(pos - 1 + length));
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
135 } catch (IndexOutOfBoundsException e) {
209
94131372ad0b Improved implementation of MonetClob and MonetBlob classes by adding checks on validity of input parameters of methods of those classes.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 200
diff changeset
136 throw new SQLException(e.getMessage(), "M1M05");
0
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
137 }
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
138 }
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
139
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
140 /**
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
141 * Retrieves the number of characters in the CLOB value designated
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
142 * by this Clob object.
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
143 *
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
144 * @return length of the CLOB in characters
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
145 * @throws SQLException if there is an error accessing the length
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
146 * of the CLOB value
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
147 */
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
148 @Override
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
149 public long length() throws SQLException {
147
ad0fe5b04fd4 Improve MonetClob implementatin.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 90
diff changeset
150 checkBufIsNotNull();
0
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
151 return (long)buf.length();
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
152 }
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
153
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
154 /**
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
155 * Retrieves the character position at which the specified Clob
295
003ae6d881db Add "final" keyword to method arguments and local variables where possible.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 289
diff changeset
156 * object searchstr appears in this Clob object. The search
0
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
157 * begins at position start.
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
158 *
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
159 * @param searchstr the Clob object for which to search
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
160 * @param start the position at which to begin searching;
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
161 * the first position is 1
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
162 * @return the position at which the Clob object appears or
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
163 * -1 if it is not present; the first position is 1
209
94131372ad0b Improved implementation of MonetClob and MonetBlob classes by adding checks on validity of input parameters of methods of those classes.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 200
diff changeset
164 * @throws SQLException - if there is an error accessing the CLOB value
0
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
165 */
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
166 @Override
295
003ae6d881db Add "final" keyword to method arguments and local variables where possible.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 289
diff changeset
167 public long position(final Clob searchstr, final long start) throws SQLException {
209
94131372ad0b Improved implementation of MonetClob and MonetBlob classes by adding checks on validity of input parameters of methods of those classes.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 200
diff changeset
168 if (searchstr == null) {
94131372ad0b Improved implementation of MonetClob and MonetBlob classes by adding checks on validity of input parameters of methods of those classes.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 200
diff changeset
169 throw new SQLException("Missing searchstr object", "M1M05");
94131372ad0b Improved implementation of MonetClob and MonetBlob classes by adding checks on validity of input parameters of methods of those classes.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 200
diff changeset
170 }
316
d479475888e3 Replace StringBuilder methods sb.delete(0, sb.length()) with faster sb.setLength(0).
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 295
diff changeset
171 // buf and input argument start will be checked in method position(String, long)
209
94131372ad0b Improved implementation of MonetClob and MonetBlob classes by adding checks on validity of input parameters of methods of those classes.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 200
diff changeset
172 return position(searchstr.toString(), start);
0
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
173 }
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
174
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
175 /**
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
176 * Retrieves the character position at which the specified
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
177 * substring searchstr appears in the SQL CLOB value represented
295
003ae6d881db Add "final" keyword to method arguments and local variables where possible.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 289
diff changeset
178 * by this Clob object. The search begins at position start.
0
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
179 *
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
180 * @param searchstr the substring for which to search
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
181 * @param start the position at which to begin searching;
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
182 * the first position is 1
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
183 * @return the position at which the substring appears or
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
184 * -1 if it is not present; the first position is 1
209
94131372ad0b Improved implementation of MonetClob and MonetBlob classes by adding checks on validity of input parameters of methods of those classes.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 200
diff changeset
185 * @throws SQLException - if there is an error accessing the CLOB value
0
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
186 */
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
187 @Override
295
003ae6d881db Add "final" keyword to method arguments and local variables where possible.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 289
diff changeset
188 public long position(final String searchstr, final long start) throws SQLException {
147
ad0fe5b04fd4 Improve MonetClob implementatin.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 90
diff changeset
189 checkBufIsNotNull();
209
94131372ad0b Improved implementation of MonetClob and MonetBlob classes by adding checks on validity of input parameters of methods of those classes.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 200
diff changeset
190 if (searchstr == null) {
94131372ad0b Improved implementation of MonetClob and MonetBlob classes by adding checks on validity of input parameters of methods of those classes.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 200
diff changeset
191 throw new SQLException("Missing searchstr object", "M1M05");
94131372ad0b Improved implementation of MonetClob and MonetBlob classes by adding checks on validity of input parameters of methods of those classes.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 200
diff changeset
192 }
94131372ad0b Improved implementation of MonetClob and MonetBlob classes by adding checks on validity of input parameters of methods of those classes.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 200
diff changeset
193 if (start < 1 || start > buf.length()) {
94131372ad0b Improved implementation of MonetClob and MonetBlob classes by adding checks on validity of input parameters of methods of those classes.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 200
diff changeset
194 throw new SQLException("Invalid start value: " + start, "M1M05");
94131372ad0b Improved implementation of MonetClob and MonetBlob classes by adding checks on validity of input parameters of methods of those classes.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 200
diff changeset
195 }
0
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
196 return (long)(buf.indexOf(searchstr, (int)(start - 1)));
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
197 }
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
198
209
94131372ad0b Improved implementation of MonetClob and MonetBlob classes by adding checks on validity of input parameters of methods of those classes.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 200
diff changeset
199 /**
94131372ad0b Improved implementation of MonetClob and MonetBlob classes by adding checks on validity of input parameters of methods of those classes.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 200
diff changeset
200 * Retrieves a stream to be used to write Ascii characters to the CLOB value that this
94131372ad0b Improved implementation of MonetClob and MonetBlob classes by adding checks on validity of input parameters of methods of those classes.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 200
diff changeset
201 * Clob object represents, starting at position pos. Characters written to the stream
94131372ad0b Improved implementation of MonetClob and MonetBlob classes by adding checks on validity of input parameters of methods of those classes.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 200
diff changeset
202 * will overwrite the existing characters in the Clob object starting at the position pos.
94131372ad0b Improved implementation of MonetClob and MonetBlob classes by adding checks on validity of input parameters of methods of those classes.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 200
diff changeset
203 * If the end of the Clob value is reached while writing characters to the stream,
94131372ad0b Improved implementation of MonetClob and MonetBlob classes by adding checks on validity of input parameters of methods of those classes.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 200
diff changeset
204 * then the length of the Clob value will be increased to accomodate the extra characters.
94131372ad0b Improved implementation of MonetClob and MonetBlob classes by adding checks on validity of input parameters of methods of those classes.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 200
diff changeset
205 *
94131372ad0b Improved implementation of MonetClob and MonetBlob classes by adding checks on validity of input parameters of methods of those classes.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 200
diff changeset
206 * Note: If the value specified for pos is greater then the length+1 of the CLOB value
94131372ad0b Improved implementation of MonetClob and MonetBlob classes by adding checks on validity of input parameters of methods of those classes.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 200
diff changeset
207 * then the behavior is undefined. Some JDBC drivers may throw a SQLException while
94131372ad0b Improved implementation of MonetClob and MonetBlob classes by adding checks on validity of input parameters of methods of those classes.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 200
diff changeset
208 * other drivers may support this operation.
94131372ad0b Improved implementation of MonetClob and MonetBlob classes by adding checks on validity of input parameters of methods of those classes.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 200
diff changeset
209 *
94131372ad0b Improved implementation of MonetClob and MonetBlob classes by adding checks on validity of input parameters of methods of those classes.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 200
diff changeset
210 * @param pos - the position at which to start writing to this CLOB object; The first position is 1
94131372ad0b Improved implementation of MonetClob and MonetBlob classes by adding checks on validity of input parameters of methods of those classes.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 200
diff changeset
211 * @return the stream to which ASCII encoded characters can be written
94131372ad0b Improved implementation of MonetClob and MonetBlob classes by adding checks on validity of input parameters of methods of those classes.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 200
diff changeset
212 * @throws SQLException - if there is an error accessing the CLOB value or if pos is less than 1
94131372ad0b Improved implementation of MonetClob and MonetBlob classes by adding checks on validity of input parameters of methods of those classes.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 200
diff changeset
213 * @throws SQLFeatureNotSupportedException - if the JDBC driver does not support this method
94131372ad0b Improved implementation of MonetClob and MonetBlob classes by adding checks on validity of input parameters of methods of those classes.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 200
diff changeset
214 */
0
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
215 @Override
295
003ae6d881db Add "final" keyword to method arguments and local variables where possible.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 289
diff changeset
216 public java.io.OutputStream setAsciiStream(final long pos) throws SQLException {
262
2d62ca1f758b Moved utility method newSQLFeatureNotSupportedException(String name) from MonetPreparedStatement.java and MonetResultSet.java
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 261
diff changeset
217 throw MonetWrapper.newSQLFeatureNotSupportedException("setAsciiStream");
0
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
218 }
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
219
209
94131372ad0b Improved implementation of MonetClob and MonetBlob classes by adding checks on validity of input parameters of methods of those classes.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 200
diff changeset
220 /**
94131372ad0b Improved implementation of MonetClob and MonetBlob classes by adding checks on validity of input parameters of methods of those classes.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 200
diff changeset
221 * Retrieves a stream to be used to write a stream of Unicode characters to the CLOB value that
94131372ad0b Improved implementation of MonetClob and MonetBlob classes by adding checks on validity of input parameters of methods of those classes.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 200
diff changeset
222 * this Clob object represents, starting at position pos. Characters written to the stream
94131372ad0b Improved implementation of MonetClob and MonetBlob classes by adding checks on validity of input parameters of methods of those classes.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 200
diff changeset
223 * will overwrite the existing characters in the Clob object starting at the position pos.
94131372ad0b Improved implementation of MonetClob and MonetBlob classes by adding checks on validity of input parameters of methods of those classes.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 200
diff changeset
224 * If the end of the Clob value is reached while writing characters to the stream,
94131372ad0b Improved implementation of MonetClob and MonetBlob classes by adding checks on validity of input parameters of methods of those classes.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 200
diff changeset
225 * then the length of the Clob value will be increased to accomodate the extra characters.
94131372ad0b Improved implementation of MonetClob and MonetBlob classes by adding checks on validity of input parameters of methods of those classes.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 200
diff changeset
226 *
94131372ad0b Improved implementation of MonetClob and MonetBlob classes by adding checks on validity of input parameters of methods of those classes.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 200
diff changeset
227 * Note: If the value specified for pos is greater then the length+1 of the CLOB value
94131372ad0b Improved implementation of MonetClob and MonetBlob classes by adding checks on validity of input parameters of methods of those classes.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 200
diff changeset
228 * then the behavior is undefined. Some JDBC drivers may throw a SQLException while
94131372ad0b Improved implementation of MonetClob and MonetBlob classes by adding checks on validity of input parameters of methods of those classes.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 200
diff changeset
229 * other drivers may support this operation.
94131372ad0b Improved implementation of MonetClob and MonetBlob classes by adding checks on validity of input parameters of methods of those classes.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 200
diff changeset
230 *
94131372ad0b Improved implementation of MonetClob and MonetBlob classes by adding checks on validity of input parameters of methods of those classes.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 200
diff changeset
231 * @param pos - the position at which to start writing to this CLOB object; The first position is 1
94131372ad0b Improved implementation of MonetClob and MonetBlob classes by adding checks on validity of input parameters of methods of those classes.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 200
diff changeset
232 * @return the stream to which Unicode encoded characters can be written
94131372ad0b Improved implementation of MonetClob and MonetBlob classes by adding checks on validity of input parameters of methods of those classes.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 200
diff changeset
233 * @throws SQLException - if there is an error accessing the CLOB value or if pos is less than 1
94131372ad0b Improved implementation of MonetClob and MonetBlob classes by adding checks on validity of input parameters of methods of those classes.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 200
diff changeset
234 * @throws SQLFeatureNotSupportedException - if the JDBC driver does not support this method
94131372ad0b Improved implementation of MonetClob and MonetBlob classes by adding checks on validity of input parameters of methods of those classes.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 200
diff changeset
235 */
0
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
236 @Override
295
003ae6d881db Add "final" keyword to method arguments and local variables where possible.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 289
diff changeset
237 public java.io.Writer setCharacterStream(final long pos) throws SQLException {
262
2d62ca1f758b Moved utility method newSQLFeatureNotSupportedException(String name) from MonetPreparedStatement.java and MonetResultSet.java
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 261
diff changeset
238 throw MonetWrapper.newSQLFeatureNotSupportedException("setCharacterStream");
0
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
239 }
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
240
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
241 /**
209
94131372ad0b Improved implementation of MonetClob and MonetBlob classes by adding checks on validity of input parameters of methods of those classes.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 200
diff changeset
242 * Writes the given Java String to the CLOB value that this Clob object designates at the position pos.
94131372ad0b Improved implementation of MonetClob and MonetBlob classes by adding checks on validity of input parameters of methods of those classes.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 200
diff changeset
243 * The string will overwrite the existing characters in the Clob object starting at the position pos.
289
cce8a1803f68 Implemented method MonetClob.getAsciiStream()
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 266
diff changeset
244 * If the end of the Clob value is reached while writing the given string,
cce8a1803f68 Implemented method MonetClob.getAsciiStream()
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 266
diff changeset
245 * then the length of the Clob value will be increased to accomodate the extra characters.
0
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
246 *
289
cce8a1803f68 Implemented method MonetClob.getAsciiStream()
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 266
diff changeset
247 * @param pos the position at which to start writing to the CLOB value that this Clob object represents
cce8a1803f68 Implemented method MonetClob.getAsciiStream()
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 266
diff changeset
248 * @param str the string to be written to the CLOB value that this Clob designates
0
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
249 * @return the number of characters written
289
cce8a1803f68 Implemented method MonetClob.getAsciiStream()
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 266
diff changeset
250 * @throws SQLException if there is an error accessing the CLOB value or if pos is less than 1
0
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
251 */
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
252 @Override
295
003ae6d881db Add "final" keyword to method arguments and local variables where possible.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 289
diff changeset
253 public int setString(final long pos, final String str) throws SQLException {
316
d479475888e3 Replace StringBuilder methods sb.delete(0, sb.length()) with faster sb.setLength(0).
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 295
diff changeset
254 // buf and input arguments will be checked in method setString(long, String, int, int)
d479475888e3 Replace StringBuilder methods sb.delete(0, sb.length()) with faster sb.setLength(0).
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 295
diff changeset
255 final int len = (str != null) ? str.length() : 0;
d479475888e3 Replace StringBuilder methods sb.delete(0, sb.length()) with faster sb.setLength(0).
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 295
diff changeset
256 return setString(pos, str, 0, len);
0
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
257 }
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
258
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
259 /**
209
94131372ad0b Improved implementation of MonetClob and MonetBlob classes by adding checks on validity of input parameters of methods of those classes.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 200
diff changeset
260 * Writes len characters of str, starting at character offset, to the CLOB value that this Clob represents.
94131372ad0b Improved implementation of MonetClob and MonetBlob classes by adding checks on validity of input parameters of methods of those classes.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 200
diff changeset
261 * The string will overwrite the existing characters in the Clob object starting at the position pos.
289
cce8a1803f68 Implemented method MonetClob.getAsciiStream()
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 266
diff changeset
262 * If the end of the Clob value is reached while writing the given string,
cce8a1803f68 Implemented method MonetClob.getAsciiStream()
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 266
diff changeset
263 * then the length of the Clob value will be increased to accomodate the extra characters.
0
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
264 *
289
cce8a1803f68 Implemented method MonetClob.getAsciiStream()
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 266
diff changeset
265 * @param pos the position at which to start writing to this CLOB object
cce8a1803f68 Implemented method MonetClob.getAsciiStream()
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 266
diff changeset
266 * @param str the string to be written to the CLOB value that this Clob object represents
cce8a1803f68 Implemented method MonetClob.getAsciiStream()
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 266
diff changeset
267 * @param offset the offset into str to start reading the characters to be written
0
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
268 * @param len the number of characters to be written
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
269 * @return the number of characters written
289
cce8a1803f68 Implemented method MonetClob.getAsciiStream()
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 266
diff changeset
270 * @throws SQLException if there is an error accessing the CLOB value or if pos is less than 1
0
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
271 */
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
272 @Override
295
003ae6d881db Add "final" keyword to method arguments and local variables where possible.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 289
diff changeset
273 public int setString(final long pos, final String str, final int offset, final int len)
0
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
274 throws SQLException
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
275 {
147
ad0fe5b04fd4 Improve MonetClob implementatin.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 90
diff changeset
276 checkBufIsNotNull();
209
94131372ad0b Improved implementation of MonetClob and MonetBlob classes by adding checks on validity of input parameters of methods of those classes.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 200
diff changeset
277 if (str == null) {
94131372ad0b Improved implementation of MonetClob and MonetBlob classes by adding checks on validity of input parameters of methods of those classes.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 200
diff changeset
278 throw new SQLException("Missing str object", "M1M05");
94131372ad0b Improved implementation of MonetClob and MonetBlob classes by adding checks on validity of input parameters of methods of those classes.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 200
diff changeset
279 }
94131372ad0b Improved implementation of MonetClob and MonetBlob classes by adding checks on validity of input parameters of methods of those classes.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 200
diff changeset
280 if (pos < 1 || pos > Integer.MAX_VALUE) {
94131372ad0b Improved implementation of MonetClob and MonetBlob classes by adding checks on validity of input parameters of methods of those classes.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 200
diff changeset
281 throw new SQLException("Invalid pos value: " + pos, "M1M05");
94131372ad0b Improved implementation of MonetClob and MonetBlob classes by adding checks on validity of input parameters of methods of those classes.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 200
diff changeset
282 }
94131372ad0b Improved implementation of MonetClob and MonetBlob classes by adding checks on validity of input parameters of methods of those classes.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 200
diff changeset
283 if (offset < 0 || offset > str.length()) {
94131372ad0b Improved implementation of MonetClob and MonetBlob classes by adding checks on validity of input parameters of methods of those classes.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 200
diff changeset
284 throw new SQLException("Invalid offset value: " + offset, "M1M05");
94131372ad0b Improved implementation of MonetClob and MonetBlob classes by adding checks on validity of input parameters of methods of those classes.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 200
diff changeset
285 }
94131372ad0b Improved implementation of MonetClob and MonetBlob classes by adding checks on validity of input parameters of methods of those classes.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 200
diff changeset
286 if (len < 1 || (offset + len) > str.length()) {
94131372ad0b Improved implementation of MonetClob and MonetBlob classes by adding checks on validity of input parameters of methods of those classes.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 200
diff changeset
287 throw new SQLException("Invalid len value: " + len, "M1M05");
94131372ad0b Improved implementation of MonetClob and MonetBlob classes by adding checks on validity of input parameters of methods of those classes.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 200
diff changeset
288 }
316
d479475888e3 Replace StringBuilder methods sb.delete(0, sb.length()) with faster sb.setLength(0).
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 295
diff changeset
289 if (((int) pos + len) > buf.capacity()) {
d479475888e3 Replace StringBuilder methods sb.delete(0, sb.length()) with faster sb.setLength(0).
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 295
diff changeset
290 // enlarge the buffer before filling it
d479475888e3 Replace StringBuilder methods sb.delete(0, sb.length()) with faster sb.setLength(0).
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 295
diff changeset
291 buf.ensureCapacity((int) pos + len);
0
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
292 }
316
d479475888e3 Replace StringBuilder methods sb.delete(0, sb.length()) with faster sb.setLength(0).
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 295
diff changeset
293 buf.replace((int) pos - 1, (int) pos + len, str.substring(offset, (offset + len)));
209
94131372ad0b Improved implementation of MonetClob and MonetBlob classes by adding checks on validity of input parameters of methods of those classes.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 200
diff changeset
294 return len;
0
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
295 }
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
296
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
297 /**
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
298 * Truncates the CLOB value that this Clob designates to
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
299 * have a length of len characters.
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
300 *
289
cce8a1803f68 Implemented method MonetClob.getAsciiStream()
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 266
diff changeset
301 * @param len the length, in bytes, to which the CLOB value should be truncated
0
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
302 * @throws SQLException if there is an error accessing the
209
94131372ad0b Improved implementation of MonetClob and MonetBlob classes by adding checks on validity of input parameters of methods of those classes.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 200
diff changeset
303 * CLOB value or if len is less than 0
0
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
304 */
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
305 @Override
295
003ae6d881db Add "final" keyword to method arguments and local variables where possible.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 289
diff changeset
306 public void truncate(final long len) throws SQLException {
147
ad0fe5b04fd4 Improve MonetClob implementatin.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 90
diff changeset
307 checkBufIsNotNull();
209
94131372ad0b Improved implementation of MonetClob and MonetBlob classes by adding checks on validity of input parameters of methods of those classes.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 200
diff changeset
308 if (len < 0 || len > buf.length()) {
94131372ad0b Improved implementation of MonetClob and MonetBlob classes by adding checks on validity of input parameters of methods of those classes.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 200
diff changeset
309 throw new SQLException("Invalid len value: " + len, "M1M05");
94131372ad0b Improved implementation of MonetClob and MonetBlob classes by adding checks on validity of input parameters of methods of those classes.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 200
diff changeset
310 }
316
d479475888e3 Replace StringBuilder methods sb.delete(0, sb.length()) with faster sb.setLength(0).
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 295
diff changeset
311 buf.setLength((int)len);
d479475888e3 Replace StringBuilder methods sb.delete(0, sb.length()) with faster sb.setLength(0).
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 295
diff changeset
312 // reduce storage used for the character sequence.
289
cce8a1803f68 Implemented method MonetClob.getAsciiStream()
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 266
diff changeset
313 buf.trimToSize();
0
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
314 }
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
315
209
94131372ad0b Improved implementation of MonetClob and MonetBlob classes by adding checks on validity of input parameters of methods of those classes.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 200
diff changeset
316
0
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
317 /**
289
cce8a1803f68 Implemented method MonetClob.getAsciiStream()
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 266
diff changeset
318 * Returns a String from this MonetClob buf.
0
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
319 *
289
cce8a1803f68 Implemented method MonetClob.getAsciiStream()
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 266
diff changeset
320 * @return the String this MonetClob wraps or empty string when this MonetClob was freed.
0
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
321 */
316
d479475888e3 Replace StringBuilder methods sb.delete(0, sb.length()) with faster sb.setLength(0).
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 295
diff changeset
322 public String toString() {
d479475888e3 Replace StringBuilder methods sb.delete(0, sb.length()) with faster sb.setLength(0).
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 295
diff changeset
323 if (buf == null)
d479475888e3 Replace StringBuilder methods sb.delete(0, sb.length()) with faster sb.setLength(0).
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 295
diff changeset
324 return "";
d479475888e3 Replace StringBuilder methods sb.delete(0, sb.length()) with faster sb.setLength(0).
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 295
diff changeset
325 return buf.toString();
0
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
326 }
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
327 }