comparison src/main/java/nl/cwi/monetdb/jdbc/MonetConnection.java @ 215:71b039bc2d99

Added support for querying the sys.comments table for some meta data methods when connected to a MonetDB server which has table sys.comments.
author Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
date Thu, 19 Apr 2018 16:13:01 +0200 (2018-04-19)
parents b8c007e86694
children 4572f0694fde
comparison
equal deleted inserted replaced
214:b8c007e86694 215:71b039bc2d99
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.comments (new as of Mar2018 release) exists on server
151 private boolean queriedCommentsTable = false;
152 private boolean hasCommentsTable = false;
153
154
150 /** 155 /**
151 * Constructor of a Connection for MonetDB. At this moment the 156 * Constructor of a Connection for MonetDB. At this moment the
152 * current implementation limits itself to storing the given host, 157 * current implementation limits itself to storing the given host,
153 * database, username and password for later use by the 158 * database, username and password for later use by the
154 * createStatement() call. This constructor is only accessible to 159 * createStatement() call. This constructor is only accessible to
1666 * This allows generic JDBC programs to fetch Clob data via getString() 1671 * This allows generic JDBC programs to fetch Clob data via getString()
1667 * instead of getClob() and Clob.getCharacterStream() to reduce overhead. 1672 * instead of getClob() and Clob.getCharacterStream() to reduce overhead.
1668 */ 1673 */
1669 boolean mapClobAsVarChar() { 1674 boolean mapClobAsVarChar() {
1670 return treatClobAsVarChar; 1675 return treatClobAsVarChar;
1676 }
1677
1678 /**
1679 * Internal utility method to query the server to find out if it has
1680 * 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.
1682 * This method is used by methods from MonetDatabaseMetaData.
1683 */
1684 boolean commentsTableExists() {
1685 if (queriedCommentsTable)
1686 return hasCommentsTable;
1687
1688 queriedCommentsTable = true; // set flag, so the querying part below is done only once, at first invocation.
1689 Statement stmt = null;
1690 ResultSet rs = null;
1691 try {
1692 stmt = createStatement();
1693 if (stmt != null) {
1694 rs = stmt.executeQuery( "SELECT \"id\", \"remark\" FROM \"sys\".\"comments\" LIMIT 1");
1695 if (rs != null) {
1696 rs.next();
1697 hasCommentsTable = true;
1698 }
1699 }
1700 } catch (SQLException se) {
1701 /* ignore */
1702 } finally {
1703 if (rs != null) {
1704 try {
1705 rs.close();
1706 } catch (SQLException e) { /* ignore */ }
1707 }
1708 if (stmt != null) {
1709 try {
1710 stmt.close();
1711 } catch (SQLException e) { /* ignore */ }
1712 }
1713 }
1714 // for debug: System.out.println("commentsTableExists returns: " + hasCommentsTable);
1715 return hasCommentsTable;
1671 } 1716 }
1672 1717
1673 /** 1718 /**
1674 * Sends the given string to MonetDB as special transaction command. 1719 * Sends the given string to MonetDB as special transaction command.
1675 * All possible returned information is discarded. 1720 * All possible returned information is discarded.