Mercurial > hg > monetdb-java
comparison src/main/java/nl/cwi/monetdb/jdbc/MonetDriver.java.in @ 144:d6abd1ffffbb
Use SQLNonTransientConnectionException instead of SQLException where applicable (SQLState starts with 08)
Use SQLDataException instead of SQLException where applicable (SQLState starts with 22)
Also updated documentation file: SQLSTATEs which documents the MonetDB JDBC driver specific SQLSTATEs
author | Martin van Dinther <martin.van.dinther@monetdbsolutions.com> |
---|---|
date | Thu, 03 Aug 2017 18:53:04 +0200 (2017-08-03) |
parents | b9b35ca2eec2 |
children | 60063c67f9e7 8700d9ef2ace |
comparison
equal
deleted
inserted
replaced
143:dcf7879d4862 | 144:d6abd1ffffbb |
---|---|
14 import java.sql.Driver; | 14 import java.sql.Driver; |
15 import java.sql.DriverManager; | 15 import java.sql.DriverManager; |
16 import java.sql.DriverPropertyInfo; | 16 import java.sql.DriverPropertyInfo; |
17 import java.sql.SQLException; | 17 import java.sql.SQLException; |
18 import java.sql.SQLFeatureNotSupportedException; | 18 import java.sql.SQLFeatureNotSupportedException; |
19 import java.sql.SQLNonTransientConnectionException; | |
19 import java.sql.Types; | 20 import java.sql.Types; |
20 import java.util.ArrayList; | 21 import java.util.ArrayList; |
21 import java.util.List; | 22 import java.util.List; |
22 import java.util.Map.Entry; | 23 import java.util.Map.Entry; |
23 import java.util.Properties; | 24 import java.util.Properties; |
81 * subprotocol specified in the URL and false if they do not. | 82 * subprotocol specified in the URL and false if they do not. |
82 * | 83 * |
83 * @param url the URL of the database | 84 * @param url the URL of the database |
84 * @return true if this driver understands the given URL; false otherwise | 85 * @return true if this driver understands the given URL; false otherwise |
85 */ | 86 */ |
87 @Override | |
86 public boolean acceptsURL(String url) { | 88 public boolean acceptsURL(String url) { |
87 return url != null && url.startsWith(MONETURL); | 89 return url != null && url.startsWith(MONETURL); |
88 } | 90 } |
89 | 91 |
90 /** | 92 /** |
106 * arguments. Normally at least a "user" and "password" property | 108 * arguments. Normally at least a "user" and "password" property |
107 * should be included | 109 * should be included |
108 * @return a Connection object that represents a connection to the URL | 110 * @return a Connection object that represents a connection to the URL |
109 * @throws SQLException if a database access error occurs | 111 * @throws SQLException if a database access error occurs |
110 */ | 112 */ |
113 @Override | |
111 public Connection connect(String url, Properties info) | 114 public Connection connect(String url, Properties info) |
112 throws SQLException | 115 throws SQLException |
113 { | 116 { |
114 int tmp; | 117 int tmp; |
115 Properties props = new Properties(); | 118 Properties props = new Properties(); |
122 props.putAll(info); | 125 props.putAll(info); |
123 info = props; | 126 info = props; |
124 | 127 |
125 // url should be of style jdbc:monetdb://<host>/<database> | 128 // url should be of style jdbc:monetdb://<host>/<database> |
126 if (!acceptsURL(url)) | 129 if (!acceptsURL(url)) |
127 throw new SQLException("Invalid URL: it does not start with: " + MONETURL, "08M26"); | 130 throw new SQLNonTransientConnectionException("Invalid URL: it does not start with: " + MONETURL, "08M26"); |
128 | 131 |
129 // remove leading "jdbc:" so the rest is a valid hierarchical URI | 132 // remove leading "jdbc:" so the rest is a valid hierarchical URI |
130 URI uri; | 133 URI uri; |
131 try { | 134 try { |
132 uri = new URI(url.substring(5)); | 135 uri = new URI(url.substring(5)); |
133 } catch (URISyntaxException e) { | 136 } catch (URISyntaxException e) { |
134 throw new SQLException(e.toString(), "08M26"); | 137 throw new SQLNonTransientConnectionException(e.toString(), "08M26"); |
135 } | 138 } |
136 | 139 |
137 String uri_host = uri.getHost(); | 140 String uri_host = uri.getHost(); |
138 if (uri_host == null) | 141 if (uri_host == null) |
139 throw new SQLException("Invalid URL: no hostname given or unparsable in '" + url + "'", "08M26"); | 142 throw new SQLNonTransientConnectionException("Invalid URL: no hostname given or unparsable in '" + url + "'", "08M26"); |
140 info.put("host", uri_host); | 143 info.put("host", uri_host); |
141 | 144 |
142 int uri_port = uri.getPort(); | 145 int uri_port = uri.getPort(); |
143 if (uri_port > 0) | 146 if (uri_port > 0) |
144 info.put("port", "" + uri_port); | 147 info.put("port", "" + uri_port); |
169 /** | 172 /** |
170 * Retrieves the driver's major version number. Initially this should be 1. | 173 * Retrieves the driver's major version number. Initially this should be 1. |
171 * | 174 * |
172 * @return this driver's major version number | 175 * @return this driver's major version number |
173 */ | 176 */ |
177 @Override | |
174 public int getMajorVersion() { | 178 public int getMajorVersion() { |
175 return DRIVERMAJOR; | 179 return DRIVERMAJOR; |
176 } | 180 } |
177 | 181 |
178 /** | 182 /** |
179 * Gets the driver's minor version number. Initially this should be 0. | 183 * Gets the driver's minor version number. Initially this should be 0. |
180 * | 184 * |
181 * @return this driver's minor version number | 185 * @return this driver's minor version number |
182 */ | 186 */ |
187 @Override | |
183 public int getMinorVersion() { | 188 public int getMinorVersion() { |
184 return DRIVERMINOR; | 189 return DRIVERMINOR; |
185 } | 190 } |
186 | 191 |
187 /** | 192 /** |
199 * connect open | 204 * connect open |
200 * @return an array of DriverPropertyInfo objects describing possible | 205 * @return an array of DriverPropertyInfo objects describing possible |
201 * properties. This array may be an empty array if no properties | 206 * properties. This array may be an empty array if no properties |
202 * are required. | 207 * are required. |
203 */ | 208 */ |
209 @Override | |
204 public DriverPropertyInfo[] getPropertyInfo(String url, Properties info) { | 210 public DriverPropertyInfo[] getPropertyInfo(String url, Properties info) { |
205 if (!acceptsURL(url)) | 211 if (!acceptsURL(url)) |
206 return null; | 212 return null; |
207 | 213 |
208 List<DriverPropertyInfo> props = new ArrayList<DriverPropertyInfo>(); | 214 List<DriverPropertyInfo> props = new ArrayList<DriverPropertyInfo>(); |
272 * such as document information retrieval where a SQL implementation may not | 278 * such as document information retrieval where a SQL implementation may not |
273 * be feasible. | 279 * be feasible. |
274 * | 280 * |
275 * @return true if this driver is JDBC Compliant; false otherwise | 281 * @return true if this driver is JDBC Compliant; false otherwise |
276 */ | 282 */ |
283 @Override | |
277 public boolean jdbcCompliant() { | 284 public boolean jdbcCompliant() { |
278 return MONETJDBCCOMPLIANT; | 285 return MONETJDBCCOMPLIANT; |
286 } | |
287 | |
288 /** | |
289 * Return the parent Logger of all the Loggers used by this data source. | |
290 * This should be the Logger farthest from the root Logger that is | |
291 * still an ancestor of all of the Loggers used by this data source. | |
292 * Configuring this Logger will affect all of the log messages | |
293 * generated by the data source. | |
294 * In the worst case, this may be the root Logger. | |
295 * | |
296 * @return the parent Logger for this data source | |
297 * @throws SQLFeatureNotSupportedException if the data source does | |
298 * not use java.util.logging | |
299 * @since 1.7 | |
300 */ | |
301 @Override | |
302 public Logger getParentLogger() throws SQLFeatureNotSupportedException { | |
303 throw new SQLFeatureNotSupportedException("java.util.logging not in use", "0A000"); | |
279 } | 304 } |
280 | 305 |
281 //== end methods of interface driver | 306 //== end methods of interface driver |
282 | 307 |
283 | 308 |
318 // new in Java 8: Types.TIME_WITH_TIMEZONE (value 2013). Can't use it yet as we compile for java 7 | 343 // new in Java 8: Types.TIME_WITH_TIMEZONE (value 2013). Can't use it yet as we compile for java 7 |
319 typeMap.put("tinyint", Integer.valueOf(Types.TINYINT)); | 344 typeMap.put("tinyint", Integer.valueOf(Types.TINYINT)); |
320 typeMap.put("url", Integer.valueOf(Types.VARCHAR)); | 345 typeMap.put("url", Integer.valueOf(Types.VARCHAR)); |
321 typeMap.put("uuid", Integer.valueOf(Types.VARCHAR)); | 346 typeMap.put("uuid", Integer.valueOf(Types.VARCHAR)); |
322 typeMap.put("varchar", Integer.valueOf(Types.VARCHAR)); | 347 typeMap.put("varchar", Integer.valueOf(Types.VARCHAR)); |
323 typeMap.put("wrd", Integer.valueOf(Types.BIGINT)); | 348 typeMap.put("wrd", Integer.valueOf(Types.BIGINT)); // keep it in for older MonetDB servers |
324 } | 349 } |
325 | 350 |
326 /** | 351 /** |
327 * Returns the java.sql.Types equivalent of the given MonetDB type. | 352 * Returns the java.sql.Types equivalent of the given MonetDB type. |
328 * | 353 * |
382 } | 407 } |
383 | 408 |
384 public static int getDriverMinorVersion() { | 409 public static int getDriverMinorVersion() { |
385 return DRIVERMINOR; | 410 return DRIVERMINOR; |
386 } | 411 } |
387 | |
388 /** | |
389 * Return the parent Logger of all the Loggers used by this data | |
390 * source. This should be the Logger farthest from the root Logger | |
391 * that is still an ancestor of all of the Loggers used by this data | |
392 * source. Configuring this Logger will affect all of the log | |
393 * messages generated by the data source. In the worst case, this | |
394 * may be the root Logger. | |
395 * | |
396 * @return the parent Logger for this data source | |
397 * @throws SQLFeatureNotSupportedException if the data source does | |
398 * not use java.util.logging | |
399 */ | |
400 public Logger getParentLogger() throws SQLFeatureNotSupportedException { | |
401 throw new SQLFeatureNotSupportedException("java.util.logging not in use", "0A000"); | |
402 } | |
403 } | 412 } |