forked from LogBlock/LogBlock
use long when accessing id columns
This commit is contained in:
@ -62,7 +62,7 @@ public class BlockChange implements LookupCacheElement {
|
||||
}
|
||||
|
||||
public BlockChange(ResultSet rs, QueryParams p) throws SQLException {
|
||||
id = p.needId ? rs.getInt("id") : 0;
|
||||
id = p.needId ? rs.getLong("id") : 0;
|
||||
date = p.needDate ? rs.getTimestamp("date").getTime() : 0;
|
||||
loc = p.needCoords ? new Location(p.world, rs.getInt("x"), rs.getInt("y"), rs.getInt("z")) : null;
|
||||
actor = p.needPlayer ? new Actor(rs) : null;
|
||||
|
@ -26,7 +26,7 @@ public class ChatMessage implements LookupCacheElement {
|
||||
}
|
||||
|
||||
public ChatMessage(ResultSet rs, QueryParams p) throws SQLException {
|
||||
id = p.needId ? rs.getInt("id") : 0;
|
||||
id = p.needId ? rs.getLong("id") : 0;
|
||||
date = p.needDate ? rs.getTimestamp("date").getTime() : 0;
|
||||
player = p.needPlayer ? new Actor(rs) : null;
|
||||
playerName = p.needPlayer ? rs.getString("playername") : null;
|
||||
|
@ -965,14 +965,14 @@ public class CommandsHandler implements CommandExecutor {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
if (params.bct == BlockChangeType.CHAT) {
|
||||
sb.append("INSERT INTO `lb-chat` (`id`, `date`, `playerid`, `message`) VALUES (");
|
||||
sb.append(rs.getInt("id")).append(", FROM_UNIXTIME(");
|
||||
sb.append(rs.getLong("id")).append(", FROM_UNIXTIME(");
|
||||
sb.append(rs.getTimestamp("date").getTime() / 1000).append("), ");
|
||||
sb.append(rs.getInt("playerid")).append(", '");
|
||||
sb.append(Utils.mysqlTextEscape(rs.getString("message")));
|
||||
sb.append("');\n");
|
||||
} else if (params.bct == BlockChangeType.KILLS) {
|
||||
sb.append("INSERT INTO `").append(tableBase).append("-kills` (`id`, `date`, `killer`, `victim`, `weapon`, `x`, `y`, `z`) VALUES (");
|
||||
sb.append(rs.getInt("id")).append(", FROM_UNIXTIME(");
|
||||
sb.append(rs.getLong("id")).append(", FROM_UNIXTIME(");
|
||||
sb.append(rs.getTimestamp("date").getTime() / 1000).append("), ");
|
||||
sb.append(rs.getInt("killerid")).append(", ");
|
||||
sb.append(rs.getInt("victimid")).append(", ");
|
||||
@ -985,7 +985,7 @@ public class CommandsHandler implements CommandExecutor {
|
||||
|
||||
} else {
|
||||
sb.append("INSERT INTO `").append(tableBase).append("-blocks` (`id`, `date`, `playerid`, `replaced`, `replacedData`, `type`, `typeData`, `x`, `y`, `z`) VALUES (");
|
||||
sb.append(rs.getInt("id")).append(", FROM_UNIXTIME(");
|
||||
sb.append(rs.getLong("id")).append(", FROM_UNIXTIME(");
|
||||
sb.append(rs.getTimestamp("date").getTime() / 1000).append("), ");
|
||||
sb.append(rs.getInt("playerid")).append(", ");
|
||||
sb.append(rs.getInt("replaced")).append(", ");
|
||||
@ -1000,7 +1000,7 @@ public class CommandsHandler implements CommandExecutor {
|
||||
byte[] typeState = rs.getBytes("typeState");
|
||||
if (replacedState != null || typeState != null) {
|
||||
sb.append("INSERT INTO `").append(tableBase).append("-state` (`id`, `replacedState`, `typeState`) VALUES (");
|
||||
sb.append(rs.getInt("id")).append(", ");
|
||||
sb.append(rs.getLong("id")).append(", ");
|
||||
sb.append(Utils.mysqlPrepareBytesForInsertAllowNull(replacedState)).append(", ");
|
||||
sb.append(Utils.mysqlPrepareBytesForInsertAllowNull(typeState));
|
||||
sb.append(");\n");
|
||||
@ -1008,7 +1008,7 @@ public class CommandsHandler implements CommandExecutor {
|
||||
byte[] item = rs.getBytes("item");
|
||||
if (item != null) {
|
||||
sb.append("INSERT INTO `").append(tableBase).append("-chestdata` (`id`, `item`, `itemremove`, `itemtype`) VALUES (");
|
||||
sb.append(rs.getInt("id")).append(", ");
|
||||
sb.append(rs.getLong("id")).append(", ");
|
||||
sb.append(Utils.mysqlPrepareBytesForInsertAllowNull(item)).append(", ");
|
||||
sb.append(rs.getInt("itemremove")).append(", ");
|
||||
sb.append(rs.getInt("itemtype"));
|
||||
|
@ -67,7 +67,7 @@ public class Consumer extends Thread {
|
||||
private final LogBlock logblock;
|
||||
private final Map<Actor, Integer> playerIds = new HashMap<>();
|
||||
private final Map<Actor, Integer> uncommitedPlayerIds = new HashMap<>();
|
||||
private final Map<World, Map<UUID, Integer>> uncommitedEntityIds = new HashMap<>();
|
||||
private final Map<World, Map<UUID, Long>> uncommitedEntityIds = new HashMap<>();
|
||||
|
||||
private long addEntryCounter;
|
||||
private long nextWarnCounter;
|
||||
@ -650,13 +650,13 @@ public class Consumer extends Thread {
|
||||
return uncommitedPlayerIds.containsKey(actor);
|
||||
}
|
||||
|
||||
private int getEntityUUID(Connection conn, World world, UUID uuid) throws SQLException {
|
||||
Map<UUID, Integer> uncommitedEntityIdsHere = uncommitedEntityIds.get(world);
|
||||
private long getEntityUUID(Connection conn, World world, UUID uuid) throws SQLException {
|
||||
Map<UUID, Long> uncommitedEntityIdsHere = uncommitedEntityIds.get(world);
|
||||
if (uncommitedEntityIdsHere == null) {
|
||||
uncommitedEntityIdsHere = new HashMap<>();
|
||||
uncommitedEntityIds.put(world, uncommitedEntityIdsHere);
|
||||
}
|
||||
Integer existing = uncommitedEntityIdsHere.get(uuid);
|
||||
Long existing = uncommitedEntityIdsHere.get(uuid);
|
||||
if (existing != null) {
|
||||
return existing;
|
||||
}
|
||||
@ -670,7 +670,7 @@ public class Consumer extends Thread {
|
||||
int q1Result = state.executeUpdate(q1);
|
||||
ResultSet rs = state.executeQuery(q2);
|
||||
if (rs.next()) {
|
||||
uncommitedEntityIdsHere.put(uuid, rs.getInt(1));
|
||||
uncommitedEntityIdsHere.put(uuid, rs.getLong(1));
|
||||
}
|
||||
rs.close();
|
||||
// if there was not any row in the table the query above does not work, so we need to try this one
|
||||
@ -678,7 +678,7 @@ public class Consumer extends Thread {
|
||||
state.executeUpdate("INSERT IGNORE INTO `" + table + "-entityids` (entityuuid) VALUES ('" + mysqlTextEscape(uuidString) + "')");
|
||||
rs = state.executeQuery(q2);
|
||||
if (rs.next()) {
|
||||
uncommitedEntityIdsHere.put(uuid, rs.getInt(1));
|
||||
uncommitedEntityIdsHere.put(uuid, rs.getLong(1));
|
||||
} else {
|
||||
logblock.getLogger().warning("[Consumer] Failed to add entity uuid " + uuidString.toString());
|
||||
logblock.getLogger().warning("[Consumer-Debug] World: " + world.getName());
|
||||
@ -881,22 +881,22 @@ public class Consumer extends Thread {
|
||||
smt.setInt(8, safeY(loc));
|
||||
smt.setInt(9, loc.getBlockZ());
|
||||
batchHelper.addUncommitedBlockActorId(loc, sourceActor);
|
||||
batchHelper.addBatch(smt, new IntCallback() {
|
||||
batchHelper.addBatch(smt, new LongCallback() {
|
||||
@Override
|
||||
public void call(int id) throws SQLException {
|
||||
public void call(long id) throws SQLException {
|
||||
PreparedStatement ps;
|
||||
if (typeState != null || replacedState != null) {
|
||||
ps = batchHelper.getOrPrepareStatement(conn, getWorldConfig(loc.getWorld()).insertBlockStateStatementString, Statement.NO_GENERATED_KEYS);
|
||||
ps.setBytes(1, replacedState);
|
||||
ps.setBytes(2, typeState);
|
||||
ps.setInt(3, id);
|
||||
ps.setLong(3, id);
|
||||
batchHelper.addBatch(ps, null);
|
||||
}
|
||||
if (ca != null) {
|
||||
ps = batchHelper.getOrPrepareStatement(conn, getWorldConfig(loc.getWorld()).insertBlockChestDataStatementString, Statement.NO_GENERATED_KEYS);
|
||||
ps.setBytes(1, finalSerializedItemStack);
|
||||
ps.setInt(2, ca.remove ? 1 : 0);
|
||||
ps.setInt(3, id);
|
||||
ps.setLong(3, id);
|
||||
ps.setInt(4, ca.itemType);
|
||||
batchHelper.addBatch(ps, null);
|
||||
}
|
||||
@ -1108,7 +1108,7 @@ public class Consumer extends Thread {
|
||||
PreparedStatement smt = batchHelper.getOrPrepareStatement(conn, statementString, Statement.NO_GENERATED_KEYS);
|
||||
smt.setLong(1, date);
|
||||
smt.setInt(2, sourceActor);
|
||||
smt.setInt(3, getEntityUUID(conn, loc.getWorld(), entityUUID));
|
||||
smt.setLong(3, getEntityUUID(conn, loc.getWorld(), entityUUID));
|
||||
smt.setInt(4, EntityTypeConverter.getOrAddEntityTypeId(type));
|
||||
smt.setInt(5, loc.getBlockX());
|
||||
smt.setInt(6, safeY(loc));
|
||||
@ -1121,11 +1121,11 @@ public class Consumer extends Thread {
|
||||
|
||||
private class EntityUUIDChange implements Row {
|
||||
private final World world;
|
||||
private final int entityId;
|
||||
private final long entityId;
|
||||
private final UUID entityUUID;
|
||||
final String updateEntityUUIDString;
|
||||
|
||||
public EntityUUIDChange(World world, int entityId, UUID entityUUID) {
|
||||
public EntityUUIDChange(World world, long entityId, UUID entityUUID) {
|
||||
this.world = world;
|
||||
this.entityId = entityId;
|
||||
this.entityUUID = entityUUID;
|
||||
@ -1150,7 +1150,7 @@ public class Consumer extends Thread {
|
||||
public void process(Connection conn, BatchHelper batchHelper) throws SQLException {
|
||||
PreparedStatement smt = batchHelper.getOrPrepareStatement(conn, updateEntityUUIDString, Statement.NO_GENERATED_KEYS);
|
||||
smt.setString(1, entityUUID.toString());
|
||||
smt.setInt(2, entityId);
|
||||
smt.setLong(2, entityId);
|
||||
smt.executeUpdate();
|
||||
}
|
||||
}
|
||||
@ -1169,7 +1169,7 @@ public class Consumer extends Thread {
|
||||
private class BatchHelper {
|
||||
private HashMap<String, PreparedStatement> preparedStatements = new HashMap<>();
|
||||
private HashSet<PreparedStatement> preparedStatementsWithGeneratedKeys = new HashSet<>();
|
||||
private LinkedHashMap<PreparedStatement, ArrayList<IntCallback>> generatedKeyHandler = new LinkedHashMap<>();
|
||||
private LinkedHashMap<PreparedStatement, ArrayList<LongCallback>> generatedKeyHandler = new LinkedHashMap<>();
|
||||
private HashMap<Location, Integer> uncommitedBlockActors = new HashMap<>();
|
||||
|
||||
public void reset() {
|
||||
@ -1189,21 +1189,21 @@ public class Consumer extends Thread {
|
||||
|
||||
public void processStatements(Connection conn) throws SQLException {
|
||||
while (!generatedKeyHandler.isEmpty()) {
|
||||
Entry<PreparedStatement, ArrayList<IntCallback>> entry = generatedKeyHandler.entrySet().iterator().next();
|
||||
Entry<PreparedStatement, ArrayList<LongCallback>> entry = generatedKeyHandler.entrySet().iterator().next();
|
||||
PreparedStatement smt = entry.getKey();
|
||||
ArrayList<IntCallback> callbackList = entry.getValue();
|
||||
ArrayList<LongCallback> callbackList = entry.getValue();
|
||||
generatedKeyHandler.remove(smt);
|
||||
smt.executeBatch();
|
||||
if (preparedStatementsWithGeneratedKeys.contains(smt)) {
|
||||
ResultSet keys = smt.getGeneratedKeys();
|
||||
int[] results = new int[callbackList.size()];
|
||||
long[] results = new long[callbackList.size()];
|
||||
int pos = 0;
|
||||
while (keys.next() && pos < results.length) {
|
||||
results[pos++] = keys.getInt(1);
|
||||
results[pos++] = keys.getLong(1);
|
||||
}
|
||||
keys.close();
|
||||
for (int i = 0; i < results.length; i++) {
|
||||
IntCallback callback = callbackList.get(i);
|
||||
LongCallback callback = callbackList.get(i);
|
||||
if (callback != null) {
|
||||
callback.call(results[i]);
|
||||
}
|
||||
@ -1225,9 +1225,9 @@ public class Consumer extends Thread {
|
||||
return smt;
|
||||
}
|
||||
|
||||
public void addBatch(PreparedStatement smt, IntCallback generatedKeysCallback) throws SQLException {
|
||||
public void addBatch(PreparedStatement smt, LongCallback generatedKeysCallback) throws SQLException {
|
||||
smt.addBatch();
|
||||
ArrayList<IntCallback> callbackList = generatedKeyHandler.get(smt);
|
||||
ArrayList<LongCallback> callbackList = generatedKeyHandler.get(smt);
|
||||
if (callbackList == null) {
|
||||
callbackList = new ArrayList<>();
|
||||
generatedKeyHandler.put(smt, callbackList);
|
||||
@ -1236,7 +1236,7 @@ public class Consumer extends Thread {
|
||||
}
|
||||
}
|
||||
|
||||
protected interface IntCallback {
|
||||
public void call(int value) throws SQLException;
|
||||
protected interface LongCallback {
|
||||
public void call(long value) throws SQLException;
|
||||
}
|
||||
}
|
||||
|
@ -60,7 +60,7 @@ public class EntityChange implements LookupCacheElement {
|
||||
}
|
||||
|
||||
public EntityChange(ResultSet rs, QueryParams p) throws SQLException {
|
||||
id = p.needId ? rs.getInt("id") : 0;
|
||||
id = p.needId ? rs.getLong("id") : 0;
|
||||
date = p.needDate ? rs.getTimestamp("date").getTime() : 0;
|
||||
loc = p.needCoords ? new Location(p.world, rs.getInt("x"), rs.getInt("y"), rs.getInt("z")) : null;
|
||||
actor = p.needPlayer ? new Actor(rs) : null;
|
||||
|
@ -30,7 +30,7 @@ public class Kill implements LookupCacheElement {
|
||||
}
|
||||
|
||||
public Kill(ResultSet rs, QueryParams p) throws SQLException {
|
||||
id = p.needId ? rs.getInt("id") : 0;
|
||||
id = p.needId ? rs.getLong("id") : 0;
|
||||
date = p.needDate ? rs.getTimestamp("date").getTime() : 0;
|
||||
loc = p.needCoords ? new Location(p.world, rs.getInt("x"), rs.getInt("y"), rs.getInt("z")) : null;
|
||||
killerName = p.needKiller ? rs.getString("killer") : null;
|
||||
|
@ -439,7 +439,7 @@ class Updater {
|
||||
ResultSet entries = st.executeQuery("SELECT id, date, playerid, replaced, type, data, x, y, z FROM `" + wcfg.table + "` ORDER BY id ASC LIMIT " + BLOCKS_CONVERT_BATCH_SIZE);
|
||||
while (entries.next()) {
|
||||
hadRow = true;
|
||||
int id = entries.getInt("id");
|
||||
long id = entries.getLong("id");
|
||||
Timestamp date = entries.getTimestamp("date");
|
||||
int playerid = entries.getInt("playerid");
|
||||
int replaced = entries.getInt("replaced");
|
||||
@ -462,7 +462,7 @@ class Updater {
|
||||
int newSetId = MaterialConverter.getOrAddMaterialId(setBlockData);
|
||||
int newSetData = MaterialConverter.getOrAddBlockStateId(setBlockData);
|
||||
|
||||
insertStatement.setInt(1, id);
|
||||
insertStatement.setLong(1, id);
|
||||
insertStatement.setTimestamp(2, date);
|
||||
insertStatement.setInt(3, playerid);
|
||||
insertStatement.setInt(4, newReplacedId);
|
||||
@ -476,7 +476,7 @@ class Updater {
|
||||
} catch (Exception e) {
|
||||
logblock.getLogger().info("Exception in entry " + id + " (" + replaced + ":" + data + "->" + type + ":" + data + "): " + e.getMessage());
|
||||
}
|
||||
deleteStatement.setInt(1, id);
|
||||
deleteStatement.setLong(1, id);
|
||||
deleteStatement.addBatch();
|
||||
|
||||
done++;
|
||||
@ -522,7 +522,7 @@ class Updater {
|
||||
boolean anyRow = false;
|
||||
while (rs.next()) {
|
||||
anyRow = true;
|
||||
int id = rs.getInt("id");
|
||||
long id = rs.getLong("id");
|
||||
int itemtype = rs.getInt("itemtype");
|
||||
int itemdata = rs.getInt("itemdata");
|
||||
int amount = rs.getInt("itemamount");
|
||||
@ -532,13 +532,13 @@ class Updater {
|
||||
}
|
||||
@SuppressWarnings("deprecation")
|
||||
ItemStack stack = weaponMaterial.getMaxDurability() > 0 ? new ItemStack(weaponMaterial, Math.abs(amount), (short) itemdata) : new ItemStack(weaponMaterial, Math.abs(amount));
|
||||
insertChestData.setInt(1, id);
|
||||
insertChestData.setLong(1, id);
|
||||
insertChestData.setBytes(2, Utils.saveItemStack(stack));
|
||||
insertChestData.setInt(3, amount >= 0 ? 0 : 1);
|
||||
insertChestData.setInt(4, MaterialConverter.getOrAddMaterialId(weaponMaterial));
|
||||
insertChestData.addBatch();
|
||||
|
||||
deleteChest.setInt(1, id);
|
||||
deleteChest.setLong(1, id);
|
||||
deleteChest.addBatch();
|
||||
done++;
|
||||
}
|
||||
@ -585,7 +585,7 @@ class Updater {
|
||||
boolean anyRow = false;
|
||||
while (rs.next()) {
|
||||
anyRow = true;
|
||||
int id = rs.getInt("id");
|
||||
long id = rs.getLong("id");
|
||||
int weapon = rs.getInt("weapon");
|
||||
Material weaponMaterial = materialUpdater.getMaterial(weapon, 0);
|
||||
if (weaponMaterial == null) {
|
||||
@ -595,7 +595,7 @@ class Updater {
|
||||
if (newWeapon != weapon) {
|
||||
anyUpdate = true;
|
||||
updateWeaponStatement.setInt(1, newWeapon);
|
||||
updateWeaponStatement.setInt(2, id);
|
||||
updateWeaponStatement.setLong(2, id);
|
||||
updateWeaponStatement.addBatch();
|
||||
}
|
||||
done++;
|
||||
@ -666,7 +666,7 @@ class Updater {
|
||||
boolean anyRow = false;
|
||||
while (rs.next()) {
|
||||
anyRow = true;
|
||||
int id = rs.getInt("id");
|
||||
long id = rs.getLong("id");
|
||||
String signText = rs.getString("signtext");
|
||||
int replaced = rs.getInt("replaced");
|
||||
boolean nullBlock = rs.wasNull();
|
||||
@ -681,13 +681,13 @@ class Updater {
|
||||
boolean wasSign = replacedMaterial == Material.OAK_SIGN || replacedMaterial == Material.OAK_WALL_SIGN;
|
||||
boolean isSign = typeMaterial == Material.OAK_SIGN || typeMaterial == Material.OAK_WALL_SIGN;
|
||||
|
||||
insertSignState.setInt(1, id);
|
||||
insertSignState.setLong(1, id);
|
||||
insertSignState.setBytes(2, wasSign ? bytes : null);
|
||||
insertSignState.setBytes(3, isSign ? bytes : null);
|
||||
insertSignState.addBatch();
|
||||
}
|
||||
|
||||
deleteSign.setInt(1, id);
|
||||
deleteSign.setLong(1, id);
|
||||
deleteSign.addBatch();
|
||||
done++;
|
||||
}
|
||||
|
Reference in New Issue
Block a user