Mercurial > hg > monetdb-java
annotate src/main/java/org/monetdb/jdbc/MonetConnection.java @ 973:32f246853ec4 default tip
Optimisation, call connection.mapClobAsVarChar() and connection.mapBlobAsVarBinary() outside the for-loop, as it does not change.
author | Martin van Dinther <martin.van.dinther@monetdbsolutions.com> |
---|---|
date | Thu, 10 Apr 2025 19:26:59 +0200 (3 hours ago) |
parents | 5cc071c5c170 |
children |
rev | line source |
---|---|
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
1 /* |
833
e890195256ac
Update copyright for the new year, move to MonetDB Foundation, add SPDX.
Sjoerd Mullender <sjoerd@acm.org>
parents:
819
diff
changeset
|
2 * SPDX-License-Identifier: MPL-2.0 |
e890195256ac
Update copyright for the new year, move to MonetDB Foundation, add SPDX.
Sjoerd Mullender <sjoerd@acm.org>
parents:
819
diff
changeset
|
3 * |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
4 * 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
|
5 * 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
|
6 * 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
|
7 * |
937
d416e9b6b3d0
Update Copyright year.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
924
diff
changeset
|
8 * Copyright 2024, 2025 MonetDB Foundation; |
833
e890195256ac
Update copyright for the new year, move to MonetDB Foundation, add SPDX.
Sjoerd Mullender <sjoerd@acm.org>
parents:
819
diff
changeset
|
9 * Copyright August 2008 - 2023 MonetDB B.V.; |
e890195256ac
Update copyright for the new year, move to MonetDB Foundation, add SPDX.
Sjoerd Mullender <sjoerd@acm.org>
parents:
819
diff
changeset
|
10 * Copyright 1997 - July 2008 CWI. |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
11 */ |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
12 |
391
f523727db392
Moved Java classes from packages starting with nl.cwi.monetdb.* to package org.monetdb.*
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
381
diff
changeset
|
13 package org.monetdb.jdbc; |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
14 |
514
443780d71bae
More renaming. user registers MonetUploadHandler which is handed an Upload
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
511
diff
changeset
|
15 import java.io.*; |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
16 import java.net.SocketException; |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
17 import java.net.SocketTimeoutException; |
514
443780d71bae
More renaming. user registers MonetUploadHandler which is handed an Upload
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
511
diff
changeset
|
18 import java.nio.charset.StandardCharsets; |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
19 import java.sql.CallableStatement; |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
20 import java.sql.Connection; |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
21 import java.sql.DatabaseMetaData; |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
22 import java.sql.PreparedStatement; |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
23 import java.sql.ResultSet; |
905
a52bc2dcdb8c
Implement ClientInfo API
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
903
diff
changeset
|
24 import java.sql.ResultSetMetaData; |
194
1296dbcc4958
Resolved javadoc many errors and warnings, such as:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
186
diff
changeset
|
25 import java.sql.SQLClientInfoException; |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
26 import java.sql.SQLException; |
266
eefa7f625673
Resolve javadoc errors:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
262
diff
changeset
|
27 import java.sql.SQLFeatureNotSupportedException; |
144
d6abd1ffffbb
Use SQLNonTransientConnectionException instead of SQLException where applicable (SQLState starts with 08)
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
136
diff
changeset
|
28 import java.sql.SQLNonTransientConnectionException; |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
29 import java.sql.SQLWarning; |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
30 import java.sql.Savepoint; |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
31 import java.sql.Statement; |
814
1344603ee8af
Use intrinsics rather than manual flow control
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
771
diff
changeset
|
32 import java.util.*; |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
33 import java.util.Map.Entry; |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
34 import java.util.concurrent.Executor; |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
35 |
391
f523727db392
Moved Java classes from packages starting with nl.cwi.monetdb.* to package org.monetdb.*
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
381
diff
changeset
|
36 import org.monetdb.mcl.io.BufferedMCLReader; |
f523727db392
Moved Java classes from packages starting with nl.cwi.monetdb.* to package org.monetdb.*
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
381
diff
changeset
|
37 import org.monetdb.mcl.io.BufferedMCLWriter; |
497
aed7f32e029a
Refactor LineType to be an enum
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
496
diff
changeset
|
38 import org.monetdb.mcl.io.LineType; |
905
a52bc2dcdb8c
Implement ClientInfo API
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
903
diff
changeset
|
39 import org.monetdb.mcl.net.ClientInfo; |
391
f523727db392
Moved Java classes from packages starting with nl.cwi.monetdb.* to package org.monetdb.*
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
381
diff
changeset
|
40 import org.monetdb.mcl.net.MapiSocket; |
793
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
788
diff
changeset
|
41 import org.monetdb.mcl.net.Target; |
940
c5e47b8a509c
Prefer getters of class Target.Validated over class Target
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
937
diff
changeset
|
42 import org.monetdb.mcl.net.ValidationError; |
391
f523727db392
Moved Java classes from packages starting with nl.cwi.monetdb.* to package org.monetdb.*
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
381
diff
changeset
|
43 import org.monetdb.mcl.parser.HeaderLineParser; |
f523727db392
Moved Java classes from packages starting with nl.cwi.monetdb.* to package org.monetdb.*
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
381
diff
changeset
|
44 import org.monetdb.mcl.parser.MCLParseException; |
f523727db392
Moved Java classes from packages starting with nl.cwi.monetdb.* to package org.monetdb.*
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
381
diff
changeset
|
45 import org.monetdb.mcl.parser.StartOfHeaderParser; |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
46 |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
47 /** |
451
3dfcd06fd8ba
Correcting typos in documentation text. Also improved the readability of the generated javadoc documents.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
441
diff
changeset
|
48 *<pre> |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
49 * A {@link Connection} suitable for the MonetDB database. |
45
c2bf983dc79b
Implemented Connection methods: getClientInfo(name) and getClientInfo().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
25
diff
changeset
|
50 * |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
51 * This connection represents a connection (session) to a MonetDB |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
52 * database. SQL statements are executed and results are returned within |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
53 * the context of a connection. This Connection object holds a physical |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
54 * connection to the MonetDB database. |
45
c2bf983dc79b
Implemented Connection methods: getClientInfo(name) and getClientInfo().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
25
diff
changeset
|
55 * |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
56 * A Connection object's database should able to provide information |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
57 * describing its tables, its supported SQL grammar, its stored |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
58 * procedures, the capabilities of this connection, and so on. This |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
59 * information is obtained with the getMetaData method. |
45
c2bf983dc79b
Implemented Connection methods: getClientInfo(name) and getClientInfo().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
25
diff
changeset
|
60 * |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
61 * Note: By default a Connection object is in auto-commit mode, which |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
62 * means that it automatically commits changes after executing each |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
63 * statement. If auto-commit mode has been disabled, the method commit |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
64 * must be called explicitly in order to commit changes; otherwise, |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
65 * database changes will not be saved. |
45
c2bf983dc79b
Implemented Connection methods: getClientInfo(name) and getClientInfo().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
25
diff
changeset
|
66 * |
451
3dfcd06fd8ba
Correcting typos in documentation text. Also improved the readability of the generated javadoc documents.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
441
diff
changeset
|
67 * The current state of this class is that it nearly implements the |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
68 * whole Connection interface. |
451
3dfcd06fd8ba
Correcting typos in documentation text. Also improved the readability of the generated javadoc documents.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
441
diff
changeset
|
69 *</pre> |
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 * @author Fabian Groffen |
45
c2bf983dc79b
Implemented Connection methods: getClientInfo(name) and getClientInfo().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
25
diff
changeset
|
72 * @author Martin van Dinther |
576
095e896f9d7a
Updated comments. Improved code. Added final keywords
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
568
diff
changeset
|
73 * @version 1.7 |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
74 */ |
164
7c9e386fe49a
As of Java 1.7 implementations of JDBC interfaces Connection, Statement, PreparedStatement,
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
144
diff
changeset
|
75 public class MonetConnection |
7c9e386fe49a
As of Java 1.7 implementations of JDBC interfaces Connection, Statement, PreparedStatement,
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
144
diff
changeset
|
76 extends MonetWrapper |
7c9e386fe49a
As of Java 1.7 implementations of JDBC interfaces Connection, Statement, PreparedStatement,
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
144
diff
changeset
|
77 implements Connection, AutoCloseable |
7c9e386fe49a
As of Java 1.7 implementations of JDBC interfaces Connection, Statement, PreparedStatement,
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
144
diff
changeset
|
78 { |
834
5aa19bbed0d6
Comments and formatting
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
810
diff
changeset
|
79 /* All connection parameters */ |
869
676725ad17b5
Remove not needed/used internal method checkValidProperty()
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
867
diff
changeset
|
80 private final Target target; |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
81 /** A connection to mserver5 using a TCP socket */ |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
82 private final MapiSocket server; |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
83 /** The Reader from the server */ |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
84 private final BufferedMCLReader in; |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
85 /** The Writer to the server */ |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
86 private final BufferedMCLWriter out; |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
87 |
295
003ae6d881db
Add "final" keyword to method arguments and local variables where possible.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
292
diff
changeset
|
88 /** A StartOfHeaderParser declared for reuse. */ |
414
1e278695fe54
Small improvements: adding some final keywords, removing unnecesary initialisations, improve comments.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
408
diff
changeset
|
89 private final StartOfHeaderParser sohp = new StartOfHeaderParser(); |
0
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 /** Whether this Connection is closed (and cannot be used anymore) */ |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
92 private boolean closed; |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
93 |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
94 /** Whether this Connection is in autocommit mode */ |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
95 private boolean autoCommit = true; |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
96 |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
97 /** The stack of warnings for this Connection object */ |
407
40a1db14dca5
Optimise code, reduce duplicate code, cache major and minor version nrs of connected database server and max nr of clients so conversion of strings to ints is only done once.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
406
diff
changeset
|
98 private SQLWarning warnings; |
284
e5b99c929a2d
Improve setSchema(String schema) by checking also on empty name.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
278
diff
changeset
|
99 |
e5b99c929a2d
Improve setSchema(String schema) by checking also on empty name.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
278
diff
changeset
|
100 /** The Connection specific mapping of user defined types to Java types */ |
45
c2bf983dc79b
Implemented Connection methods: getClientInfo(name) and getClientInfo().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
25
diff
changeset
|
101 private Map<String,Class<?>> typeMap = new HashMap<String,Class<?>>() { |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
102 private static final long serialVersionUID = 1L; |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
103 { |
391
f523727db392
Moved Java classes from packages starting with nl.cwi.monetdb.* to package org.monetdb.*
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
381
diff
changeset
|
104 put("inet", org.monetdb.jdbc.types.INET.class); |
f523727db392
Moved Java classes from packages starting with nl.cwi.monetdb.* to package org.monetdb.*
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
381
diff
changeset
|
105 put("url", org.monetdb.jdbc.types.URL.class); |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
106 } |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
107 }; |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
108 |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
109 // See javadoc for documentation about WeakHashMap if you don't know what |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
110 // it does !!!NOW!!! (only when you deal with it of course) |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
111 /** A Map containing all (active) Statements created from this Connection */ |
414
1e278695fe54
Small improvements: adding some final keywords, removing unnecesary initialisations, improve comments.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
408
diff
changeset
|
112 private final WeakHashMap<Statement,?> statements = new WeakHashMap<Statement, Object>(); |
0
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 /** The number of results we receive from the server at once */ |
434
57d46c34c649
default server reply size is 100, not -1
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
433
diff
changeset
|
115 private int curReplySize = 100; // server default |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
116 |
45
c2bf983dc79b
Implemented Connection methods: getClientInfo(name) and getClientInfo().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
25
diff
changeset
|
117 /** A template to apply to each query (like pre and post fixes), filled in constructor */ |
336
5826913bdc6d
commandTempl[2] is never used, so no need to allocate and initialise it.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
335
diff
changeset
|
118 // note: it is made public to the package as queryTempl[2] is used from MonetStatement |
332
e8962bdaa206
Moved utility methods and associated caches from DatabaseMetaData to Connection object.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
324
diff
changeset
|
119 final String[] queryTempl = new String[3]; // pre, post, sep |
45
c2bf983dc79b
Implemented Connection methods: getClientInfo(name) and getClientInfo().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
25
diff
changeset
|
120 |
c2bf983dc79b
Implemented Connection methods: getClientInfo(name) and getClientInfo().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
25
diff
changeset
|
121 /** A template to apply to each command (like pre and post fixes), filled in constructor */ |
336
5826913bdc6d
commandTempl[2] is never used, so no need to allocate and initialise it.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
335
diff
changeset
|
122 private final String[] commandTempl = new String[2]; // pre, post |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
123 |
905
a52bc2dcdb8c
Implement ClientInfo API
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
903
diff
changeset
|
124 /** A mapping of ClientInfo property names such as 'ClientHostname' to columns of the |
a52bc2dcdb8c
Implement ClientInfo API
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
903
diff
changeset
|
125 * sessions table, such as 'hostname'. |
a52bc2dcdb8c
Implement ClientInfo API
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
903
diff
changeset
|
126 */ |
a52bc2dcdb8c
Implement ClientInfo API
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
903
diff
changeset
|
127 private HashMap<String,String> clientInfoAttributeNames = null; |
a52bc2dcdb8c
Implement ClientInfo API
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
903
diff
changeset
|
128 |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
129 /** the SQL language */ |
186
4767b005a531
Making variables private where possible.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
184
diff
changeset
|
130 private static final int LANG_SQL = 0; |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
131 /** the MAL language (officially *NOT* supported) */ |
186
4767b005a531
Making variables private where possible.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
184
diff
changeset
|
132 private static final int LANG_MAL = 3; |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
133 /** an unknown language */ |
186
4767b005a531
Making variables private where possible.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
184
diff
changeset
|
134 private static final int LANG_UNKNOWN = -1; |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
135 /** The language which is used */ |
186
4767b005a531
Making variables private where possible.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
184
diff
changeset
|
136 private final int lang; |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
137 |
271
4880267d0fe1
Added implementation of java.sql.CallableStatement interface, test program and updated the ChangeLog and release notes.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
266
diff
changeset
|
138 /** The last set query timeout on the server as used by Statement, PreparedStatement and CallableStatement */ |
751
1566dbfaa13b
Correct setQueryTimeout(secs) implementation. It was changed to match the web documentation (see https://dev.monetdb.org/hg/monetdb-java/rev/849f99124e32 ) but it appears the web documentation was wrong. So revert the changes made.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
736
diff
changeset
|
139 protected int lastSetQueryTimeout = 0; // 0 means no timeout, which is the default on the server |
249
46385d8ff8c9
Improve the implementation of Statement methods getQueryTimeout() and setQueryTimeout().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
243
diff
changeset
|
140 |
472
0e21097f438b
Reduce the number of MonetDatabaseMetaData objects created via getMetaData() to maximum 1 per connection as it can be reused.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
451
diff
changeset
|
141 /** A cache to reduce the number of DatabaseMetaData objects created by getMetaData() to maximum 1 per connection */ |
0e21097f438b
Reduce the number of MonetDatabaseMetaData objects created via getMetaData() to maximum 1 per connection as it can be reused.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
451
diff
changeset
|
142 private DatabaseMetaData dbmd; |
0e21097f438b
Reduce the number of MonetDatabaseMetaData objects created via getMetaData() to maximum 1 per connection as it can be reused.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
451
diff
changeset
|
143 |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
144 /** |
834
5aa19bbed0d6
Comments and formatting
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
810
diff
changeset
|
145 * Constructor of a Connection for MonetDB. |
869
676725ad17b5
Remove not needed/used internal method checkValidProperty()
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
867
diff
changeset
|
146 * This constructor is only accessible to classes from the jdbc package. |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
147 * |
834
5aa19bbed0d6
Comments and formatting
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
810
diff
changeset
|
148 * @param target a {@link Target} object containing all connection parameters |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
149 * @throws SQLException if a database error occurs |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
150 * @throws IllegalArgumentException is one of the arguments is null or empty |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
151 */ |
793
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
788
diff
changeset
|
152 MonetConnection(Target target) |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
153 throws SQLException, IllegalArgumentException |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
154 { |
793
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
788
diff
changeset
|
155 this.target = target; |
940
c5e47b8a509c
Prefer getters of class Target.Validated over class Target
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
937
diff
changeset
|
156 Target.Validated validated; |
c5e47b8a509c
Prefer getters of class Target.Validated over class Target
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
937
diff
changeset
|
157 try { |
c5e47b8a509c
Prefer getters of class Target.Validated over class Target
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
937
diff
changeset
|
158 validated = target.validate(); |
c5e47b8a509c
Prefer getters of class Target.Validated over class Target
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
937
diff
changeset
|
159 } catch (ValidationError e) { |
c5e47b8a509c
Prefer getters of class Target.Validated over class Target
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
937
diff
changeset
|
160 throw new SQLNonTransientConnectionException(e.getMessage()); |
c5e47b8a509c
Prefer getters of class Target.Validated over class Target
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
937
diff
changeset
|
161 } |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
162 server = new MapiSocket(); |
422
8368cbc670bf
Send reply size and time zone during initial handshake
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
416
diff
changeset
|
163 |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
164 // we're debugging here... uhm, should be off in real life |
940
c5e47b8a509c
Prefer getters of class Target.Validated over class Target
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
937
diff
changeset
|
165 if (validated.isDebug()) { |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
166 try { |
940
c5e47b8a509c
Prefer getters of class Target.Validated over class Target
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
937
diff
changeset
|
167 String fname = validated.getLogfile(); |
793
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
788
diff
changeset
|
168 if (fname == null) |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
788
diff
changeset
|
169 fname = "monet_" + System.currentTimeMillis() + ".log"; |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
788
diff
changeset
|
170 |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
171 File f = new File(fname); |
295
003ae6d881db
Add "final" keyword to method arguments and local variables where possible.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
292
diff
changeset
|
172 |
25
5ec116ba7d71
When single character use faster version of indexOf(<char>)
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
8
diff
changeset
|
173 int ext = fname.lastIndexOf('.'); |
45
c2bf983dc79b
Implemented Connection methods: getClientInfo(name) and getClientInfo().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
25
diff
changeset
|
174 if (ext < 0) |
c2bf983dc79b
Implemented Connection methods: getClientInfo(name) and getClientInfo().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
25
diff
changeset
|
175 ext = fname.length(); |
295
003ae6d881db
Add "final" keyword to method arguments and local variables where possible.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
292
diff
changeset
|
176 final String pre = fname.substring(0, ext); |
003ae6d881db
Add "final" keyword to method arguments and local variables where possible.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
292
diff
changeset
|
177 final String suf = fname.substring(ext); |
0
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 for (int i = 1; f.exists(); i++) { |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
180 f = new File(pre + "-" + i + suf); |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
181 } |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
182 |
278
1d6062d94377
Reduce duplicate code.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
271
diff
changeset
|
183 server.debug(f.getAbsolutePath()); // enable logging on the MapiSocket level |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
184 } catch (IOException ex) { |
144
d6abd1ffffbb
Use SQLNonTransientConnectionException instead of SQLException where applicable (SQLState starts with 08)
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
136
diff
changeset
|
185 throw new SQLNonTransientConnectionException("Opening logfile failed: " + ex.getMessage(), "08M01"); |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
186 } |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
187 } |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
188 |
793
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
788
diff
changeset
|
189 SqlOptionsCallback callback = null; |
940
c5e47b8a509c
Prefer getters of class Target.Validated over class Target
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
937
diff
changeset
|
190 switch (validated.getLanguage()) { |
793
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
788
diff
changeset
|
191 case "sql": |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
788
diff
changeset
|
192 lang = LANG_SQL; |
834
5aa19bbed0d6
Comments and formatting
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
810
diff
changeset
|
193 queryTempl[0] = "s"; // pre |
5aa19bbed0d6
Comments and formatting
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
810
diff
changeset
|
194 queryTempl[1] = "\n;"; // post |
5aa19bbed0d6
Comments and formatting
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
810
diff
changeset
|
195 queryTempl[2] = "\n;\n"; // separator |
5aa19bbed0d6
Comments and formatting
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
810
diff
changeset
|
196 commandTempl[0] = "X"; // pre |
5aa19bbed0d6
Comments and formatting
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
810
diff
changeset
|
197 commandTempl[1] = ""; // post |
940
c5e47b8a509c
Prefer getters of class Target.Validated over class Target
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
937
diff
changeset
|
198 callback = new SqlOptionsCallback(validated); |
793
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
788
diff
changeset
|
199 break; |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
788
diff
changeset
|
200 case "mal": |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
788
diff
changeset
|
201 lang = LANG_MAL; |
834
5aa19bbed0d6
Comments and formatting
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
810
diff
changeset
|
202 queryTempl[0] = ""; // pre |
5aa19bbed0d6
Comments and formatting
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
810
diff
changeset
|
203 queryTempl[1] = ";\n"; // post |
5aa19bbed0d6
Comments and formatting
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
810
diff
changeset
|
204 queryTempl[2] = ";\n"; // separator |
5aa19bbed0d6
Comments and formatting
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
810
diff
changeset
|
205 commandTempl[0] = ""; // pre |
5aa19bbed0d6
Comments and formatting
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
810
diff
changeset
|
206 commandTempl[1] = ""; // post |
793
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
788
diff
changeset
|
207 break; |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
788
diff
changeset
|
208 default: |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
788
diff
changeset
|
209 lang = LANG_UNKNOWN; |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
788
diff
changeset
|
210 break; |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
788
diff
changeset
|
211 } |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
788
diff
changeset
|
212 |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
213 try { |
793
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
788
diff
changeset
|
214 |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
788
diff
changeset
|
215 final java.util.List<String> warnings = server.connect(target, callback); |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
216 for (String warning : warnings) { |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
217 addWarning(warning, "01M02"); |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
218 } |
45
c2bf983dc79b
Implemented Connection methods: getClientInfo(name) and getClientInfo().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
25
diff
changeset
|
219 |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
220 in = server.getReader(); |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
221 out = server.getWriter(); |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
222 |
700
940e266eeccd
Refactor BufferedMCLReader
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
697
diff
changeset
|
223 final String error = in.discardRemainder(); |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
224 if (error != null) |
144
d6abd1ffffbb
Use SQLNonTransientConnectionException instead of SQLException where applicable (SQLState starts with 08)
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
136
diff
changeset
|
225 throw new SQLNonTransientConnectionException((error.length() > 6) ? error.substring(6) : error, "08001"); |
869
676725ad17b5
Remove not needed/used internal method checkValidProperty()
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
867
diff
changeset
|
226 } catch (javax.net.ssl.SSLException e) { |
801
88b3e8e89126
TLS seems to work
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
798
diff
changeset
|
227 throw new SQLNonTransientConnectionException("Cannot establish secure connection: " + e.getMessage(), e); |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
228 } catch (IOException e) { |
801
88b3e8e89126
TLS seems to work
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
798
diff
changeset
|
229 throw new SQLNonTransientConnectionException("Cannot connect: " + e.getMessage(), "08006", e); |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
230 } catch (MCLParseException e) { |
144
d6abd1ffffbb
Use SQLNonTransientConnectionException instead of SQLException where applicable (SQLState starts with 08)
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
136
diff
changeset
|
231 throw new SQLNonTransientConnectionException(e.getMessage(), "08001"); |
391
f523727db392
Moved Java classes from packages starting with nl.cwi.monetdb.* to package org.monetdb.*
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
381
diff
changeset
|
232 } catch (org.monetdb.mcl.MCLException e) { |
295
003ae6d881db
Add "final" keyword to method arguments and local variables where possible.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
292
diff
changeset
|
233 final String[] connex = e.getMessage().split("\n"); |
003ae6d881db
Add "final" keyword to method arguments and local variables where possible.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
292
diff
changeset
|
234 final SQLException sqle = new SQLNonTransientConnectionException(connex[0], "08001", e); |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
235 for (int i = 1; i < connex.length; i++) { |
144
d6abd1ffffbb
Use SQLNonTransientConnectionException instead of SQLException where applicable (SQLState starts with 08)
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
136
diff
changeset
|
236 sqle.setNextException(new SQLNonTransientConnectionException(connex[1], "08001")); |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
237 } |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
238 throw sqle; |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
239 } |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
240 |
940
c5e47b8a509c
Prefer getters of class Target.Validated over class Target
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
937
diff
changeset
|
241 if (server.canClientInfo() && validated.sendClientInfo()) { |
905
a52bc2dcdb8c
Implement ClientInfo API
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
903
diff
changeset
|
242 ClientInfo info = new ClientInfo(); |
a52bc2dcdb8c
Implement ClientInfo API
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
903
diff
changeset
|
243 info.setDefaults(); |
940
c5e47b8a509c
Prefer getters of class Target.Validated over class Target
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
937
diff
changeset
|
244 String clientApplication = validated.getClientApplication(); |
c5e47b8a509c
Prefer getters of class Target.Validated over class Target
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
937
diff
changeset
|
245 String clientRemark = validated.getClientRemark(); |
905
a52bc2dcdb8c
Implement ClientInfo API
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
903
diff
changeset
|
246 if (!clientApplication.isEmpty()) |
a52bc2dcdb8c
Implement ClientInfo API
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
903
diff
changeset
|
247 info.set("ApplicationName", clientApplication); |
a52bc2dcdb8c
Implement ClientInfo API
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
903
diff
changeset
|
248 if (!clientRemark.isEmpty()) |
a52bc2dcdb8c
Implement ClientInfo API
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
903
diff
changeset
|
249 info.set("ClientRemark", clientRemark); |
a52bc2dcdb8c
Implement ClientInfo API
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
903
diff
changeset
|
250 sendClientInfo(info); |
903
778959b2e0a4
Send ClientInfo on startup
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
879
diff
changeset
|
251 } |
778959b2e0a4
Send ClientInfo on startup
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
879
diff
changeset
|
252 |
879
6e8ff2818fa7
Implement the new schema= option of the jdbc URL
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
878
diff
changeset
|
253 // Now take care of any options not handled during the handshake |
793
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
788
diff
changeset
|
254 curReplySize = defaultFetchSize; |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
255 if (lang == LANG_SQL) { |
940
c5e47b8a509c
Prefer getters of class Target.Validated over class Target
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
937
diff
changeset
|
256 if (autoCommit != validated.isAutocommit()) { |
c5e47b8a509c
Prefer getters of class Target.Validated over class Target
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
937
diff
changeset
|
257 setAutoCommit(validated.isAutocommit()); |
658
108123ca6889
Add autocommit=true/false option to jdbc url
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
657
diff
changeset
|
258 } |
837
5df67d5d7a7b
Move timeZoneSet and sizeHeaderEnabled into Callback
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
834
diff
changeset
|
259 if (!callback.sizeHeaderEnabled) { |
671
fade6c6960cc
Refactor Handshake options
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
666
diff
changeset
|
260 sendControlCommand("sizeheader 1"); |
422
8368cbc670bf
Send reply size and time zone during initial handshake
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
416
diff
changeset
|
261 } |
837
5df67d5d7a7b
Move timeZoneSet and sizeHeaderEnabled into Callback
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
834
diff
changeset
|
262 if (!callback.timeZoneSet) { |
940
c5e47b8a509c
Prefer getters of class Target.Validated over class Target
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
937
diff
changeset
|
263 setTimezone(60 * validated.getTimezone()); |
671
fade6c6960cc
Refactor Handshake options
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
666
diff
changeset
|
264 } |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
265 } |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
266 |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
267 // we're absolutely not closed, since we're brand new |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
268 closed = false; |
879
6e8ff2818fa7
Implement the new schema= option of the jdbc URL
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
878
diff
changeset
|
269 |
940
c5e47b8a509c
Prefer getters of class Target.Validated over class Target
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
937
diff
changeset
|
270 if (!validated.getSchema().isEmpty()) { |
879
6e8ff2818fa7
Implement the new schema= option of the jdbc URL
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
878
diff
changeset
|
271 try (Statement stmt = this.createStatement()) { |
940
c5e47b8a509c
Prefer getters of class Target.Validated over class Target
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
937
diff
changeset
|
272 String escaped = validated.getSchema().replaceAll("\"", "\"\""); |
879
6e8ff2818fa7
Implement the new schema= option of the jdbc URL
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
878
diff
changeset
|
273 stmt.execute("SET SCHEMA \"" + escaped + "\""); |
6e8ff2818fa7
Implement the new schema= option of the jdbc URL
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
878
diff
changeset
|
274 } |
6e8ff2818fa7
Implement the new schema= option of the jdbc URL
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
878
diff
changeset
|
275 } |
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 |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
278 //== methods of interface Connection |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
279 |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
280 /** |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
281 * Clears all warnings reported for this Connection object. After a |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
282 * call to this method, the method getWarnings returns null until a |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
283 * new warning is reported for this Connection object. |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
284 */ |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
285 @Override |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
286 public void clearWarnings() { |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
287 warnings = null; |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
288 } |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
289 |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
290 /** |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
291 * Releases this Connection object's database and JDBC resources |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
292 * immediately instead of waiting for them to be automatically |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
293 * released. All Statements created from this Connection will be |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
294 * closed when this method is called. |
45
c2bf983dc79b
Implemented Connection methods: getClientInfo(name) and getClientInfo().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
25
diff
changeset
|
295 * |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
296 * Calling the method close on a Connection object that is already |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
297 * closed is a no-op. |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
298 */ |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
299 @Override |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
300 public void close() { |
623
1c3cdf0667d7
Do more cleanup in the close() methods such as calling clearWarnings(), clearParameters(), clearBatch() and dereferencing cached objects.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
620
diff
changeset
|
301 if (closed) |
1c3cdf0667d7
Do more cleanup in the close() methods such as calling clearWarnings(), clearParameters(), clearBatch() and dereferencing cached objects.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
620
diff
changeset
|
302 return; |
1c3cdf0667d7
Do more cleanup in the close() methods such as calling clearWarnings(), clearParameters(), clearBatch() and dereferencing cached objects.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
620
diff
changeset
|
303 |
1c3cdf0667d7
Do more cleanup in the close() methods such as calling clearWarnings(), clearParameters(), clearBatch() and dereferencing cached objects.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
620
diff
changeset
|
304 clearWarnings(); |
924
ace9f8f617f1
In close() also set clientInfoAttributeNames = null; so it can be gc-ed.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
919
diff
changeset
|
305 clientInfoAttributeNames = null; |
623
1c3cdf0667d7
Do more cleanup in the close() methods such as calling clearWarnings(), clearParameters(), clearBatch() and dereferencing cached objects.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
620
diff
changeset
|
306 dbmd = null; |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
307 synchronized (server) { |
623
1c3cdf0667d7
Do more cleanup in the close() methods such as calling clearWarnings(), clearParameters(), clearBatch() and dereferencing cached objects.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
620
diff
changeset
|
308 // Note: An entry in a WeakHashMap will automatically be |
1c3cdf0667d7
Do more cleanup in the close() methods such as calling clearWarnings(), clearParameters(), clearBatch() and dereferencing cached objects.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
620
diff
changeset
|
309 // removed when its key is no longer in ordinary use. |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
310 for (Statement st : statements.keySet()) { |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
311 try { |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
312 st.close(); |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
313 } catch (SQLException e) { |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
314 // better luck next time! |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
315 } |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
316 } |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
317 // close the socket |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
318 server.close(); |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
319 // report ourselves as closed |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
320 closed = true; |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
321 } |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
322 } |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
323 |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
324 /** |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
325 * Makes all changes made since the previous commit/rollback |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
326 * permanent and releases any database locks currently held by this |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
327 * Connection object. This method should be used only when |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
328 * auto-commit mode has been disabled. |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
329 * |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
330 * @throws SQLException if a database access error occurs or this |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
331 * Connection object is in auto-commit mode |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
332 * @see #setAutoCommit(boolean) |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
333 */ |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
334 @Override |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
335 public void commit() throws SQLException { |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
336 // note: can't use sendIndependentCommand here because we need |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
337 // to process the auto_commit state the server gives |
77
83aee4f60649
Added private method sendTransactionCommand(String); to reduce duplicate code in 6 methods.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
47
diff
changeset
|
338 sendTransactionCommand("COMMIT"); |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
339 } |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
340 |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
341 /** |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
342 * Creates a Statement object for sending SQL statements to the |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
343 * database. SQL statements without parameters are normally |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
344 * executed using Statement objects. If the same SQL statement is |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
345 * executed many times, it may be more efficient to use a |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
346 * PreparedStatement object. |
45
c2bf983dc79b
Implemented Connection methods: getClientInfo(name) and getClientInfo().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
25
diff
changeset
|
347 * |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
348 * Result sets created using the returned Statement object will by |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
349 * default be type TYPE_FORWARD_ONLY and have a concurrency level of |
292
b127164342c4
Introduce default general behavior settings DEF_... for MonetResultSets and use them
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
288
diff
changeset
|
350 * CONCUR_READ_ONLY and a holdability of HOLD_CURSORS_OVER_COMMIT. |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
351 * |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
352 * @return a new default Statement object |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
353 * @throws SQLException if a database access error occurs |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
354 */ |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
355 @Override |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
356 public Statement createStatement() throws SQLException { |
292
b127164342c4
Introduce default general behavior settings DEF_... for MonetResultSets and use them
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
288
diff
changeset
|
357 return createStatement(MonetResultSet.DEF_RESULTSETTYPE, MonetResultSet.DEF_CONCURRENCY, MonetResultSet.DEF_HOLDABILITY); |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
358 } |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
359 |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
360 /** |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
361 * Creates a Statement object that will generate ResultSet objects |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
362 * with the given type and concurrency. This method is the same as |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
363 * the createStatement method above, but it allows the default |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
364 * result set type and concurrency to be overridden. |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
365 * |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
366 * @param resultSetType a result set type; one of |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
367 * ResultSet.TYPE_FORWARD_ONLY, ResultSet.TYPE_SCROLL_INSENSITIVE, |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
368 * or ResultSet.TYPE_SCROLL_SENSITIVE |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
369 * @param resultSetConcurrency a concurrency type; one of |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
370 * ResultSet.CONCUR_READ_ONLY or ResultSet.CONCUR_UPDATABLE |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
371 * @return a new Statement object that will generate ResultSet objects with |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
372 * the given type and concurrency |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
373 * @throws SQLException if a database access error occurs |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
374 */ |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
375 @Override |
295
003ae6d881db
Add "final" keyword to method arguments and local variables where possible.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
292
diff
changeset
|
376 public Statement createStatement(final int resultSetType, final int resultSetConcurrency) throws SQLException { |
292
b127164342c4
Introduce default general behavior settings DEF_... for MonetResultSets and use them
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
288
diff
changeset
|
377 return createStatement(resultSetType, resultSetConcurrency, MonetResultSet.DEF_HOLDABILITY); |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
378 } |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
379 |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
380 /** |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
381 * Creates a Statement object that will generate ResultSet objects |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
382 * with the given type, concurrency, and holdability. This method |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
383 * is the same as the createStatement method above, but it allows |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
384 * the default result set type, concurrency, and holdability to be |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
385 * overridden. |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
386 * |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
387 * @param resultSetType one of the following ResultSet constants: |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
388 * ResultSet.TYPE_FORWARD_ONLY, ResultSet.TYPE_SCROLL_INSENSITIVE, |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
389 * or ResultSet.TYPE_SCROLL_SENSITIVE |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
390 * @param resultSetConcurrency one of the following ResultSet |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
391 * constants: ResultSet.CONCUR_READ_ONLY or |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
392 * ResultSet.CONCUR_UPDATABLE |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
393 * @param resultSetHoldability one of the following ResultSet |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
394 * constants: ResultSet.HOLD_CURSORS_OVER_COMMIT or |
45
c2bf983dc79b
Implemented Connection methods: getClientInfo(name) and getClientInfo().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
25
diff
changeset
|
395 * ResultSet.CLOSE_CURSORS_AT_COMMIT |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
396 * |
697
68422d7f3961
Inline isValidProperty() in checkValidProperty() as it is the only place the method is called. Also add javadoc comments.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
696
diff
changeset
|
397 * @return a new Statement object that will generate ResultSet |
45
c2bf983dc79b
Implemented Connection methods: getClientInfo(name) and getClientInfo().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
25
diff
changeset
|
398 * objects with the given type, concurrency, and holdability |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
399 * @throws SQLException if a database access error occurs or the |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
400 * given parameters are not ResultSet constants indicating type, |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
401 * concurrency, and holdability |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
402 */ |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
403 @Override |
295
003ae6d881db
Add "final" keyword to method arguments and local variables where possible.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
292
diff
changeset
|
404 public Statement createStatement(final int resultSetType, final int resultSetConcurrency, final int resultSetHoldability) throws SQLException { |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
405 try { |
295
003ae6d881db
Add "final" keyword to method arguments and local variables where possible.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
292
diff
changeset
|
406 final Statement ret = new MonetStatement(this, resultSetType, resultSetConcurrency, resultSetHoldability); |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
407 // store it in the map for when we close... |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
408 statements.put(ret, null); |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
409 return ret; |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
410 } catch (IllegalArgumentException e) { |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
411 throw new SQLException(e.toString(), "M0M03"); |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
412 } |
271
4880267d0fe1
Added implementation of java.sql.CallableStatement interface, test program and updated the ChangeLog and release notes.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
266
diff
changeset
|
413 // we don't have to catch SQLException because that is declared to be thrown |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
414 } |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
415 |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
416 /** |
77
83aee4f60649
Added private method sendTransactionCommand(String); to reduce duplicate code in 6 methods.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
47
diff
changeset
|
417 * Retrieves the current auto-commit mode for this Connection object. |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
418 * |
77
83aee4f60649
Added private method sendTransactionCommand(String); to reduce duplicate code in 6 methods.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
47
diff
changeset
|
419 * @return the current state of this Connection object's auto-commit mode |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
420 * @see #setAutoCommit(boolean) |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
421 */ |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
422 @Override |
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
|
423 public boolean getAutoCommit() { |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
424 return autoCommit; |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
425 } |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
426 |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
427 /** |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
428 * Retrieves this Connection object's current catalog name. |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
429 * |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
430 * @return the current catalog name or null if there is none |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
431 */ |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
432 @Override |
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
|
433 public String getCatalog() { |
697
68422d7f3961
Inline isValidProperty() in checkValidProperty() as it is the only place the method is called. Also add javadoc comments.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
696
diff
changeset
|
434 // MonetDB does NOT support catalog names or qualifiers |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
435 return null; |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
436 } |
77
83aee4f60649
Added private method sendTransactionCommand(String); to reduce duplicate code in 6 methods.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
47
diff
changeset
|
437 |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
438 /** |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
439 * Retrieves the current holdability of ResultSet objects created |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
440 * using this Connection object. |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
441 * |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
442 * @return the holdability, one of |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
443 * ResultSet.HOLD_CURSORS_OVER_COMMIT or |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
444 * ResultSet.CLOSE_CURSORS_AT_COMMIT |
194
1296dbcc4958
Resolved javadoc many errors and warnings, such as:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
186
diff
changeset
|
445 * @see #setHoldability(int) |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
446 */ |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
447 @Override |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
448 public int getHoldability() { |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
449 // TODO: perhaps it is better to have the server implement |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
450 // CLOSE_CURSORS_AT_COMMIT |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
451 return ResultSet.HOLD_CURSORS_OVER_COMMIT; |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
452 } |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
453 |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
454 /** |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
455 * Retrieves a DatabaseMetaData object that contains metadata about |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
456 * the database to which this Connection object represents a |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
457 * connection. The metadata includes information about the |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
458 * database's tables, its supported SQL grammar, its stored |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
459 * procedures, the capabilities of this connection, and so on. |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
460 * |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
461 * @throws SQLException if the current language is not SQL |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
462 * @return a DatabaseMetaData object for this Connection object |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
463 */ |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
464 @Override |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
465 public DatabaseMetaData getMetaData() throws SQLException { |
472
0e21097f438b
Reduce the number of MonetDatabaseMetaData objects created via getMetaData() to maximum 1 per connection as it can be reused.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
451
diff
changeset
|
466 // for debug: System.out.println("calling getMetaData()"); |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
467 if (lang != LANG_SQL) |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
468 throw new SQLException("This method is only supported in SQL mode", "M0M04"); |
472
0e21097f438b
Reduce the number of MonetDatabaseMetaData objects created via getMetaData() to maximum 1 per connection as it can be reused.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
451
diff
changeset
|
469 if (dbmd == null) { |
0e21097f438b
Reduce the number of MonetDatabaseMetaData objects created via getMetaData() to maximum 1 per connection as it can be reused.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
451
diff
changeset
|
470 // first use, construct it once and reuse it for all next calls |
0e21097f438b
Reduce the number of MonetDatabaseMetaData objects created via getMetaData() to maximum 1 per connection as it can be reused.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
451
diff
changeset
|
471 dbmd = new MonetDatabaseMetaData(this); |
0e21097f438b
Reduce the number of MonetDatabaseMetaData objects created via getMetaData() to maximum 1 per connection as it can be reused.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
451
diff
changeset
|
472 } |
0e21097f438b
Reduce the number of MonetDatabaseMetaData objects created via getMetaData() to maximum 1 per connection as it can be reused.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
451
diff
changeset
|
473 return dbmd; |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
474 } |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
475 |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
476 /** |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
477 * Retrieves this Connection object's current transaction isolation |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
478 * level. |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
479 * |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
480 * @return the current transaction isolation level, which will be |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
481 * Connection.TRANSACTION_SERIALIZABLE |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
482 */ |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
483 @Override |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
484 public int getTransactionIsolation() { |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
485 return TRANSACTION_SERIALIZABLE; |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
486 } |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
487 |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
488 /** |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
489 * Retrieves the Map object associated with this Connection object. |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
490 * Unless the application has added an entry, the type map returned |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
491 * will be empty. |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
492 * |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
493 * @return the java.util.Map object associated with this Connection |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
494 * object |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
495 */ |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
496 @Override |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
497 public Map<String,Class<?>> getTypeMap() { |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
498 return typeMap; |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
499 } |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
500 |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
501 /** |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
502 * Retrieves the first warning reported by calls on this Connection |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
503 * object. If there is more than one warning, subsequent warnings |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
504 * will be chained to the first one and can be retrieved by calling |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
505 * the method SQLWarning.getNextWarning on the warning that was |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
506 * retrieved previously. |
45
c2bf983dc79b
Implemented Connection methods: getClientInfo(name) and getClientInfo().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
25
diff
changeset
|
507 * |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
508 * This method may not be called on a closed connection; doing so |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
509 * will cause an SQLException to be thrown. |
45
c2bf983dc79b
Implemented Connection methods: getClientInfo(name) and getClientInfo().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
25
diff
changeset
|
510 * |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
511 * Note: Subsequent warnings will be chained to this SQLWarning. |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
512 * |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
513 * @return the first SQLWarning object or null if there are none |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
514 * @throws SQLException if a database access error occurs or this method is |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
515 * called on a closed connection |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
516 */ |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
517 @Override |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
518 public SQLWarning getWarnings() throws SQLException { |
348
bcb9a99d399d
Add private checkNotClosed() method to check if the connection is not closed.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
345
diff
changeset
|
519 checkNotClosed(); |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
520 // if there are no warnings, this will be null, which fits with the |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
521 // specification. |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
522 return warnings; |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
523 } |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
524 |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
525 /** |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
526 * Retrieves whether this Connection object has been closed. A |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
527 * connection is closed if the method close has been called on it or |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
528 * if certain fatal errors have occurred. This method is guaranteed |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
529 * to return true only when it is called after the method |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
530 * Connection.close has been called. |
45
c2bf983dc79b
Implemented Connection methods: getClientInfo(name) and getClientInfo().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
25
diff
changeset
|
531 * |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
532 * This method generally cannot be called to determine whether a |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
533 * connection to a database is valid or invalid. A typical client |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
534 * can determine that a connection is invalid by catching any |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
535 * exceptions that might be thrown when an operation is attempted. |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
536 * |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
537 * @return true if this Connection object is closed; false if it is |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
538 * still open |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
539 */ |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
540 @Override |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
541 public boolean isClosed() { |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
542 return closed; |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
543 } |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
544 |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
545 /** |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
546 * Retrieves whether this Connection object is in read-only mode. |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
547 * MonetDB currently doesn't support updateable result sets, but |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
548 * updates are possible. Hence the Connection object is never in |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
549 * read-only mode. |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
550 * |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
551 * @return true if this Connection object is read-only; false otherwise |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
552 */ |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
553 @Override |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
554 public boolean isReadOnly() { |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
555 return false; |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
556 } |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
557 |
184
e0f76fedafc8
Corrected implementation of Connection.prepareCall() methods. They used to return null.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
178
diff
changeset
|
558 /** |
e0f76fedafc8
Corrected implementation of Connection.prepareCall() methods. They used to return null.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
178
diff
changeset
|
559 * Converts the given SQL statement into the system's native SQL grammar. |
e0f76fedafc8
Corrected implementation of Connection.prepareCall() methods. They used to return null.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
178
diff
changeset
|
560 * A driver may convert the JDBC SQL grammar into its system's native SQL grammar prior to sending it. |
e0f76fedafc8
Corrected implementation of Connection.prepareCall() methods. They used to return null.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
178
diff
changeset
|
561 * This method returns the native form of the statement that the driver would have sent. |
e0f76fedafc8
Corrected implementation of Connection.prepareCall() methods. They used to return null.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
178
diff
changeset
|
562 * |
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
|
563 * @param sql - an SQL statement that may contain one or more '?' parameter placeholders. |
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
|
564 * @return the native form of this statement |
184
e0f76fedafc8
Corrected implementation of Connection.prepareCall() methods. They used to return null.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
178
diff
changeset
|
565 */ |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
566 @Override |
295
003ae6d881db
Add "final" keyword to method arguments and local variables where possible.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
292
diff
changeset
|
567 public String nativeSQL(final String sql) { |
77
83aee4f60649
Added private method sendTransactionCommand(String); to reduce duplicate code in 6 methods.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
47
diff
changeset
|
568 /* there is currently no way to get the native MonetDB rewritten SQL string back, so just return the original string */ |
83aee4f60649
Added private method sendTransactionCommand(String); to reduce duplicate code in 6 methods.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
47
diff
changeset
|
569 return sql; |
83aee4f60649
Added private method sendTransactionCommand(String); to reduce duplicate code in 6 methods.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
47
diff
changeset
|
570 } |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
571 |
184
e0f76fedafc8
Corrected implementation of Connection.prepareCall() methods. They used to return null.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
178
diff
changeset
|
572 /** |
e0f76fedafc8
Corrected implementation of Connection.prepareCall() methods. They used to return null.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
178
diff
changeset
|
573 * Creates a CallableStatement object for calling database stored procedures. |
e0f76fedafc8
Corrected implementation of Connection.prepareCall() methods. They used to return null.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
178
diff
changeset
|
574 * The CallableStatement object provides methods for setting up its IN and OUT parameters, |
e0f76fedafc8
Corrected implementation of Connection.prepareCall() methods. They used to return null.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
178
diff
changeset
|
575 * and methods for executing the call to a stored procedure. |
e0f76fedafc8
Corrected implementation of Connection.prepareCall() methods. They used to return null.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
178
diff
changeset
|
576 * |
e0f76fedafc8
Corrected implementation of Connection.prepareCall() methods. They used to return null.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
178
diff
changeset
|
577 * Note: This method is optimized for handling stored procedure call statements. |
e0f76fedafc8
Corrected implementation of Connection.prepareCall() methods. They used to return null.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
178
diff
changeset
|
578 * Some drivers may send the call statement to the database when the method prepareCall is done; |
e0f76fedafc8
Corrected implementation of Connection.prepareCall() methods. They used to return null.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
178
diff
changeset
|
579 * others may wait until the CallableStatement object is executed. This has no direct effect |
e0f76fedafc8
Corrected implementation of Connection.prepareCall() methods. They used to return null.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
178
diff
changeset
|
580 * on users; however, it does affect which method throws certain SQLExceptions. |
e0f76fedafc8
Corrected implementation of Connection.prepareCall() methods. They used to return null.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
178
diff
changeset
|
581 * |
e0f76fedafc8
Corrected implementation of Connection.prepareCall() methods. They used to return null.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
178
diff
changeset
|
582 * Result sets created using the returned CallableStatement object will by default be type TYPE_FORWARD_ONLY |
e0f76fedafc8
Corrected implementation of Connection.prepareCall() methods. They used to return null.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
178
diff
changeset
|
583 * and have a concurrency level of CONCUR_READ_ONLY. |
e0f76fedafc8
Corrected implementation of Connection.prepareCall() methods. They used to return null.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
178
diff
changeset
|
584 * The holdability of the created result sets can be determined by calling getHoldability(). |
e0f76fedafc8
Corrected implementation of Connection.prepareCall() methods. They used to return null.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
178
diff
changeset
|
585 * |
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
|
586 * @param sql - an SQL statement that may contain one or more '?' parameter placeholders. |
184
e0f76fedafc8
Corrected implementation of Connection.prepareCall() methods. They used to return null.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
178
diff
changeset
|
587 * Typically this statement is specified using JDBC call escape syntax. |
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
|
588 * @return a new default CallableStatement object containing the pre-compiled SQL statement |
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
|
589 * @throws SQLException - if a database access error occurs or this method is called on a closed connection |
184
e0f76fedafc8
Corrected implementation of Connection.prepareCall() methods. They used to return null.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
178
diff
changeset
|
590 */ |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
591 @Override |
295
003ae6d881db
Add "final" keyword to method arguments and local variables where possible.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
292
diff
changeset
|
592 public CallableStatement prepareCall(final String sql) throws SQLException { |
292
b127164342c4
Introduce default general behavior settings DEF_... for MonetResultSets and use them
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
288
diff
changeset
|
593 return prepareCall(sql, MonetResultSet.DEF_RESULTSETTYPE, MonetResultSet.DEF_CONCURRENCY, MonetResultSet.DEF_HOLDABILITY); |
77
83aee4f60649
Added private method sendTransactionCommand(String); to reduce duplicate code in 6 methods.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
47
diff
changeset
|
594 } |
45
c2bf983dc79b
Implemented Connection methods: getClientInfo(name) and getClientInfo().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
25
diff
changeset
|
595 |
184
e0f76fedafc8
Corrected implementation of Connection.prepareCall() methods. They used to return null.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
178
diff
changeset
|
596 /** |
e0f76fedafc8
Corrected implementation of Connection.prepareCall() methods. They used to return null.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
178
diff
changeset
|
597 * Creates a CallableStatement object that will generate ResultSet objects with the given type and concurrency. |
e0f76fedafc8
Corrected implementation of Connection.prepareCall() methods. They used to return null.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
178
diff
changeset
|
598 * This method is the same as the prepareCall method above, but it allows the default result set type and concurrency to be overridden. |
e0f76fedafc8
Corrected implementation of Connection.prepareCall() methods. They used to return null.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
178
diff
changeset
|
599 * The holdability of the created result sets can be determined by calling getHoldability(). |
e0f76fedafc8
Corrected implementation of Connection.prepareCall() methods. They used to return null.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
178
diff
changeset
|
600 * |
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
|
601 * @param sql - a String object that is the SQL statement to be sent to the database; may contain on or more '?' parameters |
184
e0f76fedafc8
Corrected implementation of Connection.prepareCall() methods. They used to return null.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
178
diff
changeset
|
602 * Typically this statement is specified using JDBC call escape syntax. |
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
|
603 * @param resultSetType - a result set type; one of ResultSet.TYPE_FORWARD_ONLY, ResultSet.TYPE_SCROLL_INSENSITIVE, or ResultSet.TYPE_SCROLL_SENSITIVE |
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
|
604 * @param resultSetConcurrency - a concurrency type; one of ResultSet.CONCUR_READ_ONLY or ResultSet.CONCUR_UPDATABLE |
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
|
605 * @return a new CallableStatement object containing the pre-compiled SQL statement that |
184
e0f76fedafc8
Corrected implementation of Connection.prepareCall() methods. They used to return null.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
178
diff
changeset
|
606 * will produce ResultSet objects with the given type and concurrency |
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
|
607 * @throws SQLException - if a database access error occurs, this method is called on a closed connection or |
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
|
608 * the given parameters are not ResultSet constants indicating type and concurrency |
184
e0f76fedafc8
Corrected implementation of Connection.prepareCall() methods. They used to return null.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
178
diff
changeset
|
609 */ |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
610 @Override |
295
003ae6d881db
Add "final" keyword to method arguments and local variables where possible.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
292
diff
changeset
|
611 public CallableStatement prepareCall(final String sql, final int resultSetType, final int resultSetConcurrency) throws SQLException { |
292
b127164342c4
Introduce default general behavior settings DEF_... for MonetResultSets and use them
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
288
diff
changeset
|
612 return prepareCall(sql, resultSetType, resultSetConcurrency, MonetResultSet.DEF_HOLDABILITY); |
77
83aee4f60649
Added private method sendTransactionCommand(String); to reduce duplicate code in 6 methods.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
47
diff
changeset
|
613 } |
45
c2bf983dc79b
Implemented Connection methods: getClientInfo(name) and getClientInfo().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
25
diff
changeset
|
614 |
184
e0f76fedafc8
Corrected implementation of Connection.prepareCall() methods. They used to return null.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
178
diff
changeset
|
615 /** |
e0f76fedafc8
Corrected implementation of Connection.prepareCall() methods. They used to return null.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
178
diff
changeset
|
616 * Creates a CallableStatement object that will generate ResultSet objects with the given type and concurrency. |
e0f76fedafc8
Corrected implementation of Connection.prepareCall() methods. They used to return null.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
178
diff
changeset
|
617 * This method is the same as the prepareCall method above, but it allows the default result set type, result set concurrency type and holdability to be overridden. |
e0f76fedafc8
Corrected implementation of Connection.prepareCall() methods. They used to return null.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
178
diff
changeset
|
618 * |
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
|
619 * @param sql - a String object that is the SQL statement to be sent to the database; may contain on or more '?' parameters |
184
e0f76fedafc8
Corrected implementation of Connection.prepareCall() methods. They used to return null.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
178
diff
changeset
|
620 * Typically this statement is specified using JDBC call escape syntax. |
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
|
621 * @param resultSetType - a result set type; one of ResultSet.TYPE_FORWARD_ONLY, ResultSet.TYPE_SCROLL_INSENSITIVE, or ResultSet.TYPE_SCROLL_SENSITIVE |
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
|
622 * @param resultSetConcurrency - a concurrency type; one of ResultSet.CONCUR_READ_ONLY or ResultSet.CONCUR_UPDATABLE |
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
|
623 * @param resultSetHoldability - one of the following ResultSet constants: ResultSet.HOLD_CURSORS_OVER_COMMIT or ResultSet.CLOSE_CURSORS_AT_COMMIT |
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
|
624 * @return a new CallableStatement object, containing the pre-compiled SQL statement, that will generate ResultSet objects with the given type, concurrency, and holdability |
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
|
625 * @throws SQLException - if a database access error occurs, this method is called on a closed connection or |
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
|
626 * the given parameters are not ResultSet constants indicating type, concurrency, and holdability |
184
e0f76fedafc8
Corrected implementation of Connection.prepareCall() methods. They used to return null.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
178
diff
changeset
|
627 */ |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
628 @Override |
295
003ae6d881db
Add "final" keyword to method arguments and local variables where possible.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
292
diff
changeset
|
629 public CallableStatement prepareCall(final String sql, final int resultSetType, final int resultSetConcurrency, final int resultSetHoldability) |
184
e0f76fedafc8
Corrected implementation of Connection.prepareCall() methods. They used to return null.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
178
diff
changeset
|
630 throws SQLException |
e0f76fedafc8
Corrected implementation of Connection.prepareCall() methods. They used to return null.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
178
diff
changeset
|
631 { |
348
bcb9a99d399d
Add private checkNotClosed() method to check if the connection is not closed.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
345
diff
changeset
|
632 checkNotClosed(); |
692
2233b172e06d
Add checks for sql String parameter to prevent NullPointerException or executing an empty sql String.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
690
diff
changeset
|
633 |
2233b172e06d
Add checks for sql String parameter to prevent NullPointerException or executing an empty sql String.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
690
diff
changeset
|
634 if (sql == null || sql.isEmpty()) |
2233b172e06d
Add checks for sql String parameter to prevent NullPointerException or executing an empty sql String.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
690
diff
changeset
|
635 throw new SQLException("Missing SQL statement", "M1M05"); |
2233b172e06d
Add checks for sql String parameter to prevent NullPointerException or executing an empty sql String.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
690
diff
changeset
|
636 |
271
4880267d0fe1
Added implementation of java.sql.CallableStatement interface, test program and updated the ChangeLog and release notes.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
266
diff
changeset
|
637 try { |
295
003ae6d881db
Add "final" keyword to method arguments and local variables where possible.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
292
diff
changeset
|
638 final CallableStatement ret = new MonetCallableStatement( |
271
4880267d0fe1
Added implementation of java.sql.CallableStatement interface, test program and updated the ChangeLog and release notes.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
266
diff
changeset
|
639 this, |
4880267d0fe1
Added implementation of java.sql.CallableStatement interface, test program and updated the ChangeLog and release notes.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
266
diff
changeset
|
640 resultSetType, |
4880267d0fe1
Added implementation of java.sql.CallableStatement interface, test program and updated the ChangeLog and release notes.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
266
diff
changeset
|
641 resultSetConcurrency, |
4880267d0fe1
Added implementation of java.sql.CallableStatement interface, test program and updated the ChangeLog and release notes.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
266
diff
changeset
|
642 resultSetHoldability, |
4880267d0fe1
Added implementation of java.sql.CallableStatement interface, test program and updated the ChangeLog and release notes.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
266
diff
changeset
|
643 sql |
4880267d0fe1
Added implementation of java.sql.CallableStatement interface, test program and updated the ChangeLog and release notes.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
266
diff
changeset
|
644 ); |
4880267d0fe1
Added implementation of java.sql.CallableStatement interface, test program and updated the ChangeLog and release notes.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
266
diff
changeset
|
645 // store it in the map for when we close... |
4880267d0fe1
Added implementation of java.sql.CallableStatement interface, test program and updated the ChangeLog and release notes.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
266
diff
changeset
|
646 statements.put(ret, null); |
4880267d0fe1
Added implementation of java.sql.CallableStatement interface, test program and updated the ChangeLog and release notes.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
266
diff
changeset
|
647 return ret; |
4880267d0fe1
Added implementation of java.sql.CallableStatement interface, test program and updated the ChangeLog and release notes.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
266
diff
changeset
|
648 } catch (IllegalArgumentException e) { |
4880267d0fe1
Added implementation of java.sql.CallableStatement interface, test program and updated the ChangeLog and release notes.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
266
diff
changeset
|
649 throw new SQLException(e.toString(), "M0M03"); |
4880267d0fe1
Added implementation of java.sql.CallableStatement interface, test program and updated the ChangeLog and release notes.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
266
diff
changeset
|
650 } |
4880267d0fe1
Added implementation of java.sql.CallableStatement interface, test program and updated the ChangeLog and release notes.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
266
diff
changeset
|
651 // we don't have to catch SQLException because that is declared to be thrown |
77
83aee4f60649
Added private method sendTransactionCommand(String); to reduce duplicate code in 6 methods.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
47
diff
changeset
|
652 } |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
653 |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
654 /** |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
655 * Creates a PreparedStatement object for sending parameterized SQL |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
656 * statements to the database. |
45
c2bf983dc79b
Implemented Connection methods: getClientInfo(name) and getClientInfo().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
25
diff
changeset
|
657 * |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
658 * A SQL statement with or without IN parameters can be pre-compiled |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
659 * and stored in a PreparedStatement object. This object can then be |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
660 * used to efficiently execute this statement multiple times. |
45
c2bf983dc79b
Implemented Connection methods: getClientInfo(name) and getClientInfo().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
25
diff
changeset
|
661 * |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
662 * Note: This method is optimized for handling parametric SQL |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
663 * statements that benefit from precompilation. If the driver |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
664 * supports precompilation, the method prepareStatement will send |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
665 * the statement to the database for precompilation. Some drivers |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
666 * may not support precompilation. In this case, the statement may |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
667 * not be sent to the database until the PreparedStatement object is |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
668 * executed. This has no direct effect on users; however, it does |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
669 * affect which methods throw certain SQLException objects. |
45
c2bf983dc79b
Implemented Connection methods: getClientInfo(name) and getClientInfo().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
25
diff
changeset
|
670 * |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
671 * Result sets created using the returned PreparedStatement object |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
672 * will by default be type TYPE_FORWARD_ONLY and have a concurrency |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
673 * level of CONCUR_READ_ONLY. |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
674 * |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
675 * @param sql an SQL statement that may contain one or more '?' IN |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
676 * parameter placeholders |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
677 * @return a new default PreparedStatement object containing the |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
678 * pre-compiled SQL statement |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
679 * @throws SQLException if a database access error occurs |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
680 */ |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
681 @Override |
295
003ae6d881db
Add "final" keyword to method arguments and local variables where possible.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
292
diff
changeset
|
682 public PreparedStatement prepareStatement(final String sql) throws SQLException { |
292
b127164342c4
Introduce default general behavior settings DEF_... for MonetResultSets and use them
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
288
diff
changeset
|
683 return prepareStatement(sql, MonetResultSet.DEF_RESULTSETTYPE, MonetResultSet.DEF_CONCURRENCY, MonetResultSet.DEF_HOLDABILITY); |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
684 } |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
685 |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
686 /** |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
687 * Creates a PreparedStatement object that will generate ResultSet |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
688 * objects with the given type and concurrency. This method is the |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
689 * same as the prepareStatement method above, but it allows the |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
690 * default result set type and concurrency to be overridden. |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
691 * |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
692 * @param sql a String object that is the SQL statement to be sent to the |
144
d6abd1ffffbb
Use SQLNonTransientConnectionException instead of SQLException where applicable (SQLState starts with 08)
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
136
diff
changeset
|
693 * database; may contain one or more ? IN parameters |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
694 * @param resultSetType a result set type; one of |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
695 * ResultSet.TYPE_FORWARD_ONLY, ResultSet.TYPE_SCROLL_INSENSITIVE, |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
696 * or ResultSet.TYPE_SCROLL_SENSITIVE |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
697 * @param resultSetConcurrency a concurrency type; one of |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
698 * ResultSet.CONCUR_READ_ONLY or ResultSet.CONCUR_UPDATABLE |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
699 * @return a new PreparedStatement object containing the pre-compiled SQL |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
700 * statement that will produce ResultSet objects with the given |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
701 * type and concurrency |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
702 * @throws SQLException if a database access error occurs or the given |
144
d6abd1ffffbb
Use SQLNonTransientConnectionException instead of SQLException where applicable (SQLState starts with 08)
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
136
diff
changeset
|
703 * parameters are not ResultSet constants indicating |
d6abd1ffffbb
Use SQLNonTransientConnectionException instead of SQLException where applicable (SQLState starts with 08)
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
136
diff
changeset
|
704 * type and concurrency |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
705 */ |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
706 @Override |
295
003ae6d881db
Add "final" keyword to method arguments and local variables where possible.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
292
diff
changeset
|
707 public PreparedStatement prepareStatement(final String sql, final int resultSetType, final int resultSetConcurrency) throws SQLException { |
292
b127164342c4
Introduce default general behavior settings DEF_... for MonetResultSets and use them
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
288
diff
changeset
|
708 return prepareStatement(sql, resultSetType, resultSetConcurrency, MonetResultSet.DEF_HOLDABILITY); |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
709 } |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
710 |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
711 /** |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
712 * Creates a PreparedStatement object that will generate ResultSet |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
713 * objects with the given type, concurrency, and holdability. |
45
c2bf983dc79b
Implemented Connection methods: getClientInfo(name) and getClientInfo().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
25
diff
changeset
|
714 * |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
715 * This method is the same as the prepareStatement method above, but |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
716 * it allows the default result set type, concurrency, and |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
717 * holdability to be overridden. |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
718 * |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
719 * @param sql a String object that is the SQL statement to be sent |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
720 * to the database; may contain one or more ? IN parameters |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
721 * @param resultSetType one of the following ResultSet constants: |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
722 * ResultSet.TYPE_FORWARD_ONLY, ResultSet.TYPE_SCROLL_INSENSITIVE, |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
723 * or ResultSet.TYPE_SCROLL_SENSITIVE |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
724 * @param resultSetConcurrency one of the following ResultSet |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
725 * constants: ResultSet.CONCUR_READ_ONLY or |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
726 * ResultSet.CONCUR_UPDATABLE |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
727 * @param resultSetHoldability one of the following ResultSet |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
728 * constants: ResultSet.HOLD_CURSORS_OVER_COMMIT or |
45
c2bf983dc79b
Implemented Connection methods: getClientInfo(name) and getClientInfo().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
25
diff
changeset
|
729 * ResultSet.CLOSE_CURSORS_AT_COMMIT |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
730 * @return a new PreparedStatement object, containing the |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
731 * pre-compiled SQL statement, that will generate ResultSet objects |
45
c2bf983dc79b
Implemented Connection methods: getClientInfo(name) and getClientInfo().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
25
diff
changeset
|
732 * with the given type, concurrency, and holdability |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
733 * @throws SQLException if a database access error occurs or the |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
734 * given parameters are not ResultSet constants indicating type, |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
735 * concurrency, and holdability |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
736 */ |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
737 @Override |
295
003ae6d881db
Add "final" keyword to method arguments and local variables where possible.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
292
diff
changeset
|
738 public PreparedStatement prepareStatement(final String sql, final int resultSetType, final int resultSetConcurrency, final int resultSetHoldability) |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
739 throws SQLException |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
740 { |
348
bcb9a99d399d
Add private checkNotClosed() method to check if the connection is not closed.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
345
diff
changeset
|
741 checkNotClosed(); |
692
2233b172e06d
Add checks for sql String parameter to prevent NullPointerException or executing an empty sql String.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
690
diff
changeset
|
742 |
2233b172e06d
Add checks for sql String parameter to prevent NullPointerException or executing an empty sql String.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
690
diff
changeset
|
743 if (sql == null || sql.isEmpty()) |
2233b172e06d
Add checks for sql String parameter to prevent NullPointerException or executing an empty sql String.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
690
diff
changeset
|
744 throw new SQLException("Missing SQL statement", "M1M05"); |
2233b172e06d
Add checks for sql String parameter to prevent NullPointerException or executing an empty sql String.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
690
diff
changeset
|
745 |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
746 try { |
295
003ae6d881db
Add "final" keyword to method arguments and local variables where possible.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
292
diff
changeset
|
747 final PreparedStatement ret = new MonetPreparedStatement( |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
748 this, |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
749 resultSetType, |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
750 resultSetConcurrency, |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
751 resultSetHoldability, |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
752 sql |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
753 ); |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
754 // store it in the map for when we close... |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
755 statements.put(ret, null); |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
756 return ret; |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
757 } catch (IllegalArgumentException e) { |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
758 throw new SQLException(e.toString(), "M0M03"); |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
759 } |
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
|
760 // we don't have to catch SQLException because that is declared to be thrown |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
761 } |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
762 |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
763 /** |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
764 * Creates a default PreparedStatement object that has the |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
765 * capability to retrieve auto-generated keys. The given constant |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
766 * tells the driver whether it should make auto-generated keys |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
767 * available for retrieval. This parameter is ignored if the SQL |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
768 * statement is not an INSERT statement. |
45
c2bf983dc79b
Implemented Connection methods: getClientInfo(name) and getClientInfo().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
25
diff
changeset
|
769 * |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
770 * Note: This method is optimized for handling parametric SQL |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
771 * statements that benefit from precompilation. If the driver |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
772 * supports precompilation, the method prepareStatement will send |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
773 * the statement to the database for precompilation. Some drivers |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
774 * may not support precompilation. In this case, the statement may |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
775 * not be sent to the database until the PreparedStatement object is |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
776 * executed. This has no direct effect on users; however, it does |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
777 * affect which methods throw certain SQLExceptions. |
45
c2bf983dc79b
Implemented Connection methods: getClientInfo(name) and getClientInfo().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
25
diff
changeset
|
778 * |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
779 * Result sets created using the returned PreparedStatement object |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
780 * will by default be type TYPE_FORWARD_ONLY and have a concurrency |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
781 * level of CONCUR_READ_ONLY. |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
782 * |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
783 * @param sql an SQL statement that may contain one or more '?' IN |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
784 * parameter placeholders |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
785 * @param autoGeneratedKeys a flag indicating whether auto-generated |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
786 * keys should be returned; one of |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
787 * Statement.RETURN_GENERATED_KEYS or |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
788 * Statement.NO_GENERATED_KEYS |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
789 * @return a new PreparedStatement object, containing the |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
790 * pre-compiled SQL statement, that will have the capability |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
791 * of returning auto-generated keys |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
792 * @throws SQLException - if a database access error occurs or the |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
793 * given parameter is not a Statement constant indicating |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
794 * whether auto-generated keys should be returned |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
795 */ |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
796 @Override |
295
003ae6d881db
Add "final" keyword to method arguments and local variables where possible.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
292
diff
changeset
|
797 public PreparedStatement prepareStatement(final String sql, final int autoGeneratedKeys) throws SQLException { |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
798 if (autoGeneratedKeys != Statement.RETURN_GENERATED_KEYS && |
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
|
799 autoGeneratedKeys != Statement.NO_GENERATED_KEYS) |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
800 throw new SQLException("Invalid argument, expected RETURN_GENERATED_KEYS or NO_GENERATED_KEYS", "M1M05"); |
77
83aee4f60649
Added private method sendTransactionCommand(String); to reduce duplicate code in 6 methods.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
47
diff
changeset
|
801 |
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
|
802 /* MonetDB has no way to disable this, so just do the normal thing ;) */ |
292
b127164342c4
Introduce default general behavior settings DEF_... for MonetResultSets and use them
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
288
diff
changeset
|
803 return prepareStatement(sql, MonetResultSet.DEF_RESULTSETTYPE, MonetResultSet.DEF_CONCURRENCY, MonetResultSet.DEF_HOLDABILITY); |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
804 } |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
805 |
77
83aee4f60649
Added private method sendTransactionCommand(String); to reduce duplicate code in 6 methods.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
47
diff
changeset
|
806 /** |
83aee4f60649
Added private method sendTransactionCommand(String); to reduce duplicate code in 6 methods.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
47
diff
changeset
|
807 * Creates a default PreparedStatement object capable of returning the auto-generated keys designated by the given array. |
83aee4f60649
Added private method sendTransactionCommand(String); to reduce duplicate code in 6 methods.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
47
diff
changeset
|
808 * This array contains the indexes of the columns in the target table that contain the auto-generated keys that should be made available. |
83aee4f60649
Added private method sendTransactionCommand(String); to reduce duplicate code in 6 methods.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
47
diff
changeset
|
809 * The driver will ignore the array if the SQL statement is not an INSERT statement, or an SQL statement able to |
83aee4f60649
Added private method sendTransactionCommand(String); to reduce duplicate code in 6 methods.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
47
diff
changeset
|
810 * return auto-generated keys (the list of such statements is vendor-specific). |
83aee4f60649
Added private method sendTransactionCommand(String); to reduce duplicate code in 6 methods.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
47
diff
changeset
|
811 * |
83aee4f60649
Added private method sendTransactionCommand(String); to reduce duplicate code in 6 methods.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
47
diff
changeset
|
812 * An SQL statement with or without IN parameters can be pre-compiled and stored in a PreparedStatement object. |
83aee4f60649
Added private method sendTransactionCommand(String); to reduce duplicate code in 6 methods.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
47
diff
changeset
|
813 * This object can then be used to efficiently execute this statement multiple times. |
83aee4f60649
Added private method sendTransactionCommand(String); to reduce duplicate code in 6 methods.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
47
diff
changeset
|
814 * |
83aee4f60649
Added private method sendTransactionCommand(String); to reduce duplicate code in 6 methods.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
47
diff
changeset
|
815 * Note: This method is optimized for handling parametric SQL statements that benefit from precompilation. |
83aee4f60649
Added private method sendTransactionCommand(String); to reduce duplicate code in 6 methods.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
47
diff
changeset
|
816 * If the driver supports precompilation, the method prepareStatement will send the statement to the database for precompilation. |
83aee4f60649
Added private method sendTransactionCommand(String); to reduce duplicate code in 6 methods.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
47
diff
changeset
|
817 * Some drivers may not support precompilation. In this case, the statement may not be sent to the database until the PreparedStatement |
83aee4f60649
Added private method sendTransactionCommand(String); to reduce duplicate code in 6 methods.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
47
diff
changeset
|
818 * object is executed. This has no direct effect on users; however, it does affect which methods throw certain SQLExceptions. |
83aee4f60649
Added private method sendTransactionCommand(String); to reduce duplicate code in 6 methods.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
47
diff
changeset
|
819 * |
83aee4f60649
Added private method sendTransactionCommand(String); to reduce duplicate code in 6 methods.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
47
diff
changeset
|
820 * Result sets created using the returned PreparedStatement object will by default be type TYPE_FORWARD_ONLY and have |
83aee4f60649
Added private method sendTransactionCommand(String); to reduce duplicate code in 6 methods.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
47
diff
changeset
|
821 * a concurrency level of CONCUR_READ_ONLY. The holdability of the created result sets can be determined by calling getHoldability(). |
83aee4f60649
Added private method sendTransactionCommand(String); to reduce duplicate code in 6 methods.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
47
diff
changeset
|
822 * |
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
|
823 * @param sql - an SQL statement that may contain one or more '?' IN parameter placeholders |
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
|
824 * @param columnIndexes - an array of column indexes indicating the columns that should be returned from the inserted row or rows |
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
|
825 * @return a new PreparedStatement object, containing the pre-compiled statement, that is capable of |
414
1e278695fe54
Small improvements: adding some final keywords, removing unnecesary initialisations, improve comments.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
408
diff
changeset
|
826 * returning the auto-generated keys designated by the given array of column indexes |
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
|
827 * @throws SQLException - if a database access error occurs or this method is called on a closed connection |
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
|
828 * @throws SQLFeatureNotSupportedException - if the JDBC driver does not support this method |
77
83aee4f60649
Added private method sendTransactionCommand(String); to reduce duplicate code in 6 methods.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
47
diff
changeset
|
829 */ |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
830 @Override |
295
003ae6d881db
Add "final" keyword to method arguments and local variables where possible.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
292
diff
changeset
|
831 public PreparedStatement prepareStatement(final String sql, final int[] columnIndexes) 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
|
832 throw newSQLFeatureNotSupportedException("prepareStatement(String sql, int[] columnIndexes)"); |
77
83aee4f60649
Added private method sendTransactionCommand(String); to reduce duplicate code in 6 methods.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
47
diff
changeset
|
833 } |
45
c2bf983dc79b
Implemented Connection methods: getClientInfo(name) and getClientInfo().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
25
diff
changeset
|
834 |
77
83aee4f60649
Added private method sendTransactionCommand(String); to reduce duplicate code in 6 methods.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
47
diff
changeset
|
835 /** |
83aee4f60649
Added private method sendTransactionCommand(String); to reduce duplicate code in 6 methods.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
47
diff
changeset
|
836 * Creates a default PreparedStatement object capable of returning the auto-generated keys designated by the given array. |
83aee4f60649
Added private method sendTransactionCommand(String); to reduce duplicate code in 6 methods.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
47
diff
changeset
|
837 * This array contains the names of the columns in the target table that contain the auto-generated keys that should be returned. |
83aee4f60649
Added private method sendTransactionCommand(String); to reduce duplicate code in 6 methods.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
47
diff
changeset
|
838 * The driver will ignore the array if the SQL statement is not an INSERT statement, or an SQL statement able to |
83aee4f60649
Added private method sendTransactionCommand(String); to reduce duplicate code in 6 methods.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
47
diff
changeset
|
839 * return auto-generated keys (the list of such statements is vendor-specific). |
83aee4f60649
Added private method sendTransactionCommand(String); to reduce duplicate code in 6 methods.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
47
diff
changeset
|
840 * |
83aee4f60649
Added private method sendTransactionCommand(String); to reduce duplicate code in 6 methods.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
47
diff
changeset
|
841 * An SQL statement with or without IN parameters can be pre-compiled and stored in a PreparedStatement object. |
83aee4f60649
Added private method sendTransactionCommand(String); to reduce duplicate code in 6 methods.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
47
diff
changeset
|
842 * This object can then be used to efficiently execute this statement multiple times. |
83aee4f60649
Added private method sendTransactionCommand(String); to reduce duplicate code in 6 methods.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
47
diff
changeset
|
843 * |
83aee4f60649
Added private method sendTransactionCommand(String); to reduce duplicate code in 6 methods.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
47
diff
changeset
|
844 * Note: This method is optimized for handling parametric SQL statements that benefit from precompilation. |
83aee4f60649
Added private method sendTransactionCommand(String); to reduce duplicate code in 6 methods.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
47
diff
changeset
|
845 * If the driver supports precompilation, the method prepareStatement will send the statement to the database for precompilation. |
83aee4f60649
Added private method sendTransactionCommand(String); to reduce duplicate code in 6 methods.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
47
diff
changeset
|
846 * Some drivers may not support precompilation. In this case, the statement may not be sent to the database until the PreparedStatement |
83aee4f60649
Added private method sendTransactionCommand(String); to reduce duplicate code in 6 methods.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
47
diff
changeset
|
847 * object is executed. This has no direct effect on users; however, it does affect which methods throw certain SQLExceptions. |
83aee4f60649
Added private method sendTransactionCommand(String); to reduce duplicate code in 6 methods.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
47
diff
changeset
|
848 * |
83aee4f60649
Added private method sendTransactionCommand(String); to reduce duplicate code in 6 methods.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
47
diff
changeset
|
849 * Result sets created using the returned PreparedStatement object will by default be type TYPE_FORWARD_ONLY and have |
83aee4f60649
Added private method sendTransactionCommand(String); to reduce duplicate code in 6 methods.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
47
diff
changeset
|
850 * a concurrency level of CONCUR_READ_ONLY. The holdability of the created result sets can be determined by calling getHoldability(). |
83aee4f60649
Added private method sendTransactionCommand(String); to reduce duplicate code in 6 methods.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
47
diff
changeset
|
851 * |
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
|
852 * @param sql - an SQL statement that may contain one or more '?' IN parameter placeholders |
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
|
853 * @param columnNames - an array of column names indicating the columns that should be returned from the inserted row or rows |
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
|
854 * @return a new PreparedStatement object, containing the pre-compiled statement, that is capable of |
414
1e278695fe54
Small improvements: adding some final keywords, removing unnecesary initialisations, improve comments.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
408
diff
changeset
|
855 * returning the auto-generated keys designated by the given array of column names |
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
|
856 * @throws SQLException - if a database access error occurs or this method is called on a closed connection |
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
|
857 * @throws SQLFeatureNotSupportedException - if the JDBC driver does not support this method |
77
83aee4f60649
Added private method sendTransactionCommand(String); to reduce duplicate code in 6 methods.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
47
diff
changeset
|
858 */ |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
859 @Override |
295
003ae6d881db
Add "final" keyword to method arguments and local variables where possible.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
292
diff
changeset
|
860 public PreparedStatement prepareStatement(final String sql, final String[] columnNames) 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
|
861 throw newSQLFeatureNotSupportedException("prepareStatement(String sql, String[] columnNames)"); |
77
83aee4f60649
Added private method sendTransactionCommand(String); to reduce duplicate code in 6 methods.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
47
diff
changeset
|
862 } |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
863 |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
864 /** |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
865 * Removes the given Savepoint object from the current transaction. |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
866 * Any reference to the savepoint after it have been removed will |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
867 * cause an SQLException to be thrown. |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
868 * |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
869 * @param savepoint the Savepoint object to be removed |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
870 * @throws SQLException if a database access error occurs or the given |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
871 * Savepoint object is not a valid savepoint in the current |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
872 * transaction |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
873 */ |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
874 @Override |
295
003ae6d881db
Add "final" keyword to method arguments and local variables where possible.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
292
diff
changeset
|
875 public void releaseSavepoint(final Savepoint savepoint) throws SQLException { |
348
bcb9a99d399d
Add private checkNotClosed() method to check if the connection is not closed.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
345
diff
changeset
|
876 checkNotClosed(); |
45
c2bf983dc79b
Implemented Connection methods: getClientInfo(name) and getClientInfo().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
25
diff
changeset
|
877 if (!(savepoint instanceof MonetSavepoint)) |
c2bf983dc79b
Implemented Connection methods: getClientInfo(name) and getClientInfo().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
25
diff
changeset
|
878 throw new SQLException("This driver can only handle savepoints it created itself", "M0M06"); |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
879 |
295
003ae6d881db
Add "final" keyword to method arguments and local variables where possible.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
292
diff
changeset
|
880 final MonetSavepoint sp = (MonetSavepoint)savepoint; |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
881 |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
882 // note: can't use sendIndependentCommand here because we need |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
883 // to process the auto_commit state the server gives |
77
83aee4f60649
Added private method sendTransactionCommand(String); to reduce duplicate code in 6 methods.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
47
diff
changeset
|
884 sendTransactionCommand("RELEASE SAVEPOINT " + sp.getName()); |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
885 } |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
886 |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
887 /** |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
888 * Undoes all changes made in the current transaction and releases |
45
c2bf983dc79b
Implemented Connection methods: getClientInfo(name) and getClientInfo().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
25
diff
changeset
|
889 * any database locks currently held by this Connection object. |
c2bf983dc79b
Implemented Connection methods: getClientInfo(name) and getClientInfo().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
25
diff
changeset
|
890 * This method should be used only when auto-commit mode has been disabled. |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
891 * |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
892 * @throws SQLException if a database access error occurs or this |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
893 * Connection object is in auto-commit mode |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
894 * @see #setAutoCommit(boolean) |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
895 */ |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
896 @Override |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
897 public void rollback() throws SQLException { |
348
bcb9a99d399d
Add private checkNotClosed() method to check if the connection is not closed.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
345
diff
changeset
|
898 checkNotClosed(); |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
899 // note: can't use sendIndependentCommand here because we need |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
900 // to process the auto_commit state the server gives |
77
83aee4f60649
Added private method sendTransactionCommand(String); to reduce duplicate code in 6 methods.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
47
diff
changeset
|
901 sendTransactionCommand("ROLLBACK"); |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
902 } |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
903 |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
904 /** |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
905 * Undoes all changes made after the given Savepoint object was set. |
45
c2bf983dc79b
Implemented Connection methods: getClientInfo(name) and getClientInfo().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
25
diff
changeset
|
906 * |
c2bf983dc79b
Implemented Connection methods: getClientInfo(name) and getClientInfo().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
25
diff
changeset
|
907 * This method should be used only when auto-commit has been disabled. |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
908 * |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
909 * @param savepoint the Savepoint object to roll back to |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
910 * @throws SQLException if a database access error occurs, the |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
911 * Savepoint object is no longer valid, or this Connection |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
912 * object is currently in auto-commit mode |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
913 */ |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
914 @Override |
295
003ae6d881db
Add "final" keyword to method arguments and local variables where possible.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
292
diff
changeset
|
915 public void rollback(final Savepoint savepoint) throws SQLException { |
348
bcb9a99d399d
Add private checkNotClosed() method to check if the connection is not closed.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
345
diff
changeset
|
916 checkNotClosed(); |
45
c2bf983dc79b
Implemented Connection methods: getClientInfo(name) and getClientInfo().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
25
diff
changeset
|
917 if (!(savepoint instanceof MonetSavepoint)) |
c2bf983dc79b
Implemented Connection methods: getClientInfo(name) and getClientInfo().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
25
diff
changeset
|
918 throw new SQLException("This driver can only handle savepoints it created itself", "M0M06"); |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
919 |
295
003ae6d881db
Add "final" keyword to method arguments and local variables where possible.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
292
diff
changeset
|
920 final MonetSavepoint sp = (MonetSavepoint)savepoint; |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
921 |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
922 // note: can't use sendIndependentCommand here because we need |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
923 // to process the auto_commit state the server gives |
77
83aee4f60649
Added private method sendTransactionCommand(String); to reduce duplicate code in 6 methods.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
47
diff
changeset
|
924 sendTransactionCommand("ROLLBACK TO SAVEPOINT " + sp.getName()); |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
925 } |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
926 |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
927 /** |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
928 * Sets this connection's auto-commit mode to the given state. If a |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
929 * connection is in auto-commit mode, then all its SQL statements |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
930 * will be executed and committed as individual transactions. |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
931 * Otherwise, its SQL statements are grouped into transactions that |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
932 * are terminated by a call to either the method commit or the |
45
c2bf983dc79b
Implemented Connection methods: getClientInfo(name) and getClientInfo().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
25
diff
changeset
|
933 * method rollback. By default, new connections are in auto-commit mode. |
c2bf983dc79b
Implemented Connection methods: getClientInfo(name) and getClientInfo().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
25
diff
changeset
|
934 * |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
935 * The commit occurs when the statement completes or the next |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
936 * execute occurs, whichever comes first. In the case of statements |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
937 * returning a ResultSet object, the statement completes when the |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
938 * last row of the ResultSet object has been retrieved or the |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
939 * ResultSet object has been closed. In advanced cases, a single |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
940 * statement may return multiple results as well as output parameter |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
941 * values. In these cases, the commit occurs when all results and |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
942 * output parameter values have been retrieved. |
45
c2bf983dc79b
Implemented Connection methods: getClientInfo(name) and getClientInfo().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
25
diff
changeset
|
943 * |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
944 * NOTE: If this method is called during a transaction, the |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
945 * transaction is committed. |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
946 * |
8
a27ee2cb14a0
Replace String methods equals("") and "".equals( with isEmpty()
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
0
diff
changeset
|
947 * @param autoCommit true to enable auto-commit mode; false to disable it |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
948 * @throws SQLException if a database access error occurs |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
949 * @see #getAutoCommit() |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
950 */ |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
951 @Override |
295
003ae6d881db
Add "final" keyword to method arguments and local variables where possible.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
292
diff
changeset
|
952 public void setAutoCommit(final boolean autoCommit) throws SQLException { |
348
bcb9a99d399d
Add private checkNotClosed() method to check if the connection is not closed.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
345
diff
changeset
|
953 checkNotClosed(); |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
954 if (this.autoCommit != autoCommit) { |
407
40a1db14dca5
Optimise code, reduce duplicate code, cache major and minor version nrs of connected database server and max nr of clients so conversion of strings to ints is only done once.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
406
diff
changeset
|
955 sendControlCommand(autoCommit ? "auto_commit 1" : "auto_commit 0"); |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
956 this.autoCommit = autoCommit; |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
957 } |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
958 } |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
959 |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
960 /** |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
961 * Sets the given catalog name in order to select a subspace of this |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
962 * Connection object's database in which to work. If the driver |
45
c2bf983dc79b
Implemented Connection methods: getClientInfo(name) and getClientInfo().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
25
diff
changeset
|
963 * does not support catalogs, it will silently ignore this request. |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
964 */ |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
965 @Override |
295
003ae6d881db
Add "final" keyword to method arguments and local variables where possible.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
292
diff
changeset
|
966 public void setCatalog(final String catalog) { |
697
68422d7f3961
Inline isValidProperty() in checkValidProperty() as it is the only place the method is called. Also add javadoc comments.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
696
diff
changeset
|
967 // silently ignore this request as MonetDB does not support catalog names |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
968 } |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
969 |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
970 /** |
45
c2bf983dc79b
Implemented Connection methods: getClientInfo(name) and getClientInfo().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
25
diff
changeset
|
971 * Changes the default holdability of ResultSet objects created using this |
c2bf983dc79b
Implemented Connection methods: getClientInfo(name) and getClientInfo().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
25
diff
changeset
|
972 * Connection object to the given holdability. The default holdability of |
c2bf983dc79b
Implemented Connection methods: getClientInfo(name) and getClientInfo().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
25
diff
changeset
|
973 * ResultSet objects can be be determined by invoking DatabaseMetaData.getResultSetHoldability(). |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
974 * |
45
c2bf983dc79b
Implemented Connection methods: getClientInfo(name) and getClientInfo().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
25
diff
changeset
|
975 * @param holdability - a ResultSet holdability constant; one of |
c2bf983dc79b
Implemented Connection methods: getClientInfo(name) and getClientInfo().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
25
diff
changeset
|
976 * ResultSet.HOLD_CURSORS_OVER_COMMIT or |
c2bf983dc79b
Implemented Connection methods: getClientInfo(name) and getClientInfo().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
25
diff
changeset
|
977 * ResultSet.CLOSE_CURSORS_AT_COMMIT |
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
|
978 * @throws SQLException - if a database access error occurs or this method is called on a closed connection |
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
|
979 * @throws SQLFeatureNotSupportedException - if the JDBC driver does not support this method or argument |
45
c2bf983dc79b
Implemented Connection methods: getClientInfo(name) and getClientInfo().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
25
diff
changeset
|
980 * @see #getHoldability() |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
981 */ |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
982 @Override |
295
003ae6d881db
Add "final" keyword to method arguments and local variables where possible.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
292
diff
changeset
|
983 public void setHoldability(final int holdability) throws SQLException { |
45
c2bf983dc79b
Implemented Connection methods: getClientInfo(name) and getClientInfo().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
25
diff
changeset
|
984 // we only support ResultSet.HOLD_CURSORS_OVER_COMMIT |
c2bf983dc79b
Implemented Connection methods: getClientInfo(name) and getClientInfo().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
25
diff
changeset
|
985 if (holdability != ResultSet.HOLD_CURSORS_OVER_COMMIT) |
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
|
986 throw newSQLFeatureNotSupportedException("setHoldability(CLOSE_CURSORS_AT_COMMIT)"); |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
987 } |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
988 |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
989 /** |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
990 * Puts this connection in read-only mode as a hint to the driver to |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
991 * enable database optimizations. MonetDB doesn't support any mode |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
992 * here, hence an SQLWarning is generated if attempted to set |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
993 * to true here. |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
994 * |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
995 * @param readOnly true enables read-only mode; false disables it |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
996 * @throws SQLException if a database access error occurs or this |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
997 * method is called during a transaction. |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
998 */ |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
999 @Override |
295
003ae6d881db
Add "final" keyword to method arguments and local variables where possible.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
292
diff
changeset
|
1000 public void setReadOnly(final boolean readOnly) throws SQLException { |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
1001 if (readOnly == true) |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
1002 addWarning("cannot setReadOnly(true): read-only Connection mode not supported", "01M08"); |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
1003 } |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
1004 |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
1005 /** |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
1006 * Creates an unnamed savepoint in the current transaction and |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
1007 * returns the new Savepoint object that represents it. |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
1008 * |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
1009 * @return the new Savepoint object |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
1010 * @throws SQLException if a database access error occurs or this Connection |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
1011 * object is currently in auto-commit mode |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
1012 */ |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
1013 @Override |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
1014 public Savepoint setSavepoint() throws SQLException { |
407
40a1db14dca5
Optimise code, reduce duplicate code, cache major and minor version nrs of connected database server and max nr of clients so conversion of strings to ints is only done once.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
406
diff
changeset
|
1015 return setSavepoint(null); |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
1016 } |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
1017 |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
1018 /** |
45
c2bf983dc79b
Implemented Connection methods: getClientInfo(name) and getClientInfo().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
25
diff
changeset
|
1019 * Creates a savepoint with the given name in the current transaction |
c2bf983dc79b
Implemented Connection methods: getClientInfo(name) and getClientInfo().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
25
diff
changeset
|
1020 * and returns the new Savepoint object that represents it. |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
1021 * |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
1022 * @param name a String containing the name of the savepoint |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
1023 * @return the new Savepoint object |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
1024 * @throws SQLException if a database access error occurs or this Connection |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
1025 * object is currently in auto-commit mode |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
1026 */ |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
1027 @Override |
295
003ae6d881db
Add "final" keyword to method arguments and local variables where possible.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
292
diff
changeset
|
1028 public Savepoint setSavepoint(final String name) throws SQLException { |
348
bcb9a99d399d
Add private checkNotClosed() method to check if the connection is not closed.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
345
diff
changeset
|
1029 checkNotClosed(); |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
1030 // create a new Savepoint object |
295
003ae6d881db
Add "final" keyword to method arguments and local variables where possible.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
292
diff
changeset
|
1031 final MonetSavepoint sp; |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
1032 try { |
407
40a1db14dca5
Optimise code, reduce duplicate code, cache major and minor version nrs of connected database server and max nr of clients so conversion of strings to ints is only done once.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
406
diff
changeset
|
1033 sp = (name != null) ? new MonetSavepoint(name) : new MonetSavepoint(); |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
1034 } catch (IllegalArgumentException e) { |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
1035 throw new SQLException(e.getMessage(), "M0M03"); |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
1036 } |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
1037 |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
1038 // note: can't use sendIndependentCommand here because we need |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
1039 // to process the auto_commit state the server gives |
77
83aee4f60649
Added private method sendTransactionCommand(String); to reduce duplicate code in 6 methods.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
47
diff
changeset
|
1040 sendTransactionCommand("SAVEPOINT " + sp.getName()); |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
1041 return sp; |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
1042 } |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
1043 |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
1044 /** |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
1045 * Attempts to change the transaction isolation level for this |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
1046 * Connection object to the one given. The constants defined in the |
45
c2bf983dc79b
Implemented Connection methods: getClientInfo(name) and getClientInfo().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
25
diff
changeset
|
1047 * interface Connection are the possible transaction isolation levels. |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
1048 * |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
1049 * @param level one of the following Connection constants: |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
1050 * Connection.TRANSACTION_READ_UNCOMMITTED, |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
1051 * Connection.TRANSACTION_READ_COMMITTED, |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
1052 * Connection.TRANSACTION_REPEATABLE_READ, or |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
1053 * Connection.TRANSACTION_SERIALIZABLE. |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
1054 */ |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
1055 @Override |
295
003ae6d881db
Add "final" keyword to method arguments and local variables where possible.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
292
diff
changeset
|
1056 public void setTransactionIsolation(final int level) { |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
1057 if (level != TRANSACTION_SERIALIZABLE) { |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
1058 addWarning("MonetDB only supports fully serializable " + |
45
c2bf983dc79b
Implemented Connection methods: getClientInfo(name) and getClientInfo().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
25
diff
changeset
|
1059 "transactions, continuing with transaction level " + |
c2bf983dc79b
Implemented Connection methods: getClientInfo(name) and getClientInfo().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
25
diff
changeset
|
1060 "raised to TRANSACTION_SERIALIZABLE", "01M09"); |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
1061 } |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
1062 } |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
1063 |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
1064 /** |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
1065 * Installs the given TypeMap object as the type map for this |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
1066 * Connection object. The type map will be used for the custom |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
1067 * mapping of SQL structured types and distinct types. |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
1068 * |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
1069 * @param map the java.util.Map object to install as the replacement for |
697
68422d7f3961
Inline isValidProperty() in checkValidProperty() as it is the only place the method is called. Also add javadoc comments.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
696
diff
changeset
|
1070 * this Connection object's default type map |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
1071 */ |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
1072 @Override |
295
003ae6d881db
Add "final" keyword to method arguments and local variables where possible.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
292
diff
changeset
|
1073 public void setTypeMap(final Map<String, Class<?>> map) { |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
1074 typeMap = map; |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
1075 } |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
1076 |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
1077 /** |
45
c2bf983dc79b
Implemented Connection methods: getClientInfo(name) and getClientInfo().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
25
diff
changeset
|
1078 * Returns a string identifying this Connection to the MonetDB server. |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
1079 * |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
1080 * @return a String representing this Object |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
1081 */ |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
1082 @Override |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
1083 public String toString() { |
480
849af4b76b28
Optimise code by reducing local variables which are used only once, replacing complex string concatenation by using StringBuilder, replacing some ternairy operators.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
474
diff
changeset
|
1084 return "MonetDB Connection (" + getJDBCURL() |
849af4b76b28
Optimise code by reducing local variables which are used only once, replacing complex string concatenation by using StringBuilder, replacing some ternairy operators.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
474
diff
changeset
|
1085 + (closed ? ") disconnected" : ") connected"); |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
1086 } |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
1087 |
45
c2bf983dc79b
Implemented Connection methods: getClientInfo(name) and getClientInfo().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
25
diff
changeset
|
1088 //== Java 1.6 methods (JDBC 4.0) |
c2bf983dc79b
Implemented Connection methods: getClientInfo(name) and getClientInfo().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
25
diff
changeset
|
1089 |
c2bf983dc79b
Implemented Connection methods: getClientInfo(name) and getClientInfo().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
25
diff
changeset
|
1090 /** |
c2bf983dc79b
Implemented Connection methods: getClientInfo(name) and getClientInfo().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
25
diff
changeset
|
1091 * Factory method for creating Array objects. |
c2bf983dc79b
Implemented Connection methods: getClientInfo(name) and getClientInfo().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
25
diff
changeset
|
1092 * |
c2bf983dc79b
Implemented Connection methods: getClientInfo(name) and getClientInfo().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
25
diff
changeset
|
1093 * Note: When createArrayOf is used to create an array object that |
c2bf983dc79b
Implemented Connection methods: getClientInfo(name) and getClientInfo().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
25
diff
changeset
|
1094 * maps to a primitive data type, then it is implementation-defined |
c2bf983dc79b
Implemented Connection methods: getClientInfo(name) and getClientInfo().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
25
diff
changeset
|
1095 * whether the Array object is an array of that primitive data type |
c2bf983dc79b
Implemented Connection methods: getClientInfo(name) and getClientInfo().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
25
diff
changeset
|
1096 * or an array of Object. |
c2bf983dc79b
Implemented Connection methods: getClientInfo(name) and getClientInfo().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
25
diff
changeset
|
1097 * |
c2bf983dc79b
Implemented Connection methods: getClientInfo(name) and getClientInfo().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
25
diff
changeset
|
1098 * Note: The JDBC driver is responsible for mapping the elements |
c2bf983dc79b
Implemented Connection methods: getClientInfo(name) and getClientInfo().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
25
diff
changeset
|
1099 * Object array to the default JDBC SQL type defined in |
c2bf983dc79b
Implemented Connection methods: getClientInfo(name) and getClientInfo().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
25
diff
changeset
|
1100 * java.sql.Types for the given class of Object. The default mapping |
c2bf983dc79b
Implemented Connection methods: getClientInfo(name) and getClientInfo().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
25
diff
changeset
|
1101 * is specified in Appendix B of the JDBC specification. If the |
c2bf983dc79b
Implemented Connection methods: getClientInfo(name) and getClientInfo().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
25
diff
changeset
|
1102 * resulting JDBC type is not the appropriate type for the given |
c2bf983dc79b
Implemented Connection methods: getClientInfo(name) and getClientInfo().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
25
diff
changeset
|
1103 * typeName then it is implementation defined whether an |
c2bf983dc79b
Implemented Connection methods: getClientInfo(name) and getClientInfo().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
25
diff
changeset
|
1104 * SQLException is thrown or the driver supports the resulting conversion. |
c2bf983dc79b
Implemented Connection methods: getClientInfo(name) and getClientInfo().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
25
diff
changeset
|
1105 * |
c2bf983dc79b
Implemented Connection methods: getClientInfo(name) and getClientInfo().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
25
diff
changeset
|
1106 * @param typeName the SQL name of the type the elements of the |
c2bf983dc79b
Implemented Connection methods: getClientInfo(name) and getClientInfo().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
25
diff
changeset
|
1107 * array map to. The typeName is a database-specific name |
c2bf983dc79b
Implemented Connection methods: getClientInfo(name) and getClientInfo().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
25
diff
changeset
|
1108 * which may be the name of a built-in type, a user-defined |
c2bf983dc79b
Implemented Connection methods: getClientInfo(name) and getClientInfo().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
25
diff
changeset
|
1109 * type or a standard SQL type supported by this database. |
c2bf983dc79b
Implemented Connection methods: getClientInfo(name) and getClientInfo().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
25
diff
changeset
|
1110 * This is the value returned by Array.getBaseTypeName |
c2bf983dc79b
Implemented Connection methods: getClientInfo(name) and getClientInfo().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
25
diff
changeset
|
1111 * @return an Array object whose elements map to the specified SQL type |
89
a6608e9581c1
Moved content of ChangeLog to ChangeLog-Archive.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
77
diff
changeset
|
1112 * @throws SQLException - if a database error occurs, the JDBC type is not appropriate for the typeName and |
a6608e9581c1
Moved content of ChangeLog to ChangeLog-Archive.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
77
diff
changeset
|
1113 * the conversion is not supported, the typeName is null or this method is called on a closed connection |
a6608e9581c1
Moved content of ChangeLog to ChangeLog-Archive.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
77
diff
changeset
|
1114 * @throws SQLFeatureNotSupportedException - if the JDBC driver does not support this data type |
45
c2bf983dc79b
Implemented Connection methods: getClientInfo(name) and getClientInfo().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
25
diff
changeset
|
1115 * @since 1.6 |
c2bf983dc79b
Implemented Connection methods: getClientInfo(name) and getClientInfo().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
25
diff
changeset
|
1116 */ |
c2bf983dc79b
Implemented Connection methods: getClientInfo(name) and getClientInfo().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
25
diff
changeset
|
1117 @Override |
295
003ae6d881db
Add "final" keyword to method arguments and local variables where possible.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
292
diff
changeset
|
1118 public java.sql.Array createArrayOf(final String typeName, final Object[] elements) 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
|
1119 throw newSQLFeatureNotSupportedException("createArrayOf"); |
45
c2bf983dc79b
Implemented Connection methods: getClientInfo(name) and getClientInfo().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
25
diff
changeset
|
1120 } |
c2bf983dc79b
Implemented Connection methods: getClientInfo(name) and getClientInfo().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
25
diff
changeset
|
1121 |
c2bf983dc79b
Implemented Connection methods: getClientInfo(name) and getClientInfo().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
25
diff
changeset
|
1122 /** |
c2bf983dc79b
Implemented Connection methods: getClientInfo(name) and getClientInfo().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
25
diff
changeset
|
1123 * Constructs an object that implements the Clob interface. The |
c2bf983dc79b
Implemented Connection methods: getClientInfo(name) and getClientInfo().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
25
diff
changeset
|
1124 * object returned initially contains no data. The setAsciiStream, |
c2bf983dc79b
Implemented Connection methods: getClientInfo(name) and getClientInfo().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
25
diff
changeset
|
1125 * setCharacterStream and setString methods of the Clob interface |
c2bf983dc79b
Implemented Connection methods: getClientInfo(name) and getClientInfo().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
25
diff
changeset
|
1126 * may be used to add data to the Clob. |
c2bf983dc79b
Implemented Connection methods: getClientInfo(name) and getClientInfo().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
25
diff
changeset
|
1127 * |
c2bf983dc79b
Implemented Connection methods: getClientInfo(name) and getClientInfo().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
25
diff
changeset
|
1128 * @return a MonetClob instance |
89
a6608e9581c1
Moved content of ChangeLog to ChangeLog-Archive.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
77
diff
changeset
|
1129 * @throws SQLException - if an object that implements the Clob interface can not be constructed, |
a6608e9581c1
Moved content of ChangeLog to ChangeLog-Archive.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
77
diff
changeset
|
1130 * this method is called on a closed connection or a database access error occurs. |
45
c2bf983dc79b
Implemented Connection methods: getClientInfo(name) and getClientInfo().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
25
diff
changeset
|
1131 * @since 1.6 |
c2bf983dc79b
Implemented Connection methods: getClientInfo(name) and getClientInfo().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
25
diff
changeset
|
1132 */ |
c2bf983dc79b
Implemented Connection methods: getClientInfo(name) and getClientInfo().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
25
diff
changeset
|
1133 @Override |
c2bf983dc79b
Implemented Connection methods: getClientInfo(name) and getClientInfo().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
25
diff
changeset
|
1134 public java.sql.Clob createClob() throws SQLException { |
c2bf983dc79b
Implemented Connection methods: getClientInfo(name) and getClientInfo().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
25
diff
changeset
|
1135 return new MonetClob(""); |
c2bf983dc79b
Implemented Connection methods: getClientInfo(name) and getClientInfo().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
25
diff
changeset
|
1136 } |
c2bf983dc79b
Implemented Connection methods: getClientInfo(name) and getClientInfo().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
25
diff
changeset
|
1137 |
c2bf983dc79b
Implemented Connection methods: getClientInfo(name) and getClientInfo().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
25
diff
changeset
|
1138 /** |
c2bf983dc79b
Implemented Connection methods: getClientInfo(name) and getClientInfo().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
25
diff
changeset
|
1139 * Constructs an object that implements the Blob interface. The |
c2bf983dc79b
Implemented Connection methods: getClientInfo(name) and getClientInfo().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
25
diff
changeset
|
1140 * object returned initially contains no data. The setBinaryStream |
c2bf983dc79b
Implemented Connection methods: getClientInfo(name) and getClientInfo().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
25
diff
changeset
|
1141 * and setBytes methods of the Blob interface may be used to add |
c2bf983dc79b
Implemented Connection methods: getClientInfo(name) and getClientInfo().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
25
diff
changeset
|
1142 * data to the Blob. |
c2bf983dc79b
Implemented Connection methods: getClientInfo(name) and getClientInfo().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
25
diff
changeset
|
1143 * |
c2bf983dc79b
Implemented Connection methods: getClientInfo(name) and getClientInfo().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
25
diff
changeset
|
1144 * @return a MonetBlob instance |
89
a6608e9581c1
Moved content of ChangeLog to ChangeLog-Archive.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
77
diff
changeset
|
1145 * @throws SQLException - if an object that implements the Blob interface can not be constructed, |
a6608e9581c1
Moved content of ChangeLog to ChangeLog-Archive.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
77
diff
changeset
|
1146 * this method is called on a closed connection or a database access error occurs. |
45
c2bf983dc79b
Implemented Connection methods: getClientInfo(name) and getClientInfo().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
25
diff
changeset
|
1147 * @since 1.6 |
c2bf983dc79b
Implemented Connection methods: getClientInfo(name) and getClientInfo().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
25
diff
changeset
|
1148 */ |
c2bf983dc79b
Implemented Connection methods: getClientInfo(name) and getClientInfo().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
25
diff
changeset
|
1149 @Override |
c2bf983dc79b
Implemented Connection methods: getClientInfo(name) and getClientInfo().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
25
diff
changeset
|
1150 public java.sql.Blob createBlob() throws SQLException { |
295
003ae6d881db
Add "final" keyword to method arguments and local variables where possible.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
292
diff
changeset
|
1151 return new MonetBlob(new byte[1]); |
45
c2bf983dc79b
Implemented Connection methods: getClientInfo(name) and getClientInfo().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
25
diff
changeset
|
1152 } |
c2bf983dc79b
Implemented Connection methods: getClientInfo(name) and getClientInfo().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
25
diff
changeset
|
1153 |
c2bf983dc79b
Implemented Connection methods: getClientInfo(name) and getClientInfo().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
25
diff
changeset
|
1154 /** |
c2bf983dc79b
Implemented Connection methods: getClientInfo(name) and getClientInfo().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
25
diff
changeset
|
1155 * Constructs an object that implements the NClob interface. The |
c2bf983dc79b
Implemented Connection methods: getClientInfo(name) and getClientInfo().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
25
diff
changeset
|
1156 * object returned initially contains no data. The setAsciiStream, |
c2bf983dc79b
Implemented Connection methods: getClientInfo(name) and getClientInfo().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
25
diff
changeset
|
1157 * setCharacterStream and setString methods of the NClob interface |
c2bf983dc79b
Implemented Connection methods: getClientInfo(name) and getClientInfo().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
25
diff
changeset
|
1158 * may be used to add data to the NClob. |
c2bf983dc79b
Implemented Connection methods: getClientInfo(name) and getClientInfo().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
25
diff
changeset
|
1159 * |
c2bf983dc79b
Implemented Connection methods: getClientInfo(name) and getClientInfo().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
25
diff
changeset
|
1160 * @return an NClob instance |
89
a6608e9581c1
Moved content of ChangeLog to ChangeLog-Archive.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
77
diff
changeset
|
1161 * @throws SQLException - if an object that implements the NClob interface can not be constructed, |
a6608e9581c1
Moved content of ChangeLog to ChangeLog-Archive.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
77
diff
changeset
|
1162 * this method is called on a closed connection or a database access error occurs. |
a6608e9581c1
Moved content of ChangeLog to ChangeLog-Archive.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
77
diff
changeset
|
1163 * @throws SQLFeatureNotSupportedException - if the JDBC driver does not support this data type |
45
c2bf983dc79b
Implemented Connection methods: getClientInfo(name) and getClientInfo().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
25
diff
changeset
|
1164 * @since 1.6 |
c2bf983dc79b
Implemented Connection methods: getClientInfo(name) and getClientInfo().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
25
diff
changeset
|
1165 */ |
c2bf983dc79b
Implemented Connection methods: getClientInfo(name) and getClientInfo().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
25
diff
changeset
|
1166 @Override |
c2bf983dc79b
Implemented Connection methods: getClientInfo(name) and getClientInfo().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
25
diff
changeset
|
1167 public java.sql.NClob createNClob() 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
|
1168 throw newSQLFeatureNotSupportedException("createNClob"); |
45
c2bf983dc79b
Implemented Connection methods: getClientInfo(name) and getClientInfo().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
25
diff
changeset
|
1169 } |
c2bf983dc79b
Implemented Connection methods: getClientInfo(name) and getClientInfo().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
25
diff
changeset
|
1170 |
c2bf983dc79b
Implemented Connection methods: getClientInfo(name) and getClientInfo().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
25
diff
changeset
|
1171 /** |
c2bf983dc79b
Implemented Connection methods: getClientInfo(name) and getClientInfo().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
25
diff
changeset
|
1172 * Factory method for creating Struct objects. |
c2bf983dc79b
Implemented Connection methods: getClientInfo(name) and getClientInfo().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
25
diff
changeset
|
1173 * |
c2bf983dc79b
Implemented Connection methods: getClientInfo(name) and getClientInfo().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
25
diff
changeset
|
1174 * @param typeName the SQL type name of the SQL structured type that |
c2bf983dc79b
Implemented Connection methods: getClientInfo(name) and getClientInfo().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
25
diff
changeset
|
1175 * this Struct object maps to. The typeName is the name of a |
c2bf983dc79b
Implemented Connection methods: getClientInfo(name) and getClientInfo().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
25
diff
changeset
|
1176 * user-defined type that has been defined for this database. |
c2bf983dc79b
Implemented Connection methods: getClientInfo(name) and getClientInfo().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
25
diff
changeset
|
1177 * It is the value returned by Struct.getSQLTypeName. |
c2bf983dc79b
Implemented Connection methods: getClientInfo(name) and getClientInfo().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
25
diff
changeset
|
1178 * @param attributes the attributes that populate the returned object |
c2bf983dc79b
Implemented Connection methods: getClientInfo(name) and getClientInfo().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
25
diff
changeset
|
1179 * @return a Struct object that maps to the given SQL type and is |
c2bf983dc79b
Implemented Connection methods: getClientInfo(name) and getClientInfo().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
25
diff
changeset
|
1180 * populated with the given attributes |
89
a6608e9581c1
Moved content of ChangeLog to ChangeLog-Archive.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
77
diff
changeset
|
1181 * @throws SQLException - if an object that implements the Struct interface can not be constructed, |
a6608e9581c1
Moved content of ChangeLog to ChangeLog-Archive.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
77
diff
changeset
|
1182 * this method is called on a closed connection or a database access error occurs. |
a6608e9581c1
Moved content of ChangeLog to ChangeLog-Archive.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
77
diff
changeset
|
1183 * @throws SQLFeatureNotSupportedException - if the JDBC driver does not support this data type |
45
c2bf983dc79b
Implemented Connection methods: getClientInfo(name) and getClientInfo().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
25
diff
changeset
|
1184 * @since 1.6 |
c2bf983dc79b
Implemented Connection methods: getClientInfo(name) and getClientInfo().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
25
diff
changeset
|
1185 */ |
c2bf983dc79b
Implemented Connection methods: getClientInfo(name) and getClientInfo().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
25
diff
changeset
|
1186 @Override |
77
83aee4f60649
Added private method sendTransactionCommand(String); to reduce duplicate code in 6 methods.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
47
diff
changeset
|
1187 public java.sql.Struct createStruct(String typeName, Object[] attributes) 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
|
1188 throw newSQLFeatureNotSupportedException("createStruct"); |
45
c2bf983dc79b
Implemented Connection methods: getClientInfo(name) and getClientInfo().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
25
diff
changeset
|
1189 } |
c2bf983dc79b
Implemented Connection methods: getClientInfo(name) and getClientInfo().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
25
diff
changeset
|
1190 |
c2bf983dc79b
Implemented Connection methods: getClientInfo(name) and getClientInfo().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
25
diff
changeset
|
1191 /** |
c2bf983dc79b
Implemented Connection methods: getClientInfo(name) and getClientInfo().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
25
diff
changeset
|
1192 * Constructs an object that implements the SQLXML interface. The |
c2bf983dc79b
Implemented Connection methods: getClientInfo(name) and getClientInfo().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
25
diff
changeset
|
1193 * object returned initially contains no data. The |
c2bf983dc79b
Implemented Connection methods: getClientInfo(name) and getClientInfo().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
25
diff
changeset
|
1194 * createXmlStreamWriter object and setString method of the SQLXML |
c2bf983dc79b
Implemented Connection methods: getClientInfo(name) and getClientInfo().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
25
diff
changeset
|
1195 * interface may be used to add data to the SQLXML object. |
c2bf983dc79b
Implemented Connection methods: getClientInfo(name) and getClientInfo().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
25
diff
changeset
|
1196 * |
c2bf983dc79b
Implemented Connection methods: getClientInfo(name) and getClientInfo().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
25
diff
changeset
|
1197 * @return An object that implements the SQLXML interface |
89
a6608e9581c1
Moved content of ChangeLog to ChangeLog-Archive.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
77
diff
changeset
|
1198 * @throws SQLException - if an object that implements the SQLXML interface can not be constructed, |
a6608e9581c1
Moved content of ChangeLog to ChangeLog-Archive.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
77
diff
changeset
|
1199 * this method is called on a closed connection or a database access error occurs. |
a6608e9581c1
Moved content of ChangeLog to ChangeLog-Archive.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
77
diff
changeset
|
1200 * @throws SQLFeatureNotSupportedException - if the JDBC driver does not support this data type |
45
c2bf983dc79b
Implemented Connection methods: getClientInfo(name) and getClientInfo().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
25
diff
changeset
|
1201 * @since 1.6 |
c2bf983dc79b
Implemented Connection methods: getClientInfo(name) and getClientInfo().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
25
diff
changeset
|
1202 */ |
c2bf983dc79b
Implemented Connection methods: getClientInfo(name) and getClientInfo().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
25
diff
changeset
|
1203 @Override |
c2bf983dc79b
Implemented Connection methods: getClientInfo(name) and getClientInfo().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
25
diff
changeset
|
1204 public java.sql.SQLXML createSQLXML() 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
|
1205 throw newSQLFeatureNotSupportedException("createSQLXML"); |
45
c2bf983dc79b
Implemented Connection methods: getClientInfo(name) and getClientInfo().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
25
diff
changeset
|
1206 } |
c2bf983dc79b
Implemented Connection methods: getClientInfo(name) and getClientInfo().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
25
diff
changeset
|
1207 |
c2bf983dc79b
Implemented Connection methods: getClientInfo(name) and getClientInfo().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
25
diff
changeset
|
1208 /** |
c2bf983dc79b
Implemented Connection methods: getClientInfo(name) and getClientInfo().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
25
diff
changeset
|
1209 * Returns true if the connection has not been closed and is still |
c2bf983dc79b
Implemented Connection methods: getClientInfo(name) and getClientInfo().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
25
diff
changeset
|
1210 * valid. The driver shall submit a query on the connection or use |
c2bf983dc79b
Implemented Connection methods: getClientInfo(name) and getClientInfo().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
25
diff
changeset
|
1211 * some other mechanism that positively verifies the connection is |
c2bf983dc79b
Implemented Connection methods: getClientInfo(name) and getClientInfo().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
25
diff
changeset
|
1212 * still valid when this method is called. |
c2bf983dc79b
Implemented Connection methods: getClientInfo(name) and getClientInfo().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
25
diff
changeset
|
1213 * |
c2bf983dc79b
Implemented Connection methods: getClientInfo(name) and getClientInfo().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
25
diff
changeset
|
1214 * The query submitted by the driver to validate the connection |
c2bf983dc79b
Implemented Connection methods: getClientInfo(name) and getClientInfo().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
25
diff
changeset
|
1215 * shall be executed in the context of the current transaction. |
c2bf983dc79b
Implemented Connection methods: getClientInfo(name) and getClientInfo().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
25
diff
changeset
|
1216 * |
c2bf983dc79b
Implemented Connection methods: getClientInfo(name) and getClientInfo().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
25
diff
changeset
|
1217 * @param timeout The time in seconds to wait for the database |
c2bf983dc79b
Implemented Connection methods: getClientInfo(name) and getClientInfo().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
25
diff
changeset
|
1218 * operation used to validate the connection to complete. If |
c2bf983dc79b
Implemented Connection methods: getClientInfo(name) and getClientInfo().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
25
diff
changeset
|
1219 * the timeout period expires before the operation completes, |
c2bf983dc79b
Implemented Connection methods: getClientInfo(name) and getClientInfo().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
25
diff
changeset
|
1220 * this method returns false. A value of 0 indicates a |
c2bf983dc79b
Implemented Connection methods: getClientInfo(name) and getClientInfo().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
25
diff
changeset
|
1221 * timeout is not applied to the database operation. |
c2bf983dc79b
Implemented Connection methods: getClientInfo(name) and getClientInfo().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
25
diff
changeset
|
1222 * @return true if the connection is valid, false otherwise |
c2bf983dc79b
Implemented Connection methods: getClientInfo(name) and getClientInfo().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
25
diff
changeset
|
1223 * @throws SQLException if the value supplied for timeout is less than 0 |
c2bf983dc79b
Implemented Connection methods: getClientInfo(name) and getClientInfo().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
25
diff
changeset
|
1224 * @since 1.6 |
c2bf983dc79b
Implemented Connection methods: getClientInfo(name) and getClientInfo().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
25
diff
changeset
|
1225 */ |
c2bf983dc79b
Implemented Connection methods: getClientInfo(name) and getClientInfo().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
25
diff
changeset
|
1226 @Override |
295
003ae6d881db
Add "final" keyword to method arguments and local variables where possible.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
292
diff
changeset
|
1227 public boolean isValid(final int timeout) throws SQLException { |
45
c2bf983dc79b
Implemented Connection methods: getClientInfo(name) and getClientInfo().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
25
diff
changeset
|
1228 if (timeout < 0) |
c2bf983dc79b
Implemented Connection methods: getClientInfo(name) and getClientInfo().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
25
diff
changeset
|
1229 throw new SQLException("timeout is less than 0", "M1M05"); |
c2bf983dc79b
Implemented Connection methods: getClientInfo(name) and getClientInfo().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
25
diff
changeset
|
1230 if (closed) |
c2bf983dc79b
Implemented Connection methods: getClientInfo(name) and getClientInfo().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
25
diff
changeset
|
1231 return false; |
c2bf983dc79b
Implemented Connection methods: getClientInfo(name) and getClientInfo().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
25
diff
changeset
|
1232 |
284
e5b99c929a2d
Improve setSchema(String schema) by checking also on empty name.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
278
diff
changeset
|
1233 // ping monetdb server using query: select 1; |
45
c2bf983dc79b
Implemented Connection methods: getClientInfo(name) and getClientInfo().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
25
diff
changeset
|
1234 Statement stmt = null; |
c2bf983dc79b
Implemented Connection methods: getClientInfo(name) and getClientInfo().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
25
diff
changeset
|
1235 ResultSet rs = null; |
167
89e954e7acbb
Correct implementation of method Connection.isValid().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
164
diff
changeset
|
1236 boolean isValid = false; |
345
45155894aece
Remove catch code from finally part where original timeout is reset on server.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
343
diff
changeset
|
1237 final int original_timeout = this.lastSetQueryTimeout; |
45
c2bf983dc79b
Implemented Connection methods: getClientInfo(name) and getClientInfo().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
25
diff
changeset
|
1238 try { |
c2bf983dc79b
Implemented Connection methods: getClientInfo(name) and getClientInfo().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
25
diff
changeset
|
1239 stmt = createStatement(); |
167
89e954e7acbb
Correct implementation of method Connection.isValid().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
164
diff
changeset
|
1240 if (stmt != null) { |
89e954e7acbb
Correct implementation of method Connection.isValid().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
164
diff
changeset
|
1241 if (timeout > 0 && original_timeout != timeout) { |
89e954e7acbb
Correct implementation of method Connection.isValid().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
164
diff
changeset
|
1242 // we need to change the requested timeout for this test query |
89e954e7acbb
Correct implementation of method Connection.isValid().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
164
diff
changeset
|
1243 stmt.setQueryTimeout(timeout); |
89e954e7acbb
Correct implementation of method Connection.isValid().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
164
diff
changeset
|
1244 } |
89e954e7acbb
Correct implementation of method Connection.isValid().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
164
diff
changeset
|
1245 rs = stmt.executeQuery("SELECT 1"); |
89e954e7acbb
Correct implementation of method Connection.isValid().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
164
diff
changeset
|
1246 if (rs != null && rs.next()) { |
89e954e7acbb
Correct implementation of method Connection.isValid().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
164
diff
changeset
|
1247 isValid = true; |
89e954e7acbb
Correct implementation of method Connection.isValid().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
164
diff
changeset
|
1248 } |
89e954e7acbb
Correct implementation of method Connection.isValid().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
164
diff
changeset
|
1249 } |
89e954e7acbb
Correct implementation of method Connection.isValid().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
164
diff
changeset
|
1250 } catch (SQLException se) { |
408
5540793628d6
Improve code when setting query timeout. It used to call the sys.settimeout(bigint) which is deprecated as of release Jun2020 (11.37.7) and replaced by new sys.setquerytimeout(int).
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
407
diff
changeset
|
1251 final String msg = se.getMessage(); |
175
8700d9ef2ace
Added possibility via a connection property to let the JDBC driver
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
167
diff
changeset
|
1252 // System.out.println(se.getSQLState() + " Con.isValid(): " + msg); |
8700d9ef2ace
Added possibility via a connection property to let the JDBC driver
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
167
diff
changeset
|
1253 if (msg != null && msg.equalsIgnoreCase("Current transaction is aborted (please ROLLBACK)")) { |
8700d9ef2ace
Added possibility via a connection property to let the JDBC driver
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
167
diff
changeset
|
1254 // Must use equalsIgnoreCase() here because up to Jul2017 release 'Current' was 'current' so with lowercase c. |
8700d9ef2ace
Added possibility via a connection property to let the JDBC driver
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
167
diff
changeset
|
1255 // It changed to 'Current' after Jul2017 release. We need to support all server versions. |
8700d9ef2ace
Added possibility via a connection property to let the JDBC driver
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
167
diff
changeset
|
1256 // SQLState = 25005 |
167
89e954e7acbb
Correct implementation of method Connection.isValid().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
164
diff
changeset
|
1257 isValid = true; |
89e954e7acbb
Correct implementation of method Connection.isValid().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
164
diff
changeset
|
1258 } |
89e954e7acbb
Correct implementation of method Connection.isValid().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
164
diff
changeset
|
1259 /* ignore stmt errors/exceptions, we are only testing if the connection is still alive and usable */ |
89e954e7acbb
Correct implementation of method Connection.isValid().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
164
diff
changeset
|
1260 } finally { |
408
5540793628d6
Improve code when setting query timeout. It used to call the sys.settimeout(bigint) which is deprecated as of release Jun2020 (11.37.7) and replaced by new sys.setquerytimeout(int).
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
407
diff
changeset
|
1261 closeResultsetStatement(rs, stmt); |
345
45155894aece
Remove catch code from finally part where original timeout is reset on server.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
343
diff
changeset
|
1262 /* when changed, reset the original server timeout value on the server */ |
45155894aece
Remove catch code from finally part where original timeout is reset on server.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
343
diff
changeset
|
1263 if (timeout > 0 && original_timeout != this.lastSetQueryTimeout) { |
45155894aece
Remove catch code from finally part where original timeout is reset on server.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
343
diff
changeset
|
1264 this.lastSetQueryTimeout = original_timeout; |
343
48ee2ca98975
Added test and fix for bug 6782, ie set the connection's query timeout explicitly at the end of isValid method.
Pedro Ferreira <pedro.ferreira@monetdbsolutions.com>
parents:
336
diff
changeset
|
1265 try { |
414
1e278695fe54
Small improvements: adding some final keywords, removing unnecesary initialisations, improve comments.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
408
diff
changeset
|
1266 /* we have to set in the server explicitly, because the test 'queryTimeout != connection.lastSetQueryTimeout' |
345
45155894aece
Remove catch code from finally part where original timeout is reset on server.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
343
diff
changeset
|
1267 on MonetStatement.internalExecute(sql) won't pass and the server won't be set back */ |
408
5540793628d6
Improve code when setting query timeout. It used to call the sys.settimeout(bigint) which is deprecated as of release Jun2020 (11.37.7) and replaced by new sys.setquerytimeout(int).
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
407
diff
changeset
|
1268 setQueryTimeout(original_timeout); |
343
48ee2ca98975
Added test and fix for bug 6782, ie set the connection's query timeout explicitly at the end of isValid method.
Pedro Ferreira <pedro.ferreira@monetdbsolutions.com>
parents:
336
diff
changeset
|
1269 } catch (SQLException se) { |
345
45155894aece
Remove catch code from finally part where original timeout is reset on server.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
343
diff
changeset
|
1270 /* ignore stmt errors/exceptions, we are only testing if the connection is still alive and usable */ |
343
48ee2ca98975
Added test and fix for bug 6782, ie set the connection's query timeout explicitly at the end of isValid method.
Pedro Ferreira <pedro.ferreira@monetdbsolutions.com>
parents:
336
diff
changeset
|
1271 } |
48ee2ca98975
Added test and fix for bug 6782, ie set the connection's query timeout explicitly at the end of isValid method.
Pedro Ferreira <pedro.ferreira@monetdbsolutions.com>
parents:
336
diff
changeset
|
1272 } |
45
c2bf983dc79b
Implemented Connection methods: getClientInfo(name) and getClientInfo().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
25
diff
changeset
|
1273 } |
167
89e954e7acbb
Correct implementation of method Connection.isValid().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
164
diff
changeset
|
1274 return isValid; |
45
c2bf983dc79b
Implemented Connection methods: getClientInfo(name) and getClientInfo().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
25
diff
changeset
|
1275 } |
c2bf983dc79b
Implemented Connection methods: getClientInfo(name) and getClientInfo().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
25
diff
changeset
|
1276 |
c2bf983dc79b
Implemented Connection methods: getClientInfo(name) and getClientInfo().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
25
diff
changeset
|
1277 /** |
c2bf983dc79b
Implemented Connection methods: getClientInfo(name) and getClientInfo().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
25
diff
changeset
|
1278 * Returns the value of the client info property specified by name. |
c2bf983dc79b
Implemented Connection methods: getClientInfo(name) and getClientInfo().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
25
diff
changeset
|
1279 * This method may return null if the specified client info property |
c2bf983dc79b
Implemented Connection methods: getClientInfo(name) and getClientInfo().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
25
diff
changeset
|
1280 * has not been set and does not have a default value. |
c2bf983dc79b
Implemented Connection methods: getClientInfo(name) and getClientInfo().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
25
diff
changeset
|
1281 * This method will also return null if the specified client info |
c2bf983dc79b
Implemented Connection methods: getClientInfo(name) and getClientInfo().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
25
diff
changeset
|
1282 * property name is not supported by the driver. |
c2bf983dc79b
Implemented Connection methods: getClientInfo(name) and getClientInfo().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
25
diff
changeset
|
1283 * Applications may use the DatabaseMetaData.getClientInfoProperties method |
c2bf983dc79b
Implemented Connection methods: getClientInfo(name) and getClientInfo().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
25
diff
changeset
|
1284 * to determine the client info properties supported by the driver. |
c2bf983dc79b
Implemented Connection methods: getClientInfo(name) and getClientInfo().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
25
diff
changeset
|
1285 * |
c2bf983dc79b
Implemented Connection methods: getClientInfo(name) and getClientInfo().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
25
diff
changeset
|
1286 * @param name - The name of the client info property to retrieve |
c2bf983dc79b
Implemented Connection methods: getClientInfo(name) and getClientInfo().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
25
diff
changeset
|
1287 * @return The value of the client info property specified or null |
c2bf983dc79b
Implemented Connection methods: getClientInfo(name) and getClientInfo().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
25
diff
changeset
|
1288 * @throws SQLException - if the database server returns an error |
c2bf983dc79b
Implemented Connection methods: getClientInfo(name) and getClientInfo().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
25
diff
changeset
|
1289 * when fetching the client info value from the database |
c2bf983dc79b
Implemented Connection methods: getClientInfo(name) and getClientInfo().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
25
diff
changeset
|
1290 * or this method is called on a closed connection |
c2bf983dc79b
Implemented Connection methods: getClientInfo(name) and getClientInfo().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
25
diff
changeset
|
1291 * @since 1.6 |
c2bf983dc79b
Implemented Connection methods: getClientInfo(name) and getClientInfo().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
25
diff
changeset
|
1292 */ |
c2bf983dc79b
Implemented Connection methods: getClientInfo(name) and getClientInfo().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
25
diff
changeset
|
1293 @Override |
295
003ae6d881db
Add "final" keyword to method arguments and local variables where possible.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
292
diff
changeset
|
1294 public String getClientInfo(final String name) throws SQLException { |
914
e0120c7052bb
Check for rs == null to prevent NullPoinerExceptions.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
906
diff
changeset
|
1295 // only MonetDB Server 11.51 (Aug2024) or higher supports Client Info Properties |
905
a52bc2dcdb8c
Implement ClientInfo API
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
903
diff
changeset
|
1296 String attrName = getClientInfoAttributeNames().get(name); |
a52bc2dcdb8c
Implement ClientInfo API
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
903
diff
changeset
|
1297 if (attrName == null) |
a52bc2dcdb8c
Implement ClientInfo API
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
903
diff
changeset
|
1298 return null; |
a52bc2dcdb8c
Implement ClientInfo API
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
903
diff
changeset
|
1299 String query = "SELECT " + attrName + " FROM sys.sessions WHERE sessionid = current_sessionid()"; |
a52bc2dcdb8c
Implement ClientInfo API
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
903
diff
changeset
|
1300 try (Statement st = createStatement(); ResultSet rs = st.executeQuery(query)) { |
914
e0120c7052bb
Check for rs == null to prevent NullPoinerExceptions.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
906
diff
changeset
|
1301 if (rs != null && rs.next()) |
905
a52bc2dcdb8c
Implement ClientInfo API
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
903
diff
changeset
|
1302 return rs.getString(1); |
a52bc2dcdb8c
Implement ClientInfo API
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
903
diff
changeset
|
1303 else |
a52bc2dcdb8c
Implement ClientInfo API
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
903
diff
changeset
|
1304 return null; |
a52bc2dcdb8c
Implement ClientInfo API
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
903
diff
changeset
|
1305 } |
45
c2bf983dc79b
Implemented Connection methods: getClientInfo(name) and getClientInfo().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
25
diff
changeset
|
1306 } |
c2bf983dc79b
Implemented Connection methods: getClientInfo(name) and getClientInfo().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
25
diff
changeset
|
1307 |
c2bf983dc79b
Implemented Connection methods: getClientInfo(name) and getClientInfo().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
25
diff
changeset
|
1308 /** |
c2bf983dc79b
Implemented Connection methods: getClientInfo(name) and getClientInfo().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
25
diff
changeset
|
1309 * Returns a list containing the name and current value of each client info |
c2bf983dc79b
Implemented Connection methods: getClientInfo(name) and getClientInfo().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
25
diff
changeset
|
1310 * property supported by the driver. The value of a client info property may |
c2bf983dc79b
Implemented Connection methods: getClientInfo(name) and getClientInfo().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
25
diff
changeset
|
1311 * be null if the property has not been set and does not have a default value. |
c2bf983dc79b
Implemented Connection methods: getClientInfo(name) and getClientInfo().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
25
diff
changeset
|
1312 * |
c2bf983dc79b
Implemented Connection methods: getClientInfo(name) and getClientInfo().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
25
diff
changeset
|
1313 * @return A Properties object that contains the name and current value |
c2bf983dc79b
Implemented Connection methods: getClientInfo(name) and getClientInfo().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
25
diff
changeset
|
1314 * of each of the client info properties supported by the driver. |
c2bf983dc79b
Implemented Connection methods: getClientInfo(name) and getClientInfo().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
25
diff
changeset
|
1315 * @throws SQLException - if the database server returns an error |
c2bf983dc79b
Implemented Connection methods: getClientInfo(name) and getClientInfo().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
25
diff
changeset
|
1316 * when fetching the client info value from the database |
c2bf983dc79b
Implemented Connection methods: getClientInfo(name) and getClientInfo().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
25
diff
changeset
|
1317 * or this method is called on a closed connection |
c2bf983dc79b
Implemented Connection methods: getClientInfo(name) and getClientInfo().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
25
diff
changeset
|
1318 * @since 1.6 |
c2bf983dc79b
Implemented Connection methods: getClientInfo(name) and getClientInfo().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
25
diff
changeset
|
1319 */ |
c2bf983dc79b
Implemented Connection methods: getClientInfo(name) and getClientInfo().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
25
diff
changeset
|
1320 @Override |
c2bf983dc79b
Implemented Connection methods: getClientInfo(name) and getClientInfo().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
25
diff
changeset
|
1321 public Properties getClientInfo() throws SQLException { |
905
a52bc2dcdb8c
Implement ClientInfo API
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
903
diff
changeset
|
1322 Properties props = new Properties(); |
a52bc2dcdb8c
Implement ClientInfo API
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
903
diff
changeset
|
1323 |
914
e0120c7052bb
Check for rs == null to prevent NullPoinerExceptions.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
906
diff
changeset
|
1324 // only MonetDB Server 11.51 (Aug2024) or higher supports Client Info Properties |
905
a52bc2dcdb8c
Implement ClientInfo API
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
903
diff
changeset
|
1325 if (server.canClientInfo()) { |
a52bc2dcdb8c
Implement ClientInfo API
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
903
diff
changeset
|
1326 StringBuilder builder = new StringBuilder("SELECT "); |
a52bc2dcdb8c
Implement ClientInfo API
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
903
diff
changeset
|
1327 String sep = ""; |
a52bc2dcdb8c
Implement ClientInfo API
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
903
diff
changeset
|
1328 for (Entry<String, String> entry: getClientInfoAttributeNames().entrySet()) { |
a52bc2dcdb8c
Implement ClientInfo API
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
903
diff
changeset
|
1329 String jdbcName = entry.getKey(); |
a52bc2dcdb8c
Implement ClientInfo API
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
903
diff
changeset
|
1330 String attrName = entry.getValue(); |
a52bc2dcdb8c
Implement ClientInfo API
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
903
diff
changeset
|
1331 builder.append(sep); |
a52bc2dcdb8c
Implement ClientInfo API
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
903
diff
changeset
|
1332 sep = ", "; |
a52bc2dcdb8c
Implement ClientInfo API
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
903
diff
changeset
|
1333 builder.append(attrName); |
a52bc2dcdb8c
Implement ClientInfo API
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
903
diff
changeset
|
1334 builder.append(" AS \""); |
a52bc2dcdb8c
Implement ClientInfo API
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
903
diff
changeset
|
1335 builder.append(jdbcName); |
a52bc2dcdb8c
Implement ClientInfo API
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
903
diff
changeset
|
1336 builder.append("\""); |
a52bc2dcdb8c
Implement ClientInfo API
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
903
diff
changeset
|
1337 } |
a52bc2dcdb8c
Implement ClientInfo API
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
903
diff
changeset
|
1338 builder.append(" FROM sys.sessions WHERE sessionid = current_sessionid()"); |
a52bc2dcdb8c
Implement ClientInfo API
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
903
diff
changeset
|
1339 |
914
e0120c7052bb
Check for rs == null to prevent NullPoinerExceptions.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
906
diff
changeset
|
1340 try (Statement st = createStatement(); ResultSet rs = st.executeQuery(builder.toString())) { |
e0120c7052bb
Check for rs == null to prevent NullPoinerExceptions.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
906
diff
changeset
|
1341 if (rs != null && rs.next()) { |
905
a52bc2dcdb8c
Implement ClientInfo API
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
903
diff
changeset
|
1342 ResultSetMetaData md = rs.getMetaData(); |
a52bc2dcdb8c
Implement ClientInfo API
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
903
diff
changeset
|
1343 for (int i = 1; i <= md.getColumnCount(); i++) { |
a52bc2dcdb8c
Implement ClientInfo API
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
903
diff
changeset
|
1344 String key = md.getColumnName(i); |
a52bc2dcdb8c
Implement ClientInfo API
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
903
diff
changeset
|
1345 String value = rs.getString(i); |
a52bc2dcdb8c
Implement ClientInfo API
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
903
diff
changeset
|
1346 props.setProperty(key, value != null ? value : ""); |
a52bc2dcdb8c
Implement ClientInfo API
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
903
diff
changeset
|
1347 } |
a52bc2dcdb8c
Implement ClientInfo API
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
903
diff
changeset
|
1348 } |
a52bc2dcdb8c
Implement ClientInfo API
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
903
diff
changeset
|
1349 } |
a52bc2dcdb8c
Implement ClientInfo API
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
903
diff
changeset
|
1350 } |
a52bc2dcdb8c
Implement ClientInfo API
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
903
diff
changeset
|
1351 return props; |
a52bc2dcdb8c
Implement ClientInfo API
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
903
diff
changeset
|
1352 } |
a52bc2dcdb8c
Implement ClientInfo API
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
903
diff
changeset
|
1353 |
a52bc2dcdb8c
Implement ClientInfo API
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
903
diff
changeset
|
1354 private HashMap<String,String> getClientInfoAttributeNames() throws SQLException { |
a52bc2dcdb8c
Implement ClientInfo API
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
903
diff
changeset
|
1355 if (clientInfoAttributeNames == null) { |
a52bc2dcdb8c
Implement ClientInfo API
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
903
diff
changeset
|
1356 HashMap<String, String> map = new HashMap<>(); |
914
e0120c7052bb
Check for rs == null to prevent NullPoinerExceptions.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
906
diff
changeset
|
1357 // only MonetDB Server 11.51 (Aug2024) or higher has table sys.clientinfo_properties with 5 rows |
906
8c8c423dc619
Older servers don't have clientinfo_properties yet
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
905
diff
changeset
|
1358 if (server.canClientInfo()) { |
8c8c423dc619
Older servers don't have clientinfo_properties yet
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
905
diff
changeset
|
1359 try (Statement st = createStatement(); ResultSet rs = st.executeQuery("SELECT prop, session_attr FROM sys.clientinfo_properties")) { |
914
e0120c7052bb
Check for rs == null to prevent NullPoinerExceptions.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
906
diff
changeset
|
1360 while (rs != null && rs.next()) { |
906
8c8c423dc619
Older servers don't have clientinfo_properties yet
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
905
diff
changeset
|
1361 String jdbcName = rs.getString(1); |
8c8c423dc619
Older servers don't have clientinfo_properties yet
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
905
diff
changeset
|
1362 String attrName = rs.getString(2); |
8c8c423dc619
Older servers don't have clientinfo_properties yet
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
905
diff
changeset
|
1363 map.put(jdbcName, attrName); |
8c8c423dc619
Older servers don't have clientinfo_properties yet
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
905
diff
changeset
|
1364 } |
905
a52bc2dcdb8c
Implement ClientInfo API
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
903
diff
changeset
|
1365 } |
a52bc2dcdb8c
Implement ClientInfo API
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
903
diff
changeset
|
1366 } |
a52bc2dcdb8c
Implement ClientInfo API
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
903
diff
changeset
|
1367 clientInfoAttributeNames = map; |
a52bc2dcdb8c
Implement ClientInfo API
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
903
diff
changeset
|
1368 } |
a52bc2dcdb8c
Implement ClientInfo API
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
903
diff
changeset
|
1369 return clientInfoAttributeNames; |
45
c2bf983dc79b
Implemented Connection methods: getClientInfo(name) and getClientInfo().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
25
diff
changeset
|
1370 } |
c2bf983dc79b
Implemented Connection methods: getClientInfo(name) and getClientInfo().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
25
diff
changeset
|
1371 |
c2bf983dc79b
Implemented Connection methods: getClientInfo(name) and getClientInfo().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
25
diff
changeset
|
1372 /** |
c2bf983dc79b
Implemented Connection methods: getClientInfo(name) and getClientInfo().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
25
diff
changeset
|
1373 * Sets the value of the client info property specified by name to the value specified by value. |
c2bf983dc79b
Implemented Connection methods: getClientInfo(name) and getClientInfo().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
25
diff
changeset
|
1374 * Applications may use the DatabaseMetaData.getClientInfoProperties method to determine |
c2bf983dc79b
Implemented Connection methods: getClientInfo(name) and getClientInfo().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
25
diff
changeset
|
1375 * the client info properties supported by the driver and the maximum length that may be specified |
c2bf983dc79b
Implemented Connection methods: getClientInfo(name) and getClientInfo().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
25
diff
changeset
|
1376 * for each property. |
c2bf983dc79b
Implemented Connection methods: getClientInfo(name) and getClientInfo().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
25
diff
changeset
|
1377 * |
c2bf983dc79b
Implemented Connection methods: getClientInfo(name) and getClientInfo().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
25
diff
changeset
|
1378 * The driver stores the value specified in a suitable location in the database. For example |
c2bf983dc79b
Implemented Connection methods: getClientInfo(name) and getClientInfo().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
25
diff
changeset
|
1379 * in a special register, session parameter, or system table column. For efficiency the driver |
c2bf983dc79b
Implemented Connection methods: getClientInfo(name) and getClientInfo().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
25
diff
changeset
|
1380 * may defer setting the value in the database until the next time a statement is executed |
c2bf983dc79b
Implemented Connection methods: getClientInfo(name) and getClientInfo().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
25
diff
changeset
|
1381 * or prepared. Other than storing the client information in the appropriate place in the |
c2bf983dc79b
Implemented Connection methods: getClientInfo(name) and getClientInfo().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
25
diff
changeset
|
1382 * database, these methods shall not alter the behavior of the connection in anyway. |
c2bf983dc79b
Implemented Connection methods: getClientInfo(name) and getClientInfo().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
25
diff
changeset
|
1383 * The values supplied to these methods are used for accounting, diagnostics and debugging purposes only. |
c2bf983dc79b
Implemented Connection methods: getClientInfo(name) and getClientInfo().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
25
diff
changeset
|
1384 * |
c2bf983dc79b
Implemented Connection methods: getClientInfo(name) and getClientInfo().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
25
diff
changeset
|
1385 * The driver shall generate a warning if the client info name specified is not recognized by the driver. |
c2bf983dc79b
Implemented Connection methods: getClientInfo(name) and getClientInfo().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
25
diff
changeset
|
1386 * |
c2bf983dc79b
Implemented Connection methods: getClientInfo(name) and getClientInfo().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
25
diff
changeset
|
1387 * If the value specified to this method is greater than the maximum length for the property |
c2bf983dc79b
Implemented Connection methods: getClientInfo(name) and getClientInfo().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
25
diff
changeset
|
1388 * the driver may either truncate the value and generate a warning or generate a SQLClientInfoException. |
c2bf983dc79b
Implemented Connection methods: getClientInfo(name) and getClientInfo().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
25
diff
changeset
|
1389 * If the driver generates a SQLClientInfoException, the value specified was not set on the connection. |
c2bf983dc79b
Implemented Connection methods: getClientInfo(name) and getClientInfo().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
25
diff
changeset
|
1390 * |
c2bf983dc79b
Implemented Connection methods: getClientInfo(name) and getClientInfo().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
25
diff
changeset
|
1391 * The following are standard client info properties. Drivers are not required to support these |
c2bf983dc79b
Implemented Connection methods: getClientInfo(name) and getClientInfo().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
25
diff
changeset
|
1392 * properties however if the driver supports a client info property that can be described by one |
c2bf983dc79b
Implemented Connection methods: getClientInfo(name) and getClientInfo().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
25
diff
changeset
|
1393 * of the standard properties, the standard property name should be used. |
c2bf983dc79b
Implemented Connection methods: getClientInfo(name) and getClientInfo().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
25
diff
changeset
|
1394 * |
c2bf983dc79b
Implemented Connection methods: getClientInfo(name) and getClientInfo().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
25
diff
changeset
|
1395 * ApplicationName - The name of the application currently utilizing the connection |
c2bf983dc79b
Implemented Connection methods: getClientInfo(name) and getClientInfo().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
25
diff
changeset
|
1396 * ClientUser - The name of the user that the application using the connection is performing work for. |
c2bf983dc79b
Implemented Connection methods: getClientInfo(name) and getClientInfo().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
25
diff
changeset
|
1397 * This may not be the same as the user name that was used in establishing the connection. |
c2bf983dc79b
Implemented Connection methods: getClientInfo(name) and getClientInfo().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
25
diff
changeset
|
1398 * ClientHostname - The hostname of the computer the application using the connection is running on. |
c2bf983dc79b
Implemented Connection methods: getClientInfo(name) and getClientInfo().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
25
diff
changeset
|
1399 * |
c2bf983dc79b
Implemented Connection methods: getClientInfo(name) and getClientInfo().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
25
diff
changeset
|
1400 * @param name - The name of the client info property to set |
c2bf983dc79b
Implemented Connection methods: getClientInfo(name) and getClientInfo().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
25
diff
changeset
|
1401 * @param value - The value to set the client info property to. If the |
c2bf983dc79b
Implemented Connection methods: getClientInfo(name) and getClientInfo().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
25
diff
changeset
|
1402 * value is null, the current value of the specified property is cleared. |
c2bf983dc79b
Implemented Connection methods: getClientInfo(name) and getClientInfo().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
25
diff
changeset
|
1403 * @throws SQLClientInfoException - if the database server returns an error |
c2bf983dc79b
Implemented Connection methods: getClientInfo(name) and getClientInfo().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
25
diff
changeset
|
1404 * while setting the clientInfo values on the database server |
c2bf983dc79b
Implemented Connection methods: getClientInfo(name) and getClientInfo().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
25
diff
changeset
|
1405 * or this method is called on a closed connection |
c2bf983dc79b
Implemented Connection methods: getClientInfo(name) and getClientInfo().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
25
diff
changeset
|
1406 * @since 1.6 |
c2bf983dc79b
Implemented Connection methods: getClientInfo(name) and getClientInfo().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
25
diff
changeset
|
1407 */ |
c2bf983dc79b
Implemented Connection methods: getClientInfo(name) and getClientInfo().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
25
diff
changeset
|
1408 @Override |
295
003ae6d881db
Add "final" keyword to method arguments and local variables where possible.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
292
diff
changeset
|
1409 public void setClientInfo(final String name, final String value) throws SQLClientInfoException { |
905
a52bc2dcdb8c
Implement ClientInfo API
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
903
diff
changeset
|
1410 ClientInfo info = new ClientInfo(); |
a52bc2dcdb8c
Implement ClientInfo API
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
903
diff
changeset
|
1411 try { |
a52bc2dcdb8c
Implement ClientInfo API
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
903
diff
changeset
|
1412 info.set(name, value, getClientInfoAttributeNames().keySet()); |
a52bc2dcdb8c
Implement ClientInfo API
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
903
diff
changeset
|
1413 sendClientInfo(info); |
a52bc2dcdb8c
Implement ClientInfo API
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
903
diff
changeset
|
1414 SQLWarning warn = info.warnings(); |
a52bc2dcdb8c
Implement ClientInfo API
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
903
diff
changeset
|
1415 if (warn != null) |
a52bc2dcdb8c
Implement ClientInfo API
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
903
diff
changeset
|
1416 addWarning(warn); |
a52bc2dcdb8c
Implement ClientInfo API
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
903
diff
changeset
|
1417 } catch (SQLException e) { |
a52bc2dcdb8c
Implement ClientInfo API
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
903
diff
changeset
|
1418 throw info.wrapException(e); |
a52bc2dcdb8c
Implement ClientInfo API
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
903
diff
changeset
|
1419 } |
45
c2bf983dc79b
Implemented Connection methods: getClientInfo(name) and getClientInfo().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
25
diff
changeset
|
1420 } |
c2bf983dc79b
Implemented Connection methods: getClientInfo(name) and getClientInfo().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
25
diff
changeset
|
1421 |
c2bf983dc79b
Implemented Connection methods: getClientInfo(name) and getClientInfo().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
25
diff
changeset
|
1422 /** |
c2bf983dc79b
Implemented Connection methods: getClientInfo(name) and getClientInfo().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
25
diff
changeset
|
1423 * Sets the value of the connection's client info properties. |
c2bf983dc79b
Implemented Connection methods: getClientInfo(name) and getClientInfo().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
25
diff
changeset
|
1424 * The Properties object contains the names and values of the client info |
c2bf983dc79b
Implemented Connection methods: getClientInfo(name) and getClientInfo().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
25
diff
changeset
|
1425 * properties to be set. The set of client info properties contained in the |
c2bf983dc79b
Implemented Connection methods: getClientInfo(name) and getClientInfo().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
25
diff
changeset
|
1426 * properties list replaces the current set of client info properties on the connection. |
c2bf983dc79b
Implemented Connection methods: getClientInfo(name) and getClientInfo().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
25
diff
changeset
|
1427 * If a property that is currently set on the connection is not present in the |
c2bf983dc79b
Implemented Connection methods: getClientInfo(name) and getClientInfo().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
25
diff
changeset
|
1428 * properties list, that property is cleared. Specifying an empty properties list |
c2bf983dc79b
Implemented Connection methods: getClientInfo(name) and getClientInfo().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
25
diff
changeset
|
1429 * will clear all of the properties on the connection. |
c2bf983dc79b
Implemented Connection methods: getClientInfo(name) and getClientInfo().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
25
diff
changeset
|
1430 * See setClientInfo (String, String) for more information. |
c2bf983dc79b
Implemented Connection methods: getClientInfo(name) and getClientInfo().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
25
diff
changeset
|
1431 * |
c2bf983dc79b
Implemented Connection methods: getClientInfo(name) and getClientInfo().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
25
diff
changeset
|
1432 * If an error occurs in setting any of the client info properties, a |
c2bf983dc79b
Implemented Connection methods: getClientInfo(name) and getClientInfo().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
25
diff
changeset
|
1433 * SQLClientInfoException is thrown. The SQLClientInfoException contains information |
c2bf983dc79b
Implemented Connection methods: getClientInfo(name) and getClientInfo().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
25
diff
changeset
|
1434 * indicating which client info properties were not set. The state of the client |
c2bf983dc79b
Implemented Connection methods: getClientInfo(name) and getClientInfo().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
25
diff
changeset
|
1435 * information is unknown because some databases do not allow multiple client info |
c2bf983dc79b
Implemented Connection methods: getClientInfo(name) and getClientInfo().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
25
diff
changeset
|
1436 * properties to be set atomically. For those databases, one or more properties may |
c2bf983dc79b
Implemented Connection methods: getClientInfo(name) and getClientInfo().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
25
diff
changeset
|
1437 * have been set before the error occurred. |
c2bf983dc79b
Implemented Connection methods: getClientInfo(name) and getClientInfo().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
25
diff
changeset
|
1438 * |
c2bf983dc79b
Implemented Connection methods: getClientInfo(name) and getClientInfo().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
25
diff
changeset
|
1439 * @param props - The list of client info properties to set |
c2bf983dc79b
Implemented Connection methods: getClientInfo(name) and getClientInfo().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
25
diff
changeset
|
1440 * @throws SQLClientInfoException - if the database server returns an error |
c2bf983dc79b
Implemented Connection methods: getClientInfo(name) and getClientInfo().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
25
diff
changeset
|
1441 * while setting the clientInfo values on the database server |
c2bf983dc79b
Implemented Connection methods: getClientInfo(name) and getClientInfo().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
25
diff
changeset
|
1442 * or this method is called on a closed connection |
c2bf983dc79b
Implemented Connection methods: getClientInfo(name) and getClientInfo().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
25
diff
changeset
|
1443 * @since 1.6 |
c2bf983dc79b
Implemented Connection methods: getClientInfo(name) and getClientInfo().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
25
diff
changeset
|
1444 */ |
c2bf983dc79b
Implemented Connection methods: getClientInfo(name) and getClientInfo().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
25
diff
changeset
|
1445 @Override |
295
003ae6d881db
Add "final" keyword to method arguments and local variables where possible.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
292
diff
changeset
|
1446 public void setClientInfo(final Properties props) throws SQLClientInfoException { |
905
a52bc2dcdb8c
Implement ClientInfo API
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
903
diff
changeset
|
1447 ClientInfo info = new ClientInfo(); |
a52bc2dcdb8c
Implement ClientInfo API
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
903
diff
changeset
|
1448 try { |
a52bc2dcdb8c
Implement ClientInfo API
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
903
diff
changeset
|
1449 for (String name: props.stringPropertyNames()) { |
a52bc2dcdb8c
Implement ClientInfo API
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
903
diff
changeset
|
1450 String value = props.getProperty(name); |
a52bc2dcdb8c
Implement ClientInfo API
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
903
diff
changeset
|
1451 info.set(name, value, getClientInfoAttributeNames().keySet()); |
47
562dbfb2fee8
Prevent null pointer exception by checking props argument
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
45
diff
changeset
|
1452 } |
905
a52bc2dcdb8c
Implement ClientInfo API
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
903
diff
changeset
|
1453 sendClientInfo(info); |
a52bc2dcdb8c
Implement ClientInfo API
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
903
diff
changeset
|
1454 SQLWarning warn = info.warnings(); |
a52bc2dcdb8c
Implement ClientInfo API
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
903
diff
changeset
|
1455 if (warn != null) |
a52bc2dcdb8c
Implement ClientInfo API
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
903
diff
changeset
|
1456 addWarning(warn); |
a52bc2dcdb8c
Implement ClientInfo API
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
903
diff
changeset
|
1457 } catch (SQLClientInfoException e) { |
a52bc2dcdb8c
Implement ClientInfo API
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
903
diff
changeset
|
1458 throw e; |
a52bc2dcdb8c
Implement ClientInfo API
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
903
diff
changeset
|
1459 } catch (SQLException e) { |
a52bc2dcdb8c
Implement ClientInfo API
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
903
diff
changeset
|
1460 throw info.wrapException(e); |
45
c2bf983dc79b
Implemented Connection methods: getClientInfo(name) and getClientInfo().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
25
diff
changeset
|
1461 } |
c2bf983dc79b
Implemented Connection methods: getClientInfo(name) and getClientInfo().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
25
diff
changeset
|
1462 } |
c2bf983dc79b
Implemented Connection methods: getClientInfo(name) and getClientInfo().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
25
diff
changeset
|
1463 |
905
a52bc2dcdb8c
Implement ClientInfo API
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
903
diff
changeset
|
1464 private void sendClientInfo(ClientInfo info) throws SQLException { |
a52bc2dcdb8c
Implement ClientInfo API
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
903
diff
changeset
|
1465 String formatted = info.format(); |
a52bc2dcdb8c
Implement ClientInfo API
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
903
diff
changeset
|
1466 if (!formatted.isEmpty()) |
a52bc2dcdb8c
Implement ClientInfo API
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
903
diff
changeset
|
1467 sendControlCommand("clientinfo " + formatted); |
a52bc2dcdb8c
Implement ClientInfo API
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
903
diff
changeset
|
1468 } |
a52bc2dcdb8c
Implement ClientInfo API
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
903
diff
changeset
|
1469 |
45
c2bf983dc79b
Implemented Connection methods: getClientInfo(name) and getClientInfo().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
25
diff
changeset
|
1470 //== Java 1.7 methods (JDBC 4.1) |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
1471 |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
1472 /** |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
1473 * Sets the given schema name to access. |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
1474 * |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
1475 * @param schema the name of a schema in which to work |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
1476 * @throws SQLException if a database access error occurs or this |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
1477 * method is called on a closed connection |
45
c2bf983dc79b
Implemented Connection methods: getClientInfo(name) and getClientInfo().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
25
diff
changeset
|
1478 * @since 1.7 |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
1479 */ |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
1480 @Override |
295
003ae6d881db
Add "final" keyword to method arguments and local variables where possible.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
292
diff
changeset
|
1481 public void setSchema(final String schema) throws SQLException { |
348
bcb9a99d399d
Add private checkNotClosed() method to check if the connection is not closed.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
345
diff
changeset
|
1482 checkNotClosed(); |
284
e5b99c929a2d
Improve setSchema(String schema) by checking also on empty name.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
278
diff
changeset
|
1483 if (schema == null || schema.isEmpty()) |
45
c2bf983dc79b
Implemented Connection methods: getClientInfo(name) and getClientInfo().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
25
diff
changeset
|
1484 throw new SQLException("Missing schema name", "M1M05"); |
c2bf983dc79b
Implemented Connection methods: getClientInfo(name) and getClientInfo().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
25
diff
changeset
|
1485 |
284
e5b99c929a2d
Improve setSchema(String schema) by checking also on empty name.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
278
diff
changeset
|
1486 Statement st = null; |
45
c2bf983dc79b
Implemented Connection methods: getClientInfo(name) and getClientInfo().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
25
diff
changeset
|
1487 try { |
284
e5b99c929a2d
Improve setSchema(String schema) by checking also on empty name.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
278
diff
changeset
|
1488 st = createStatement(); |
e5b99c929a2d
Improve setSchema(String schema) by checking also on empty name.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
278
diff
changeset
|
1489 if (st != null) |
e5b99c929a2d
Improve setSchema(String schema) by checking also on empty name.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
278
diff
changeset
|
1490 st.execute("SET SCHEMA \"" + schema + "\""); |
e5b99c929a2d
Improve setSchema(String schema) by checking also on empty name.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
278
diff
changeset
|
1491 // do not catch any Exception, just let it propagate |
45
c2bf983dc79b
Implemented Connection methods: getClientInfo(name) and getClientInfo().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
25
diff
changeset
|
1492 } finally { |
300
8cc3b51d1984
Add a utility method to close objects ignoring any possible SQLExceptions thrown.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
296
diff
changeset
|
1493 closeResultsetStatement(null, st); |
45
c2bf983dc79b
Implemented Connection methods: getClientInfo(name) and getClientInfo().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
25
diff
changeset
|
1494 } |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
1495 } |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
1496 |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
1497 /** |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
1498 * Retrieves this Connection object's current schema name. |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
1499 * |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
1500 * @return the current schema name or null if there is none |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
1501 * @throws SQLException if a database access error occurs or this |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
1502 * method is called on a closed connection |
45
c2bf983dc79b
Implemented Connection methods: getClientInfo(name) and getClientInfo().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
25
diff
changeset
|
1503 * @since 1.7 |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
1504 */ |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
1505 @Override |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
1506 public String getSchema() throws SQLException { |
348
bcb9a99d399d
Add private checkNotClosed() method to check if the connection is not closed.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
345
diff
changeset
|
1507 checkNotClosed(); |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
1508 |
284
e5b99c929a2d
Improve setSchema(String schema) by checking also on empty name.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
278
diff
changeset
|
1509 String cur_schema = null; |
e5b99c929a2d
Improve setSchema(String schema) by checking also on empty name.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
278
diff
changeset
|
1510 Statement st = null; |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
1511 ResultSet rs = null; |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
1512 try { |
284
e5b99c929a2d
Improve setSchema(String schema) by checking also on empty name.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
278
diff
changeset
|
1513 st = createStatement(); |
e5b99c929a2d
Improve setSchema(String schema) by checking also on empty name.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
278
diff
changeset
|
1514 if (st != null) { |
e5b99c929a2d
Improve setSchema(String schema) by checking also on empty name.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
278
diff
changeset
|
1515 rs = st.executeQuery("SELECT CURRENT_SCHEMA"); |
703
1c9d4c2a6947
Add method boolean inRawStringsMode() to check if iconnected server is running in raw_strings mode.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
702
diff
changeset
|
1516 if (rs != null && rs.next()) { |
1c9d4c2a6947
Add method boolean inRawStringsMode() to check if iconnected server is running in raw_strings mode.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
702
diff
changeset
|
1517 cur_schema = rs.getString(1); |
284
e5b99c929a2d
Improve setSchema(String schema) by checking also on empty name.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
278
diff
changeset
|
1518 } |
e5b99c929a2d
Improve setSchema(String schema) by checking also on empty name.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
278
diff
changeset
|
1519 } |
e5b99c929a2d
Improve setSchema(String schema) by checking also on empty name.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
278
diff
changeset
|
1520 // do not catch any Exception, just let it propagate |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
1521 } finally { |
300
8cc3b51d1984
Add a utility method to close objects ignoring any possible SQLExceptions thrown.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
296
diff
changeset
|
1522 closeResultsetStatement(rs, st); |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
1523 } |
284
e5b99c929a2d
Improve setSchema(String schema) by checking also on empty name.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
278
diff
changeset
|
1524 if (cur_schema == null) |
e5b99c929a2d
Improve setSchema(String schema) by checking also on empty name.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
278
diff
changeset
|
1525 throw new SQLException("Failed to fetch schema name", "02000"); |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
1526 return cur_schema; |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
1527 } |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
1528 |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
1529 /** |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
1530 * Terminates an open connection. Calling abort results in: |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
1531 * * The connection marked as closed |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
1532 * * Closes any physical connection to the database |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
1533 * * Releases resources used by the connection |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
1534 * * Insures that any thread that is currently accessing the |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
1535 * connection will either progress to completion or throw an |
45
c2bf983dc79b
Implemented Connection methods: getClientInfo(name) and getClientInfo().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
25
diff
changeset
|
1536 * SQLException. |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
1537 * Calling abort marks the connection closed and releases any |
45
c2bf983dc79b
Implemented Connection methods: getClientInfo(name) and getClientInfo().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
25
diff
changeset
|
1538 * resources. Calling abort on a closed connection is a no-op. |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
1539 * |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
1540 * @param executor The Executor implementation which will be used by |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
1541 * abort |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
1542 * @throws SQLException if a database access error occurs or the |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
1543 * executor is null |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
1544 * @throws SecurityException if a security manager exists and |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
1545 * its checkPermission method denies calling abort |
45
c2bf983dc79b
Implemented Connection methods: getClientInfo(name) and getClientInfo().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
25
diff
changeset
|
1546 * @since 1.7 |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
1547 */ |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
1548 @Override |
295
003ae6d881db
Add "final" keyword to method arguments and local variables where possible.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
292
diff
changeset
|
1549 public void abort(final Executor executor) throws SQLException { |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
1550 if (closed) |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
1551 return; |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
1552 if (executor == null) |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
1553 throw new SQLException("executor is null", "M1M05"); |
771
c85c2d90d31f
Improve the implementation of abort() by using the provided Executor object.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
764
diff
changeset
|
1554 |
c85c2d90d31f
Improve the implementation of abort() by using the provided Executor object.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
764
diff
changeset
|
1555 executor.execute(new Runnable() { |
c85c2d90d31f
Improve the implementation of abort() by using the provided Executor object.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
764
diff
changeset
|
1556 @Override |
c85c2d90d31f
Improve the implementation of abort() by using the provided Executor object.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
764
diff
changeset
|
1557 public void run() { |
c85c2d90d31f
Improve the implementation of abort() by using the provided Executor object.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
764
diff
changeset
|
1558 // this is really the simplest thing to do, it destroys |
c85c2d90d31f
Improve the implementation of abort() by using the provided Executor object.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
764
diff
changeset
|
1559 // everything (in particular the server connection) |
c85c2d90d31f
Improve the implementation of abort() by using the provided Executor object.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
764
diff
changeset
|
1560 close(); |
c85c2d90d31f
Improve the implementation of abort() by using the provided Executor object.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
764
diff
changeset
|
1561 } |
c85c2d90d31f
Improve the implementation of abort() by using the provided Executor object.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
764
diff
changeset
|
1562 }); |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
1563 } |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
1564 |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
1565 /** |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
1566 * Sets the maximum period a Connection or objects created from the |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
1567 * Connection will wait for the database to reply to any one |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
1568 * request. If any request remains unanswered, the waiting method |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
1569 * will return with a SQLException, and the Connection or objects |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
1570 * created from the Connection will be marked as closed. Any |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
1571 * subsequent use of the objects, with the exception of the close, |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
1572 * isClosed or Connection.isValid methods, will result in a |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
1573 * SQLException. |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
1574 * |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
1575 * @param executor The Executor implementation which will be used by |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
1576 * setNetworkTimeout |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
1577 * @param millis The time in milliseconds to wait for the |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
1578 * database operation to complete |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
1579 * @throws SQLException if a database access error occurs, this |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
1580 * method is called on a closed connection, the executor is |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
1581 * null, or the value specified for seconds is less than 0. |
45
c2bf983dc79b
Implemented Connection methods: getClientInfo(name) and getClientInfo().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
25
diff
changeset
|
1582 * @since 1.7 |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
1583 */ |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
1584 @Override |
295
003ae6d881db
Add "final" keyword to method arguments and local variables where possible.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
292
diff
changeset
|
1585 public void setNetworkTimeout(final Executor executor, final int millis) throws SQLException { |
348
bcb9a99d399d
Add private checkNotClosed() method to check if the connection is not closed.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
345
diff
changeset
|
1586 checkNotClosed(); |
bcb9a99d399d
Add private checkNotClosed() method to check if the connection is not closed.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
345
diff
changeset
|
1587 // executor object is not used yet, so no need to test it. |
bcb9a99d399d
Add private checkNotClosed() method to check if the connection is not closed.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
345
diff
changeset
|
1588 // if (executor == null) |
bcb9a99d399d
Add private checkNotClosed() method to check if the connection is not closed.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
345
diff
changeset
|
1589 // throw new SQLException("executor is null", "M1M05"); |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
1590 if (millis < 0) |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
1591 throw new SQLException("milliseconds is less than zero", "M1M05"); |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
1592 |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
1593 try { |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
1594 server.setSoTimeout(millis); |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
1595 } catch (SocketException e) { |
144
d6abd1ffffbb
Use SQLNonTransientConnectionException instead of SQLException where applicable (SQLState starts with 08)
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
136
diff
changeset
|
1596 throw new SQLNonTransientConnectionException(e.getMessage(), "08000"); |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
1597 } |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
1598 } |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
1599 |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
1600 /** |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
1601 * Retrieves the number of milliseconds the driver will wait for a |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
1602 * database request to complete. If the limit is exceeded, a |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
1603 * SQLException is thrown. |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
1604 * |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
1605 * @return the current timeout limit in milliseconds; zero means |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
1606 * there is no limit |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
1607 * @throws SQLException if a database access error occurs or |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
1608 * this method is called on a closed Connection |
45
c2bf983dc79b
Implemented Connection methods: getClientInfo(name) and getClientInfo().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
25
diff
changeset
|
1609 * @since 1.7 |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
1610 */ |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
1611 @Override |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
1612 public int getNetworkTimeout() throws SQLException { |
348
bcb9a99d399d
Add private checkNotClosed() method to check if the connection is not closed.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
345
diff
changeset
|
1613 checkNotClosed(); |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
1614 try { |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
1615 return server.getSoTimeout(); |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
1616 } catch (SocketException e) { |
144
d6abd1ffffbb
Use SQLNonTransientConnectionException instead of SQLException where applicable (SQLState starts with 08)
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
136
diff
changeset
|
1617 throw new SQLNonTransientConnectionException(e.getMessage(), "08000"); |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
1618 } |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
1619 } |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
1620 |
45
c2bf983dc79b
Implemented Connection methods: getClientInfo(name) and getClientInfo().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
25
diff
changeset
|
1621 //== end methods of interface java.sql.Connection |
c2bf983dc79b
Implemented Connection methods: getClientInfo(name) and getClientInfo().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
25
diff
changeset
|
1622 |
562
c640075da7c9
only comment improvements
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
559
diff
changeset
|
1623 |
857
8dc5047e9d04
Move non JDBC API method to the end where the other add methods are placed.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
852
diff
changeset
|
1624 //== internal helper methods which do NOT belong to the JDBC interface |
8dc5047e9d04
Move non JDBC API method to the end where the other add methods are placed.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
852
diff
changeset
|
1625 |
8dc5047e9d04
Move non JDBC API method to the end where the other add methods are placed.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
852
diff
changeset
|
1626 /** |
8dc5047e9d04
Move non JDBC API method to the end where the other add methods are placed.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
852
diff
changeset
|
1627 * Construct a Properties object holding all connection parameters such |
8dc5047e9d04
Move non JDBC API method to the end where the other add methods are placed.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
852
diff
changeset
|
1628 * as host, port, TLS configuration, autocommit, etc. |
867
5a59910e8f87
Resolve some javadoc errors and warnings
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
857
diff
changeset
|
1629 * Passing this to {@link java.sql.DriverManager#getConnection(String,java.util.Properties)} |
5a59910e8f87
Resolve some javadoc errors and warnings
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
857
diff
changeset
|
1630 * together with the URL "jdbc:monetdb:" will create a new connection identical to |
857
8dc5047e9d04
Move non JDBC API method to the end where the other add methods are placed.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
852
diff
changeset
|
1631 * the current one. |
8dc5047e9d04
Move non JDBC API method to the end where the other add methods are placed.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
852
diff
changeset
|
1632 * |
8dc5047e9d04
Move non JDBC API method to the end where the other add methods are placed.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
852
diff
changeset
|
1633 * @return a Properties object |
8dc5047e9d04
Move non JDBC API method to the end where the other add methods are placed.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
852
diff
changeset
|
1634 */ |
8dc5047e9d04
Move non JDBC API method to the end where the other add methods are placed.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
852
diff
changeset
|
1635 public Properties getConnectionProperties() { |
8dc5047e9d04
Move non JDBC API method to the end where the other add methods are placed.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
852
diff
changeset
|
1636 return target.getProperties(); |
8dc5047e9d04
Move non JDBC API method to the end where the other add methods are placed.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
852
diff
changeset
|
1637 } |
8dc5047e9d04
Move non JDBC API method to the end where the other add methods are placed.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
852
diff
changeset
|
1638 |
562
c640075da7c9
only comment improvements
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
559
diff
changeset
|
1639 |
576
095e896f9d7a
Updated comments. Improved code. Added final keywords
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
568
diff
changeset
|
1640 /** Handler for COPY ... INTO ... FROM 'data-file-name' ON CLIENT requests */ |
563
fa2493d924c8
Small updates
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
562
diff
changeset
|
1641 private UploadHandler uploadHandler; |
576
095e896f9d7a
Updated comments. Improved code. Added final keywords
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
568
diff
changeset
|
1642 /** Handler for COPY ... INTO 'data-file-name' ON CLIENT requests */ |
563
fa2493d924c8
Small updates
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
562
diff
changeset
|
1643 private DownloadHandler downloadHandler; |
fa2493d924c8
Small updates
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
562
diff
changeset
|
1644 |
539
5d524783f7b0
Move {get/set}{Down/Up}loadHander further down the file
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
535
diff
changeset
|
1645 /** |
563
fa2493d924c8
Small updates
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
562
diff
changeset
|
1646 * Registers a {@link UploadHandler} to support for example COPY INTO mytable FROM 'data.csv' ON CLIENT |
539
5d524783f7b0
Move {get/set}{Down/Up}loadHander further down the file
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
535
diff
changeset
|
1647 * |
5d524783f7b0
Move {get/set}{Down/Up}loadHander further down the file
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
535
diff
changeset
|
1648 * @param uploadHandler the handler to register, or null to deregister |
5d524783f7b0
Move {get/set}{Down/Up}loadHander further down the file
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
535
diff
changeset
|
1649 */ |
576
095e896f9d7a
Updated comments. Improved code. Added final keywords
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
568
diff
changeset
|
1650 public void setUploadHandler(final UploadHandler uploadHandler) { |
539
5d524783f7b0
Move {get/set}{Down/Up}loadHander further down the file
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
535
diff
changeset
|
1651 this.uploadHandler = uploadHandler; |
5d524783f7b0
Move {get/set}{Down/Up}loadHander further down the file
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
535
diff
changeset
|
1652 } |
5d524783f7b0
Move {get/set}{Down/Up}loadHander further down the file
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
535
diff
changeset
|
1653 |
5d524783f7b0
Move {get/set}{Down/Up}loadHander further down the file
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
535
diff
changeset
|
1654 /** |
943 | 1655 * Get the currently registered {@link UploadHandler}, or null |
709
bdeabbd46ec6
Resolve javac and javadoc warnings when compiled with JDK19.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
708
diff
changeset
|
1656 * |
943 | 1657 * @return the currently registered UploadHandler, or null |
539
5d524783f7b0
Move {get/set}{Down/Up}loadHander further down the file
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
535
diff
changeset
|
1658 */ |
541
31df6a12fd41
Make the MonetUploadHandler and MonetDownloadHandler interfaces part of MonetConnection
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
540
diff
changeset
|
1659 public UploadHandler getUploadHandler() { |
539
5d524783f7b0
Move {get/set}{Down/Up}loadHander further down the file
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
535
diff
changeset
|
1660 return uploadHandler; |
5d524783f7b0
Move {get/set}{Down/Up}loadHander further down the file
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
535
diff
changeset
|
1661 } |
576
095e896f9d7a
Updated comments. Improved code. Added final keywords
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
568
diff
changeset
|
1662 |
539
5d524783f7b0
Move {get/set}{Down/Up}loadHander further down the file
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
535
diff
changeset
|
1663 /** |
563
fa2493d924c8
Small updates
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
562
diff
changeset
|
1664 * Registers a {@link DownloadHandler} to support for example COPY select_result INTO 'data.csv' ON CLIENT |
539
5d524783f7b0
Move {get/set}{Down/Up}loadHander further down the file
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
535
diff
changeset
|
1665 * |
5d524783f7b0
Move {get/set}{Down/Up}loadHander further down the file
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
535
diff
changeset
|
1666 * @param downloadHandler the handler to register, or null to deregister |
5d524783f7b0
Move {get/set}{Down/Up}loadHander further down the file
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
535
diff
changeset
|
1667 */ |
576
095e896f9d7a
Updated comments. Improved code. Added final keywords
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
568
diff
changeset
|
1668 public void setDownloadHandler(final DownloadHandler downloadHandler) { |
539
5d524783f7b0
Move {get/set}{Down/Up}loadHander further down the file
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
535
diff
changeset
|
1669 this.downloadHandler = downloadHandler; |
5d524783f7b0
Move {get/set}{Down/Up}loadHander further down the file
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
535
diff
changeset
|
1670 } |
5d524783f7b0
Move {get/set}{Down/Up}loadHander further down the file
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
535
diff
changeset
|
1671 |
5d524783f7b0
Move {get/set}{Down/Up}loadHander further down the file
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
535
diff
changeset
|
1672 /** |
943 | 1673 * Get the currently registered {@link DownloadHandler} handler, or null |
709
bdeabbd46ec6
Resolve javac and javadoc warnings when compiled with JDK19.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
708
diff
changeset
|
1674 * |
943 | 1675 * @return the currently registered DownloadHandler handler, or null |
539
5d524783f7b0
Move {get/set}{Down/Up}loadHander further down the file
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
535
diff
changeset
|
1676 */ |
541
31df6a12fd41
Make the MonetUploadHandler and MonetDownloadHandler interfaces part of MonetConnection
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
540
diff
changeset
|
1677 public DownloadHandler getDownloadHandler() { |
539
5d524783f7b0
Move {get/set}{Down/Up}loadHander further down the file
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
535
diff
changeset
|
1678 return downloadHandler; |
5d524783f7b0
Move {get/set}{Down/Up}loadHander further down the file
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
535
diff
changeset
|
1679 } |
5d524783f7b0
Move {get/set}{Down/Up}loadHander further down the file
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
535
diff
changeset
|
1680 |
709
bdeabbd46ec6
Resolve javac and javadoc warnings when compiled with JDK19.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
708
diff
changeset
|
1681 /** |
bdeabbd46ec6
Resolve javac and javadoc warnings when compiled with JDK19.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
708
diff
changeset
|
1682 * Local helper method to set the time zone for this connection |
bdeabbd46ec6
Resolve javac and javadoc warnings when compiled with JDK19.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
708
diff
changeset
|
1683 * |
bdeabbd46ec6
Resolve javac and javadoc warnings when compiled with JDK19.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
708
diff
changeset
|
1684 * @param offsetSeconds Time Zone offset in seconds, can be negative or zero |
bdeabbd46ec6
Resolve javac and javadoc warnings when compiled with JDK19.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
708
diff
changeset
|
1685 * @throws SQLException if an IO exception or a database error occurs |
bdeabbd46ec6
Resolve javac and javadoc warnings when compiled with JDK19.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
708
diff
changeset
|
1686 */ |
bdeabbd46ec6
Resolve javac and javadoc warnings when compiled with JDK19.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
708
diff
changeset
|
1687 private void setTimezone(int offsetSeconds) throws SQLException { |
671
fade6c6960cc
Refactor Handshake options
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
666
diff
changeset
|
1688 final StringBuilder tz = new StringBuilder(64); |
fade6c6960cc
Refactor Handshake options
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
666
diff
changeset
|
1689 tz.append("SET TIME ZONE INTERVAL '"); |
fade6c6960cc
Refactor Handshake options
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
666
diff
changeset
|
1690 int offsetMinutes = offsetSeconds / 60; |
fade6c6960cc
Refactor Handshake options
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
666
diff
changeset
|
1691 if (offsetMinutes < 0) { |
fade6c6960cc
Refactor Handshake options
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
666
diff
changeset
|
1692 tz.append('-'); |
fade6c6960cc
Refactor Handshake options
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
666
diff
changeset
|
1693 offsetMinutes = -offsetMinutes; // make it positive |
fade6c6960cc
Refactor Handshake options
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
666
diff
changeset
|
1694 } else { |
fade6c6960cc
Refactor Handshake options
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
666
diff
changeset
|
1695 tz.append('+'); |
fade6c6960cc
Refactor Handshake options
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
666
diff
changeset
|
1696 } |
fade6c6960cc
Refactor Handshake options
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
666
diff
changeset
|
1697 int offsetHours = offsetMinutes / 60; |
fade6c6960cc
Refactor Handshake options
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
666
diff
changeset
|
1698 if (offsetHours < 10) |
fade6c6960cc
Refactor Handshake options
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
666
diff
changeset
|
1699 tz.append('0'); |
fade6c6960cc
Refactor Handshake options
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
666
diff
changeset
|
1700 tz.append(offsetHours).append(':'); |
fade6c6960cc
Refactor Handshake options
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
666
diff
changeset
|
1701 offsetMinutes -= offsetHours * 60; |
fade6c6960cc
Refactor Handshake options
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
666
diff
changeset
|
1702 if (offsetMinutes < 10) |
fade6c6960cc
Refactor Handshake options
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
666
diff
changeset
|
1703 tz.append('0'); |
fade6c6960cc
Refactor Handshake options
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
666
diff
changeset
|
1704 tz.append(offsetMinutes).append("' HOUR TO MINUTE"); |
fade6c6960cc
Refactor Handshake options
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
666
diff
changeset
|
1705 sendIndependentCommand(tz.toString()); |
fade6c6960cc
Refactor Handshake options
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
666
diff
changeset
|
1706 } |
fade6c6960cc
Refactor Handshake options
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
666
diff
changeset
|
1707 |
45
c2bf983dc79b
Implemented Connection methods: getClientInfo(name) and getClientInfo().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
25
diff
changeset
|
1708 /** |
709
bdeabbd46ec6
Resolve javac and javadoc warnings when compiled with JDK19.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
708
diff
changeset
|
1709 * Local helper method to check whether the Connection object is closed |
bdeabbd46ec6
Resolve javac and javadoc warnings when compiled with JDK19.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
708
diff
changeset
|
1710 * and throw an SQLExecption if it is closed. |
bdeabbd46ec6
Resolve javac and javadoc warnings when compiled with JDK19.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
708
diff
changeset
|
1711 * |
bdeabbd46ec6
Resolve javac and javadoc warnings when compiled with JDK19.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
708
diff
changeset
|
1712 * @throws SQLException if this connection is closed |
408
5540793628d6
Improve code when setting query timeout. It used to call the sys.settimeout(bigint) which is deprecated as of release Jun2020 (11.37.7) and replaced by new sys.setquerytimeout(int).
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
407
diff
changeset
|
1713 */ |
5540793628d6
Improve code when setting query timeout. It used to call the sys.settimeout(bigint) which is deprecated as of release Jun2020 (11.37.7) and replaced by new sys.setquerytimeout(int).
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
407
diff
changeset
|
1714 private void checkNotClosed() throws SQLException { |
5540793628d6
Improve code when setting query timeout. It used to call the sys.settimeout(bigint) which is deprecated as of release Jun2020 (11.37.7) and replaced by new sys.setquerytimeout(int).
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
407
diff
changeset
|
1715 if (closed) |
5540793628d6
Improve code when setting query timeout. It used to call the sys.settimeout(bigint) which is deprecated as of release Jun2020 (11.37.7) and replaced by new sys.setquerytimeout(int).
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
407
diff
changeset
|
1716 throw new SQLException("Connection is closed", "M1M20"); |
5540793628d6
Improve code when setting query timeout. It used to call the sys.settimeout(bigint) which is deprecated as of release Jun2020 (11.37.7) and replaced by new sys.setquerytimeout(int).
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
407
diff
changeset
|
1717 } |
5540793628d6
Improve code when setting query timeout. It used to call the sys.settimeout(bigint) which is deprecated as of release Jun2020 (11.37.7) and replaced by new sys.setquerytimeout(int).
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
407
diff
changeset
|
1718 |
5540793628d6
Improve code when setting query timeout. It used to call the sys.settimeout(bigint) which is deprecated as of release Jun2020 (11.37.7) and replaced by new sys.setquerytimeout(int).
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
407
diff
changeset
|
1719 /** |
709
bdeabbd46ec6
Resolve javac and javadoc warnings when compiled with JDK19.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
708
diff
changeset
|
1720 * Utility method to call sys.setquerytimeout(int); procedure on the connected server |
bdeabbd46ec6
Resolve javac and javadoc warnings when compiled with JDK19.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
708
diff
changeset
|
1721 * or sys.settimeout(int); procedure on older servers which do not support the new procedure. |
408
5540793628d6
Improve code when setting query timeout. It used to call the sys.settimeout(bigint) which is deprecated as of release Jun2020 (11.37.7) and replaced by new sys.setquerytimeout(int).
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
407
diff
changeset
|
1722 * It is called from: MonetConnection.isValid() and MonetStatement.internalExecute() |
709
bdeabbd46ec6
Resolve javac and javadoc warnings when compiled with JDK19.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
708
diff
changeset
|
1723 * |
bdeabbd46ec6
Resolve javac and javadoc warnings when compiled with JDK19.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
708
diff
changeset
|
1724 * @param seconds the time out time in seconds |
bdeabbd46ec6
Resolve javac and javadoc warnings when compiled with JDK19.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
708
diff
changeset
|
1725 * @throws SQLException if an IO exception or a database error occurs |
408
5540793628d6
Improve code when setting query timeout. It used to call the sys.settimeout(bigint) which is deprecated as of release Jun2020 (11.37.7) and replaced by new sys.setquerytimeout(int).
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
407
diff
changeset
|
1726 */ |
650
849f99124e32
Correcting implementation of Statement.setQueryTimeout(int seconds).
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
626
diff
changeset
|
1727 void setQueryTimeout(final int seconds) throws SQLException { |
849f99124e32
Correcting implementation of Statement.setQueryTimeout(int seconds).
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
626
diff
changeset
|
1728 if (seconds < 0) |
849f99124e32
Correcting implementation of Statement.setQueryTimeout(int seconds).
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
626
diff
changeset
|
1729 throw new SQLException("query timeout seconds is less than zero", "M1M05"); |
408
5540793628d6
Improve code when setting query timeout. It used to call the sys.settimeout(bigint) which is deprecated as of release Jun2020 (11.37.7) and replaced by new sys.setquerytimeout(int).
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
407
diff
changeset
|
1730 |
5540793628d6
Improve code when setting query timeout. It used to call the sys.settimeout(bigint) which is deprecated as of release Jun2020 (11.37.7) and replaced by new sys.setquerytimeout(int).
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
407
diff
changeset
|
1731 checkNotClosed(); |
5540793628d6
Improve code when setting query timeout. It used to call the sys.settimeout(bigint) which is deprecated as of release Jun2020 (11.37.7) and replaced by new sys.setquerytimeout(int).
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
407
diff
changeset
|
1732 Statement st = null; |
5540793628d6
Improve code when setting query timeout. It used to call the sys.settimeout(bigint) which is deprecated as of release Jun2020 (11.37.7) and replaced by new sys.setquerytimeout(int).
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
407
diff
changeset
|
1733 try { |
480
849af4b76b28
Optimise code by reducing local variables which are used only once, replacing complex string concatenation by using StringBuilder, replacing some ternairy operators.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
474
diff
changeset
|
1734 final String callstmt; |
751
1566dbfaa13b
Correct setQueryTimeout(secs) implementation. It was changed to match the web documentation (see https://dev.monetdb.org/hg/monetdb-java/rev/849f99124e32 ) but it appears the web documentation was wrong. So revert the changes made.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
736
diff
changeset
|
1735 |
1566dbfaa13b
Correct setQueryTimeout(secs) implementation. It was changed to match the web documentation (see https://dev.monetdb.org/hg/monetdb-java/rev/849f99124e32 ) but it appears the web documentation was wrong. So revert the changes made.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
736
diff
changeset
|
1736 // as of release Jun2020 (11.37.7) the function sys.settimeout(secs bigint) |
1566dbfaa13b
Correct setQueryTimeout(secs) implementation. It was changed to match the web documentation (see https://dev.monetdb.org/hg/monetdb-java/rev/849f99124e32 ) but it appears the web documentation was wrong. So revert the changes made.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
736
diff
changeset
|
1737 // is deprecated and replaced by new sys.setquerytimeout(secs int) |
919
ce6bc9908735
Add utility method checkMinimumDBVersion(int major, int minor). Will be used in more classes.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
914
diff
changeset
|
1738 if (checkMinimumDBVersion(11, 37)) |
ce6bc9908735
Add utility method checkMinimumDBVersion(int major, int minor). Will be used in more classes.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
914
diff
changeset
|
1739 callstmt = "CALL sys.\"setquerytimeout\"(" + seconds + ")"; |
ce6bc9908735
Add utility method checkMinimumDBVersion(int major, int minor). Will be used in more classes.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
914
diff
changeset
|
1740 else |
751
1566dbfaa13b
Correct setQueryTimeout(secs) implementation. It was changed to match the web documentation (see https://dev.monetdb.org/hg/monetdb-java/rev/849f99124e32 ) but it appears the web documentation was wrong. So revert the changes made.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
736
diff
changeset
|
1741 callstmt = "CALL sys.\"settimeout\"(" + seconds + ")"; |
919
ce6bc9908735
Add utility method checkMinimumDBVersion(int major, int minor). Will be used in more classes.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
914
diff
changeset
|
1742 |
408
5540793628d6
Improve code when setting query timeout. It used to call the sys.settimeout(bigint) which is deprecated as of release Jun2020 (11.37.7) and replaced by new sys.setquerytimeout(int).
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
407
diff
changeset
|
1743 // for debug: System.out.println("Before: " + callstmt); |
5540793628d6
Improve code when setting query timeout. It used to call the sys.settimeout(bigint) which is deprecated as of release Jun2020 (11.37.7) and replaced by new sys.setquerytimeout(int).
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
407
diff
changeset
|
1744 st = createStatement(); |
5540793628d6
Improve code when setting query timeout. It used to call the sys.settimeout(bigint) which is deprecated as of release Jun2020 (11.37.7) and replaced by new sys.setquerytimeout(int).
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
407
diff
changeset
|
1745 st.execute(callstmt); |
5540793628d6
Improve code when setting query timeout. It used to call the sys.settimeout(bigint) which is deprecated as of release Jun2020 (11.37.7) and replaced by new sys.setquerytimeout(int).
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
407
diff
changeset
|
1746 // for debug: System.out.println("After : " + callstmt); |
5540793628d6
Improve code when setting query timeout. It used to call the sys.settimeout(bigint) which is deprecated as of release Jun2020 (11.37.7) and replaced by new sys.setquerytimeout(int).
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
407
diff
changeset
|
1747 |
650
849f99124e32
Correcting implementation of Statement.setQueryTimeout(int seconds).
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
626
diff
changeset
|
1748 this.lastSetQueryTimeout = seconds; |
408
5540793628d6
Improve code when setting query timeout. It used to call the sys.settimeout(bigint) which is deprecated as of release Jun2020 (11.37.7) and replaced by new sys.setquerytimeout(int).
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
407
diff
changeset
|
1749 } |
5540793628d6
Improve code when setting query timeout. It used to call the sys.settimeout(bigint) which is deprecated as of release Jun2020 (11.37.7) and replaced by new sys.setquerytimeout(int).
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
407
diff
changeset
|
1750 /* do not catch SQLException here, as we want to know it when it fails */ |
5540793628d6
Improve code when setting query timeout. It used to call the sys.settimeout(bigint) which is deprecated as of release Jun2020 (11.37.7) and replaced by new sys.setquerytimeout(int).
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
407
diff
changeset
|
1751 finally { |
5540793628d6
Improve code when setting query timeout. It used to call the sys.settimeout(bigint) which is deprecated as of release Jun2020 (11.37.7) and replaced by new sys.setquerytimeout(int).
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
407
diff
changeset
|
1752 closeResultsetStatement(null, st); |
5540793628d6
Improve code when setting query timeout. It used to call the sys.settimeout(bigint) which is deprecated as of release Jun2020 (11.37.7) and replaced by new sys.setquerytimeout(int).
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
407
diff
changeset
|
1753 } |
5540793628d6
Improve code when setting query timeout. It used to call the sys.settimeout(bigint) which is deprecated as of release Jun2020 (11.37.7) and replaced by new sys.setquerytimeout(int).
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
407
diff
changeset
|
1754 } |
5540793628d6
Improve code when setting query timeout. It used to call the sys.settimeout(bigint) which is deprecated as of release Jun2020 (11.37.7) and replaced by new sys.setquerytimeout(int).
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
407
diff
changeset
|
1755 |
5540793628d6
Improve code when setting query timeout. It used to call the sys.settimeout(bigint) which is deprecated as of release Jun2020 (11.37.7) and replaced by new sys.setquerytimeout(int).
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
407
diff
changeset
|
1756 /** |
175
8700d9ef2ace
Added possibility via a connection property to let the JDBC driver
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
167
diff
changeset
|
1757 * This allows generic JDBC programs to fetch Blob data via getBytes() |
8700d9ef2ace
Added possibility via a connection property to let the JDBC driver
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
167
diff
changeset
|
1758 * instead of getBlob() and Blob.getBinaryStream() to reduce overhead. |
332
e8962bdaa206
Moved utility methods and associated caches from DatabaseMetaData to Connection object.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
324
diff
changeset
|
1759 * It is called from: MonetResultSet and MonetPreparedStatement |
709
bdeabbd46ec6
Resolve javac and javadoc warnings when compiled with JDK19.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
708
diff
changeset
|
1760 * |
bdeabbd46ec6
Resolve javac and javadoc warnings when compiled with JDK19.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
708
diff
changeset
|
1761 * @return whether the JDBC BLOB type should be mapped to VARBINARY type. |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
1762 */ |
199
e87d89d371f1
Make some public non-JDBC methods accessable only to classes of the same package.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
194
diff
changeset
|
1763 boolean mapBlobAsVarBinary() { |
793
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
788
diff
changeset
|
1764 return target.isTreatBlobAsBinary(); |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
1765 } |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
1766 |
175
8700d9ef2ace
Added possibility via a connection property to let the JDBC driver
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
167
diff
changeset
|
1767 /** |
8700d9ef2ace
Added possibility via a connection property to let the JDBC driver
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
167
diff
changeset
|
1768 * This allows generic JDBC programs to fetch Clob data via getString() |
8700d9ef2ace
Added possibility via a connection property to let the JDBC driver
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
167
diff
changeset
|
1769 * instead of getClob() and Clob.getCharacterStream() to reduce overhead. |
332
e8962bdaa206
Moved utility methods and associated caches from DatabaseMetaData to Connection object.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
324
diff
changeset
|
1770 * It is called from: MonetResultSet and MonetPreparedStatement |
709
bdeabbd46ec6
Resolve javac and javadoc warnings when compiled with JDK19.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
708
diff
changeset
|
1771 * |
bdeabbd46ec6
Resolve javac and javadoc warnings when compiled with JDK19.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
708
diff
changeset
|
1772 * @return whether the JDBC CLOB type should be mapped to VARCHAR type. |
175
8700d9ef2ace
Added possibility via a connection property to let the JDBC driver
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
167
diff
changeset
|
1773 */ |
199
e87d89d371f1
Make some public non-JDBC methods accessable only to classes of the same package.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
194
diff
changeset
|
1774 boolean mapClobAsVarChar() { |
793
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
788
diff
changeset
|
1775 return target.isTreatClobAsVarchar(); |
175
8700d9ef2ace
Added possibility via a connection property to let the JDBC driver
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
167
diff
changeset
|
1776 } |
77
83aee4f60649
Added private method sendTransactionCommand(String); to reduce duplicate code in 6 methods.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
47
diff
changeset
|
1777 |
83aee4f60649
Added private method sendTransactionCommand(String); to reduce duplicate code in 6 methods.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
47
diff
changeset
|
1778 /** |
709
bdeabbd46ec6
Resolve javac and javadoc warnings when compiled with JDK19.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
708
diff
changeset
|
1779 * It is called from: getURL()in MonetDatabaseMetaData |
bdeabbd46ec6
Resolve javac and javadoc warnings when compiled with JDK19.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
708
diff
changeset
|
1780 * |
332
e8962bdaa206
Moved utility methods and associated caches from DatabaseMetaData to Connection object.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
324
diff
changeset
|
1781 * @return the MonetDB JDBC Connection URL (without user name and password). |
e8962bdaa206
Moved utility methods and associated caches from DatabaseMetaData to Connection object.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
324
diff
changeset
|
1782 */ |
e8962bdaa206
Moved utility methods and associated caches from DatabaseMetaData to Connection object.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
324
diff
changeset
|
1783 String getJDBCURL() { |
793
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
788
diff
changeset
|
1784 return target.buildUrl(); |
332
e8962bdaa206
Moved utility methods and associated caches from DatabaseMetaData to Connection object.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
324
diff
changeset
|
1785 } |
e8962bdaa206
Moved utility methods and associated caches from DatabaseMetaData to Connection object.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
324
diff
changeset
|
1786 |
703
1c9d4c2a6947
Add method boolean inRawStringsMode() to check if iconnected server is running in raw_strings mode.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
702
diff
changeset
|
1787 // Internal caches for 4 static mserver5 environment values |
407
40a1db14dca5
Optimise code, reduce duplicate code, cache major and minor version nrs of connected database server and max nr of clients so conversion of strings to ints is only done once.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
406
diff
changeset
|
1788 private String env_current_user; |
40a1db14dca5
Optimise code, reduce duplicate code, cache major and minor version nrs of connected database server and max nr of clients so conversion of strings to ints is only done once.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
406
diff
changeset
|
1789 private String env_monet_version; |
703
1c9d4c2a6947
Add method boolean inRawStringsMode() to check if iconnected server is running in raw_strings mode.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
702
diff
changeset
|
1790 private String env_raw_strings; // Note: this is only supported from Jun2020 (11.37) servers |
407
40a1db14dca5
Optimise code, reduce duplicate code, cache major and minor version nrs of connected database server and max nr of clients so conversion of strings to ints is only done once.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
406
diff
changeset
|
1791 private int maxConnections; |
332
e8962bdaa206
Moved utility methods and associated caches from DatabaseMetaData to Connection object.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
324
diff
changeset
|
1792 |
e8962bdaa206
Moved utility methods and associated caches from DatabaseMetaData to Connection object.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
324
diff
changeset
|
1793 /** |
703
1c9d4c2a6947
Add method boolean inRawStringsMode() to check if iconnected server is running in raw_strings mode.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
702
diff
changeset
|
1794 * Utility method to fetch 4 mserver5 environment values combined in one query for efficiency. |
1c9d4c2a6947
Add method boolean inRawStringsMode() to check if iconnected server is running in raw_strings mode.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
702
diff
changeset
|
1795 * We fetch the env values of: current_user, monet_version, max_clients and raw_strings. |
332
e8962bdaa206
Moved utility methods and associated caches from DatabaseMetaData to Connection object.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
324
diff
changeset
|
1796 * We cache them such that we do not need to query the server again and again. |
703
1c9d4c2a6947
Add method boolean inRawStringsMode() to check if iconnected server is running in raw_strings mode.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
702
diff
changeset
|
1797 * Note: raw_strings is available in sys.env() result set since release Jun2020 (11.37) |
709
bdeabbd46ec6
Resolve javac and javadoc warnings when compiled with JDK19.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
708
diff
changeset
|
1798 * |
bdeabbd46ec6
Resolve javac and javadoc warnings when compiled with JDK19.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
708
diff
changeset
|
1799 * @throws SQLException if execution of query failed |
332
e8962bdaa206
Moved utility methods and associated caches from DatabaseMetaData to Connection object.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
324
diff
changeset
|
1800 */ |
e8962bdaa206
Moved utility methods and associated caches from DatabaseMetaData to Connection object.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
324
diff
changeset
|
1801 private synchronized void getEnvValues() throws SQLException { |
e8962bdaa206
Moved utility methods and associated caches from DatabaseMetaData to Connection object.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
324
diff
changeset
|
1802 Statement st = null; |
e8962bdaa206
Moved utility methods and associated caches from DatabaseMetaData to Connection object.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
324
diff
changeset
|
1803 ResultSet rs = null; |
e8962bdaa206
Moved utility methods and associated caches from DatabaseMetaData to Connection object.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
324
diff
changeset
|
1804 try { |
e8962bdaa206
Moved utility methods and associated caches from DatabaseMetaData to Connection object.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
324
diff
changeset
|
1805 st = createStatement(); |
e8962bdaa206
Moved utility methods and associated caches from DatabaseMetaData to Connection object.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
324
diff
changeset
|
1806 if (st != null) { |
e8962bdaa206
Moved utility methods and associated caches from DatabaseMetaData to Connection object.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
324
diff
changeset
|
1807 rs = st.executeQuery( |
e8962bdaa206
Moved utility methods and associated caches from DatabaseMetaData to Connection object.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
324
diff
changeset
|
1808 "SELECT \"name\", \"value\" FROM \"sys\".\"env\"()" + |
703
1c9d4c2a6947
Add method boolean inRawStringsMode() to check if iconnected server is running in raw_strings mode.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
702
diff
changeset
|
1809 " WHERE \"name\" IN ('monet_version', 'max_clients', 'raw_strings')" + |
332
e8962bdaa206
Moved utility methods and associated caches from DatabaseMetaData to Connection object.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
324
diff
changeset
|
1810 " UNION SELECT 'current_user' as \"name\", current_user as \"value\""); |
e8962bdaa206
Moved utility methods and associated caches from DatabaseMetaData to Connection object.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
324
diff
changeset
|
1811 if (rs != null) { |
e8962bdaa206
Moved utility methods and associated caches from DatabaseMetaData to Connection object.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
324
diff
changeset
|
1812 while (rs.next()) { |
e8962bdaa206
Moved utility methods and associated caches from DatabaseMetaData to Connection object.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
324
diff
changeset
|
1813 final String prop = rs.getString(1); |
e8962bdaa206
Moved utility methods and associated caches from DatabaseMetaData to Connection object.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
324
diff
changeset
|
1814 final String value = rs.getString(2); |
e8962bdaa206
Moved utility methods and associated caches from DatabaseMetaData to Connection object.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
324
diff
changeset
|
1815 if ("current_user".equals(prop)) { |
e8962bdaa206
Moved utility methods and associated caches from DatabaseMetaData to Connection object.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
324
diff
changeset
|
1816 env_current_user = value; |
e8962bdaa206
Moved utility methods and associated caches from DatabaseMetaData to Connection object.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
324
diff
changeset
|
1817 } else |
e8962bdaa206
Moved utility methods and associated caches from DatabaseMetaData to Connection object.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
324
diff
changeset
|
1818 if ("monet_version".equals(prop)) { |
e8962bdaa206
Moved utility methods and associated caches from DatabaseMetaData to Connection object.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
324
diff
changeset
|
1819 env_monet_version = value; |
e8962bdaa206
Moved utility methods and associated caches from DatabaseMetaData to Connection object.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
324
diff
changeset
|
1820 } else |
703
1c9d4c2a6947
Add method boolean inRawStringsMode() to check if iconnected server is running in raw_strings mode.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
702
diff
changeset
|
1821 if ("raw_strings".equals(prop)) { |
1c9d4c2a6947
Add method boolean inRawStringsMode() to check if iconnected server is running in raw_strings mode.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
702
diff
changeset
|
1822 env_raw_strings = value; |
1c9d4c2a6947
Add method boolean inRawStringsMode() to check if iconnected server is running in raw_strings mode.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
702
diff
changeset
|
1823 } else |
407
40a1db14dca5
Optimise code, reduce duplicate code, cache major and minor version nrs of connected database server and max nr of clients so conversion of strings to ints is only done once.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
406
diff
changeset
|
1824 if ("max_clients".equals(prop) && value != null) { |
40a1db14dca5
Optimise code, reduce duplicate code, cache major and minor version nrs of connected database server and max nr of clients so conversion of strings to ints is only done once.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
406
diff
changeset
|
1825 try { |
40a1db14dca5
Optimise code, reduce duplicate code, cache major and minor version nrs of connected database server and max nr of clients so conversion of strings to ints is only done once.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
406
diff
changeset
|
1826 maxConnections = Integer.parseInt(value); |
40a1db14dca5
Optimise code, reduce duplicate code, cache major and minor version nrs of connected database server and max nr of clients so conversion of strings to ints is only done once.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
406
diff
changeset
|
1827 } catch (NumberFormatException nfe) { |
40a1db14dca5
Optimise code, reduce duplicate code, cache major and minor version nrs of connected database server and max nr of clients so conversion of strings to ints is only done once.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
406
diff
changeset
|
1828 /* ignore */ |
40a1db14dca5
Optimise code, reduce duplicate code, cache major and minor version nrs of connected database server and max nr of clients so conversion of strings to ints is only done once.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
406
diff
changeset
|
1829 } |
40a1db14dca5
Optimise code, reduce duplicate code, cache major and minor version nrs of connected database server and max nr of clients so conversion of strings to ints is only done once.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
406
diff
changeset
|
1830 if (maxConnections <= 0) |
40a1db14dca5
Optimise code, reduce duplicate code, cache major and minor version nrs of connected database server and max nr of clients so conversion of strings to ints is only done once.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
406
diff
changeset
|
1831 maxConnections = 1; |
332
e8962bdaa206
Moved utility methods and associated caches from DatabaseMetaData to Connection object.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
324
diff
changeset
|
1832 } |
e8962bdaa206
Moved utility methods and associated caches from DatabaseMetaData to Connection object.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
324
diff
changeset
|
1833 } |
e8962bdaa206
Moved utility methods and associated caches from DatabaseMetaData to Connection object.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
324
diff
changeset
|
1834 } |
e8962bdaa206
Moved utility methods and associated caches from DatabaseMetaData to Connection object.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
324
diff
changeset
|
1835 } |
e8962bdaa206
Moved utility methods and associated caches from DatabaseMetaData to Connection object.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
324
diff
changeset
|
1836 /* do not catch SQLException here, as we need to know it when it fails */ |
e8962bdaa206
Moved utility methods and associated caches from DatabaseMetaData to Connection object.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
324
diff
changeset
|
1837 } finally { |
e8962bdaa206
Moved utility methods and associated caches from DatabaseMetaData to Connection object.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
324
diff
changeset
|
1838 closeResultsetStatement(rs, st); |
e8962bdaa206
Moved utility methods and associated caches from DatabaseMetaData to Connection object.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
324
diff
changeset
|
1839 } |
703
1c9d4c2a6947
Add method boolean inRawStringsMode() to check if iconnected server is running in raw_strings mode.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
702
diff
changeset
|
1840 // for debug: System.out.println("Read: env_current_user: " + env_current_user + " env_monet_version: " + env_monet_version + " env_max_clients: " + maxConnections + " env_raw_strings: " + env_raw_strings); |
332
e8962bdaa206
Moved utility methods and associated caches from DatabaseMetaData to Connection object.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
324
diff
changeset
|
1841 } |
e8962bdaa206
Moved utility methods and associated caches from DatabaseMetaData to Connection object.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
324
diff
changeset
|
1842 |
e8962bdaa206
Moved utility methods and associated caches from DatabaseMetaData to Connection object.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
324
diff
changeset
|
1843 /** |
709
bdeabbd46ec6
Resolve javac and javadoc warnings when compiled with JDK19.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
708
diff
changeset
|
1844 * Get user login name from the server. |
332
e8962bdaa206
Moved utility methods and associated caches from DatabaseMetaData to Connection object.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
324
diff
changeset
|
1845 * It is called from: MonetDatabaseMetaData |
709
bdeabbd46ec6
Resolve javac and javadoc warnings when compiled with JDK19.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
708
diff
changeset
|
1846 * |
bdeabbd46ec6
Resolve javac and javadoc warnings when compiled with JDK19.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
708
diff
changeset
|
1847 * @return the current User Name for this comnection |
bdeabbd46ec6
Resolve javac and javadoc warnings when compiled with JDK19.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
708
diff
changeset
|
1848 * @throws SQLException if fetching user name failed |
332
e8962bdaa206
Moved utility methods and associated caches from DatabaseMetaData to Connection object.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
324
diff
changeset
|
1849 */ |
e8962bdaa206
Moved utility methods and associated caches from DatabaseMetaData to Connection object.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
324
diff
changeset
|
1850 String getUserName() throws SQLException { |
e8962bdaa206
Moved utility methods and associated caches from DatabaseMetaData to Connection object.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
324
diff
changeset
|
1851 if (env_current_user == null) |
e8962bdaa206
Moved utility methods and associated caches from DatabaseMetaData to Connection object.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
324
diff
changeset
|
1852 getEnvValues(); |
e8962bdaa206
Moved utility methods and associated caches from DatabaseMetaData to Connection object.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
324
diff
changeset
|
1853 return env_current_user; |
e8962bdaa206
Moved utility methods and associated caches from DatabaseMetaData to Connection object.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
324
diff
changeset
|
1854 } |
e8962bdaa206
Moved utility methods and associated caches from DatabaseMetaData to Connection object.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
324
diff
changeset
|
1855 |
e8962bdaa206
Moved utility methods and associated caches from DatabaseMetaData to Connection object.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
324
diff
changeset
|
1856 /** |
709
bdeabbd46ec6
Resolve javac and javadoc warnings when compiled with JDK19.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
708
diff
changeset
|
1857 * Get the maximum number of allowed connections from the server. |
408
5540793628d6
Improve code when setting query timeout. It used to call the sys.settimeout(bigint) which is deprecated as of release Jun2020 (11.37.7) and replaced by new sys.setquerytimeout(int).
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
407
diff
changeset
|
1858 * It is called from: MonetDatabaseMetaData |
709
bdeabbd46ec6
Resolve javac and javadoc warnings when compiled with JDK19.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
708
diff
changeset
|
1859 * A result of zero means that there is no limit or the limit is not known |
bdeabbd46ec6
Resolve javac and javadoc warnings when compiled with JDK19.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
708
diff
changeset
|
1860 * |
bdeabbd46ec6
Resolve javac and javadoc warnings when compiled with JDK19.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
708
diff
changeset
|
1861 * @return the maximum number of active connections possible at one time |
bdeabbd46ec6
Resolve javac and javadoc warnings when compiled with JDK19.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
708
diff
changeset
|
1862 * @throws SQLException if fetching maximum connections failed |
408
5540793628d6
Improve code when setting query timeout. It used to call the sys.settimeout(bigint) which is deprecated as of release Jun2020 (11.37.7) and replaced by new sys.setquerytimeout(int).
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
407
diff
changeset
|
1863 */ |
5540793628d6
Improve code when setting query timeout. It used to call the sys.settimeout(bigint) which is deprecated as of release Jun2020 (11.37.7) and replaced by new sys.setquerytimeout(int).
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
407
diff
changeset
|
1864 int getMaxConnections() throws SQLException { |
5540793628d6
Improve code when setting query timeout. It used to call the sys.settimeout(bigint) which is deprecated as of release Jun2020 (11.37.7) and replaced by new sys.setquerytimeout(int).
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
407
diff
changeset
|
1865 if (maxConnections == 0) |
5540793628d6
Improve code when setting query timeout. It used to call the sys.settimeout(bigint) which is deprecated as of release Jun2020 (11.37.7) and replaced by new sys.setquerytimeout(int).
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
407
diff
changeset
|
1866 getEnvValues(); |
5540793628d6
Improve code when setting query timeout. It used to call the sys.settimeout(bigint) which is deprecated as of release Jun2020 (11.37.7) and replaced by new sys.setquerytimeout(int).
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
407
diff
changeset
|
1867 return maxConnections; |
5540793628d6
Improve code when setting query timeout. It used to call the sys.settimeout(bigint) which is deprecated as of release Jun2020 (11.37.7) and replaced by new sys.setquerytimeout(int).
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
407
diff
changeset
|
1868 } |
5540793628d6
Improve code when setting query timeout. It used to call the sys.settimeout(bigint) which is deprecated as of release Jun2020 (11.37.7) and replaced by new sys.setquerytimeout(int).
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
407
diff
changeset
|
1869 |
716
aeb268156580
Updated Copyright year.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
709
diff
changeset
|
1870 /** |
709
bdeabbd46ec6
Resolve javac and javadoc warnings when compiled with JDK19.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
708
diff
changeset
|
1871 * Get whether the server is started with raw_strings turned on. |
703
1c9d4c2a6947
Add method boolean inRawStringsMode() to check if iconnected server is running in raw_strings mode.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
702
diff
changeset
|
1872 * By default this is false (so C-style strings processing is used). |
707
7752e15b6a23
Correcting a typo in comment
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
705
diff
changeset
|
1873 * When a server is started with option: --set raw_strings=true |
703
1c9d4c2a6947
Add method boolean inRawStringsMode() to check if iconnected server is running in raw_strings mode.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
702
diff
changeset
|
1874 * then this will return true, else false. |
1c9d4c2a6947
Add method boolean inRawStringsMode() to check if iconnected server is running in raw_strings mode.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
702
diff
changeset
|
1875 * This startup option is supported only by servers since Jun2020 (11.37) onwards. |
709
bdeabbd46ec6
Resolve javac and javadoc warnings when compiled with JDK19.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
708
diff
changeset
|
1876 * |
bdeabbd46ec6
Resolve javac and javadoc warnings when compiled with JDK19.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
708
diff
changeset
|
1877 * @return whether the server is started with raw_strings processing enabled. |
bdeabbd46ec6
Resolve javac and javadoc warnings when compiled with JDK19.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
708
diff
changeset
|
1878 * @throws SQLException if fetching raw_strings setting failed |
703
1c9d4c2a6947
Add method boolean inRawStringsMode() to check if iconnected server is running in raw_strings mode.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
702
diff
changeset
|
1879 */ |
1c9d4c2a6947
Add method boolean inRawStringsMode() to check if iconnected server is running in raw_strings mode.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
702
diff
changeset
|
1880 boolean inRawStringsMode() throws SQLException { |
1c9d4c2a6947
Add method boolean inRawStringsMode() to check if iconnected server is running in raw_strings mode.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
702
diff
changeset
|
1881 if (env_raw_strings == null) { |
1c9d4c2a6947
Add method boolean inRawStringsMode() to check if iconnected server is running in raw_strings mode.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
702
diff
changeset
|
1882 getEnvValues(); |
1c9d4c2a6947
Add method boolean inRawStringsMode() to check if iconnected server is running in raw_strings mode.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
702
diff
changeset
|
1883 if (env_raw_strings == null) { |
1c9d4c2a6947
Add method boolean inRawStringsMode() to check if iconnected server is running in raw_strings mode.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
702
diff
changeset
|
1884 /* older servers (pre Jun2020 (11.37)) do not |
1c9d4c2a6947
Add method boolean inRawStringsMode() to check if iconnected server is running in raw_strings mode.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
702
diff
changeset
|
1885 * return this in the sys.env() view and did |
1c9d4c2a6947
Add method boolean inRawStringsMode() to check if iconnected server is running in raw_strings mode.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
702
diff
changeset
|
1886 * not yet support raw_strings. |
1c9d4c2a6947
Add method boolean inRawStringsMode() to check if iconnected server is running in raw_strings mode.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
702
diff
changeset
|
1887 * So set it to: false. */ |
1c9d4c2a6947
Add method boolean inRawStringsMode() to check if iconnected server is running in raw_strings mode.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
702
diff
changeset
|
1888 env_raw_strings = "false"; |
1c9d4c2a6947
Add method boolean inRawStringsMode() to check if iconnected server is running in raw_strings mode.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
702
diff
changeset
|
1889 } |
1c9d4c2a6947
Add method boolean inRawStringsMode() to check if iconnected server is running in raw_strings mode.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
702
diff
changeset
|
1890 } |
722
9a243dce3b15
Small improvements.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
716
diff
changeset
|
1891 return "true".equals(env_raw_strings); |
703
1c9d4c2a6947
Add method boolean inRawStringsMode() to check if iconnected server is running in raw_strings mode.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
702
diff
changeset
|
1892 } |
1c9d4c2a6947
Add method boolean inRawStringsMode() to check if iconnected server is running in raw_strings mode.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
702
diff
changeset
|
1893 |
408
5540793628d6
Improve code when setting query timeout. It used to call the sys.settimeout(bigint) which is deprecated as of release Jun2020 (11.37.7) and replaced by new sys.setquerytimeout(int).
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
407
diff
changeset
|
1894 /** |
709
bdeabbd46ec6
Resolve javac and javadoc warnings when compiled with JDK19.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
708
diff
changeset
|
1895 * Get the product version of the connected MonetDB Database Server. |
bdeabbd46ec6
Resolve javac and javadoc warnings when compiled with JDK19.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
708
diff
changeset
|
1896 * It is called from: MonetDatabaseMetaData |
bdeabbd46ec6
Resolve javac and javadoc warnings when compiled with JDK19.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
708
diff
changeset
|
1897 * |
332
e8962bdaa206
Moved utility methods and associated caches from DatabaseMetaData to Connection object.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
324
diff
changeset
|
1898 * @return the MonetDB Database Server version string. |
709
bdeabbd46ec6
Resolve javac and javadoc warnings when compiled with JDK19.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
708
diff
changeset
|
1899 * @throws SQLException if fetching MonetDB server version string failed |
332
e8962bdaa206
Moved utility methods and associated caches from DatabaseMetaData to Connection object.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
324
diff
changeset
|
1900 */ |
e8962bdaa206
Moved utility methods and associated caches from DatabaseMetaData to Connection object.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
324
diff
changeset
|
1901 String getDatabaseProductVersion() throws SQLException { |
e8962bdaa206
Moved utility methods and associated caches from DatabaseMetaData to Connection object.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
324
diff
changeset
|
1902 if (env_monet_version == null) |
e8962bdaa206
Moved utility methods and associated caches from DatabaseMetaData to Connection object.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
324
diff
changeset
|
1903 getEnvValues(); |
e8962bdaa206
Moved utility methods and associated caches from DatabaseMetaData to Connection object.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
324
diff
changeset
|
1904 // always return a valid String to prevent NPE in getTables() and getTableTypes() |
e8962bdaa206
Moved utility methods and associated caches from DatabaseMetaData to Connection object.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
324
diff
changeset
|
1905 if (env_monet_version != null) |
e8962bdaa206
Moved utility methods and associated caches from DatabaseMetaData to Connection object.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
324
diff
changeset
|
1906 return env_monet_version; |
e8962bdaa206
Moved utility methods and associated caches from DatabaseMetaData to Connection object.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
324
diff
changeset
|
1907 return ""; |
e8962bdaa206
Moved utility methods and associated caches from DatabaseMetaData to Connection object.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
324
diff
changeset
|
1908 } |
e8962bdaa206
Moved utility methods and associated caches from DatabaseMetaData to Connection object.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
324
diff
changeset
|
1909 |
408
5540793628d6
Improve code when setting query timeout. It used to call the sys.settimeout(bigint) which is deprecated as of release Jun2020 (11.37.7) and replaced by new sys.setquerytimeout(int).
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
407
diff
changeset
|
1910 private int databaseMajorVersion; |
332
e8962bdaa206
Moved utility methods and associated caches from DatabaseMetaData to Connection object.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
324
diff
changeset
|
1911 /** |
709
bdeabbd46ec6
Resolve javac and javadoc warnings when compiled with JDK19.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
708
diff
changeset
|
1912 * Get the major product version of the connected MonetDB Database Server. |
408
5540793628d6
Improve code when setting query timeout. It used to call the sys.settimeout(bigint) which is deprecated as of release Jun2020 (11.37.7) and replaced by new sys.setquerytimeout(int).
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
407
diff
changeset
|
1913 * The number is extracted from the env_monet_version the first time and cached for next calls. |
5540793628d6
Improve code when setting query timeout. It used to call the sys.settimeout(bigint) which is deprecated as of release Jun2020 (11.37.7) and replaced by new sys.setquerytimeout(int).
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
407
diff
changeset
|
1914 * It is called from: MonetDatabaseMetaData and MonetConnection |
709
bdeabbd46ec6
Resolve javac and javadoc warnings when compiled with JDK19.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
708
diff
changeset
|
1915 * |
bdeabbd46ec6
Resolve javac and javadoc warnings when compiled with JDK19.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
708
diff
changeset
|
1916 * @return the MonetDB Database Server major version number. |
bdeabbd46ec6
Resolve javac and javadoc warnings when compiled with JDK19.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
708
diff
changeset
|
1917 * @throws SQLException if fetching MonetDB server version string failed |
332
e8962bdaa206
Moved utility methods and associated caches from DatabaseMetaData to Connection object.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
324
diff
changeset
|
1918 */ |
e8962bdaa206
Moved utility methods and associated caches from DatabaseMetaData to Connection object.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
324
diff
changeset
|
1919 int getDatabaseMajorVersion() throws SQLException { |
407
40a1db14dca5
Optimise code, reduce duplicate code, cache major and minor version nrs of connected database server and max nr of clients so conversion of strings to ints is only done once.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
406
diff
changeset
|
1920 if (databaseMajorVersion == 0) { |
40a1db14dca5
Optimise code, reduce duplicate code, cache major and minor version nrs of connected database server and max nr of clients so conversion of strings to ints is only done once.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
406
diff
changeset
|
1921 if (env_monet_version == null) |
40a1db14dca5
Optimise code, reduce duplicate code, cache major and minor version nrs of connected database server and max nr of clients so conversion of strings to ints is only done once.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
406
diff
changeset
|
1922 getEnvValues(); |
40a1db14dca5
Optimise code, reduce duplicate code, cache major and minor version nrs of connected database server and max nr of clients so conversion of strings to ints is only done once.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
406
diff
changeset
|
1923 if (env_monet_version != null) { |
40a1db14dca5
Optimise code, reduce duplicate code, cache major and minor version nrs of connected database server and max nr of clients so conversion of strings to ints is only done once.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
406
diff
changeset
|
1924 try { |
40a1db14dca5
Optimise code, reduce duplicate code, cache major and minor version nrs of connected database server and max nr of clients so conversion of strings to ints is only done once.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
406
diff
changeset
|
1925 // from version string such as 11.33.9 extract number: 11 |
480
849af4b76b28
Optimise code by reducing local variables which are used only once, replacing complex string concatenation by using StringBuilder, replacing some ternairy operators.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
474
diff
changeset
|
1926 final int end = env_monet_version.indexOf('.'); |
849af4b76b28
Optimise code by reducing local variables which are used only once, replacing complex string concatenation by using StringBuilder, replacing some ternairy operators.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
474
diff
changeset
|
1927 databaseMajorVersion = Integer.parseInt((end >= 0) ? env_monet_version.substring(0, end) : env_monet_version); |
407
40a1db14dca5
Optimise code, reduce duplicate code, cache major and minor version nrs of connected database server and max nr of clients so conversion of strings to ints is only done once.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
406
diff
changeset
|
1928 } catch (NumberFormatException nfe) { |
40a1db14dca5
Optimise code, reduce duplicate code, cache major and minor version nrs of connected database server and max nr of clients so conversion of strings to ints is only done once.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
406
diff
changeset
|
1929 // ignore |
40a1db14dca5
Optimise code, reduce duplicate code, cache major and minor version nrs of connected database server and max nr of clients so conversion of strings to ints is only done once.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
406
diff
changeset
|
1930 } |
332
e8962bdaa206
Moved utility methods and associated caches from DatabaseMetaData to Connection object.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
324
diff
changeset
|
1931 } |
e8962bdaa206
Moved utility methods and associated caches from DatabaseMetaData to Connection object.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
324
diff
changeset
|
1932 } |
407
40a1db14dca5
Optimise code, reduce duplicate code, cache major and minor version nrs of connected database server and max nr of clients so conversion of strings to ints is only done once.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
406
diff
changeset
|
1933 return databaseMajorVersion; |
332
e8962bdaa206
Moved utility methods and associated caches from DatabaseMetaData to Connection object.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
324
diff
changeset
|
1934 } |
e8962bdaa206
Moved utility methods and associated caches from DatabaseMetaData to Connection object.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
324
diff
changeset
|
1935 |
408
5540793628d6
Improve code when setting query timeout. It used to call the sys.settimeout(bigint) which is deprecated as of release Jun2020 (11.37.7) and replaced by new sys.setquerytimeout(int).
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
407
diff
changeset
|
1936 private int databaseMinorVersion; |
332
e8962bdaa206
Moved utility methods and associated caches from DatabaseMetaData to Connection object.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
324
diff
changeset
|
1937 /** |
709
bdeabbd46ec6
Resolve javac and javadoc warnings when compiled with JDK19.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
708
diff
changeset
|
1938 * Get the minor product version of the connected MonetDB Database Server. |
408
5540793628d6
Improve code when setting query timeout. It used to call the sys.settimeout(bigint) which is deprecated as of release Jun2020 (11.37.7) and replaced by new sys.setquerytimeout(int).
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
407
diff
changeset
|
1939 * The number is extracted from the env_monet_version the first time and cached for next calls. |
5540793628d6
Improve code when setting query timeout. It used to call the sys.settimeout(bigint) which is deprecated as of release Jun2020 (11.37.7) and replaced by new sys.setquerytimeout(int).
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
407
diff
changeset
|
1940 * It is called from: MonetDatabaseMetaData and MonetConnection |
709
bdeabbd46ec6
Resolve javac and javadoc warnings when compiled with JDK19.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
708
diff
changeset
|
1941 * |
bdeabbd46ec6
Resolve javac and javadoc warnings when compiled with JDK19.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
708
diff
changeset
|
1942 * @return the MonetDB Database Server minor version number. |
bdeabbd46ec6
Resolve javac and javadoc warnings when compiled with JDK19.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
708
diff
changeset
|
1943 * @throws SQLException if fetching MonetDB server version string failed |
332
e8962bdaa206
Moved utility methods and associated caches from DatabaseMetaData to Connection object.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
324
diff
changeset
|
1944 */ |
e8962bdaa206
Moved utility methods and associated caches from DatabaseMetaData to Connection object.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
324
diff
changeset
|
1945 int getDatabaseMinorVersion() throws SQLException { |
407
40a1db14dca5
Optimise code, reduce duplicate code, cache major and minor version nrs of connected database server and max nr of clients so conversion of strings to ints is only done once.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
406
diff
changeset
|
1946 if (databaseMinorVersion == 0) { |
40a1db14dca5
Optimise code, reduce duplicate code, cache major and minor version nrs of connected database server and max nr of clients so conversion of strings to ints is only done once.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
406
diff
changeset
|
1947 if (env_monet_version == null) |
40a1db14dca5
Optimise code, reduce duplicate code, cache major and minor version nrs of connected database server and max nr of clients so conversion of strings to ints is only done once.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
406
diff
changeset
|
1948 getEnvValues(); |
40a1db14dca5
Optimise code, reduce duplicate code, cache major and minor version nrs of connected database server and max nr of clients so conversion of strings to ints is only done once.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
406
diff
changeset
|
1949 if (env_monet_version != null) { |
40a1db14dca5
Optimise code, reduce duplicate code, cache major and minor version nrs of connected database server and max nr of clients so conversion of strings to ints is only done once.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
406
diff
changeset
|
1950 try { |
40a1db14dca5
Optimise code, reduce duplicate code, cache major and minor version nrs of connected database server and max nr of clients so conversion of strings to ints is only done once.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
406
diff
changeset
|
1951 // from version string such as 11.33.9 extract number: 33 |
40a1db14dca5
Optimise code, reduce duplicate code, cache major and minor version nrs of connected database server and max nr of clients so conversion of strings to ints is only done once.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
406
diff
changeset
|
1952 int start = env_monet_version.indexOf('.'); |
40a1db14dca5
Optimise code, reduce duplicate code, cache major and minor version nrs of connected database server and max nr of clients so conversion of strings to ints is only done once.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
406
diff
changeset
|
1953 if (start >= 0) { |
40a1db14dca5
Optimise code, reduce duplicate code, cache major and minor version nrs of connected database server and max nr of clients so conversion of strings to ints is only done once.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
406
diff
changeset
|
1954 start++; |
40a1db14dca5
Optimise code, reduce duplicate code, cache major and minor version nrs of connected database server and max nr of clients so conversion of strings to ints is only done once.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
406
diff
changeset
|
1955 final int end = env_monet_version.indexOf('.', start); |
40a1db14dca5
Optimise code, reduce duplicate code, cache major and minor version nrs of connected database server and max nr of clients so conversion of strings to ints is only done once.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
406
diff
changeset
|
1956 databaseMinorVersion = Integer.parseInt((end > 0) ? env_monet_version.substring(start, end) : env_monet_version.substring(start)); |
40a1db14dca5
Optimise code, reduce duplicate code, cache major and minor version nrs of connected database server and max nr of clients so conversion of strings to ints is only done once.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
406
diff
changeset
|
1957 } |
40a1db14dca5
Optimise code, reduce duplicate code, cache major and minor version nrs of connected database server and max nr of clients so conversion of strings to ints is only done once.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
406
diff
changeset
|
1958 } catch (NumberFormatException nfe) { |
40a1db14dca5
Optimise code, reduce duplicate code, cache major and minor version nrs of connected database server and max nr of clients so conversion of strings to ints is only done once.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
406
diff
changeset
|
1959 // ignore |
332
e8962bdaa206
Moved utility methods and associated caches from DatabaseMetaData to Connection object.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
324
diff
changeset
|
1960 } |
e8962bdaa206
Moved utility methods and associated caches from DatabaseMetaData to Connection object.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
324
diff
changeset
|
1961 } |
e8962bdaa206
Moved utility methods and associated caches from DatabaseMetaData to Connection object.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
324
diff
changeset
|
1962 } |
407
40a1db14dca5
Optimise code, reduce duplicate code, cache major and minor version nrs of connected database server and max nr of clients so conversion of strings to ints is only done once.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
406
diff
changeset
|
1963 return databaseMinorVersion; |
332
e8962bdaa206
Moved utility methods and associated caches from DatabaseMetaData to Connection object.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
324
diff
changeset
|
1964 } |
e8962bdaa206
Moved utility methods and associated caches from DatabaseMetaData to Connection object.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
324
diff
changeset
|
1965 |
736
f317b37bad30
In MonetCallableStatement constructor skip calling removeEscapes() when the connected server supports ODBC/JDBC escape sequence syntax.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
722
diff
changeset
|
1966 /** |
919
ce6bc9908735
Add utility method checkMinimumDBVersion(int major, int minor). Will be used in more classes.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
914
diff
changeset
|
1967 * Utility method to check if connected server matches or is higher than a requested version. |
ce6bc9908735
Add utility method checkMinimumDBVersion(int major, int minor). Will be used in more classes.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
914
diff
changeset
|
1968 * |
ce6bc9908735
Add utility method checkMinimumDBVersion(int major, int minor). Will be used in more classes.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
914
diff
changeset
|
1969 * @param major dbserver major version number. |
ce6bc9908735
Add utility method checkMinimumDBVersion(int major, int minor). Will be used in more classes.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
914
diff
changeset
|
1970 * @param minor dbserver minor version number. |
ce6bc9908735
Add utility method checkMinimumDBVersion(int major, int minor). Will be used in more classes.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
914
diff
changeset
|
1971 * @return true when the server version is higher or equal to the major.minor else false. |
ce6bc9908735
Add utility method checkMinimumDBVersion(int major, int minor). Will be used in more classes.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
914
diff
changeset
|
1972 */ |
ce6bc9908735
Add utility method checkMinimumDBVersion(int major, int minor). Will be used in more classes.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
914
diff
changeset
|
1973 boolean checkMinimumDBVersion(int major, int minor) { |
ce6bc9908735
Add utility method checkMinimumDBVersion(int major, int minor). Will be used in more classes.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
914
diff
changeset
|
1974 try { |
ce6bc9908735
Add utility method checkMinimumDBVersion(int major, int minor). Will be used in more classes.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
914
diff
changeset
|
1975 if ((getDatabaseMinorVersion() >= minor) && (getDatabaseMajorVersion() == major)) |
ce6bc9908735
Add utility method checkMinimumDBVersion(int major, int minor). Will be used in more classes.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
914
diff
changeset
|
1976 return true; |
ce6bc9908735
Add utility method checkMinimumDBVersion(int major, int minor). Will be used in more classes.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
914
diff
changeset
|
1977 } catch (SQLException e) { /* ignore */ } |
ce6bc9908735
Add utility method checkMinimumDBVersion(int major, int minor). Will be used in more classes.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
914
diff
changeset
|
1978 return false; |
ce6bc9908735
Add utility method checkMinimumDBVersion(int major, int minor). Will be used in more classes.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
914
diff
changeset
|
1979 } |
ce6bc9908735
Add utility method checkMinimumDBVersion(int major, int minor). Will be used in more classes.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
914
diff
changeset
|
1980 |
ce6bc9908735
Add utility method checkMinimumDBVersion(int major, int minor). Will be used in more classes.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
914
diff
changeset
|
1981 /** |
736
f317b37bad30
In MonetCallableStatement constructor skip calling removeEscapes() when the connected server supports ODBC/JDBC escape sequence syntax.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
722
diff
changeset
|
1982 * Get whether the MonetDB SQL parser supports ODBC/JDBC escape sequence syntax. |
f317b37bad30
In MonetCallableStatement constructor skip calling removeEscapes() when the connected server supports ODBC/JDBC escape sequence syntax.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
722
diff
changeset
|
1983 * See also: https://docs.oracle.com/javadb/10.6.2.1/ref/rrefjdbc1020262.html |
919
ce6bc9908735
Add utility method checkMinimumDBVersion(int major, int minor). Will be used in more classes.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
914
diff
changeset
|
1984 * It does when the server version is 11.47 (Jun2023) or higher. |
736
f317b37bad30
In MonetCallableStatement constructor skip calling removeEscapes() when the connected server supports ODBC/JDBC escape sequence syntax.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
722
diff
changeset
|
1985 * This method is called from: MonetDatabaseMetaData and MonetCallableStatement. |
f317b37bad30
In MonetCallableStatement constructor skip calling removeEscapes() when the connected server supports ODBC/JDBC escape sequence syntax.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
722
diff
changeset
|
1986 * |
f317b37bad30
In MonetCallableStatement constructor skip calling removeEscapes() when the connected server supports ODBC/JDBC escape sequence syntax.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
722
diff
changeset
|
1987 * @return true when the server supports ODBC/JDBC escape sequence syntax else false. |
f317b37bad30
In MonetCallableStatement constructor skip calling removeEscapes() when the connected server supports ODBC/JDBC escape sequence syntax.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
722
diff
changeset
|
1988 */ |
f317b37bad30
In MonetCallableStatement constructor skip calling removeEscapes() when the connected server supports ODBC/JDBC escape sequence syntax.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
722
diff
changeset
|
1989 boolean supportsEscapeSequenceSyntax() { |
919
ce6bc9908735
Add utility method checkMinimumDBVersion(int major, int minor). Will be used in more classes.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
914
diff
changeset
|
1990 return checkMinimumDBVersion(11, 47); |
736
f317b37bad30
In MonetCallableStatement constructor skip calling removeEscapes() when the connected server supports ODBC/JDBC escape sequence syntax.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
722
diff
changeset
|
1991 } |
f317b37bad30
In MonetCallableStatement constructor skip calling removeEscapes() when the connected server supports ODBC/JDBC escape sequence syntax.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
722
diff
changeset
|
1992 |
332
e8962bdaa206
Moved utility methods and associated caches from DatabaseMetaData to Connection object.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
324
diff
changeset
|
1993 |
e8962bdaa206
Moved utility methods and associated caches from DatabaseMetaData to Connection object.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
324
diff
changeset
|
1994 // Internal cache for determining if system table sys.privilege_codes (new as of Jul2017 release) exists on connected server |
e8962bdaa206
Moved utility methods and associated caches from DatabaseMetaData to Connection object.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
324
diff
changeset
|
1995 private boolean queriedPrivilege_codesTable = false; |
e8962bdaa206
Moved utility methods and associated caches from DatabaseMetaData to Connection object.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
324
diff
changeset
|
1996 private boolean hasPrivilege_codesTable = false; |
e8962bdaa206
Moved utility methods and associated caches from DatabaseMetaData to Connection object.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
324
diff
changeset
|
1997 /** |
e8962bdaa206
Moved utility methods and associated caches from DatabaseMetaData to Connection object.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
324
diff
changeset
|
1998 * Utility method to query the server to find out if it has |
e8962bdaa206
Moved utility methods and associated caches from DatabaseMetaData to Connection object.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
324
diff
changeset
|
1999 * the system table sys.privilege_codes (which is new as of Jul2017 release). |
e8962bdaa206
Moved utility methods and associated caches from DatabaseMetaData to Connection object.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
324
diff
changeset
|
2000 * The result is cached and reused, so that we only test the query once per connection. |
e8962bdaa206
Moved utility methods and associated caches from DatabaseMetaData to Connection object.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
324
diff
changeset
|
2001 * This method is used by methods from MonetDatabaseMetaData. |
709
bdeabbd46ec6
Resolve javac and javadoc warnings when compiled with JDK19.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
708
diff
changeset
|
2002 * |
bdeabbd46ec6
Resolve javac and javadoc warnings when compiled with JDK19.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
708
diff
changeset
|
2003 * @return whether the system table sys.privilege_codes exist in the connected server. |
332
e8962bdaa206
Moved utility methods and associated caches from DatabaseMetaData to Connection object.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
324
diff
changeset
|
2004 */ |
e8962bdaa206
Moved utility methods and associated caches from DatabaseMetaData to Connection object.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
324
diff
changeset
|
2005 boolean privilege_codesTableExists() { |
e8962bdaa206
Moved utility methods and associated caches from DatabaseMetaData to Connection object.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
324
diff
changeset
|
2006 if (!queriedPrivilege_codesTable) { |
685
35653312f9cb
Optimise check on existence of specific tables. Instead of doing a query per table name, combine them in one query.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
684
diff
changeset
|
2007 querySysTable(); |
332
e8962bdaa206
Moved utility methods and associated caches from DatabaseMetaData to Connection object.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
324
diff
changeset
|
2008 queriedPrivilege_codesTable = true; // set flag, so the querying is done only at first invocation. |
e8962bdaa206
Moved utility methods and associated caches from DatabaseMetaData to Connection object.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
324
diff
changeset
|
2009 } |
e8962bdaa206
Moved utility methods and associated caches from DatabaseMetaData to Connection object.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
324
diff
changeset
|
2010 return hasPrivilege_codesTable; |
e8962bdaa206
Moved utility methods and associated caches from DatabaseMetaData to Connection object.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
324
diff
changeset
|
2011 } |
e8962bdaa206
Moved utility methods and associated caches from DatabaseMetaData to Connection object.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
324
diff
changeset
|
2012 |
e8962bdaa206
Moved utility methods and associated caches from DatabaseMetaData to Connection object.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
324
diff
changeset
|
2013 // Internal cache for determining if system table sys.comments (new as of Mar2018 release) exists on connected server |
e8962bdaa206
Moved utility methods and associated caches from DatabaseMetaData to Connection object.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
324
diff
changeset
|
2014 private boolean queriedCommentsTable = false; |
e8962bdaa206
Moved utility methods and associated caches from DatabaseMetaData to Connection object.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
324
diff
changeset
|
2015 private boolean hasCommentsTable = false; |
e8962bdaa206
Moved utility methods and associated caches from DatabaseMetaData to Connection object.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
324
diff
changeset
|
2016 /** |
e8962bdaa206
Moved utility methods and associated caches from DatabaseMetaData to Connection object.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
324
diff
changeset
|
2017 * Utility method to query the server to find out if it has |
215
71b039bc2d99
Added support for querying the sys.comments table for some meta data methods
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
214
diff
changeset
|
2018 * the system table sys.comments (which is new as of Mar2018 release). |
71b039bc2d99
Added support for querying the sys.comments table for some meta data methods
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
214
diff
changeset
|
2019 * The result is cached and reused, so that we only test the query once per connection. |
71b039bc2d99
Added support for querying the sys.comments table for some meta data methods
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
214
diff
changeset
|
2020 * This method is used by methods from MonetDatabaseMetaData. |
709
bdeabbd46ec6
Resolve javac and javadoc warnings when compiled with JDK19.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
708
diff
changeset
|
2021 * |
bdeabbd46ec6
Resolve javac and javadoc warnings when compiled with JDK19.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
708
diff
changeset
|
2022 * @return whether the system table sys.comments exist in the connected server. |
215
71b039bc2d99
Added support for querying the sys.comments table for some meta data methods
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
214
diff
changeset
|
2023 */ |
71b039bc2d99
Added support for querying the sys.comments table for some meta data methods
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
214
diff
changeset
|
2024 boolean commentsTableExists() { |
219
4572f0694fde
Improved DatabaseMetaData methods getTablePrivileges() and getColumnPrivileges() by returning also
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
215
diff
changeset
|
2025 if (!queriedCommentsTable) { |
685
35653312f9cb
Optimise check on existence of specific tables. Instead of doing a query per table name, combine them in one query.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
684
diff
changeset
|
2026 querySysTable(); |
219
4572f0694fde
Improved DatabaseMetaData methods getTablePrivileges() and getColumnPrivileges() by returning also
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
215
diff
changeset
|
2027 queriedCommentsTable = true; // set flag, so the querying is done only at first invocation. |
4572f0694fde
Improved DatabaseMetaData methods getTablePrivileges() and getColumnPrivileges() by returning also
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
215
diff
changeset
|
2028 } |
4572f0694fde
Improved DatabaseMetaData methods getTablePrivileges() and getColumnPrivileges() by returning also
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
215
diff
changeset
|
2029 return hasCommentsTable; |
4572f0694fde
Improved DatabaseMetaData methods getTablePrivileges() and getColumnPrivileges() by returning also
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
215
diff
changeset
|
2030 } |
215
71b039bc2d99
Added support for querying the sys.comments table for some meta data methods
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
214
diff
changeset
|
2031 |
219
4572f0694fde
Improved DatabaseMetaData methods getTablePrivileges() and getColumnPrivileges() by returning also
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
215
diff
changeset
|
2032 |
4572f0694fde
Improved DatabaseMetaData methods getTablePrivileges() and getColumnPrivileges() by returning also
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
215
diff
changeset
|
2033 /** |
708
5022a57f9d97
Resolve javadoc errors.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
707
diff
changeset
|
2034 * Internal utility method to query the server to find out if it has a specific system tables. |
219
4572f0694fde
Improved DatabaseMetaData methods getTablePrivileges() and getColumnPrivileges() by returning also
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
215
diff
changeset
|
2035 */ |
685
35653312f9cb
Optimise check on existence of specific tables. Instead of doing a query per table name, combine them in one query.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
684
diff
changeset
|
2036 private void querySysTable() { |
215
71b039bc2d99
Added support for querying the sys.comments table for some meta data methods
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
214
diff
changeset
|
2037 Statement stmt = null; |
71b039bc2d99
Added support for querying the sys.comments table for some meta data methods
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
214
diff
changeset
|
2038 ResultSet rs = null; |
71b039bc2d99
Added support for querying the sys.comments table for some meta data methods
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
214
diff
changeset
|
2039 try { |
71b039bc2d99
Added support for querying the sys.comments table for some meta data methods
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
214
diff
changeset
|
2040 stmt = createStatement(); |
71b039bc2d99
Added support for querying the sys.comments table for some meta data methods
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
214
diff
changeset
|
2041 if (stmt != null) { |
685
35653312f9cb
Optimise check on existence of specific tables. Instead of doing a query per table name, combine them in one query.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
684
diff
changeset
|
2042 rs = stmt.executeQuery("SELECT name FROM sys._tables WHERE name in ('privilege_codes', 'comments')" |
35653312f9cb
Optimise check on existence of specific tables. Instead of doing a query per table name, combine them in one query.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
684
diff
changeset
|
2043 + " AND schema_id IN (SELECT id FROM sys.schemas WHERE name = 'sys')"); |
215
71b039bc2d99
Added support for querying the sys.comments table for some meta data methods
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
214
diff
changeset
|
2044 if (rs != null) { |
685
35653312f9cb
Optimise check on existence of specific tables. Instead of doing a query per table name, combine them in one query.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
684
diff
changeset
|
2045 while (rs.next()) { |
35653312f9cb
Optimise check on existence of specific tables. Instead of doing a query per table name, combine them in one query.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
684
diff
changeset
|
2046 String name = rs.getString(1); |
35653312f9cb
Optimise check on existence of specific tables. Instead of doing a query per table name, combine them in one query.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
684
diff
changeset
|
2047 // for debug: System.out.println("querySysTable() retrieved name: " + name); |
35653312f9cb
Optimise check on existence of specific tables. Instead of doing a query per table name, combine them in one query.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
684
diff
changeset
|
2048 if ("comments".equals(name)) { |
35653312f9cb
Optimise check on existence of specific tables. Instead of doing a query per table name, combine them in one query.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
684
diff
changeset
|
2049 hasCommentsTable = true; |
35653312f9cb
Optimise check on existence of specific tables. Instead of doing a query per table name, combine them in one query.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
684
diff
changeset
|
2050 queriedCommentsTable = true; |
35653312f9cb
Optimise check on existence of specific tables. Instead of doing a query per table name, combine them in one query.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
684
diff
changeset
|
2051 } else |
35653312f9cb
Optimise check on existence of specific tables. Instead of doing a query per table name, combine them in one query.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
684
diff
changeset
|
2052 if ("privilege_codes".equals(name)) { |
35653312f9cb
Optimise check on existence of specific tables. Instead of doing a query per table name, combine them in one query.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
684
diff
changeset
|
2053 hasPrivilege_codesTable = true; |
35653312f9cb
Optimise check on existence of specific tables. Instead of doing a query per table name, combine them in one query.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
684
diff
changeset
|
2054 queriedPrivilege_codesTable = true; |
35653312f9cb
Optimise check on existence of specific tables. Instead of doing a query per table name, combine them in one query.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
684
diff
changeset
|
2055 } |
35653312f9cb
Optimise check on existence of specific tables. Instead of doing a query per table name, combine them in one query.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
684
diff
changeset
|
2056 } |
215
71b039bc2d99
Added support for querying the sys.comments table for some meta data methods
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
214
diff
changeset
|
2057 } |
71b039bc2d99
Added support for querying the sys.comments table for some meta data methods
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
214
diff
changeset
|
2058 } |
71b039bc2d99
Added support for querying the sys.comments table for some meta data methods
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
214
diff
changeset
|
2059 } catch (SQLException se) { |
71b039bc2d99
Added support for querying the sys.comments table for some meta data methods
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
214
diff
changeset
|
2060 /* ignore */ |
71b039bc2d99
Added support for querying the sys.comments table for some meta data methods
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
214
diff
changeset
|
2061 } finally { |
300
8cc3b51d1984
Add a utility method to close objects ignoring any possible SQLExceptions thrown.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
296
diff
changeset
|
2062 closeResultsetStatement(rs, stmt); |
215
71b039bc2d99
Added support for querying the sys.comments table for some meta data methods
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
214
diff
changeset
|
2063 } |
71b039bc2d99
Added support for querying the sys.comments table for some meta data methods
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
214
diff
changeset
|
2064 } |
71b039bc2d99
Added support for querying the sys.comments table for some meta data methods
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
214
diff
changeset
|
2065 |
71b039bc2d99
Added support for querying the sys.comments table for some meta data methods
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
214
diff
changeset
|
2066 /** |
300
8cc3b51d1984
Add a utility method to close objects ignoring any possible SQLExceptions thrown.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
296
diff
changeset
|
2067 * Closes a ResultSet and/or Statement object without throwing any SQLExceptions |
8cc3b51d1984
Add a utility method to close objects ignoring any possible SQLExceptions thrown.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
296
diff
changeset
|
2068 * It can be used in the finally clause after creating a Statement and |
8cc3b51d1984
Add a utility method to close objects ignoring any possible SQLExceptions thrown.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
296
diff
changeset
|
2069 * (optionally) executed a query which produced a ResultSet. |
8cc3b51d1984
Add a utility method to close objects ignoring any possible SQLExceptions thrown.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
296
diff
changeset
|
2070 * |
8cc3b51d1984
Add a utility method to close objects ignoring any possible SQLExceptions thrown.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
296
diff
changeset
|
2071 * @param rs ResultSet object to be closed. It may be null |
8cc3b51d1984
Add a utility method to close objects ignoring any possible SQLExceptions thrown.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
296
diff
changeset
|
2072 * @param st Statement object to be closed. It may be null |
8cc3b51d1984
Add a utility method to close objects ignoring any possible SQLExceptions thrown.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
296
diff
changeset
|
2073 */ |
8cc3b51d1984
Add a utility method to close objects ignoring any possible SQLExceptions thrown.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
296
diff
changeset
|
2074 static final void closeResultsetStatement(final ResultSet rs, final Statement st) { |
8cc3b51d1984
Add a utility method to close objects ignoring any possible SQLExceptions thrown.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
296
diff
changeset
|
2075 if (rs != null) { |
8cc3b51d1984
Add a utility method to close objects ignoring any possible SQLExceptions thrown.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
296
diff
changeset
|
2076 try { |
8cc3b51d1984
Add a utility method to close objects ignoring any possible SQLExceptions thrown.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
296
diff
changeset
|
2077 rs.close(); |
8cc3b51d1984
Add a utility method to close objects ignoring any possible SQLExceptions thrown.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
296
diff
changeset
|
2078 } catch (SQLException e) { /* ignore */ } |
8cc3b51d1984
Add a utility method to close objects ignoring any possible SQLExceptions thrown.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
296
diff
changeset
|
2079 } |
8cc3b51d1984
Add a utility method to close objects ignoring any possible SQLExceptions thrown.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
296
diff
changeset
|
2080 if (st != null) { |
8cc3b51d1984
Add a utility method to close objects ignoring any possible SQLExceptions thrown.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
296
diff
changeset
|
2081 try { |
8cc3b51d1984
Add a utility method to close objects ignoring any possible SQLExceptions thrown.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
296
diff
changeset
|
2082 st.close(); |
8cc3b51d1984
Add a utility method to close objects ignoring any possible SQLExceptions thrown.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
296
diff
changeset
|
2083 } catch (SQLException e) { /* ignore */ } |
8cc3b51d1984
Add a utility method to close objects ignoring any possible SQLExceptions thrown.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
296
diff
changeset
|
2084 } |
8cc3b51d1984
Add a utility method to close objects ignoring any possible SQLExceptions thrown.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
296
diff
changeset
|
2085 } |
8cc3b51d1984
Add a utility method to close objects ignoring any possible SQLExceptions thrown.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
296
diff
changeset
|
2086 |
8cc3b51d1984
Add a utility method to close objects ignoring any possible SQLExceptions thrown.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
296
diff
changeset
|
2087 /** |
77
83aee4f60649
Added private method sendTransactionCommand(String); to reduce duplicate code in 6 methods.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
47
diff
changeset
|
2088 * Sends the given string to MonetDB as special transaction command. |
83aee4f60649
Added private method sendTransactionCommand(String); to reduce duplicate code in 6 methods.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
47
diff
changeset
|
2089 * All possible returned information is discarded. |
83aee4f60649
Added private method sendTransactionCommand(String); to reduce duplicate code in 6 methods.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
47
diff
changeset
|
2090 * Encountered errors are reported. |
83aee4f60649
Added private method sendTransactionCommand(String); to reduce duplicate code in 6 methods.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
47
diff
changeset
|
2091 * |
83aee4f60649
Added private method sendTransactionCommand(String); to reduce duplicate code in 6 methods.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
47
diff
changeset
|
2092 * @param command the exact string to send to MonetDB |
83aee4f60649
Added private method sendTransactionCommand(String); to reduce duplicate code in 6 methods.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
47
diff
changeset
|
2093 * @throws SQLException if an IO exception or a database error occurs |
83aee4f60649
Added private method sendTransactionCommand(String); to reduce duplicate code in 6 methods.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
47
diff
changeset
|
2094 */ |
295
003ae6d881db
Add "final" keyword to method arguments and local variables where possible.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
292
diff
changeset
|
2095 private void sendTransactionCommand(final String command) throws SQLException { |
77
83aee4f60649
Added private method sendTransactionCommand(String); to reduce duplicate code in 6 methods.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
47
diff
changeset
|
2096 // create a container for the result |
295
003ae6d881db
Add "final" keyword to method arguments and local variables where possible.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
292
diff
changeset
|
2097 final ResponseList l = new ResponseList(0, 0, ResultSet.FETCH_FORWARD, ResultSet.CONCUR_READ_ONLY); |
77
83aee4f60649
Added private method sendTransactionCommand(String); to reduce duplicate code in 6 methods.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
47
diff
changeset
|
2098 // send the appropriate query string to the database |
83aee4f60649
Added private method sendTransactionCommand(String); to reduce duplicate code in 6 methods.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
47
diff
changeset
|
2099 try { |
83aee4f60649
Added private method sendTransactionCommand(String); to reduce duplicate code in 6 methods.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
47
diff
changeset
|
2100 l.processQuery(command); |
83aee4f60649
Added private method sendTransactionCommand(String); to reduce duplicate code in 6 methods.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
47
diff
changeset
|
2101 } finally { |
83aee4f60649
Added private method sendTransactionCommand(String); to reduce duplicate code in 6 methods.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
47
diff
changeset
|
2102 l.close(); |
83aee4f60649
Added private method sendTransactionCommand(String); to reduce duplicate code in 6 methods.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
47
diff
changeset
|
2103 } |
83aee4f60649
Added private method sendTransactionCommand(String); to reduce duplicate code in 6 methods.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
47
diff
changeset
|
2104 } |
83aee4f60649
Added private method sendTransactionCommand(String); to reduce duplicate code in 6 methods.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
47
diff
changeset
|
2105 |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2106 /** |
278
1d6062d94377
Reduce duplicate code.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
271
diff
changeset
|
2107 * Sends the given string to MonetDB as regular SQL statement/query using queryTempl |
1d6062d94377
Reduce duplicate code.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
271
diff
changeset
|
2108 * Making sure there is a prompt after the command is sent. All possible |
1d6062d94377
Reduce duplicate code.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
271
diff
changeset
|
2109 * returned information is discarded. Encountered errors are reported. |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2110 * |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2111 * @param command the exact string to send to MonetDB |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2112 * @throws SQLException if an IO exception or a database error occurs |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2113 */ |
278
1d6062d94377
Reduce duplicate code.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
271
diff
changeset
|
2114 private void sendIndependentCommand(String command) throws SQLException { |
1d6062d94377
Reduce duplicate code.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
271
diff
changeset
|
2115 sendCommand(command, true); |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2116 } |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2117 |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2118 /** |
278
1d6062d94377
Reduce duplicate code.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
271
diff
changeset
|
2119 * Sends the given string to MonetDB as control statement using commandTempl |
1d6062d94377
Reduce duplicate code.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
271
diff
changeset
|
2120 * Making sure there is a prompt after the command is sent. All possible |
1d6062d94377
Reduce duplicate code.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
271
diff
changeset
|
2121 * returned information is discarded. Encountered errors are reported. |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2122 * |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2123 * @param command the exact string to send to MonetDB |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2124 * @throws SQLException if an IO exception or a database error occurs |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2125 */ |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2126 void sendControlCommand(String command) throws SQLException { |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2127 // send X command |
278
1d6062d94377
Reduce duplicate code.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
271
diff
changeset
|
2128 sendCommand(command, false); |
1d6062d94377
Reduce duplicate code.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
271
diff
changeset
|
2129 } |
1d6062d94377
Reduce duplicate code.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
271
diff
changeset
|
2130 |
1d6062d94377
Reduce duplicate code.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
271
diff
changeset
|
2131 /** |
1d6062d94377
Reduce duplicate code.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
271
diff
changeset
|
2132 * Sends the given string to MonetDB as command/query using commandTempl or queryTempl |
1d6062d94377
Reduce duplicate code.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
271
diff
changeset
|
2133 * Making sure there is a prompt after the command is sent. All possible |
332
e8962bdaa206
Moved utility methods and associated caches from DatabaseMetaData to Connection object.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
324
diff
changeset
|
2134 * returned information is discarded. Encountered errors are reported. |
278
1d6062d94377
Reduce duplicate code.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
271
diff
changeset
|
2135 * |
1d6062d94377
Reduce duplicate code.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
271
diff
changeset
|
2136 * @param command the exact string to send to MonetDB |
332
e8962bdaa206
Moved utility methods and associated caches from DatabaseMetaData to Connection object.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
324
diff
changeset
|
2137 * @param usequeryTempl send the command using queryTempl or else using commandTempl |
278
1d6062d94377
Reduce duplicate code.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
271
diff
changeset
|
2138 * @throws SQLException if an IO exception or a database error occurs |
1d6062d94377
Reduce duplicate code.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
271
diff
changeset
|
2139 */ |
295
003ae6d881db
Add "final" keyword to method arguments and local variables where possible.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
292
diff
changeset
|
2140 private void sendCommand(final String command, final boolean usequeryTempl) throws SQLException { |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2141 synchronized (server) { |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2142 try { |
480
849af4b76b28
Optimise code by reducing local variables which are used only once, replacing complex string concatenation by using StringBuilder, replacing some ternairy operators.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
474
diff
changeset
|
2143 if (usequeryTempl) |
849af4b76b28
Optimise code by reducing local variables which are used only once, replacing complex string concatenation by using StringBuilder, replacing some ternairy operators.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
474
diff
changeset
|
2144 out.writeLine(queryTempl[0] + command + queryTempl[1]); |
849af4b76b28
Optimise code by reducing local variables which are used only once, replacing complex string concatenation by using StringBuilder, replacing some ternairy operators.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
474
diff
changeset
|
2145 else |
849af4b76b28
Optimise code by reducing local variables which are used only once, replacing complex string concatenation by using StringBuilder, replacing some ternairy operators.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
474
diff
changeset
|
2146 out.writeLine(commandTempl[0] + command + commandTempl[1]); |
700
940e266eeccd
Refactor BufferedMCLReader
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
697
diff
changeset
|
2147 final String error = in.discardRemainder(); |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2148 if (error != null) |
144
d6abd1ffffbb
Use SQLNonTransientConnectionException instead of SQLException where applicable (SQLState starts with 08)
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
136
diff
changeset
|
2149 throw new SQLException(error.substring(6), error.substring(0, 5)); |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2150 } catch (SocketTimeoutException e) { |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2151 close(); // JDBC 4.1 semantics, abort() |
144
d6abd1ffffbb
Use SQLNonTransientConnectionException instead of SQLException where applicable (SQLState starts with 08)
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
136
diff
changeset
|
2152 throw new SQLNonTransientConnectionException("connection timed out", "08M33"); |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2153 } catch (IOException e) { |
144
d6abd1ffffbb
Use SQLNonTransientConnectionException instead of SQLException where applicable (SQLState starts with 08)
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
136
diff
changeset
|
2154 throw new SQLNonTransientConnectionException(e.getMessage(), "08000"); |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2155 } |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2156 } |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2157 } |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2158 |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2159 /** |
709
bdeabbd46ec6
Resolve javac and javadoc warnings when compiled with JDK19.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
708
diff
changeset
|
2160 * Adds a warning to the pile of warnings this Connection object has. |
bdeabbd46ec6
Resolve javac and javadoc warnings when compiled with JDK19.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
708
diff
changeset
|
2161 * If there were no warnings (or clearWarnings was called) this |
bdeabbd46ec6
Resolve javac and javadoc warnings when compiled with JDK19.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
708
diff
changeset
|
2162 * warning will be the first, otherwise this warning will get |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2163 * appended to the current warning. |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2164 * |
905
a52bc2dcdb8c
Implement ClientInfo API
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
903
diff
changeset
|
2165 * @param warning The warning to add |
a52bc2dcdb8c
Implement ClientInfo API
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
903
diff
changeset
|
2166 */ |
a52bc2dcdb8c
Implement ClientInfo API
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
903
diff
changeset
|
2167 private final void addWarning(SQLWarning warning) { |
a52bc2dcdb8c
Implement ClientInfo API
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
903
diff
changeset
|
2168 if (warnings == null) { |
a52bc2dcdb8c
Implement ClientInfo API
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
903
diff
changeset
|
2169 warnings = warning; |
a52bc2dcdb8c
Implement ClientInfo API
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
903
diff
changeset
|
2170 } else { |
a52bc2dcdb8c
Implement ClientInfo API
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
903
diff
changeset
|
2171 warnings.setNextWarning(warning); |
a52bc2dcdb8c
Implement ClientInfo API
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
903
diff
changeset
|
2172 } |
a52bc2dcdb8c
Implement ClientInfo API
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
903
diff
changeset
|
2173 } |
a52bc2dcdb8c
Implement ClientInfo API
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
903
diff
changeset
|
2174 |
a52bc2dcdb8c
Implement ClientInfo API
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
903
diff
changeset
|
2175 /** |
a52bc2dcdb8c
Implement ClientInfo API
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
903
diff
changeset
|
2176 * Adds a warning to the pile of warnings this Connection object has. |
a52bc2dcdb8c
Implement ClientInfo API
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
903
diff
changeset
|
2177 * If there were no warnings (or clearWarnings was called) this |
a52bc2dcdb8c
Implement ClientInfo API
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
903
diff
changeset
|
2178 * warning will be the first, otherwise this warning will get |
a52bc2dcdb8c
Implement ClientInfo API
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
903
diff
changeset
|
2179 * appended to the current warning. |
a52bc2dcdb8c
Implement ClientInfo API
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
903
diff
changeset
|
2180 * |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2181 * @param reason the warning message |
709
bdeabbd46ec6
Resolve javac and javadoc warnings when compiled with JDK19.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
708
diff
changeset
|
2182 * @param sqlstate the SQLState code (5 characters) |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2183 */ |
295
003ae6d881db
Add "final" keyword to method arguments and local variables where possible.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
292
diff
changeset
|
2184 private final void addWarning(final String reason, final String sqlstate) { |
905
a52bc2dcdb8c
Implement ClientInfo API
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
903
diff
changeset
|
2185 final SQLWarning warning = new SQLWarning(reason, sqlstate); |
a52bc2dcdb8c
Implement ClientInfo API
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
903
diff
changeset
|
2186 addWarning(warning); |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2187 } |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2188 |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2189 /** the default number of rows that are (attempted to) read at once */ |
186
4767b005a531
Making variables private where possible.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
184
diff
changeset
|
2190 private static final int DEF_FETCHSIZE = 250; |
423
de2ef68b672f
Allow to set fetchsize from the connection url
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
422
diff
changeset
|
2191 |
de2ef68b672f
Allow to set fetchsize from the connection url
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
422
diff
changeset
|
2192 /** the default number of rows to read at once from this connection */ |
de2ef68b672f
Allow to set fetchsize from the connection url
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
422
diff
changeset
|
2193 private int defaultFetchSize = DEF_FETCHSIZE; |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2194 /** The sequence counter */ |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2195 private static int seqCounter = 0; |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2196 |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2197 /** |
696
07d60185eeb9
Eliminate hardcoded value 250 in the constructor of MonetPreparedStatement. For this an internal package method MonetConnection.getDefaultFetchSize() is added.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
692
diff
changeset
|
2198 * returns default fetchSize as set at connection moment |
07d60185eeb9
Eliminate hardcoded value 250 in the constructor of MonetPreparedStatement. For this an internal package method MonetConnection.getDefaultFetchSize() is added.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
692
diff
changeset
|
2199 * |
07d60185eeb9
Eliminate hardcoded value 250 in the constructor of MonetPreparedStatement. For this an internal package method MonetConnection.getDefaultFetchSize() is added.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
692
diff
changeset
|
2200 * @return defaultFetchSize |
07d60185eeb9
Eliminate hardcoded value 250 in the constructor of MonetPreparedStatement. For this an internal package method MonetConnection.getDefaultFetchSize() is added.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
692
diff
changeset
|
2201 */ |
07d60185eeb9
Eliminate hardcoded value 250 in the constructor of MonetPreparedStatement. For this an internal package method MonetConnection.getDefaultFetchSize() is added.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
692
diff
changeset
|
2202 protected int getDefaultFetchSize() { |
07d60185eeb9
Eliminate hardcoded value 250 in the constructor of MonetPreparedStatement. For this an internal package method MonetConnection.getDefaultFetchSize() is added.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
692
diff
changeset
|
2203 return defaultFetchSize; |
07d60185eeb9
Eliminate hardcoded value 250 in the constructor of MonetPreparedStatement. For this an internal package method MonetConnection.getDefaultFetchSize() is added.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
692
diff
changeset
|
2204 } |
07d60185eeb9
Eliminate hardcoded value 250 in the constructor of MonetPreparedStatement. For this an internal package method MonetConnection.getDefaultFetchSize() is added.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
692
diff
changeset
|
2205 |
07d60185eeb9
Eliminate hardcoded value 250 in the constructor of MonetPreparedStatement. For this an internal package method MonetConnection.getDefaultFetchSize() is added.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
692
diff
changeset
|
2206 /** |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2207 * A Response is a message sent by the server to indicate some |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2208 * action has taken place, and possible results of that action. |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2209 */ |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2210 // {{{ interface Response |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2211 interface Response { |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2212 /** |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2213 * Adds a line to the underlying Response implementation. |
45
c2bf983dc79b
Implemented Connection methods: getClientInfo(name) and getClientInfo().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
25
diff
changeset
|
2214 * |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2215 * @param line the header line as String |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2216 * @param linetype the line type according to the MAPI protocol |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2217 * @return a non-null String if the line is invalid, |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2218 * or additional lines are not allowed. |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2219 */ |
556
87feb93330a6
Misc. changes suggested by analysis tool
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
554
diff
changeset
|
2220 String addLine(String line, LineType linetype); |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2221 |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2222 /** |
288
f412032e3b43
Correcting typo
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
286
diff
changeset
|
2223 * Returns whether this Response expects more lines to be added |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2224 * to it. |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2225 * |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2226 * @return true if a next line should be added, false otherwise |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2227 */ |
556
87feb93330a6
Misc. changes suggested by analysis tool
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
554
diff
changeset
|
2228 boolean wantsMore(); |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2229 |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2230 /** |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2231 * Indicates that no more header lines will be added to this |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2232 * Response implementation. |
45
c2bf983dc79b
Implemented Connection methods: getClientInfo(name) and getClientInfo().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
25
diff
changeset
|
2233 * |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2234 * @throws SQLException if the contents of the Response is not |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2235 * consistent or sufficient. |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2236 */ |
324
0b01771d5f8a
Method Response.complete() is never used or needed. Disabled the code from the interface and its implementations.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
300
diff
changeset
|
2237 /* MvD: disabled not used/needed code |
562
c640075da7c9
only comment improvements
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
559
diff
changeset
|
2238 void complete() throws SQLException; |
324
0b01771d5f8a
Method Response.complete() is never used or needed. Disabled the code from the interface and its implementations.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
300
diff
changeset
|
2239 */ |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2240 |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2241 /** |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2242 * Instructs the Response implementation to close and do the |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2243 * necessary clean up procedures. |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2244 */ |
556
87feb93330a6
Misc. changes suggested by analysis tool
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
554
diff
changeset
|
2245 void close(); |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2246 } |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2247 // }}} |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2248 |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2249 /** |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2250 * The ResultSetResponse represents a tabular result sent by the |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2251 * server. This is typically an SQL table. The MAPI headers of the |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2252 * Response look like: |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2253 * <pre> |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2254 * &1 1 28 2 10 |
665
8f7d51c478df
Improved implementation of methods ResultSetMetaData.getPrecision() and ResultSetMetaData.getScale().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
660
diff
changeset
|
2255 * % sys.props, sys.props # table_name |
8f7d51c478df
Improved implementation of methods ResultSetMetaData.getPrecision() and ResultSetMetaData.getScale().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
660
diff
changeset
|
2256 * % name, value # name |
8f7d51c478df
Improved implementation of methods ResultSetMetaData.getPrecision() and ResultSetMetaData.getScale().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
660
diff
changeset
|
2257 * % varchar, int # type |
8f7d51c478df
Improved implementation of methods ResultSetMetaData.getPrecision() and ResultSetMetaData.getScale().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
660
diff
changeset
|
2258 * % 15, 3 # length |
8f7d51c478df
Improved implementation of methods ResultSetMetaData.getPrecision() and ResultSetMetaData.getScale().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
660
diff
changeset
|
2259 * % 60 0, 32 0 # typesizes |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2260 * </pre> |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2261 * there the first line consists out of<br /> |
708
5022a57f9d97
Resolve javadoc errors.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
707
diff
changeset
|
2262 * <samp>&"qt" "id" "tc" "cc" "rc"</samp>. |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2263 */ |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2264 // {{{ ResultSetResponse class implementation |
296
c5efd6e661e5
Add "final" keyword to classes, method arguments and local variables where possible.`
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
295
diff
changeset
|
2265 final class ResultSetResponse implements Response { |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2266 /** The number of columns in this result */ |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2267 public final int columncount; |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2268 /** The total number of rows this result set has */ |
377
8a813f5cef1b
Extend StartOfHeaderParser with method getNextAsLong() and change type of tuplecount to long.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
376
diff
changeset
|
2269 public final long tuplecount; |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2270 /** The numbers of rows to retrieve per DataBlockResponse */ |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2271 private int cacheSize; |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2272 /** The table ID of this result */ |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2273 public final int id; |
665
8f7d51c478df
Improved implementation of methods ResultSetMetaData.getPrecision() and ResultSetMetaData.getScale().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
660
diff
changeset
|
2274 |
8f7d51c478df
Improved implementation of methods ResultSetMetaData.getPrecision() and ResultSetMetaData.getScale().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
660
diff
changeset
|
2275 /** arrays for the resultset columns metadata */ |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2276 /** The names of the columns in this result */ |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2277 private String[] name; |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2278 /** The types of the columns in this result */ |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2279 private String[] type; |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2280 /** The max string length for each column in this result */ |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2281 private int[] columnLengths; |
665
8f7d51c478df
Improved implementation of methods ResultSetMetaData.getPrecision() and ResultSetMetaData.getScale().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
660
diff
changeset
|
2282 /** The precision for each column in this result */ |
8f7d51c478df
Improved implementation of methods ResultSetMetaData.getPrecision() and ResultSetMetaData.getScale().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
660
diff
changeset
|
2283 private int[] colPrecisions; |
8f7d51c478df
Improved implementation of methods ResultSetMetaData.getPrecision() and ResultSetMetaData.getScale().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
660
diff
changeset
|
2284 /** The scale for each column in this result */ |
8f7d51c478df
Improved implementation of methods ResultSetMetaData.getPrecision() and ResultSetMetaData.getScale().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
660
diff
changeset
|
2285 private int[] colScales; |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2286 /** The table for each column in this result */ |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2287 private String[] tableNames; |
416
b3c876a0d61f
Improved performance of ResultSetMetaData methods getSchemaName(), getTableName(), getPrecision(), getScale(), isNullable() and isAutoIncrement().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
414
diff
changeset
|
2288 /** The schema for each column in this result */ |
b3c876a0d61f
Improved performance of ResultSetMetaData methods getSchemaName(), getTableName(), getPrecision(), getScale(), isNullable() and isAutoIncrement().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
414
diff
changeset
|
2289 private String[] schemaNames; |
665
8f7d51c478df
Improved implementation of methods ResultSetMetaData.getPrecision() and ResultSetMetaData.getScale().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
660
diff
changeset
|
2290 |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2291 /** The query sequence number */ |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2292 private final int seqnr; |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2293 /** A List of result blocks (chunks of size fetchSize/cacheSize) */ |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2294 private DataBlockResponse[] resultBlocks; |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2295 |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2296 /** Whether this Response is closed */ |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2297 private boolean closed; |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2298 |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2299 /** The Connection that we should use when requesting a new block */ |
286
d430f8adbf1b
Add keyword "final" to those variables which do not change after first assigment.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
285
diff
changeset
|
2300 private final MonetConnection.ResponseList parent; |
943 | 2301 /** Whether the fetchSize was explicitly set by the user */ |
295
003ae6d881db
Add "final" keyword to method arguments and local variables where possible.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
292
diff
changeset
|
2302 private final boolean cacheSizeSetExplicitly; |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2303 /** Whether we should send an Xclose command to the server |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2304 * if we close this Response */ |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2305 private boolean destroyOnClose; |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2306 /** the offset to be used on Xexport queries */ |
408
5540793628d6
Improve code when setting query timeout. It used to call the sys.settimeout(bigint) which is deprecated as of release Jun2020 (11.37.7) and replaced by new sys.setquerytimeout(int).
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
407
diff
changeset
|
2307 private int blockOffset; |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2308 |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2309 /** A parser for header lines */ |
295
003ae6d881db
Add "final" keyword to method arguments and local variables where possible.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
292
diff
changeset
|
2310 private final HeaderLineParser hlp; |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2311 |
286
d430f8adbf1b
Add keyword "final" to those variables which do not change after first assigment.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
285
diff
changeset
|
2312 /** A boolean array telling whether the headers are set or not */ |
d430f8adbf1b
Add keyword "final" to those variables which do not change after first assigment.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
285
diff
changeset
|
2313 private final boolean[] isSet; |
408
5540793628d6
Improve code when setting query timeout. It used to call the sys.settimeout(bigint) which is deprecated as of release Jun2020 (11.37.7) and replaced by new sys.setquerytimeout(int).
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
407
diff
changeset
|
2314 private static final int NAMES = 0; |
5540793628d6
Improve code when setting query timeout. It used to call the sys.settimeout(bigint) which is deprecated as of release Jun2020 (11.37.7) and replaced by new sys.setquerytimeout(int).
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
407
diff
changeset
|
2315 private static final int TYPES = 1; |
5540793628d6
Improve code when setting query timeout. It used to call the sys.settimeout(bigint) which is deprecated as of release Jun2020 (11.37.7) and replaced by new sys.setquerytimeout(int).
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
407
diff
changeset
|
2316 private static final int TABLES = 2; |
5540793628d6
Improve code when setting query timeout. It used to call the sys.settimeout(bigint) which is deprecated as of release Jun2020 (11.37.7) and replaced by new sys.setquerytimeout(int).
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
407
diff
changeset
|
2317 private static final int LENS = 3; |
665
8f7d51c478df
Improved implementation of methods ResultSetMetaData.getPrecision() and ResultSetMetaData.getScale().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
660
diff
changeset
|
2318 private static final int TYPESIZES = 4; |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2319 |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2320 /** |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2321 * Sole constructor, which requires a MonetConnection parent to |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2322 * be given. |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2323 * |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2324 * @param id the ID of the result set |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2325 * @param tuplecount the total number of tuples in the result set |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2326 * @param columncount the number of columns in the result set |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2327 * @param rowcount the number of rows in the current block |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2328 * @param parent the parent that created this Response and will |
144
d6abd1ffffbb
Use SQLNonTransientConnectionException instead of SQLException where applicable (SQLState starts with 08)
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
136
diff
changeset
|
2329 * supply new result blocks when necessary |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2330 * @param seq the query sequence number |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2331 */ |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2332 ResultSetResponse( |
295
003ae6d881db
Add "final" keyword to method arguments and local variables where possible.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
292
diff
changeset
|
2333 final int id, |
377
8a813f5cef1b
Extend StartOfHeaderParser with method getNextAsLong() and change type of tuplecount to long.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
376
diff
changeset
|
2334 final long tuplecount, |
295
003ae6d881db
Add "final" keyword to method arguments and local variables where possible.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
292
diff
changeset
|
2335 final int columncount, |
003ae6d881db
Add "final" keyword to method arguments and local variables where possible.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
292
diff
changeset
|
2336 final int rowcount, |
003ae6d881db
Add "final" keyword to method arguments and local variables where possible.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
292
diff
changeset
|
2337 final MonetConnection.ResponseList parent, |
003ae6d881db
Add "final" keyword to method arguments and local variables where possible.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
292
diff
changeset
|
2338 final int seq) |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2339 { |
665
8f7d51c478df
Improved implementation of methods ResultSetMetaData.getPrecision() and ResultSetMetaData.getScale().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
660
diff
changeset
|
2340 isSet = new boolean[5]; |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2341 this.parent = parent; |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2342 if (parent.cachesize == 0) { |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2343 /* Below we have to calculate how many "chunks" we need |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2344 * to allocate to store the entire result. However, if |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2345 * the user didn't set a cache size, as in this case, we |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2346 * need to stick to our defaults. */ |
660
7ec8d469fd0b
Adapt the cacheSize to the actual fetch size instead of using the default fetch size.
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
658
diff
changeset
|
2347 cacheSize = defaultFetchSize; |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2348 cacheSizeSetExplicitly = false; |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2349 } else { |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2350 cacheSize = parent.cachesize; |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2351 cacheSizeSetExplicitly = true; |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2352 } |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2353 /* So far, so good. Now the problem with EXPLAIN, DOT, etc |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2354 * queries is, that they don't support any block fetching, |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2355 * so we need to always fetch everything at once. For that |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2356 * reason, the cache size is here set to the rowcount if |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2357 * it's larger, such that we do a full fetch at once. |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2358 * (Because we always set a reply_size, we can only get a |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2359 * larger rowcount from the server if it doesn't paginate, |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2360 * because it's a pseudo SQL result.) */ |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2361 if (rowcount > cacheSize) |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2362 cacheSize = rowcount; |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2363 seqnr = seq; |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2364 closed = false; |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2365 destroyOnClose = id > 0 && tuplecount > rowcount; |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2366 |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2367 this.id = id; |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2368 this.tuplecount = tuplecount; |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2369 this.columncount = columncount; |
377
8a813f5cef1b
Extend StartOfHeaderParser with method getNextAsLong() and change type of tuplecount to long.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
376
diff
changeset
|
2370 this.resultBlocks = new DataBlockResponse[(int)(tuplecount / cacheSize) + 1]; |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2371 |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2372 hlp = new HeaderLineParser(columncount); |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2373 |
286
d430f8adbf1b
Add keyword "final" to those variables which do not change after first assigment.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
285
diff
changeset
|
2374 resultBlocks[0] = new DataBlockResponse(rowcount, parent.rstype == ResultSet.TYPE_FORWARD_ONLY); |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2375 } |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2376 |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2377 /** |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2378 * Parses the given string and changes the value of the matching |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2379 * header appropriately, or passes it on to the underlying |
690
f7946d36d1dd
Extend error messages with the linetype to give more info.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
685
diff
changeset
|
2380 * DataBlockResponse. |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2381 * |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2382 * @param tmpLine the string that contains the header |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2383 * @return a non-null String if the header cannot be parsed or |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2384 * is unknown |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2385 */ |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2386 @Override |
497
aed7f32e029a
Refactor LineType to be an enum
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
496
diff
changeset
|
2387 public String addLine(final String tmpLine, final LineType linetype) { |
665
8f7d51c478df
Improved implementation of methods ResultSetMetaData.getPrecision() and ResultSetMetaData.getScale().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
660
diff
changeset
|
2388 // System.out.println("In ResultSetResponse.addLine(line, type: " + linetype + ") line: " + tmpLine); |
8f7d51c478df
Improved implementation of methods ResultSetMetaData.getPrecision() and ResultSetMetaData.getScale().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
660
diff
changeset
|
2389 if (linetype == LineType.RESULT || |
8f7d51c478df
Improved implementation of methods ResultSetMetaData.getPrecision() and ResultSetMetaData.getScale().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
660
diff
changeset
|
2390 (isSet[LENS] && isSet[TYPES] && isSet[TABLES] && isSet[NAMES] && isSet[TYPESIZES])) { |
8f7d51c478df
Improved implementation of methods ResultSetMetaData.getPrecision() and ResultSetMetaData.getScale().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
660
diff
changeset
|
2391 if (!isSet[TYPESIZES]) |
8f7d51c478df
Improved implementation of methods ResultSetMetaData.getPrecision() and ResultSetMetaData.getScale().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
660
diff
changeset
|
2392 // this is needed to get proper output when processing a: DEBUG SQL-statement |
8f7d51c478df
Improved implementation of methods ResultSetMetaData.getPrecision() and ResultSetMetaData.getScale().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
660
diff
changeset
|
2393 isSet[TYPESIZES] = true; |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2394 return resultBlocks[0].addLine(tmpLine, linetype); |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2395 } |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2396 |
665
8f7d51c478df
Improved implementation of methods ResultSetMetaData.getPrecision() and ResultSetMetaData.getScale().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
660
diff
changeset
|
2397 if (linetype != LineType.HEADER) { |
8f7d51c478df
Improved implementation of methods ResultSetMetaData.getPrecision() and ResultSetMetaData.getScale().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
660
diff
changeset
|
2398 if (!isSet[TYPESIZES]) |
8f7d51c478df
Improved implementation of methods ResultSetMetaData.getPrecision() and ResultSetMetaData.getScale().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
660
diff
changeset
|
2399 isSet[TYPESIZES] = true; |
690
f7946d36d1dd
Extend error messages with the linetype to give more info.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
685
diff
changeset
|
2400 return "Header expected, got " + linetype + " line: " + tmpLine; |
665
8f7d51c478df
Improved implementation of methods ResultSetMetaData.getPrecision() and ResultSetMetaData.getScale().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
660
diff
changeset
|
2401 } |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2402 |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2403 // depending on the name of the header, we continue |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2404 try { |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2405 switch (hlp.parse(tmpLine)) { |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2406 case HeaderLineParser.NAME: |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2407 name = hlp.values.clone(); |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2408 isSet[NAMES] = true; |
665
8f7d51c478df
Improved implementation of methods ResultSetMetaData.getPrecision() and ResultSetMetaData.getScale().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
660
diff
changeset
|
2409 break; |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2410 case HeaderLineParser.LENGTH: |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2411 columnLengths = hlp.intValues.clone(); |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2412 isSet[LENS] = true; |
665
8f7d51c478df
Improved implementation of methods ResultSetMetaData.getPrecision() and ResultSetMetaData.getScale().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
660
diff
changeset
|
2413 break; |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2414 case HeaderLineParser.TYPE: |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2415 type = hlp.values.clone(); |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2416 isSet[TYPES] = true; |
665
8f7d51c478df
Improved implementation of methods ResultSetMetaData.getPrecision() and ResultSetMetaData.getScale().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
660
diff
changeset
|
2417 break; |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2418 case HeaderLineParser.TABLE: |
416
b3c876a0d61f
Improved performance of ResultSetMetaData methods getSchemaName(), getTableName(), getPrecision(), getScale(), isNullable() and isAutoIncrement().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
414
diff
changeset
|
2419 { |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2420 tableNames = hlp.values.clone(); |
416
b3c876a0d61f
Improved performance of ResultSetMetaData methods getSchemaName(), getTableName(), getPrecision(), getScale(), isNullable() and isAutoIncrement().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
414
diff
changeset
|
2421 final int array_size = tableNames.length; |
b3c876a0d61f
Improved performance of ResultSetMetaData methods getSchemaName(), getTableName(), getPrecision(), getScale(), isNullable() and isAutoIncrement().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
414
diff
changeset
|
2422 schemaNames = new String[array_size]; |
b3c876a0d61f
Improved performance of ResultSetMetaData methods getSchemaName(), getTableName(), getPrecision(), getScale(), isNullable() and isAutoIncrement().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
414
diff
changeset
|
2423 // split the schema and table names from the cloned values array |
b3c876a0d61f
Improved performance of ResultSetMetaData methods getSchemaName(), getTableName(), getPrecision(), getScale(), isNullable() and isAutoIncrement().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
414
diff
changeset
|
2424 for (int i = 0; i < array_size; i++) { |
b3c876a0d61f
Improved performance of ResultSetMetaData methods getSchemaName(), getTableName(), getPrecision(), getScale(), isNullable() and isAutoIncrement().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
414
diff
changeset
|
2425 String qtable = tableNames[i]; |
b3c876a0d61f
Improved performance of ResultSetMetaData methods getSchemaName(), getTableName(), getPrecision(), getScale(), isNullable() and isAutoIncrement().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
414
diff
changeset
|
2426 if (qtable != null) { |
b3c876a0d61f
Improved performance of ResultSetMetaData methods getSchemaName(), getTableName(), getPrecision(), getScale(), isNullable() and isAutoIncrement().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
414
diff
changeset
|
2427 int dot = qtable.indexOf('.'); |
b3c876a0d61f
Improved performance of ResultSetMetaData methods getSchemaName(), getTableName(), getPrecision(), getScale(), isNullable() and isAutoIncrement().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
414
diff
changeset
|
2428 if (dot >= 0) { |
b3c876a0d61f
Improved performance of ResultSetMetaData methods getSchemaName(), getTableName(), getPrecision(), getScale(), isNullable() and isAutoIncrement().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
414
diff
changeset
|
2429 schemaNames[i] = qtable.substring(0, dot); |
b3c876a0d61f
Improved performance of ResultSetMetaData methods getSchemaName(), getTableName(), getPrecision(), getScale(), isNullable() and isAutoIncrement().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
414
diff
changeset
|
2430 tableNames[i] = qtable.substring(dot +1); |
b3c876a0d61f
Improved performance of ResultSetMetaData methods getSchemaName(), getTableName(), getPrecision(), getScale(), isNullable() and isAutoIncrement().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
414
diff
changeset
|
2431 } else { |
b3c876a0d61f
Improved performance of ResultSetMetaData methods getSchemaName(), getTableName(), getPrecision(), getScale(), isNullable() and isAutoIncrement().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
414
diff
changeset
|
2432 schemaNames[i] = ""; |
b3c876a0d61f
Improved performance of ResultSetMetaData methods getSchemaName(), getTableName(), getPrecision(), getScale(), isNullable() and isAutoIncrement().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
414
diff
changeset
|
2433 } |
b3c876a0d61f
Improved performance of ResultSetMetaData methods getSchemaName(), getTableName(), getPrecision(), getScale(), isNullable() and isAutoIncrement().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
414
diff
changeset
|
2434 } else { |
b3c876a0d61f
Improved performance of ResultSetMetaData methods getSchemaName(), getTableName(), getPrecision(), getScale(), isNullable() and isAutoIncrement().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
414
diff
changeset
|
2435 schemaNames[i] = ""; |
b3c876a0d61f
Improved performance of ResultSetMetaData methods getSchemaName(), getTableName(), getPrecision(), getScale(), isNullable() and isAutoIncrement().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
414
diff
changeset
|
2436 tableNames[i] = ""; |
b3c876a0d61f
Improved performance of ResultSetMetaData methods getSchemaName(), getTableName(), getPrecision(), getScale(), isNullable() and isAutoIncrement().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
414
diff
changeset
|
2437 } |
b3c876a0d61f
Improved performance of ResultSetMetaData methods getSchemaName(), getTableName(), getPrecision(), getScale(), isNullable() and isAutoIncrement().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
414
diff
changeset
|
2438 } |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2439 isSet[TABLES] = true; |
665
8f7d51c478df
Improved implementation of methods ResultSetMetaData.getPrecision() and ResultSetMetaData.getScale().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
660
diff
changeset
|
2440 break; |
416
b3c876a0d61f
Improved performance of ResultSetMetaData methods getSchemaName(), getTableName(), getPrecision(), getScale(), isNullable() and isAutoIncrement().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
414
diff
changeset
|
2441 } |
665
8f7d51c478df
Improved implementation of methods ResultSetMetaData.getPrecision() and ResultSetMetaData.getScale().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
660
diff
changeset
|
2442 case HeaderLineParser.TYPESIZES: |
8f7d51c478df
Improved implementation of methods ResultSetMetaData.getPrecision() and ResultSetMetaData.getScale().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
660
diff
changeset
|
2443 { |
8f7d51c478df
Improved implementation of methods ResultSetMetaData.getPrecision() and ResultSetMetaData.getScale().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
660
diff
changeset
|
2444 // System.out.println("In ResultSetResponse.addLine() case HeaderLineParser.TYPESIZES: values: " + hlp.values[0]); |
8f7d51c478df
Improved implementation of methods ResultSetMetaData.getPrecision() and ResultSetMetaData.getScale().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
660
diff
changeset
|
2445 final int array_size = hlp.values.length; |
8f7d51c478df
Improved implementation of methods ResultSetMetaData.getPrecision() and ResultSetMetaData.getScale().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
660
diff
changeset
|
2446 colPrecisions = new int[array_size]; |
8f7d51c478df
Improved implementation of methods ResultSetMetaData.getPrecision() and ResultSetMetaData.getScale().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
660
diff
changeset
|
2447 colScales = new int[array_size]; |
8f7d51c478df
Improved implementation of methods ResultSetMetaData.getPrecision() and ResultSetMetaData.getScale().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
660
diff
changeset
|
2448 // extract the precision and scale integer numbers from the string |
8f7d51c478df
Improved implementation of methods ResultSetMetaData.getPrecision() and ResultSetMetaData.getScale().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
660
diff
changeset
|
2449 for (int i = 0; i < array_size; i++) { |
8f7d51c478df
Improved implementation of methods ResultSetMetaData.getPrecision() and ResultSetMetaData.getScale().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
660
diff
changeset
|
2450 String ps = hlp.values[i]; |
8f7d51c478df
Improved implementation of methods ResultSetMetaData.getPrecision() and ResultSetMetaData.getScale().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
660
diff
changeset
|
2451 if (ps != null) { |
8f7d51c478df
Improved implementation of methods ResultSetMetaData.getPrecision() and ResultSetMetaData.getScale().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
660
diff
changeset
|
2452 try { |
8f7d51c478df
Improved implementation of methods ResultSetMetaData.getPrecision() and ResultSetMetaData.getScale().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
660
diff
changeset
|
2453 int separator = ps.indexOf(' '); |
8f7d51c478df
Improved implementation of methods ResultSetMetaData.getPrecision() and ResultSetMetaData.getScale().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
660
diff
changeset
|
2454 if (separator > 0) { |
8f7d51c478df
Improved implementation of methods ResultSetMetaData.getPrecision() and ResultSetMetaData.getScale().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
660
diff
changeset
|
2455 colPrecisions[i] = Integer.parseInt(ps.substring(0, separator)); |
8f7d51c478df
Improved implementation of methods ResultSetMetaData.getPrecision() and ResultSetMetaData.getScale().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
660
diff
changeset
|
2456 colScales[i] = Integer.parseInt(ps.substring(separator +1)); |
8f7d51c478df
Improved implementation of methods ResultSetMetaData.getPrecision() and ResultSetMetaData.getScale().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
660
diff
changeset
|
2457 } else { |
8f7d51c478df
Improved implementation of methods ResultSetMetaData.getPrecision() and ResultSetMetaData.getScale().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
660
diff
changeset
|
2458 colPrecisions[i] = Integer.parseInt(ps); |
8f7d51c478df
Improved implementation of methods ResultSetMetaData.getPrecision() and ResultSetMetaData.getScale().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
660
diff
changeset
|
2459 colScales[i] = 0; |
8f7d51c478df
Improved implementation of methods ResultSetMetaData.getPrecision() and ResultSetMetaData.getScale().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
660
diff
changeset
|
2460 } |
8f7d51c478df
Improved implementation of methods ResultSetMetaData.getPrecision() and ResultSetMetaData.getScale().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
660
diff
changeset
|
2461 } catch (NumberFormatException nfe) { |
8f7d51c478df
Improved implementation of methods ResultSetMetaData.getPrecision() and ResultSetMetaData.getScale().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
660
diff
changeset
|
2462 return nfe.getMessage(); |
8f7d51c478df
Improved implementation of methods ResultSetMetaData.getPrecision() and ResultSetMetaData.getScale().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
660
diff
changeset
|
2463 } |
8f7d51c478df
Improved implementation of methods ResultSetMetaData.getPrecision() and ResultSetMetaData.getScale().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
660
diff
changeset
|
2464 } else { |
8f7d51c478df
Improved implementation of methods ResultSetMetaData.getPrecision() and ResultSetMetaData.getScale().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
660
diff
changeset
|
2465 colPrecisions[i] = 1; |
8f7d51c478df
Improved implementation of methods ResultSetMetaData.getPrecision() and ResultSetMetaData.getScale().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
660
diff
changeset
|
2466 colScales[i] = 0; |
8f7d51c478df
Improved implementation of methods ResultSetMetaData.getPrecision() and ResultSetMetaData.getScale().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
660
diff
changeset
|
2467 } |
8f7d51c478df
Improved implementation of methods ResultSetMetaData.getPrecision() and ResultSetMetaData.getScale().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
660
diff
changeset
|
2468 } |
8f7d51c478df
Improved implementation of methods ResultSetMetaData.getPrecision() and ResultSetMetaData.getScale().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
660
diff
changeset
|
2469 isSet[TYPESIZES] = true; |
8f7d51c478df
Improved implementation of methods ResultSetMetaData.getPrecision() and ResultSetMetaData.getScale().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
660
diff
changeset
|
2470 break; |
8f7d51c478df
Improved implementation of methods ResultSetMetaData.getPrecision() and ResultSetMetaData.getScale().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
660
diff
changeset
|
2471 } |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2472 } |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2473 } catch (MCLParseException e) { |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2474 return e.getMessage(); |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2475 } |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2476 |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2477 // all is well |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2478 return null; |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2479 } |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2480 |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2481 /** |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2482 * Returns whether this ResultSetResponse needs more lines. |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2483 * This method returns true if not all headers are set, or the |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2484 * first DataBlockResponse reports to want more. |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2485 */ |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2486 @Override |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2487 public boolean wantsMore() { |
701
f89882b07614
Fix a problem with PREPARE INSERT
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
700
diff
changeset
|
2488 return resultBlocks[0].wantsMore(); |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2489 } |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2490 |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2491 /** |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2492 * Returns an array of Strings containing the values between |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2493 * ',\t' separators. |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2494 * |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2495 * @param chrLine a character array holding the input data |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2496 * @param start where the relevant data starts |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2497 * @param stop where the relevant data stops |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2498 * @return an array of Strings |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2499 */ |
295
003ae6d881db
Add "final" keyword to method arguments and local variables where possible.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
292
diff
changeset
|
2500 private final String[] getValues(final char[] chrLine, int start, final int stop) { |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2501 int elem = 0; |
295
003ae6d881db
Add "final" keyword to method arguments and local variables where possible.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
292
diff
changeset
|
2502 final String[] values = new String[columncount]; |
77
83aee4f60649
Added private method sendTransactionCommand(String); to reduce duplicate code in 6 methods.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
47
diff
changeset
|
2503 |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2504 for (int i = start; i < stop; i++) { |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2505 if (chrLine[i] == '\t' && chrLine[i - 1] == ',') { |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2506 values[elem++] = |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2507 new String(chrLine, start, i - 1 - start); |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2508 start = i + 1; |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2509 } |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2510 } |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2511 // at the left over part |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2512 values[elem++] = new String(chrLine, start, stop - start); |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2513 |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2514 return values; |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2515 } |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2516 |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2517 /** |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2518 * Adds the given DataBlockResponse to this ResultSetResponse at |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2519 * the given block position. |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2520 * |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2521 * @param offset the offset number of rows for this block |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2522 * @param rr the DataBlockResponse to add |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2523 */ |
295
003ae6d881db
Add "final" keyword to method arguments and local variables where possible.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
292
diff
changeset
|
2524 void addDataBlockResponse(final int offset, final DataBlockResponse rr) { |
003ae6d881db
Add "final" keyword to method arguments and local variables where possible.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
292
diff
changeset
|
2525 final int block = (offset - blockOffset) / cacheSize; |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2526 resultBlocks[block] = rr; |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2527 } |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2528 |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2529 /** |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2530 * Marks this Response as being completed. A complete Response |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2531 * needs to be consistent with regard to its internal data. |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2532 * |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2533 * @throws SQLException if the data currently in this Response is not |
943 | 2534 * sufficient to be consistent |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2535 */ |
324
0b01771d5f8a
Method Response.complete() is never used or needed. Disabled the code from the interface and its implementations.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
300
diff
changeset
|
2536 /* MvD: disabled not used/needed code |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2537 @Override |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2538 public void complete() throws SQLException { |
295
003ae6d881db
Add "final" keyword to method arguments and local variables where possible.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
292
diff
changeset
|
2539 final StringBuilder err = new StringBuilder(99); |
003ae6d881db
Add "final" keyword to method arguments and local variables where possible.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
292
diff
changeset
|
2540 if (!isSet[NAMES]) err.append("name header missing\n"); |
003ae6d881db
Add "final" keyword to method arguments and local variables where possible.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
292
diff
changeset
|
2541 if (!isSet[TYPES]) err.append("type header missing\n"); |
003ae6d881db
Add "final" keyword to method arguments and local variables where possible.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
292
diff
changeset
|
2542 if (!isSet[TABLES]) err.append("table name header missing\n"); |
003ae6d881db
Add "final" keyword to method arguments and local variables where possible.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
292
diff
changeset
|
2543 if (!isSet[LENS]) err.append("column width header missing\n"); |
665
8f7d51c478df
Improved implementation of methods ResultSetMetaData.getPrecision() and ResultSetMetaData.getScale().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
660
diff
changeset
|
2544 if (!isSet[TYPESIZES]) err.append("column precision and scale header missing\n"); |
295
003ae6d881db
Add "final" keyword to method arguments and local variables where possible.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
292
diff
changeset
|
2545 if (err.length() > 0) |
003ae6d881db
Add "final" keyword to method arguments and local variables where possible.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
292
diff
changeset
|
2546 throw new SQLException(err.toString(), "M0M10"); |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2547 } |
324
0b01771d5f8a
Method Response.complete() is never used or needed. Disabled the code from the interface and its implementations.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
300
diff
changeset
|
2548 */ |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2549 |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2550 /** |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2551 * Returns the names of the columns |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2552 * |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2553 * @return the names of the columns |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2554 */ |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2555 String[] getNames() { |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2556 return name; |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2557 } |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2558 |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2559 /** |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2560 * Returns the types of the columns |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2561 * |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2562 * @return the types of the columns |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2563 */ |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2564 String[] getTypes() { |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2565 return type; |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2566 } |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2567 |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2568 /** |
665
8f7d51c478df
Improved implementation of methods ResultSetMetaData.getPrecision() and ResultSetMetaData.getScale().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
660
diff
changeset
|
2569 * Returns the table names of the columns |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2570 * |
665
8f7d51c478df
Improved implementation of methods ResultSetMetaData.getPrecision() and ResultSetMetaData.getScale().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
660
diff
changeset
|
2571 * @return the table names of the columns |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2572 */ |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2573 String[] getTableNames() { |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2574 return tableNames; |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2575 } |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2576 |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2577 /** |
665
8f7d51c478df
Improved implementation of methods ResultSetMetaData.getPrecision() and ResultSetMetaData.getScale().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
660
diff
changeset
|
2578 * Returns the schema names of the columns |
416
b3c876a0d61f
Improved performance of ResultSetMetaData methods getSchemaName(), getTableName(), getPrecision(), getScale(), isNullable() and isAutoIncrement().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
414
diff
changeset
|
2579 * |
665
8f7d51c478df
Improved implementation of methods ResultSetMetaData.getPrecision() and ResultSetMetaData.getScale().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
660
diff
changeset
|
2580 * @return the schema names of the columns |
416
b3c876a0d61f
Improved performance of ResultSetMetaData methods getSchemaName(), getTableName(), getPrecision(), getScale(), isNullable() and isAutoIncrement().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
414
diff
changeset
|
2581 */ |
b3c876a0d61f
Improved performance of ResultSetMetaData methods getSchemaName(), getTableName(), getPrecision(), getScale(), isNullable() and isAutoIncrement().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
414
diff
changeset
|
2582 String[] getSchemaNames() { |
b3c876a0d61f
Improved performance of ResultSetMetaData methods getSchemaName(), getTableName(), getPrecision(), getScale(), isNullable() and isAutoIncrement().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
414
diff
changeset
|
2583 return schemaNames; |
b3c876a0d61f
Improved performance of ResultSetMetaData methods getSchemaName(), getTableName(), getPrecision(), getScale(), isNullable() and isAutoIncrement().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
414
diff
changeset
|
2584 } |
b3c876a0d61f
Improved performance of ResultSetMetaData methods getSchemaName(), getTableName(), getPrecision(), getScale(), isNullable() and isAutoIncrement().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
414
diff
changeset
|
2585 |
b3c876a0d61f
Improved performance of ResultSetMetaData methods getSchemaName(), getTableName(), getPrecision(), getScale(), isNullable() and isAutoIncrement().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
414
diff
changeset
|
2586 /** |
665
8f7d51c478df
Improved implementation of methods ResultSetMetaData.getPrecision() and ResultSetMetaData.getScale().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
660
diff
changeset
|
2587 * Returns the display lengths of the columns |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2588 * |
665
8f7d51c478df
Improved implementation of methods ResultSetMetaData.getPrecision() and ResultSetMetaData.getScale().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
660
diff
changeset
|
2589 * @return the display lengths of the columns |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2590 */ |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2591 int[] getColumnLengths() { |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2592 return columnLengths; |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2593 } |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2594 |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2595 /** |
665
8f7d51c478df
Improved implementation of methods ResultSetMetaData.getPrecision() and ResultSetMetaData.getScale().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
660
diff
changeset
|
2596 * Returns the precisions of the columns |
8f7d51c478df
Improved implementation of methods ResultSetMetaData.getPrecision() and ResultSetMetaData.getScale().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
660
diff
changeset
|
2597 * |
8f7d51c478df
Improved implementation of methods ResultSetMetaData.getPrecision() and ResultSetMetaData.getScale().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
660
diff
changeset
|
2598 * @return the precisions of the columns, it can return null |
8f7d51c478df
Improved implementation of methods ResultSetMetaData.getPrecision() and ResultSetMetaData.getScale().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
660
diff
changeset
|
2599 */ |
8f7d51c478df
Improved implementation of methods ResultSetMetaData.getPrecision() and ResultSetMetaData.getScale().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
660
diff
changeset
|
2600 int[] getColumnPrecisions() { |
8f7d51c478df
Improved implementation of methods ResultSetMetaData.getPrecision() and ResultSetMetaData.getScale().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
660
diff
changeset
|
2601 return colPrecisions; |
8f7d51c478df
Improved implementation of methods ResultSetMetaData.getPrecision() and ResultSetMetaData.getScale().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
660
diff
changeset
|
2602 } |
8f7d51c478df
Improved implementation of methods ResultSetMetaData.getPrecision() and ResultSetMetaData.getScale().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
660
diff
changeset
|
2603 |
8f7d51c478df
Improved implementation of methods ResultSetMetaData.getPrecision() and ResultSetMetaData.getScale().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
660
diff
changeset
|
2604 /** |
8f7d51c478df
Improved implementation of methods ResultSetMetaData.getPrecision() and ResultSetMetaData.getScale().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
660
diff
changeset
|
2605 * Returns the scales of the columns (0 when scale is not applicable) |
8f7d51c478df
Improved implementation of methods ResultSetMetaData.getPrecision() and ResultSetMetaData.getScale().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
660
diff
changeset
|
2606 * |
8f7d51c478df
Improved implementation of methods ResultSetMetaData.getPrecision() and ResultSetMetaData.getScale().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
660
diff
changeset
|
2607 * @return the scales of the columns, it can return null |
8f7d51c478df
Improved implementation of methods ResultSetMetaData.getPrecision() and ResultSetMetaData.getScale().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
660
diff
changeset
|
2608 */ |
8f7d51c478df
Improved implementation of methods ResultSetMetaData.getPrecision() and ResultSetMetaData.getScale().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
660
diff
changeset
|
2609 int[] getColumnScales() { |
8f7d51c478df
Improved implementation of methods ResultSetMetaData.getPrecision() and ResultSetMetaData.getScale().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
660
diff
changeset
|
2610 return colScales; |
8f7d51c478df
Improved implementation of methods ResultSetMetaData.getPrecision() and ResultSetMetaData.getScale().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
660
diff
changeset
|
2611 } |
8f7d51c478df
Improved implementation of methods ResultSetMetaData.getPrecision() and ResultSetMetaData.getScale().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
660
diff
changeset
|
2612 |
8f7d51c478df
Improved implementation of methods ResultSetMetaData.getPrecision() and ResultSetMetaData.getScale().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
660
diff
changeset
|
2613 /** |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2614 * Returns the cache size used within this Response |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2615 * |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2616 * @return the cache size |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2617 */ |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2618 int getCacheSize() { |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2619 return cacheSize; |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2620 } |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2621 |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2622 /** |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2623 * Returns the current block offset |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2624 * |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2625 * @return the current block offset |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2626 */ |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2627 int getBlockOffset() { |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2628 return blockOffset; |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2629 } |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2630 |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2631 /** |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2632 * Returns the ResultSet type, FORWARD_ONLY or not. |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2633 * |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2634 * @return the ResultSet type |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2635 */ |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2636 int getRSType() { |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2637 return parent.rstype; |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2638 } |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2639 |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2640 /** |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2641 * Returns the concurrency of the ResultSet. |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2642 * |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2643 * @return the ResultSet concurrency |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2644 */ |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2645 int getRSConcur() { |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2646 return parent.rsconcur; |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2647 } |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2648 |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2649 /** |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2650 * Returns a line from the cache. If the line is already present in the |
136
4320e6891536
Replace AssertionError() with SQLException().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
90
diff
changeset
|
2651 * cache, it is returned, if not appropriate actions are taken to make |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2652 * sure the right block is being fetched and as soon as the requested |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2653 * line is fetched it is returned. |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2654 * |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2655 * @param row the row in the result set to return |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2656 * @return the exact row read as requested or null if the requested row |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2657 * is out of the scope of the result set |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2658 * @throws SQLException if an database error occurs |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2659 */ |
295
003ae6d881db
Add "final" keyword to method arguments and local variables where possible.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
292
diff
changeset
|
2660 String getLine(final int row) throws SQLException { |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2661 if (row >= tuplecount || row < 0) |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2662 return null; |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2663 |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2664 int block = (row - blockOffset) / cacheSize; |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2665 int blockLine = (row - blockOffset) % cacheSize; |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2666 |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2667 // do we have the right block loaded? (optimistic try) |
214
b8c007e86694
Improve readability
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
200
diff
changeset
|
2668 DataBlockResponse rawr = resultBlocks[block]; |
b8c007e86694
Improve readability
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
200
diff
changeset
|
2669 if (rawr == null) { |
b8c007e86694
Improve readability
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
200
diff
changeset
|
2670 // load block |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2671 /// TODO: ponder about a maximum number of blocks to keep |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2672 /// in memory when dealing with random access to |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2673 /// reduce memory blow-up |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2674 |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2675 // if we're running forward only, we can discard the old |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2676 // block loaded |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2677 if (parent.rstype == ResultSet.TYPE_FORWARD_ONLY) { |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2678 for (int i = 0; i < block; i++) |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2679 resultBlocks[i] = null; |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2680 |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2681 if (MonetConnection.seqCounter - 1 == seqnr && |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2682 !cacheSizeSetExplicitly && |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2683 tuplecount - row > cacheSize && |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2684 cacheSize < MonetConnection.DEF_FETCHSIZE * 10) |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2685 { |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2686 // there has no query been issued after this |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2687 // one, so we can consider this an uninterrupted |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2688 // continuation request. Let's once increase |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2689 // the cacheSize as it was not explicitly set, |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2690 // since the chances are high that we won't |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2691 // bother anyone else by doing so, and just |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2692 // gaining some performance. |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2693 |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2694 // store the previous position in the |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2695 // blockOffset variable |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2696 blockOffset += cacheSize; |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2697 |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2698 // increase the cache size (a lot) |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2699 cacheSize *= 10; |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2700 |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2701 // by changing the cacheSize, we also |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2702 // change the block measures. Luckily |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2703 // we don't care about previous blocks |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2704 // because we have a forward running |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2705 // pointer only. However, we do have |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2706 // to recalculate the block number, to |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2707 // ensure the next call to find this |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2708 // new block. |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2709 block = (row - blockOffset) / cacheSize; |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2710 blockLine = (row - blockOffset) % cacheSize; |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2711 } |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2712 } |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2713 |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2714 // ok, need to fetch cache block first |
136
4320e6891536
Replace AssertionError() with SQLException().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
90
diff
changeset
|
2715 parent.executeQuery(commandTempl, |
4320e6891536
Replace AssertionError() with SQLException().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
90
diff
changeset
|
2716 "export " + id + " " + ((block * cacheSize) + blockOffset) + " " + cacheSize); |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2717 rawr = resultBlocks[block]; |
45
c2bf983dc79b
Implemented Connection methods: getClientInfo(name) and getClientInfo().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
25
diff
changeset
|
2718 if (rawr == null) |
136
4320e6891536
Replace AssertionError() with SQLException().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
90
diff
changeset
|
2719 throw new SQLException("resultBlocks[" + block + "] should have been fetched by now", "M0M10"); |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2720 } |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2721 |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2722 return rawr.getRow(blockLine); |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2723 } |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2724 |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2725 /** |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2726 * Closes this Response by sending an Xclose to the server indicating |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2727 * that the result can be closed at the server side as well. |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2728 */ |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2729 @Override |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2730 public void close() { |
623
1c3cdf0667d7
Do more cleanup in the close() methods such as calling clearWarnings(), clearParameters(), clearBatch() and dereferencing cached objects.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
620
diff
changeset
|
2731 if (closed) |
1c3cdf0667d7
Do more cleanup in the close() methods such as calling clearWarnings(), clearParameters(), clearBatch() and dereferencing cached objects.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
620
diff
changeset
|
2732 return; |
45
c2bf983dc79b
Implemented Connection methods: getClientInfo(name) and getClientInfo().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
25
diff
changeset
|
2733 |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2734 // send command to server indicating we're done with this |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2735 // result only if we had an ID in the header and this result |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2736 // was larger than the reply size |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2737 try { |
45
c2bf983dc79b
Implemented Connection methods: getClientInfo(name) and getClientInfo().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
25
diff
changeset
|
2738 if (destroyOnClose) |
c2bf983dc79b
Implemented Connection methods: getClientInfo(name) and getClientInfo().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
25
diff
changeset
|
2739 sendControlCommand("close " + id); |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2740 } catch (SQLException e) { |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2741 // probably a connection error... |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2742 } |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2743 |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2744 // close the data block associated with us |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2745 for (int i = 1; i < resultBlocks.length; i++) { |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2746 DataBlockResponse r = resultBlocks[i]; |
45
c2bf983dc79b
Implemented Connection methods: getClientInfo(name) and getClientInfo().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
25
diff
changeset
|
2747 if (r != null) |
c2bf983dc79b
Implemented Connection methods: getClientInfo(name) and getClientInfo().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
25
diff
changeset
|
2748 r.close(); |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2749 } |
623
1c3cdf0667d7
Do more cleanup in the close() methods such as calling clearWarnings(), clearParameters(), clearBatch() and dereferencing cached objects.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
620
diff
changeset
|
2750 name = null; |
1c3cdf0667d7
Do more cleanup in the close() methods such as calling clearWarnings(), clearParameters(), clearBatch() and dereferencing cached objects.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
620
diff
changeset
|
2751 type = null; |
1c3cdf0667d7
Do more cleanup in the close() methods such as calling clearWarnings(), clearParameters(), clearBatch() and dereferencing cached objects.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
620
diff
changeset
|
2752 columnLengths = null; |
665
8f7d51c478df
Improved implementation of methods ResultSetMetaData.getPrecision() and ResultSetMetaData.getScale().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
660
diff
changeset
|
2753 colPrecisions = null; |
8f7d51c478df
Improved implementation of methods ResultSetMetaData.getPrecision() and ResultSetMetaData.getScale().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
660
diff
changeset
|
2754 colScales = null; |
623
1c3cdf0667d7
Do more cleanup in the close() methods such as calling clearWarnings(), clearParameters(), clearBatch() and dereferencing cached objects.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
620
diff
changeset
|
2755 tableNames = null; |
1c3cdf0667d7
Do more cleanup in the close() methods such as calling clearWarnings(), clearParameters(), clearBatch() and dereferencing cached objects.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
620
diff
changeset
|
2756 schemaNames = null; |
1c3cdf0667d7
Do more cleanup in the close() methods such as calling clearWarnings(), clearParameters(), clearBatch() and dereferencing cached objects.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
620
diff
changeset
|
2757 resultBlocks = null; |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2758 closed = true; |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2759 } |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2760 |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2761 /** |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2762 * Returns whether this Response is closed |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2763 * |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2764 * @return whether this Response is closed |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2765 */ |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2766 boolean isClosed() { |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2767 return closed; |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2768 } |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2769 } |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2770 // }}} |
77
83aee4f60649
Added private method sendTransactionCommand(String); to reduce duplicate code in 6 methods.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
47
diff
changeset
|
2771 |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2772 /** |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2773 * The DataBlockResponse is tabular data belonging to a |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2774 * ResultSetResponse. Tabular data from the server typically looks |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2775 * like: |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2776 * <pre> |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2777 * [ "value", 56 ] |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2778 * </pre> |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2779 * where each column is separated by ",\t" and each tuple surrounded |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2780 * by brackets ("[" and "]"). A DataBlockResponse object holds the |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2781 * raw data as read from the server, in a parsed manner, ready for |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2782 * easy retrieval. |
45
c2bf983dc79b
Implemented Connection methods: getClientInfo(name) and getClientInfo().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
25
diff
changeset
|
2783 * |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2784 * This object is not intended to be queried by multiple threads |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2785 * synchronously. It is designed to work for one thread retrieving |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2786 * rows from it. When multiple threads will retrieve rows from this |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2787 * object, it is possible for threads to get the same data. |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2788 */ |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2789 // {{{ DataBlockResponse class implementation |
296
c5efd6e661e5
Add "final" keyword to classes, method arguments and local variables where possible.`
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
295
diff
changeset
|
2790 private final static class DataBlockResponse implements Response { |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2791 /** The String array to keep the data in */ |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2792 private final String[] data; |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2793 |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2794 /** The counter which keeps the current position in the data array */ |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2795 private int pos; |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2796 /** Whether we can discard lines as soon as we have read them */ |
295
003ae6d881db
Add "final" keyword to method arguments and local variables where possible.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
292
diff
changeset
|
2797 private final boolean forwardOnly; |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2798 |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2799 /** |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2800 * Constructs a DataBlockResponse object |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2801 * @param size the size of the data array to create |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2802 * @param forward whether this is a forward only result |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2803 */ |
295
003ae6d881db
Add "final" keyword to method arguments and local variables where possible.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
292
diff
changeset
|
2804 DataBlockResponse(final int size, final boolean forward) { |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2805 pos = -1; |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2806 data = new String[size]; |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2807 forwardOnly = forward; |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2808 } |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2809 |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2810 /** |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2811 * addLine adds a String of data to this object's data array. |
702
b4e968e5bd74
Some improvements.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
701
diff
changeset
|
2812 * Note that an ArrayIndexOutOfBoundsException can be thrown when an |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2813 * attempt is made to add more than the original construction size |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2814 * specified. |
45
c2bf983dc79b
Implemented Connection methods: getClientInfo(name) and getClientInfo().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
25
diff
changeset
|
2815 * |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2816 * @param line the header line as String |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2817 * @param linetype the line type according to the MAPI protocol |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2818 * @return a non-null String if the line is invalid, |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2819 * or additional lines are not allowed. |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2820 */ |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2821 @Override |
497
aed7f32e029a
Refactor LineType to be an enum
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
496
diff
changeset
|
2822 public String addLine(final String line, final LineType linetype) { |
aed7f32e029a
Refactor LineType to be an enum
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
496
diff
changeset
|
2823 if (linetype != LineType.RESULT) |
690
f7946d36d1dd
Extend error messages with the linetype to give more info.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
685
diff
changeset
|
2824 return "protocol violation: unexpected " + linetype + " line in data block: " + line; |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2825 // add to the backing array |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2826 data[++pos] = line; |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2827 |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2828 // all is well |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2829 return null; |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2830 } |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2831 |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2832 /** |
288
f412032e3b43
Correcting typo
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
286
diff
changeset
|
2833 * Returns whether this Response expects more lines to be added |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2834 * to it. |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2835 * |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2836 * @return true if a next line should be added, false otherwise |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2837 */ |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2838 @Override |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2839 public boolean wantsMore() { |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2840 // remember: pos is the value already stored |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2841 return pos + 1 < data.length; |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2842 } |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2843 |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2844 /** |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2845 * Indicates that no more header lines will be added to this |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2846 * Response implementation. In most cases this is a redundant |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2847 * operation because the data array is full. However... it can |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2848 * happen that this is NOT the case! |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2849 * |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2850 * @throws SQLException if not all rows are filled |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2851 */ |
324
0b01771d5f8a
Method Response.complete() is never used or needed. Disabled the code from the interface and its implementations.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
300
diff
changeset
|
2852 /* MvD: disabled not used/needed code |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2853 @Override |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2854 public void complete() throws SQLException { |
45
c2bf983dc79b
Implemented Connection methods: getClientInfo(name) and getClientInfo().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
25
diff
changeset
|
2855 if ((pos + 1) != data.length) |
295
003ae6d881db
Add "final" keyword to method arguments and local variables where possible.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
292
diff
changeset
|
2856 throw new SQLException("Inconsistent state detected! Current block capacity: " |
003ae6d881db
Add "final" keyword to method arguments and local variables where possible.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
292
diff
changeset
|
2857 + data.length + ", block usage: " + (pos + 1) |
003ae6d881db
Add "final" keyword to method arguments and local variables where possible.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
292
diff
changeset
|
2858 + ". Did MonetDB send what it promised to?", "M0M10"); |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2859 } |
324
0b01771d5f8a
Method Response.complete() is never used or needed. Disabled the code from the interface and its implementations.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
300
diff
changeset
|
2860 */ |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2861 |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2862 /** |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2863 * Instructs the Response implementation to close and do the |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2864 * necessary clean up procedures. |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2865 */ |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2866 @Override |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2867 public void close() { |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2868 // feed all rows to the garbage collector |
819
726a1d7b168c
correct indentation
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
814
diff
changeset
|
2869 Arrays.fill(data, null); |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2870 } |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2871 |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2872 /** |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2873 * Retrieves the required row. Warning: if the requested rows |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2874 * is out of bounds, an IndexOutOfBoundsException will be |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2875 * thrown. |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2876 * |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2877 * @param line the row to retrieve |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2878 * @return the requested row as String |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2879 */ |
295
003ae6d881db
Add "final" keyword to method arguments and local variables where possible.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
292
diff
changeset
|
2880 String getRow(final int line) { |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2881 if (forwardOnly) { |
295
003ae6d881db
Add "final" keyword to method arguments and local variables where possible.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
292
diff
changeset
|
2882 final String ret = data[line]; |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2883 data[line] = null; |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2884 return ret; |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2885 } else { |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2886 return data[line]; |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2887 } |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2888 } |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2889 } |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2890 // }}} |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2891 |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2892 /** |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2893 * The UpdateResponse represents an update statement response. It |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2894 * is issued on an UPDATE, INSERT or DELETE SQL statement. This |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2895 * response keeps a count field that represents the affected rows |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2896 * and a field that contains the last inserted auto-generated ID, or |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2897 * -1 if not applicable.<br /> |
708
5022a57f9d97
Resolve javadoc errors.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
707
diff
changeset
|
2898 * <samp>&2 0 -1</samp> |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2899 */ |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2900 // {{{ UpdateResponse class implementation |
296
c5efd6e661e5
Add "final" keyword to classes, method arguments and local variables where possible.`
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
295
diff
changeset
|
2901 final static class UpdateResponse implements Response { |
378
02f353f62abe
Adjust UpdateResponse to allow for large updates (long instead of int).
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
377
diff
changeset
|
2902 public final long count; |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2903 public final String lastid; |
77
83aee4f60649
Added private method sendTransactionCommand(String); to reduce duplicate code in 6 methods.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
47
diff
changeset
|
2904 |
378
02f353f62abe
Adjust UpdateResponse to allow for large updates (long instead of int).
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
377
diff
changeset
|
2905 public UpdateResponse(final long cnt, final String id) { |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2906 // fill the blank finals |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2907 this.count = cnt; |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2908 this.lastid = id; |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2909 } |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2910 |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2911 @Override |
497
aed7f32e029a
Refactor LineType to be an enum
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
496
diff
changeset
|
2912 public String addLine(final String line, final LineType linetype) { |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2913 return "Header lines are not supported for an UpdateResponse"; |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2914 } |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2915 |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2916 @Override |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2917 public boolean wantsMore() { |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2918 return false; |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2919 } |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2920 |
324
0b01771d5f8a
Method Response.complete() is never used or needed. Disabled the code from the interface and its implementations.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
300
diff
changeset
|
2921 /* MvD: disabled not used/needed code |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2922 @Override |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2923 public void complete() { |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2924 // empty, because there is nothing to check |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2925 } |
324
0b01771d5f8a
Method Response.complete() is never used or needed. Disabled the code from the interface and its implementations.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
300
diff
changeset
|
2926 */ |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2927 |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2928 @Override |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2929 public void close() { |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2930 // nothing to do here... |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2931 } |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2932 } |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2933 // }}} |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2934 |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2935 /** |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2936 * The SchemaResponse represents an schema modification response. |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2937 * It is issued on statements like CREATE, DROP or ALTER TABLE. |
708
5022a57f9d97
Resolve javadoc errors.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
707
diff
changeset
|
2938 * <samp>&3</samp> |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2939 */ |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2940 // {{{ SchemaResponse class implementation |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2941 class SchemaResponse implements Response { |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2942 @Override |
497
aed7f32e029a
Refactor LineType to be an enum
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
496
diff
changeset
|
2943 public String addLine(final String line, final LineType linetype) { |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2944 return "Header lines are not supported for a SchemaResponse"; |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2945 } |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2946 |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2947 @Override |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2948 public boolean wantsMore() { |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2949 return false; |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2950 } |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2951 |
324
0b01771d5f8a
Method Response.complete() is never used or needed. Disabled the code from the interface and its implementations.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
300
diff
changeset
|
2952 /* MvD: disabled not used/needed code |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2953 @Override |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2954 public void complete() { |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2955 // empty, because there is nothing to check |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2956 } |
324
0b01771d5f8a
Method Response.complete() is never used or needed. Disabled the code from the interface and its implementations.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
300
diff
changeset
|
2957 */ |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2958 |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2959 @Override |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2960 public void close() { |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2961 // nothing to do here... |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2962 } |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2963 } |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2964 // }}} |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2965 |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2966 /** |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2967 * The AutoCommitResponse represents a transaction message. It |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2968 * stores (a change in) the server side auto commit mode.<br /> |
708
5022a57f9d97
Resolve javadoc errors.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
707
diff
changeset
|
2969 * <samp>&4 (t|f)</samp> |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2970 */ |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2971 // {{{ AutoCommitResponse class implementation |
296
c5efd6e661e5
Add "final" keyword to classes, method arguments and local variables where possible.`
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
295
diff
changeset
|
2972 private final class AutoCommitResponse extends SchemaResponse { |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2973 public final boolean autocommit; |
77
83aee4f60649
Added private method sendTransactionCommand(String); to reduce duplicate code in 6 methods.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
47
diff
changeset
|
2974 |
295
003ae6d881db
Add "final" keyword to method arguments and local variables where possible.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
292
diff
changeset
|
2975 public AutoCommitResponse(final boolean ac) { |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2976 // fill the blank final |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2977 this.autocommit = ac; |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2978 } |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2979 } |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2980 // }}} |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2981 |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2982 /** |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2983 * A list of Response objects. Responses are added to this list. |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2984 * Methods of this class are not synchronized. This is left as |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2985 * responsibility to the caller to prevent concurrent access. |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2986 */ |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2987 // {{{ ResponseList class implementation |
296
c5efd6e661e5
Add "final" keyword to classes, method arguments and local variables where possible.`
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
295
diff
changeset
|
2988 final class ResponseList { |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2989 /** The cache size (number of rows in a DataBlockResponse object) */ |
186
4767b005a531
Making variables private where possible.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
184
diff
changeset
|
2990 private final int cachesize; |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2991 /** The maximum number of results for this query */ |
376
ffdc7b0e102d
Updated JDBC driver to comply with JDBC 4.2 interface now we compile for Java 8. This includes:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
370
diff
changeset
|
2992 private final long maxrows; |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2993 /** The ResultSet type to produce */ |
186
4767b005a531
Making variables private where possible.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
184
diff
changeset
|
2994 private final int rstype; |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2995 /** The ResultSet concurrency to produce */ |
186
4767b005a531
Making variables private where possible.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
184
diff
changeset
|
2996 private final int rsconcur; |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2997 /** The sequence number of this ResponseList */ |
186
4767b005a531
Making variables private where possible.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
184
diff
changeset
|
2998 private final int seqnr; |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2999 /** A list of the Responses associated with the query, |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
3000 * in the right order */ |
295
003ae6d881db
Add "final" keyword to method arguments and local variables where possible.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
292
diff
changeset
|
3001 private final ArrayList<Response> responses; |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
3002 /** A map of ResultSetResponses, used for additional |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
3003 * DataBlockResponse mapping */ |
295
003ae6d881db
Add "final" keyword to method arguments and local variables where possible.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
292
diff
changeset
|
3004 private HashMap<Integer, ResultSetResponse> rsresponses; |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
3005 |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
3006 /** The current header returned by getNextResponse() */ |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
3007 private int curResponse; |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
3008 |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
3009 /** |
709
bdeabbd46ec6
Resolve javac and javadoc warnings when compiled with JDK19.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
708
diff
changeset
|
3010 * Main constructor. |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
3011 * |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
3012 * @param cachesize overall cachesize to use |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
3013 * @param maxrows maximum number of rows to allow in the set |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
3014 * @param rstype the type of result sets to produce |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
3015 * @param rsconcur the concurrency of result sets to produce |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
3016 */ |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
3017 ResponseList( |
295
003ae6d881db
Add "final" keyword to method arguments and local variables where possible.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
292
diff
changeset
|
3018 final int cachesize, |
376
ffdc7b0e102d
Updated JDBC driver to comply with JDBC 4.2 interface now we compile for Java 8. This includes:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
370
diff
changeset
|
3019 final long maxrows, |
295
003ae6d881db
Add "final" keyword to method arguments and local variables where possible.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
292
diff
changeset
|
3020 final int rstype, |
709
bdeabbd46ec6
Resolve javac and javadoc warnings when compiled with JDK19.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
708
diff
changeset
|
3021 final int rsconcur) |
bdeabbd46ec6
Resolve javac and javadoc warnings when compiled with JDK19.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
708
diff
changeset
|
3022 { |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
3023 this.cachesize = cachesize; |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
3024 this.maxrows = maxrows; |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
3025 this.rstype = rstype; |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
3026 this.rsconcur = rsconcur; |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
3027 responses = new ArrayList<Response>(); |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
3028 curResponse = -1; |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
3029 seqnr = MonetConnection.seqCounter++; |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
3030 } |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
3031 |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
3032 /** |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
3033 * Retrieves the next available response, or null if there are |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
3034 * no more responses. |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
3035 * |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
3036 * @return the next Response available or null |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
3037 */ |
709
bdeabbd46ec6
Resolve javac and javadoc warnings when compiled with JDK19.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
708
diff
changeset
|
3038 Response getNextResponse() { |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
3039 if (rstype == ResultSet.TYPE_FORWARD_ONLY) { |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
3040 // free resources if we're running forward only |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
3041 if (curResponse >= 0 && curResponse < responses.size()) { |
295
003ae6d881db
Add "final" keyword to method arguments and local variables where possible.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
292
diff
changeset
|
3042 final Response tmp = responses.get(curResponse); |
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
|
3043 if (tmp != null) |
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
|
3044 tmp.close(); |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
3045 responses.set(curResponse, null); |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
3046 } |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
3047 } |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
3048 curResponse++; |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
3049 if (curResponse >= responses.size()) { |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
3050 // ResponseList is obviously completed so, there are no |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
3051 // more responses |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
3052 return null; |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
3053 } else { |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
3054 // return this response |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
3055 return responses.get(curResponse); |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
3056 } |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
3057 } |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
3058 |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
3059 /** |
288
f412032e3b43
Correcting typo
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
286
diff
changeset
|
3060 * Closes the Response at index i, if not null. |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
3061 * |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
3062 * @param i the index position of the header to close |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
3063 */ |
295
003ae6d881db
Add "final" keyword to method arguments and local variables where possible.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
292
diff
changeset
|
3064 void closeResponse(final int i) { |
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
|
3065 if (i < 0 || i >= responses.size()) |
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
|
3066 return; |
295
003ae6d881db
Add "final" keyword to method arguments and local variables where possible.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
292
diff
changeset
|
3067 final Response tmp = responses.set(i, null); |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
3068 if (tmp != null) |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
3069 tmp.close(); |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
3070 } |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
3071 |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
3072 /** |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
3073 * Closes the current response. |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
3074 */ |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
3075 void closeCurrentResponse() { |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
3076 closeResponse(curResponse); |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
3077 } |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
3078 |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
3079 /** |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
3080 * Closes the current and previous responses. |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
3081 */ |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
3082 void closeCurOldResponses() { |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
3083 for (int i = curResponse; i >= 0; i--) { |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
3084 closeResponse(i); |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
3085 } |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
3086 } |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
3087 |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
3088 /** |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
3089 * Closes this ResponseList by closing all the Responses in this |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
3090 * ResponseList. |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
3091 */ |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
3092 void close() { |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
3093 for (int i = 0; i < responses.size(); i++) { |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
3094 closeResponse(i); |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
3095 } |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
3096 } |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
3097 |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
3098 /** |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
3099 * Returns whether this ResponseList has still unclosed |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
3100 * Responses. |
709
bdeabbd46ec6
Resolve javac and javadoc warnings when compiled with JDK19.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
708
diff
changeset
|
3101 * @return whether there are unclosed Responses |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
3102 */ |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
3103 boolean hasUnclosedResponses() { |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
3104 for (Response r : responses) { |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
3105 if (r != null) |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
3106 return true; |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
3107 } |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
3108 return false; |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
3109 } |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
3110 |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
3111 /** |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
3112 * Executes the query contained in this ResponseList, and |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
3113 * stores the Responses resulting from this query in this |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
3114 * ResponseList. |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
3115 * |
709
bdeabbd46ec6
Resolve javac and javadoc warnings when compiled with JDK19.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
708
diff
changeset
|
3116 * @param query the SQL query to execute |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
3117 * @throws SQLException if a database error occurs |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
3118 */ |
295
003ae6d881db
Add "final" keyword to method arguments and local variables where possible.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
292
diff
changeset
|
3119 void processQuery(final String query) throws SQLException { |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
3120 executeQuery(queryTempl, query); |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
3121 } |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
3122 |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
3123 /** |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
3124 * Internal executor of queries. |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
3125 * |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
3126 * @param templ the template to fill in |
552
7b320303b579
Doc comment improvements
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
551
diff
changeset
|
3127 * @param query the query to execute |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
3128 * @throws SQLException if a database error occurs |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
3129 */ |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
3130 @SuppressWarnings("fallthrough") |
295
003ae6d881db
Add "final" keyword to method arguments and local variables where possible.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
292
diff
changeset
|
3131 void executeQuery(final String[] templ, final String query) |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
3132 throws SQLException |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
3133 { |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
3134 String error = null; |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
3135 |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
3136 try { |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
3137 synchronized (server) { |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
3138 // make sure we're ready to send query; read data till we |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
3139 // have the prompt it is possible (and most likely) that we |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
3140 // already have the prompt and do not have to skip any |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
3141 // lines. Ignore errors from previous result sets. |
700
940e266eeccd
Refactor BufferedMCLReader
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
697
diff
changeset
|
3142 in.discardRemainder(); |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
3143 |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
3144 // {{{ set reply size |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
3145 /** |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
3146 * Change the reply size of the server. If the given |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
3147 * value is the same as the current value known to use, |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
3148 * then ignore this call. If it is set to 0 we get a |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
3149 * prompt after the server sent it's header. |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
3150 */ |
480
849af4b76b28
Optimise code by reducing local variables which are used only once, replacing complex string concatenation by using StringBuilder, replacing some ternairy operators.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
474
diff
changeset
|
3151 int size = cachesize; |
849af4b76b28
Optimise code by reducing local variables which are used only once, replacing complex string concatenation by using StringBuilder, replacing some ternairy operators.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
474
diff
changeset
|
3152 if (size == 0) |
849af4b76b28
Optimise code by reducing local variables which are used only once, replacing complex string concatenation by using StringBuilder, replacing some ternairy operators.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
474
diff
changeset
|
3153 size = defaultFetchSize; |
178
dd12348c41cf
Improvement: only extend typeMap when the property was set to true.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
175
diff
changeset
|
3154 if (maxrows > 0 && maxrows < size) |
376
ffdc7b0e102d
Updated JDBC driver to comply with JDBC 4.2 interface now we compile for Java 8. This includes:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
370
diff
changeset
|
3155 size = (int)maxrows; |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
3156 // don't do work if it's not needed |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
3157 if (lang == LANG_SQL && size != curReplySize && templ != commandTempl) { |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
3158 sendControlCommand("reply_size " + size); |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
3159 |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
3160 // store the reply size after a successful change |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
3161 curReplySize = size; |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
3162 } |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
3163 // }}} set reply size |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
3164 |
285
637899bda602
Removed SendThread class and its usage from MonetConnection.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
284
diff
changeset
|
3165 // send query to the server |
576
095e896f9d7a
Updated comments. Improved code. Added final keywords
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
568
diff
changeset
|
3166 out.writeLine(templ[0] + query + templ[1]); |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
3167 |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
3168 // go for new results |
700
940e266eeccd
Refactor BufferedMCLReader
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
697
diff
changeset
|
3169 in.advance(); |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
3170 Response res = null; |
700
940e266eeccd
Refactor BufferedMCLReader
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
697
diff
changeset
|
3171 while (in.getLineType() != LineType.PROMPT) { |
284
e5b99c929a2d
Improve setSchema(String schema) by checking also on empty name.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
278
diff
changeset
|
3172 // each response should start with a start of header (or error) |
700
940e266eeccd
Refactor BufferedMCLReader
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
697
diff
changeset
|
3173 switch (in.getLineType()) { |
497
aed7f32e029a
Refactor LineType to be an enum
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
496
diff
changeset
|
3174 case SOHEADER: |
284
e5b99c929a2d
Improve setSchema(String schema) by checking also on empty name.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
278
diff
changeset
|
3175 // make the response object, and fill it |
e5b99c929a2d
Improve setSchema(String schema) by checking also on empty name.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
278
diff
changeset
|
3176 try { |
700
940e266eeccd
Refactor BufferedMCLReader
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
697
diff
changeset
|
3177 switch (sohp.parse(in.getLine())) { |
284
e5b99c929a2d
Improve setSchema(String schema) by checking also on empty name.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
278
diff
changeset
|
3178 case StartOfHeaderParser.Q_PARSE: |
e5b99c929a2d
Improve setSchema(String schema) by checking also on empty name.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
278
diff
changeset
|
3179 throw new MCLParseException("Q_PARSE header not allowed here", 1); |
e5b99c929a2d
Improve setSchema(String schema) by checking also on empty name.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
278
diff
changeset
|
3180 case StartOfHeaderParser.Q_TABLE: |
e5b99c929a2d
Improve setSchema(String schema) by checking also on empty name.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
278
diff
changeset
|
3181 case StartOfHeaderParser.Q_PREPARE: { |
295
003ae6d881db
Add "final" keyword to method arguments and local variables where possible.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
292
diff
changeset
|
3182 final int id = sohp.getNextAsInt(); |
377
8a813f5cef1b
Extend StartOfHeaderParser with method getNextAsLong() and change type of tuplecount to long.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
376
diff
changeset
|
3183 long tuplecount = sohp.getNextAsLong(); |
295
003ae6d881db
Add "final" keyword to method arguments and local variables where possible.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
292
diff
changeset
|
3184 final int columncount = sohp.getNextAsInt(); |
003ae6d881db
Add "final" keyword to method arguments and local variables where possible.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
292
diff
changeset
|
3185 final int rowcount = sohp.getNextAsInt(); |
284
e5b99c929a2d
Improve setSchema(String schema) by checking also on empty name.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
278
diff
changeset
|
3186 // enforce the maxrows setting |
e5b99c929a2d
Improve setSchema(String schema) by checking also on empty name.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
278
diff
changeset
|
3187 if (maxrows != 0 && tuplecount > maxrows) |
377
8a813f5cef1b
Extend StartOfHeaderParser with method getNextAsLong() and change type of tuplecount to long.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
376
diff
changeset
|
3188 tuplecount = maxrows; |
284
e5b99c929a2d
Improve setSchema(String schema) by checking also on empty name.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
278
diff
changeset
|
3189 res = new ResultSetResponse(id, tuplecount, columncount, rowcount, this, seqnr); |
e5b99c929a2d
Improve setSchema(String schema) by checking also on empty name.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
278
diff
changeset
|
3190 // only add this resultset to the hashmap if it can possibly have an additional datablock |
e5b99c929a2d
Improve setSchema(String schema) by checking also on empty name.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
278
diff
changeset
|
3191 if (rowcount < tuplecount) { |
e5b99c929a2d
Improve setSchema(String schema) by checking also on empty name.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
278
diff
changeset
|
3192 if (rsresponses == null) |
e5b99c929a2d
Improve setSchema(String schema) by checking also on empty name.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
278
diff
changeset
|
3193 rsresponses = new HashMap<Integer, ResultSetResponse>(); |
556
87feb93330a6
Misc. changes suggested by analysis tool
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
554
diff
changeset
|
3194 rsresponses.put(id, (ResultSetResponse) res); |
284
e5b99c929a2d
Improve setSchema(String schema) by checking also on empty name.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
278
diff
changeset
|
3195 } |
e5b99c929a2d
Improve setSchema(String schema) by checking also on empty name.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
278
diff
changeset
|
3196 } break; |
e5b99c929a2d
Improve setSchema(String schema) by checking also on empty name.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
278
diff
changeset
|
3197 case StartOfHeaderParser.Q_UPDATE: |
378
02f353f62abe
Adjust UpdateResponse to allow for large updates (long instead of int).
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
377
diff
changeset
|
3198 res = new UpdateResponse(sohp.getNextAsLong(), // count |
284
e5b99c929a2d
Improve setSchema(String schema) by checking also on empty name.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
278
diff
changeset
|
3199 sohp.getNextAsString() // key-id |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
3200 ); |
284
e5b99c929a2d
Improve setSchema(String schema) by checking also on empty name.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
278
diff
changeset
|
3201 break; |
e5b99c929a2d
Improve setSchema(String schema) by checking also on empty name.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
278
diff
changeset
|
3202 case StartOfHeaderParser.Q_SCHEMA: |
e5b99c929a2d
Improve setSchema(String schema) by checking also on empty name.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
278
diff
changeset
|
3203 res = new SchemaResponse(); |
e5b99c929a2d
Improve setSchema(String schema) by checking also on empty name.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
278
diff
changeset
|
3204 break; |
e5b99c929a2d
Improve setSchema(String schema) by checking also on empty name.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
278
diff
changeset
|
3205 case StartOfHeaderParser.Q_TRANS: |
480
849af4b76b28
Optimise code by reducing local variables which are used only once, replacing complex string concatenation by using StringBuilder, replacing some ternairy operators.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
474
diff
changeset
|
3206 final boolean ac = sohp.getNextAsString().equals("t"); |
284
e5b99c929a2d
Improve setSchema(String schema) by checking also on empty name.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
278
diff
changeset
|
3207 if (autoCommit && ac) { |
e5b99c929a2d
Improve setSchema(String schema) by checking also on empty name.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
278
diff
changeset
|
3208 addWarning("Server enabled auto commit mode " + |
e5b99c929a2d
Improve setSchema(String schema) by checking also on empty name.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
278
diff
changeset
|
3209 "while local state already was auto commit.", "01M11"); |
e5b99c929a2d
Improve setSchema(String schema) by checking also on empty name.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
278
diff
changeset
|
3210 } |
e5b99c929a2d
Improve setSchema(String schema) by checking also on empty name.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
278
diff
changeset
|
3211 autoCommit = ac; |
e5b99c929a2d
Improve setSchema(String schema) by checking also on empty name.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
278
diff
changeset
|
3212 res = new AutoCommitResponse(ac); |
e5b99c929a2d
Improve setSchema(String schema) by checking also on empty name.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
278
diff
changeset
|
3213 break; |
e5b99c929a2d
Improve setSchema(String schema) by checking also on empty name.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
278
diff
changeset
|
3214 case StartOfHeaderParser.Q_BLOCK: { |
e5b99c929a2d
Improve setSchema(String schema) by checking also on empty name.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
278
diff
changeset
|
3215 // a new block of results for a response... |
295
003ae6d881db
Add "final" keyword to method arguments and local variables where possible.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
292
diff
changeset
|
3216 final int id = sohp.getNextAsInt(); |
284
e5b99c929a2d
Improve setSchema(String schema) by checking also on empty name.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
278
diff
changeset
|
3217 sohp.getNextAsInt(); // columncount |
295
003ae6d881db
Add "final" keyword to method arguments and local variables where possible.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
292
diff
changeset
|
3218 final int rowcount = sohp.getNextAsInt(); |
003ae6d881db
Add "final" keyword to method arguments and local variables where possible.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
292
diff
changeset
|
3219 final int offset = sohp.getNextAsInt(); |
480
849af4b76b28
Optimise code by reducing local variables which are used only once, replacing complex string concatenation by using StringBuilder, replacing some ternairy operators.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
474
diff
changeset
|
3220 final ResultSetResponse t; |
849af4b76b28
Optimise code by reducing local variables which are used only once, replacing complex string concatenation by using StringBuilder, replacing some ternairy operators.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
474
diff
changeset
|
3221 if (rsresponses != null) |
556
87feb93330a6
Misc. changes suggested by analysis tool
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
554
diff
changeset
|
3222 t = rsresponses.get(id); |
480
849af4b76b28
Optimise code by reducing local variables which are used only once, replacing complex string concatenation by using StringBuilder, replacing some ternairy operators.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
474
diff
changeset
|
3223 else |
849af4b76b28
Optimise code by reducing local variables which are used only once, replacing complex string concatenation by using StringBuilder, replacing some ternairy operators.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
474
diff
changeset
|
3224 t = null; |
284
e5b99c929a2d
Improve setSchema(String schema) by checking also on empty name.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
278
diff
changeset
|
3225 if (t == null) { |
e5b99c929a2d
Improve setSchema(String schema) by checking also on empty name.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
278
diff
changeset
|
3226 error = "M0M12!no ResultSetResponse with id " + id + " found"; |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
3227 break; |
284
e5b99c929a2d
Improve setSchema(String schema) by checking also on empty name.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
278
diff
changeset
|
3228 } |
295
003ae6d881db
Add "final" keyword to method arguments and local variables where possible.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
292
diff
changeset
|
3229 final DataBlockResponse r = new DataBlockResponse(rowcount, t.getRSType() == ResultSet.TYPE_FORWARD_ONLY); |
284
e5b99c929a2d
Improve setSchema(String schema) by checking also on empty name.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
278
diff
changeset
|
3230 t.addDataBlockResponse(offset, r); |
e5b99c929a2d
Improve setSchema(String schema) by checking also on empty name.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
278
diff
changeset
|
3231 res = r; |
e5b99c929a2d
Improve setSchema(String schema) by checking also on empty name.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
278
diff
changeset
|
3232 } break; |
e5b99c929a2d
Improve setSchema(String schema) by checking also on empty name.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
278
diff
changeset
|
3233 } // end of switch (sohp.parse(tmpLine)) |
e5b99c929a2d
Improve setSchema(String schema) by checking also on empty name.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
278
diff
changeset
|
3234 } catch (MCLParseException e) { |
480
849af4b76b28
Optimise code by reducing local variables which are used only once, replacing complex string concatenation by using StringBuilder, replacing some ternairy operators.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
474
diff
changeset
|
3235 final int offset = e.getErrorOffset(); |
284
e5b99c929a2d
Improve setSchema(String schema) by checking also on empty name.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
278
diff
changeset
|
3236 error = "M0M10!error while parsing start of header:\n" + |
e5b99c929a2d
Improve setSchema(String schema) by checking also on empty name.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
278
diff
changeset
|
3237 e.getMessage() + |
700
940e266eeccd
Refactor BufferedMCLReader
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
697
diff
changeset
|
3238 " found: '" + in.getLine().charAt(offset) + |
940e266eeccd
Refactor BufferedMCLReader
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
697
diff
changeset
|
3239 "' in: \"" + in.getLine() + |
480
849af4b76b28
Optimise code by reducing local variables which are used only once, replacing complex string concatenation by using StringBuilder, replacing some ternairy operators.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
474
diff
changeset
|
3240 "\" at pos: " + offset; |
284
e5b99c929a2d
Improve setSchema(String schema) by checking also on empty name.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
278
diff
changeset
|
3241 // flush all the rest |
700
940e266eeccd
Refactor BufferedMCLReader
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
697
diff
changeset
|
3242 in.discardRemainder(); |
284
e5b99c929a2d
Improve setSchema(String schema) by checking also on empty name.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
278
diff
changeset
|
3243 break; |
e5b99c929a2d
Improve setSchema(String schema) by checking also on empty name.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
278
diff
changeset
|
3244 } |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
3245 |
284
e5b99c929a2d
Improve setSchema(String schema) by checking also on empty name.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
278
diff
changeset
|
3246 // immediately handle errors after parsing the header (res may be null) |
e5b99c929a2d
Improve setSchema(String schema) by checking also on empty name.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
278
diff
changeset
|
3247 if (error != null) { |
700
940e266eeccd
Refactor BufferedMCLReader
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
697
diff
changeset
|
3248 in.discardRemainder(); |
284
e5b99c929a2d
Improve setSchema(String schema) by checking also on empty name.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
278
diff
changeset
|
3249 break; |
e5b99c929a2d
Improve setSchema(String schema) by checking also on empty name.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
278
diff
changeset
|
3250 } |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
3251 |
701
f89882b07614
Fix a problem with PREPARE INSERT
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
700
diff
changeset
|
3252 // advance to the line after the header |
f89882b07614
Fix a problem with PREPARE INSERT
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
700
diff
changeset
|
3253 in.advance(); |
f89882b07614
Fix a problem with PREPARE INSERT
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
700
diff
changeset
|
3254 |
f89882b07614
Fix a problem with PREPARE INSERT
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
700
diff
changeset
|
3255 // stuff all header lines into the res |
f89882b07614
Fix a problem with PREPARE INSERT
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
700
diff
changeset
|
3256 while (error == null && in.getLineType() == LineType.HEADER) { |
700
940e266eeccd
Refactor BufferedMCLReader
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
697
diff
changeset
|
3257 error = res.addLine(in.getLine(), in.getLineType()); |
701
f89882b07614
Fix a problem with PREPARE INSERT
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
700
diff
changeset
|
3258 in.advance(); |
f89882b07614
Fix a problem with PREPARE INSERT
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
700
diff
changeset
|
3259 } |
f89882b07614
Fix a problem with PREPARE INSERT
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
700
diff
changeset
|
3260 |
f89882b07614
Fix a problem with PREPARE INSERT
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
700
diff
changeset
|
3261 // then feed it more lines until it is satisfied |
f89882b07614
Fix a problem with PREPARE INSERT
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
700
diff
changeset
|
3262 while (error == null && res.wantsMore()) { |
f89882b07614
Fix a problem with PREPARE INSERT
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
700
diff
changeset
|
3263 error = res.addLine(in.getLine(), in.getLineType()); |
f89882b07614
Fix a problem with PREPARE INSERT
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
700
diff
changeset
|
3264 in.advance(); |
284
e5b99c929a2d
Improve setSchema(String schema) by checking also on empty name.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
278
diff
changeset
|
3265 } |
701
f89882b07614
Fix a problem with PREPARE INSERT
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
700
diff
changeset
|
3266 |
f89882b07614
Fix a problem with PREPARE INSERT
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
700
diff
changeset
|
3267 if (error != null) { |
f89882b07614
Fix a problem with PREPARE INSERT
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
700
diff
changeset
|
3268 // right, some protocol violation, |
f89882b07614
Fix a problem with PREPARE INSERT
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
700
diff
changeset
|
3269 // skip the rest of the result |
f89882b07614
Fix a problem with PREPARE INSERT
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
700
diff
changeset
|
3270 error = "M0M10!" + error; |
702
b4e968e5bd74
Some improvements.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
701
diff
changeset
|
3271 in.discardRemainder(error); |
284
e5b99c929a2d
Improve setSchema(String schema) by checking also on empty name.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
278
diff
changeset
|
3272 break; |
701
f89882b07614
Fix a problem with PREPARE INSERT
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
700
diff
changeset
|
3273 } |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
3274 |
288
f412032e3b43
Correcting typo
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
286
diff
changeset
|
3275 // it is of no use to store DataBlockResponses, you never want to |
284
e5b99c929a2d
Improve setSchema(String schema) by checking also on empty name.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
278
diff
changeset
|
3276 // retrieve them directly anyway |
e5b99c929a2d
Improve setSchema(String schema) by checking also on empty name.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
278
diff
changeset
|
3277 if (!(res instanceof DataBlockResponse)) |
e5b99c929a2d
Improve setSchema(String schema) by checking also on empty name.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
278
diff
changeset
|
3278 responses.add(res); |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
3279 |
701
f89882b07614
Fix a problem with PREPARE INSERT
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
700
diff
changeset
|
3280 // We have already advanced 'in' to the next line in the response |
f89882b07614
Fix a problem with PREPARE INSERT
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
700
diff
changeset
|
3281 // so we're ready to start the next iteration of the loop. |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
3282 break; |
497
aed7f32e029a
Refactor LineType to be an enum
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
496
diff
changeset
|
3283 case INFO: |
700
940e266eeccd
Refactor BufferedMCLReader
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
697
diff
changeset
|
3284 addWarning(in.getLine().substring(1), "01000"); |
284
e5b99c929a2d
Improve setSchema(String schema) by checking also on empty name.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
278
diff
changeset
|
3285 // read the next line (can be prompt, new result, error, etc.) |
e5b99c929a2d
Improve setSchema(String schema) by checking also on empty name.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
278
diff
changeset
|
3286 // before we start the loop over |
700
940e266eeccd
Refactor BufferedMCLReader
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
697
diff
changeset
|
3287 in.advance(); |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
3288 break; |
500
95d1b0a38aed
Stub implementation of FILETRANSFER handling
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
499
diff
changeset
|
3289 case FILETRANSFER: |
95d1b0a38aed
Stub implementation of FILETRANSFER handling
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
499
diff
changeset
|
3290 // Consume the command |
700
940e266eeccd
Refactor BufferedMCLReader
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
697
diff
changeset
|
3291 in.advance(); |
940e266eeccd
Refactor BufferedMCLReader
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
697
diff
changeset
|
3292 final String transferCommand = in.getLine(); |
500
95d1b0a38aed
Stub implementation of FILETRANSFER handling
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
499
diff
changeset
|
3293 // Consume the fake prompt inserted by MapiSocket. |
700
940e266eeccd
Refactor BufferedMCLReader
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
697
diff
changeset
|
3294 in.advance(); |
502
83354bd21320
Upload fake data when an upload request is received
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
500
diff
changeset
|
3295 // Handle the request |
540
d3a96675969e
Handle case where in.readLine() returns null
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
539
diff
changeset
|
3296 if (transferCommand != null) |
d3a96675969e
Handle case where in.readLine() returns null
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
539
diff
changeset
|
3297 error = handleTransfer(transferCommand); |
d3a96675969e
Handle case where in.readLine() returns null
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
539
diff
changeset
|
3298 else |
566
eeea18f501b3
Remove SQLStates from error messages sent upstream
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
563
diff
changeset
|
3299 error = "Protocol violation, expected transfer command, got nothing"; |
506
2ae90050720c
Improve flushing around error responses
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
505
diff
changeset
|
3300 // Then prepare for the next iteration |
502
83354bd21320
Upload fake data when an upload request is received
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
500
diff
changeset
|
3301 if (error != null) { |
566
eeea18f501b3
Remove SQLStates from error messages sent upstream
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
563
diff
changeset
|
3302 out.writeLine(error + "\n"); |
700
940e266eeccd
Refactor BufferedMCLReader
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
697
diff
changeset
|
3303 error = in.discardRemainder(); |
506
2ae90050720c
Improve flushing around error responses
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
505
diff
changeset
|
3304 } else { |
705
ba226d5d3996
Fix file transfers
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
703
diff
changeset
|
3305 in.resetLineType(); |
700
940e266eeccd
Refactor BufferedMCLReader
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
697
diff
changeset
|
3306 in.advance(); |
502
83354bd21320
Upload fake data when an upload request is received
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
500
diff
changeset
|
3307 } |
500
95d1b0a38aed
Stub implementation of FILETRANSFER handling
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
499
diff
changeset
|
3308 break; |
700
940e266eeccd
Refactor BufferedMCLReader
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
697
diff
changeset
|
3309 default: |
284
e5b99c929a2d
Improve setSchema(String schema) by checking also on empty name.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
278
diff
changeset
|
3310 // we have something we don't expect/understand, let's make it an error message |
700
940e266eeccd
Refactor BufferedMCLReader
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
697
diff
changeset
|
3311 String msg = "M0M10!protocol violation, unexpected " + in.getLineType() + " line: " + in.getLine(); |
940e266eeccd
Refactor BufferedMCLReader
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
697
diff
changeset
|
3312 error = in.discardRemainder(msg); |
940e266eeccd
Refactor BufferedMCLReader
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
697
diff
changeset
|
3313 break; |
497
aed7f32e029a
Refactor LineType to be an enum
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
496
diff
changeset
|
3314 case ERROR: |
284
e5b99c929a2d
Improve setSchema(String schema) by checking also on empty name.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
278
diff
changeset
|
3315 // read everything till the prompt (should be |
e5b99c929a2d
Improve setSchema(String schema) by checking also on empty name.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
278
diff
changeset
|
3316 // error) we don't know if we ignore some |
e5b99c929a2d
Improve setSchema(String schema) by checking also on empty name.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
278
diff
changeset
|
3317 // garbage here... but the log should reveal that |
700
940e266eeccd
Refactor BufferedMCLReader
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
697
diff
changeset
|
3318 error = in.discardRemainder(in.getLine().substring(1)); |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
3319 break; |
284
e5b99c929a2d
Improve setSchema(String schema) by checking also on empty name.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
278
diff
changeset
|
3320 } // end of switch (linetype) |
665
8f7d51c478df
Improved implementation of methods ResultSetMetaData.getPrecision() and ResultSetMetaData.getScale().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
660
diff
changeset
|
3321 } // end of while (linetype != LineType.PROMPT) |
284
e5b99c929a2d
Improve setSchema(String schema) by checking also on empty name.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
278
diff
changeset
|
3322 } // end of synchronized (server) |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
3323 |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
3324 if (error != null) { |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
3325 SQLException ret = null; |
295
003ae6d881db
Add "final" keyword to method arguments and local variables where possible.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
292
diff
changeset
|
3326 final String[] errors = error.split("\n"); |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
3327 for (int i = 0; i < errors.length; i++) { |
295
003ae6d881db
Add "final" keyword to method arguments and local variables where possible.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
292
diff
changeset
|
3328 final SQLException newErr; |
144
d6abd1ffffbb
Use SQLNonTransientConnectionException instead of SQLException where applicable (SQLState starts with 08)
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
136
diff
changeset
|
3329 if (errors[i].length() >= 6) { |
d6abd1ffffbb
Use SQLNonTransientConnectionException instead of SQLException where applicable (SQLState starts with 08)
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
136
diff
changeset
|
3330 newErr = new SQLException(errors[i].substring(6), errors[i].substring(0, 5)); |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
3331 } else { |
144
d6abd1ffffbb
Use SQLNonTransientConnectionException instead of SQLException where applicable (SQLState starts with 08)
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
136
diff
changeset
|
3332 newErr = new SQLNonTransientConnectionException(errors[i], "08000"); |
d6abd1ffffbb
Use SQLNonTransientConnectionException instead of SQLException where applicable (SQLState starts with 08)
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
136
diff
changeset
|
3333 } |
d6abd1ffffbb
Use SQLNonTransientConnectionException instead of SQLException where applicable (SQLState starts with 08)
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
136
diff
changeset
|
3334 if (ret == null) { |
d6abd1ffffbb
Use SQLNonTransientConnectionException instead of SQLException where applicable (SQLState starts with 08)
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
136
diff
changeset
|
3335 ret = newErr; |
d6abd1ffffbb
Use SQLNonTransientConnectionException instead of SQLException where applicable (SQLState starts with 08)
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
136
diff
changeset
|
3336 } else { |
d6abd1ffffbb
Use SQLNonTransientConnectionException instead of SQLException where applicable (SQLState starts with 08)
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
136
diff
changeset
|
3337 ret.setNextException(newErr); |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
3338 } |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
3339 } |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
3340 throw ret; |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
3341 } |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
3342 } catch (SocketTimeoutException e) { |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
3343 close(); // JDBC 4.1 semantics, abort() |
144
d6abd1ffffbb
Use SQLNonTransientConnectionException instead of SQLException where applicable (SQLState starts with 08)
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
136
diff
changeset
|
3344 throw new SQLNonTransientConnectionException("connection timed out", "08M33"); |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
3345 } catch (IOException e) { |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
3346 closed = true; |
144
d6abd1ffffbb
Use SQLNonTransientConnectionException instead of SQLException where applicable (SQLState starts with 08)
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
136
diff
changeset
|
3347 throw new SQLNonTransientConnectionException(e.getMessage() + " (mserver5 still alive?)", "08006"); |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
3348 } |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
3349 } |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
3350 } |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
3351 // }}} |
502
83354bd21320
Upload fake data when an upload request is received
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
500
diff
changeset
|
3352 |
576
095e896f9d7a
Updated comments. Improved code. Added final keywords
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
568
diff
changeset
|
3353 private String handleTransfer(final String transferCommand) throws IOException { |
553
50b15ee1cb5e
Process suggestions from Martin
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
552
diff
changeset
|
3354 if (transferCommand.startsWith("r ")) { |
576
095e896f9d7a
Updated comments. Improved code. Added final keywords
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
568
diff
changeset
|
3355 final String[] parts = transferCommand.split(" ", 3); |
553
50b15ee1cb5e
Process suggestions from Martin
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
552
diff
changeset
|
3356 if (parts.length == 3) { |
50b15ee1cb5e
Process suggestions from Martin
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
552
diff
changeset
|
3357 final long offset; |
50b15ee1cb5e
Process suggestions from Martin
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
552
diff
changeset
|
3358 try { |
50b15ee1cb5e
Process suggestions from Martin
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
552
diff
changeset
|
3359 offset = Long.parseLong(parts[1]); |
50b15ee1cb5e
Process suggestions from Martin
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
552
diff
changeset
|
3360 } catch (NumberFormatException e) { |
50b15ee1cb5e
Process suggestions from Martin
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
552
diff
changeset
|
3361 return e.toString(); |
50b15ee1cb5e
Process suggestions from Martin
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
552
diff
changeset
|
3362 } |
50b15ee1cb5e
Process suggestions from Martin
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
552
diff
changeset
|
3363 return handleUpload(parts[2], true, offset); |
502
83354bd21320
Upload fake data when an upload request is received
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
500
diff
changeset
|
3364 } |
503
7e3987c16cde
Succesful file uploading
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
502
diff
changeset
|
3365 } else if (transferCommand.startsWith("rb ")) { |
7e3987c16cde
Succesful file uploading
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
502
diff
changeset
|
3366 return handleUpload(transferCommand.substring(3), false, 0); |
505
8a014286dac2
Add stub code for downloading
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
504
diff
changeset
|
3367 } else if (transferCommand.startsWith("w ")) { |
616
65641a7cea31
Implement line ending conversion for downloads
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
613
diff
changeset
|
3368 return handleDownload(transferCommand.substring(2), true); |
65641a7cea31
Implement line ending conversion for downloads
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
613
diff
changeset
|
3369 } else if (transferCommand.startsWith("wb ")) { |
620
5ab170ddc66a
Some small improvements
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
617
diff
changeset
|
3370 return handleDownload(transferCommand.substring(3), false); |
502
83354bd21320
Upload fake data when an upload request is received
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
500
diff
changeset
|
3371 } |
553
50b15ee1cb5e
Process suggestions from Martin
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
552
diff
changeset
|
3372 return "JDBC does not support this file transfer yet: " + transferCommand; |
502
83354bd21320
Upload fake data when an upload request is received
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
500
diff
changeset
|
3373 } |
83354bd21320
Upload fake data when an upload request is received
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
500
diff
changeset
|
3374 |
576
095e896f9d7a
Updated comments. Improved code. Added final keywords
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
568
diff
changeset
|
3375 private String handleUpload(final String path, final boolean textMode, final long offset) throws IOException { |
535
c9d88af06d35
Javadoc and some minor changes
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
526
diff
changeset
|
3376 if (uploadHandler == null) { |
505
8a014286dac2
Add stub code for downloading
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
504
diff
changeset
|
3377 return "No file upload handler has been registered with the JDBC driver"; |
503
7e3987c16cde
Succesful file uploading
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
502
diff
changeset
|
3378 } |
7e3987c16cde
Succesful file uploading
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
502
diff
changeset
|
3379 |
576
095e896f9d7a
Updated comments. Improved code. Added final keywords
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
568
diff
changeset
|
3380 final long linesToSkip = offset >= 1 ? offset - 1 : 0; |
613
9397c0b487f8
Normalize CRLF on upload
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
610
diff
changeset
|
3381 final Upload handle = new Upload(server, uploadHandler::uploadCancelled, textMode); |
576
095e896f9d7a
Updated comments. Improved code. Added final keywords
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
568
diff
changeset
|
3382 final boolean wasFaking = server.setInsertFakePrompts(false); |
502
83354bd21320
Upload fake data when an upload request is received
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
500
diff
changeset
|
3383 try { |
551
5ce6a942aff3
Last minute API fix: 'int offset' -> 'long linesToSkip'
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
546
diff
changeset
|
3384 uploadHandler.handleUpload(handle, path, textMode, linesToSkip); |
503
7e3987c16cde
Succesful file uploading
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
502
diff
changeset
|
3385 if (!handle.hasBeenUsed()) { |
576
095e896f9d7a
Updated comments. Improved code. Added final keywords
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
568
diff
changeset
|
3386 throw new IOException("Call to " + uploadHandler.getClass().getCanonicalName() + ".handleUpload for path '" + path + "' sent neither data nor an error message"); |
502
83354bd21320
Upload fake data when an upload request is received
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
500
diff
changeset
|
3387 } |
620
5ab170ddc66a
Some small improvements
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
617
diff
changeset
|
3388 } finally { |
503
7e3987c16cde
Succesful file uploading
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
502
diff
changeset
|
3389 handle.close(); |
511
bd860e850fe1
rename insertFakeFlushes to insertFakePrompts
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
510
diff
changeset
|
3390 server.setInsertFakePrompts(wasFaking); |
502
83354bd21320
Upload fake data when an upload request is received
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
500
diff
changeset
|
3391 } |
503
7e3987c16cde
Succesful file uploading
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
502
diff
changeset
|
3392 return handle.getError(); |
502
83354bd21320
Upload fake data when an upload request is received
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
500
diff
changeset
|
3393 } |
83354bd21320
Upload fake data when an upload request is received
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
500
diff
changeset
|
3394 |
620
5ab170ddc66a
Some small improvements
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
617
diff
changeset
|
3395 private String handleDownload(final String path, final boolean textMode) throws IOException { |
535
c9d88af06d35
Javadoc and some minor changes
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
526
diff
changeset
|
3396 if (downloadHandler == null) { |
505
8a014286dac2
Add stub code for downloading
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
504
diff
changeset
|
3397 return "No file download handler has been registered with the JDBC driver"; |
8a014286dac2
Add stub code for downloading
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
504
diff
changeset
|
3398 } |
8a014286dac2
Add stub code for downloading
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
504
diff
changeset
|
3399 |
616
65641a7cea31
Implement line ending conversion for downloads
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
613
diff
changeset
|
3400 final Download handle = new Download(server, textMode); |
546
eb7ecfbb48f2
Never forget to close the download handle
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
542
diff
changeset
|
3401 try { |
eb7ecfbb48f2
Never forget to close the download handle
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
542
diff
changeset
|
3402 downloadHandler.handleDownload(handle, path, true); |
eb7ecfbb48f2
Never forget to close the download handle
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
542
diff
changeset
|
3403 if (!handle.hasBeenUsed()) { |
576
095e896f9d7a
Updated comments. Improved code. Added final keywords
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
568
diff
changeset
|
3404 handle.sendError("Call to " + downloadHandler.getClass().getSimpleName() + ".handleDownload sent neither data nor error"); |
546
eb7ecfbb48f2
Never forget to close the download handle
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
542
diff
changeset
|
3405 } |
eb7ecfbb48f2
Never forget to close the download handle
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
542
diff
changeset
|
3406 } finally { |
eb7ecfbb48f2
Never forget to close the download handle
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
542
diff
changeset
|
3407 handle.close(); |
505
8a014286dac2
Add stub code for downloading
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
504
diff
changeset
|
3408 } |
8a014286dac2
Add stub code for downloading
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
504
diff
changeset
|
3409 return handle.getError(); |
502
83354bd21320
Upload fake data when an upload request is received
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
500
diff
changeset
|
3410 } |
514
443780d71bae
More renaming. user registers MonetUploadHandler which is handed an Upload
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
511
diff
changeset
|
3411 |
535
c9d88af06d35
Javadoc and some minor changes
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
526
diff
changeset
|
3412 /** |
576
095e896f9d7a
Updated comments. Improved code. Added final keywords
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
568
diff
changeset
|
3413 * Callback for sending files for COPY INTO "table" FROM 'file-name' ON CLIENT commands |
541
31df6a12fd41
Make the MonetUploadHandler and MonetDownloadHandler interfaces part of MonetConnection
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
540
diff
changeset
|
3414 * |
31df6a12fd41
Make the MonetUploadHandler and MonetDownloadHandler interfaces part of MonetConnection
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
540
diff
changeset
|
3415 * To be registered with {@link MonetConnection#setUploadHandler(UploadHandler)} |
576
095e896f9d7a
Updated comments. Improved code. Added final keywords
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
568
diff
changeset
|
3416 * |
095e896f9d7a
Updated comments. Improved code. Added final keywords
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
568
diff
changeset
|
3417 * An example implementation can be found at ../util/FileTransferHandler.java |
541
31df6a12fd41
Make the MonetUploadHandler and MonetDownloadHandler interfaces part of MonetConnection
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
540
diff
changeset
|
3418 */ |
556
87feb93330a6
Misc. changes suggested by analysis tool
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
554
diff
changeset
|
3419 public interface UploadHandler { |
541
31df6a12fd41
Make the MonetUploadHandler and MonetDownloadHandler interfaces part of MonetConnection
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
540
diff
changeset
|
3420 /** |
542
d462000fc410
Various changes suggested by Martin van Dinther
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
541
diff
changeset
|
3421 * Called if the server sends a request to read file data. |
541
31df6a12fd41
Make the MonetUploadHandler and MonetDownloadHandler interfaces part of MonetConnection
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
540
diff
changeset
|
3422 * |
31df6a12fd41
Make the MonetUploadHandler and MonetDownloadHandler interfaces part of MonetConnection
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
540
diff
changeset
|
3423 * Use the given handle to receive data or send errors to the server. |
620
5ab170ddc66a
Some small improvements
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
617
diff
changeset
|
3424 * |
5ab170ddc66a
Some small improvements
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
617
diff
changeset
|
3425 * @param handle Handle to communicate with the server |
542
d462000fc410
Various changes suggested by Martin van Dinther
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
541
diff
changeset
|
3426 * @param name Name of the file the server would like to read. Make sure |
d462000fc410
Various changes suggested by Martin van Dinther
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
541
diff
changeset
|
3427 * to validate this before reading from the file system |
559
7f10d662a788
fixup doc comment fixes
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
557
diff
changeset
|
3428 * @param textMode Whether to open the file as text or binary data. |
551
5ce6a942aff3
Last minute API fix: 'int offset' -> 'long linesToSkip'
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
546
diff
changeset
|
3429 * @param linesToSkip In text mode, number of initial lines to skip. |
5ce6a942aff3
Last minute API fix: 'int offset' -> 'long linesToSkip'
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
546
diff
changeset
|
3430 * 0 means upload everything, 1 means skip the first line, etc. |
5ce6a942aff3
Last minute API fix: 'int offset' -> 'long linesToSkip'
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
546
diff
changeset
|
3431 * Note: this is different from the OFFSET option of the COPY INTO, |
5ce6a942aff3
Last minute API fix: 'int offset' -> 'long linesToSkip'
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
546
diff
changeset
|
3432 * where both 0 and 1 mean 'upload everything' |
626
06d69b82d409
Resolve javadoc error and warnings :
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
623
diff
changeset
|
3433 * @throws IOException when I/O problem occurs |
541
31df6a12fd41
Make the MonetUploadHandler and MonetDownloadHandler interfaces part of MonetConnection
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
540
diff
changeset
|
3434 */ |
551
5ce6a942aff3
Last minute API fix: 'int offset' -> 'long linesToSkip'
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
546
diff
changeset
|
3435 void handleUpload(Upload handle, String name, boolean textMode, long linesToSkip) throws IOException; |
557
ce2b616ed22e
Add a cancellation callback to UploadHandler
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
556
diff
changeset
|
3436 |
ce2b616ed22e
Add a cancellation callback to UploadHandler
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
556
diff
changeset
|
3437 /** |
ce2b616ed22e
Add a cancellation callback to UploadHandler
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
556
diff
changeset
|
3438 * Called when the upload is cancelled halfway by the server. |
ce2b616ed22e
Add a cancellation callback to UploadHandler
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
556
diff
changeset
|
3439 * |
ce2b616ed22e
Add a cancellation callback to UploadHandler
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
556
diff
changeset
|
3440 * The default implementation does nothing. |
ce2b616ed22e
Add a cancellation callback to UploadHandler
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
556
diff
changeset
|
3441 */ |
ce2b616ed22e
Add a cancellation callback to UploadHandler
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
556
diff
changeset
|
3442 default void uploadCancelled() {} |
541
31df6a12fd41
Make the MonetUploadHandler and MonetDownloadHandler interfaces part of MonetConnection
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
540
diff
changeset
|
3443 } |
31df6a12fd41
Make the MonetUploadHandler and MonetDownloadHandler interfaces part of MonetConnection
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
540
diff
changeset
|
3444 |
31df6a12fd41
Make the MonetUploadHandler and MonetDownloadHandler interfaces part of MonetConnection
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
540
diff
changeset
|
3445 /** |
576
095e896f9d7a
Updated comments. Improved code. Added final keywords
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
568
diff
changeset
|
3446 * Callback for receiving files from COPY .. INTO 'file-name' ON CLIENT commands |
541
31df6a12fd41
Make the MonetUploadHandler and MonetDownloadHandler interfaces part of MonetConnection
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
540
diff
changeset
|
3447 * |
31df6a12fd41
Make the MonetUploadHandler and MonetDownloadHandler interfaces part of MonetConnection
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
540
diff
changeset
|
3448 * To be registered with {@link MonetConnection#setDownloadHandler(DownloadHandler)} |
576
095e896f9d7a
Updated comments. Improved code. Added final keywords
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
568
diff
changeset
|
3449 * |
095e896f9d7a
Updated comments. Improved code. Added final keywords
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
568
diff
changeset
|
3450 * An example implementation can be found at ../util/FileTransferHandler.java |
541
31df6a12fd41
Make the MonetUploadHandler and MonetDownloadHandler interfaces part of MonetConnection
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
540
diff
changeset
|
3451 */ |
556
87feb93330a6
Misc. changes suggested by analysis tool
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
554
diff
changeset
|
3452 public interface DownloadHandler { |
541
31df6a12fd41
Make the MonetUploadHandler and MonetDownloadHandler interfaces part of MonetConnection
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
540
diff
changeset
|
3453 /** |
31df6a12fd41
Make the MonetUploadHandler and MonetDownloadHandler interfaces part of MonetConnection
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
540
diff
changeset
|
3454 * Called if the server sends a request to write a file. |
31df6a12fd41
Make the MonetUploadHandler and MonetDownloadHandler interfaces part of MonetConnection
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
540
diff
changeset
|
3455 * |
31df6a12fd41
Make the MonetUploadHandler and MonetDownloadHandler interfaces part of MonetConnection
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
540
diff
changeset
|
3456 * Use the given handle to send data or errors to the server. |
31df6a12fd41
Make the MonetUploadHandler and MonetDownloadHandler interfaces part of MonetConnection
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
540
diff
changeset
|
3457 * |
31df6a12fd41
Make the MonetUploadHandler and MonetDownloadHandler interfaces part of MonetConnection
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
540
diff
changeset
|
3458 * @param handle Handle to communicate with the server |
620
5ab170ddc66a
Some small improvements
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
617
diff
changeset
|
3459 * @param name Name of the file the server would like to write. Make sure |
5ab170ddc66a
Some small improvements
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
617
diff
changeset
|
3460 * to validate this before writing to the file system |
541
31df6a12fd41
Make the MonetUploadHandler and MonetDownloadHandler interfaces part of MonetConnection
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
540
diff
changeset
|
3461 * @param textMode Whether this is text or binary data. |
626
06d69b82d409
Resolve javadoc error and warnings :
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
623
diff
changeset
|
3462 * @throws IOException when I/O problem occurs |
541
31df6a12fd41
Make the MonetUploadHandler and MonetDownloadHandler interfaces part of MonetConnection
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
540
diff
changeset
|
3463 */ |
31df6a12fd41
Make the MonetUploadHandler and MonetDownloadHandler interfaces part of MonetConnection
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
540
diff
changeset
|
3464 void handleDownload(Download handle, String name, boolean textMode) throws IOException; |
31df6a12fd41
Make the MonetUploadHandler and MonetDownloadHandler interfaces part of MonetConnection
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
540
diff
changeset
|
3465 } |
31df6a12fd41
Make the MonetUploadHandler and MonetDownloadHandler interfaces part of MonetConnection
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
540
diff
changeset
|
3466 |
31df6a12fd41
Make the MonetUploadHandler and MonetDownloadHandler interfaces part of MonetConnection
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
540
diff
changeset
|
3467 /** |
31df6a12fd41
Make the MonetUploadHandler and MonetDownloadHandler interfaces part of MonetConnection
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
540
diff
changeset
|
3468 * Handle passed to {@link UploadHandler} to allow communication with the server |
535
c9d88af06d35
Javadoc and some minor changes
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
526
diff
changeset
|
3469 */ |
514
443780d71bae
More renaming. user registers MonetUploadHandler which is handed an Upload
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
511
diff
changeset
|
3470 public static class Upload { |
443780d71bae
More renaming. user registers MonetUploadHandler which is handed an Upload
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
511
diff
changeset
|
3471 private final MapiSocket server; |
557
ce2b616ed22e
Add a cancellation callback to UploadHandler
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
556
diff
changeset
|
3472 private final Runnable cancellationCallback; |
613
9397c0b487f8
Normalize CRLF on upload
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
610
diff
changeset
|
3473 private final boolean textMode; |
514
443780d71bae
More renaming. user registers MonetUploadHandler which is handed an Upload
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
511
diff
changeset
|
3474 private PrintStream print = null; |
443780d71bae
More renaming. user registers MonetUploadHandler which is handed an Upload
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
511
diff
changeset
|
3475 private String error = null; |
521
72007c4f8f8a
Allow MonetUploadHandler to configure the chunk size
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
516
diff
changeset
|
3476 private int customChunkSize = -1; |
514
443780d71bae
More renaming. user registers MonetUploadHandler which is handed an Upload
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
511
diff
changeset
|
3477 |
613
9397c0b487f8
Normalize CRLF on upload
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
610
diff
changeset
|
3478 Upload(MapiSocket server, Runnable cancellationCallback, boolean textMode) { |
514
443780d71bae
More renaming. user registers MonetUploadHandler which is handed an Upload
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
511
diff
changeset
|
3479 this.server = server; |
557
ce2b616ed22e
Add a cancellation callback to UploadHandler
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
556
diff
changeset
|
3480 this.cancellationCallback = cancellationCallback; |
613
9397c0b487f8
Normalize CRLF on upload
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
610
diff
changeset
|
3481 this.textMode = textMode; |
514
443780d71bae
More renaming. user registers MonetUploadHandler which is handed an Upload
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
511
diff
changeset
|
3482 } |
443780d71bae
More renaming. user registers MonetUploadHandler which is handed an Upload
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
511
diff
changeset
|
3483 |
535
c9d88af06d35
Javadoc and some minor changes
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
526
diff
changeset
|
3484 /** |
c9d88af06d35
Javadoc and some minor changes
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
526
diff
changeset
|
3485 * Send an error message to the server |
c9d88af06d35
Javadoc and some minor changes
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
526
diff
changeset
|
3486 * |
c9d88af06d35
Javadoc and some minor changes
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
526
diff
changeset
|
3487 * The server will generally let the currently executing statement fail |
562
c640075da7c9
only comment improvements
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
559
diff
changeset
|
3488 * with this error message. The connection will remain usable. |
535
c9d88af06d35
Javadoc and some minor changes
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
526
diff
changeset
|
3489 * |
c9d88af06d35
Javadoc and some minor changes
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
526
diff
changeset
|
3490 * This method can only be sent if no data has been sent to the server |
c9d88af06d35
Javadoc and some minor changes
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
526
diff
changeset
|
3491 * yet. After data has been sent, you can still throw an |
c9d88af06d35
Javadoc and some minor changes
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
526
diff
changeset
|
3492 * {@link IOException} but this will terminate the connection. |
626
06d69b82d409
Resolve javadoc error and warnings :
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
623
diff
changeset
|
3493 * |
06d69b82d409
Resolve javadoc error and warnings :
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
623
diff
changeset
|
3494 * @param errorMessage the error message to send |
06d69b82d409
Resolve javadoc error and warnings :
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
623
diff
changeset
|
3495 * @throws IOException when error message is null |
535
c9d88af06d35
Javadoc and some minor changes
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
526
diff
changeset
|
3496 */ |
576
095e896f9d7a
Updated comments. Improved code. Added final keywords
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
568
diff
changeset
|
3497 public void sendError(final String errorMessage) throws IOException { |
514
443780d71bae
More renaming. user registers MonetUploadHandler which is handed an Upload
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
511
diff
changeset
|
3498 if (error != null) { |
443780d71bae
More renaming. user registers MonetUploadHandler which is handed an Upload
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
511
diff
changeset
|
3499 throw new IOException("another error has already been sent: " + error); |
443780d71bae
More renaming. user registers MonetUploadHandler which is handed an Upload
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
511
diff
changeset
|
3500 } |
443780d71bae
More renaming. user registers MonetUploadHandler which is handed an Upload
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
511
diff
changeset
|
3501 error = errorMessage; |
443780d71bae
More renaming. user registers MonetUploadHandler which is handed an Upload
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
511
diff
changeset
|
3502 } |
443780d71bae
More renaming. user registers MonetUploadHandler which is handed an Upload
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
511
diff
changeset
|
3503 |
535
c9d88af06d35
Javadoc and some minor changes
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
526
diff
changeset
|
3504 /** |
c9d88af06d35
Javadoc and some minor changes
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
526
diff
changeset
|
3505 * After every {@code chunkSize} bytes, the server gets the opportunity to |
c9d88af06d35
Javadoc and some minor changes
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
526
diff
changeset
|
3506 * terminate the upload. |
626
06d69b82d409
Resolve javadoc error and warnings :
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
623
diff
changeset
|
3507 * |
06d69b82d409
Resolve javadoc error and warnings :
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
623
diff
changeset
|
3508 * @param chunkSize size of chunk |
535
c9d88af06d35
Javadoc and some minor changes
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
526
diff
changeset
|
3509 */ |
576
095e896f9d7a
Updated comments. Improved code. Added final keywords
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
568
diff
changeset
|
3510 public void setChunkSize(final int chunkSize) { |
521
72007c4f8f8a
Allow MonetUploadHandler to configure the chunk size
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
516
diff
changeset
|
3511 this.customChunkSize = chunkSize; |
72007c4f8f8a
Allow MonetUploadHandler to configure the chunk size
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
516
diff
changeset
|
3512 } |
72007c4f8f8a
Allow MonetUploadHandler to configure the chunk size
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
516
diff
changeset
|
3513 |
535
c9d88af06d35
Javadoc and some minor changes
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
526
diff
changeset
|
3514 /** |
c9d88af06d35
Javadoc and some minor changes
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
526
diff
changeset
|
3515 * Get a {@link PrintStream} to write data to. |
c9d88af06d35
Javadoc and some minor changes
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
526
diff
changeset
|
3516 * |
c9d88af06d35
Javadoc and some minor changes
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
526
diff
changeset
|
3517 * For text mode uploads, the data MUST be validly UTF-8 encoded. |
626
06d69b82d409
Resolve javadoc error and warnings :
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
623
diff
changeset
|
3518 * |
06d69b82d409
Resolve javadoc error and warnings :
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
623
diff
changeset
|
3519 * @return PrintStream a PrintStream |
06d69b82d409
Resolve javadoc error and warnings :
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
623
diff
changeset
|
3520 * @throws IOException when error message is null or I/O problem occurs |
535
c9d88af06d35
Javadoc and some minor changes
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
526
diff
changeset
|
3521 */ |
514
443780d71bae
More renaming. user registers MonetUploadHandler which is handed an Upload
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
511
diff
changeset
|
3522 public PrintStream getStream() throws IOException { |
443780d71bae
More renaming. user registers MonetUploadHandler which is handed an Upload
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
511
diff
changeset
|
3523 if (error != null) { |
443780d71bae
More renaming. user registers MonetUploadHandler which is handed an Upload
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
511
diff
changeset
|
3524 throw new IOException("Cannot send data after an error has been sent"); |
443780d71bae
More renaming. user registers MonetUploadHandler which is handed an Upload
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
511
diff
changeset
|
3525 } |
443780d71bae
More renaming. user registers MonetUploadHandler which is handed an Upload
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
511
diff
changeset
|
3526 if (print == null) { |
443780d71bae
More renaming. user registers MonetUploadHandler which is handed an Upload
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
511
diff
changeset
|
3527 try { |
576
095e896f9d7a
Updated comments. Improved code. Added final keywords
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
568
diff
changeset
|
3528 final MapiSocket.UploadStream up = customChunkSize >= 0 ? server.uploadStream(customChunkSize) : server.uploadStream(); |
557
ce2b616ed22e
Add a cancellation callback to UploadHandler
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
556
diff
changeset
|
3529 up.setCancellationCallback(cancellationCallback); |
613
9397c0b487f8
Normalize CRLF on upload
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
610
diff
changeset
|
3530 print = new PrintStream(textMode ? new StripCrLfStream(up) : up, false, "UTF-8"); |
514
443780d71bae
More renaming. user registers MonetUploadHandler which is handed an Upload
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
511
diff
changeset
|
3531 up.write('\n'); |
443780d71bae
More renaming. user registers MonetUploadHandler which is handed an Upload
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
511
diff
changeset
|
3532 } catch (UnsupportedEncodingException e) { |
443780d71bae
More renaming. user registers MonetUploadHandler which is handed an Upload
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
511
diff
changeset
|
3533 throw new RuntimeException("The system is guaranteed to support the UTF-8 encoding but apparently it doesn't", e); |
443780d71bae
More renaming. user registers MonetUploadHandler which is handed an Upload
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
511
diff
changeset
|
3534 } |
443780d71bae
More renaming. user registers MonetUploadHandler which is handed an Upload
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
511
diff
changeset
|
3535 } |
443780d71bae
More renaming. user registers MonetUploadHandler which is handed an Upload
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
511
diff
changeset
|
3536 return print; |
443780d71bae
More renaming. user registers MonetUploadHandler which is handed an Upload
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
511
diff
changeset
|
3537 } |
443780d71bae
More renaming. user registers MonetUploadHandler which is handed an Upload
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
511
diff
changeset
|
3538 |
535
c9d88af06d35
Javadoc and some minor changes
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
526
diff
changeset
|
3539 /** |
709
bdeabbd46ec6
Resolve javac and javadoc warnings when compiled with JDK19.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
708
diff
changeset
|
3540 * Tell whether data or an error has been sent. |
554
9fa67487f38a
Doc comment fixes
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
553
diff
changeset
|
3541 * @return true if data or an error has been sent. |
535
c9d88af06d35
Javadoc and some minor changes
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
526
diff
changeset
|
3542 */ |
514
443780d71bae
More renaming. user registers MonetUploadHandler which is handed an Upload
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
511
diff
changeset
|
3543 public boolean hasBeenUsed() { |
443780d71bae
More renaming. user registers MonetUploadHandler which is handed an Upload
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
511
diff
changeset
|
3544 return print != null || error != null; |
443780d71bae
More renaming. user registers MonetUploadHandler which is handed an Upload
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
511
diff
changeset
|
3545 } |
443780d71bae
More renaming. user registers MonetUploadHandler which is handed an Upload
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
511
diff
changeset
|
3546 |
535
c9d88af06d35
Javadoc and some minor changes
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
526
diff
changeset
|
3547 /** |
709
bdeabbd46ec6
Resolve javac and javadoc warnings when compiled with JDK19.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
708
diff
changeset
|
3548 * Get the error string. |
554
9fa67487f38a
Doc comment fixes
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
553
diff
changeset
|
3549 * @return the error that was sent, if any |
535
c9d88af06d35
Javadoc and some minor changes
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
526
diff
changeset
|
3550 */ |
514
443780d71bae
More renaming. user registers MonetUploadHandler which is handed an Upload
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
511
diff
changeset
|
3551 public String getError() { |
443780d71bae
More renaming. user registers MonetUploadHandler which is handed an Upload
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
511
diff
changeset
|
3552 return error; |
443780d71bae
More renaming. user registers MonetUploadHandler which is handed an Upload
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
511
diff
changeset
|
3553 } |
443780d71bae
More renaming. user registers MonetUploadHandler which is handed an Upload
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
511
diff
changeset
|
3554 |
535
c9d88af06d35
Javadoc and some minor changes
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
526
diff
changeset
|
3555 /** |
c9d88af06d35
Javadoc and some minor changes
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
526
diff
changeset
|
3556 * Read from the given input stream and write it to the server. |
562
c640075da7c9
only comment improvements
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
559
diff
changeset
|
3557 * |
535
c9d88af06d35
Javadoc and some minor changes
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
526
diff
changeset
|
3558 * For text mode uploads, the data MUST be validly UTF-8 encoded. |
626
06d69b82d409
Resolve javadoc error and warnings :
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
623
diff
changeset
|
3559 * |
06d69b82d409
Resolve javadoc error and warnings :
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
623
diff
changeset
|
3560 * @param inputStream stream to read from |
06d69b82d409
Resolve javadoc error and warnings :
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
623
diff
changeset
|
3561 * @throws IOException when I/O problem occurs |
535
c9d88af06d35
Javadoc and some minor changes
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
526
diff
changeset
|
3562 */ |
576
095e896f9d7a
Updated comments. Improved code. Added final keywords
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
568
diff
changeset
|
3563 public void uploadFrom(final InputStream inputStream) throws IOException { |
095e896f9d7a
Updated comments. Improved code. Added final keywords
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
568
diff
changeset
|
3564 final OutputStream s = getStream(); |
095e896f9d7a
Updated comments. Improved code. Added final keywords
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
568
diff
changeset
|
3565 final byte[] buffer = new byte[64 * 1024]; |
514
443780d71bae
More renaming. user registers MonetUploadHandler which is handed an Upload
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
511
diff
changeset
|
3566 while (true) { |
443780d71bae
More renaming. user registers MonetUploadHandler which is handed an Upload
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
511
diff
changeset
|
3567 int nread = inputStream.read(buffer); |
443780d71bae
More renaming. user registers MonetUploadHandler which is handed an Upload
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
511
diff
changeset
|
3568 if (nread < 0) { |
443780d71bae
More renaming. user registers MonetUploadHandler which is handed an Upload
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
511
diff
changeset
|
3569 break; |
443780d71bae
More renaming. user registers MonetUploadHandler which is handed an Upload
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
511
diff
changeset
|
3570 } |
443780d71bae
More renaming. user registers MonetUploadHandler which is handed an Upload
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
511
diff
changeset
|
3571 s.write(buffer, 0, nread); |
443780d71bae
More renaming. user registers MonetUploadHandler which is handed an Upload
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
511
diff
changeset
|
3572 } |
443780d71bae
More renaming. user registers MonetUploadHandler which is handed an Upload
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
511
diff
changeset
|
3573 } |
443780d71bae
More renaming. user registers MonetUploadHandler which is handed an Upload
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
511
diff
changeset
|
3574 |
535
c9d88af06d35
Javadoc and some minor changes
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
526
diff
changeset
|
3575 /** |
c9d88af06d35
Javadoc and some minor changes
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
526
diff
changeset
|
3576 * Read data from the given buffered reader and send it to the server |
626
06d69b82d409
Resolve javadoc error and warnings :
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
623
diff
changeset
|
3577 * |
06d69b82d409
Resolve javadoc error and warnings :
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
623
diff
changeset
|
3578 * @param reader buffered reader to read from |
551
5ce6a942aff3
Last minute API fix: 'int offset' -> 'long linesToSkip'
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
546
diff
changeset
|
3579 * @param linesToSkip start uploading at line {@code offset}. Value 0 and 1 |
620
5ab170ddc66a
Some small improvements
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
617
diff
changeset
|
3580 * both mean upload the whole file, value 2 means skip the first line, etc. |
626
06d69b82d409
Resolve javadoc error and warnings :
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
623
diff
changeset
|
3581 * @throws IOException when I/O problem occurs |
535
c9d88af06d35
Javadoc and some minor changes
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
526
diff
changeset
|
3582 */ |
576
095e896f9d7a
Updated comments. Improved code. Added final keywords
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
568
diff
changeset
|
3583 public void uploadFrom(final BufferedReader reader, final long linesToSkip) throws IOException { |
551
5ce6a942aff3
Last minute API fix: 'int offset' -> 'long linesToSkip'
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
546
diff
changeset
|
3584 for (int i = 0; i < linesToSkip; i++) { |
514
443780d71bae
More renaming. user registers MonetUploadHandler which is handed an Upload
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
511
diff
changeset
|
3585 String line = reader.readLine(); |
443780d71bae
More renaming. user registers MonetUploadHandler which is handed an Upload
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
511
diff
changeset
|
3586 if (line == null) { |
443780d71bae
More renaming. user registers MonetUploadHandler which is handed an Upload
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
511
diff
changeset
|
3587 return; |
443780d71bae
More renaming. user registers MonetUploadHandler which is handed an Upload
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
511
diff
changeset
|
3588 } |
443780d71bae
More renaming. user registers MonetUploadHandler which is handed an Upload
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
511
diff
changeset
|
3589 } |
443780d71bae
More renaming. user registers MonetUploadHandler which is handed an Upload
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
511
diff
changeset
|
3590 |
443780d71bae
More renaming. user registers MonetUploadHandler which is handed an Upload
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
511
diff
changeset
|
3591 uploadFrom(reader); |
443780d71bae
More renaming. user registers MonetUploadHandler which is handed an Upload
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
511
diff
changeset
|
3592 } |
443780d71bae
More renaming. user registers MonetUploadHandler which is handed an Upload
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
511
diff
changeset
|
3593 |
535
c9d88af06d35
Javadoc and some minor changes
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
526
diff
changeset
|
3594 /** |
c9d88af06d35
Javadoc and some minor changes
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
526
diff
changeset
|
3595 * Read data from the given buffered reader and send it to the server |
626
06d69b82d409
Resolve javadoc error and warnings :
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
623
diff
changeset
|
3596 * |
535
c9d88af06d35
Javadoc and some minor changes
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
526
diff
changeset
|
3597 * @param reader reader to read from |
626
06d69b82d409
Resolve javadoc error and warnings :
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
623
diff
changeset
|
3598 * @throws IOException when ... |
535
c9d88af06d35
Javadoc and some minor changes
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
526
diff
changeset
|
3599 */ |
576
095e896f9d7a
Updated comments. Improved code. Added final keywords
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
568
diff
changeset
|
3600 public void uploadFrom(final Reader reader) throws IOException { |
095e896f9d7a
Updated comments. Improved code. Added final keywords
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
568
diff
changeset
|
3601 final OutputStream s = getStream(); |
095e896f9d7a
Updated comments. Improved code. Added final keywords
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
568
diff
changeset
|
3602 final OutputStreamWriter writer = new OutputStreamWriter(s, StandardCharsets.UTF_8); |
095e896f9d7a
Updated comments. Improved code. Added final keywords
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
568
diff
changeset
|
3603 final char[] buffer = new char[64 * 1024]; |
514
443780d71bae
More renaming. user registers MonetUploadHandler which is handed an Upload
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
511
diff
changeset
|
3604 while (true) { |
443780d71bae
More renaming. user registers MonetUploadHandler which is handed an Upload
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
511
diff
changeset
|
3605 int nread = reader.read(buffer, 0, buffer.length); |
443780d71bae
More renaming. user registers MonetUploadHandler which is handed an Upload
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
511
diff
changeset
|
3606 if (nread < 0) { |
443780d71bae
More renaming. user registers MonetUploadHandler which is handed an Upload
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
511
diff
changeset
|
3607 break; |
443780d71bae
More renaming. user registers MonetUploadHandler which is handed an Upload
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
511
diff
changeset
|
3608 } |
443780d71bae
More renaming. user registers MonetUploadHandler which is handed an Upload
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
511
diff
changeset
|
3609 writer.write(buffer, 0, nread); |
443780d71bae
More renaming. user registers MonetUploadHandler which is handed an Upload
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
511
diff
changeset
|
3610 } |
617
15eb17b911a5
Only close the writer after the loop has finished
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
616
diff
changeset
|
3611 writer.close(); |
514
443780d71bae
More renaming. user registers MonetUploadHandler which is handed an Upload
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
511
diff
changeset
|
3612 } |
443780d71bae
More renaming. user registers MonetUploadHandler which is handed an Upload
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
511
diff
changeset
|
3613 |
576
095e896f9d7a
Updated comments. Improved code. Added final keywords
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
568
diff
changeset
|
3614 /** |
095e896f9d7a
Updated comments. Improved code. Added final keywords
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
568
diff
changeset
|
3615 * Close opened {@link PrintStream}. |
095e896f9d7a
Updated comments. Improved code. Added final keywords
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
568
diff
changeset
|
3616 */ |
514
443780d71bae
More renaming. user registers MonetUploadHandler which is handed an Upload
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
511
diff
changeset
|
3617 public void close() { |
443780d71bae
More renaming. user registers MonetUploadHandler which is handed an Upload
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
511
diff
changeset
|
3618 if (print != null) { |
443780d71bae
More renaming. user registers MonetUploadHandler which is handed an Upload
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
511
diff
changeset
|
3619 print.close(); |
576
095e896f9d7a
Updated comments. Improved code. Added final keywords
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
568
diff
changeset
|
3620 print = null; |
514
443780d71bae
More renaming. user registers MonetUploadHandler which is handed an Upload
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
511
diff
changeset
|
3621 } |
443780d71bae
More renaming. user registers MonetUploadHandler which is handed an Upload
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
511
diff
changeset
|
3622 } |
443780d71bae
More renaming. user registers MonetUploadHandler which is handed an Upload
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
511
diff
changeset
|
3623 } |
443780d71bae
More renaming. user registers MonetUploadHandler which is handed an Upload
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
511
diff
changeset
|
3624 |
535
c9d88af06d35
Javadoc and some minor changes
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
526
diff
changeset
|
3625 /** |
541
31df6a12fd41
Make the MonetUploadHandler and MonetDownloadHandler interfaces part of MonetConnection
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
540
diff
changeset
|
3626 * Handle passed to {@link DownloadHandler} to allow communication with the server |
535
c9d88af06d35
Javadoc and some minor changes
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
526
diff
changeset
|
3627 */ |
514
443780d71bae
More renaming. user registers MonetUploadHandler which is handed an Upload
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
511
diff
changeset
|
3628 public static class Download { |
443780d71bae
More renaming. user registers MonetUploadHandler which is handed an Upload
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
511
diff
changeset
|
3629 private final MapiSocket server; |
616
65641a7cea31
Implement line ending conversion for downloads
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
613
diff
changeset
|
3630 private boolean prependCr; |
514
443780d71bae
More renaming. user registers MonetUploadHandler which is handed an Upload
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
511
diff
changeset
|
3631 private MapiSocket.DownloadStream stream = null; |
443780d71bae
More renaming. user registers MonetUploadHandler which is handed an Upload
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
511
diff
changeset
|
3632 private String error = null; |
443780d71bae
More renaming. user registers MonetUploadHandler which is handed an Upload
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
511
diff
changeset
|
3633 |
616
65641a7cea31
Implement line ending conversion for downloads
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
613
diff
changeset
|
3634 Download(MapiSocket server, boolean textMode) { |
514
443780d71bae
More renaming. user registers MonetUploadHandler which is handed an Upload
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
511
diff
changeset
|
3635 this.server = server; |
616
65641a7cea31
Implement line ending conversion for downloads
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
613
diff
changeset
|
3636 prependCr = false; |
65641a7cea31
Implement line ending conversion for downloads
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
613
diff
changeset
|
3637 if (textMode) { |
65641a7cea31
Implement line ending conversion for downloads
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
613
diff
changeset
|
3638 setLineSeparator(System.lineSeparator()); |
65641a7cea31
Implement line ending conversion for downloads
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
613
diff
changeset
|
3639 } |
514
443780d71bae
More renaming. user registers MonetUploadHandler which is handed an Upload
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
511
diff
changeset
|
3640 } |
443780d71bae
More renaming. user registers MonetUploadHandler which is handed an Upload
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
511
diff
changeset
|
3641 |
535
c9d88af06d35
Javadoc and some minor changes
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
526
diff
changeset
|
3642 /** |
c9d88af06d35
Javadoc and some minor changes
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
526
diff
changeset
|
3643 * Send an error message to the server |
c9d88af06d35
Javadoc and some minor changes
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
526
diff
changeset
|
3644 * |
c9d88af06d35
Javadoc and some minor changes
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
526
diff
changeset
|
3645 * The server will generally let the currently executing statement fail |
c9d88af06d35
Javadoc and some minor changes
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
526
diff
changeset
|
3646 * with this error message. The connection will remain usable. |
c9d88af06d35
Javadoc and some minor changes
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
526
diff
changeset
|
3647 * |
c9d88af06d35
Javadoc and some minor changes
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
526
diff
changeset
|
3648 * This method can only be sent if no data has been received from the server |
c9d88af06d35
Javadoc and some minor changes
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
526
diff
changeset
|
3649 * yet. After data has been received, you can still throw an |
c9d88af06d35
Javadoc and some minor changes
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
526
diff
changeset
|
3650 * {@link IOException} but this will terminate the connection. |
562
c640075da7c9
only comment improvements
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
559
diff
changeset
|
3651 * |
535
c9d88af06d35
Javadoc and some minor changes
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
526
diff
changeset
|
3652 * Note: as of MonetDB version Jul2021 the server always terminates the connection |
c9d88af06d35
Javadoc and some minor changes
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
526
diff
changeset
|
3653 * when this error is used. This will probably change in the future. |
626
06d69b82d409
Resolve javadoc error and warnings :
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
623
diff
changeset
|
3654 * |
06d69b82d409
Resolve javadoc error and warnings :
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
623
diff
changeset
|
3655 * @param errorMessage the error message to send |
06d69b82d409
Resolve javadoc error and warnings :
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
623
diff
changeset
|
3656 * @throws IOException when error message is null |
535
c9d88af06d35
Javadoc and some minor changes
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
526
diff
changeset
|
3657 */ |
620
5ab170ddc66a
Some small improvements
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
617
diff
changeset
|
3658 public void sendError(final String errorMessage) throws IOException { |
514
443780d71bae
More renaming. user registers MonetUploadHandler which is handed an Upload
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
511
diff
changeset
|
3659 if (error != null) { |
443780d71bae
More renaming. user registers MonetUploadHandler which is handed an Upload
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
511
diff
changeset
|
3660 throw new IOException("another error has already been sent: " + error); |
443780d71bae
More renaming. user registers MonetUploadHandler which is handed an Upload
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
511
diff
changeset
|
3661 } |
443780d71bae
More renaming. user registers MonetUploadHandler which is handed an Upload
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
511
diff
changeset
|
3662 error = errorMessage; |
443780d71bae
More renaming. user registers MonetUploadHandler which is handed an Upload
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
511
diff
changeset
|
3663 } |
443780d71bae
More renaming. user registers MonetUploadHandler which is handed an Upload
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
511
diff
changeset
|
3664 |
535
c9d88af06d35
Javadoc and some minor changes
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
526
diff
changeset
|
3665 /** |
c9d88af06d35
Javadoc and some minor changes
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
526
diff
changeset
|
3666 * Get an {@link InputStream} to read data from. |
562
c640075da7c9
only comment improvements
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
559
diff
changeset
|
3667 * |
616
65641a7cea31
Implement line ending conversion for downloads
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
613
diff
changeset
|
3668 * Textual data is UTF-8 encoded. If the download is in text mode, line endings |
65641a7cea31
Implement line ending conversion for downloads
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
613
diff
changeset
|
3669 * are converted according to {@link java.lang.System#lineSeparator()}. |
65641a7cea31
Implement line ending conversion for downloads
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
613
diff
changeset
|
3670 * This can be overridden with {@link Download#setLineSeparator(String)}. |
626
06d69b82d409
Resolve javadoc error and warnings :
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
623
diff
changeset
|
3671 * |
06d69b82d409
Resolve javadoc error and warnings :
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
623
diff
changeset
|
3672 * @return InputStream the stream to read from |
06d69b82d409
Resolve javadoc error and warnings :
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
623
diff
changeset
|
3673 * @throws IOException when error message exist or I/O problem occurs |
535
c9d88af06d35
Javadoc and some minor changes
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
526
diff
changeset
|
3674 */ |
514
443780d71bae
More renaming. user registers MonetUploadHandler which is handed an Upload
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
511
diff
changeset
|
3675 public InputStream getStream() throws IOException { |
443780d71bae
More renaming. user registers MonetUploadHandler which is handed an Upload
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
511
diff
changeset
|
3676 if (error != null) { |
443780d71bae
More renaming. user registers MonetUploadHandler which is handed an Upload
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
511
diff
changeset
|
3677 throw new IOException("cannot receive data after error has been sent"); |
443780d71bae
More renaming. user registers MonetUploadHandler which is handed an Upload
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
511
diff
changeset
|
3678 } |
443780d71bae
More renaming. user registers MonetUploadHandler which is handed an Upload
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
511
diff
changeset
|
3679 if (stream == null) { |
616
65641a7cea31
Implement line ending conversion for downloads
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
613
diff
changeset
|
3680 stream = server.downloadStream(prependCr); |
514
443780d71bae
More renaming. user registers MonetUploadHandler which is handed an Upload
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
511
diff
changeset
|
3681 server.getOutputStream().flush(); |
443780d71bae
More renaming. user registers MonetUploadHandler which is handed an Upload
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
511
diff
changeset
|
3682 } |
443780d71bae
More renaming. user registers MonetUploadHandler which is handed an Upload
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
511
diff
changeset
|
3683 return stream; |
443780d71bae
More renaming. user registers MonetUploadHandler which is handed an Upload
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
511
diff
changeset
|
3684 } |
515
7bbcff2c775b
Also implement downloadTo(), and use it in FileTransferHandler
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
514
diff
changeset
|
3685 |
535
c9d88af06d35
Javadoc and some minor changes
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
526
diff
changeset
|
3686 /** |
c9d88af06d35
Javadoc and some minor changes
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
526
diff
changeset
|
3687 * Write the data from the server to the given {@link OutputStream}. |
626
06d69b82d409
Resolve javadoc error and warnings :
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
623
diff
changeset
|
3688 * |
06d69b82d409
Resolve javadoc error and warnings :
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
623
diff
changeset
|
3689 * @param stream the OutputStream to write to |
06d69b82d409
Resolve javadoc error and warnings :
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
623
diff
changeset
|
3690 * @throws IOException when cannot read from InputStream or write to OutputStream |
535
c9d88af06d35
Javadoc and some minor changes
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
526
diff
changeset
|
3691 */ |
576
095e896f9d7a
Updated comments. Improved code. Added final keywords
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
568
diff
changeset
|
3692 public void downloadTo(final OutputStream stream) throws IOException { |
095e896f9d7a
Updated comments. Improved code. Added final keywords
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
568
diff
changeset
|
3693 final InputStream s = getStream(); |
095e896f9d7a
Updated comments. Improved code. Added final keywords
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
568
diff
changeset
|
3694 final byte[] buffer = new byte[65536]; |
515
7bbcff2c775b
Also implement downloadTo(), and use it in FileTransferHandler
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
514
diff
changeset
|
3695 while (true) { |
7bbcff2c775b
Also implement downloadTo(), and use it in FileTransferHandler
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
514
diff
changeset
|
3696 int nread = s.read(buffer); |
576
095e896f9d7a
Updated comments. Improved code. Added final keywords
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
568
diff
changeset
|
3697 if (nread < 0) { |
515
7bbcff2c775b
Also implement downloadTo(), and use it in FileTransferHandler
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
514
diff
changeset
|
3698 break; |
576
095e896f9d7a
Updated comments. Improved code. Added final keywords
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
568
diff
changeset
|
3699 } |
515
7bbcff2c775b
Also implement downloadTo(), and use it in FileTransferHandler
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
514
diff
changeset
|
3700 stream.write(buffer, 0, nread); |
7bbcff2c775b
Also implement downloadTo(), and use it in FileTransferHandler
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
514
diff
changeset
|
3701 } |
7bbcff2c775b
Also implement downloadTo(), and use it in FileTransferHandler
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
514
diff
changeset
|
3702 } |
7bbcff2c775b
Also implement downloadTo(), and use it in FileTransferHandler
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
514
diff
changeset
|
3703 |
535
c9d88af06d35
Javadoc and some minor changes
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
526
diff
changeset
|
3704 /** |
579
72f4437de9be
Reencode downloads if necessary
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
576
diff
changeset
|
3705 * Write the textual data from the server to the given {@link Writer} |
626
06d69b82d409
Resolve javadoc error and warnings :
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
623
diff
changeset
|
3706 * |
06d69b82d409
Resolve javadoc error and warnings :
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
623
diff
changeset
|
3707 * @param writer to write to |
06d69b82d409
Resolve javadoc error and warnings :
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
623
diff
changeset
|
3708 * @throws IOException when cannot read from InputStreamReader or write to Writer |
579
72f4437de9be
Reencode downloads if necessary
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
576
diff
changeset
|
3709 */ |
72f4437de9be
Reencode downloads if necessary
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
576
diff
changeset
|
3710 public void downloadTo(final Writer writer) throws IOException { |
72f4437de9be
Reencode downloads if necessary
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
576
diff
changeset
|
3711 final InputStream s = getStream(); |
72f4437de9be
Reencode downloads if necessary
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
576
diff
changeset
|
3712 final InputStreamReader r = new InputStreamReader(s, StandardCharsets.UTF_8); |
72f4437de9be
Reencode downloads if necessary
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
576
diff
changeset
|
3713 final char[] buffer = new char[65536]; |
72f4437de9be
Reencode downloads if necessary
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
576
diff
changeset
|
3714 while (true) { |
72f4437de9be
Reencode downloads if necessary
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
576
diff
changeset
|
3715 final int nread = r.read(buffer); |
620
5ab170ddc66a
Some small improvements
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
617
diff
changeset
|
3716 if (nread < 0) { |
579
72f4437de9be
Reencode downloads if necessary
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
576
diff
changeset
|
3717 break; |
620
5ab170ddc66a
Some small improvements
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
617
diff
changeset
|
3718 } |
579
72f4437de9be
Reencode downloads if necessary
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
576
diff
changeset
|
3719 writer.write(buffer, 0, nread); |
72f4437de9be
Reencode downloads if necessary
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
576
diff
changeset
|
3720 } |
72f4437de9be
Reencode downloads if necessary
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
576
diff
changeset
|
3721 } |
72f4437de9be
Reencode downloads if necessary
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
576
diff
changeset
|
3722 |
72f4437de9be
Reencode downloads if necessary
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
576
diff
changeset
|
3723 /** |
709
bdeabbd46ec6
Resolve javac and javadoc warnings when compiled with JDK19.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
708
diff
changeset
|
3724 * Tell whether data has been received or an error has been sent. |
626
06d69b82d409
Resolve javadoc error and warnings :
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
623
diff
changeset
|
3725 * @return true if data has been received or an error has been sent. |
535
c9d88af06d35
Javadoc and some minor changes
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
526
diff
changeset
|
3726 */ |
514
443780d71bae
More renaming. user registers MonetUploadHandler which is handed an Upload
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
511
diff
changeset
|
3727 public boolean hasBeenUsed() { |
620
5ab170ddc66a
Some small improvements
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
617
diff
changeset
|
3728 return stream != null || error != null; |
514
443780d71bae
More renaming. user registers MonetUploadHandler which is handed an Upload
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
511
diff
changeset
|
3729 } |
443780d71bae
More renaming. user registers MonetUploadHandler which is handed an Upload
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
511
diff
changeset
|
3730 |
535
c9d88af06d35
Javadoc and some minor changes
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
526
diff
changeset
|
3731 /** |
709
bdeabbd46ec6
Resolve javac and javadoc warnings when compiled with JDK19.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
708
diff
changeset
|
3732 * Get the error string. |
554
9fa67487f38a
Doc comment fixes
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
553
diff
changeset
|
3733 * @return the error that was sent, if any |
535
c9d88af06d35
Javadoc and some minor changes
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
526
diff
changeset
|
3734 */ |
514
443780d71bae
More renaming. user registers MonetUploadHandler which is handed an Upload
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
511
diff
changeset
|
3735 public String getError() { |
443780d71bae
More renaming. user registers MonetUploadHandler which is handed an Upload
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
511
diff
changeset
|
3736 return error; |
443780d71bae
More renaming. user registers MonetUploadHandler which is handed an Upload
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
511
diff
changeset
|
3737 } |
576
095e896f9d7a
Updated comments. Improved code. Added final keywords
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
568
diff
changeset
|
3738 |
095e896f9d7a
Updated comments. Improved code. Added final keywords
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
568
diff
changeset
|
3739 /** |
095e896f9d7a
Updated comments. Improved code. Added final keywords
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
568
diff
changeset
|
3740 * Close opened stream. |
095e896f9d7a
Updated comments. Improved code. Added final keywords
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
568
diff
changeset
|
3741 */ |
095e896f9d7a
Updated comments. Improved code. Added final keywords
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
568
diff
changeset
|
3742 public void close() { |
095e896f9d7a
Updated comments. Improved code. Added final keywords
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
568
diff
changeset
|
3743 if (stream != null) { |
095e896f9d7a
Updated comments. Improved code. Added final keywords
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
568
diff
changeset
|
3744 try { |
095e896f9d7a
Updated comments. Improved code. Added final keywords
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
568
diff
changeset
|
3745 stream.close(); |
095e896f9d7a
Updated comments. Improved code. Added final keywords
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
568
diff
changeset
|
3746 stream = null; |
095e896f9d7a
Updated comments. Improved code. Added final keywords
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
568
diff
changeset
|
3747 } catch (IOException e) { |
095e896f9d7a
Updated comments. Improved code. Added final keywords
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
568
diff
changeset
|
3748 /* ignore close error */ |
095e896f9d7a
Updated comments. Improved code. Added final keywords
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
568
diff
changeset
|
3749 } |
514
443780d71bae
More renaming. user registers MonetUploadHandler which is handed an Upload
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
511
diff
changeset
|
3750 } |
443780d71bae
More renaming. user registers MonetUploadHandler which is handed an Upload
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
511
diff
changeset
|
3751 } |
616
65641a7cea31
Implement line ending conversion for downloads
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
613
diff
changeset
|
3752 |
65641a7cea31
Implement line ending conversion for downloads
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
613
diff
changeset
|
3753 /** |
65641a7cea31
Implement line ending conversion for downloads
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
613
diff
changeset
|
3754 * Set the line endings used in the stream returned by {@link Download#getStream()} |
626
06d69b82d409
Resolve javadoc error and warnings :
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
623
diff
changeset
|
3755 * |
616
65641a7cea31
Implement line ending conversion for downloads
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
613
diff
changeset
|
3756 * @param sep separator to use |
65641a7cea31
Implement line ending conversion for downloads
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
613
diff
changeset
|
3757 * @throws IllegalArgumentException if sep is neither "\n" nor "\r\n" |
65641a7cea31
Implement line ending conversion for downloads
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
613
diff
changeset
|
3758 */ |
620
5ab170ddc66a
Some small improvements
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
617
diff
changeset
|
3759 public void setLineSeparator(final String sep) { |
616
65641a7cea31
Implement line ending conversion for downloads
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
613
diff
changeset
|
3760 if ("\n".equals(sep)) { |
65641a7cea31
Implement line ending conversion for downloads
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
613
diff
changeset
|
3761 prependCr = false; |
65641a7cea31
Implement line ending conversion for downloads
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
613
diff
changeset
|
3762 } else if ("\r\n".equals(sep)) { |
65641a7cea31
Implement line ending conversion for downloads
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
613
diff
changeset
|
3763 prependCr = true; |
65641a7cea31
Implement line ending conversion for downloads
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
613
diff
changeset
|
3764 } else { |
620
5ab170ddc66a
Some small improvements
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
617
diff
changeset
|
3765 throw new IllegalArgumentException("sep must be \\n or \\r\\n"); |
616
65641a7cea31
Implement line ending conversion for downloads
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
613
diff
changeset
|
3766 } |
65641a7cea31
Implement line ending conversion for downloads
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
613
diff
changeset
|
3767 } |
514
443780d71bae
More renaming. user registers MonetUploadHandler which is handed an Upload
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
511
diff
changeset
|
3768 } |
613
9397c0b487f8
Normalize CRLF on upload
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
610
diff
changeset
|
3769 |
9397c0b487f8
Normalize CRLF on upload
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
610
diff
changeset
|
3770 public static class StripCrLfStream extends FilterOutputStream { |
9397c0b487f8
Normalize CRLF on upload
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
610
diff
changeset
|
3771 private boolean crPending = false; |
9397c0b487f8
Normalize CRLF on upload
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
610
diff
changeset
|
3772 |
9397c0b487f8
Normalize CRLF on upload
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
610
diff
changeset
|
3773 public StripCrLfStream(OutputStream out) { |
9397c0b487f8
Normalize CRLF on upload
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
610
diff
changeset
|
3774 super(out); |
9397c0b487f8
Normalize CRLF on upload
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
610
diff
changeset
|
3775 } |
9397c0b487f8
Normalize CRLF on upload
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
610
diff
changeset
|
3776 |
9397c0b487f8
Normalize CRLF on upload
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
610
diff
changeset
|
3777 public boolean pending() { |
9397c0b487f8
Normalize CRLF on upload
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
610
diff
changeset
|
3778 return this.crPending; |
9397c0b487f8
Normalize CRLF on upload
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
610
diff
changeset
|
3779 } |
9397c0b487f8
Normalize CRLF on upload
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
610
diff
changeset
|
3780 |
9397c0b487f8
Normalize CRLF on upload
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
610
diff
changeset
|
3781 @Override |
620
5ab170ddc66a
Some small improvements
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
617
diff
changeset
|
3782 public void write(final int b) throws IOException { |
613
9397c0b487f8
Normalize CRLF on upload
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
610
diff
changeset
|
3783 if (crPending && b != '\n') { |
620
5ab170ddc66a
Some small improvements
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
617
diff
changeset
|
3784 out.write('\r'); |
613
9397c0b487f8
Normalize CRLF on upload
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
610
diff
changeset
|
3785 } |
9397c0b487f8
Normalize CRLF on upload
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
610
diff
changeset
|
3786 if (b != '\r') { |
9397c0b487f8
Normalize CRLF on upload
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
610
diff
changeset
|
3787 out.write(b); |
9397c0b487f8
Normalize CRLF on upload
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
610
diff
changeset
|
3788 crPending = false; |
9397c0b487f8
Normalize CRLF on upload
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
610
diff
changeset
|
3789 } else { |
9397c0b487f8
Normalize CRLF on upload
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
610
diff
changeset
|
3790 crPending = true; |
9397c0b487f8
Normalize CRLF on upload
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
610
diff
changeset
|
3791 } |
9397c0b487f8
Normalize CRLF on upload
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
610
diff
changeset
|
3792 } |
9397c0b487f8
Normalize CRLF on upload
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
610
diff
changeset
|
3793 |
9397c0b487f8
Normalize CRLF on upload
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
610
diff
changeset
|
3794 @Override |
620
5ab170ddc66a
Some small improvements
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
617
diff
changeset
|
3795 public void write(final byte[] b) throws IOException { |
613
9397c0b487f8
Normalize CRLF on upload
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
610
diff
changeset
|
3796 this.write(b, 0, b.length); |
9397c0b487f8
Normalize CRLF on upload
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
610
diff
changeset
|
3797 } |
9397c0b487f8
Normalize CRLF on upload
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
610
diff
changeset
|
3798 |
9397c0b487f8
Normalize CRLF on upload
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
610
diff
changeset
|
3799 @Override |
620
5ab170ddc66a
Some small improvements
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
617
diff
changeset
|
3800 public void write(final byte[] b, int off, int len) throws IOException { |
613
9397c0b487f8
Normalize CRLF on upload
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
610
diff
changeset
|
3801 if (len == 0) { |
9397c0b487f8
Normalize CRLF on upload
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
610
diff
changeset
|
3802 return; |
9397c0b487f8
Normalize CRLF on upload
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
610
diff
changeset
|
3803 } |
9397c0b487f8
Normalize CRLF on upload
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
610
diff
changeset
|
3804 if (crPending && b[0] != '\n') { |
9397c0b487f8
Normalize CRLF on upload
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
610
diff
changeset
|
3805 out.write('\r'); |
9397c0b487f8
Normalize CRLF on upload
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
610
diff
changeset
|
3806 } |
9397c0b487f8
Normalize CRLF on upload
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
610
diff
changeset
|
3807 |
9397c0b487f8
Normalize CRLF on upload
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
610
diff
changeset
|
3808 // deal with final \r up front |
9397c0b487f8
Normalize CRLF on upload
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
610
diff
changeset
|
3809 if (b[len - 1] == '\r') { |
9397c0b487f8
Normalize CRLF on upload
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
610
diff
changeset
|
3810 crPending = true; |
9397c0b487f8
Normalize CRLF on upload
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
610
diff
changeset
|
3811 len -= 1; |
9397c0b487f8
Normalize CRLF on upload
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
610
diff
changeset
|
3812 } else { |
9397c0b487f8
Normalize CRLF on upload
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
610
diff
changeset
|
3813 crPending = false; |
9397c0b487f8
Normalize CRLF on upload
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
610
diff
changeset
|
3814 } |
9397c0b487f8
Normalize CRLF on upload
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
610
diff
changeset
|
3815 |
9397c0b487f8
Normalize CRLF on upload
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
610
diff
changeset
|
3816 for (int i = off; i < off + len - 1; i++) { |
9397c0b487f8
Normalize CRLF on upload
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
610
diff
changeset
|
3817 if (b[i] == '\r' && b[i + 1] == '\n') { |
9397c0b487f8
Normalize CRLF on upload
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
610
diff
changeset
|
3818 int chunk = i - off; |
9397c0b487f8
Normalize CRLF on upload
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
610
diff
changeset
|
3819 out.write(b, off, chunk); |
9397c0b487f8
Normalize CRLF on upload
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
610
diff
changeset
|
3820 // chunk + 1 because we want to skip the \r |
9397c0b487f8
Normalize CRLF on upload
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
610
diff
changeset
|
3821 len -= chunk + 1; |
9397c0b487f8
Normalize CRLF on upload
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
610
diff
changeset
|
3822 off += chunk + 1; |
9397c0b487f8
Normalize CRLF on upload
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
610
diff
changeset
|
3823 // we don't have to look at the \n because we know it's no \r. |
9397c0b487f8
Normalize CRLF on upload
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
610
diff
changeset
|
3824 i++; |
9397c0b487f8
Normalize CRLF on upload
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
610
diff
changeset
|
3825 } |
9397c0b487f8
Normalize CRLF on upload
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
610
diff
changeset
|
3826 } |
9397c0b487f8
Normalize CRLF on upload
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
610
diff
changeset
|
3827 |
9397c0b487f8
Normalize CRLF on upload
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
610
diff
changeset
|
3828 // write the remainder |
9397c0b487f8
Normalize CRLF on upload
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
610
diff
changeset
|
3829 out.write(b, off, len); |
9397c0b487f8
Normalize CRLF on upload
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
610
diff
changeset
|
3830 } |
9397c0b487f8
Normalize CRLF on upload
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
610
diff
changeset
|
3831 |
9397c0b487f8
Normalize CRLF on upload
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
610
diff
changeset
|
3832 @Override |
9397c0b487f8
Normalize CRLF on upload
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
610
diff
changeset
|
3833 public void flush() throws IOException { |
9397c0b487f8
Normalize CRLF on upload
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
610
diff
changeset
|
3834 // we cannot flush our pending CR but we can ask our downstream to flush what we have sent them so far |
9397c0b487f8
Normalize CRLF on upload
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
610
diff
changeset
|
3835 out.flush(); |
9397c0b487f8
Normalize CRLF on upload
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
610
diff
changeset
|
3836 } |
9397c0b487f8
Normalize CRLF on upload
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
610
diff
changeset
|
3837 |
9397c0b487f8
Normalize CRLF on upload
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
610
diff
changeset
|
3838 @Override |
9397c0b487f8
Normalize CRLF on upload
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
610
diff
changeset
|
3839 public void close() throws IOException { |
9397c0b487f8
Normalize CRLF on upload
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
610
diff
changeset
|
3840 if (crPending) { |
9397c0b487f8
Normalize CRLF on upload
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
610
diff
changeset
|
3841 out.write('\r'); |
9397c0b487f8
Normalize CRLF on upload
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
610
diff
changeset
|
3842 } |
9397c0b487f8
Normalize CRLF on upload
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
610
diff
changeset
|
3843 crPending = false; |
9397c0b487f8
Normalize CRLF on upload
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
610
diff
changeset
|
3844 super.close(); |
9397c0b487f8
Normalize CRLF on upload
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
610
diff
changeset
|
3845 } |
9397c0b487f8
Normalize CRLF on upload
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
610
diff
changeset
|
3846 } |
793
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
788
diff
changeset
|
3847 |
834
5aa19bbed0d6
Comments and formatting
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
810
diff
changeset
|
3848 /* encode knowledge of currently available handshake options as an enum. */ |
5aa19bbed0d6
Comments and formatting
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
810
diff
changeset
|
3849 enum SqlOption { |
793
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
788
diff
changeset
|
3850 Autocommit(1, "auto_commit"), |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
788
diff
changeset
|
3851 ReplySize(2, "reply_size"), |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
788
diff
changeset
|
3852 SizeHeader(3, "size_header"), |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
788
diff
changeset
|
3853 // NOTE: 4 has been omitted on purpose |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
788
diff
changeset
|
3854 TimeZone(5, "time_zone"), |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
788
diff
changeset
|
3855 ; |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
788
diff
changeset
|
3856 final int level; |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
788
diff
changeset
|
3857 final String field; |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
788
diff
changeset
|
3858 |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
788
diff
changeset
|
3859 SqlOption(int level, String field) { |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
788
diff
changeset
|
3860 this.level = level; |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
788
diff
changeset
|
3861 this.field = field; |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
788
diff
changeset
|
3862 } |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
788
diff
changeset
|
3863 } |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
788
diff
changeset
|
3864 |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
788
diff
changeset
|
3865 |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
788
diff
changeset
|
3866 private class SqlOptionsCallback extends MapiSocket.OptionsCallback { |
940
c5e47b8a509c
Prefer getters of class Target.Validated over class Target
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
937
diff
changeset
|
3867 private final Target.Validated validated; |
793
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
788
diff
changeset
|
3868 private int level; |
837
5df67d5d7a7b
Move timeZoneSet and sizeHeaderEnabled into Callback
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
834
diff
changeset
|
3869 boolean sizeHeaderEnabled = false; // used during handshake |
5df67d5d7a7b
Move timeZoneSet and sizeHeaderEnabled into Callback
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
834
diff
changeset
|
3870 boolean timeZoneSet = false; // used during handshake |
5df67d5d7a7b
Move timeZoneSet and sizeHeaderEnabled into Callback
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
834
diff
changeset
|
3871 |
940
c5e47b8a509c
Prefer getters of class Target.Validated over class Target
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
937
diff
changeset
|
3872 public SqlOptionsCallback(Target.Validated validated) { |
c5e47b8a509c
Prefer getters of class Target.Validated over class Target
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
937
diff
changeset
|
3873 super(); |
c5e47b8a509c
Prefer getters of class Target.Validated over class Target
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
937
diff
changeset
|
3874 this.validated = validated; |
c5e47b8a509c
Prefer getters of class Target.Validated over class Target
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
937
diff
changeset
|
3875 } |
c5e47b8a509c
Prefer getters of class Target.Validated over class Target
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
937
diff
changeset
|
3876 |
834
5aa19bbed0d6
Comments and formatting
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
810
diff
changeset
|
3877 |
793
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
788
diff
changeset
|
3878 @Override |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
788
diff
changeset
|
3879 public void addOptions(String lang, int level) { |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
788
diff
changeset
|
3880 if (!lang.equals("sql")) |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
788
diff
changeset
|
3881 return; |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
788
diff
changeset
|
3882 this.level = level; |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
788
diff
changeset
|
3883 |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
788
diff
changeset
|
3884 // Try to add options and record that this happened if it succeeds. |
940
c5e47b8a509c
Prefer getters of class Target.Validated over class Target
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
937
diff
changeset
|
3885 if (contribute(SqlOption.Autocommit, validated.isAutocommit() ? 1 : 0)) |
793
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
788
diff
changeset
|
3886 autoCommit = target.isAutocommit(); |
940
c5e47b8a509c
Prefer getters of class Target.Validated over class Target
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
937
diff
changeset
|
3887 if (contribute(SqlOption.ReplySize, validated.getReplySize())) |
c5e47b8a509c
Prefer getters of class Target.Validated over class Target
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
937
diff
changeset
|
3888 defaultFetchSize = validated.getReplySize(); |
793
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
788
diff
changeset
|
3889 if (contribute(SqlOption.SizeHeader, 1)) |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
788
diff
changeset
|
3890 sizeHeaderEnabled = true; |
878
dc33533e6468
Target timezone is in minutes, setTimeZone is in seconds
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
869
diff
changeset
|
3891 if (contribute(SqlOption.TimeZone, 60 * target.getTimezone())) |
793
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
788
diff
changeset
|
3892 timeZoneSet = true; |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
788
diff
changeset
|
3893 } |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
788
diff
changeset
|
3894 |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
788
diff
changeset
|
3895 private boolean contribute(SqlOption opt, int value) { |
834
5aa19bbed0d6
Comments and formatting
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
810
diff
changeset
|
3896 if (opt.level >= this.level) |
793
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
788
diff
changeset
|
3897 return false; |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
788
diff
changeset
|
3898 contribute(opt.field, value); |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
788
diff
changeset
|
3899 return true; |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
788
diff
changeset
|
3900 } |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
788
diff
changeset
|
3901 } |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
3902 } |