private void internalClose() { this.rs = closeResultSet(this.rs); this.stmt = closeStatement(this.stmt); this.ch.closeConnection(this.connection); this.connection = null; if (LOG.isDebugEnabled()) { LOG.debug(this.message + " -> " + this.cnt + " results in " + elapsed + "ms"); } } }
private void internalClose() { this.rs = closeResultSet(this.rs); this.stmt = closeStatement(this.stmt); this.ch.closeConnection(this.connection); this.connection = null; if (LOG.isDebugEnabled()) { LOG.debug(this.message + " -> " + this.cnt + " results in " + elapsed + "ms"); } } }
private boolean upgradeTable(Connection con, String tableName, int level) throws SQLException { boolean wasChanged = false; for (String statement : this.dbInfo.getTableUpgradeStatements(tableName, level)) { Statement upgradeStatement = null; try { upgradeStatement = con.createStatement(); upgradeStatement.execute(statement); upgradeStatement.close(); con.commit(); LOG.info("Upgraded " + tableName + " to DB level " + level + " using '" + statement + "'"); wasChanged = true; } catch (SQLException exup) { con.rollback(); String message = String.format( "Attempted to upgrade %s to DB level %d using '%s', but failed with SQLException '%s' (code: %d/state: %s) - will continue without.", tableName, level, statement, exup.getMessage(), exup.getErrorCode(), exup.getSQLState()); if (LOG.isDebugEnabled()) { LOG.debug(message, exup); } else { LOG.info(message); } } finally { closeStatement(upgradeStatement); } } return wasChanged; }
private boolean addModifiedIndex(Connection con, String tableName) throws SQLException { boolean wasChanged = false; String statement = this.dbInfo.getModifiedIndexStatement(tableName); Statement upgradeStatement = null; try { upgradeStatement = con.createStatement(); upgradeStatement.execute(statement); upgradeStatement.close(); con.commit(); LOG.info("Added 'modified' index to " + tableName + " using '" + statement + "'"); wasChanged = true; } catch (SQLException exup) { con.rollback(); String message = String.format( "Attempted to add 'modified' index to %s using '%s', but failed with SQLException '%s' (code: %d/state: %s) - will continue without.", tableName, statement, exup.getMessage(), exup.getErrorCode(), exup.getSQLState()); if (LOG.isDebugEnabled()) { LOG.debug(message, exup); } else { LOG.info(message); } } finally { closeStatement(upgradeStatement); } return wasChanged; }
private boolean addModifiedIndex(Connection con, String tableName) throws SQLException { boolean wasChanged = false; String statement = this.dbInfo.getModifiedIndexStatement(tableName); Statement upgradeStatement = null; try { upgradeStatement = con.createStatement(); upgradeStatement.execute(statement); upgradeStatement.close(); con.commit(); LOG.info("Added 'modified' index to " + tableName + " using '" + statement + "'"); wasChanged = true; } catch (SQLException exup) { con.rollback(); String message = String.format( "Attempted to add 'modified' index to %s using '%s', but failed with SQLException '%s' (code: %d/state: %s) - will continue without.", tableName, statement, exup.getMessage(), exup.getErrorCode(), exup.getSQLState()); if (LOG.isDebugEnabled()) { LOG.debug(message, exup); } else { LOG.info(message); } } finally { closeStatement(upgradeStatement); } return wasChanged; }
@Override public String getAdditionalDiagnostics(RDBConnectionHandler ch, String tableName) { Connection con = null; PreparedStatement stmt = null; ResultSet rs = null; Map<String, String> result = new HashMap<String, String>(); try { con = ch.getROConnection(); String cat = con.getCatalog(); stmt = con.prepareStatement("SELECT pg_encoding_to_char(encoding), datcollate FROM pg_database WHERE datname=?"); stmt.setString(1, cat); rs = stmt.executeQuery(); while (rs.next()) { result.put("pg_encoding_to_char(encoding)", rs.getString(1)); result.put("datcollate", rs.getString(2)); } con.commit(); } catch (SQLException ex) { LOG.debug("while getting diagnostics", ex); } finally { closeResultSet(rs); closeStatement(stmt); ch.closeConnection(con); } return result.toString(); }
public long getLong(Connection connection, RDBTableMetaData tmd, String aggregate, String field, String minId, String maxId, List<String> excludeKeyPatterns, List<QueryCondition> conditions) throws SQLException { PreparedStatement stmt = null; ResultSet rs = null; long start = System.currentTimeMillis(); long result = -1; String selector = aggregate + "(" + ("*".equals(field) ? "*" : INDEXED_PROP_MAPPING.get(field)) + ")"; try { stmt = prepareQuery(connection, tmd, selector, minId, maxId, excludeKeyPatterns, conditions, Integer.MAX_VALUE, null); rs = stmt.executeQuery(); result = rs.next() ? rs.getLong(1) : -1; return result; } finally { closeStatement(stmt); closeResultSet(rs); if (LOG.isDebugEnabled()) { long elapsed = System.currentTimeMillis() - start; String params = String.format("params minid '%s' maxid '%s' excludeKeyPatterns %s conditions %s.", minId, maxId, excludeKeyPatterns, conditions); LOG.debug("Aggregate query " + selector + " on " + tmd.getName() + " with " + params + " -> " + result + ", took " + elapsed + "ms"); } } }
@Override public String getAdditionalDiagnostics(RDBConnectionHandler ch, String tableName) { Connection con = null; Statement stmt = null; ResultSet rs = null; Map<String, String> result = new HashMap<String, String>(); try { con = ch.getROConnection(); stmt = con.createStatement(); rs = stmt .executeQuery("SELECT PARAMETER, VALUE from NLS_DATABASE_PARAMETERS WHERE PARAMETER IN ('NLS_COMP', 'NLS_CHARACTERSET')"); while (rs.next()) { result.put(rs.getString(1), rs.getString(2)); } stmt.close(); con.commit(); } catch (SQLException ex) { LOG.debug("while getting diagnostics", ex); } finally { closeResultSet(rs); closeStatement(stmt); ch.closeConnection(con); } return result.toString(); }
@Override public String getAdditionalDiagnostics(RDBConnectionHandler ch, String tableName) { Connection con = null; PreparedStatement stmt = null; ResultSet rs = null; Map<String, String> result = new HashMap<String, String>(); try { con = ch.getROConnection(); String cat = con.getCatalog(); stmt = con.prepareStatement("SELECT collation_name FROM sys.databases WHERE name=?"); stmt.setString(1, cat); rs = stmt.executeQuery(); while (rs.next()) { result.put("collation_name", rs.getString(1)); } rs.close(); stmt.close(); con.commit(); } catch (SQLException ex) { LOG.debug("while getting diagnostics", ex); } finally { closeResultSet(rs); closeStatement(stmt); ch.closeConnection(con); } return result.toString(); }
@Override public String getAdditionalDiagnostics(RDBConnectionHandler ch, String tableName) { Connection con = null; PreparedStatement stmt = null; ResultSet rs = null; Map<String, String> result = new HashMap<String, String>(); try { con = ch.getROConnection(); String cat = con.getCatalog(); stmt = con.prepareStatement("SELECT collation_name FROM sys.databases WHERE name=?"); stmt.setString(1, cat); rs = stmt.executeQuery(); while (rs.next()) { result.put("collation_name", rs.getString(1)); } rs.close(); stmt.close(); con.commit(); } catch (SQLException ex) { LOG.debug("while getting diagnostics", ex); } finally { closeResultSet(rs); closeStatement(stmt); ch.closeConnection(con); } return result.toString(); }
@Override public String getAdditionalDiagnostics(RDBConnectionHandler ch, String tableName) { Connection con = null; Statement stmt = null; ResultSet rs = null; Map<String, String> result = new HashMap<String, String>(); try { con = ch.getROConnection(); stmt = con.createStatement(); rs = stmt .executeQuery("SELECT PARAMETER, VALUE from NLS_DATABASE_PARAMETERS WHERE PARAMETER IN ('NLS_COMP', 'NLS_CHARACTERSET')"); while (rs.next()) { result.put(rs.getString(1), rs.getString(2)); } stmt.close(); con.commit(); } catch (SQLException ex) { LOG.debug("while getting diagnostics", ex); } finally { closeResultSet(rs); closeStatement(stmt); ch.closeConnection(con); } return result.toString(); }
public long getLong(Connection connection, RDBTableMetaData tmd, String aggregate, String field, String minId, String maxId, List<String> excludeKeyPatterns, List<QueryCondition> conditions) throws SQLException { PreparedStatement stmt = null; ResultSet rs = null; long start = System.currentTimeMillis(); long result = -1; String selector = aggregate + "(" + ("*".equals(field) ? "*" : INDEXED_PROP_MAPPING.get(field)) + ")"; try { stmt = prepareQuery(connection, tmd, selector, minId, maxId, excludeKeyPatterns, conditions, Integer.MAX_VALUE, null); rs = stmt.executeQuery(); result = rs.next() ? rs.getLong(1) : -1; return result; } finally { closeStatement(stmt); closeResultSet(rs); if (LOG.isDebugEnabled()) { long elapsed = System.currentTimeMillis() - start; String params = String.format("params minid '%s' maxid '%s' excludeKeyPatterns %s conditions %s.", minId, maxId, excludeKeyPatterns, conditions); LOG.debug("Aggregate query " + selector + " on " + tmd.getName() + " with " + params + " -> " + result + ", took " + elapsed + "ms"); } } }
protected byte[] readBlockFromBackend(byte[] digest) throws Exception { String id = StringUtils.convertBytesToHex(digest); Connection con = this.ch.getROConnection(); byte[] data; try { PreparedStatement prep = con.prepareStatement("select DATA from " + this.tnData + " where ID = ?"); ResultSet rs = null; try { prep.setString(1, id); rs = prep.executeQuery(); if (!rs.next()) { throw new IOException("Datastore block " + id + " not found"); } data = rs.getBytes(1); } finally { closeResultSet(rs); closeStatement(prep); } } finally { con.commit(); this.ch.closeConnection(con); } return data; }
@Override protected void mark(BlockId blockId) throws Exception { Connection con = this.ch.getRWConnection(); PreparedStatement prep = null; try { if (minLastModified == 0) { return; } String id = StringUtils.convertBytesToHex(blockId.getDigest()); prep = con.prepareStatement("update " + this.tnMeta + " set LASTMOD = ? where ID = ? and LASTMOD < ?"); prep.setLong(1, System.currentTimeMillis()); prep.setString(2, id); prep.setLong(3, minLastModified); prep.executeUpdate(); prep.close(); } finally { closeStatement(prep); con.commit(); this.ch.closeConnection(con); } }
@Override protected void mark(BlockId blockId) throws Exception { Connection con = this.ch.getRWConnection(); PreparedStatement prep = null; try { if (minLastModified == 0) { return; } String id = StringUtils.convertBytesToHex(blockId.getDigest()); prep = con.prepareStatement("update " + this.tnMeta + " set LASTMOD = ? where ID = ? and LASTMOD < ?"); prep.setLong(1, System.currentTimeMillis()); prep.setString(2, id); prep.setLong(3, minLastModified); prep.executeUpdate(); prep.close(); } finally { closeStatement(prep); con.commit(); this.ch.closeConnection(con); } }
protected byte[] readBlockFromBackend(byte[] digest) throws Exception { String id = StringUtils.convertBytesToHex(digest); Connection con = this.ch.getROConnection(); byte[] data; try { PreparedStatement prep = con.prepareStatement("select DATA from " + this.tnData + " where ID = ?"); ResultSet rs = null; try { prep.setString(1, id); rs = prep.executeQuery(); if (!rs.next()) { throw new IOException("Datastore block " + id + " not found"); } data = rs.getBytes(1); } finally { closeResultSet(rs); closeStatement(prep); } } finally { con.commit(); this.ch.closeConnection(con); } return data; }
private static void getTableMetaData(Connection con, Collection<? extends Document> col, RDBTableMetaData tmd) throws SQLException { Statement checkStatement = null; ResultSet checkResultSet = null; try { checkStatement = con.createStatement(); checkResultSet = checkStatement.executeQuery("select * from " + tmd.getName() + " where ID = '0'"); // try to discover size of DATA column and binary-ness of ID ResultSetMetaData met = checkResultSet.getMetaData(); obtainFlagsFromResultSetMeta(met, tmd); String tableInfo = RDBJDBCTools.dumpResultSetMeta(met); tmd.setSchemaInfo(tableInfo); String indexInfo = dumpIndexData(con.getMetaData(), met, tmd.getName(), null); tmd.setIndexInfo(indexInfo); } finally { closeResultSet(checkResultSet); closeStatement(checkStatement); } }
private static void getTableMetaData(Connection con, Collection<? extends Document> col, RDBTableMetaData tmd) throws SQLException { Statement checkStatement = null; ResultSet checkResultSet = null; try { checkStatement = con.createStatement(); checkResultSet = checkStatement.executeQuery("select * from " + tmd.getName() + " where ID = '0'"); // try to discover size of DATA column and binary-ness of ID ResultSetMetaData met = checkResultSet.getMetaData(); obtainFlagsFromResultSetMeta(met, tmd); String tableInfo = RDBJDBCTools.dumpResultSetMeta(met); tmd.setSchemaInfo(tableInfo); String indexInfo = dumpIndexData(con.getMetaData(), met, tmd.getName(), null); tmd.setIndexInfo(indexInfo); } finally { closeResultSet(checkResultSet); closeStatement(checkStatement); } }
public static void killMetaEntry(RDBBlobStore ds, byte[] digest) throws Exception { String id = StringUtils.convertBytesToHex(digest); Connection con = ds.ch.getRWConnection(); PreparedStatement prepDelMeta = null; try { prepDelMeta = con.prepareStatement("delete from " + ds.tnMeta + " where ID = ?"); prepDelMeta.setString(1, id); prepDelMeta.execute(); } finally { closeStatement(prepDelMeta); con.commit(); ds.ch.closeConnection(con); } }
public static boolean isDataEntryPresent(RDBBlobStore ds, byte[] digest) throws Exception { String id = StringUtils.convertBytesToHex(digest); Connection con = ds.ch.getROConnection(); PreparedStatement prep = null; ResultSet rs = null; try { prep = con.prepareStatement("select ID from " + ds.tnData + " where ID = ?"); prep.setString(1, id); rs = prep.executeQuery(); return rs.next(); } finally { closeResultSet(rs); closeStatement(prep); con.commit(); ds.ch.closeConnection(con); } }