@Override public void putAll(String storeName, String tableName, Collection<T> states) throws IOException { try (Connection connection = dataSource.getConnection(); PreparedStatement insertStatement = connection.prepareStatement(UPSERT_JOB_STATE_SQL); ByteArrayOutputStream byteArrayOs = new ByteArrayOutputStream(); OutputStream os = compressedValues ? new GZIPOutputStream(byteArrayOs) : byteArrayOs; DataOutputStream dataOutput = new DataOutputStream(os)) { int index = 0; insertStatement.setString(++index, storeName); insertStatement.setString(++index, tableName); for (T state : states) { addStateToDataOutputStream(dataOutput, state); } dataOutput.close(); insertStatement.setBlob(++index, new ByteArrayInputStream(byteArrayOs.toByteArray())); insertStatement.executeUpdate(); connection.commit(); } catch (SQLException e) { throw new IOException("Failure storing state to store " + storeName + " table " + tableName, e); } }
@Override public void putAll(String storeName, String tableName, Collection<T> states) throws IOException { try (Connection connection = dataSource.getConnection(); PreparedStatement insertStatement = connection.prepareStatement(UPSERT_JOB_STATE_SQL); ByteArrayOutputStream byteArrayOs = new ByteArrayOutputStream(); OutputStream os = compressedValues ? new GZIPOutputStream(byteArrayOs) : byteArrayOs; DataOutputStream dataOutput = new DataOutputStream(os)) { int index = 0; insertStatement.setString(++index, storeName); insertStatement.setString(++index, tableName); for (T state : states) { addStateToDataOutputStream(dataOutput, state); } dataOutput.close(); insertStatement.setBlob(++index, new ByteArrayInputStream(byteArrayOs.toByteArray())); insertStatement.executeUpdate(); connection.commit(); } catch (SQLException e) { throw new IOException("Failure storing state to store " + storeName + " table " + tableName, e); } }