Skip to content

Commit

Permalink
TIKA-4190 -- turn off autocommit (#1576)
Browse files Browse the repository at this point in the history
  • Loading branch information
tballison committed Feb 6, 2024
1 parent c2df01c commit c25ff4c
Showing 1 changed file with 13 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,17 @@ private void emitNow(List<? extends EmitData> emitData) throws SQLException {
insertAll(d.getEmitKey().getEmitKey(), d.getMetadataList());
}
}
insertStatement.executeBatch();
if (LOGGER.isDebugEnabled()) {
long start = System.currentTimeMillis();
insertStatement.executeBatch();
connection.commit();
LOGGER.debug("took {}ms to insert {} rows ", System.currentTimeMillis() - start,
emitData.size());
} else {
insertStatement.executeBatch();
connection.commit();
}

}

private void insertAll(String emitKey, List<Metadata> metadataList) throws SQLException {
Expand Down Expand Up @@ -361,6 +371,7 @@ private void tryClose() {

if (connection != null) {
try {
connection.commit();
connection.close();
} catch (SQLException e) {
LOGGER.warn("exception closing connection", e);
Expand All @@ -370,6 +381,7 @@ private void tryClose() {

private void createConnection() throws SQLException {
connection = DriverManager.getConnection(connectionString);
connection.setAutoCommit(false);
if (postConnectionString.isPresent()) {
try (Statement st = connection.createStatement()) {
st.execute(postConnectionString.get());
Expand Down

0 comments on commit c25ff4c

Please sign in to comment.