Changeset: d6abd1ffffbb for monetdb-java URL: https://dev.monetdb.org/hg/monetdb-java?cmd=changeset;node=d6abd1ffffbb Modified Files: SQLSTATEs src/main/java/nl/cwi/monetdb/jdbc/MonetConnection.java src/main/java/nl/cwi/monetdb/jdbc/MonetDriver.java.in src/main/java/nl/cwi/monetdb/jdbc/MonetPreparedStatement.java src/main/java/nl/cwi/monetdb/jdbc/MonetResultSet.java src/main/java/nl/cwi/monetdb/jdbc/types/INET.java src/main/java/nl/cwi/monetdb/jdbc/types/URL.java Branch: default Log Message:
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 diffs (truncated from 677 to 300 lines): diff --git a/SQLSTATEs b/SQLSTATEs --- a/SQLSTATEs +++ b/SQLSTATEs @@ -1,56 +1,69 @@ -08M01 opening logfile failed +Following SQLStates are MonetDB JDBC driver specific: 01M02 redirect warning -M0M03 illegal arguments (invalid call of internal function) 01M03 illegal arguments (invalid call of internal function) -M0M04 only supported in SQL mode -M1M05 invalid argument (user supplied) -M0M06 savepoint is not MonetSavepoint 01M07 unrecognised clientinfo property 01M08 read-only conection mode not supported 01M09 transaction mode not supported -M0M10 protocol violation/unexpected server response 01M10 unexpected server output 01M11 server-client autocommit state mismatch -M0M12 matching client handle referenced by server not found 01M13 concurrency mode not supported 01M14 scrolling mode not supported 01M15 holdability mode not supported -M1M16 multistatements not supported in batches -M1M17 result set not expected for DML or DDL-statement 01M18 generated keys for columns not supported -M1M19 response is not a result set -M1M20 object closed 01M21 cursors not supported -0AM21 cursors not supported 01M22 JDBC escape syntax not supported 01M23 field size limitation not supported 01M24 query time out not supported -M1M25 failed reading from/writing to object stream + +08M01 opening logfile failed 08M26 invalid URI -M0M27 unknown error +08M33 connection timed out + +0AM21 cursors not supported +0AM34 Java generics not supported + 22M28 invalid BLOB format -M0M29 assert +22M29 invalid inet format +22M30 invalid url format + +2BM37 dependent objects still exist +2DM30 autocommit mode active 3BM30 autocommit mode active -2DM30 autocommit mode active + 42M31 user/role already exists 42M32 user/role not found -08M33 connection timeout -0AM34 Java generics not supported 42M35 sequence not found 42M36 cannot restart sequence with NULL -2BM37 dependent objects still exist -TODO: -JDBC 4.1 suggests the following SQLException subclass mapping: -NonTransientSQLExeceptions (fails when same operation executed again) -0A SQLFeatureNotSupportedException -08 SQLNonTransientConnectionException -22 SQLDataException -23 SQLIntegrityConstraintViolationException -28 SQLInvalidAuthorizationException -42 SQLSyntaxErrorException -TransientSQLExeceptions (retry of same operation might succeed) -08 SQLTransientConnectionException -40 SQLTransactionRollbackException - SQLTimeoutException +M0M03 illegal arguments (invalid call of internal function) +M0M04 only supported in SQL mode +M0M06 savepoint is not MonetSavepoint +M0M10 protocol violation/unexpected server response +M0M12 matching client handle referenced by server not found +M0M27 unknown error +M0M29 assert +M1M05 invalid argument (user supplied) +M1M16 multistatements not supported in batches +M1M17 result set not expected for DML or DDL-statement +M1M19 response is not a result set +M1M20 object closed +M1M25 failed reading from/writing to object stream + +SQLState codes are used in SQLExceptions. +JDBC 4.1 defines the following SQLException subclass mappings: + NonTransientSQLExceptions (fails when same operation executed again) + 0A SQLFeatureNotSupportedException + 08 SQLNonTransientConnectionException + 22 SQLDataException + 23 SQLIntegrityConstraintViolationException + 28 SQLInvalidAuthorizationSpecException + 42 SQLSyntaxErrorException + TransientSQLExeceptions (retry of same operation might succeed) + 08 SQLTransientConnectionException + 40 SQLTransactionRollbackException + null SQLTimeoutException + +See also: http://docs.oracle.com/javase/7/docs/api/java/sql/SQLException.html +See also: https://en.wikibooks.org/wiki/Structured_Query_Language/SQLSTATE + diff --git a/src/main/java/nl/cwi/monetdb/jdbc/MonetConnection.java b/src/main/java/nl/cwi/monetdb/jdbc/MonetConnection.java --- a/src/main/java/nl/cwi/monetdb/jdbc/MonetConnection.java +++ b/src/main/java/nl/cwi/monetdb/jdbc/MonetConnection.java @@ -19,6 +19,7 @@ import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.SQLFeatureNotSupportedException; +import java.sql.SQLNonTransientConnectionException; import java.sql.SQLWarning; import java.sql.Savepoint; import java.sql.Statement; @@ -260,7 +261,7 @@ public class MonetConnection extends Mon server.debug(f.getAbsolutePath()); } catch (IOException ex) { - throw new SQLException("Opening logfile failed: " + ex.getMessage(), "08M01"); + throw new SQLNonTransientConnectionException("Opening logfile failed: " + ex.getMessage(), "08M01"); } } @@ -279,16 +280,16 @@ public class MonetConnection extends Mon String error = in.waitForPrompt(); if (error != null) - throw new SQLException((error.length() > 6) ? error.substring(6) : error, "08001"); + throw new SQLNonTransientConnectionException((error.length() > 6) ? error.substring(6) : error, "08001"); } catch (IOException e) { - throw new SQLException("Unable to connect (" + hostname + ":" + port + "): " + e.getMessage(), "08006"); + throw new SQLNonTransientConnectionException("Unable to connect (" + hostname + ":" + port + "): " + e.getMessage(), "08006"); } catch (MCLParseException 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; } @@ -681,7 +682,7 @@ public class MonetConnection extends Mon * default result set type and concurrency to be overridden. * * @param sql a String object that is the SQL statement to be sent to the - * database; may contain one or more ? IN parameters + * database; may contain one or more ? IN parameters * @param resultSetType a result set type; one of * ResultSet.TYPE_FORWARD_ONLY, ResultSet.TYPE_SCROLL_INSENSITIVE, * or ResultSet.TYPE_SCROLL_SENSITIVE @@ -691,8 +692,8 @@ public class MonetConnection extends Mon * statement that will produce ResultSet objects with the given * type and concurrency * @throws SQLException if a database access error occurs or the given - * parameters are not ResultSet constants indicating - * type and concurrency + * parameters are not ResultSet constants indicating + * type and concurrency */ @Override public PreparedStatement prepareStatement(String sql, int resultSetType, int resultSetConcurrency) throws SQLException { @@ -1507,7 +1508,7 @@ public class MonetConnection extends Mon try { server.setSoTimeout(millis); } catch (SocketException e) { - throw new SQLException(e.getMessage(), "08000"); + throw new SQLNonTransientConnectionException(e.getMessage(), "08000"); } } @@ -1530,7 +1531,7 @@ public class MonetConnection extends Mon try { return server.getSoTimeout(); } catch (SocketException e) { - throw new SQLException(e.getMessage(), "08000"); + throw new SQLNonTransientConnectionException(e.getMessage(), "08000"); } } @@ -1546,8 +1547,7 @@ public class MonetConnection extends Mon String language = ""; if (lang == LANG_MAL) language = "?language=mal"; - return "jdbc:monetdb://" + hostname + ":" + port + "/" + - database + language; + return "jdbc:monetdb://" + hostname + ":" + port + "/" + database + language; } /** @@ -1595,13 +1595,12 @@ public class MonetConnection extends Mon (queryTempl[1] == null ? "" : queryTempl[1])); String error = in.waitForPrompt(); if (error != null) - throw new SQLException(error.substring(6), - error.substring(0, 5)); + throw new SQLException(error.substring(6), error.substring(0, 5)); } catch (SocketTimeoutException e) { close(); // JDBC 4.1 semantics: abort() - throw new SQLException("connection timed out", "08M33"); + throw new SQLNonTransientConnectionException("connection timed out", "08M33"); } catch (IOException e) { - throw new SQLException(e.getMessage(), "08000"); + throw new SQLNonTransientConnectionException(e.getMessage(), "08000"); } } } @@ -1625,13 +1624,12 @@ public class MonetConnection extends Mon (commandTempl[1] == null ? "" : commandTempl[1])); String error = in.waitForPrompt(); if (error != null) - throw new SQLException(error.substring(6), - error.substring(0, 5)); + throw new SQLException(error.substring(6), error.substring(0, 5)); } catch (SocketTimeoutException e) { close(); // JDBC 4.1 semantics, abort() - throw new SQLException("connection timed out", "08M33"); + throw new SQLNonTransientConnectionException("connection timed out", "08M33"); } catch (IOException e) { - throw new SQLException(e.getMessage(), "08000"); + throw new SQLNonTransientConnectionException(e.getMessage(), "08000"); } } } @@ -1771,7 +1769,7 @@ public class MonetConnection extends Mon * @param columncount the number of columns in the result set * @param rowcount the number of rows in the current block * @param parent the parent that created this Response and will - * supply new result blocks when necessary + * supply new result blocks when necessary * @param seq the query sequence number */ ResultSetResponse( @@ -1929,7 +1927,7 @@ public class MonetConnection extends Mon * needs to be consistent with regard to its internal data. * * @throws SQLException if the data currently in this Response is not - * sufficient to be consistant + * sufficient to be consistant */ @Override public void complete() throws SQLException { @@ -2727,23 +2725,26 @@ public class MonetConnection extends Mon SQLException ret = null; String[] errors = error.split("\n"); for (int i = 0; i < errors.length; i++) { + SQLException newErr; + if (errors[i].length() >= 6) { + newErr = new SQLException(errors[i].substring(6), errors[i].substring(0, 5)); + } else { + newErr = new SQLNonTransientConnectionException(errors[i], "08000"); + } if (ret == null) { - ret = new SQLException(errors[i].substring(6), - errors[i].substring(0, 5)); + ret = newErr; } else { - ret.setNextException(new SQLException( - errors[i].substring(6), - errors[i].substring(0, 5))); + ret.setNextException(newErr); } } throw ret; } } catch (SocketTimeoutException e) { close(); // JDBC 4.1 semantics, abort() - throw new SQLException("connection timed out", "08M33"); + throw new SQLNonTransientConnectionException("connection timed out", "08M33"); } catch (IOException e) { closed = true; - throw new SQLException(e.getMessage() + " (mserver still alive?)", "08000"); + throw new SQLNonTransientConnectionException(e.getMessage() + " (mserver5 still alive?)", "08006"); } } } diff --git a/src/main/java/nl/cwi/monetdb/jdbc/MonetDriver.java.in b/src/main/java/nl/cwi/monetdb/jdbc/MonetDriver.java.in --- 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); } _______________________________________________ checkin-list mailing list [email protected] https://www.monetdb.org/mailman/listinfo/checkin-list
