aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGravatar Ugnich Anton2014-06-17 18:37:26 +0700
committerGravatar Ugnich Anton2014-06-17 18:37:26 +0700
commit874187ffc4173296beb78e0603909ac4746c3211 (patch)
tree14b456034b4c7cfa619b2e3828aa68b1027aeade /src
parent6145ee50629a75284e790522c9840da7a1a93536 (diff)
getTags
Diffstat (limited to 'src')
-rw-r--r--src/com/juick/server/TagQueries.java63
1 files changed, 17 insertions, 46 deletions
diff --git a/src/com/juick/server/TagQueries.java b/src/com/juick/server/TagQueries.java
index 4f0639f9..b570c32a 100644
--- a/src/com/juick/server/TagQueries.java
+++ b/src/com/juick/server/TagQueries.java
@@ -29,10 +29,10 @@ import java.util.ArrayList;
* @author Ugnich Anton
*/
public class TagQueries {
-
+
public static com.juick.Tag getTag(Connection sql, String tag, boolean autoCreate) {
com.juick.Tag ret = null;
-
+
PreparedStatement stmt = null;
ResultSet rs = null;
try {
@@ -50,61 +50,32 @@ public class TagQueries {
} finally {
Utils.finishSQL(rs, stmt);
}
-
+
if (ret == null && autoCreate) {
ret = new com.juick.Tag();
ret.TID = createTag(sql, tag);
ret.Name = tag;
}
-
+
return ret;
}
-
+
public static ArrayList<com.juick.Tag> getTags(Connection sql, String[] tags, boolean autoCreate) {
ArrayList<com.juick.Tag> ret = new ArrayList<com.juick.Tag>();
-
- PreparedStatement stmt = null;
- ResultSet rs = null;
- try {
- stmt = sql.prepareStatement(Utils.buildQueryArray("SELECT tag_id,name FROM tags WHERE name IN (", tags.length, ")"));
- Utils.stmtSetStringArray(stmt, 1, tags);
- rs = stmt.executeQuery();
- rs.beforeFirst();
- while (rs.next()) {
- com.juick.Tag t = new com.juick.Tag();
- t.TID = rs.getInt(1);
- t.Name = rs.getString(2);
+
+ for (int i = 0; i < tags.length; i++) {
+ com.juick.Tag t = getTag(sql, tags[i], autoCreate);
+ if (t != null) {
ret.add(t);
}
- } catch (SQLException e) {
- System.err.println(e);
- } finally {
- Utils.finishSQL(rs, stmt);
- }
-
- if (tags.length != ret.size() && autoCreate) {
- for (int i = 0; i < tags.length; i++) {
- boolean found = false;
- for (int n = 0; n < ret.size(); n++) {
- if (tags[i].equalsIgnoreCase(ret.get(n).Name)) {
- found = true;
- break;
- }
- }
- if (!found) {
- com.juick.Tag t = new com.juick.Tag();
- t.TID = createTag(sql, tags[i]);
- t.Name = tags[i];
- }
- }
}
-
+
return ret;
}
-
+
public static int createTag(Connection sql, String name) {
int ret = 0;
-
+
PreparedStatement stmt = null;
ResultSet rs = null;
try {
@@ -120,13 +91,13 @@ public class TagQueries {
} finally {
Utils.finishSQL(rs, stmt);
}
-
+
return ret;
}
-
+
public static ArrayList<com.juick.Tag> getUserTagsAll(Connection sql, int uid) {
ArrayList<com.juick.Tag> tags = new ArrayList<com.juick.Tag>();
-
+
PreparedStatement stmt = null;
ResultSet rs = null;
try {
@@ -147,10 +118,10 @@ public class TagQueries {
}
return tags;
}
-
+
public static ArrayList<String> getUserBLTags(Connection sql, int uid) {
ArrayList<String> tags = new ArrayList<String>();
-
+
PreparedStatement stmt = null;
ResultSet rs = null;
try {