Switch report ids to use data type 'long'

This is because in the database we store them as an unsigned integer, which means the Java integer type will not be able to hold values after a certain point.
This commit is contained in:
Keir Nellyer 2016-06-23 14:11:58 +01:00
parent addbd4dd88
commit 4606f27408
9 changed files with 31 additions and 31 deletions

View File

@ -53,7 +53,7 @@ public class SnapshotRepository extends MinecraftRepository
}
public CompletableFuture<Void> insertSnapshots(int reportId, Collection<Snapshot> snapshots)
public CompletableFuture<Void> insertSnapshots(long reportId, Collection<Snapshot> snapshots)
{
return CompletableFuture.supplyAsync(() ->
{
@ -78,7 +78,7 @@ public class SnapshotRepository extends MinecraftRepository
});
}
public CompletableFuture<Void> insertSnapshot(int reportId, Snapshot snapshot)
public CompletableFuture<Void> insertSnapshot(long reportId, Snapshot snapshot)
{
return CompletableFuture.supplyAsync(() ->
{
@ -98,7 +98,7 @@ public class SnapshotRepository extends MinecraftRepository
}
// 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, long reportId, Snapshot snapshot) throws SQLException
{
long snapshotId = snapshot.getId().orElse((long) -1);
@ -143,10 +143,10 @@ public class SnapshotRepository extends MinecraftRepository
insertRecipientStatement.executeBatch();
}
private void insertReportMapping(Connection connection, int reportId, long messageId) throws SQLException
private void insertReportMapping(Connection connection, long reportId, long messageId) throws SQLException
{
PreparedStatement reportSnapshotMapping = connection.prepareStatement(INSERT_REPORT_SNAPSHOT_MAPPING);
reportSnapshotMapping.setInt(1, reportId);
reportSnapshotMapping.setLong(1, reportId);
reportSnapshotMapping.setLong(2, messageId);
reportSnapshotMapping.execute();
}

View File

@ -12,7 +12,7 @@ import org.apache.commons.lang3.RandomStringUtils;
*/
public class Report
{
protected Integer _reportId;
protected Long _reportId;
private final int _suspectId;
private final ReportCategory _category;
// set of player account ids and the reason they reported this player
@ -26,14 +26,14 @@ public class Report
this(null, suspectId, category);
}
protected Report(Integer reportId, int suspectId, ReportCategory category)
protected Report(Long reportId, int suspectId, ReportCategory category)
{
_reportId = reportId;
_suspectId = suspectId;
_category = category;
}
public Optional<Integer> getReportId()
public Optional<Long> getReportId()
{
return Optional.ofNullable(_reportId);
}

View File

@ -84,7 +84,7 @@ public class ReportManager
return _reportRepository;
}
public void closeReport(int reportId, Player reportCloser, ReportResult reportResult)
public void closeReport(long reportId, Player reportCloser, ReportResult reportResult)
{
CompletableFuture<Report> reportFuture = _reportRepository.getReport(reportId);
@ -125,7 +125,7 @@ public class ReportManager
);
}
public void handleReport(int reportId, Player reportHandler)
public void handleReport(long reportId, Player reportHandler)
{
_reportRepository.getReport(reportId).thenCompose(BukkitFuture.accept(report ->
{
@ -215,7 +215,7 @@ public class ReportManager
});
}
public CompletableFuture<Boolean> isActiveReport(int reportId)
public CompletableFuture<Boolean> isActiveReport(long reportId)
{
return getReportRepository().getReport(reportId).thenCompose(this::isActiveReport);
}
@ -353,7 +353,7 @@ public class ReportManager
public static String getReportPrefix(Report report)
{
Optional<Integer> reportIdOptional = report.getReportId();
Optional<Long> reportIdOptional = report.getReportId();
if (reportIdOptional.isPresent())
{
@ -365,7 +365,7 @@ public class ReportManager
}
}
public static String getReportPrefix(int reportId)
public static String getReportPrefix(long reportId)
{
return NAME + " #" + reportId;
}

View File

@ -89,7 +89,7 @@ public class ReportRepository extends MinecraftRepository
private final ReportManager _reportManager;
private final Cache<Integer, Report> _cachedReports = CacheBuilder.newBuilder()
private final Cache<Long, Report> _cachedReports = CacheBuilder.newBuilder()
.maximumSize(1000)
.expireAfterAccess(5, TimeUnit.MINUTES)
.build();
@ -146,7 +146,7 @@ public class ReportRepository extends MinecraftRepository
.collect(Collectors.toList()));
}
public CompletableFuture<Report> getReport(int reportId)
public CompletableFuture<Report> getReport(long reportId)
{
if (reportId != -1)
{
@ -163,7 +163,7 @@ public class ReportRepository extends MinecraftRepository
try (Connection connection = DBPool.getAccount().getConnection())
{
PreparedStatement preparedStatement = connection.prepareStatement(GET_REPORT);
preparedStatement.setInt(1, reportId);
preparedStatement.setLong(1, reportId);
ResultSet resultSet = preparedStatement.executeQuery();
if (resultSet.next())
@ -272,7 +272,7 @@ public class ReportRepository extends MinecraftRepository
});
}
private CompletableFuture<Set<ReportMessage>> getReportReasons(int reportId)
private CompletableFuture<Set<ReportMessage>> getReportReasons(long reportId)
{
return CompletableFuture.supplyAsync(() ->
{
@ -281,7 +281,7 @@ public class ReportRepository extends MinecraftRepository
try (Connection connection = DBPool.getAccount().getConnection())
{
PreparedStatement preparedStatement = connection.prepareStatement(GET_REPORT_REASONS);
preparedStatement.setInt(1, reportId);
preparedStatement.setLong(1, reportId);
ResultSet resultSet = preparedStatement.executeQuery();
while (resultSet.next())
@ -345,7 +345,7 @@ public class ReportRepository extends MinecraftRepository
ResultSet resultSet = preparedStatement.getGeneratedKeys();
if (resultSet.next())
{
report._reportId = resultSet.getInt(1);
report._reportId = resultSet.getLong(1);
}
else if (!report.getReportId().isPresent())
{
@ -353,7 +353,7 @@ public class ReportRepository extends MinecraftRepository
}
}
Optional<Integer> idOptional = report.getReportId();
Optional<Long> idOptional = report.getReportId();
if (idOptional.isPresent())
{
@ -364,7 +364,7 @@ public class ReportRepository extends MinecraftRepository
for (Map.Entry<Integer, ReportMessage> entry : report.getMessages().entrySet())
{
ReportMessage reportMessage = entry.getValue();
setReportMessageStatement.setInt(1, idOptional.get()); // report id
setReportMessageStatement.setLong(1, idOptional.get()); // report id
setReportMessageStatement.setInt(2, entry.getKey()); // reporter id
setReportMessageStatement.setString(3, reportMessage.getMessage()); // reason
setReportMessageStatement.setString(4, reportMessage.getServer()); // server
@ -376,7 +376,7 @@ public class ReportRepository extends MinecraftRepository
Optional<Integer> handlerIdOptional = report.getHandlerId();
if (handlerIdOptional.isPresent())
{
setReportHandlerStatement.setInt(1, idOptional.get()); // report id
setReportHandlerStatement.setLong(1, idOptional.get()); // report id
setReportHandlerStatement.setInt(2, handlerIdOptional.get()); // handler id
setReportHandlerStatement.addBatch();
}
@ -385,7 +385,7 @@ public class ReportRepository extends MinecraftRepository
if (reportResultOptional.isPresent())
{
ReportResult reportResult = reportResultOptional.get();
setReportResultStatement.setInt(1, idOptional.get()); // report id
setReportResultStatement.setLong(1, idOptional.get()); // report id
setReportResultStatement.setInt(2, reportResult.getResultType().getId()); // result id
setReportResultStatement.setString(3, reportResult.getReason()); // reason
setReportResultStatement.setTimestamp(4, new Timestamp(reportResult.getClosedTime().getTime())); // closed time
@ -454,7 +454,7 @@ public class ReportRepository extends MinecraftRepository
}
}
protected void clearCache(int reportId)
protected void clearCache(long reportId)
{
_cachedReports.invalidate(reportId);
}

View File

@ -28,7 +28,7 @@ public class ReportCloseCommand extends CommandBase<ReportPlugin>
}
else
{
int reportId = Integer.parseInt(args[0]);
long reportId = Long.parseLong(args[0]);
String reason = F.combine(args, 1, null, false);
Plugin.getReportManager().isActiveReport(reportId).thenCompose(BukkitFuture.accept(isActive ->

View File

@ -26,7 +26,7 @@ public class ReportHandleCommand extends CommandBase<ReportPlugin>
}
else
{
int reportId = Integer.parseInt(args[0]);
long reportId = Long.parseLong(args[0]);
Plugin.getReportManager().handleReport(reportId, player);
}
}

View File

@ -9,7 +9,7 @@ import mineplex.core.report.ReportMessage;
*/
public class ReportHandlerNotification extends ReportNotification
{
private int _reportId;
private long _reportId;
private int _handlerId;
public ReportHandlerNotification(Report report, JsonMessage notification)
@ -27,7 +27,7 @@ public class ReportHandlerNotification extends ReportNotification
return report.getMessages().values().stream().map(ReportMessage::getServer).distinct().toArray(String[]::new);
}
public int getReportId()
public long getReportId()
{
return _reportId;
}

View File

@ -33,7 +33,7 @@ public class ReportHandlerMessageTask extends BukkitRunnable
@Override
public void run()
{
int reportId = _report.getReportId().orElse(-1);
long reportId = _report.getReportId().orElse((long) -1);
_reportManager.isActiveReport(_report).thenAccept(isActive ->
{

View File

@ -15,11 +15,11 @@ import mineplex.core.report.ReportResultType;
public class ReportResultPage extends SimpleGui
{
private ReportManager _reportManager;
private int _reportId;
private long _reportId;
private Player _reportCloser;
private String _reason;
public ReportResultPage(ReportPlugin reportPlugin, int reportId, Player reportCloser, String reason)
public ReportResultPage(ReportPlugin reportPlugin, long reportId, Player reportCloser, String reason)
{
super(reportPlugin.getPlugin(), reportCloser, "Report Result", 9 * 3);
_reportManager = reportPlugin.getReportManager();