diff 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
line wrap: on
line diff
--- a/src/main/java/nl/cwi/monetdb/jdbc/MonetDriver.java.in
+++ b/src/main/java/nl/cwi/monetdb/jdbc/MonetDriver.java.in
@@ -16,6 +16,7 @@ import java.sql.DriverManager;
 import java.sql.DriverPropertyInfo;
 import java.sql.SQLException;
 import java.sql.SQLFeatureNotSupportedException;
+import java.sql.SQLNonTransientConnectionException;
 import java.sql.Types;
 import java.util.ArrayList;
 import java.util.List;
@@ -83,6 +84,7 @@ final public class MonetDriver implement
 	 * @param url the URL of the database
 	 * @return true if this driver understands the given URL; false otherwise
 	 */
+	@Override
 	public boolean acceptsURL(String url) {
 		return url != null && url.startsWith(MONETURL);
 	}
@@ -108,6 +110,7 @@ final public class MonetDriver implement
 	 * @return a Connection object that represents a connection to the URL
 	 * @throws SQLException if a database access error occurs
 	 */
+	@Override
 	public Connection connect(String url, Properties info)
 		throws SQLException
 	{
@@ -124,19 +127,19 @@ final public class MonetDriver implement
 
 		// url should be of style jdbc:monetdb://<host>/<database>
 		if (!acceptsURL(url))
-			throw new SQLException("Invalid URL: it does not start with: " + MONETURL, "08M26");
+			throw new SQLNonTransientConnectionException("Invalid URL: it does not start with: " + MONETURL, "08M26");
 
 		// remove leading "jdbc:" so the rest is a valid hierarchical URI
 		URI uri;
 		try {
 			uri = new URI(url.substring(5));
 		} catch (URISyntaxException e) {
-			throw new SQLException(e.toString(), "08M26");
+			throw new SQLNonTransientConnectionException(e.toString(), "08M26");
 		}
 
 		String uri_host = uri.getHost();
 		if (uri_host == null)
-			throw new SQLException("Invalid URL: no hostname given or unparsable in '" + url + "'", "08M26");
+			throw new SQLNonTransientConnectionException("Invalid URL: no hostname given or unparsable in '" + url + "'", "08M26");
 		info.put("host", uri_host);
 
 		int uri_port = uri.getPort();
@@ -171,6 +174,7 @@ final public class MonetDriver implement
 	 *
 	 * @return this driver's major version number
 	 */
+	@Override
 	public int getMajorVersion() {
 		return DRIVERMAJOR;
 	}
@@ -180,6 +184,7 @@ final public class MonetDriver implement
 	 *
 	 * @return this driver's minor version number
 	 */
+	@Override
 	public int getMinorVersion() {
 		return DRIVERMINOR;
 	}
@@ -201,6 +206,7 @@ final public class MonetDriver implement
 	 *         properties. This array may be an empty array if no properties
 	 *         are required.
 	 */
+	@Override
 	public DriverPropertyInfo[] getPropertyInfo(String url, Properties info) {
 		if (!acceptsURL(url))
 			return null;
@@ -274,10 +280,29 @@ final public class MonetDriver implement
 	 *
 	 * @return true if this driver is JDBC Compliant; false otherwise
 	 */
+	@Override
 	public boolean jdbcCompliant() {
 		return MONETJDBCCOMPLIANT;
 	}
 
+	/**
+	 * Return the parent Logger of all the Loggers used by this data source.
+	 * This should be the Logger farthest from the root Logger that is
+	 * still an ancestor of all of the Loggers used by this data source.
+	 * Configuring this Logger will affect all of the log messages
+	 * generated by the data source.
+	 * In the worst case, this may be the root Logger.
+	 *
+	 * @return the parent Logger for this data source
+	 * @throws SQLFeatureNotSupportedException if the data source does
+	 *         not use java.util.logging
+	 * @since 1.7
+	 */
+	@Override
+	public Logger getParentLogger() throws SQLFeatureNotSupportedException {
+		throw new SQLFeatureNotSupportedException("java.util.logging not in use", "0A000");
+	}
+
 	//== end methods of interface driver
 
 
@@ -320,7 +345,7 @@ final public class MonetDriver implement
 		typeMap.put("url", Integer.valueOf(Types.VARCHAR));
 		typeMap.put("uuid", Integer.valueOf(Types.VARCHAR));
 		typeMap.put("varchar", Integer.valueOf(Types.VARCHAR));
-		typeMap.put("wrd", Integer.valueOf(Types.BIGINT));
+		typeMap.put("wrd", Integer.valueOf(Types.BIGINT));  // keep it in for older MonetDB servers
 	}
 
 	/**
@@ -384,20 +409,4 @@ final public class MonetDriver implement
 	public static int getDriverMinorVersion() {
 		return DRIVERMINOR;
 	}
-
-	/**
-	 * Return the parent Logger of all the Loggers used by this data
-	 * source.  This should be the Logger farthest from the root Logger
-	 * that is still an ancestor of all of the Loggers used by this data
-	 * source.  Configuring this Logger will affect all of the log
-	 * messages generated by the data source. In the worst case, this
-	 * may be the root Logger.
-	 *
-	 * @return the parent Logger for this data source
-	 * @throws SQLFeatureNotSupportedException if the data source does
-	 *         not use java.util.logging
-	 */
-	public Logger getParentLogger() throws SQLFeatureNotSupportedException {
-		throw new SQLFeatureNotSupportedException("java.util.logging not in use", "0A000");
-	}
 }