annotate src/main/java/nl/cwi/monetdb/jdbc/MonetClob.java @ 289:cce8a1803f68

Implemented method MonetClob.getAsciiStream() Also reduced double checkng of input parameters in getCharacterStream(long pos, long length)
author Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
date Wed, 31 Jul 2019 15:38:59 +0200 (2019-07-31)
parents eefa7f625673
children 003ae6d881db
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
289
cce8a1803f68 Implemented method MonetClob.getAsciiStream()
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 266
diff changeset
11 import java.io.ByteArrayInputStream;
69
e092fa8d9ab7 Expand import java.*.* statements
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 0
diff changeset
12 import java.io.InputStream;
e092fa8d9ab7 Expand import java.*.* statements
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 0
diff changeset
13 import java.io.OutputStream;
e092fa8d9ab7 Expand import java.*.* statements
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 0
diff changeset
14 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
15 import java.io.StringReader;
69
e092fa8d9ab7 Expand import java.*.* statements
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 0
diff changeset
16 import java.io.Writer;
e092fa8d9ab7 Expand import java.*.* statements
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 0
diff changeset
17 import java.sql.Clob;
e092fa8d9ab7 Expand import java.*.* statements
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 0
diff changeset
18 import java.sql.SQLException;
266
eefa7f625673 Resolve javadoc errors:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 262
diff changeset
19 import java.sql.SQLFeatureNotSupportedException;
0
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
20
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
21 /**
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
22 * 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
23 *
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
24 * 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
25 * 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
26 * 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
27 * 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
28 * 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
29 * <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
30 *
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
31 * @author Fabian Groffen
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
32 */
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
33 public final class MonetClob implements Clob {
147
ad0fe5b04fd4 Improve MonetClob implementatin.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 90
diff changeset
34
0
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
35 private StringBuilder buf;
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
36
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
37 protected MonetClob(String in) {
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
38 buf = new StringBuilder(in);
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
39 }
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
40
147
ad0fe5b04fd4 Improve MonetClob implementatin.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 90
diff changeset
41 /* internal utility method */
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
42 final private void checkBufIsNotNull() throws SQLException {
147
ad0fe5b04fd4 Improve MonetClob implementatin.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 90
diff changeset
43 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
44 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
45 }
ad0fe5b04fd4 Improve MonetClob implementatin.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 90
diff changeset
46
0
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
47 //== begin interface Clob
147
ad0fe5b04fd4 Improve MonetClob implementatin.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 90
diff changeset
48
0
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 * 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
51 * 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
52 * method is called.
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
53 *
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
54 * 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
55 * 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
56 * 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
57 * as a no-op.
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 @Override
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
60 public void free() {
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
61 buf = null;
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
62 }
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 /**
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
65 * 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
66 * ascii stream.
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
67 *
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
68 * @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
69 * @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
70 */
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
71 @Override
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
72 public InputStream getAsciiStream() throws SQLException {
289
cce8a1803f68 Implemented method MonetClob.getAsciiStream()
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 266
diff changeset
73 checkBufIsNotNull();
cce8a1803f68 Implemented method MonetClob.getAsciiStream()
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 266
diff changeset
74 return new ByteArrayInputStream(buf.toString().getBytes());
0
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
75 }
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 /**
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
78 * 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
79 * 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
80 *
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
81 * @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
82 * @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
83 */
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
84 @Override
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
85 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
86 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
87 return new StringReader(buf.toString());
0
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
88 }
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
89
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 * 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
92 * 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
93 * characters in length.
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
94 *
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
95 * @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
96 * 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
97 * @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
98 * @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
99 * @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
100 * 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
101 * 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
102 */
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
103 @Override
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
104 public Reader getCharacterStream(long pos, long length) throws SQLException {
289
cce8a1803f68 Implemented method MonetClob.getAsciiStream()
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 266
diff changeset
105 // buf and input argument pos will be checked in method getSubString(long, int)
cce8a1803f68 Implemented method MonetClob.getAsciiStream()
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 266
diff changeset
106 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
107 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
108 }
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
109 return new StringReader(getSubString(pos, (int)length));
0
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
110 }
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
111
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
112 /**
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
113 * Retrieves a copy of the specified substring in the CLOB value
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
114 * designated by this Clob object. The substring begins at
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
115 * 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
116 *
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
117 * @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
118 * extracted. The first character is at position 1.
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
119 * @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
120 * @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
121 * 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
122 * @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
123 * 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
124 * 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
125 * @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
126 */
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
127 @Override
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
128 public String getSubString(long pos, int length) throws SQLException {
147
ad0fe5b04fd4 Improve MonetClob implementatin.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 90
diff changeset
129 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
130 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
131 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
132 }
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
133 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
134 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
135 }
0
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
136 try {
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
137 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
138 } 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
139 throw new SQLException(e.getMessage(), "M1M05");
0
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 }
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
142
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 * 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
145 * by this Clob object.
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
146 *
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
147 * @return length of the CLOB in characters
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
148 * @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
149 * of the CLOB value
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
150 */
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
151 @Override
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
152 public long length() throws SQLException {
147
ad0fe5b04fd4 Improve MonetClob implementatin.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 90
diff changeset
153 checkBufIsNotNull();
0
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
154 return (long)buf.length();
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
155 }
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
156
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
157 /**
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
158 * Retrieves the character position at which the specified Clob
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
159 * object searchstr appears in this Clob object. The search
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
160 * begins at position start.
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
161 *
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
162 * @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
163 * @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
164 * the first position is 1
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
165 * @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
166 * -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
167 * @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
168 */
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
169 @Override
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
170 public long position(Clob searchstr, long start) throws SQLException {
289
cce8a1803f68 Implemented method MonetClob.getAsciiStream()
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 266
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 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
173 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
174 }
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
175 return position(searchstr.toString(), start);
0
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
176 }
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
177
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
178 /**
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
179 * Retrieves the character position at which the specified
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
180 * substring searchstr appears in the SQL CLOB value represented
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
181 * by this Clob object. The search begins at position start.
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
182 *
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
183 * @param searchstr the substring for which to search
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
184 * @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
185 * the first position is 1
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
186 * @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
187 * -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
188 * @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
189 */
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
190 @Override
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
191 public long position(String searchstr, long start) throws SQLException {
147
ad0fe5b04fd4 Improve MonetClob implementatin.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 90
diff changeset
192 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
193 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
194 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
195 }
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
196 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
197 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
198 }
0
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
199 return (long)(buf.indexOf(searchstr, (int)(start - 1)));
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
200 }
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
201
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
202 /**
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 * 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
204 * 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
205 * 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
206 * 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
207 * 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
208 *
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 * 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
210 * 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
211 * 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
212 *
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 * @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
214 * @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
215 * @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
216 * @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
217 */
0
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
218 @Override
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
219 public OutputStream setAsciiStream(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
220 throw MonetWrapper.newSQLFeatureNotSupportedException("setAsciiStream");
0
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
221 }
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
222
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
223 /**
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 * 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
225 * 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
226 * 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
227 * 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
228 * 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
229 *
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 * 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
231 * 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
232 * 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
233 *
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 * @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
235 * @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
236 * @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
237 * @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
238 */
0
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
239 @Override
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
240 public Writer setCharacterStream(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
241 throw MonetWrapper.newSQLFeatureNotSupportedException("setCharacterStream");
0
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
242 }
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
243
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
244 /**
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
245 * 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
246 * 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
247 * 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
248 * 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
249 *
289
cce8a1803f68 Implemented method MonetClob.getAsciiStream()
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 266
diff changeset
250 * @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
251 * @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
252 * @return the number of characters written
289
cce8a1803f68 Implemented method MonetClob.getAsciiStream()
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 266
diff changeset
253 * @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
254 */
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
255 @Override
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
256 public int setString(long pos, String str) throws SQLException {
289
cce8a1803f68 Implemented method MonetClob.getAsciiStream()
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 266
diff changeset
257 // buf will be checked in method setString(long, String, int, int)
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
258 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
259 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
260 }
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 return setString(pos, str, 0, str.length());
0
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
262 }
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
263
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
264 /**
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
265 * 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
266 * 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
267 * 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
268 * 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
269 *
289
cce8a1803f68 Implemented method MonetClob.getAsciiStream()
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 266
diff changeset
270 * @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
271 * @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
272 * @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
273 * @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
274 * @return the number of characters written
289
cce8a1803f68 Implemented method MonetClob.getAsciiStream()
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 266
diff changeset
275 * @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
276 */
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
277 @Override
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
278 public int setString(long pos, String str, int offset, int len)
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
279 throws SQLException
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
280 {
147
ad0fe5b04fd4 Improve MonetClob implementatin.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 90
diff changeset
281 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
282 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
283 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
284 }
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 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
286 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
287 }
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 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
289 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
290 }
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
291 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
292 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
293 }
0
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
294
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
295 int ipos = (int) 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
296 if ((ipos + len) > buf.capacity()) {
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
297 buf.ensureCapacity(ipos + len);
0
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
298 }
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
299 buf.replace(ipos - 1, ipos + len, str.substring(offset, (offset + len)));
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
300 return len;
0
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
301 }
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
302
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
303 /**
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
304 * 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
305 * have a length of len characters.
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
306 *
289
cce8a1803f68 Implemented method MonetClob.getAsciiStream()
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 266
diff changeset
307 * @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
308 * @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
309 * 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
310 */
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
311 @Override
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
312 public void truncate(long len) throws SQLException {
147
ad0fe5b04fd4 Improve MonetClob implementatin.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 90
diff changeset
313 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
314 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
315 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
316 }
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
317 buf.delete((int)len, buf.length());
289
cce8a1803f68 Implemented method MonetClob.getAsciiStream()
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 266
diff changeset
318 // Attempts to reduce storage used for the character sequence.
cce8a1803f68 Implemented method MonetClob.getAsciiStream()
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 266
diff changeset
319 buf.trimToSize();
0
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
320 }
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
321
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
322
0
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
323 /**
289
cce8a1803f68 Implemented method MonetClob.getAsciiStream()
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 266
diff changeset
324 * Returns a String from this MonetClob buf.
0
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
325 *
289
cce8a1803f68 Implemented method MonetClob.getAsciiStream()
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 266
diff changeset
326 * @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
327 */
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
328 public String toString() {
289
cce8a1803f68 Implemented method MonetClob.getAsciiStream()
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 266
diff changeset
329 return (buf != null) ? buf.toString() : "";
0
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
330 }
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
331 }