Changeset: 4293d1b90e56 for MonetDB URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=4293d1b90e56 Modified Files: java/ChangeLog java/src/main/java/nl/cwi/monetdb/jdbc/MonetDatabaseMetaData.java Branch: leftmart Log Message:
merge with default diffs (truncated from 430 to 300 lines): diff --git a/java/ChangeLog b/java/ChangeLog --- a/java/ChangeLog +++ b/java/ChangeLog @@ -1,9 +1,23 @@ # ChangeLog file for java # This file is updated with Maddlog +* Thu Mar 3 2016 Martin van Dinther <martin.van.dint...@monetdbsolutions.com> +- Implemented method DatabaseMetaData.getClientProperties(). It used to always + return a resultset with 4 completely empty rows. It now returns a + resultset with the possible connection properties. +- Implemented method DatabaseMetaData.getUDTs(). It used to return an empty + resultset. Now it returns the User Defined Types such as inet, json, url and uuid. + +* Thu Feb 18 2016 Martin van Dinther <martin.van.dint...@monetdbsolutions.com> +- Corrected the returned table types in DatabaseMetaData.getTableTypes(). + It now returns all 10 table types (as stored in sys.table_types) instead + of the previously 8 hardcoded table types. + For old MonetDB servers which do not have the sys.table_types table, + the old behavior is retained. + * Thu Feb 11 2016 Martin van Dinther <martin.van.dint...@monetdbsolutions.com> -- Implemented methods getProcedures() and getProcedureColumns() - in DatabaseMetadata.java. They used to return an empty resultset. +- Implemented methods DatabaseMetadata.getProcedures() and + DatabaseMetadata.getProcedureColumns(). They used to return an empty resultset. Now they return the expected Procedures and ProcedureColumns. Also getProcedureColumns() now returns a resultset with all 20 columns instead of 13 columns previously. @@ -16,8 +30,8 @@ * Thu Jan 28 2016 Martin van Dinther <martin.van.dint...@monetdbsolutions.com> - Method getFunctions() in DatabaseMetadata used to throw an SQLException: - SELECT: no such column 'functions.sql' This has been corrected. It - now returns a resultset as requested. + SELECT: no such column 'functions.sql' This has been corrected. + It now returns a resultset as requested. - The resultsets of DatabaseMetadata methods now no longer return a value for the *_CAT columns as MonetDB does not support Catalogs. 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 @@ -36,15 +36,6 @@ public class MonetDatabaseMetaData exten con = parent; } - private synchronized Statement getStmt() throws SQLException { - // use Statement which allows scrolling both directions through results - // cannot reuse stmt here, as people may request multiple - // queries, see for example bug #2703 - return con.createStatement( - ResultSet.TYPE_SCROLL_INSENSITIVE, - ResultSet.CONCUR_READ_ONLY); - } - /** * Internal cache for 3 environment values retrieved from the * server, to avoid querying the server over and over again. @@ -55,7 +46,7 @@ public class MonetDatabaseMetaData exten Statement st = null; ResultSet rs = null; try { - st = getStmt(); + st = con.createStatement(); rs = st.executeQuery( "SELECT \"name\", \"value\" FROM \"sys\".\"environment\"" + " WHERE \"name\" IN ('monet_version', 'max_clients')" + @@ -92,6 +83,29 @@ public class MonetDatabaseMetaData exten // for debug: System.out.println("Read: env_current_user: " + env_current_user + " env_monet_version: " + env_monet_version + " env_max_clients: " + env_max_clients); } + + /** + * Internal utility method to create a Statement object, execute a query and return the ResulSet object. + * As the Statement object is created internally (the caller does not see it and thus can not close it), + * we set it to close (and free server resources) when the ResultSet object is closed by the caller. + */ + private ResultSet executeMetaDataQuery(String query) throws SQLException { + Statement stmt = null; + ResultSet rs = null; + stmt = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY); + if (stmt != null) { + rs = stmt.executeQuery(query); + if (rs != null) { + /* we want the statement object to be closed also when the resultset is closed by the caller */ + stmt.closeOnCompletion(); + } else { + /* failed to produce a resultset, so release resources for created statement object now */ + stmt.close(); + } + } + return rs; + } + /** * Can all the procedures returned by getProcedures be called * by the current user? @@ -391,7 +405,7 @@ public class MonetDatabaseMetaData exten Statement st = null; ResultSet rs = null; try { - st = getStmt(); + st = con.createStatement(); rs = st.executeQuery("SELECT \"keyword\" FROM \"sys\".\"keywords\" ORDER BY 1"); // Fetch the keywords and concatenate them into a StringBuffer separated by comma's boolean isfirst = true; @@ -490,7 +504,7 @@ public class MonetDatabaseMetaData exten ResultSet rs = null; try { String select = "SELECT DISTINCT \"name\" FROM \"sys\".\"functions\" " + whereClause + " ORDER BY 1"; - st = getStmt(); + st = con.createStatement(); rs = st.executeQuery(select); // Fetch the function names and concatenate them into a StringBuffer separated by comma's boolean isfirst = true; @@ -1601,7 +1615,7 @@ public class MonetDatabaseMetaData exten query.append(" ORDER BY \"PROCEDURE_SCHEM\", \"PROCEDURE_NAME\", \"SPECIFIC_NAME\""); - return getStmt().executeQuery(query.toString()); + return executeMetaDataQuery(query.toString()); } /** @@ -1712,7 +1726,7 @@ public class MonetDatabaseMetaData exten } query.append(" ORDER BY \"PROCEDURE_SCHEM\", \"PROCEDURE_NAME\", \"ORDINAL_POSITION\""); - return getStmt().executeQuery(query.toString()); + return executeMetaDataQuery(query.toString()); } //== this is a helper method which does not belong to the interface @@ -1862,7 +1876,7 @@ public class MonetDatabaseMetaData exten query.append(" ORDER BY \"TABLE_TYPE\", \"TABLE_SCHEM\", \"TABLE_NAME\""); - return getStmt().executeQuery(query.toString()); + return executeMetaDataQuery(query.toString()); } /** @@ -1899,7 +1913,7 @@ public class MonetDatabaseMetaData exten query += "WHERE \"name\" ILIKE '" + escapeQuotes(schemaPattern) + "' "; query += "ORDER BY \"TABLE_SCHEM\""; - return getStmt().executeQuery(query); + return executeMetaDataQuery(query); } /** @@ -1920,7 +1934,7 @@ public class MonetDatabaseMetaData exten public ResultSet getCatalogs() throws SQLException { // 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"); + return executeMetaDataQuery("SELECT cast(null as char(1)) AS \"TABLE_CAT\" WHERE 1 = 0"); } /** @@ -1955,7 +1969,7 @@ public class MonetDatabaseMetaData exten "SELECT 'VIEW' ORDER BY 1"; } - return getStmt().executeQuery(query); + return executeMetaDataQuery(query); } /** @@ -2058,7 +2072,7 @@ public class MonetDatabaseMetaData exten query += "ORDER BY \"TABLE_SCHEM\", \"TABLE_NAME\", \"ORDINAL_POSITION\""; - return getStmt().executeQuery(query); + return executeMetaDataQuery(query); } /** @@ -2141,7 +2155,7 @@ public class MonetDatabaseMetaData exten query += "ORDER BY \"COLUMN_NAME\", \"PRIVILEGE\""; - return getStmt().executeQuery(query); + return executeMetaDataQuery(query); } /** @@ -2217,7 +2231,7 @@ public class MonetDatabaseMetaData exten query += "ORDER BY \"TABLE_SCHEM\", \"TABLE_NAME\", \"PRIVILEGE\""; - return getStmt().executeQuery(query); + return executeMetaDataQuery(query); } /** @@ -2294,7 +2308,7 @@ public class MonetDatabaseMetaData exten } query += "ORDER BY \"keys\".\"type\""; - return getStmt().executeQuery(query); + return executeMetaDataQuery(query); } /** @@ -2407,7 +2421,7 @@ public class MonetDatabaseMetaData exten query += "ORDER BY \"COLUMN_NAME\""; - return getStmt().executeQuery(query); + return executeMetaDataQuery(query); } final static String keyQuery1 = @@ -2502,7 +2516,7 @@ public class MonetDatabaseMetaData exten query += "ORDER BY \"PKTABLE_CAT\", \"PKTABLE_SCHEM\", \"PKTABLE_NAME\", \"PK_NAME\", \"KEY_SEQ\""; - return getStmt().executeQuery(query); + return executeMetaDataQuery(query); } /** @@ -2572,7 +2586,7 @@ public class MonetDatabaseMetaData exten query += "ORDER BY \"FKTABLE_CAT\", \"FKTABLE_SCHEM\", \"FKTABLE_NAME\", \"FK_NAME\", \"KEY_SEQ\""; - return getStmt().executeQuery(query); + return executeMetaDataQuery(query); } /** @@ -2663,7 +2677,7 @@ public class MonetDatabaseMetaData exten query += "ORDER BY \"FKTABLE_CAT\", \"FKTABLE_SCHEM\", \"FKTABLE_NAME\", \"FK_NAME\", \"KEY_SEQ\""; - return getStmt().executeQuery(query); + return executeMetaDataQuery(query); } /** @@ -2756,7 +2770,7 @@ public class MonetDatabaseMetaData exten "\"radix\" AS \"NUM_PREC_RADIX\" " + "FROM \"sys\".\"types\""; - return getStmt().executeQuery(query); + return executeMetaDataQuery(query); } /** @@ -2877,7 +2891,7 @@ public class MonetDatabaseMetaData exten Statement sub = null; if (!approximate) sub = con.createStatement(); - ResultSet rs = getStmt().executeQuery(query); + ResultSet rs = executeMetaDataQuery(query); try { while (rs.next()) { String[] result = new String[13]; @@ -3018,10 +3032,25 @@ public class MonetDatabaseMetaData exten } /** - * Return user defined types in a schema - * Probably not possible within MonetDB + * Retrieves a description of the user-defined types (UDTs) defined in a particular schema. + * Schema-specific UDTs may have type JAVA_OBJECT, STRUCT, or DISTINCT. + * Only types matching the catalog, schema, type name and type criteria are returned. + * They are ordered by DATA_TYPE, TYPE_CAT, TYPE_SCHEM and TYPE_NAME. + * The type name parameter may be a fully-qualified name. In this case, the catalog and schemaPattern parameters are ignored. * - * @throws SQLException if I made a Boo-Boo + * Each type description has the following columns: + * + * 1 TYPE_CAT String => the type's catalog (may be null) + * 2 TYPE_SCHEM String => type's schema (may be null) + * 3 TYPE_NAME String => type name + * 4 CLASS_NAME String => Java class name + * 5 DATA_TYPE int => type value defined in java.sql.Types. One of JAVA_OBJECT, STRUCT, or DISTINCT + * 6 REMARKS String => explanatory comment on the type + * 7 BASE_TYPE short => type code of the source type of a DISTINCT type or the type that implements the + * user-generated reference type of the SELF_REFERENCING_COLUMN of a structured type as defined + * in java.sql.Types (null if DATA_TYPE is not DISTINCT or not STRUCT with REFERENCE_GENERATION = USER_DEFINED) + * + * @throws SQLException */ @Override public ResultSet getUDTs( @@ -3031,12 +3060,47 @@ public class MonetDatabaseMetaData exten int[] types ) throws SQLException { - String query = - "SELECT cast(null as char(1)) AS \"TYPE_CAT\", '' AS \"TYPE_SCHEM\", '' AS \"TYPE_NAME\", " + - "'java.lang.Object' AS \"CLASS_NAME\", 0 AS \"DATA_TYPE\", " + - "'' AS \"REMARKS\", 0 AS \"BASE_TYPE\" WHERE 1 = 0"; - - return getStmt().executeQuery(query); + StringBuilder query = new StringBuilder(990); _______________________________________________ checkin-list mailing list checkin-list@monetdb.org https://www.monetdb.org/mailman/listinfo/checkin-list