Improve readability by separating these functions out
This commit is contained in:
parent
352ecc6ad6
commit
2931826916
@ -7,26 +7,13 @@ import java.sql.SQLException;
|
|||||||
import java.sql.Timestamp;
|
import java.sql.Timestamp;
|
||||||
import java.time.ZoneId;
|
import java.time.ZoneId;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Optional;
|
|
||||||
import java.util.Set;
|
|
||||||
import java.util.UUID;
|
|
||||||
import java.util.concurrent.CompletableFuture;
|
import java.util.concurrent.CompletableFuture;
|
||||||
import java.util.stream.Collectors;
|
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
|
||||||
import com.google.gson.JsonObject;
|
|
||||||
import com.mysql.jdbc.Statement;
|
import com.mysql.jdbc.Statement;
|
||||||
import mineplex.core.database.MinecraftRepository;
|
import mineplex.core.database.MinecraftRepository;
|
||||||
import mineplex.serverdata.Utility;
|
|
||||||
import mineplex.serverdata.database.DBPool;
|
import mineplex.serverdata.database.DBPool;
|
||||||
import mineplex.serverdata.servers.ServerManager;
|
|
||||||
import redis.clients.jedis.Jedis;
|
|
||||||
import redis.clients.jedis.JedisPool;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class responsible for publishing snapshots on the website via Redis and a separate Report server.
|
* Class responsible for publishing snapshots on the website via Redis and a separate Report server.
|
||||||
@ -113,9 +100,9 @@ public class SnapshotRepository extends MinecraftRepository
|
|||||||
// this allows snapshots to be inserted in batch
|
// this allows snapshots to be inserted in batch
|
||||||
private void insertSnapshot(Connection connection, PreparedStatement insertSnapshotStatement, int reportId, Snapshot snapshot) throws SQLException
|
private void insertSnapshot(Connection connection, PreparedStatement insertSnapshotStatement, int reportId, Snapshot snapshot) throws SQLException
|
||||||
{
|
{
|
||||||
long messageId = snapshot.getId().orElse((long) -1);
|
long snapshotId = snapshot.getId().orElse((long) -1);
|
||||||
|
|
||||||
if (messageId == -1)
|
if (snapshotId == -1)
|
||||||
{
|
{
|
||||||
insertSnapshotStatement.setInt(1, snapshot.getSenderId());
|
insertSnapshotStatement.setInt(1, snapshot.getSenderId());
|
||||||
insertSnapshotStatement.setString(2, _serverName);
|
insertSnapshotStatement.setString(2, _serverName);
|
||||||
@ -127,8 +114,8 @@ public class SnapshotRepository extends MinecraftRepository
|
|||||||
ResultSet resultSet = insertSnapshotStatement.getGeneratedKeys();
|
ResultSet resultSet = insertSnapshotStatement.getGeneratedKeys();
|
||||||
if (resultSet.next())
|
if (resultSet.next())
|
||||||
{
|
{
|
||||||
messageId = resultSet.getLong(1);
|
snapshotId = resultSet.getLong(1);
|
||||||
snapshot._id = messageId;
|
snapshot._id = snapshotId;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -136,23 +123,27 @@ public class SnapshotRepository extends MinecraftRepository
|
|||||||
}
|
}
|
||||||
|
|
||||||
insertSnapshotStatement.close();
|
insertSnapshotStatement.close();
|
||||||
|
insertRecipients(connection, snapshotId, snapshot.getRecipientIds());
|
||||||
PreparedStatement insertRecipientStatement = connection.prepareStatement(INSERT_SNAPSHOT_RECIPIENT);
|
|
||||||
|
|
||||||
for (int recipientId : snapshot.getRecipientIds())
|
|
||||||
{
|
|
||||||
insertRecipientStatement.setLong(1, messageId);
|
|
||||||
insertRecipientStatement.setInt(2, recipientId);
|
|
||||||
insertRecipientStatement.addBatch();
|
|
||||||
}
|
|
||||||
|
|
||||||
insertRecipientStatement.executeBatch();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
insertReportSnapshotMapping(connection, reportId, messageId);
|
insertReportMapping(connection, reportId, snapshotId);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void insertReportSnapshotMapping(Connection connection, int reportId, long messageId) throws SQLException
|
private void insertRecipients(Connection connection, long snapshotId, Collection<Integer> recipients) throws SQLException
|
||||||
|
{
|
||||||
|
PreparedStatement insertRecipientStatement = connection.prepareStatement(INSERT_SNAPSHOT_RECIPIENT);
|
||||||
|
|
||||||
|
for (int recipientId : recipients)
|
||||||
|
{
|
||||||
|
insertRecipientStatement.setLong(1, snapshotId);
|
||||||
|
insertRecipientStatement.setInt(2, recipientId);
|
||||||
|
insertRecipientStatement.addBatch();
|
||||||
|
}
|
||||||
|
|
||||||
|
insertRecipientStatement.executeBatch();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void insertReportMapping(Connection connection, int reportId, long messageId) throws SQLException
|
||||||
{
|
{
|
||||||
PreparedStatement reportSnapshotMapping = connection.prepareStatement(INSERT_REPORT_SNAPSHOT_MAPPING);
|
PreparedStatement reportSnapshotMapping = connection.prepareStatement(INSERT_REPORT_SNAPSHOT_MAPPING);
|
||||||
reportSnapshotMapping.setInt(1, reportId);
|
reportSnapshotMapping.setInt(1, reportId);
|
||||||
|
Loading…
Reference in New Issue
Block a user