mirror of
https://github.com/plan-player-analytics/Plan.git
synced 2024-12-27 09:00:28 +08:00
Attempts to fix #311 RegisterProcessor MySQL Constraint exception (Duplicate key uuid)
This commit is contained in:
parent
03f68110b6
commit
6101b94055
@ -84,12 +84,15 @@ public class UserInfoTable extends UserIDTable {
|
||||
PreparedStatement statement = null;
|
||||
ResultSet set = null;
|
||||
try (Connection connection = getConnection()) {
|
||||
statement = connection.prepareStatement(Select.from(tableName, columnUserID)
|
||||
statement = connection.prepareStatement(Select.from(tableName, "COUNT(" + columnUserID + ") as c")
|
||||
.where(columnUserID + "=" + usersTable.statementSelectID)
|
||||
.toString());
|
||||
statement.setString(1, uuid.toString());
|
||||
set = statement.executeQuery();
|
||||
return set.next();
|
||||
if (set.next()) {
|
||||
return set.getInt("c") >= 1;
|
||||
}
|
||||
return false;
|
||||
} finally {
|
||||
close(set, statement);
|
||||
}
|
||||
@ -161,7 +164,7 @@ public class UserInfoTable extends UserIDTable {
|
||||
public List<UserInfo> getServerUserInfo(UUID serverUUID) throws SQLException {
|
||||
PreparedStatement statement = null;
|
||||
ResultSet set = null;
|
||||
try (Connection connection = getConnection()){
|
||||
try (Connection connection = getConnection()) {
|
||||
List<UserInfo> userInfo = new ArrayList<>();
|
||||
String usersIDColumn = usersTable + "." + usersTable.getColumnID();
|
||||
String usersUUIDColumn = usersTable + "." + usersTable.getColumnUUID() + " as uuid";
|
||||
@ -199,7 +202,7 @@ public class UserInfoTable extends UserIDTable {
|
||||
public Map<UUID, List<UserInfo>> getAllUserInfo() throws SQLException {
|
||||
PreparedStatement statement = null;
|
||||
ResultSet set = null;
|
||||
try (Connection connection = getConnection()){
|
||||
try (Connection connection = getConnection()) {
|
||||
String usersIDColumn = usersTable + "." + usersTable.getColumnID();
|
||||
String usersUUIDColumn = usersTable + "." + usersTable.getColumnUUID() + " as uuid";
|
||||
String serverIDColumn = serverTable + "." + serverTable.getColumnID();
|
||||
@ -242,7 +245,7 @@ public class UserInfoTable extends UserIDTable {
|
||||
return;
|
||||
}
|
||||
PreparedStatement statement = null;
|
||||
try (Connection connection = getConnection()){
|
||||
try (Connection connection = getConnection()) {
|
||||
statement = connection.prepareStatement("INSERT INTO " + tableName + " (" +
|
||||
columnUserID + ", " +
|
||||
columnRegistered + ", " +
|
||||
@ -278,7 +281,7 @@ public class UserInfoTable extends UserIDTable {
|
||||
public Map<UUID, Set<UUID>> getSavedUUIDs() throws SQLException {
|
||||
PreparedStatement statement = null;
|
||||
ResultSet set = null;
|
||||
try (Connection connection = getConnection()){
|
||||
try (Connection connection = getConnection()) {
|
||||
String usersIDColumn = usersTable + "." + usersTable.getColumnID();
|
||||
String usersUUIDColumn = usersTable + "." + usersTable.getColumnUUID() + " as uuid";
|
||||
String serverIDColumn = serverTable + "." + serverTable.getColumnID();
|
||||
|
@ -180,12 +180,15 @@ public class UsersTable extends UserIDTable {
|
||||
PreparedStatement statement = null;
|
||||
ResultSet set = null;
|
||||
try (Connection connection = getConnection()) {
|
||||
statement = connection.prepareStatement(Select.from(tableName, columnID)
|
||||
statement = connection.prepareStatement(Select.from(tableName, "COUNT(" + columnID + ") as c")
|
||||
.where(columnUUID + "=?")
|
||||
.toString());
|
||||
statement.setString(1, uuid.toString());
|
||||
set = statement.executeQuery();
|
||||
return set.next();
|
||||
if (set.next()) {
|
||||
return set.getInt("c") >= 1;
|
||||
}
|
||||
return false;
|
||||
} finally {
|
||||
close(set, statement);
|
||||
}
|
||||
@ -423,7 +426,7 @@ public class UsersTable extends UserIDTable {
|
||||
public int getPlayerCount() throws SQLException {
|
||||
PreparedStatement statement = null;
|
||||
ResultSet set = null;
|
||||
try (Connection connection = getConnection()){
|
||||
try (Connection connection = getConnection()) {
|
||||
statement = connection.prepareStatement("SELECT COUNT(*) AS player_count FROM " + tableName);
|
||||
statement.setFetchSize(5000);
|
||||
|
||||
|
@ -14,7 +14,9 @@ import main.java.com.djrapitops.plan.database.databases.MySQLDB;
|
||||
import main.java.com.djrapitops.plan.database.databases.SQLDB;
|
||||
import main.java.com.djrapitops.plan.database.databases.SQLiteDB;
|
||||
import main.java.com.djrapitops.plan.database.tables.*;
|
||||
import main.java.com.djrapitops.plan.systems.cache.DataCache;
|
||||
import main.java.com.djrapitops.plan.systems.info.server.ServerInfo;
|
||||
import main.java.com.djrapitops.plan.systems.processing.player.RegisterProcessor;
|
||||
import main.java.com.djrapitops.plan.utilities.ManageUtils;
|
||||
import main.java.com.djrapitops.plan.utilities.MiscUtils;
|
||||
import main.java.com.djrapitops.plan.utilities.analysis.MathUtils;
|
||||
@ -38,6 +40,7 @@ import java.sql.SQLException;
|
||||
import java.util.*;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.powermock.api.mockito.PowerMockito.when;
|
||||
|
||||
/**
|
||||
* @author Rsl1122
|
||||
@ -62,6 +65,14 @@ public class DatabaseTest {
|
||||
db = new SQLiteDB(plan, "debug" + MiscUtils.getTime());
|
||||
db.init();
|
||||
|
||||
when(plan.getDB()).thenReturn(db);
|
||||
DataCache dataCache = new DataCache(plan) {
|
||||
@Override
|
||||
public void markFirstSession(UUID uuid) {
|
||||
}
|
||||
};
|
||||
when(plan.getDataCache()).thenReturn(dataCache);
|
||||
|
||||
db.getServerTable().saveCurrentServerInfo(new ServerInfo(-1, TestInit.getServerUUID(), "ServerName", "", 20));
|
||||
|
||||
File f = new File(plan.getDataFolder(), "Errors.txt");
|
||||
@ -849,4 +860,13 @@ public class DatabaseTest {
|
||||
|
||||
assertEquals(worldTimes, allSessions.get(serverUUID).get(uuid).get(0).getWorldTimes());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRegisterProcessorRegisterException() throws SQLException {
|
||||
for (int i = 0; i < 200; i++) {
|
||||
new RegisterProcessor(uuid, 500L, 1000L, "name", 4).process();
|
||||
}
|
||||
assertTrue(db.getUsersTable().isRegistered(uuid));
|
||||
assertTrue(db.getUserInfoTable().isRegistered(uuid));
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user