Remove source from constructor

This commit is contained in:
Xephi 2015-12-30 12:05:24 +01:00
parent 14e130eaee
commit dbacf7754d
3 changed files with 46 additions and 48 deletions

View File

@ -256,7 +256,7 @@ public class MySQL implements DataSource {
@Override @Override
public synchronized boolean isAuthAvailable(String user) { public synchronized boolean isAuthAvailable(String user) {
try (Connection con = getConnection()) { try (Connection con = getConnection()) {
PreparedStatement pst = con.prepareStatement(new Query(this) PreparedStatement pst = con.prepareStatement(new Query()
.select(columnName) .select(columnName)
.from(tableName) .from(tableName)
.addWhere(columnName + "=?", null) .addWhere(columnName + "=?", null)
@ -283,7 +283,7 @@ public class MySQL implements DataSource {
public synchronized PlayerAuth getAuth(String user) { public synchronized PlayerAuth getAuth(String user) {
PlayerAuth pAuth; PlayerAuth pAuth;
try (Connection con = getConnection()) { try (Connection con = getConnection()) {
PreparedStatement pst = con.prepareStatement(new Query(this) PreparedStatement pst = con.prepareStatement(new Query()
.select("*") .select("*")
.from(tableName) .from(tableName)
.addWhere(columnName + "=?", null) .addWhere(columnName + "=?", null)
@ -314,7 +314,7 @@ public class MySQL implements DataSource {
rs.close(); rs.close();
pst.close(); pst.close();
if (Settings.getPasswordHash == HashAlgorithm.XENFORO) { if (Settings.getPasswordHash == HashAlgorithm.XENFORO) {
pst = con.prepareStatement(new Query(this) pst = con.prepareStatement(new Query()
.select("data") .select("data")
.from("xf_user_authenticate") .from("xf_user_authenticate")
.addWhere(columnID + "=?", null) .addWhere(columnID + "=?", null)
@ -611,7 +611,7 @@ public class MySQL implements DataSource {
@Override @Override
public synchronized boolean updateSession(PlayerAuth auth) { public synchronized boolean updateSession(PlayerAuth auth) {
try(Connection con = getConnection()) { try(Connection con = getConnection()) {
PreparedStatement pst = con.prepareStatement(new Query(this) PreparedStatement pst = con.prepareStatement(new Query()
.update() .update()
.from(tableName) .from(tableName)
.addUpdateSet(columnIp + "=?") .addUpdateSet(columnIp + "=?")
@ -646,7 +646,7 @@ public class MySQL implements DataSource {
public synchronized int purgeDatabase(long until) { public synchronized int purgeDatabase(long until) {
int result = 0; int result = 0;
try(Connection con = getConnection()) { try(Connection con = getConnection()) {
PreparedStatement pst = con.prepareStatement(new Query(this) PreparedStatement pst = con.prepareStatement(new Query()
.delete() .delete()
.from(tableName) .from(tableName)
.addWhere(columnLastLogin + "<?", null) .addWhere(columnLastLogin + "<?", null)
@ -674,7 +674,7 @@ public class MySQL implements DataSource {
public synchronized List<String> autoPurgeDatabase(long until) { public synchronized List<String> autoPurgeDatabase(long until) {
List<String> list = new ArrayList<>(); List<String> list = new ArrayList<>();
try(Connection con = getConnection()) { try(Connection con = getConnection()) {
PreparedStatement st = con.prepareStatement(new Query(this) PreparedStatement st = con.prepareStatement(new Query()
.select(columnName) .select(columnName)
.from(tableName) .from(tableName)
.addWhere(columnLastLogin + "<" + until, null) .addWhere(columnLastLogin + "<" + until, null)
@ -686,7 +686,7 @@ public class MySQL implements DataSource {
} }
rs.close(); rs.close();
st.close(); st.close();
st = con.prepareStatement(new Query(this) st = con.prepareStatement(new Query()
.delete() .delete()
.from(tableName) .from(tableName)
.addWhere(columnLastLogin + "<" + until, null) .addWhere(columnLastLogin + "<" + until, null)
@ -754,7 +754,7 @@ public class MySQL implements DataSource {
@Override @Override
public synchronized boolean updateQuitLoc(PlayerAuth auth) { public synchronized boolean updateQuitLoc(PlayerAuth auth) {
try(Connection con = getConnection()) { try(Connection con = getConnection()) {
PreparedStatement pst = con.prepareStatement(new Query(this) PreparedStatement pst = con.prepareStatement(new Query()
.update() .update()
.from(tableName) .from(tableName)
.addUpdateSet(lastlocX + "=?") .addUpdateSet(lastlocX + "=?")
@ -792,7 +792,7 @@ public class MySQL implements DataSource {
public synchronized int getIps(String ip) { public synchronized int getIps(String ip) {
int countIp = 0; int countIp = 0;
try (Connection con = getConnection()) { try (Connection con = getConnection()) {
PreparedStatement pst = con.prepareStatement(new Query(this) PreparedStatement pst = con.prepareStatement(new Query()
.select("COUNT(*)") .select("COUNT(*)")
.from(tableName) .from(tableName)
.addWhere(columnIp + "=?", null) .addWhere(columnIp + "=?", null)
@ -824,7 +824,7 @@ public class MySQL implements DataSource {
@Override @Override
public synchronized boolean updateEmail(PlayerAuth auth) { public synchronized boolean updateEmail(PlayerAuth auth) {
try (Connection con = getConnection()) { try (Connection con = getConnection()) {
PreparedStatement pst = con.prepareStatement(new Query(this) PreparedStatement pst = con.prepareStatement(new Query()
.update() .update()
.from(tableName) .from(tableName)
.addUpdateSet(columnEmail + "=?") .addUpdateSet(columnEmail + "=?")
@ -858,7 +858,7 @@ public class MySQL implements DataSource {
return false; return false;
} }
try (Connection con = getConnection()) { try (Connection con = getConnection()) {
PreparedStatement pst = con.prepareStatement(new Query(this) PreparedStatement pst = con.prepareStatement(new Query()
.update() .update()
.from(tableName) .from(tableName)
.addUpdateSet(columnSalt + "=?") .addUpdateSet(columnSalt + "=?")
@ -919,7 +919,7 @@ public class MySQL implements DataSource {
public synchronized List<String> getAllAuthsByName(PlayerAuth auth) { public synchronized List<String> getAllAuthsByName(PlayerAuth auth) {
List<String> result = new ArrayList<>(); List<String> result = new ArrayList<>();
try (Connection con = getConnection()) { try (Connection con = getConnection()) {
PreparedStatement pst = getConnection().prepareStatement(new Query(this) PreparedStatement pst = getConnection().prepareStatement(new Query()
.select(columnName) .select(columnName)
.from(tableName) .from(tableName)
.addWhere(columnIp + "=?", null) .addWhere(columnIp + "=?", null)
@ -951,7 +951,7 @@ public class MySQL implements DataSource {
public synchronized List<String> getAllAuthsByIp(String ip) { public synchronized List<String> getAllAuthsByIp(String ip) {
List<String> result = new ArrayList<>(); List<String> result = new ArrayList<>();
try { try {
PreparedStatement pst = getConnection().prepareStatement(new Query(this) PreparedStatement pst = getConnection().prepareStatement(new Query()
.select(columnName) .select(columnName)
.from(tableName) .from(tableName)
.addWhere(columnIp + "=?", null) .addWhere(columnIp + "=?", null)
@ -983,7 +983,7 @@ public class MySQL implements DataSource {
public synchronized List<String> getAllAuthsByEmail(String email){ public synchronized List<String> getAllAuthsByEmail(String email){
List<String> countEmail = new ArrayList<>(); List<String> countEmail = new ArrayList<>();
try { try {
PreparedStatement pst = getConnection().prepareStatement(new Query(this) PreparedStatement pst = getConnection().prepareStatement(new Query()
.select(columnName) .select(columnName)
.from(tableName) .from(tableName)
.addWhere(columnEmail + "=?", null) .addWhere(columnEmail + "=?", null)
@ -1012,7 +1012,7 @@ public class MySQL implements DataSource {
@Override @Override
public synchronized void purgeBanned(List<String> banned) { public synchronized void purgeBanned(List<String> banned) {
try (Connection con = getConnection()) { try (Connection con = getConnection()) {
PreparedStatement pst = con.prepareStatement(new Query(this) PreparedStatement pst = con.prepareStatement(new Query()
.delete() .delete()
.from(tableName) .from(tableName)
.addWhere(columnName + "=?", null) .addWhere(columnName + "=?", null)
@ -1050,7 +1050,7 @@ public class MySQL implements DataSource {
public boolean isLogged(String user) { public boolean isLogged(String user) {
boolean isLogged = false; boolean isLogged = false;
try { try {
PreparedStatement pst = getConnection().prepareStatement(new Query(this) PreparedStatement pst = getConnection().prepareStatement(new Query()
.select(columnLogged) .select(columnLogged)
.from(tableName) .from(tableName)
.addWhere(columnName + "=?", null) .addWhere(columnName + "=?", null)
@ -1076,7 +1076,7 @@ public class MySQL implements DataSource {
@Override @Override
public void setLogged(String user) { public void setLogged(String user) {
try { try {
PreparedStatement pst = getConnection().prepareStatement(new Query(this) PreparedStatement pst = getConnection().prepareStatement(new Query()
.update() .update()
.from(tableName) .from(tableName)
.addUpdateSet(columnLogged + "='1'") .addUpdateSet(columnLogged + "='1'")
@ -1101,7 +1101,7 @@ public class MySQL implements DataSource {
@Override @Override
public void setUnlogged(String user) { public void setUnlogged(String user) {
try { try {
PreparedStatement pst = getConnection().prepareStatement(new Query(this) PreparedStatement pst = getConnection().prepareStatement(new Query()
.update() .update()
.from(tableName) .from(tableName)
.addUpdateSet(columnLogged + "='0'") .addUpdateSet(columnLogged + "='0'")
@ -1124,7 +1124,7 @@ public class MySQL implements DataSource {
@Override @Override
public void purgeLogged() { public void purgeLogged() {
try (Connection con = getConnection()) { try (Connection con = getConnection()) {
PreparedStatement pst = con.prepareStatement(new Query(this) PreparedStatement pst = con.prepareStatement(new Query()
.update() .update()
.from(tableName) .from(tableName)
.addUpdateSet(columnLogged + "=" + 0) .addUpdateSet(columnLogged + "=" + 0)
@ -1150,7 +1150,7 @@ public class MySQL implements DataSource {
public int getAccountsRegistered() { public int getAccountsRegistered() {
int result = 0; int result = 0;
try (Connection con = getConnection()) { try (Connection con = getConnection()) {
PreparedStatement st = con.prepareStatement(new Query(this) PreparedStatement st = con.prepareStatement(new Query()
.select("COUNT(*)") .select("COUNT(*)")
.from(tableName) .from(tableName)
.build() .build()
@ -1180,7 +1180,7 @@ public class MySQL implements DataSource {
public void updateName(String oldOne, String newOne) { public void updateName(String oldOne, String newOne) {
try (Connection con = getConnection()) { try (Connection con = getConnection()) {
PreparedStatement pst = PreparedStatement pst =
con.prepareStatement(new Query(this) con.prepareStatement(new Query()
.update() .update()
.from(tableName) .from(tableName)
.addUpdateSet(columnName + "=?") .addUpdateSet(columnName + "=?")
@ -1208,14 +1208,14 @@ public class MySQL implements DataSource {
public List<PlayerAuth> getAllAuths() { public List<PlayerAuth> getAllAuths() {
List<PlayerAuth> auths = new ArrayList<>(); List<PlayerAuth> auths = new ArrayList<>();
try (Connection con = getConnection()) { try (Connection con = getConnection()) {
PreparedStatement st = con.prepareStatement(new Query(this) PreparedStatement st = con.prepareStatement(new Query()
.select("*") .select("*")
.from(tableName) .from(tableName)
.build() .build()
.getQuery()); .getQuery());
ResultSet rs = st ResultSet rs = st
.executeQuery(); .executeQuery();
PreparedStatement pst = con.prepareStatement(new Query(this) PreparedStatement pst = con.prepareStatement(new Query()
.select("data") .select("data")
.from("xf_user_authenticate") .from("xf_user_authenticate")
.addWhere(columnID + "=?", null) .addWhere(columnID + "=?", null)

View File

@ -164,7 +164,7 @@ public class SQLite implements DataSource {
PreparedStatement pst = null; PreparedStatement pst = null;
ResultSet rs = null; ResultSet rs = null;
try { try {
pst = getConnection().prepareStatement(new Query(this) pst = getConnection().prepareStatement(new Query()
.select("*") .select("*")
.from(tableName) .from(tableName)
.addWhere("LOWER(" + columnName + ")=LOWER(?)", null) .addWhere("LOWER(" + columnName + ")=LOWER(?)", null)
@ -194,7 +194,7 @@ public class SQLite implements DataSource {
PreparedStatement pst = null; PreparedStatement pst = null;
ResultSet rs = null; ResultSet rs = null;
try { try {
pst = getConnection().prepareStatement(new Query(this) pst = getConnection().prepareStatement(new Query()
.select("*") .select("*")
.from(tableName) .from(tableName)
.addWhere("LOWER(" + columnName + ")=LOWER(?)", null) .addWhere("LOWER(" + columnName + ")=LOWER(?)", null)
@ -272,7 +272,7 @@ public class SQLite implements DataSource {
@Override @Override
public synchronized boolean updatePassword(PlayerAuth auth) { public synchronized boolean updatePassword(PlayerAuth auth) {
try { try {
PreparedStatement pst = getConnection().prepareStatement(new Query(this) PreparedStatement pst = getConnection().prepareStatement(new Query()
.update() .update()
.from(tableName) .from(tableName)
.addUpdateSet(columnPassword + "=?") .addUpdateSet(columnPassword + "=?")
@ -302,7 +302,7 @@ public class SQLite implements DataSource {
@Override @Override
public synchronized boolean updateSession(PlayerAuth auth) { public synchronized boolean updateSession(PlayerAuth auth) {
try { try {
PreparedStatement pst = getConnection().prepareStatement(new Query(this) PreparedStatement pst = getConnection().prepareStatement(new Query()
.update() .update()
.from(tableName) .from(tableName)
.addUpdateSet(columnIp + "=?") .addUpdateSet(columnIp + "=?")
@ -336,7 +336,7 @@ public class SQLite implements DataSource {
public synchronized int purgeDatabase(long until) { public synchronized int purgeDatabase(long until) {
int result = 0; int result = 0;
try { try {
PreparedStatement pst = getConnection().prepareStatement(new Query(this) PreparedStatement pst = getConnection().prepareStatement(new Query()
.delete() .delete()
.from(tableName) .from(tableName)
.addWhere(columnLastLogin + "<?", null) .addWhere(columnLastLogin + "<?", null)
@ -364,7 +364,7 @@ public class SQLite implements DataSource {
public synchronized List<String> autoPurgeDatabase(long until) { public synchronized List<String> autoPurgeDatabase(long until) {
List<String> list = new ArrayList<>(); List<String> list = new ArrayList<>();
try { try {
PreparedStatement st = getConnection().prepareStatement(new Query(this) PreparedStatement st = getConnection().prepareStatement(new Query()
.select(columnName) .select(columnName)
.from(tableName) .from(tableName)
.addWhere(columnLastLogin + "<" + until, null) .addWhere(columnLastLogin + "<" + until, null)
@ -375,7 +375,7 @@ public class SQLite implements DataSource {
list.add(rs.getString(columnName)); list.add(rs.getString(columnName));
} }
rs.close(); rs.close();
st = getConnection().prepareStatement(new Query(this) st = getConnection().prepareStatement(new Query()
.delete() .delete()
.from(tableName) .from(tableName)
.addWhere(columnLastLogin + "<" + until, null) .addWhere(columnLastLogin + "<" + until, null)
@ -424,7 +424,7 @@ public class SQLite implements DataSource {
@Override @Override
public synchronized boolean updateQuitLoc(PlayerAuth auth) { public synchronized boolean updateQuitLoc(PlayerAuth auth) {
try { try {
PreparedStatement pst = getConnection().prepareStatement(new Query(this) PreparedStatement pst = getConnection().prepareStatement(new Query()
.update() .update()
.from(tableName) .from(tableName)
.addUpdateSet(lastlocX + "=?") .addUpdateSet(lastlocX + "=?")
@ -461,7 +461,7 @@ public class SQLite implements DataSource {
public synchronized int getIps(String ip) { public synchronized int getIps(String ip) {
int countIp = 0; int countIp = 0;
try { try {
PreparedStatement pst = getConnection().prepareStatement(new Query(this) PreparedStatement pst = getConnection().prepareStatement(new Query()
.select("COUNT(*)") .select("COUNT(*)")
.from(tableName) .from(tableName)
.addWhere(columnIp + "=?", null) .addWhere(columnIp + "=?", null)
@ -492,7 +492,7 @@ public class SQLite implements DataSource {
@Override @Override
public synchronized boolean updateEmail(PlayerAuth auth) { public synchronized boolean updateEmail(PlayerAuth auth) {
try { try {
PreparedStatement pst = getConnection().prepareStatement(new Query(this) PreparedStatement pst = getConnection().prepareStatement(new Query()
.update() .update()
.from(tableName) .from(tableName)
.addUpdateSet(columnEmail + "=?") .addUpdateSet(columnEmail + "=?")
@ -525,7 +525,7 @@ public class SQLite implements DataSource {
return false; return false;
} }
try { try {
PreparedStatement pst = getConnection().prepareStatement(new Query(this) PreparedStatement pst = getConnection().prepareStatement(new Query()
.update() .update()
.from(tableName) .from(tableName)
.addUpdateSet(columnSalt + "=?") .addUpdateSet(columnSalt + "=?")
@ -609,7 +609,7 @@ public class SQLite implements DataSource {
public synchronized List<String> getAllAuthsByName(PlayerAuth auth) { public synchronized List<String> getAllAuthsByName(PlayerAuth auth) {
List<String> result = new ArrayList<>(); List<String> result = new ArrayList<>();
try (Connection con = getConnection()) { try (Connection con = getConnection()) {
PreparedStatement pst = getConnection().prepareStatement(new Query(this) PreparedStatement pst = getConnection().prepareStatement(new Query()
.select(columnName) .select(columnName)
.from(tableName) .from(tableName)
.addWhere(columnIp + "=?", null) .addWhere(columnIp + "=?", null)
@ -641,7 +641,7 @@ public class SQLite implements DataSource {
public synchronized List<String> getAllAuthsByIp(String ip) { public synchronized List<String> getAllAuthsByIp(String ip) {
List<String> result = new ArrayList<>(); List<String> result = new ArrayList<>();
try { try {
PreparedStatement pst = getConnection().prepareStatement(new Query(this) PreparedStatement pst = getConnection().prepareStatement(new Query()
.select(columnName) .select(columnName)
.from(tableName) .from(tableName)
.addWhere(columnIp + "=?", null) .addWhere(columnIp + "=?", null)
@ -673,7 +673,7 @@ public class SQLite implements DataSource {
public synchronized List<String> getAllAuthsByEmail(String email){ public synchronized List<String> getAllAuthsByEmail(String email){
List<String> countEmail = new ArrayList<>(); List<String> countEmail = new ArrayList<>();
try { try {
PreparedStatement pst = getConnection().prepareStatement(new Query(this) PreparedStatement pst = getConnection().prepareStatement(new Query()
.select(columnName) .select(columnName)
.from(tableName) .from(tableName)
.addWhere(columnEmail + "=?", null) .addWhere(columnEmail + "=?", null)
@ -702,7 +702,7 @@ public class SQLite implements DataSource {
@Override @Override
public synchronized void purgeBanned(List<String> banned) { public synchronized void purgeBanned(List<String> banned) {
try { try {
PreparedStatement pst = getConnection().prepareStatement(new Query(this) PreparedStatement pst = getConnection().prepareStatement(new Query()
.delete() .delete()
.from(tableName) .from(tableName)
.addWhere(columnName + "=?", null) .addWhere(columnName + "=?", null)
@ -739,7 +739,7 @@ public class SQLite implements DataSource {
public boolean isLogged(String user) { public boolean isLogged(String user) {
boolean isLogged = false; boolean isLogged = false;
try { try {
PreparedStatement pst = getConnection().prepareStatement(new Query(this) PreparedStatement pst = getConnection().prepareStatement(new Query()
.select(columnLogged) .select(columnLogged)
.from(tableName) .from(tableName)
.addWhere(columnName + "=?", null) .addWhere(columnName + "=?", null)
@ -765,7 +765,7 @@ public class SQLite implements DataSource {
@Override @Override
public void setLogged(String user) { public void setLogged(String user) {
try { try {
PreparedStatement pst = getConnection().prepareStatement(new Query(this) PreparedStatement pst = getConnection().prepareStatement(new Query()
.update() .update()
.from(tableName) .from(tableName)
.addUpdateSet(columnLogged + "='1'") .addUpdateSet(columnLogged + "='1'")
@ -790,7 +790,7 @@ public class SQLite implements DataSource {
@Override @Override
public void setUnlogged(String user) { public void setUnlogged(String user) {
try { try {
PreparedStatement pst = getConnection().prepareStatement(new Query(this) PreparedStatement pst = getConnection().prepareStatement(new Query()
.update() .update()
.from(tableName) .from(tableName)
.addUpdateSet(columnLogged + "='0'") .addUpdateSet(columnLogged + "='0'")
@ -813,7 +813,7 @@ public class SQLite implements DataSource {
@Override @Override
public void purgeLogged() { public void purgeLogged() {
try { try {
PreparedStatement pst = getConnection().prepareStatement(new Query(this) PreparedStatement pst = getConnection().prepareStatement(new Query()
.update() .update()
.from(tableName) .from(tableName)
.addUpdateSet(columnLogged + "='0'") .addUpdateSet(columnLogged + "='0'")
@ -838,7 +838,7 @@ public class SQLite implements DataSource {
public int getAccountsRegistered() { public int getAccountsRegistered() {
int result = 0; int result = 0;
try { try {
PreparedStatement st = getConnection().prepareStatement(new Query(this) PreparedStatement st = getConnection().prepareStatement(new Query()
.select("COUNT(*)") .select("COUNT(*)")
.from(tableName) .from(tableName)
.build() .build()
@ -867,7 +867,7 @@ public class SQLite implements DataSource {
public void updateName(String oldOne, String newOne) { public void updateName(String oldOne, String newOne) {
try (Connection con = getConnection()) { try (Connection con = getConnection()) {
PreparedStatement pst = PreparedStatement pst =
con.prepareStatement(new Query(this) con.prepareStatement(new Query()
.update() .update()
.from(tableName) .from(tableName)
.addUpdateSet(columnName + "=?") .addUpdateSet(columnName + "=?")
@ -894,7 +894,7 @@ public class SQLite implements DataSource {
public List<PlayerAuth> getAllAuths() { public List<PlayerAuth> getAllAuths() {
List<PlayerAuth> auths = new ArrayList<>(); List<PlayerAuth> auths = new ArrayList<>();
try { try {
PreparedStatement st = getConnection().prepareStatement(new Query(this) PreparedStatement st = getConnection().prepareStatement(new Query()
.select("*") .select("*")
.from(tableName) .from(tableName)
.build() .build()

View File

@ -9,7 +9,6 @@ import fr.xephi.authme.datasource.DataSource;
public class Query { public class Query {
private DataSource source;
private String selector = null; private String selector = null;
private String from = null; private String from = null;
private HashMap<String, String> where = new HashMap<String, String>(); private HashMap<String, String> where = new HashMap<String, String>();
@ -23,9 +22,8 @@ public class Query {
* *
* @param source * @param source
*/ */
public Query(DataSource source) public Query()
{ {
this.source = source;
} }
/** /**