Mercurial > hg > monetdb-java
annotate src/main/java/nl/cwi/monetdb/jdbc/MonetBlob.java @ 102:08bc9009d190 embedded
Merged with default
author | Pedro Ferreira <pedro.ferreira@monetdbsolutions.com> |
---|---|
date | Fri, 13 Jan 2017 18:16:30 +0100 (2017-01-13) |
parents | 6f74e01c57da b9b35ca2eec2 |
children | 60063c67f9e7 |
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 * |
90
b9b35ca2eec2
Updated copyright year to 2017 in *.java files and MonetDriver.java.in and build.xml and version.sh
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
69
diff
changeset
|
6 * Copyright 1997 - July 2008 CWI, August 2008 - 2017 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.ByteArrayInputStream; |
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; |
102
08bc9009d190
Merged with default
Pedro Ferreira <pedro.ferreira@monetdbsolutions.com>
diff
changeset
|
14 import java.io.Serializable; |
69
e092fa8d9ab7
Expand import java.*.* statements
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
0
diff
changeset
|
15 import java.sql.Blob; |
e092fa8d9ab7
Expand import java.*.* statements
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
0
diff
changeset
|
16 import java.sql.SQLException; |
e092fa8d9ab7
Expand import java.*.* statements
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
0
diff
changeset
|
17 import java.sql.SQLFeatureNotSupportedException; |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
18 import java.util.Arrays; |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
19 |
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 * The MonetBlob class implements the {@link java.sql.Blob} interface. Because |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
22 * MonetDB/SQL currently has no support for streams, this class is a |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
23 * shallow wrapper of a byte[]. It is more or less supplied to |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
24 * 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
|
25 * 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
|
26 * benefits for a Blob: avoidance of huge resource consumption. |
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 */ |
68
86967be24645
Ready to start testing the old mapi connection. After passing the tests. The embedded integration will be very straightforward.
Pedro Ferreira <pedro.ferreira@monetdbsolutions.com>
parents:
66
diff
changeset
|
30 public class MonetBlob implements Blob, Serializable, Comparable<MonetBlob> { |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
31 |
68
86967be24645
Ready to start testing the old mapi connection. After passing the tests. The embedded integration will be very straightforward.
Pedro Ferreira <pedro.ferreira@monetdbsolutions.com>
parents:
66
diff
changeset
|
32 private byte[] buffer; |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
33 |
68
86967be24645
Ready to start testing the old mapi connection. After passing the tests. The embedded integration will be very straightforward.
Pedro Ferreira <pedro.ferreira@monetdbsolutions.com>
parents:
66
diff
changeset
|
34 public MonetBlob(byte[] buf) { |
86967be24645
Ready to start testing the old mapi connection. After passing the tests. The embedded integration will be very straightforward.
Pedro Ferreira <pedro.ferreira@monetdbsolutions.com>
parents:
66
diff
changeset
|
35 this.buffer = buf; |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
36 } |
66
7307caacc2d5
Intermediary commit. Cross-implementation interface (for mapi connection with the old protocol, mapi connection with the new protocol and the embedded connection) almost done. The mcl layer processing is more memory efficient now.
Pedro Ferreira <pedro.ferreira@monetdbsolutions.com>
parents:
63
diff
changeset
|
37 |
68
86967be24645
Ready to start testing the old mapi connection. After passing the tests. The embedded integration will be very straightforward.
Pedro Ferreira <pedro.ferreira@monetdbsolutions.com>
parents:
66
diff
changeset
|
38 public byte[] getBuffer() { |
86967be24645
Ready to start testing the old mapi connection. After passing the tests. The embedded integration will be very straightforward.
Pedro Ferreira <pedro.ferreira@monetdbsolutions.com>
parents:
66
diff
changeset
|
39 return buffer; |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
40 } |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
41 |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
42 //== begin interface Blob |
68
86967be24645
Ready to start testing the old mapi connection. After passing the tests. The embedded integration will be very straightforward.
Pedro Ferreira <pedro.ferreira@monetdbsolutions.com>
parents:
66
diff
changeset
|
43 |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
44 /** |
68
86967be24645
Ready to start testing the old mapi connection. After passing the tests. The embedded integration will be very straightforward.
Pedro Ferreira <pedro.ferreira@monetdbsolutions.com>
parents:
66
diff
changeset
|
45 * This method frees the Blob object and releases the resources that it holds. The object is invalid once the |
86967be24645
Ready to start testing the old mapi connection. After passing the tests. The embedded integration will be very straightforward.
Pedro Ferreira <pedro.ferreira@monetdbsolutions.com>
parents:
66
diff
changeset
|
46 * free method is called. |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
47 * |
68
86967be24645
Ready to start testing the old mapi connection. After passing the tests. The embedded integration will be very straightforward.
Pedro Ferreira <pedro.ferreira@monetdbsolutions.com>
parents:
66
diff
changeset
|
48 * After free has been called, any attempt to invoke a method other than free will result in a SQLException being |
86967be24645
Ready to start testing the old mapi connection. After passing the tests. The embedded integration will be very straightforward.
Pedro Ferreira <pedro.ferreira@monetdbsolutions.com>
parents:
66
diff
changeset
|
49 * thrown. If free is called multiple times, the subsequent calls to free are treated as a no-op. |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
50 */ |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
51 @Override |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
52 public void free() throws SQLException { |
68
86967be24645
Ready to start testing the old mapi connection. After passing the tests. The embedded integration will be very straightforward.
Pedro Ferreira <pedro.ferreira@monetdbsolutions.com>
parents:
66
diff
changeset
|
53 buffer = null; |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
54 } |
68
86967be24645
Ready to start testing the old mapi connection. After passing the tests. The embedded integration will be very straightforward.
Pedro Ferreira <pedro.ferreira@monetdbsolutions.com>
parents:
66
diff
changeset
|
55 |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
56 /** |
68
86967be24645
Ready to start testing the old mapi connection. After passing the tests. The embedded integration will be very straightforward.
Pedro Ferreira <pedro.ferreira@monetdbsolutions.com>
parents:
66
diff
changeset
|
57 * Retrieves the BLOB value designated by this Blob instance as a stream. |
0
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 * @return a stream containing the BLOB data |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
60 * @throws SQLException if there is an error accessing the BLOB value |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
61 */ |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
62 @Override |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
63 public InputStream getBinaryStream() throws SQLException { |
68
86967be24645
Ready to start testing the old mapi connection. After passing the tests. The embedded integration will be very straightforward.
Pedro Ferreira <pedro.ferreira@monetdbsolutions.com>
parents:
66
diff
changeset
|
64 if (buffer == null) |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
65 throw new SQLException("This Blob object has been freed", "M1M20"); |
68
86967be24645
Ready to start testing the old mapi connection. After passing the tests. The embedded integration will be very straightforward.
Pedro Ferreira <pedro.ferreira@monetdbsolutions.com>
parents:
66
diff
changeset
|
66 return new ByteArrayInputStream(buffer); |
0
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 |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
69 /** |
68
86967be24645
Ready to start testing the old mapi connection. After passing the tests. The embedded integration will be very straightforward.
Pedro Ferreira <pedro.ferreira@monetdbsolutions.com>
parents:
66
diff
changeset
|
70 * Returns an InputStream object that contains a partial Blob value, starting with the byte specified by pos, |
86967be24645
Ready to start testing the old mapi connection. After passing the tests. The embedded integration will be very straightforward.
Pedro Ferreira <pedro.ferreira@monetdbsolutions.com>
parents:
66
diff
changeset
|
71 * which is length bytes in length. |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
72 * |
68
86967be24645
Ready to start testing the old mapi connection. After passing the tests. The embedded integration will be very straightforward.
Pedro Ferreira <pedro.ferreira@monetdbsolutions.com>
parents:
66
diff
changeset
|
73 * @param pos the offset to the first byte of the partial value to be retrieved. The first byte in the Blob is at |
86967be24645
Ready to start testing the old mapi connection. After passing the tests. The embedded integration will be very straightforward.
Pedro Ferreira <pedro.ferreira@monetdbsolutions.com>
parents:
66
diff
changeset
|
74 * position 1 |
86967be24645
Ready to start testing the old mapi connection. After passing the tests. The embedded integration will be very straightforward.
Pedro Ferreira <pedro.ferreira@monetdbsolutions.com>
parents:
66
diff
changeset
|
75 * @param length the length in bytes of the partial value to be retrieved |
86967be24645
Ready to start testing the old mapi connection. After passing the tests. The embedded integration will be very straightforward.
Pedro Ferreira <pedro.ferreira@monetdbsolutions.com>
parents:
66
diff
changeset
|
76 * @return InputStream through which the partial Blob value can be read. |
86967be24645
Ready to start testing the old mapi connection. After passing the tests. The embedded integration will be very straightforward.
Pedro Ferreira <pedro.ferreira@monetdbsolutions.com>
parents:
66
diff
changeset
|
77 * @throws SQLException if pos is less than 1 or if pos is greater than the number of bytes in the Blob or if pos + |
86967be24645
Ready to start testing the old mapi connection. After passing the tests. The embedded integration will be very straightforward.
Pedro Ferreira <pedro.ferreira@monetdbsolutions.com>
parents:
66
diff
changeset
|
78 * length is greater than the number of bytes in the Blob |
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 |
66
7307caacc2d5
Intermediary commit. Cross-implementation interface (for mapi connection with the old protocol, mapi connection with the new protocol and the embedded connection) almost done. The mcl layer processing is more memory efficient now.
Pedro Ferreira <pedro.ferreira@monetdbsolutions.com>
parents:
63
diff
changeset
|
81 public InputStream getBinaryStream(long pos, long length) throws SQLException { |
68
86967be24645
Ready to start testing the old mapi connection. After passing the tests. The embedded integration will be very straightforward.
Pedro Ferreira <pedro.ferreira@monetdbsolutions.com>
parents:
66
diff
changeset
|
82 if (buffer == null) |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
83 throw new SQLException("This Blob object has been freed", "M1M20"); |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
84 if (pos < 1) |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
85 throw new SQLException("pos is less than 1", "M1M05"); |
68
86967be24645
Ready to start testing the old mapi connection. After passing the tests. The embedded integration will be very straightforward.
Pedro Ferreira <pedro.ferreira@monetdbsolutions.com>
parents:
66
diff
changeset
|
86 if (pos - 1 > buffer.length) |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
87 throw new SQLException("pos is greater than the number of bytes in the Blob", "M1M05"); |
68
86967be24645
Ready to start testing the old mapi connection. After passing the tests. The embedded integration will be very straightforward.
Pedro Ferreira <pedro.ferreira@monetdbsolutions.com>
parents:
66
diff
changeset
|
88 if (pos - 1 + length > buffer.length) |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
89 throw new SQLException("pos + length is greater than the number of bytes in the Blob", "M1M05"); |
68
86967be24645
Ready to start testing the old mapi connection. After passing the tests. The embedded integration will be very straightforward.
Pedro Ferreira <pedro.ferreira@monetdbsolutions.com>
parents:
66
diff
changeset
|
90 return new ByteArrayInputStream(buffer, (int)(pos - 1), (int)length); |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
91 } |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
92 |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
93 /** |
68
86967be24645
Ready to start testing the old mapi connection. After passing the tests. The embedded integration will be very straightforward.
Pedro Ferreira <pedro.ferreira@monetdbsolutions.com>
parents:
66
diff
changeset
|
94 * Retrieves all or part of the BLOB value that this Blob object represents, as an array of bytes. This byte array |
86967be24645
Ready to start testing the old mapi connection. After passing the tests. The embedded integration will be very straightforward.
Pedro Ferreira <pedro.ferreira@monetdbsolutions.com>
parents:
66
diff
changeset
|
95 * contains up to length consecutive bytes starting at position pos. |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
96 * |
68
86967be24645
Ready to start testing the old mapi connection. After passing the tests. The embedded integration will be very straightforward.
Pedro Ferreira <pedro.ferreira@monetdbsolutions.com>
parents:
66
diff
changeset
|
97 * @param pos the ordinal position of the first byte in the BLOB value to be extracted; the first byte is at |
86967be24645
Ready to start testing the old mapi connection. After passing the tests. The embedded integration will be very straightforward.
Pedro Ferreira <pedro.ferreira@monetdbsolutions.com>
parents:
66
diff
changeset
|
98 * position 1. |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
99 * @param length the number of consecutive bytes to be copied |
68
86967be24645
Ready to start testing the old mapi connection. After passing the tests. The embedded integration will be very straightforward.
Pedro Ferreira <pedro.ferreira@monetdbsolutions.com>
parents:
66
diff
changeset
|
100 * @return a byte array containing up to length consecutive bytes from the BLOB value designated by this Blob |
86967be24645
Ready to start testing the old mapi connection. After passing the tests. The embedded integration will be very straightforward.
Pedro Ferreira <pedro.ferreira@monetdbsolutions.com>
parents:
66
diff
changeset
|
101 * object, starting with the byte at position pos. |
86967be24645
Ready to start testing the old mapi connection. After passing the tests. The embedded integration will be very straightforward.
Pedro Ferreira <pedro.ferreira@monetdbsolutions.com>
parents:
66
diff
changeset
|
102 * @throws SQLException if there is an error accessing the BLOB value |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
103 */ |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
104 @Override |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
105 public byte[] getBytes(long pos, int length) throws SQLException { |
68
86967be24645
Ready to start testing the old mapi connection. After passing the tests. The embedded integration will be very straightforward.
Pedro Ferreira <pedro.ferreira@monetdbsolutions.com>
parents:
66
diff
changeset
|
106 if (buffer == null) |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
107 throw new SQLException("This Blob object has been freed", "M1M20"); |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
108 try { |
68
86967be24645
Ready to start testing the old mapi connection. After passing the tests. The embedded integration will be very straightforward.
Pedro Ferreira <pedro.ferreira@monetdbsolutions.com>
parents:
66
diff
changeset
|
109 return Arrays.copyOfRange(buffer, (int) pos - 1, (int) pos - 1 + length); |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
110 } catch (IndexOutOfBoundsException e) { |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
111 throw new SQLException(e.getMessage(), "M0M10"); |
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 } |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
114 |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
115 /** |
68
86967be24645
Ready to start testing the old mapi connection. After passing the tests. The embedded integration will be very straightforward.
Pedro Ferreira <pedro.ferreira@monetdbsolutions.com>
parents:
66
diff
changeset
|
116 * Returns the number of bytes in the BLOB value designated by this Blob object. |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
117 * |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
118 * @return length of the BLOB in bytes |
68
86967be24645
Ready to start testing the old mapi connection. After passing the tests. The embedded integration will be very straightforward.
Pedro Ferreira <pedro.ferreira@monetdbsolutions.com>
parents:
66
diff
changeset
|
119 * @throws SQLException if there is an error accessing the length of the BLOB value |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
120 */ |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
121 @Override |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
122 public long length() throws SQLException { |
68
86967be24645
Ready to start testing the old mapi connection. After passing the tests. The embedded integration will be very straightforward.
Pedro Ferreira <pedro.ferreira@monetdbsolutions.com>
parents:
66
diff
changeset
|
123 if (buffer == null) |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
124 throw new SQLException("This Blob object has been freed", "M1M20"); |
68
86967be24645
Ready to start testing the old mapi connection. After passing the tests. The embedded integration will be very straightforward.
Pedro Ferreira <pedro.ferreira@monetdbsolutions.com>
parents:
66
diff
changeset
|
125 return (long) buffer.length; |
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 |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
128 /** |
68
86967be24645
Ready to start testing the old mapi connection. After passing the tests. The embedded integration will be very straightforward.
Pedro Ferreira <pedro.ferreira@monetdbsolutions.com>
parents:
66
diff
changeset
|
129 * Retrieves the byte position in the BLOB value designated by this Blob object at which pattern begins. The search |
86967be24645
Ready to start testing the old mapi connection. After passing the tests. The embedded integration will be very straightforward.
Pedro Ferreira <pedro.ferreira@monetdbsolutions.com>
parents:
66
diff
changeset
|
130 * begins at position start. |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
131 * |
68
86967be24645
Ready to start testing the old mapi connection. After passing the tests. The embedded integration will be very straightforward.
Pedro Ferreira <pedro.ferreira@monetdbsolutions.com>
parents:
66
diff
changeset
|
132 * @param pattern the Blob object designating the BLOB value for which to search |
86967be24645
Ready to start testing the old mapi connection. After passing the tests. The embedded integration will be very straightforward.
Pedro Ferreira <pedro.ferreira@monetdbsolutions.com>
parents:
66
diff
changeset
|
133 * @param start the position in the BLOB value at which to begin searching; the first position is 1 |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
134 * @return the position at which the pattern begins, else -1 |
68
86967be24645
Ready to start testing the old mapi connection. After passing the tests. The embedded integration will be very straightforward.
Pedro Ferreira <pedro.ferreira@monetdbsolutions.com>
parents:
66
diff
changeset
|
135 * @throws SQLException if there is an error accessing the BLOB value |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
136 */ |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
137 @Override |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
138 public long position(Blob pattern, long start) throws SQLException { |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
139 return position(pattern.getBytes(1L, (int)pattern.length()), start); |
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 /** |
68
86967be24645
Ready to start testing the old mapi connection. After passing the tests. The embedded integration will be very straightforward.
Pedro Ferreira <pedro.ferreira@monetdbsolutions.com>
parents:
66
diff
changeset
|
143 * Retrieves the byte position at which the specified byte array pattern begins within the BLOB value that this |
86967be24645
Ready to start testing the old mapi connection. After passing the tests. The embedded integration will be very straightforward.
Pedro Ferreira <pedro.ferreira@monetdbsolutions.com>
parents:
66
diff
changeset
|
144 * Blob object represents. The search for pattern begins at position start. |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
145 * |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
146 * @param pattern the byte array for which to search |
68
86967be24645
Ready to start testing the old mapi connection. After passing the tests. The embedded integration will be very straightforward.
Pedro Ferreira <pedro.ferreira@monetdbsolutions.com>
parents:
66
diff
changeset
|
147 * @param start the position at which to begin searching; the first position is 1 |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
148 * @return the position at which the pattern appears, else -1 |
68
86967be24645
Ready to start testing the old mapi connection. After passing the tests. The embedded integration will be very straightforward.
Pedro Ferreira <pedro.ferreira@monetdbsolutions.com>
parents:
66
diff
changeset
|
149 * @throws SQLException if there is an error accessing the BLOB value |
0
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 position(byte[] pattern, long start) throws SQLException { |
68
86967be24645
Ready to start testing the old mapi connection. After passing the tests. The embedded integration will be very straightforward.
Pedro Ferreira <pedro.ferreira@monetdbsolutions.com>
parents:
66
diff
changeset
|
153 if (buffer == null) |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
154 throw new SQLException("This Blob object has been freed", "M1M20"); |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
155 try { |
68
86967be24645
Ready to start testing the old mapi connection. After passing the tests. The embedded integration will be very straightforward.
Pedro Ferreira <pedro.ferreira@monetdbsolutions.com>
parents:
66
diff
changeset
|
156 for (int i = (int)(start - 1); i < buffer.length - pattern.length; i++) { |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
157 int j; |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
158 for (j = 0; j < pattern.length; j++) { |
68
86967be24645
Ready to start testing the old mapi connection. After passing the tests. The embedded integration will be very straightforward.
Pedro Ferreira <pedro.ferreira@monetdbsolutions.com>
parents:
66
diff
changeset
|
159 if (buffer[i + j] != pattern[j]) |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
160 break; |
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 if (j == pattern.length) |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
163 return i; |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
164 } |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
165 } catch (IndexOutOfBoundsException e) { |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
166 throw new SQLException(e.getMessage(), "M0M10"); |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
167 } |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
168 return -1; |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
169 } |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
170 |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
171 /** |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
172 * Retrieves a stream that can be used to write to the BLOB value |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
173 * that this Blob object represents. The stream begins at position |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
174 * pos. The bytes written to the stream will overwrite the existing |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
175 * bytes in the Blob object starting at the position pos. If the end |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
176 * of the Blob value is reached while writing to the stream, then |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
177 * the length of the Blob value will be increased to accomodate the |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
178 * extra bytes. |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
179 * |
68
86967be24645
Ready to start testing the old mapi connection. After passing the tests. The embedded integration will be very straightforward.
Pedro Ferreira <pedro.ferreira@monetdbsolutions.com>
parents:
66
diff
changeset
|
180 * @param pos the position in the BLOB value at which to start writing; the first position is 1 |
86967be24645
Ready to start testing the old mapi connection. After passing the tests. The embedded integration will be very straightforward.
Pedro Ferreira <pedro.ferreira@monetdbsolutions.com>
parents:
66
diff
changeset
|
181 * @return a java.io.OutputStream object to which data can be written |
86967be24645
Ready to start testing the old mapi connection. After passing the tests. The embedded integration will be very straightforward.
Pedro Ferreira <pedro.ferreira@monetdbsolutions.com>
parents:
66
diff
changeset
|
182 * @throws SQLException if there is an error accessing the BLOB value or if pos is less than 1 |
86967be24645
Ready to start testing the old mapi connection. After passing the tests. The embedded integration will be very straightforward.
Pedro Ferreira <pedro.ferreira@monetdbsolutions.com>
parents:
66
diff
changeset
|
183 * @throws SQLFeatureNotSupportedException if the JDBC driver does not support this method |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
184 */ |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
185 @Override |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
186 public OutputStream setBinaryStream(long pos) throws SQLException { |
68
86967be24645
Ready to start testing the old mapi connection. After passing the tests. The embedded integration will be very straightforward.
Pedro Ferreira <pedro.ferreira@monetdbsolutions.com>
parents:
66
diff
changeset
|
187 if (buffer == null) |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
188 throw new SQLException("This Blob object has been freed", "M1M20"); |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
189 if (pos < 1) |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
190 throw new SQLException("pos is less than 1", "M1M05"); |
68
86967be24645
Ready to start testing the old mapi connection. After passing the tests. The embedded integration will be very straightforward.
Pedro Ferreira <pedro.ferreira@monetdbsolutions.com>
parents:
66
diff
changeset
|
191 throw new SQLFeatureNotSupportedException("Operation setBinaryStream(long pos) currently not supported", |
86967be24645
Ready to start testing the old mapi connection. After passing the tests. The embedded integration will be very straightforward.
Pedro Ferreira <pedro.ferreira@monetdbsolutions.com>
parents:
66
diff
changeset
|
192 "0A000"); |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
193 } |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
194 |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
195 /** |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
196 * Writes the given array of bytes to the BLOB value that this Blob |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
197 * object represents, starting at position pos, and returns the |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
198 * number of bytes written. |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
199 * |
68
86967be24645
Ready to start testing the old mapi connection. After passing the tests. The embedded integration will be very straightforward.
Pedro Ferreira <pedro.ferreira@monetdbsolutions.com>
parents:
66
diff
changeset
|
200 * @param pos the position in the BLOB object at which to start writing |
86967be24645
Ready to start testing the old mapi connection. After passing the tests. The embedded integration will be very straightforward.
Pedro Ferreira <pedro.ferreira@monetdbsolutions.com>
parents:
66
diff
changeset
|
201 * @param bytes the array of bytes to be written to the BLOB value that this Blob object represents |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
202 * @return the number of bytes written |
68
86967be24645
Ready to start testing the old mapi connection. After passing the tests. The embedded integration will be very straightforward.
Pedro Ferreira <pedro.ferreira@monetdbsolutions.com>
parents:
66
diff
changeset
|
203 * @throws SQLException if there is an error accessing the BLOB value |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
204 */ |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
205 @Override |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
206 public int setBytes(long pos, byte[] bytes) throws SQLException { |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
207 return setBytes(pos, bytes, 1, bytes.length); |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
208 } |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
209 |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
210 /** |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
211 * Writes all or part of the given byte array to the BLOB value that |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
212 * this Blob object represents and returns the number of bytes |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
213 * written. Writing starts at position pos in the BLOB value; len |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
214 * bytes from the given byte array are written. |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
215 * |
68
86967be24645
Ready to start testing the old mapi connection. After passing the tests. The embedded integration will be very straightforward.
Pedro Ferreira <pedro.ferreira@monetdbsolutions.com>
parents:
66
diff
changeset
|
216 * @param pos the position in the BLOB object at which to start writing |
86967be24645
Ready to start testing the old mapi connection. After passing the tests. The embedded integration will be very straightforward.
Pedro Ferreira <pedro.ferreira@monetdbsolutions.com>
parents:
66
diff
changeset
|
217 * @param bytes the array of bytes to be written to this BLOB object |
86967be24645
Ready to start testing the old mapi connection. After passing the tests. The embedded integration will be very straightforward.
Pedro Ferreira <pedro.ferreira@monetdbsolutions.com>
parents:
66
diff
changeset
|
218 * @param offset the offset into the array bytes at which to start reading the bytes to be set |
86967be24645
Ready to start testing the old mapi connection. After passing the tests. The embedded integration will be very straightforward.
Pedro Ferreira <pedro.ferreira@monetdbsolutions.com>
parents:
66
diff
changeset
|
219 * @param len the number of bytes to be written to the BLOB value from the array of bytes bytes |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
220 * @return the number of bytes written |
68
86967be24645
Ready to start testing the old mapi connection. After passing the tests. The embedded integration will be very straightforward.
Pedro Ferreira <pedro.ferreira@monetdbsolutions.com>
parents:
66
diff
changeset
|
221 * @throws SQLException if there is an error accessing the BLOB value |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
222 */ |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
223 @Override |
66
7307caacc2d5
Intermediary commit. Cross-implementation interface (for mapi connection with the old protocol, mapi connection with the new protocol and the embedded connection) almost done. The mcl layer processing is more memory efficient now.
Pedro Ferreira <pedro.ferreira@monetdbsolutions.com>
parents:
63
diff
changeset
|
224 public int setBytes(long pos, byte[] bytes, int offset, int len) throws SQLException { |
68
86967be24645
Ready to start testing the old mapi connection. After passing the tests. The embedded integration will be very straightforward.
Pedro Ferreira <pedro.ferreira@monetdbsolutions.com>
parents:
66
diff
changeset
|
225 if (buffer == null) |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
226 throw new SQLException("This Blob object has been freed", "M1M20"); |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
227 try { |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
228 /* transactions? what are you talking about? */ |
68
86967be24645
Ready to start testing the old mapi connection. After passing the tests. The embedded integration will be very straightforward.
Pedro Ferreira <pedro.ferreira@monetdbsolutions.com>
parents:
66
diff
changeset
|
229 System.arraycopy(bytes, offset - 1 + (int) pos, buffer, (int) pos, len - (int) pos); |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
230 } catch (IndexOutOfBoundsException e) { |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
231 throw new SQLException(e.getMessage(), "M0M10"); |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
232 } |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
233 return len; |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
234 } |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
235 |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
236 /** |
68
86967be24645
Ready to start testing the old mapi connection. After passing the tests. The embedded integration will be very straightforward.
Pedro Ferreira <pedro.ferreira@monetdbsolutions.com>
parents:
66
diff
changeset
|
237 * Truncates the BLOB value that this Blob object represents to be len bytes in length. |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
238 * |
68
86967be24645
Ready to start testing the old mapi connection. After passing the tests. The embedded integration will be very straightforward.
Pedro Ferreira <pedro.ferreira@monetdbsolutions.com>
parents:
66
diff
changeset
|
239 * @param len the length, in bytes, to which the BLOB value should be truncated |
86967be24645
Ready to start testing the old mapi connection. After passing the tests. The embedded integration will be very straightforward.
Pedro Ferreira <pedro.ferreira@monetdbsolutions.com>
parents:
66
diff
changeset
|
240 * @throws SQLException if there is an error accessing the BLOB value |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
241 */ |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
242 @Override |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
243 public void truncate(long len) throws SQLException { |
68
86967be24645
Ready to start testing the old mapi connection. After passing the tests. The embedded integration will be very straightforward.
Pedro Ferreira <pedro.ferreira@monetdbsolutions.com>
parents:
66
diff
changeset
|
244 if (buffer == null) |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
245 throw new SQLException("This Blob object has been freed", "M1M20"); |
68
86967be24645
Ready to start testing the old mapi connection. After passing the tests. The embedded integration will be very straightforward.
Pedro Ferreira <pedro.ferreira@monetdbsolutions.com>
parents:
66
diff
changeset
|
246 if (buffer.length > len) { |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
247 byte[] newbuf = new byte[(int)len]; |
68
86967be24645
Ready to start testing the old mapi connection. After passing the tests. The embedded integration will be very straightforward.
Pedro Ferreira <pedro.ferreira@monetdbsolutions.com>
parents:
66
diff
changeset
|
248 System.arraycopy(buffer, 0, newbuf, 0, (int) len); |
86967be24645
Ready to start testing the old mapi connection. After passing the tests. The embedded integration will be very straightforward.
Pedro Ferreira <pedro.ferreira@monetdbsolutions.com>
parents:
66
diff
changeset
|
249 buffer = newbuf; |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
250 } |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
251 } |
68
86967be24645
Ready to start testing the old mapi connection. After passing the tests. The embedded integration will be very straightforward.
Pedro Ferreira <pedro.ferreira@monetdbsolutions.com>
parents:
66
diff
changeset
|
252 |
86967be24645
Ready to start testing the old mapi connection. After passing the tests. The embedded integration will be very straightforward.
Pedro Ferreira <pedro.ferreira@monetdbsolutions.com>
parents:
66
diff
changeset
|
253 /** |
86967be24645
Ready to start testing the old mapi connection. After passing the tests. The embedded integration will be very straightforward.
Pedro Ferreira <pedro.ferreira@monetdbsolutions.com>
parents:
66
diff
changeset
|
254 * Overriding the equals method for the byte array. |
86967be24645
Ready to start testing the old mapi connection. After passing the tests. The embedded integration will be very straightforward.
Pedro Ferreira <pedro.ferreira@monetdbsolutions.com>
parents:
66
diff
changeset
|
255 */ |
86967be24645
Ready to start testing the old mapi connection. After passing the tests. The embedded integration will be very straightforward.
Pedro Ferreira <pedro.ferreira@monetdbsolutions.com>
parents:
66
diff
changeset
|
256 @Override |
86967be24645
Ready to start testing the old mapi connection. After passing the tests. The embedded integration will be very straightforward.
Pedro Ferreira <pedro.ferreira@monetdbsolutions.com>
parents:
66
diff
changeset
|
257 public boolean equals(Object obj) { |
86967be24645
Ready to start testing the old mapi connection. After passing the tests. The embedded integration will be very straightforward.
Pedro Ferreira <pedro.ferreira@monetdbsolutions.com>
parents:
66
diff
changeset
|
258 return obj instanceof MonetBlob && Arrays.equals(this.buffer, ((MonetBlob) obj).buffer); |
86967be24645
Ready to start testing the old mapi connection. After passing the tests. The embedded integration will be very straightforward.
Pedro Ferreira <pedro.ferreira@monetdbsolutions.com>
parents:
66
diff
changeset
|
259 } |
86967be24645
Ready to start testing the old mapi connection. After passing the tests. The embedded integration will be very straightforward.
Pedro Ferreira <pedro.ferreira@monetdbsolutions.com>
parents:
66
diff
changeset
|
260 |
86967be24645
Ready to start testing the old mapi connection. After passing the tests. The embedded integration will be very straightforward.
Pedro Ferreira <pedro.ferreira@monetdbsolutions.com>
parents:
66
diff
changeset
|
261 /** |
86967be24645
Ready to start testing the old mapi connection. After passing the tests. The embedded integration will be very straightforward.
Pedro Ferreira <pedro.ferreira@monetdbsolutions.com>
parents:
66
diff
changeset
|
262 * Overriding the hashCode method for the byte array. |
86967be24645
Ready to start testing the old mapi connection. After passing the tests. The embedded integration will be very straightforward.
Pedro Ferreira <pedro.ferreira@monetdbsolutions.com>
parents:
66
diff
changeset
|
263 */ |
86967be24645
Ready to start testing the old mapi connection. After passing the tests. The embedded integration will be very straightforward.
Pedro Ferreira <pedro.ferreira@monetdbsolutions.com>
parents:
66
diff
changeset
|
264 @Override |
86967be24645
Ready to start testing the old mapi connection. After passing the tests. The embedded integration will be very straightforward.
Pedro Ferreira <pedro.ferreira@monetdbsolutions.com>
parents:
66
diff
changeset
|
265 public int hashCode() { return Arrays.hashCode(this.buffer); } |
86967be24645
Ready to start testing the old mapi connection. After passing the tests. The embedded integration will be very straightforward.
Pedro Ferreira <pedro.ferreira@monetdbsolutions.com>
parents:
66
diff
changeset
|
266 |
86967be24645
Ready to start testing the old mapi connection. After passing the tests. The embedded integration will be very straightforward.
Pedro Ferreira <pedro.ferreira@monetdbsolutions.com>
parents:
66
diff
changeset
|
267 /** |
86967be24645
Ready to start testing the old mapi connection. After passing the tests. The embedded integration will be very straightforward.
Pedro Ferreira <pedro.ferreira@monetdbsolutions.com>
parents:
66
diff
changeset
|
268 * Overriding the toString method for the byte array. |
86967be24645
Ready to start testing the old mapi connection. After passing the tests. The embedded integration will be very straightforward.
Pedro Ferreira <pedro.ferreira@monetdbsolutions.com>
parents:
66
diff
changeset
|
269 */ |
86967be24645
Ready to start testing the old mapi connection. After passing the tests. The embedded integration will be very straightforward.
Pedro Ferreira <pedro.ferreira@monetdbsolutions.com>
parents:
66
diff
changeset
|
270 @Override |
86967be24645
Ready to start testing the old mapi connection. After passing the tests. The embedded integration will be very straightforward.
Pedro Ferreira <pedro.ferreira@monetdbsolutions.com>
parents:
66
diff
changeset
|
271 public String toString() { return Arrays.toString(this.buffer); } |
86967be24645
Ready to start testing the old mapi connection. After passing the tests. The embedded integration will be very straightforward.
Pedro Ferreira <pedro.ferreira@monetdbsolutions.com>
parents:
66
diff
changeset
|
272 |
86967be24645
Ready to start testing the old mapi connection. After passing the tests. The embedded integration will be very straightforward.
Pedro Ferreira <pedro.ferreira@monetdbsolutions.com>
parents:
66
diff
changeset
|
273 @Override |
86967be24645
Ready to start testing the old mapi connection. After passing the tests. The embedded integration will be very straightforward.
Pedro Ferreira <pedro.ferreira@monetdbsolutions.com>
parents:
66
diff
changeset
|
274 public int compareTo(MonetBlob o) { |
86967be24645
Ready to start testing the old mapi connection. After passing the tests. The embedded integration will be very straightforward.
Pedro Ferreira <pedro.ferreira@monetdbsolutions.com>
parents:
66
diff
changeset
|
275 byte[] first = this.buffer, second = o.buffer; |
86967be24645
Ready to start testing the old mapi connection. After passing the tests. The embedded integration will be very straightforward.
Pedro Ferreira <pedro.ferreira@monetdbsolutions.com>
parents:
66
diff
changeset
|
276 int len = Math.min(first.length, second.length), res = 0; |
86967be24645
Ready to start testing the old mapi connection. After passing the tests. The embedded integration will be very straightforward.
Pedro Ferreira <pedro.ferreira@monetdbsolutions.com>
parents:
66
diff
changeset
|
277 for(int i = 0; i < len ; i++) { |
86967be24645
Ready to start testing the old mapi connection. After passing the tests. The embedded integration will be very straightforward.
Pedro Ferreira <pedro.ferreira@monetdbsolutions.com>
parents:
66
diff
changeset
|
278 res = res + first[i] - second[i]; |
86967be24645
Ready to start testing the old mapi connection. After passing the tests. The embedded integration will be very straightforward.
Pedro Ferreira <pedro.ferreira@monetdbsolutions.com>
parents:
66
diff
changeset
|
279 } |
86967be24645
Ready to start testing the old mapi connection. After passing the tests. The embedded integration will be very straightforward.
Pedro Ferreira <pedro.ferreira@monetdbsolutions.com>
parents:
66
diff
changeset
|
280 return res; |
86967be24645
Ready to start testing the old mapi connection. After passing the tests. The embedded integration will be very straightforward.
Pedro Ferreira <pedro.ferreira@monetdbsolutions.com>
parents:
66
diff
changeset
|
281 } |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
282 } |