Unfortunately we can't batch these SQL commands as we have to retrieve the snapshot id after inserting
This commit is contained in:
parent
e6989cd8da
commit
7f75a7ff50
@ -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());
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user