Changeset: 6eb2dba25f32 for MonetDB URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=6eb2dba25f32 Modified Files: java/ChangeLog.Dec2011 java/SQLSTATEs java/src/nl/cwi/monetdb/jdbc/MonetConnection.java java/src/nl/cwi/monetdb/jdbc/MonetDatabaseMetaData.java java/src/nl/cwi/monetdb/jdbc/MonetResultSet.java java/src/nl/cwi/monetdb/jdbc/MonetStatement.java Branch: Dec2011 Log Message:
JDBC: implemented JDBC 4.1 methods We can now compile JDBC with Java 7 as well. TODO: check and apply all changes from the JDBC 4.1 specification. diffs (truncated from 393 to 300 lines): diff --git a/java/ChangeLog.Dec2011 b/java/ChangeLog.Dec2011 --- a/java/ChangeLog.Dec2011 +++ b/java/ChangeLog.Dec2011 @@ -1,6 +1,12 @@ # ChangeLog file for java # This file is updated with Maddlog +* Mon Dec 19 2011 Fabian Groffen <[email protected]> +- JDBC now implementd JDBCv4.1 which makes it possible to be built with + Java 7 and up. JDBCv4.1 is a maintenance release of JDBCv4, and hence + can be compiled with Java 6, although the added methods obviously are + not part of the java.sql interfaces. + * Sun Dec 11 2011 Fabian Groffen <[email protected]> - SQLExceptions thrown now carry a SQLSTATE. Until the server starts sending correct SQLSTATEs for all errors, server originated errors diff --git a/java/SQLSTATEs b/java/SQLSTATEs --- a/java/SQLSTATEs +++ b/java/SQLSTATEs @@ -35,6 +35,7 @@ 2DM30 autocommit mode active 42M31 user/role already exists 42M32 user/role not found 08M33 connection timeout +0AM34 Java generics not supported TODO: JDBC 4.1 suggests the following SQLException subclass mapping: diff --git a/java/src/nl/cwi/monetdb/jdbc/MonetConnection.java b/java/src/nl/cwi/monetdb/jdbc/MonetConnection.java --- a/java/src/nl/cwi/monetdb/jdbc/MonetConnection.java +++ b/java/src/nl/cwi/monetdb/jdbc/MonetConnection.java @@ -2192,8 +2192,9 @@ public class MonetConnection extends Mon */ void closeResponse(int i) { if (i < 0 || i >= responses.size()) return; - Response tmp = (Response)(responses.get(i)); - if (tmp != null) tmp.close(); + Response tmp = (Response)(responses.set(i, null)); + if (tmp != null) + tmp.close(); } /** @@ -2223,6 +2224,18 @@ public class MonetConnection extends Mon } /** + * Returns whether this ResponseList has still unclosed + * Responses. + */ + boolean hasUnclosedResponses() { + for (int i = 0; i < responses.size(); i++) { + if (responses.get(i) != null) + return(true); + } + return(false); + } + + /** * Executes the query contained in this ResponseList, and * stores the Responses resulting from this query in this * ResponseList. diff --git a/java/src/nl/cwi/monetdb/jdbc/MonetDatabaseMetaData.java b/java/src/nl/cwi/monetdb/jdbc/MonetDatabaseMetaData.java --- a/java/src/nl/cwi/monetdb/jdbc/MonetDatabaseMetaData.java +++ b/java/src/nl/cwi/monetdb/jdbc/MonetDatabaseMetaData.java @@ -3060,7 +3060,7 @@ public class MonetDatabaseMetaData exten * @return JDBC version major number */ public int getJDBCMajorVersion() { - return(4); // This class implements JDBC 4.0 (at least we try to) + return(4); // This class implements JDBC 4.1 (at least we try to) } /** @@ -3070,7 +3070,7 @@ public class MonetDatabaseMetaData exten * @return JDBC version minor number */ public int getJDBCMinorVersion() { - return(0); // This class implements JDBC 4.0 (at least we try to) + return(1); // This class implements JDBC 4.1 (at least we try to) } /** diff --git a/java/src/nl/cwi/monetdb/jdbc/MonetResultSet.java b/java/src/nl/cwi/monetdb/jdbc/MonetResultSet.java --- a/java/src/nl/cwi/monetdb/jdbc/MonetResultSet.java +++ b/java/src/nl/cwi/monetdb/jdbc/MonetResultSet.java @@ -249,6 +249,8 @@ public class MonetResultSet extends Mone if (!header.isClosed()) { header.close(); } + if (statement instanceof MonetStatement) + ((MonetStatement)statement).closeIfCompletion(); } // Chapter 14.2.3 from Sun JDBC 3.0 specification @@ -1434,15 +1436,25 @@ public class MonetResultSet extends Mone * value * @throws SQLException if a database access error occurs */ - public Object getObject(int i, Map map) throws SQLException { + public Object getObject(int i, Map<String,Class<?>> map) + throws SQLException + { + Class type; + if (tlp.values[i - 1] == null) { lastColumnRead = i - 1; return(null); } - Class type = getClassForType(getJavaType(types[i - 1])); + if (map.containsKey(types[i - 1])) { + type = map.get(types[i - 1]); + } else { + type = getClassForType(getJavaType(types[i - 1])); + } - if (type == BigDecimal.class) { + if (type == String.class) { + return(getString(i)); + } else if (type == BigDecimal.class) { return(getBigDecimal(i)); } else if (type == Boolean.class) { return(Boolean.valueOf(getBoolean(i))); @@ -1454,6 +1466,8 @@ public class MonetResultSet extends Mone return(new Float(getFloat(i))); } else if (type == Double.class) { return(new Double(getDouble(i))); + } else if (type == byte[].class) { + return(getBytes(i)); } else if (type == java.sql.Date.class) { return(getDate(i)); } else if (type == Time.class) { @@ -1464,14 +1478,59 @@ public class MonetResultSet extends Mone return(getClob(i)); } else if (type == Blob.class) { return(getBlob(i)); - } else if (type == byte[].class) { - return(getBytes(i)); } else { return(getString(i)); } } /** + * Retrieves the value of the designated column in the current row + * of this ResultSet object and will convert from the SQL type of + * the column to the requested Java data type, if the conversion is + * supported. If the conversion is not supported or null is + * specified for the type, a SQLException is thrown. + * + * @param i the first column is 1, the second is 2, ... + * @param type Class representing the Java data type to convert the + * designated column to + * @return an instance of type holding the column value + * @throws SQLException if conversion is not supported, type is + * null or another error occurs. The getCause() method of + * the exception may provide a more detailed exception, for + * example, if a conversion error occurs + */ + public <T> T getObject(int i, Class<T> type) throws SQLException { + if (type == null) + throw new SQLException("type is null", "M1M05"); + + throw new SQLFeatureNotSupportedException("cannot return a Java generic type based on static types from getXXX methods", "0AM34"); + } + + /** + * Retrieves the value of the designated column in the current row + * of this ResultSet object and will convert from the SQL type of + * the column to the requested Java data type, if the conversion is + * supported. If the conversion is not supported or null is + * specified for the type, a SQLException is thrown. + * + * @param columnLabel the label for the column specified with the + * SQL AS clause. If the SQL AS clause was not specified, + * then the label is the name of the column + * @param type Class representing the Java data type to convert the + * designated column to + * @return an instance of type holding the column value + * @throws SQLException if conversion is not supported, type is + * null or another error occurs. The getCause() method of + * the exception may provide a more detailed exception, for + * example, if a conversion error occurs + */ + public <T> T getObject(String columnLabel, Class<T> type) + throws SQLException + { + return(getObject(findColumn(columnLabel), type)); + } + + /** * Helper method to support the getObject and * ResultsetMetaData.getColumnClassName JDBC methods. * @@ -1481,8 +1540,9 @@ public class MonetResultSet extends Mone static Class getClassForType(int type) { /** * This switch returns the types as objects according to table B-3 from - * Sun's JDBC specification 3.0 + * Oracle's JDBC specification 4.1 */ + // keep this switch aligned with getObject(int, Map) ! switch(type) { case Types.CHAR: case Types.VARCHAR: @@ -1505,6 +1565,10 @@ public class MonetResultSet extends Mone case Types.FLOAT: case Types.DOUBLE: return(Double.class); + case Types.BINARY: // MonetDB currently does not support these + case Types.VARBINARY: // see treat_blob_as_binary property + case Types.LONGVARBINARY: + return(byte[].class); case Types.DATE: return(java.sql.Date.class); case Types.TIME: @@ -1515,18 +1579,8 @@ public class MonetResultSet extends Mone return(Clob.class); case Types.BLOB: return(Blob.class); - case Types.BINARY: // MonetDB currently does not support these - case Types.VARBINARY: // see treat_blob_as_binary property - case Types.LONGVARBINARY: - return(byte[].class); - // all below are currently not implemented and used - case Types.DISTINCT: - case Types.ARRAY: - case Types.STRUCT: - case Types.REF: - case Types.DATALINK: - case Types.OTHER: + // all the rest are currently not implemented and used default: return(String.class); } diff --git a/java/src/nl/cwi/monetdb/jdbc/MonetStatement.java b/java/src/nl/cwi/monetdb/jdbc/MonetStatement.java --- a/java/src/nl/cwi/monetdb/jdbc/MonetStatement.java +++ b/java/src/nl/cwi/monetdb/jdbc/MonetStatement.java @@ -62,6 +62,9 @@ public class MonetStatement extends Mone protected boolean closed; /** Whether the application wants this Statement object to be pooled */ protected boolean poolable; + /** Whether this Statement should be closed if the last ResultSet + * closes */ + private boolean closeOnCompletion = false; /** The size of the blocks of results to ask for at the server */ private int fetchSize = 0; /** The maximum number of rows to return in a ResultSet */ @@ -316,28 +319,6 @@ public class MonetStatement extends Mone closed = true; } - /** - * Retrieves whether this Statement object has been closed. A - * Statement is closed if the method close has been called on it, or - * if it is automatically closed. - * - * @return true if this Statement object is closed; false if it is - * still open - */ - public boolean isClosed() { - return(closed); - } - - /** - * Returns a value indicating whether the Statement is poolable or - * not. - * - * @return true if the Statement is poolable; false otherwise - */ - public boolean isPoolable() { - return(poolable); - } - // Chapter 13.1.2.3 of Sun's JDBC 3.0 Specification /** * Executes the given SQL statement, which may return multiple results. In @@ -1062,6 +1043,40 @@ public class MonetStatement extends Mone } /** + * Sets the number of seconds the driver will wait for a Statement + * object to execute to the given number of seconds. If the limit is + * exceeded, an SQLException is thrown. + * <br /><br /> + * MonetDB does not support cancelling running queries, hence this + * method does not do anything. + * + * @param seconds the new query timeout limit in seconds; zero means + * there is no limit + * @throws SQLException if a database access error occurs or the + * condition seconds >= 0 is not satisfied + */ + public void setQueryTimeout(int seconds) throws SQLException { + if (seconds < 0) + throw new SQLException("Illegal timeout value: " + seconds, "M1M05"); + if (seconds > 0) + addWarning("setQueryTimeout: query time outs not supported", "01M24"); + } _______________________________________________ Checkin-list mailing list [email protected] http://mail.monetdb.org/mailman/listinfo/checkin-list
