From 7f75a7ff507fbf9e006cd2b6ecd793eb09d27203 Mon Sep 17 00:00:00 2001 From: Keir Nellyer Date: Thu, 23 Jun 2016 20:36:34 +0100 Subject: [PATCH] Unfortunately we can't batch these SQL commands as we have to retrieve the snapshot id after inserting --- .../mineplex/core/chatsnap/SnapshotRepository.java | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/Plugins/Mineplex.Core/src/mineplex/core/chatsnap/SnapshotRepository.java b/Plugins/Mineplex.Core/src/mineplex/core/chatsnap/SnapshotRepository.java index ecb293b40..8e8d7ffbb 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/chatsnap/SnapshotRepository.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/chatsnap/SnapshotRepository.java @@ -60,14 +60,14 @@ public class SnapshotRepository extends MinecraftRepository try (Connection connection = DBPool.getAccount().getConnection()) { - PreparedStatement insertSnapshotStatement = connection.prepareStatement(INSERT_SNAPSHOT, Statement.RETURN_GENERATED_KEYS); + PreparedStatement insertSnapshotStatement = connection.prepareStatement(INSERT_SNAPSHOT, new String[]{"id"}); for (Snapshot snapshot : snapshots) { insertSnapshot(connection, insertSnapshotStatement, reportId, snapshot); } - insertSnapshotStatement.executeBatch(); + insertSnapshotStatement.close(); } catch (SQLException e) { @@ -84,9 +84,9 @@ public class SnapshotRepository extends MinecraftRepository { try (Connection connection = DBPool.getAccount().getConnection()) { - PreparedStatement insertSnapshotStatement = connection.prepareStatement(INSERT_SNAPSHOT, Statement.RETURN_GENERATED_KEYS); + PreparedStatement insertSnapshotStatement = connection.prepareStatement(INSERT_SNAPSHOT, new String[]{"id"}); insertSnapshot(connection, insertSnapshotStatement, reportId, snapshot); - insertSnapshotStatement.executeBatch(); + insertSnapshotStatement.close(); } catch (SQLException e) { @@ -109,7 +109,7 @@ public class SnapshotRepository extends MinecraftRepository insertSnapshotStatement.setTimestamp(3, new Timestamp(snapshot.getSentTime().atZone(ZONE_ID).toInstant().toEpochMilli())); insertSnapshotStatement.setString(4, snapshot.getMessage()); insertSnapshotStatement.setInt(5, snapshot.getType().getId()); - insertSnapshotStatement.addBatch(); + insertSnapshotStatement.execute(); ResultSet resultSet = insertSnapshotStatement.getGeneratedKeys(); if (resultSet.next()) @@ -122,7 +122,6 @@ public class SnapshotRepository extends MinecraftRepository throw new IllegalStateException("Query did not return a message id (we need one)."); } - insertSnapshotStatement.close(); insertRecipients(connection, snapshotId, snapshot.getRecipientIds()); }