private void write(MarshalledEntry entry, Connection connection, int segment) throws SQLException, InterruptedException { write(entry, connection, key2Str(entry.getKey()), segment); }
@Override public void deleteBatch(Iterable<Object> keys) { Connection connection = null; try { connection = connectionFactory.getConnection(); try (PreparedStatement deleteBatch = connection.prepareStatement(tableManager.getDeleteRowSql())) { int batchSize = 0; for (Object key : keys) { String keyStr = key2Str(key); deleteBatch.setString(1, keyStr); deleteBatch.addBatch(); batchSize++; if (batchSize == configuration.maxBatchSize()) { batchSize = 0; deleteBatch.executeBatch(); deleteBatch.clearBatch(); } } if (batchSize != 0) deleteBatch.executeBatch(); } } catch (SQLException e) { throw log.sqlFailureDeletingBatch(keys, e); } finally { connectionFactory.releaseConnection(connection); } }
@Override public boolean delete(Object key) { Connection connection = null; PreparedStatement ps = null; String keyStr = key2Str(key); try { String sql = tableManager.getDeleteRowSql(); if (trace) { log.tracef("Running sql '%s' on %s", sql, keyStr); } connection = connectionFactory.getConnection(); ps = connection.prepareStatement(sql); ps.setString(1, keyStr); return ps.executeUpdate() == 1; } catch (SQLException ex) { log.sqlFailureRemovingKeys(ex); throw new PersistenceException("Error while removing string keys from database", ex); } finally { JdbcUtil.safeClose(ps); connectionFactory.releaseConnection(connection); } }
@Override public void write(MarshalledEntry entry) { Connection connection = null; String keyStr = key2Str(entry.getKey()); try { connection = connectionFactory.getConnection(); write(entry, connection, keyStr, getSegment(entry)); } catch (SQLException ex) { log.sqlFailureStoringKey(keyStr, ex); throw new PersistenceException(String.format("Error while storing string key to database; key: '%s'", keyStr), ex); } catch (InterruptedException e) { if (trace) { log.trace("Interrupted while marshalling to store"); } Thread.currentThread().interrupt(); } finally { connectionFactory.releaseConnection(connection); } }
int batchSize = 0; for (MarshalledEntry entry : marshalledEntries) { String keyStr = key2Str(entry.getKey()); prepareUpsertStatement(entry, keyStr, getSegment(entry), upsertBatch); upsertBatch.addBatch();
@Override public MarshalledEntry<K, V> load(Object key) { String lockingKey = key2Str(key); Connection conn = null; PreparedStatement ps = null;