diff --git a/src/main/java/fr/xephi/authme/datasource/MySQL.java b/src/main/java/fr/xephi/authme/datasource/MySQL.java index a2c503f8f..881747c2c 100644 --- a/src/main/java/fr/xephi/authme/datasource/MySQL.java +++ b/src/main/java/fr/xephi/authme/datasource/MySQL.java @@ -256,7 +256,7 @@ public class MySQL implements DataSource { @Override public synchronized boolean isAuthAvailable(String user) { try (Connection con = getConnection()) { - PreparedStatement pst = con.prepareStatement(new Query() + PreparedStatement pst = con.prepareStatement(new Query(this) .select(columnName) .from(tableName) .addWhere(columnName + "=?", null) @@ -283,7 +283,7 @@ public class MySQL implements DataSource { public synchronized PlayerAuth getAuth(String user) { PlayerAuth pAuth; try (Connection con = getConnection()) { - PreparedStatement pst = con.prepareStatement(new Query() + PreparedStatement pst = con.prepareStatement(new Query(this) .select("*") .from(tableName) .addWhere(columnName + "=?", null) @@ -314,7 +314,7 @@ public class MySQL implements DataSource { rs.close(); pst.close(); if (Settings.getPasswordHash == HashAlgorithm.XENFORO) { - pst = con.prepareStatement(new Query() + pst = con.prepareStatement(new Query(this) .select("data") .from("xf_user_authenticate") .addWhere(columnID + "=?", null) @@ -611,7 +611,7 @@ public class MySQL implements DataSource { @Override public synchronized boolean updateSession(PlayerAuth auth) { try(Connection con = getConnection()) { - PreparedStatement pst = con.prepareStatement(new Query() + PreparedStatement pst = con.prepareStatement(new Query(this) .update() .from(tableName) .addUpdateSet(columnIp + "=?") @@ -646,7 +646,7 @@ public class MySQL implements DataSource { public synchronized int purgeDatabase(long until) { int result = 0; try(Connection con = getConnection()) { - PreparedStatement pst = con.prepareStatement(new Query() + PreparedStatement pst = con.prepareStatement(new Query(this) .delete() .from(tableName) .addWhere(columnLastLogin + " autoPurgeDatabase(long until) { List list = new ArrayList<>(); try(Connection con = getConnection()) { - PreparedStatement st = con.prepareStatement(new Query() + PreparedStatement st = con.prepareStatement(new Query(this) .select(columnName) .from(tableName) .addWhere(columnLastLogin + "<" + until, null) @@ -686,7 +686,7 @@ public class MySQL implements DataSource { } rs.close(); st.close(); - st = con.prepareStatement(new Query() + st = con.prepareStatement(new Query(this) .delete() .from(tableName) .addWhere(columnLastLogin + "<" + until, null) @@ -754,7 +754,7 @@ public class MySQL implements DataSource { @Override public synchronized boolean updateQuitLoc(PlayerAuth auth) { try(Connection con = getConnection()) { - PreparedStatement pst = con.prepareStatement(new Query() + PreparedStatement pst = con.prepareStatement(new Query(this) .update() .from(tableName) .addUpdateSet(lastlocX + "=?") @@ -792,7 +792,7 @@ public class MySQL implements DataSource { public synchronized int getIps(String ip) { int countIp = 0; try (Connection con = getConnection()) { - PreparedStatement pst = con.prepareStatement(new Query() + PreparedStatement pst = con.prepareStatement(new Query(this) .select("COUNT(*)") .from(tableName) .addWhere(columnIp + "=?", null) @@ -824,7 +824,7 @@ public class MySQL implements DataSource { @Override public synchronized boolean updateEmail(PlayerAuth auth) { try (Connection con = getConnection()) { - PreparedStatement pst = con.prepareStatement(new Query() + PreparedStatement pst = con.prepareStatement(new Query(this) .update() .from(tableName) .addUpdateSet(columnEmail + "=?") @@ -858,7 +858,7 @@ public class MySQL implements DataSource { return false; } try (Connection con = getConnection()) { - PreparedStatement pst = con.prepareStatement(new Query() + PreparedStatement pst = con.prepareStatement(new Query(this) .update() .from(tableName) .addUpdateSet(columnSalt + "=?") @@ -919,7 +919,7 @@ public class MySQL implements DataSource { public synchronized List getAllAuthsByName(PlayerAuth auth) { List result = new ArrayList<>(); try (Connection con = getConnection()) { - PreparedStatement pst = getConnection().prepareStatement(new Query() + PreparedStatement pst = getConnection().prepareStatement(new Query(this) .select(columnName) .from(tableName) .addWhere(columnIp + "=?", null) @@ -951,7 +951,7 @@ public class MySQL implements DataSource { public synchronized List getAllAuthsByIp(String ip) { List result = new ArrayList<>(); try { - PreparedStatement pst = getConnection().prepareStatement(new Query() + PreparedStatement pst = getConnection().prepareStatement(new Query(this) .select(columnName) .from(tableName) .addWhere(columnIp + "=?", null) @@ -983,7 +983,7 @@ public class MySQL implements DataSource { public synchronized List getAllAuthsByEmail(String email){ List countEmail = new ArrayList<>(); try { - PreparedStatement pst = getConnection().prepareStatement(new Query() + PreparedStatement pst = getConnection().prepareStatement(new Query(this) .select(columnName) .from(tableName) .addWhere(columnEmail + "=?", null) @@ -1012,7 +1012,7 @@ public class MySQL implements DataSource { @Override public synchronized void purgeBanned(List banned) { try (Connection con = getConnection()) { - PreparedStatement pst = con.prepareStatement(new Query() + PreparedStatement pst = con.prepareStatement(new Query(this) .delete() .from(tableName) .addWhere(columnName + "=?", null) @@ -1050,7 +1050,7 @@ public class MySQL implements DataSource { public boolean isLogged(String user) { boolean isLogged = false; try { - PreparedStatement pst = getConnection().prepareStatement(new Query() + PreparedStatement pst = getConnection().prepareStatement(new Query(this) .select(columnLogged) .from(tableName) .addWhere(columnName + "=?", null) @@ -1076,7 +1076,7 @@ public class MySQL implements DataSource { @Override public void setLogged(String user) { try { - PreparedStatement pst = getConnection().prepareStatement(new Query() + PreparedStatement pst = getConnection().prepareStatement(new Query(this) .update() .from(tableName) .addUpdateSet(columnLogged + "='1'") @@ -1101,7 +1101,7 @@ public class MySQL implements DataSource { @Override public void setUnlogged(String user) { try { - PreparedStatement pst = getConnection().prepareStatement(new Query() + PreparedStatement pst = getConnection().prepareStatement(new Query(this) .update() .from(tableName) .addUpdateSet(columnLogged + "='0'") @@ -1124,7 +1124,7 @@ public class MySQL implements DataSource { @Override public void purgeLogged() { try (Connection con = getConnection()) { - PreparedStatement pst = con.prepareStatement(new Query() + PreparedStatement pst = con.prepareStatement(new Query(this) .update() .from(tableName) .addUpdateSet(columnLogged + "=" + 0) @@ -1150,7 +1150,7 @@ public class MySQL implements DataSource { public int getAccountsRegistered() { int result = 0; try (Connection con = getConnection()) { - PreparedStatement st = con.prepareStatement(new Query() + PreparedStatement st = con.prepareStatement(new Query(this) .select("COUNT(*)") .from(tableName) .build() @@ -1180,7 +1180,7 @@ public class MySQL implements DataSource { public void updateName(String oldOne, String newOne) { try (Connection con = getConnection()) { PreparedStatement pst = - con.prepareStatement(new Query() + con.prepareStatement(new Query(this) .update() .from(tableName) .addUpdateSet(columnName + "=?") @@ -1208,14 +1208,14 @@ public class MySQL implements DataSource { public List getAllAuths() { List auths = new ArrayList<>(); try (Connection con = getConnection()) { - PreparedStatement st = con.prepareStatement(new Query() + PreparedStatement st = con.prepareStatement(new Query(this) .select("*") .from(tableName) .build() .getQuery()); ResultSet rs = st .executeQuery(); - PreparedStatement pst = con.prepareStatement(new Query() + PreparedStatement pst = con.prepareStatement(new Query(this) .select("data") .from("xf_user_authenticate") .addWhere(columnID + "=?", null) diff --git a/src/main/java/fr/xephi/authme/datasource/SQLite.java b/src/main/java/fr/xephi/authme/datasource/SQLite.java index a58a71b65..e541baf5a 100644 --- a/src/main/java/fr/xephi/authme/datasource/SQLite.java +++ b/src/main/java/fr/xephi/authme/datasource/SQLite.java @@ -164,7 +164,7 @@ public class SQLite implements DataSource { PreparedStatement pst = null; ResultSet rs = null; try { - pst = getConnection().prepareStatement(new Query() + pst = getConnection().prepareStatement(new Query(this) .select("*") .from(tableName) .addWhere("LOWER(" + columnName + ")=LOWER(?)", null) @@ -194,7 +194,7 @@ public class SQLite implements DataSource { PreparedStatement pst = null; ResultSet rs = null; try { - pst = getConnection().prepareStatement(new Query() + pst = getConnection().prepareStatement(new Query(this) .select("*") .from(tableName) .addWhere("LOWER(" + columnName + ")=LOWER(?)", null) @@ -272,7 +272,7 @@ public class SQLite implements DataSource { @Override public synchronized boolean updatePassword(PlayerAuth auth) { try { - PreparedStatement pst = getConnection().prepareStatement(new Query() + PreparedStatement pst = getConnection().prepareStatement(new Query(this) .update() .from(tableName) .addUpdateSet(columnPassword + "=?") @@ -302,7 +302,7 @@ public class SQLite implements DataSource { @Override public synchronized boolean updateSession(PlayerAuth auth) { try { - PreparedStatement pst = getConnection().prepareStatement(new Query() + PreparedStatement pst = getConnection().prepareStatement(new Query(this) .update() .from(tableName) .addUpdateSet(columnIp + "=?") @@ -336,7 +336,7 @@ public class SQLite implements DataSource { public synchronized int purgeDatabase(long until) { int result = 0; try { - PreparedStatement pst = getConnection().prepareStatement(new Query() + PreparedStatement pst = getConnection().prepareStatement(new Query(this) .delete() .from(tableName) .addWhere(columnLastLogin + " autoPurgeDatabase(long until) { List list = new ArrayList<>(); try { - PreparedStatement st = getConnection().prepareStatement(new Query() + PreparedStatement st = getConnection().prepareStatement(new Query(this) .select(columnName) .from(tableName) .addWhere(columnLastLogin + "<" + until, null) @@ -375,7 +375,7 @@ public class SQLite implements DataSource { list.add(rs.getString(columnName)); } rs.close(); - st = getConnection().prepareStatement(new Query() + st = getConnection().prepareStatement(new Query(this) .delete() .from(tableName) .addWhere(columnLastLogin + "<" + until, null) @@ -424,7 +424,7 @@ public class SQLite implements DataSource { @Override public synchronized boolean updateQuitLoc(PlayerAuth auth) { try { - PreparedStatement pst = getConnection().prepareStatement(new Query() + PreparedStatement pst = getConnection().prepareStatement(new Query(this) .update() .from(tableName) .addUpdateSet(lastlocX + "=?") @@ -461,7 +461,7 @@ public class SQLite implements DataSource { public synchronized int getIps(String ip) { int countIp = 0; try { - PreparedStatement pst = getConnection().prepareStatement(new Query() + PreparedStatement pst = getConnection().prepareStatement(new Query(this) .select("COUNT(*)") .from(tableName) .addWhere(columnIp + "=?", null) @@ -492,7 +492,7 @@ public class SQLite implements DataSource { @Override public synchronized boolean updateEmail(PlayerAuth auth) { try { - PreparedStatement pst = getConnection().prepareStatement(new Query() + PreparedStatement pst = getConnection().prepareStatement(new Query(this) .update() .from(tableName) .addUpdateSet(columnEmail + "=?") @@ -525,7 +525,7 @@ public class SQLite implements DataSource { return false; } try { - PreparedStatement pst = getConnection().prepareStatement(new Query() + PreparedStatement pst = getConnection().prepareStatement(new Query(this) .update() .from(tableName) .addUpdateSet(columnSalt + "=?") @@ -609,7 +609,7 @@ public class SQLite implements DataSource { public synchronized List getAllAuthsByName(PlayerAuth auth) { List result = new ArrayList<>(); try (Connection con = getConnection()) { - PreparedStatement pst = getConnection().prepareStatement(new Query() + PreparedStatement pst = getConnection().prepareStatement(new Query(this) .select(columnName) .from(tableName) .addWhere(columnIp + "=?", null) @@ -641,7 +641,7 @@ public class SQLite implements DataSource { public synchronized List getAllAuthsByIp(String ip) { List result = new ArrayList<>(); try { - PreparedStatement pst = getConnection().prepareStatement(new Query() + PreparedStatement pst = getConnection().prepareStatement(new Query(this) .select(columnName) .from(tableName) .addWhere(columnIp + "=?", null) @@ -673,7 +673,7 @@ public class SQLite implements DataSource { public synchronized List getAllAuthsByEmail(String email){ List countEmail = new ArrayList<>(); try { - PreparedStatement pst = getConnection().prepareStatement(new Query() + PreparedStatement pst = getConnection().prepareStatement(new Query(this) .select(columnName) .from(tableName) .addWhere(columnEmail + "=?", null) @@ -702,7 +702,7 @@ public class SQLite implements DataSource { @Override public synchronized void purgeBanned(List banned) { try { - PreparedStatement pst = getConnection().prepareStatement(new Query() + PreparedStatement pst = getConnection().prepareStatement(new Query(this) .delete() .from(tableName) .addWhere(columnName + "=?", null) @@ -739,7 +739,7 @@ public class SQLite implements DataSource { public boolean isLogged(String user) { boolean isLogged = false; try { - PreparedStatement pst = getConnection().prepareStatement(new Query() + PreparedStatement pst = getConnection().prepareStatement(new Query(this) .select(columnLogged) .from(tableName) .addWhere(columnName + "=?", null) @@ -765,7 +765,7 @@ public class SQLite implements DataSource { @Override public void setLogged(String user) { try { - PreparedStatement pst = getConnection().prepareStatement(new Query() + PreparedStatement pst = getConnection().prepareStatement(new Query(this) .update() .from(tableName) .addUpdateSet(columnLogged + "='1'") @@ -790,7 +790,7 @@ public class SQLite implements DataSource { @Override public void setUnlogged(String user) { try { - PreparedStatement pst = getConnection().prepareStatement(new Query() + PreparedStatement pst = getConnection().prepareStatement(new Query(this) .update() .from(tableName) .addUpdateSet(columnLogged + "='0'") @@ -813,7 +813,7 @@ public class SQLite implements DataSource { @Override public void purgeLogged() { try { - PreparedStatement pst = getConnection().prepareStatement(new Query() + PreparedStatement pst = getConnection().prepareStatement(new Query(this) .update() .from(tableName) .addUpdateSet(columnLogged + "='0'") @@ -838,7 +838,7 @@ public class SQLite implements DataSource { public int getAccountsRegistered() { int result = 0; try { - PreparedStatement st = getConnection().prepareStatement(new Query() + PreparedStatement st = getConnection().prepareStatement(new Query(this) .select("COUNT(*)") .from(tableName) .build() @@ -867,7 +867,7 @@ public class SQLite implements DataSource { public void updateName(String oldOne, String newOne) { try (Connection con = getConnection()) { PreparedStatement pst = - con.prepareStatement(new Query() + con.prepareStatement(new Query(this) .update() .from(tableName) .addUpdateSet(columnName + "=?") @@ -894,7 +894,7 @@ public class SQLite implements DataSource { public List getAllAuths() { List auths = new ArrayList<>(); try { - PreparedStatement st = getConnection().prepareStatement(new Query() + PreparedStatement st = getConnection().prepareStatement(new Query(this) .select("*") .from(tableName) .build() diff --git a/src/main/java/fr/xephi/authme/datasource/queries/Query.java b/src/main/java/fr/xephi/authme/datasource/queries/Query.java index a7db9fd80..362604163 100644 --- a/src/main/java/fr/xephi/authme/datasource/queries/Query.java +++ b/src/main/java/fr/xephi/authme/datasource/queries/Query.java @@ -9,6 +9,7 @@ import fr.xephi.authme.datasource.DataSource; public class Query { + private DataSource source; private String selector = null; private String from = null; private HashMap where = new HashMap(); @@ -22,8 +23,9 @@ public class Query { * * @param source */ - public Query() + public Query(DataSource source) { + this.source = source; } /**