Mercurial > hg > monetdb-java
annotate src/main/java/nl/cwi/monetdb/jdbc/MonetDriver.java.in @ 295:003ae6d881db
Add "final" keyword to method arguments and local variables where possible.
It discovered some bugs in the MonetStatement constructor (changed the argument instead of object variable) which are fixed now.
See also https://en.wikipedia.org/wiki/Final_(Java)
author | Martin van Dinther <martin.van.dinther@monetdbsolutions.com> |
---|---|
date | Thu, 01 Aug 2019 20:18:43 +0200 (2019-08-01) |
parents | 2d62ca1f758b |
children | 55330e40cbf1 |
rev | line source |
---|---|
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
1 /* |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2 * This Source Code Form is subject to the terms of the Mozilla Public |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
3 * License, v. 2.0. If a copy of the MPL was not distributed with this |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
5 * |
261
d4baf8a4b43a
Update Copyright year to 2019
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
254
diff
changeset
|
6 * Copyright 1997 - July 2008 CWI, August 2008 - 2019 MonetDB B.V. |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
7 */ |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
8 |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
9 package nl.cwi.monetdb.jdbc; |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
10 |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
11 import java.net.URI; |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
12 import java.sql.Connection; |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
13 import java.sql.Driver; |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
14 import java.sql.DriverManager; |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
15 import java.sql.DriverPropertyInfo; |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
16 import java.sql.SQLException; |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
17 import java.sql.SQLFeatureNotSupportedException; |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
18 import java.sql.Types; |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
19 import java.util.Map.Entry; |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
20 import java.util.Properties; |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
21 |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
22 /** |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
23 * A Driver suitable for the MonetDB database. |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
24 * |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
25 * This driver will be used by the DriverManager to determine if an URL |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
26 * is to be handled by this driver, and if it does, then this driver |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
27 * will supply a Connection suitable for MonetDB. |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
28 * |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
29 * This class has no explicit constructor, the default constructor |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
30 * generated by the Java compiler will be sufficient since nothing has |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
31 * to be set in order to use this driver. |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
32 * |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
33 * This Driver supports MonetDB database URLs. MonetDB URLs are defined |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
34 * as: |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
35 * <tt>jdbc:monetdb://<host>[:<port>]/<database></tt> |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
36 * where [:<port>] denotes that a port is optional. If not |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
37 * given the default (@JDBC_DEF_PORT@) will be used. |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
38 * |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
39 * @author Fabian Groffen |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
40 * @version @JDBC_MAJOR@.@JDBC_MINOR@ (@JDBC_VER_SUFFIX@) |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
41 */ |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
42 final public class MonetDriver implements Driver { |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
43 // the url kind will be jdbc:monetdb://<host>[:<port>]/<database> |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
44 // Chapter 9.2.1 from Sun JDBC 3.0 specification |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
45 /** The prefix of a MonetDB url */ |
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
|
46 static final String MONETURL = "jdbc:monetdb://"; |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
47 /** Major version of this driver */ |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
48 private static final int DRIVERMAJOR = @JDBC_MAJOR@; |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
49 /** Minor version of this driver */ |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
50 private static final int DRIVERMINOR = @JDBC_MINOR@; |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
51 /** Version suffix string */ |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
52 private static final String DRIVERVERSIONSUFFIX = |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
53 "@JDBC_VER_SUFFIX@ based on MCL v@MCL_MAJOR@.@MCL_MINOR@"; |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
54 |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
55 /** MonetDB default port to connect to */ |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
56 private static final String PORT = "@JDBC_DEF_PORT@"; |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
57 |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
58 |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
59 // initialize this class: register it at the DriverManager |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
60 // Chapter 9.2 from Sun JDBC 3.0 specification |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
61 static { |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
62 try { |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
63 DriverManager.registerDriver(new MonetDriver()); |
8
a27ee2cb14a0
Replace String methods equals("") and "".equals( with isEmpty()
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
0
diff
changeset
|
64 } catch (SQLException e) { |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
65 e.printStackTrace(); |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
66 } |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
67 } |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
68 |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
69 //== methods of interface Driver |
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 /** |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
72 * Retrieves whether the driver thinks that it can open a connection to the |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
73 * given URL. Typically drivers will return true if they understand the |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
74 * subprotocol specified in the URL and false if they do not. |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
75 * |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
76 * @param url the URL of the database |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
77 * @return true if this driver understands the given URL; false otherwise |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
78 */ |
144
d6abd1ffffbb
Use SQLNonTransientConnectionException instead of SQLException where applicable (SQLState starts with 08)
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
90
diff
changeset
|
79 @Override |
295
003ae6d881db
Add "final" keyword to method arguments and local variables where possible.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
262
diff
changeset
|
80 public boolean acceptsURL(final String url) { |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
81 return url != null && url.startsWith(MONETURL); |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
82 } |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
83 |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
84 /** |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
85 * Attempts to make a database connection to the given URL. The driver |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
86 * should return "null" if it realizes it is the wrong kind of driver to |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
87 * connect to the given URL. This will be common, as when the JDBC driver |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
88 * manager is asked to connect to a given URL it passes the URL to each |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
89 * loaded driver in turn. |
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 * The driver should throw an SQLException if it is the right driver to |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
92 * connect to the given URL but has trouble connecting to the database. |
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 * The java.util.Properties argument can be used to pass arbitrary string |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
95 * tag/value pairs as connection arguments. Normally at least "user" and |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
96 * "password" properties should be included in the Properties object. |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
97 * |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
98 * @param url the URL of the database to which to connect |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
99 * @param info a list of arbitrary string tag/value pairs as connection |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
100 * arguments. Normally at least a "user" and "password" property |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
101 * should be included |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
102 * @return a Connection object that represents a connection to the URL |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
103 * @throws SQLException if a database access error occurs |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
104 */ |
144
d6abd1ffffbb
Use SQLNonTransientConnectionException instead of SQLException where applicable (SQLState starts with 08)
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
90
diff
changeset
|
105 @Override |
295
003ae6d881db
Add "final" keyword to method arguments and local variables where possible.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
262
diff
changeset
|
106 public Connection connect(final String url, Properties info) |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
107 throws SQLException |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
108 { |
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
|
109 // url should be of style jdbc:monetdb://<host>/<database> |
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
|
110 if (!acceptsURL(url)) |
254
27b7166860c8
According to the JDBC specification if the JDBC URL is invalid, return null instead of an exception, so the DriverManager can keep looking for a suitable JDBC driver.
Pedro Ferreira <pedro.ferreira@monetdbsolutions.com>
parents:
224
diff
changeset
|
111 return null; |
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
|
112 |
295
003ae6d881db
Add "final" keyword to method arguments and local variables where possible.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
262
diff
changeset
|
113 final Properties props = new Properties(); |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
114 // set the optional properties and their defaults here |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
115 props.put("port", PORT); |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
116 props.put("debug", "false"); |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
117 props.put("language", "sql"); // mal, sql, <future> |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
118 props.put("so_timeout", "0"); |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
119 |
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
|
120 if (info != null) |
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
|
121 props.putAll(info); |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
122 info = props; |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
123 |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
124 // remove leading "jdbc:" so the rest is a valid hierarchical URI |
295
003ae6d881db
Add "final" keyword to method arguments and local variables where possible.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
262
diff
changeset
|
125 final URI uri; |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
126 try { |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
127 uri = new URI(url.substring(5)); |
295
003ae6d881db
Add "final" keyword to method arguments and local variables where possible.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
262
diff
changeset
|
128 } catch (java.net.URISyntaxException e) { |
254
27b7166860c8
According to the JDBC specification if the JDBC URL is invalid, return null instead of an exception, so the DriverManager can keep looking for a suitable JDBC driver.
Pedro Ferreira <pedro.ferreira@monetdbsolutions.com>
parents:
224
diff
changeset
|
129 return null; |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
130 } |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
131 |
295
003ae6d881db
Add "final" keyword to method arguments and local variables where possible.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
262
diff
changeset
|
132 final String uri_host = uri.getHost(); |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
133 if (uri_host == null) |
254
27b7166860c8
According to the JDBC specification if the JDBC URL is invalid, return null instead of an exception, so the DriverManager can keep looking for a suitable JDBC driver.
Pedro Ferreira <pedro.ferreira@monetdbsolutions.com>
parents:
224
diff
changeset
|
134 return null; |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
135 info.put("host", uri_host); |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
136 |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
137 int uri_port = uri.getPort(); |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
138 if (uri_port > 0) |
180
fdf4c888d5b7
Small code and layout improvements
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
175
diff
changeset
|
139 info.put("port", Integer.toString(uri_port)); |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
140 |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
141 // check the database |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
142 String uri_path = uri.getPath(); |
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
|
143 if (uri_path != null && !uri_path.isEmpty()) { |
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
|
144 uri_path = uri_path.substring(1).trim(); |
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
|
145 if (!uri_path.isEmpty()) |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
146 info.put("database", uri_path); |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
147 } |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
148 |
295
003ae6d881db
Add "final" keyword to method arguments and local variables where possible.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
262
diff
changeset
|
149 final String uri_query = uri.getQuery(); |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
150 if (uri_query != null) { |
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
|
151 int pos; |
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
|
152 // handle additional connection properties separated by the & character |
295
003ae6d881db
Add "final" keyword to method arguments and local variables where possible.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
262
diff
changeset
|
153 final String args[] = uri_query.split("&"); |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
154 for (int i = 0; i < args.length; i++) { |
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
|
155 pos = args[i].indexOf('='); |
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
|
156 if (pos > 0) |
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
|
157 info.put(args[i].substring(0, pos), args[i].substring(pos + 1)); |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
158 } |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
159 } |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
160 |
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
|
161 // finally return the Connection object as requested |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
162 return new MonetConnection(info); |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
163 } |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
164 |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
165 /** |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
166 * Retrieves the driver's major version number. Initially this should be 1. |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
167 * |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
168 * @return this driver's major version number |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
169 */ |
144
d6abd1ffffbb
Use SQLNonTransientConnectionException instead of SQLException where applicable (SQLState starts with 08)
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
90
diff
changeset
|
170 @Override |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
171 public int getMajorVersion() { |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
172 return DRIVERMAJOR; |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
173 } |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
174 |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
175 /** |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
176 * Gets the driver's minor version number. Initially this should be 0. |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
177 * |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
178 * @return this driver's minor version number |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
179 */ |
144
d6abd1ffffbb
Use SQLNonTransientConnectionException instead of SQLException where applicable (SQLState starts with 08)
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
90
diff
changeset
|
180 @Override |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
181 public int getMinorVersion() { |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
182 return DRIVERMINOR; |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
183 } |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
184 |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
185 /** |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
186 * Gets information about the possible properties for this driver. |
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 * The getPropertyInfo method is intended to allow a generic GUI tool to |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
189 * discover what properties it should prompt a human for in order to get |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
190 * enough information to connect to a database. Note that depending on the |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
191 * values the human has supplied so far, additional values may become |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
192 * necessary, so it may be necessary to iterate though several calls to the |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
193 * getPropertyInfo method. |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
194 * |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
195 * @param url the URL of the database to which to connect |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
196 * @param info a proposed list of tag/value pairs that will be sent on |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
197 * connect open |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
198 * @return an array of DriverPropertyInfo objects describing possible |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
199 * properties. This array may be an empty array if no properties |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
200 * are required. |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
201 */ |
144
d6abd1ffffbb
Use SQLNonTransientConnectionException instead of SQLException where applicable (SQLState starts with 08)
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
90
diff
changeset
|
202 @Override |
295
003ae6d881db
Add "final" keyword to method arguments and local variables where possible.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
262
diff
changeset
|
203 public DriverPropertyInfo[] getPropertyInfo(final String url, final Properties info) { |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
204 if (!acceptsURL(url)) |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
205 return null; |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
206 |
295
003ae6d881db
Add "final" keyword to method arguments and local variables where possible.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
262
diff
changeset
|
207 final String[] boolean_choices = new String[] { "true", "false" }; |
003ae6d881db
Add "final" keyword to method arguments and local variables where possible.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
262
diff
changeset
|
208 final String[] language_choices = new String[] { "sql", "mal" }; |
003ae6d881db
Add "final" keyword to method arguments and local variables where possible.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
262
diff
changeset
|
209 final String[] hash_choices = new String[] { "SHA512", "SHA384", "SHA256", "SHA1", "MD5" }; |
003ae6d881db
Add "final" keyword to method arguments and local variables where possible.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
262
diff
changeset
|
210 final DriverPropertyInfo[] dpi = new DriverPropertyInfo[9]; // we currently support 9 connection properties |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
211 |
224
ea729e0cf24d
Improve and extend MonetDriver.getPropertyInfo() with choice values
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
223
diff
changeset
|
212 DriverPropertyInfo prop = new DriverPropertyInfo("user", info != null ? info.getProperty("user") : null); |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
213 prop.required = true; |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
214 prop.description = "The user loginname to use when authenticating on the database server"; |
224
ea729e0cf24d
Improve and extend MonetDriver.getPropertyInfo() with choice values
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
223
diff
changeset
|
215 dpi[0] = prop; |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
216 |
224
ea729e0cf24d
Improve and extend MonetDriver.getPropertyInfo() with choice values
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
223
diff
changeset
|
217 prop = new DriverPropertyInfo("password", info != null ? info.getProperty("password") : null); |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
218 prop.required = true; |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
219 prop.description = "The password to use when authenticating on the database server"; |
224
ea729e0cf24d
Improve and extend MonetDriver.getPropertyInfo() with choice values
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
223
diff
changeset
|
220 dpi[1] = prop; |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
221 |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
222 prop = new DriverPropertyInfo("debug", "false"); |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
223 prop.required = false; |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
224 prop.description = "Whether or not to create a log file for debugging purposes"; |
224
ea729e0cf24d
Improve and extend MonetDriver.getPropertyInfo() with choice values
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
223
diff
changeset
|
225 prop.choices = boolean_choices; |
ea729e0cf24d
Improve and extend MonetDriver.getPropertyInfo() with choice values
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
223
diff
changeset
|
226 dpi[2] = prop; |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
227 |
224
ea729e0cf24d
Improve and extend MonetDriver.getPropertyInfo() with choice values
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
223
diff
changeset
|
228 prop = new DriverPropertyInfo("logfile", null); |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
229 prop.required = false; |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
230 prop.description = "The filename to write the debug log to. Only takes effect if debug is set to true. If the file exists, an incrementing number is added, till the filename is unique."; |
224
ea729e0cf24d
Improve and extend MonetDriver.getPropertyInfo() with choice values
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
223
diff
changeset
|
231 dpi[3] = prop; |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
232 |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
233 prop = new DriverPropertyInfo("language", "sql"); |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
234 prop.required = false; |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
235 prop.description = "What language to use for MonetDB conversations (experts only)"; |
224
ea729e0cf24d
Improve and extend MonetDriver.getPropertyInfo() with choice values
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
223
diff
changeset
|
236 prop.choices = language_choices; |
ea729e0cf24d
Improve and extend MonetDriver.getPropertyInfo() with choice values
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
223
diff
changeset
|
237 dpi[4] = prop; |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
238 |
224
ea729e0cf24d
Improve and extend MonetDriver.getPropertyInfo() with choice values
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
223
diff
changeset
|
239 prop = new DriverPropertyInfo("hash", null); |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
240 prop.required = false; |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
241 prop.description = "Force the use of the given hash algorithm during challenge response (one of SHA1, MD5, plain)"; |
224
ea729e0cf24d
Improve and extend MonetDriver.getPropertyInfo() with choice values
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
223
diff
changeset
|
242 prop.choices = hash_choices; |
ea729e0cf24d
Improve and extend MonetDriver.getPropertyInfo() with choice values
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
223
diff
changeset
|
243 dpi[5] = prop; |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
244 |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
245 prop = new DriverPropertyInfo("treat_blob_as_binary", "false"); |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
246 prop.required = false; |
224
ea729e0cf24d
Improve and extend MonetDriver.getPropertyInfo() with choice values
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
223
diff
changeset
|
247 prop.description = "Should blob columns be mapped to Types.VARBINARY instead of default Types.BLOB in ResultSets and PreparedStatements"; |
ea729e0cf24d
Improve and extend MonetDriver.getPropertyInfo() with choice values
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
223
diff
changeset
|
248 prop.choices = boolean_choices; |
ea729e0cf24d
Improve and extend MonetDriver.getPropertyInfo() with choice values
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
223
diff
changeset
|
249 dpi[6] = prop; |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
250 |
175
8700d9ef2ace
Added possibility via a connection property to let the JDBC driver
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
144
diff
changeset
|
251 prop = new DriverPropertyInfo("treat_clob_as_varchar", "false"); |
8700d9ef2ace
Added possibility via a connection property to let the JDBC driver
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
144
diff
changeset
|
252 prop.required = false; |
224
ea729e0cf24d
Improve and extend MonetDriver.getPropertyInfo() with choice values
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
223
diff
changeset
|
253 prop.description = "Should clob columns be mapped to Types.VARCHAR instead of default Types.CLOB in ResultSets and PreparedStatements"; // recommend for increased performance due to less overhead |
ea729e0cf24d
Improve and extend MonetDriver.getPropertyInfo() with choice values
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
223
diff
changeset
|
254 prop.choices = boolean_choices; |
ea729e0cf24d
Improve and extend MonetDriver.getPropertyInfo() with choice values
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
223
diff
changeset
|
255 dpi[7] = prop; |
175
8700d9ef2ace
Added possibility via a connection property to let the JDBC driver
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
144
diff
changeset
|
256 |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
257 prop = new DriverPropertyInfo("so_timeout", "0"); |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
258 prop.required = false; |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
259 prop.description = "Defines the maximum time to wait in milliseconds on a blocking read socket call"; // this corresponds to the Connection.setNetworkTimeout() method introduced in JDBC 4.1 |
224
ea729e0cf24d
Improve and extend MonetDriver.getPropertyInfo() with choice values
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
223
diff
changeset
|
260 dpi[8] = prop; |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
261 |
224
ea729e0cf24d
Improve and extend MonetDriver.getPropertyInfo() with choice values
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
223
diff
changeset
|
262 /* next property is no longer supported in: new MonetConnection(props) |
ea729e0cf24d
Improve and extend MonetDriver.getPropertyInfo() with choice values
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
223
diff
changeset
|
263 prop = new DriverPropertyInfo("follow_redirects", "true"); |
ea729e0cf24d
Improve and extend MonetDriver.getPropertyInfo() with choice values
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
223
diff
changeset
|
264 prop.required = false; |
ea729e0cf24d
Improve and extend MonetDriver.getPropertyInfo() with choice values
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
223
diff
changeset
|
265 prop.description = "Whether redirects issued by the server should be followed"; |
ea729e0cf24d
Improve and extend MonetDriver.getPropertyInfo() with choice values
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
223
diff
changeset
|
266 prop.choices = boolean_choices; |
ea729e0cf24d
Improve and extend MonetDriver.getPropertyInfo() with choice values
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
223
diff
changeset
|
267 dpi[9] = prop; |
ea729e0cf24d
Improve and extend MonetDriver.getPropertyInfo() with choice values
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
223
diff
changeset
|
268 */ |
ea729e0cf24d
Improve and extend MonetDriver.getPropertyInfo() with choice values
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
223
diff
changeset
|
269 |
ea729e0cf24d
Improve and extend MonetDriver.getPropertyInfo() with choice values
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
223
diff
changeset
|
270 return dpi; |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
271 } |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
272 |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
273 /** |
194
1296dbcc4958
Resolved javadoc many errors and warnings, such as:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
180
diff
changeset
|
274 * Reports whether this driver is a genuine JDBC Compliant™ driver. A |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
275 * driver may only report true here if it passes the JDBC compliance tests; |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
276 * otherwise it is required to return false. |
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 * JDBC compliance requires full support for the JDBC API and full support |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
279 * for SQL 92 Entry Level. It is expected that JDBC compliant drivers will |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
280 * be available for all the major commercial databases. |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
281 * |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
282 * This method is not intended to encourage the development of non-JDBC |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
283 * compliant drivers, but is a recognition of the fact that some vendors are |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
284 * interested in using the JDBC API and framework for lightweight databases |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
285 * that do not support full database functionality, or for special databases |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
286 * such as document information retrieval where a SQL implementation may not |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
287 * be feasible. |
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 * @return true if this driver is JDBC Compliant; false otherwise |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
290 */ |
144
d6abd1ffffbb
Use SQLNonTransientConnectionException instead of SQLException where applicable (SQLState starts with 08)
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
90
diff
changeset
|
291 @Override |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
292 public boolean jdbcCompliant() { |
295
003ae6d881db
Add "final" keyword to method arguments and local variables where possible.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
262
diff
changeset
|
293 // We're not fully JDBC compliant, but what we support is compliant |
003ae6d881db
Add "final" keyword to method arguments and local variables where possible.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
262
diff
changeset
|
294 return false; |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
295 } |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
296 |
144
d6abd1ffffbb
Use SQLNonTransientConnectionException instead of SQLException where applicable (SQLState starts with 08)
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
90
diff
changeset
|
297 /** |
d6abd1ffffbb
Use SQLNonTransientConnectionException instead of SQLException where applicable (SQLState starts with 08)
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
90
diff
changeset
|
298 * Return the parent Logger of all the Loggers used by this data source. |
d6abd1ffffbb
Use SQLNonTransientConnectionException instead of SQLException where applicable (SQLState starts with 08)
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
90
diff
changeset
|
299 * This should be the Logger farthest from the root Logger that is |
d6abd1ffffbb
Use SQLNonTransientConnectionException instead of SQLException where applicable (SQLState starts with 08)
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
90
diff
changeset
|
300 * still an ancestor of all of the Loggers used by this data source. |
d6abd1ffffbb
Use SQLNonTransientConnectionException instead of SQLException where applicable (SQLState starts with 08)
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
90
diff
changeset
|
301 * Configuring this Logger will affect all of the log messages |
d6abd1ffffbb
Use SQLNonTransientConnectionException instead of SQLException where applicable (SQLState starts with 08)
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
90
diff
changeset
|
302 * generated by the data source. |
d6abd1ffffbb
Use SQLNonTransientConnectionException instead of SQLException where applicable (SQLState starts with 08)
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
90
diff
changeset
|
303 * In the worst case, this may be the root Logger. |
d6abd1ffffbb
Use SQLNonTransientConnectionException instead of SQLException where applicable (SQLState starts with 08)
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
90
diff
changeset
|
304 * |
d6abd1ffffbb
Use SQLNonTransientConnectionException instead of SQLException where applicable (SQLState starts with 08)
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
90
diff
changeset
|
305 * @return the parent Logger for this data source |
d6abd1ffffbb
Use SQLNonTransientConnectionException instead of SQLException where applicable (SQLState starts with 08)
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
90
diff
changeset
|
306 * @throws SQLFeatureNotSupportedException if the data source does |
d6abd1ffffbb
Use SQLNonTransientConnectionException instead of SQLException where applicable (SQLState starts with 08)
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
90
diff
changeset
|
307 * not use java.util.logging |
d6abd1ffffbb
Use SQLNonTransientConnectionException instead of SQLException where applicable (SQLState starts with 08)
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
90
diff
changeset
|
308 * @since 1.7 |
d6abd1ffffbb
Use SQLNonTransientConnectionException instead of SQLException where applicable (SQLState starts with 08)
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
90
diff
changeset
|
309 */ |
d6abd1ffffbb
Use SQLNonTransientConnectionException instead of SQLException where applicable (SQLState starts with 08)
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
90
diff
changeset
|
310 @Override |
295
003ae6d881db
Add "final" keyword to method arguments and local variables where possible.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
262
diff
changeset
|
311 public java.util.logging.Logger getParentLogger() throws SQLFeatureNotSupportedException { |
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
|
312 throw MonetWrapper.newSQLFeatureNotSupportedException("getParentLogger"); |
144
d6abd1ffffbb
Use SQLNonTransientConnectionException instead of SQLException where applicable (SQLState starts with 08)
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
90
diff
changeset
|
313 } |
d6abd1ffffbb
Use SQLNonTransientConnectionException instead of SQLException where applicable (SQLState starts with 08)
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
90
diff
changeset
|
314 |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
315 //== end methods of interface driver |
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 |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
318 /** A static Map containing the mapping between MonetDB types and Java SQL types */ |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
319 /* use SELECT sqlname, * FROM sys.types order by 1, id; to view all MonetDB types */ |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
320 /* see http://docs.oracle.com/javase/7/docs/api/java/sql/Types.html to view all supported java SQL types */ |
295
003ae6d881db
Add "final" keyword to method arguments and local variables where possible.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
262
diff
changeset
|
321 private static final java.util.Map<String, Integer> typeMap = new java.util.HashMap<String, Integer>(); |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
322 static { |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
323 // fill the typeMap once |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
324 // typeMap.put("any", Integer.valueOf(Types.???)); |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
325 typeMap.put("bigint", Integer.valueOf(Types.BIGINT)); |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
326 typeMap.put("blob", Integer.valueOf(Types.BLOB)); |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
327 typeMap.put("boolean", Integer.valueOf(Types.BOOLEAN)); |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
328 typeMap.put("char", Integer.valueOf(Types.CHAR)); |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
329 typeMap.put("clob", Integer.valueOf(Types.CLOB)); |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
330 typeMap.put("date", Integer.valueOf(Types.DATE)); |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
331 typeMap.put("decimal", Integer.valueOf(Types.DECIMAL)); |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
332 typeMap.put("double", Integer.valueOf(Types.DOUBLE)); |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
333 // typeMap.put("geometry", Integer.valueOf(Types.???)); |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
334 // typeMap.put("geometrya", Integer.valueOf(Types.???)); |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
335 typeMap.put("hugeint", Integer.valueOf(Types.NUMERIC)); |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
336 typeMap.put("inet", Integer.valueOf(Types.VARCHAR)); |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
337 typeMap.put("int", Integer.valueOf(Types.INTEGER)); |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
338 typeMap.put("json", Integer.valueOf(Types.VARCHAR)); |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
339 // typeMap.put("mbr", Integer.valueOf(Types.???)); |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
340 typeMap.put("month_interval", Integer.valueOf(Types.INTEGER)); |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
341 typeMap.put("oid", Integer.valueOf(Types.BIGINT)); |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
342 // typeMap.put("ptr", Integer.valueOf(Types.???)); |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
343 typeMap.put("real", Integer.valueOf(Types.REAL)); |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
344 typeMap.put("sec_interval", Integer.valueOf(Types.DECIMAL)); |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
345 typeMap.put("smallint", Integer.valueOf(Types.SMALLINT)); |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
346 // typeMap.put("table", Integer.valueOf(Types.???)); |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
347 typeMap.put("time", Integer.valueOf(Types.TIME)); |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
348 typeMap.put("timestamp", Integer.valueOf(Types.TIMESTAMP)); |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
349 typeMap.put("timestamptz", Integer.valueOf(Types.TIMESTAMP)); |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
350 // new in Java 8: Types.TIMESTAMP_WITH_TIMEZONE (value 2014). Can't use it yet as we compile for java 7 |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
351 typeMap.put("timetz", Integer.valueOf(Types.TIME)); |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
352 // new in Java 8: Types.TIME_WITH_TIMEZONE (value 2013). Can't use it yet as we compile for java 7 |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
353 typeMap.put("tinyint", Integer.valueOf(Types.TINYINT)); |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
354 typeMap.put("url", Integer.valueOf(Types.VARCHAR)); |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
355 typeMap.put("uuid", Integer.valueOf(Types.VARCHAR)); |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
356 typeMap.put("varchar", Integer.valueOf(Types.VARCHAR)); |
144
d6abd1ffffbb
Use SQLNonTransientConnectionException instead of SQLException where applicable (SQLState starts with 08)
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
90
diff
changeset
|
357 typeMap.put("wrd", Integer.valueOf(Types.BIGINT)); // keep it in for older MonetDB servers |
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 /** |
223
e8139dbe3883
Rename internal method MonetDriver.getJavaType() into MonetDriver.getJdbcSQLType()
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
200
diff
changeset
|
361 * Returns the java.sql.Types equivalent of the given MonetDB type name. |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
362 * |
223
e8139dbe3883
Rename internal method MonetDriver.getJavaType() into MonetDriver.getJdbcSQLType()
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
200
diff
changeset
|
363 * @param type the SQL data type name as used by MonetDB |
e8139dbe3883
Rename internal method MonetDriver.getJavaType() into MonetDriver.getJdbcSQLType()
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
200
diff
changeset
|
364 * @return the matching java.sql.Types constant or |
e8139dbe3883
Rename internal method MonetDriver.getJavaType() into MonetDriver.getJdbcSQLType()
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
200
diff
changeset
|
365 * java.sql.Types.OTHER if nothing matched the given type name |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
366 */ |
295
003ae6d881db
Add "final" keyword to method arguments and local variables where possible.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
262
diff
changeset
|
367 static final int getJdbcSQLType(final String type) { |
223
e8139dbe3883
Rename internal method MonetDriver.getJavaType() into MonetDriver.getJdbcSQLType()
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
200
diff
changeset
|
368 // find the column type name in the typeMap |
295
003ae6d881db
Add "final" keyword to method arguments and local variables where possible.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
262
diff
changeset
|
369 final Integer tp = typeMap.get(type); |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
370 if (tp != null) { |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
371 return tp.intValue(); |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
372 } |
223
e8139dbe3883
Rename internal method MonetDriver.getJavaType() into MonetDriver.getJdbcSQLType()
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
200
diff
changeset
|
373 // When type name is not found in the map, for instance |
e8139dbe3883
Rename internal method MonetDriver.getJavaType() into MonetDriver.getJdbcSQLType()
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
200
diff
changeset
|
374 // when it is a new type (not yet added in the above typeMap) or |
e8139dbe3883
Rename internal method MonetDriver.getJavaType() into MonetDriver.getJdbcSQLType()
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
200
diff
changeset
|
375 // when type name is: any or geometry or geometrya or mbr or ptr or table. |
e8139dbe3883
Rename internal method MonetDriver.getJavaType() into MonetDriver.getJdbcSQLType()
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
200
diff
changeset
|
376 return Types.OTHER; |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
377 } |
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 * Returns a String usable in an SQL statement to map the server types |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
381 * to values of java.sql.Types using the global static type map. |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
382 * The returned string will be a SQL CASE x statement where the x is |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
383 * replaced with the given column name (or expression) string. |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
384 * |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
385 * @param column a String representing the value that should be evaluated |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
386 * in the SQL CASE statement |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
387 * @return a SQL CASE statement |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
388 */ |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
389 private static String TypeMapppingSQL = null; // cache to optimise getSQLTypeMap() |
295
003ae6d881db
Add "final" keyword to method arguments and local variables where possible.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
262
diff
changeset
|
390 static final String getSQLTypeMap(final String column) { |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
391 if (TypeMapppingSQL == null) { |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
392 // first time, compose TypeMappping SQL string |
295
003ae6d881db
Add "final" keyword to method arguments and local variables where possible.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
262
diff
changeset
|
393 final StringBuilder val = new StringBuilder((typeMap.size() * (7 + 7 + 7 + 4)) + 14); |
8
a27ee2cb14a0
Replace String methods equals("") and "".equals( with isEmpty()
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
0
diff
changeset
|
394 for (Entry<String, Integer> entry : typeMap.entrySet()) { |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
395 val.append(" WHEN '").append(entry.getKey()).append("' THEN ").append(entry.getValue().toString()); |
8
a27ee2cb14a0
Replace String methods equals("") and "".equals( with isEmpty()
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
0
diff
changeset
|
396 } |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
397 val.append(" ELSE ").append(Types.OTHER).append(" END"); |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
398 // as the typeMap is static, cache this SQL part for all next calls |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
399 TypeMapppingSQL = val.toString(); |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
400 } |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
401 return "CASE " + column + TypeMapppingSQL; |
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 |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
404 /** |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
405 * Returns a touched up identifying version string of this driver. |
295
003ae6d881db
Add "final" keyword to method arguments and local variables where possible.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
262
diff
changeset
|
406 * It is made public as it is called from nl/cwi/monetdb/client/JdbcClient.java |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
407 * @return the version string |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
408 */ |
295
003ae6d881db
Add "final" keyword to method arguments and local variables where possible.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
262
diff
changeset
|
409 public static final String getDriverVersion() { |
180
fdf4c888d5b7
Small code and layout improvements
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
175
diff
changeset
|
410 return DRIVERMAJOR + "." + DRIVERMINOR + " (" + DRIVERVERSIONSUFFIX + ")"; |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
411 } |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
412 |
295
003ae6d881db
Add "final" keyword to method arguments and local variables where possible.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
262
diff
changeset
|
413 static final int getDriverMajorVersion() { |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
414 return DRIVERMAJOR; |
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 |
295
003ae6d881db
Add "final" keyword to method arguments and local variables where possible.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
262
diff
changeset
|
417 static final int getDriverMinorVersion() { |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
418 return DRIVERMINOR; |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
419 } |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
420 } |