Mercurial > hg > monetdb-java
diff src/main/java/nl/cwi/monetdb/jdbc/MonetDriver.java.in @ 172:60063c67f9e7 embedded
Merged with default
author | Pedro Ferreira <pedro.ferreira@monetdbsolutions.com> |
---|---|
date | Tue, 19 Sep 2017 13:49:34 +0200 (2017-09-19) |
parents | 477c4de0eda2 d6abd1ffffbb |
children | 89c285fc0a49 |
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 @@ -15,6 +15,7 @@ import nl.cwi.monetdb.mcl.protocol.Proto import java.io.IOException; import java.lang.reflect.InvocationTargetException; +import java.net.SocketException; import java.net.URI; import java.net.URISyntaxException; import java.sql.Connection; @@ -23,6 +24,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.*; import java.util.Map.Entry; @@ -91,6 +93,7 @@ public final 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); } @@ -100,6 +103,7 @@ public final class MonetDriver implement * * @return this driver's major version number */ + @Override public int getMajorVersion() { return DRIVERMAJOR; } @@ -109,6 +113,7 @@ public final class MonetDriver implement * * @return this driver's minor version number */ + @Override public int getMinorVersion() { return DRIVERMINOR; } @@ -128,6 +133,7 @@ public final class MonetDriver implement * @return an array of DriverPropertyInfo objects describing possible 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; @@ -196,6 +202,7 @@ public final class MonetDriver implement * * @return true if this driver is JDBC Compliant; false otherwise */ + @Override public boolean jdbcCompliant() { return MONETJDBCCOMPLIANT; } @@ -302,16 +309,17 @@ public final class MonetDriver implement } /** - * 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 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"); } @@ -331,9 +339,8 @@ public final class MonetDriver implement * "password" properties should be included in the Properties object. * * @param url the URL of the database to which to connect - * @param info a list of arbitrary string tag/value pairs as connection - * arguments. Normally at least a "user" and "password" property - * should be included + * @param info a list of arbitrary string tag/value pairs as connection arguments. Normally at least a "user" and + * "password" property should be included * @return a Connection object that represents a connection to the URL * @throws SQLException if a database access error occurs */ @@ -415,7 +422,7 @@ public final class MonetDriver implement if(embeddedConnectionClass == null) { embeddedConnectionClass = Class.forName("nl.cwi.monetdb.embedded.jdbc.EmbeddedConnection"); if(embeddedConnectionClass == null) { //if it is still null then there is a problem! - throw new SQLException("EmbeddedConnection Class not found! Please add monetdb-java-lite jar to the CLASSPATH"); + throw new SQLNonTransientConnectionException("EmbeddedConnection Class not found! Please add monetdb-java-lite jar to the CLASSPATH"); } } res = (MonetConnection) embeddedConnectionClass @@ -423,7 +430,7 @@ public final class MonetDriver implement .newInstance(props, hash, language, directory); } catch (InvocationTargetException | InstantiationException | IllegalAccessException | NoSuchMethodException | ClassNotFoundException e) { - throw new SQLException(e); + throw new SQLNonTransientConnectionException(e); } } else { String hostname = props.getProperty("host"); @@ -468,11 +475,7 @@ public final class MonetDriver implement sockTimeout = 0; props.setProperty("so_timeout", "0"); } - try { - res = new MapiConnection(props, hash, language, blobIsBinary, clobIsLongChar, hostname, port, database); - } catch (IOException e) { - throw new SQLException(e); - } + res = new MapiConnection(props, hash, language, blobIsBinary, clobIsLongChar, hostname, port, database); if(failedparse1) { res.addWarning("Unable to parse port number from: " + port, "M1M05"); } @@ -485,7 +488,11 @@ public final class MonetDriver implement if(negative2) { res.addWarning("Negative socket timeout not allowed. Value ignored", "M1M05"); } - res.setSoTimeout(sockTimeout); + try { + res.setSoTimeout(sockTimeout); + } catch(SocketException ex) { + res.addWarning("Failed to set socket timeout: " + ex.getMessage(), "M1M05"); + } } try { //attempt to connect and authenticate the user @@ -505,15 +512,15 @@ public final class MonetDriver implement throw new SQLException("Unable to connect (" + con.getHostname() + ":" + con.getPort() + "): " + e.getMessage(), "08006"); } else { - throw new SQLException("Unable to connect: " + e.getMessage(), "08006"); + throw new SQLNonTransientConnectionException("Unable to connect: " + e.getMessage(), "08006"); } } catch (ProtocolException e) { - throw new SQLException(e.getMessage(), "08001"); + throw new SQLNonTransientConnectionException(e.getMessage(), "08001"); } catch (MCLException e) { String[] connex = e.getMessage().split("\n"); - SQLException sqle = new SQLException(connex[0], "08001", e); + SQLException sqle = new SQLNonTransientConnectionException(connex[0], "08001", e); for (int i = 1; i < connex.length; i++) { - sqle.setNextException(new SQLException(connex[1], "08001")); + sqle.setNextException(new SQLNonTransientConnectionException(connex[1], "08001")); } throw sqle; }