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"); } } }
@Override public void closeConnection(Connection c) { super.closeConnection(c); cnt.decrementAndGet(); } }
@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(); }
@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; 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 long determineServerTimeDifferenceMillis() { Connection connection = null; try { connection = this.ch.getROConnection(); long result = this.db.determineServerTimeDifferenceMillis(connection); connection.commit(); return result; } catch (SQLException ex) { LOG.error("Trying to determine time difference to server", ex); throw asDocumentStoreException(ex, "Trying to determine time difference to server"); } finally { this.ch.closeConnection(connection); } }
@Override public long determineServerTimeDifferenceMillis() { Connection connection = null; try { connection = this.ch.getROConnection(); long result = this.db.determineServerTimeDifferenceMillis(connection); connection.commit(); return result; } catch (SQLException ex) { LOG.error("Trying to determine time difference to server", ex); throw asDocumentStoreException(ex, "Trying to determine time difference to server"); } finally { this.ch.closeConnection(connection); } }
@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; }
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 <T extends Document> Map<String, T> readDocumentsUncached(Collection<T> collection, Set<String> keys) { Map<String, T> result = new HashMap<String, T>(); Connection connection = null; RDBTableMetaData tmd = getTable(collection); try { connection = this.ch.getROConnection(); List<RDBRow> rows = db.read(connection, tmd, keys); int size = rows.size(); for (int i = 0; i < size; i++) { RDBRow row = rows.set(i, null); T document = convertFromDBObject(collection, row); result.put(document.getId(), document); } connection.commit(); } catch (Exception ex) { throw asDocumentStoreException(ex, "trying to read: " + keys); } finally { this.ch.closeConnection(connection); } return result; }
private <T extends Document> void delete(Collection<T> collection, String id) { Connection connection = null; RDBTableMetaData tmd = getTable(collection); Stopwatch watch = startWatch(); try { connection = this.ch.getRWConnection(); db.delete(connection, tmd, Collections.singletonList(id)); connection.commit(); } catch (Exception ex) { this.ch.rollbackConnection(connection); throw handleException("removing " + id, ex, collection, id); } finally { this.ch.closeConnection(connection); stats.doneRemove(watch.elapsed(TimeUnit.NANOSECONDS), collection, 1); } }
private <T extends Document> void delete(Collection<T> collection, String id) { Connection connection = null; RDBTableMetaData tmd = getTable(collection); Stopwatch watch = startWatch(); try { connection = this.ch.getRWConnection(); db.delete(connection, tmd, Collections.singletonList(id)); connection.commit(); } catch (Exception ex) { this.ch.rollbackConnection(connection); throw handleException("removing " + id, ex, collection, id); } finally { this.ch.closeConnection(connection); stats.doneRemove(watch.elapsed(TimeUnit.NANOSECONDS), collection, 1); } }
private <T extends Document> int deleteWithCondition(Collection<T> collection, List<QueryCondition> conditions) { int numDeleted = 0; RDBTableMetaData tmd = getTable(collection); Stopwatch watch = startWatch(); Connection connection = null; try { connection = this.ch.getRWConnection(); numDeleted = db.deleteWithCondition(connection, tmd, conditions); connection.commit(); } catch (Exception ex) { this.ch.rollbackConnection(connection); throw asDocumentStoreException(ex, "deleting " + collection + ": " + conditions); } finally { this.ch.closeConnection(connection); stats.doneRemove(watch.elapsed(TimeUnit.NANOSECONDS), collection, numDeleted); } return numDeleted; }
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); } }
private <T extends Document> int deleteWithCondition(Collection<T> collection, List<QueryCondition> conditions) { int numDeleted = 0; RDBTableMetaData tmd = getTable(collection); Stopwatch watch = startWatch(); Connection connection = null; try { connection = this.ch.getRWConnection(); numDeleted = db.deleteWithCondition(connection, tmd, conditions); connection.commit(); } catch (Exception ex) { this.ch.rollbackConnection(connection); throw asDocumentStoreException(ex, "deleting " + collection + ": " + conditions); } finally { this.ch.closeConnection(connection); stats.doneRemove(watch.elapsed(TimeUnit.NANOSECONDS), collection, numDeleted); } return numDeleted; }
private <T extends Document> int delete(Collection<T> collection, List<String> ids) { int numDeleted = 0; RDBTableMetaData tmd = getTable(collection); for (List<String> sublist : Lists.partition(ids, 64)) { Connection connection = null; Stopwatch watch = startWatch(); try { connection = this.ch.getRWConnection(); numDeleted += db.delete(connection, tmd, sublist); connection.commit(); } catch (Exception ex) { this.ch.rollbackConnection(connection); throw handleException("removing " + ids, ex, collection, ids); } finally { this.ch.closeConnection(connection); stats.doneRemove(watch.elapsed(TimeUnit.NANOSECONDS), collection, ids.size()); } } return numDeleted; }
private <T extends Document> int delete(Collection<T> collection, List<String> ids) { int numDeleted = 0; RDBTableMetaData tmd = getTable(collection); for (List<String> sublist : Lists.partition(ids, 64)) { Connection connection = null; Stopwatch watch = startWatch(); try { connection = this.ch.getRWConnection(); numDeleted += db.delete(connection, tmd, sublist); connection.commit(); } catch (Exception ex) { this.ch.rollbackConnection(connection); throw handleException("removing " + ids, ex, collection, ids); } finally { this.ch.closeConnection(connection); stats.doneRemove(watch.elapsed(TimeUnit.NANOSECONDS), collection, ids.size()); } } return numDeleted; }
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); } }