From 874187ffc4173296beb78e0603909ac4746c3211 Mon Sep 17 00:00:00 2001 From: Ugnich Anton Date: Tue, 17 Jun 2014 18:37:26 +0700 Subject: getTags --- src/com/juick/server/TagQueries.java | 63 ++++++++++-------------------------- 1 file 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 getTags(Connection sql, String[] tags, boolean autoCreate) { ArrayList ret = new ArrayList(); - - 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 getUserTagsAll(Connection sql, int uid) { ArrayList tags = new ArrayList(); - + PreparedStatement stmt = null; ResultSet rs = null; try { @@ -147,10 +118,10 @@ public class TagQueries { } return tags; } - + public static ArrayList getUserBLTags(Connection sql, int uid) { ArrayList tags = new ArrayList(); - + PreparedStatement stmt = null; ResultSet rs = null; try { -- cgit v1.2.3