diff --git a/Plan/src/main/java/com/djrapitops/plan/database/Database.java b/Plan/src/main/java/com/djrapitops/plan/database/Database.java index e04f6a6bc..3b061be68 100644 --- a/Plan/src/main/java/com/djrapitops/plan/database/Database.java +++ b/Plan/src/main/java/com/djrapitops/plan/database/Database.java @@ -343,6 +343,7 @@ public abstract class Database { public UserInfoTable getUserInfoTable() { return userInfoTable; } + public BasicDataSource getDataSource() { return dataSource; } diff --git a/Plan/src/main/java/com/djrapitops/plan/database/databases/SQLDB.java b/Plan/src/main/java/com/djrapitops/plan/database/databases/SQLDB.java index c0b54e550..373d545f3 100644 --- a/Plan/src/main/java/com/djrapitops/plan/database/databases/SQLDB.java +++ b/Plan/src/main/java/com/djrapitops/plan/database/databases/SQLDB.java @@ -233,12 +233,6 @@ public abstract class SQLDB extends Database { try { Benchmark.start("Remove Account"); Log.debug("Database", "Removing Account: " + uuid); - try { - setupDatabase(); - } catch (Exception e) { - Log.toLog(this.getClass().getName(), e); - return false; - } for (Table t : getAllTablesInRemoveOrder()) { if (!(t instanceof UserIDTable)) { diff --git a/Plan/src/main/java/com/djrapitops/plan/database/tables/ActionsTable.java b/Plan/src/main/java/com/djrapitops/plan/database/tables/ActionsTable.java index 6ea7cf752..7fee4f9dd 100644 --- a/Plan/src/main/java/com/djrapitops/plan/database/tables/ActionsTable.java +++ b/Plan/src/main/java/com/djrapitops/plan/database/tables/ActionsTable.java @@ -80,8 +80,9 @@ public class ActionsTable extends UserIDTable { statement.setLong(4, action.getDate()); statement.setString(5, action.getAdditionalInfo()); statement.execute(); + + commit(statement.getConnection()); } finally { - endTransaction(statement); close(statement); } } diff --git a/Plan/src/main/java/com/djrapitops/plan/database/tables/CommandUseTable.java b/Plan/src/main/java/com/djrapitops/plan/database/tables/CommandUseTable.java index 09776433a..5718482bc 100644 --- a/Plan/src/main/java/com/djrapitops/plan/database/tables/CommandUseTable.java +++ b/Plan/src/main/java/com/djrapitops/plan/database/tables/CommandUseTable.java @@ -157,8 +157,8 @@ public class CommandUseTable extends Table { } statement.executeBatch(); + commit(statement.getConnection()); } finally { - endTransaction(statement); close(statement); } } @@ -187,8 +187,8 @@ public class CommandUseTable extends Table { } statement.executeBatch(); + commit(statement.getConnection()); } finally { - endTransaction(statement); close(statement); } } diff --git a/Plan/src/main/java/com/djrapitops/plan/database/tables/IPsTable.java b/Plan/src/main/java/com/djrapitops/plan/database/tables/IPsTable.java index da53df8b6..9563b6b32 100644 --- a/Plan/src/main/java/com/djrapitops/plan/database/tables/IPsTable.java +++ b/Plan/src/main/java/com/djrapitops/plan/database/tables/IPsTable.java @@ -103,8 +103,9 @@ public class IPsTable extends UserIDTable { statement.setString(2, ip); statement.setString(3, geolocation); statement.execute(); + + commit(statement.getConnection()); } finally { - endTransaction(statement); close(statement); } } diff --git a/Plan/src/main/java/com/djrapitops/plan/database/tables/KillsTable.java b/Plan/src/main/java/com/djrapitops/plan/database/tables/KillsTable.java index 65346a1d8..b6443bda6 100644 --- a/Plan/src/main/java/com/djrapitops/plan/database/tables/KillsTable.java +++ b/Plan/src/main/java/com/djrapitops/plan/database/tables/KillsTable.java @@ -64,17 +64,14 @@ public class KillsTable extends UserIDTable { " OR " + columnVictimUserID + " = " + usersTable.statementSelectID); statement.setString(1, uuid.toString()); statement.setString(2, uuid.toString()); + statement.execute(); + commit(statement.getConnection()); return true; } catch (SQLException ex) { Log.toLog(this.getClass().getName(), ex); return false; } finally { - try { - endTransaction(statement); - } catch (SQLException e) { - Log.toLog(this.getClass().getName(), e); - } close(statement); } } @@ -106,9 +103,10 @@ public class KillsTable extends UserIDTable { statement.setString(5, weapon); statement.addBatch(); } + statement.executeBatch(); + commit(statement.getConnection()); } finally { - endTransaction(statement); close(statement); } } @@ -128,7 +126,10 @@ public class KillsTable extends UserIDTable { " JOIN " + usersTable + " on " + usersIDColumn + "=" + columnVictimUserID + " WHERE " + columnKillerUserID + "=" + usersTable.statementSelectID); statement.setString(1, uuid.toString()); + set = statement.executeQuery(); + commit(statement.getConnection()); + while (set.next()) { long sessionID = set.getLong(columnSessionID); Session session = sessions.get(sessionID); @@ -142,7 +143,6 @@ public class KillsTable extends UserIDTable { session.getPlayerKills().add(new KillData(victim, weapon, date)); } } finally { - endTransaction(statement); close(set, statement); } } diff --git a/Plan/src/main/java/com/djrapitops/plan/database/tables/NicknamesTable.java b/Plan/src/main/java/com/djrapitops/plan/database/tables/NicknamesTable.java index 6904d20f8..4118c3bb7 100644 --- a/Plan/src/main/java/com/djrapitops/plan/database/tables/NicknamesTable.java +++ b/Plan/src/main/java/com/djrapitops/plan/database/tables/NicknamesTable.java @@ -152,9 +152,10 @@ public class NicknamesTable extends UserIDTable { statement.setString(1, uuid.toString()); statement.setString(2, Plan.getServerUUID().toString()); statement.setString(3, displayName); + statement.execute(); + commit(statement.getConnection()); } finally { - endTransaction(statement); close(statement); } } diff --git a/Plan/src/main/java/com/djrapitops/plan/database/tables/SecurityTable.java b/Plan/src/main/java/com/djrapitops/plan/database/tables/SecurityTable.java index 301601d36..151659ab9 100644 --- a/Plan/src/main/java/com/djrapitops/plan/database/tables/SecurityTable.java +++ b/Plan/src/main/java/com/djrapitops/plan/database/tables/SecurityTable.java @@ -47,18 +47,14 @@ public class SecurityTable extends Table { try { statement = prepareStatement("DELETE FROM " + tableName + " WHERE (" + columnUser + "=?)"); statement.setString(1, user); + statement.execute(); + commit(statement.getConnection()); return true; } catch (SQLException ex) { Log.toLog(this.getClass().getName(), ex); return false; } finally { - try { - endTransaction(statement); - } catch (SQLException e) { - Log.toLog(this.getClass().getName(), e); - } - close(statement); } } diff --git a/Plan/src/main/java/com/djrapitops/plan/database/tables/ServerTable.java b/Plan/src/main/java/com/djrapitops/plan/database/tables/ServerTable.java index 284d49796..2e9b6d433 100644 --- a/Plan/src/main/java/com/djrapitops/plan/database/tables/ServerTable.java +++ b/Plan/src/main/java/com/djrapitops/plan/database/tables/ServerTable.java @@ -65,7 +65,6 @@ public class ServerTable extends Table { } else { updateServerInfo(info); } - } private void updateServerInfo(ServerInfo info) throws SQLException { @@ -85,8 +84,9 @@ public class ServerTable extends Table { statement.setBoolean(4, true); statement.setInt(5, info.getId()); statement.executeUpdate(); + + commit(statement.getConnection()); } finally { - endTransaction(statement); close(statement); } } @@ -116,8 +116,9 @@ public class ServerTable extends Table { statement.setString(3, webAddress); statement.setBoolean(4, true); statement.execute(); + + commit(statement.getConnection()); } finally { - endTransaction(statement); close(statement); } } diff --git a/Plan/src/main/java/com/djrapitops/plan/database/tables/SessionsTable.java b/Plan/src/main/java/com/djrapitops/plan/database/tables/SessionsTable.java index dba1b50d6..3c84f41fa 100644 --- a/Plan/src/main/java/com/djrapitops/plan/database/tables/SessionsTable.java +++ b/Plan/src/main/java/com/djrapitops/plan/database/tables/SessionsTable.java @@ -74,6 +74,7 @@ public class SessionsTable extends UserIDTable { if (sessionID == -1) { throw new IllegalStateException("Session was not Saved!"); } + db.getWorldTimesTable().saveWorldTimes(uuid, sessionID, session.getWorldTimes()); db.getKillsTable().savePlayerKills(uuid, sessionID, session.getPlayerKills()); } @@ -107,11 +108,11 @@ public class SessionsTable extends UserIDTable { statement.setLong(3, session.getSessionEnd()); statement.setInt(4, session.getDeaths()); statement.setInt(5, session.getMobKills()); - statement.setString(6, Plan.getServerUUID().toString()); + statement.execute(); + commit(statement.getConnection()); } finally { - endTransaction(statement); close(statement); } } diff --git a/Plan/src/main/java/com/djrapitops/plan/database/tables/TPSTable.java b/Plan/src/main/java/com/djrapitops/plan/database/tables/TPSTable.java index 44b3e4678..fa56b28ac 100644 --- a/Plan/src/main/java/com/djrapitops/plan/database/tables/TPSTable.java +++ b/Plan/src/main/java/com/djrapitops/plan/database/tables/TPSTable.java @@ -117,7 +117,9 @@ public class TPSTable extends Table { statement.setLong(6, tps.getUsedMemory()); statement.setDouble(7, tps.getEntityCount()); statement.setDouble(8, tps.getChunksLoaded()); + statement.execute(); + commit(statement.getConnection()); } finally { close(statement); } @@ -133,9 +135,10 @@ public class TPSTable extends Table { // More than 2 Months ago. long fiveWeeks = TimeAmount.MONTH.ms() * 2L; statement.setLong(1, MiscUtils.getTime() - fiveWeeks); + statement.execute(); + commit(statement.getConnection()); } finally { - endTransaction(statement); close(statement); } } diff --git a/Plan/src/main/java/com/djrapitops/plan/database/tables/UserIDTable.java b/Plan/src/main/java/com/djrapitops/plan/database/tables/UserIDTable.java index d8b25fb42..a496ccb6a 100644 --- a/Plan/src/main/java/com/djrapitops/plan/database/tables/UserIDTable.java +++ b/Plan/src/main/java/com/djrapitops/plan/database/tables/UserIDTable.java @@ -29,17 +29,14 @@ public abstract class UserIDTable extends Table { statement = prepareStatement("DELETE FROM " + tableName + " WHERE (" + columnUserID + "=" + usersTable.statementSelectID + ")"); statement.setString(1, uuid.toString()); + statement.execute(); + commit(statement.getConnection()); return true; } catch (SQLException ex) { Log.toLog(this.getClass().getName(), ex); return false; } finally { - try { - endTransaction(statement); - } catch (SQLException e) { - Log.toLog(this.getClass().getName(), e); - } close(statement); } } diff --git a/Plan/src/main/java/com/djrapitops/plan/database/tables/UserInfoTable.java b/Plan/src/main/java/com/djrapitops/plan/database/tables/UserInfoTable.java index 0c04fd723..e3f35ad39 100644 --- a/Plan/src/main/java/com/djrapitops/plan/database/tables/UserInfoTable.java +++ b/Plan/src/main/java/com/djrapitops/plan/database/tables/UserInfoTable.java @@ -70,7 +70,9 @@ public class UserInfoTable extends UserIDTable { statement.setString(1, uuid.toString()); statement.setLong(2, registered); statement.setString(3, Plan.getServerUUID().toString()); + statement.execute(); + commit(statement.getConnection()); } finally { close(statement); } @@ -100,7 +102,9 @@ public class UserInfoTable extends UserIDTable { statement.setBoolean(1, opped); statement.setBoolean(2, banned); statement.setString(3, uuid.toString()); + statement.execute(); + commit(statement.getConnection()); } finally { close(statement); } diff --git a/Plan/src/main/java/com/djrapitops/plan/database/tables/UsersTable.java b/Plan/src/main/java/com/djrapitops/plan/database/tables/UsersTable.java index bb3bfebcf..cafd2ce77 100644 --- a/Plan/src/main/java/com/djrapitops/plan/database/tables/UsersTable.java +++ b/Plan/src/main/java/com/djrapitops/plan/database/tables/UsersTable.java @@ -1,7 +1,6 @@ package main.java.com.djrapitops.plan.database.tables; import com.djrapitops.plugin.utilities.Verify; -import main.java.com.djrapitops.plan.Log; import main.java.com.djrapitops.plan.database.databases.SQLDB; import main.java.com.djrapitops.plan.database.sql.*; @@ -79,16 +78,13 @@ public class UsersTable extends UserIDTable { try { statement = prepareStatement("DELETE FROM " + tableName + " WHERE (" + columnUUID + "=?)"); statement.setString(1, uuid.toString()); + statement.execute(); + commit(statement.getConnection()); return true; } catch (SQLException ex) { return false; } finally { - try { - endTransaction(statement); - } catch (SQLException e) { - Log.toLog(this.getClass().getName(), e); - } close(statement); } } @@ -167,9 +163,10 @@ public class UsersTable extends UserIDTable { statement.setString(1, uuid.toString()); statement.setLong(2, registered); statement.setString(3, name); + statement.execute(); + commit(statement.getConnection()); } finally { - endTransaction(statement); close(statement); } } @@ -198,9 +195,10 @@ public class UsersTable extends UserIDTable { .toString()); statement.setString(1, name); statement.setString(2, uuid.toString()); + statement.execute(); + commit(statement.getConnection()); } finally { - endTransaction(statement); close(statement); } } @@ -231,9 +229,10 @@ public class UsersTable extends UserIDTable { + columnTimesKicked + "=" + columnTimesKicked + "+ 1" + " WHERE " + columnUUID + "=?"); statement.setString(1, uuid.toString()); + statement.execute(); + commit(statement.getConnection()); } finally { - endTransaction(statement); close(statement); } } diff --git a/Plan/src/main/java/com/djrapitops/plan/database/tables/VersionTable.java b/Plan/src/main/java/com/djrapitops/plan/database/tables/VersionTable.java index b52bd755a..78a9ab35e 100644 --- a/Plan/src/main/java/com/djrapitops/plan/database/tables/VersionTable.java +++ b/Plan/src/main/java/com/djrapitops/plan/database/tables/VersionTable.java @@ -64,6 +64,7 @@ public class VersionTable extends Table { PreparedStatement statement = null; try { statement = prepareStatement("INSERT INTO " + tableName + " (version) VALUES (" + version + ")"); + statement.executeUpdate(); commit(statement.getConnection()); } finally { diff --git a/Plan/src/main/java/com/djrapitops/plan/database/tables/WorldTable.java b/Plan/src/main/java/com/djrapitops/plan/database/tables/WorldTable.java index 4e922e7b3..12247dfd6 100644 --- a/Plan/src/main/java/com/djrapitops/plan/database/tables/WorldTable.java +++ b/Plan/src/main/java/com/djrapitops/plan/database/tables/WorldTable.java @@ -101,8 +101,8 @@ public class WorldTable extends Table { } statement.executeBatch(); + commit(statement.getConnection()); } finally { - endTransaction(statement); close(statement); } } diff --git a/Plan/src/main/java/com/djrapitops/plan/database/tables/WorldTimesTable.java b/Plan/src/main/java/com/djrapitops/plan/database/tables/WorldTimesTable.java index 6a174a20f..ccb1bc9d1 100644 --- a/Plan/src/main/java/com/djrapitops/plan/database/tables/WorldTimesTable.java +++ b/Plan/src/main/java/com/djrapitops/plan/database/tables/WorldTimesTable.java @@ -98,8 +98,8 @@ public class WorldTimesTable extends UserIDTable { } statement.executeBatch(); + commit(statement.getConnection()); } finally { - endTransaction(statement); close(statement); } } diff --git a/Plan/test/test/java/main/java/com/djrapitops/plan/database/DatabaseTest.java b/Plan/test/test/java/main/java/com/djrapitops/plan/database/DatabaseTest.java index 7e5dd24f0..123e0081d 100644 --- a/Plan/test/test/java/main/java/com/djrapitops/plan/database/DatabaseTest.java +++ b/Plan/test/test/java/main/java/com/djrapitops/plan/database/DatabaseTest.java @@ -58,14 +58,9 @@ public class DatabaseTest { public void setUp() throws Exception { TestInit t = TestInit.init(); plan = t.getPlanMock(); - db = new SQLiteDB(plan, "debug" + MiscUtils.getTime()) { - @Override - public void startConnectionPingTask() { - - } - }; + db = new SQLiteDB(plan, "debug" + MiscUtils.getTime()); db.init(); - db.getServerTable().saveCurrentServerInfo(new ServerInfo(-1, t.getServerUUID(), "ServerName", "")); + db.getServerTable().saveCurrentServerInfo(new ServerInfo(-1, TestInit.getServerUUID(), "ServerName", "")); File f = new File(plan.getDataFolder(), "Errors.txt"); rows = FileUtil.lines(f).size(); @@ -344,6 +339,7 @@ public class DatabaseTest { saveTwoWorlds(); saveUserOne(); saveUserTwo(); + Session session = new Session(12345L, "", ""); session.endSession(22345L); session.setWorldTimes(createWorldTimes()); @@ -501,8 +497,13 @@ public class DatabaseTest { assertTrue(usersTable.isRegistered(uuid)); + System.out.println("0 " + uuid); + System.out.println("1 " + db.getUsersTable().getSavedUUIDs()); + db.removeAccount(uuid); + System.out.println("2 " + db.getUsersTable().getSavedUUIDs()); + assertFalse(usersTable.isRegistered(uuid)); assertFalse(userInfoTable.isRegistered(uuid)); assertTrue(nicknamesTable.getNicknames(uuid).isEmpty()); diff --git a/Plan/test/test/java/utils/TestInit.java b/Plan/test/test/java/utils/TestInit.java index 8e9920e5f..94343ef3e 100644 --- a/Plan/test/test/java/utils/TestInit.java +++ b/Plan/test/test/java/utils/TestInit.java @@ -24,7 +24,6 @@ import org.powermock.api.mockito.PowerMockito; import java.io.File; import java.io.FileInputStream; import java.io.IOException; -import java.nio.file.Files; import java.util.UUID; import java.util.logging.Logger;