From bfbddd466a45182d522c38d460b0f0f26f89b89a Mon Sep 17 00:00:00 2001 From: Xephi Date: Wed, 30 Dec 2015 13:14:48 +0100 Subject: [PATCH] Revert "Change to QueryType" This reverts commit f7010f1d3b8ce719157a738483aa6f1eab867624. --- .../authme/datasource/queries/Query.java | 108 ++++++++++-------- .../authme/datasource/queries/QueryType.java | 9 -- 2 files changed, 63 insertions(+), 54 deletions(-) delete mode 100644 src/main/java/fr/xephi/authme/datasource/queries/QueryType.java 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 362604163..08511e00f 100644 --- a/src/main/java/fr/xephi/authme/datasource/queries/Query.java +++ b/src/main/java/fr/xephi/authme/datasource/queries/Query.java @@ -1,10 +1,15 @@ package fr.xephi.authme.datasource.queries; +import java.sql.Connection; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; import java.util.ArrayList; import java.util.HashMap; import java.util.Iterator; import java.util.List; +import fr.xephi.authme.ConsoleLogger; import fr.xephi.authme.datasource.DataSource; public class Query { @@ -16,7 +21,10 @@ public class Query { private List into = new ArrayList(); private List values = new ArrayList(); private List updateSet = new ArrayList(); - private QueryType type; + private boolean isSelect = false; + private boolean isDelete = false; + private boolean isUpdate = false; + private boolean isInsert = false; private String buildQuery = ""; /** @@ -36,7 +44,10 @@ public class Query { public Query select(String selector) { this.selector = selector; - type = QueryType.SELECT; + isSelect = true; + isDelete = false; + isUpdate = false; + isInsert = false; return this; } @@ -46,7 +57,10 @@ public class Query { */ public Query update() { - type = QueryType.UPDATE; + isSelect = false; + isDelete = false; + isUpdate = true; + isInsert = false; return this; } @@ -56,7 +70,10 @@ public class Query { */ public Query delete() { - type = QueryType.DELETE; + isSelect = false; + isDelete = true; + isUpdate = false; + isInsert = false; return this; } @@ -67,7 +84,10 @@ public class Query { */ public Query insert() { - type = QueryType.INSERT; + isSelect = false; + isDelete = false; + isUpdate = false; + isInsert = true; return this; } @@ -129,51 +149,49 @@ public class Query { public Query build(){ StringBuilder str = new StringBuilder(); - switch (type) { - case SELECT: + if (isSelect) + { + str.append("SELECT ").append(selector).append(" FROM ").append(from); + } + else if (isDelete) + { + str.append("DELETE FROM ").append(from); + } + else if (isUpdate) + { + str.append("UPDATE ").append(from).append(" SET "); + Iterator iter = updateSet.iterator(); + while (iter.hasNext()) { - str.append("SELECT ").append(selector).append(" FROM ").append(from); + String s = iter.next(); + str.append(s); + if (iter.hasNext()) + str.append(", "); } - case DELETE: + } + else if (isInsert) + { + str.append("INSERT INTO ").append(from).append(" ('"); + Iterator iter = into.iterator(); + while (iter.hasNext()) { - str.append("DELETE FROM ").append(from); + String s = iter.next(); + str.append(s); + if (iter.hasNext()) + str.append("', '"); + else + str.append("')"); } - case UPDATE: + str.append(" VALUES ('"); + iter = values.iterator(); + while (iter.hasNext()) { - str.append("UPDATE ").append(from).append(" SET "); - Iterator iter = updateSet.iterator(); - while (iter.hasNext()) - { - String s = iter.next(); - str.append(s); - if (iter.hasNext()) - str.append(", "); - } - } - case INSERT: - { - str.append("INSERT INTO ").append(from).append(" ('"); - Iterator iter = into.iterator(); - while (iter.hasNext()) - { - String s = iter.next(); - str.append(s); - if (iter.hasNext()) - str.append("', '"); - else - str.append("')"); - } - str.append(" VALUES ('"); - iter = values.iterator(); - while (iter.hasNext()) - { - String s = iter.next(); - str.append(s); - if (iter.hasNext()) - str.append("', '"); - else - str.append("')"); - } + String s = iter.next(); + str.append(s); + if (iter.hasNext()) + str.append("', '"); + else + str.append("')"); } } if (!where.isEmpty()) diff --git a/src/main/java/fr/xephi/authme/datasource/queries/QueryType.java b/src/main/java/fr/xephi/authme/datasource/queries/QueryType.java deleted file mode 100644 index 1f1575edb..000000000 --- a/src/main/java/fr/xephi/authme/datasource/queries/QueryType.java +++ /dev/null @@ -1,9 +0,0 @@ -package fr.xephi.authme.datasource.queries; - -public enum QueryType { - - DELETE, - INSERT, - SELECT, - UPDATE; -}