comparison src/main/java/nl/cwi/monetdb/jdbc/MonetConnection.java @ 219:4572f0694fde

Improved DatabaseMetaData methods getTablePrivileges() and getColumnPrivileges() by returning also any combination of privileges for the table or column in the PRIVILEGE result column. Previously only single privileges (SELECT or UPDATE or INSERT or DELETE or EXECUTE or GRANT) would be returned.
author Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
date Thu, 26 Apr 2018 18:43:55 +0200 (2018-04-26)
parents 71b039bc2d99
children 5ddb1f20d5d5
comparison
equal deleted inserted replaced
218:5cc7101c5c8d 219:4572f0694fde
145 /** Whether or not BLOB is mapped to Types.VARBINARY instead of Types.BLOB within this connection */ 145 /** Whether or not BLOB is mapped to Types.VARBINARY instead of Types.BLOB within this connection */
146 private boolean treatBlobAsVarBinary = false; 146 private boolean treatBlobAsVarBinary = false;
147 /** Whether or not CLOB is mapped to Types.VARCHAR instead of Types.CLOB within this connection */ 147 /** Whether or not CLOB is mapped to Types.VARCHAR instead of Types.CLOB within this connection */
148 private boolean treatClobAsVarChar = false; 148 private boolean treatClobAsVarChar = false;
149 149
150 // Internal cache for determining if system table sys.privilege_codes (new as of Jul2017 release) exists on server
151 private boolean queriedPrivilege_codesTable = false;
152 private boolean hasPrivilege_codesTable = false;
153
150 // Internal cache for determining if system table sys.comments (new as of Mar2018 release) exists on server 154 // Internal cache for determining if system table sys.comments (new as of Mar2018 release) exists on server
151 private boolean queriedCommentsTable = false; 155 private boolean queriedCommentsTable = false;
152 private boolean hasCommentsTable = false; 156 private boolean hasCommentsTable = false;
153 157
154 158
1680 * the system table sys.comments (which is new as of Mar2018 release). 1684 * the system table sys.comments (which is new as of Mar2018 release).
1681 * The result is cached and reused, so that we only test the query once per connection. 1685 * The result is cached and reused, so that we only test the query once per connection.
1682 * This method is used by methods from MonetDatabaseMetaData. 1686 * This method is used by methods from MonetDatabaseMetaData.
1683 */ 1687 */
1684 boolean commentsTableExists() { 1688 boolean commentsTableExists() {
1685 if (queriedCommentsTable) 1689 if (!queriedCommentsTable) {
1686 return hasCommentsTable; 1690 hasCommentsTable = existsSysTable("comments");
1687 1691 queriedCommentsTable = true; // set flag, so the querying is done only at first invocation.
1688 queriedCommentsTable = true; // set flag, so the querying part below is done only once, at first invocation. 1692 }
1693 return hasCommentsTable;
1694 }
1695
1696 /**
1697 * Internal utility method to query the server to find out if it has
1698 * the system table sys.privilege_codes (which is new as of Jul2017 release).
1699 * The result is cached and reused, so that we only test the query once per connection.
1700 * This method is used by methods from MonetDatabaseMetaData.
1701 */
1702 boolean privilege_codesTableExists() {
1703 if (!queriedPrivilege_codesTable) {
1704 hasPrivilege_codesTable = existsSysTable("privilege_codes");
1705 queriedPrivilege_codesTable = true; // set flag, so the querying is done only at first invocation.
1706 }
1707 return hasPrivilege_codesTable;
1708 }
1709
1710 /**
1711 * Internal utility method to query the server to find out if it has the system table sys.<tablename>.
1712 */
1713 private boolean existsSysTable(String tablename) {
1714 boolean exists = false;
1689 Statement stmt = null; 1715 Statement stmt = null;
1690 ResultSet rs = null; 1716 ResultSet rs = null;
1691 try { 1717 try {
1692 stmt = createStatement(); 1718 stmt = createStatement();
1693 if (stmt != null) { 1719 if (stmt != null) {
1694 rs = stmt.executeQuery( "SELECT \"id\", \"remark\" FROM \"sys\".\"comments\" LIMIT 1"); 1720 rs = stmt.executeQuery("SELECT id FROM sys._tables WHERE name = '"
1721 + tablename
1722 + "' AND schema_id IN (SELECT id FROM sys.schemas WHERE name = 'sys')");
1695 if (rs != null) { 1723 if (rs != null) {
1696 rs.next(); 1724 exists = rs.next(); // if a row is available it exists, else not
1697 hasCommentsTable = true;
1698 } 1725 }
1699 } 1726 }
1700 } catch (SQLException se) { 1727 } catch (SQLException se) {
1701 /* ignore */ 1728 /* ignore */
1702 } finally { 1729 } finally {
1709 try { 1736 try {
1710 stmt.close(); 1737 stmt.close();
1711 } catch (SQLException e) { /* ignore */ } 1738 } catch (SQLException e) { /* ignore */ }
1712 } 1739 }
1713 } 1740 }
1714 // for debug: System.out.println("commentsTableExists returns: " + hasCommentsTable); 1741 // for debug: System.out.println("testTableExists(" + tablename + ") returns: " + exists);
1715 return hasCommentsTable; 1742 return exists;
1716 } 1743 }
1717 1744
1718 /** 1745 /**
1719 * Sends the given string to MonetDB as special transaction command. 1746 * Sends the given string to MonetDB as special transaction command.
1720 * All possible returned information is discarded. 1747 * All possible returned information is discarded.