Changeset: dae18490544e for MonetDB URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=dae18490544e Modified Files: java/ChangeLog java/src/main/java/nl/cwi/monetdb/jdbc/MonetConnection.java java/src/main/java/nl/cwi/monetdb/jdbc/MonetDatabaseMetaData.java Branch: default Log Message:
MonetDB does not support catalogs. Correcting methods which still return value for Catalog column. Also improved setSchema() and getSchema() by checking on null argument and closing resources properly. diffs (152 lines): diff --git a/java/ChangeLog b/java/ChangeLog --- a/java/ChangeLog +++ b/java/ChangeLog @@ -1,6 +1,10 @@ # ChangeLog file for java # This file is updated with Maddlog +* Thu Jan 28 2016 Martin van Dinther <[email protected]> +- The resultsets of DatabaseMetadata methods now no longer return a + value for the *_CAT columns as MonetDB does not support Catalogs. + * Thu Jan 7 2016 Martin van Dinther <[email protected]> - Fixed a memory leak in MonetDatabaseMetaData.java for a static cache which kept references to closed Connection objects. diff --git a/java/src/main/java/nl/cwi/monetdb/jdbc/MonetConnection.java b/java/src/main/java/nl/cwi/monetdb/jdbc/MonetConnection.java --- a/java/src/main/java/nl/cwi/monetdb/jdbc/MonetConnection.java +++ b/java/src/main/java/nl/cwi/monetdb/jdbc/MonetConnection.java @@ -111,11 +111,11 @@ public class MonetConnection extends Mon * */ private static final long serialVersionUID = 1L; - - { + { put("inet", INET.class); put("url", URL.class); - }}; + } + }; // See javadoc for documentation about WeakHashMap if you don't know what // it does !!!NOW!!! (only when you deal with it of course) @@ -615,17 +615,8 @@ public class MonetConnection extends Mon */ @Override public String getCatalog() throws SQLException { - if (lang != LANG_SQL) - throw new SQLException("This method is only supported in SQL mode", "M0M04"); - - // this is a dirty hack, but it works as long as MonetDB - // only handles one catalog (dbfarm) at a time - ResultSet rs = getMetaData().getCatalogs(); - try { - return rs.next() ? rs.getString(1) : null; - } finally { - rs.close(); - } + // MonetDB does NOT support catalogs + return null; } /** @@ -1138,7 +1129,7 @@ public class MonetConnection extends Mon */ @Override public void setCatalog(String catalog) throws SQLException { - // silently ignore this request + // silently ignore this request as MonetDB does not support catalogs } /** @@ -1318,7 +1309,8 @@ public class MonetConnection extends Mon public void setSchema(String schema) throws SQLException { if (closed) throw new SQLException("Cannot call on closed Connection", "M1M20"); - createStatement().executeUpdate("SET SCHEMA \"" + schema + "\""); + if (schema != null) + createStatement().execute("SET SCHEMA \"" + schema + "\""); } /** @@ -1332,14 +1324,21 @@ public class MonetConnection extends Mon public String getSchema() throws SQLException { if (closed) throw new SQLException("Cannot call on closed Connection", "M1M20"); - ResultSet rs = createStatement().executeQuery("SELECT CURRENT_SCHEMA"); - try { + + String cur_schema; + Statement st = createStatement(); + ResultSet rs = null; + try { + rs = st.executeQuery("SELECT CURRENT_SCHEMA"); if (!rs.next()) throw new SQLException("Row expected", "02000"); - return rs.getString(1); + cur_schema = rs.getString(1); } finally { - rs.close(); + if (rs != null) + rs.close(); + st.close(); } + return cur_schema; } /** @@ -2756,4 +2755,3 @@ public class MonetConnection extends Mon // }}} } -// vim: foldmethod=marker: diff --git a/java/src/main/java/nl/cwi/monetdb/jdbc/MonetDatabaseMetaData.java b/java/src/main/java/nl/cwi/monetdb/jdbc/MonetDatabaseMetaData.java --- a/java/src/main/java/nl/cwi/monetdb/jdbc/MonetDatabaseMetaData.java +++ b/java/src/main/java/nl/cwi/monetdb/jdbc/MonetDatabaseMetaData.java @@ -924,9 +924,8 @@ public class MonetDatabaseMetaData exten */ @Override public String getCatalogSeparator() { - // Give them something to work with here - // everything else returns false so it won't matter what we return here - return "."; + // MonetDB does NOT support catalogs, so also no catalog separator + return null; } /** @@ -1818,31 +1817,9 @@ public class MonetDatabaseMetaData exten */ @Override public ResultSet getCatalogs() throws SQLException { - /* - // doing this with a VirtualResultSet is much more efficient... - String query = - "SELECT '" + ((String)env.get("gdk_dbname")) + "' AS \"TABLE_CAT\""; - // some applications need a database or catalog... - - return getStmt().executeQuery(query); - */ - - String[] columns, types; - String[][] results; - - columns = new String[1]; - types = new String[1]; - results = new String[1][1]; - - columns[0] = "TABLE_CAT"; - types[0] = "varchar"; - results[0][0] = ""; - - try { - return new MonetVirtualResultSet(columns, types, results); - } catch (IllegalArgumentException e) { - throw new SQLException("Internal driver error: " + e.getMessage(), "M0M03"); - } + // MonetDB does NOT support catalogs. + // Return a resultset with no rows + return getStmt().executeQuery("SELECT cast(null as char(1)) AS \"TABLE_CAT\" WHERE 1 = 0"); } /** _______________________________________________ checkin-list mailing list [email protected] https://www.monetdb.org/mailman/listinfo/checkin-list
