From c37ed56f884661666b964e47efd23a36be9b24d4 Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Sun, 10 Jan 2016 16:56:51 +0300 Subject: logger, diamond and arraylist refactoring --- src/main/java/com/juick/server/AdsQueries.java | 6 +- .../java/com/juick/server/CrosspostQueries.java | 8 +- .../java/com/juick/server/MessagesQueries.java | 173 +++++++++++---------- src/main/java/com/juick/server/PMQueries.java | 54 ++++--- src/main/java/com/juick/server/PushQueries.java | 20 ++- src/main/java/com/juick/server/SQLHelpers.java | 25 +-- .../com/juick/server/SubscriptionsQueries.java | 39 +++-- src/main/java/com/juick/server/TagQueries.java | 37 +++-- src/main/java/com/juick/server/UserQueries.java | 79 +++++----- src/main/java/com/juick/server/Utils.java | 6 +- 10 files changed, 244 insertions(+), 203 deletions(-) (limited to 'src') diff --git a/src/main/java/com/juick/server/AdsQueries.java b/src/main/java/com/juick/server/AdsQueries.java index 0fb4c0a6..ad9b7149 100644 --- a/src/main/java/com/juick/server/AdsQueries.java +++ b/src/main/java/com/juick/server/AdsQueries.java @@ -20,6 +20,8 @@ package com.juick.server; import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.SQLException; +import java.util.logging.Level; +import java.util.logging.Logger; /** * @@ -27,6 +29,8 @@ import java.sql.SQLException; */ public class AdsQueries { + private static final Logger logger = Logger.getLogger(AdsQueries.class.getName()); + public static int getAdMID(Connection sql, int uid) { if (uid > 0) { return SQLHelpers.getInt(sql, "SELECT message_id FROM ads_messages WHERE message_id NOT IN (SELECT message_id FROM ads_messages_log WHERE user_id=? AND ts>UNIX_TIMESTAMP()-60*60*24 GROUP BY message_id HAVING COUNT(*)>2) ORDER BY RAND() LIMIT 1", uid, 0); @@ -43,7 +47,7 @@ public class AdsQueries { stmt.setInt(2, mid); stmt.executeUpdate(); } catch (SQLException e) { - System.err.println(e); + logger.log(Level.SEVERE, "sql exception", e); } finally { Utils.finishSQL(null, stmt); } diff --git a/src/main/java/com/juick/server/CrosspostQueries.java b/src/main/java/com/juick/server/CrosspostQueries.java index fd677048..b44b6b59 100644 --- a/src/main/java/com/juick/server/CrosspostQueries.java +++ b/src/main/java/com/juick/server/CrosspostQueries.java @@ -21,6 +21,8 @@ import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; +import java.util.logging.Level; +import java.util.logging.Logger; /** * @@ -28,6 +30,8 @@ import java.sql.SQLException; */ public class CrosspostQueries { + private static final Logger logger = Logger.getLogger(CrosspostQueries.class.getName()); + public static String[] getTwitterTokens(Connection sql, int uid) { String tokens[] = null; @@ -43,7 +47,7 @@ public class CrosspostQueries { tokens[1] = rs.getString(2); } } catch (SQLException e) { - System.err.println(e); + logger.log(Level.SEVERE, "sql exception", e); } finally { Utils.finishSQL(rs, stmt); } @@ -70,7 +74,7 @@ public class CrosspostQueries { tokens[1] = rs.getString(2); } } catch (SQLException e) { - System.err.println(e); + logger.log(Level.SEVERE, "sql exception", e); } finally { Utils.finishSQL(rs, stmt); } diff --git a/src/main/java/com/juick/server/MessagesQueries.java b/src/main/java/com/juick/server/MessagesQueries.java index 82fef672..4d5683bd 100644 --- a/src/main/java/com/juick/server/MessagesQueries.java +++ b/src/main/java/com/juick/server/MessagesQueries.java @@ -25,6 +25,9 @@ import java.sql.Statement; import java.sql.Types; import java.util.ArrayList; import java.util.Collections; +import java.util.List; +import java.util.logging.Level; +import java.util.logging.Logger; /** * @@ -32,11 +35,13 @@ import java.util.Collections; */ public class MessagesQueries { - public static int createMessage(Connection sql, int uid, String txt, String attachment, ArrayList tags) { + private static final Logger logger = Logger.getLogger(MessagesQueries.class.getName()); + + public static int createMessage(Connection sql, int uid, String txt, String attachment, List tags) { int mid = 0; PreparedStatement stmt = null; - ResultSet rs = null; + ResultSet rs; try { stmt = sql.prepareStatement("INSERT INTO messages(user_id,attach) VALUES (?,?)", Statement.RETURN_GENERATED_KEYS); stmt.setInt(1, uid); @@ -51,7 +56,7 @@ public class MessagesQueries { mid = rs.getInt(1); } } catch (SQLException e) { - System.err.println(e); + logger.log(Level.SEVERE, "sql exception", e); } finally { Utils.finishSQL(null, stmt); } @@ -73,7 +78,7 @@ public class MessagesQueries { stmt = sql.prepareStatement("INSERT INTO messages_tags(message_id,tag_id) VALUES " + tagsIDs); stmt.executeUpdate(); } catch (SQLException e) { - System.err.println(e); + logger.log(Level.SEVERE, "sql exception", e); } finally { Utils.finishSQL(null, stmt); } @@ -81,7 +86,7 @@ public class MessagesQueries { try { stmt = sql.prepareStatement("INSERT INTO messages_txt(message_id,tags,txt) VALUES (?,?,?)"); stmt.setInt(1, mid); - if (tagsNames == "") { + if (tagsNames.isEmpty()) { stmt.setNull(2, Types.VARCHAR); } else { stmt.setString(2, tagsNames); @@ -89,7 +94,7 @@ public class MessagesQueries { stmt.setString(3, txt); stmt.executeUpdate(); } catch (SQLException e) { - System.err.println(e); + logger.log(Level.SEVERE, "sql exception", e); } finally { Utils.finishSQL(null, stmt); } @@ -118,7 +123,7 @@ public class MessagesQueries { ridnew = 0; } } catch (SQLException e) { - System.err.println(e); + logger.log(Level.SEVERE, "sql exception", e); } finally { Utils.finishSQL(null, stmt); } @@ -166,7 +171,7 @@ public class MessagesQueries { privacy = rs.getInt(2); } } catch (SQLException e) { - System.err.println(e); + logger.log(Level.SEVERE, "sql exception", e); } finally { Utils.finishSQL(rs, stmt); } @@ -189,7 +194,7 @@ public class MessagesQueries { ret = rs.getInt(1) == 1; } } catch (SQLException e) { - System.err.println(e); + logger.log(Level.SEVERE, "sql exception", e); } finally { Utils.finishSQL(rs, stmt); } @@ -210,7 +215,7 @@ public class MessagesQueries { ret = rs.getInt(1) == 1; } } catch (SQLException e) { - System.err.println(e); + logger.log(Level.SEVERE, "sql exception", e); } finally { Utils.finishSQL(rs, stmt); } @@ -255,7 +260,7 @@ public class MessagesQueries { msg.Hidden = rs.getBoolean(13); } } catch (SQLException e) { - System.err.println(e); + logger.log(Level.SEVERE, "sql exception", e); } finally { Utils.finishSQL(rs, stmt); } @@ -276,7 +281,7 @@ public class MessagesQueries { msg.Text = rs.getString(3); } } catch (SQLException e) { - System.err.println(e); + logger.log(Level.SEVERE, "sql exception", e); } finally { Utils.finishSQL(rs, stmt); } @@ -307,7 +312,7 @@ public class MessagesQueries { msg.Text = rs.getString(6); } } catch (SQLException e) { - System.err.println(e); + logger.log(Level.SEVERE, "sql exception", e); } finally { Utils.finishSQL(rs, stmt); } @@ -330,15 +335,15 @@ public class MessagesQueries { user.UName = rs.getString(2); } } catch (SQLException e) { - System.err.println(e); + logger.log(Level.SEVERE, "sql exception", e); } finally { Utils.finishSQL(rs, stmt); } return user; } - public static ArrayList getMessageTags(Connection sql, int mid) { - ArrayList tags = new ArrayList(); + public static List getMessageTags(Connection sql, int mid) { + List tags = new ArrayList<>(); PreparedStatement stmt = null; ResultSet rs = null; @@ -356,7 +361,7 @@ public class MessagesQueries { tags.add(t); } } catch (SQLException e) { - System.err.println(e); + logger.log(Level.SEVERE, "sql exception", e); } finally { Utils.finishSQL(rs, stmt); } @@ -364,8 +369,8 @@ public class MessagesQueries { return tags; } - public static ArrayList getMessageTagsIDs(Connection sql, int mid) { - ArrayList tids = new ArrayList(); + public static List getMessageTagsIDs(Connection sql, int mid) { + List tids = new ArrayList<>(); PreparedStatement stmt = null; ResultSet rs = null; @@ -378,7 +383,7 @@ public class MessagesQueries { tids.add(rs.getInt(1)); } } catch (SQLException e) { - System.err.println(e); + logger.log(Level.SEVERE, "sql exception", e); } finally { Utils.finishSQL(rs, stmt); } @@ -387,7 +392,7 @@ public class MessagesQueries { } public static ArrayList getMessageRecommendations(Connection sql, int mid) { - ArrayList users = new ArrayList(); + ArrayList users = new ArrayList<>(); PreparedStatement stmt = null; ResultSet rs = null; @@ -400,7 +405,7 @@ public class MessagesQueries { users.add(rs.getString(1)); } } catch (SQLException e) { - System.err.println(e); + logger.log(Level.SEVERE, "sql exception", e); } finally { Utils.finishSQL(rs, stmt); } @@ -408,8 +413,8 @@ public class MessagesQueries { return users; } - public static ArrayList getAll(Connection sql, int visitor_uid, int before) { - ArrayList mids = new ArrayList(20); + public static List getAll(Connection sql, int visitor_uid, int before) { + List mids = new ArrayList<>(20); PreparedStatement stmt = null; ResultSet rs = null; @@ -448,15 +453,15 @@ public class MessagesQueries { mids.add(rs.getInt(1)); } } catch (SQLException e) { - System.err.println(e); + logger.log(Level.SEVERE, "sql exception", e); } finally { Utils.finishSQL(rs, stmt); } return mids; } - public static ArrayList getTag(Connection sql, int tid, int visitor_uid, int before, int cnt) { - ArrayList mids = new ArrayList(20); + public static List getTag(Connection sql, int tid, int visitor_uid, int before, int cnt) { + List mids = new ArrayList<>(20); PreparedStatement stmt = null; ResultSet rs = null; @@ -483,15 +488,15 @@ public class MessagesQueries { mids.add(rs.getInt(1)); } } catch (SQLException e) { - System.err.println(e); + logger.log(Level.SEVERE, "sql exception", e); } finally { Utils.finishSQL(rs, stmt); } return mids; } - public static ArrayList getTags(Connection sql, String tids, int visitor_uid, int before, int cnt) { - ArrayList mids = new ArrayList(20); + public static List getTags(Connection sql, String tids, int visitor_uid, int before, int cnt) { + List mids = new ArrayList<>(20); PreparedStatement stmt = null; ResultSet rs = null; @@ -512,15 +517,15 @@ public class MessagesQueries { mids.add(rs.getInt(1)); } } catch (SQLException e) { - System.err.println(e); + logger.log(Level.SEVERE, "sql exception", e); } finally { Utils.finishSQL(rs, stmt); } return mids; } - public static ArrayList getPlace(Connection sql, int place_id, int visitor_uid, int before) { - ArrayList mids = new ArrayList(20); + public static List getPlace(Connection sql, int place_id, int visitor_uid, int before) { + List mids = new ArrayList<>(20); PreparedStatement stmt = null; ResultSet rs = null; @@ -541,15 +546,15 @@ public class MessagesQueries { mids.add(rs.getInt(1)); } } catch (SQLException e) { - System.err.println(e); + logger.log(Level.SEVERE, "sql exception", e); } finally { Utils.finishSQL(rs, stmt); } return mids; } - public static ArrayList getMyFeed(Connection sql, int uid, int before) { - ArrayList mids = new ArrayList(40); + public static List getMyFeed(Connection sql, int uid, int before) { + List mids = new ArrayList<>(40); PreparedStatement stmt = null; ResultSet rs = null; try { @@ -569,7 +574,7 @@ public class MessagesQueries { mids.add(rs.getInt(1)); } } catch (SQLException e) { - System.err.println(e); + logger.log(Level.SEVERE, "sql exception", e); } finally { Utils.finishSQL(rs, stmt); } @@ -589,7 +594,7 @@ public class MessagesQueries { mids.add(rs.getInt(1)); } } catch (SQLException e) { - System.err.println(e); + logger.log(Level.SEVERE, "sql exception", e); } finally { Utils.finishSQL(rs, stmt); } @@ -603,8 +608,8 @@ public class MessagesQueries { return mids; } - public static ArrayList getPrivate(Connection sql, int uid, int before) { - ArrayList mids = new ArrayList(20); + public static List getPrivate(Connection sql, int uid, int before) { + List mids = new ArrayList<>(20); PreparedStatement stmt = null; ResultSet rs = null; @@ -623,15 +628,15 @@ public class MessagesQueries { mids.add(rs.getInt(1)); } } catch (SQLException e) { - System.err.println(e); + logger.log(Level.SEVERE, "sql exception", e); } finally { Utils.finishSQL(rs, stmt); } return mids; } - public static ArrayList getDiscussions(Connection sql, int uid, int before) { - ArrayList mids = new ArrayList(20); + public static List getDiscussions(Connection sql, int uid, int before) { + List mids = new ArrayList<>(20); PreparedStatement stmt = null; ResultSet rs = null; @@ -650,7 +655,7 @@ public class MessagesQueries { mids.add(rs.getInt(1)); } } catch (SQLException e) { - System.err.println(e); + logger.log(Level.SEVERE, "sql exception", e); } finally { Utils.finishSQL(rs, stmt); } @@ -658,8 +663,8 @@ public class MessagesQueries { return mids; } - public static ArrayList getRecommended(Connection sql, int uid, int before) { - ArrayList mids = new ArrayList(20); + public static List getRecommended(Connection sql, int uid, int before) { + List mids = new ArrayList<>(20); PreparedStatement stmt = null; ResultSet rs = null; @@ -678,7 +683,7 @@ public class MessagesQueries { mids.add(rs.getInt(1)); } } catch (SQLException e) { - System.err.println(e); + logger.log(Level.SEVERE, "sql exception", e); } finally { Utils.finishSQL(rs, stmt); } @@ -687,8 +692,8 @@ public class MessagesQueries { return mids; } - public static ArrayList getPopular(Connection sql, int before) { - ArrayList mids = new ArrayList(20); + public static List getPopular(Connection sql, int before) { + List mids = new ArrayList<>(20); PreparedStatement stmt = null; ResultSet rs = null; @@ -705,15 +710,15 @@ public class MessagesQueries { mids.add(rs.getInt(1)); } } catch (SQLException e) { - System.err.println(e); + logger.log(Level.SEVERE, "sql exception", e); } finally { Utils.finishSQL(rs, stmt); } return mids; } - public static ArrayList getPhotos(Connection sql, int visitor_uid, int before) { - ArrayList mids = new ArrayList(20); + public static List getPhotos(Connection sql, int visitor_uid, int before) { + List mids = new ArrayList<>(20); PreparedStatement stmt = null; ResultSet rs = null; @@ -732,15 +737,15 @@ public class MessagesQueries { mids.add(rs.getInt(1)); } } catch (SQLException e) { - System.err.println(e); + logger.log(Level.SEVERE, "sql exception", e); } finally { Utils.finishSQL(rs, stmt); } return mids; } - public static ArrayList getSearch(Connection sql, Connection sqlSearch, String search, int before) { - ArrayList mids0 = new ArrayList(20); + public static List getSearch(Connection sql, Connection sqlSearch, String search, int before) { + List mids0 = new ArrayList<>(20); PreparedStatement stmt = null; ResultSet rs = null; @@ -760,12 +765,12 @@ public class MessagesQueries { mids0.add(rs.getInt(1)); } } catch (SQLException e) { - System.err.println(e); + logger.log(Level.SEVERE, "sql exception", e); } finally { Utils.finishSQL(rs, stmt); } - ArrayList mids = new ArrayList(20); + List mids = new ArrayList<>(20); if (mids0.size() > 0) { try { stmt = sql.prepareStatement("SELECT message_id FROM messages WHERE message_id IN (" + Utils.convertArrayInt2String(mids0) + ") AND privacy>0 ORDER BY message_id DESC LIMIT 20"); @@ -775,7 +780,7 @@ public class MessagesQueries { mids.add(rs.getInt(1)); } } catch (SQLException e) { - System.err.println(e); + logger.log(Level.SEVERE, "sql exception", e); } finally { Utils.finishSQL(rs, stmt); } @@ -784,8 +789,8 @@ public class MessagesQueries { return mids; } - public static ArrayList getUserBlog(Connection sql, int UID, int privacy, int before) { - ArrayList mids = new ArrayList(20); + public static List getUserBlog(Connection sql, int UID, int privacy, int before) { + List mids = new ArrayList<>(20); PreparedStatement stmt = null; ResultSet rs = null; @@ -804,15 +809,15 @@ public class MessagesQueries { mids.add(rs.getInt(1)); } } catch (SQLException e) { - System.err.println(e); + logger.log(Level.SEVERE, "sql exception", e); } finally { Utils.finishSQL(rs, stmt); } return mids; } - public static ArrayList getUserTag(Connection sql, int UID, int TID, int privacy, int before) { - ArrayList mids = new ArrayList(20); + public static List getUserTag(Connection sql, int UID, int TID, int privacy, int before) { + List mids = new ArrayList<>(20); PreparedStatement stmt = null; ResultSet rs = null; @@ -833,15 +838,15 @@ public class MessagesQueries { mids.add(rs.getInt(1)); } } catch (SQLException e) { - System.err.println(e); + logger.log(Level.SEVERE, "sql exception", e); } finally { Utils.finishSQL(rs, stmt); } return mids; } - public static ArrayList getUserRecommendations(Connection sql, int UID, int before) { - ArrayList mids = new ArrayList(20); + public static List getUserRecommendations(Connection sql, int UID, int before) { + List mids = new ArrayList<>(20); PreparedStatement stmt = null; ResultSet rs = null; @@ -860,15 +865,15 @@ public class MessagesQueries { mids.add(rs.getInt(1)); } } catch (SQLException e) { - System.err.println(e); + logger.log(Level.SEVERE, "sql exception", e); } finally { Utils.finishSQL(rs, stmt); } return mids; } - public static ArrayList getUserPhotos(Connection sql, int UID, int privacy, int before) { - ArrayList mids = new ArrayList(20); + public static List getUserPhotos(Connection sql, int UID, int privacy, int before) { + List mids = new ArrayList<>(20); PreparedStatement stmt = null; ResultSet rs = null; @@ -887,15 +892,15 @@ public class MessagesQueries { mids.add(rs.getInt(1)); } } catch (SQLException e) { - System.err.println(e); + logger.log(Level.SEVERE, "sql exception", e); } finally { Utils.finishSQL(rs, stmt); } return mids; } - public static ArrayList getUserSearch(Connection sql, Connection sqlSearch, int UID, String search, int privacy, int before) { - ArrayList mids0 = new ArrayList(20); + public static List getUserSearch(Connection sql, Connection sqlSearch, int UID, String search, int privacy, int before) { + List mids0 = new ArrayList<>(20); PreparedStatement stmt = null; ResultSet rs = null; @@ -916,12 +921,12 @@ public class MessagesQueries { mids0.add(rs.getInt(1)); } } catch (SQLException e) { - System.err.println(e); + logger.log(Level.SEVERE, "sql exception", e); } finally { Utils.finishSQL(rs, stmt); } - ArrayList mids = new ArrayList(20); + List mids = new ArrayList<>(20); if (mids0.size() > 0) { try { stmt = sql.prepareStatement("SELECT message_id FROM messages WHERE message_id IN (" + Utils.convertArrayInt2String(mids0) + ") AND privacy>=" + privacy + " ORDER BY message_id DESC"); @@ -931,7 +936,7 @@ public class MessagesQueries { mids.add(rs.getInt(1)); } } catch (SQLException e) { - System.err.println(e); + logger.log(Level.SEVERE, "sql exception", e); } finally { Utils.finishSQL(rs, stmt); } @@ -940,8 +945,8 @@ public class MessagesQueries { return mids; } - public static ArrayList getMessages(Connection sql, ArrayList mids) { - ArrayList msgs = new ArrayList(20); + public static List getMessages(Connection sql, List mids) { + List msgs = new ArrayList<>(20); PreparedStatement stmt = null; ResultSet rs = null; @@ -978,7 +983,7 @@ public class MessagesQueries { msgs.add(msg); } } catch (SQLException e) { - System.err.println(e); + logger.log(Level.SEVERE, "sql exception", e); } finally { Utils.finishSQL(rs, stmt); } @@ -986,8 +991,8 @@ public class MessagesQueries { return msgs; } - public static ArrayList getReplies(Connection sql, int mid) { - ArrayList replies = new ArrayList(); + public static List getReplies(Connection sql, int mid) { + List replies = new ArrayList<>(); PreparedStatement stmt = null; ResultSet rs = null; @@ -1013,7 +1018,7 @@ public class MessagesQueries { replies.add(msg); } } catch (SQLException e) { - System.err.println(e); + logger.log(Level.SEVERE, "sql exception", e); } finally { Utils.finishSQL(rs, stmt); } @@ -1039,7 +1044,7 @@ public class MessagesQueries { } ret = stmt.executeUpdate() > 0; } catch (SQLException e) { - System.err.println(e); + logger.log(Level.SEVERE, "sql exception", e); } finally { Utils.finishSQL(null, stmt); } @@ -1050,7 +1055,7 @@ public class MessagesQueries { stmt.setInt(1, mid); stmt.executeUpdate(); } catch (SQLException e) { - System.err.println(e); + logger.log(Level.SEVERE, "sql exception", e); } finally { Utils.finishSQL(null, stmt); } @@ -1068,7 +1073,7 @@ public class MessagesQueries { stmt.setInt(1, mid); ret = stmt.executeUpdate() > 0; } catch (SQLException e) { - System.err.println(e); + logger.log(Level.SEVERE, "sql exception", e); } finally { Utils.finishSQL(null, stmt); } diff --git a/src/main/java/com/juick/server/PMQueries.java b/src/main/java/com/juick/server/PMQueries.java index 56b91abf..c4b4fa2d 100644 --- a/src/main/java/com/juick/server/PMQueries.java +++ b/src/main/java/com/juick/server/PMQueries.java @@ -17,11 +17,16 @@ */ package com.juick.server; +import com.juick.User; + import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; import java.util.ArrayList; +import java.util.List; +import java.util.logging.Level; +import java.util.logging.Logger; /** * @@ -29,6 +34,8 @@ import java.util.ArrayList; */ public class PMQueries { + private static final Logger logger = Logger.getLogger(PMQueries.class.getName()); + public static boolean createPM(Connection sql, int uid_from, int uid_to, String body) { boolean ret = false; PreparedStatement stmt = null; @@ -39,7 +46,7 @@ public class PMQueries { stmt.setString(3, body); ret = stmt.executeUpdate() > 0; } catch (SQLException e) { - System.err.println(e); + logger.log(Level.SEVERE, "sql exception", e); } finally { Utils.finishSQL(null, stmt); } @@ -52,7 +59,7 @@ public class PMQueries { stmt2.setInt(2, uid_to); stmt2.executeUpdate(); } catch (SQLException e) { - System.err.println(e); + logger.log(Level.SEVERE, "sql exception", e); } finally { Utils.finishSQL(null, stmt2); } @@ -70,7 +77,7 @@ public class PMQueries { stmt.setString(2, jid); ret = stmt.executeUpdate() > 0; } catch (SQLException e) { - System.err.println(e); + logger.log(Level.SEVERE, "sql exception", e); } finally { Utils.finishSQL(null, stmt); } @@ -86,7 +93,7 @@ public class PMQueries { stmt.setString(2, jid); ret = stmt.executeUpdate() > 0; } catch (SQLException e) { - System.err.println(e); + logger.log(Level.SEVERE, "sql exception", e); } finally { Utils.finishSQL(null, stmt); } @@ -107,7 +114,7 @@ public class PMQueries { ret = true; } } catch (SQLException e) { - System.err.println(e); + logger.log(Level.SEVERE, "sql exception", e); } finally { Utils.finishSQL(rs, stmt); } @@ -128,15 +135,15 @@ public class PMQueries { ret = rs.getString(1); } } catch (SQLException e) { - System.err.println(e); + logger.log(Level.SEVERE, "sql exception", e); } finally { Utils.finishSQL(rs, stmt); } return ret; } - public static ArrayList getPMLastConversationsUsers(Connection sql, int uid, int cnt) { - ArrayList users = new ArrayList(); + public static List getPMLastConversationsUsers(Connection sql, int uid, int cnt) { + List users = new ArrayList<>(); PreparedStatement stmt = null; ResultSet rs = null; @@ -152,7 +159,7 @@ public class PMQueries { users.add(u); } } catch (SQLException e) { - System.err.println(e); + logger.log(Level.SEVERE, "sql exception", e); } finally { Utils.finishSQL(rs, stmt); } @@ -177,7 +184,7 @@ public class PMQueries { } } } catch (SQLException e) { - System.err.println(e); + logger.log(Level.SEVERE, "sql exception", e); } finally { Utils.finishSQL(rs, stmt); } @@ -190,18 +197,17 @@ public class PMQueries { return users; } - public static boolean haveUserInArray(ArrayList arr, int uid) { - int s = arr.size(); - for (int i = 0; i < s; i++) { - if (arr.get(i).UID == uid) { + public static boolean haveUserInArray(List arr, int uid) { + for (User user : arr) { + if (user.UID == uid) { return true; } } return false; } - public static ArrayList getPMMessages(Connection sql, int uid, int uid_to) { - ArrayList msgs = new ArrayList(20); + public static List getPMMessages(Connection sql, int uid, int uid_to) { + List msgs = new ArrayList<>(20); PreparedStatement stmt = null; ResultSet rs = null; @@ -223,7 +229,7 @@ public class PMQueries { msgs.add(0, msg); } } catch (SQLException e) { - System.err.println(e); + logger.log(Level.SEVERE, "sql exception", e); } finally { Utils.finishSQL(rs, stmt); } @@ -235,7 +241,7 @@ public class PMQueries { stmt2.setInt(2, uid_to); stmt2.executeUpdate(); } catch (SQLException e) { - System.err.println(e); + logger.log(Level.SEVERE, "sql exception", e); } finally { Utils.finishSQL(null, stmt2); } @@ -243,8 +249,8 @@ public class PMQueries { return msgs; } - public static ArrayList getLastPMInbox(Connection sql, int uid) { - ArrayList msgs = new ArrayList(20); + public static List getLastPMInbox(Connection sql, int uid) { + List msgs = new ArrayList<>(20); PreparedStatement stmt = null; ResultSet rs = null; @@ -264,7 +270,7 @@ public class PMQueries { msgs.add(0, msg); } } catch (SQLException e) { - System.err.println(e); + logger.log(Level.SEVERE, "sql exception", e); } finally { Utils.finishSQL(rs, stmt); } @@ -272,8 +278,8 @@ public class PMQueries { return msgs; } - public static ArrayList getLastPMSent(Connection sql, int uid) { - ArrayList msgs = new ArrayList(20); + public static List getLastPMSent(Connection sql, int uid) { + List msgs = new ArrayList<>(20); PreparedStatement stmt = null; ResultSet rs = null; @@ -293,7 +299,7 @@ public class PMQueries { msgs.add(0, msg); } } catch (SQLException e) { - System.err.println(e); + logger.log(Level.SEVERE, "sql exception", e); } finally { Utils.finishSQL(rs, stmt); } diff --git a/src/main/java/com/juick/server/PushQueries.java b/src/main/java/com/juick/server/PushQueries.java index bf7505ca..c17972b0 100644 --- a/src/main/java/com/juick/server/PushQueries.java +++ b/src/main/java/com/juick/server/PushQueries.java @@ -10,6 +10,8 @@ import java.sql.ResultSet; import java.sql.SQLException; import java.util.ArrayList; import java.util.List; +import java.util.logging.Level; +import java.util.logging.Logger; /** * @@ -17,12 +19,14 @@ import java.util.List; */ public class PushQueries { + private static final Logger logger = Logger.getLogger(PushQueries.class.getName()); + public static String getAndroidRegID(Connection sql, int uid) { return SQLHelpers.getString(sql, "SELECT regid FROM android WHERE user_id=?", uid); } - public static ArrayList getAndroidSubscribers(Connection sql, int uid) { - ArrayList regids = new ArrayList(); + public static List getAndroidSubscribers(Connection sql, int uid) { + List regids = new ArrayList<>(); PreparedStatement stmt = null; ResultSet rs = null; @@ -35,7 +39,7 @@ public class PushQueries { regids.add(rs.getString(1)); } } catch (SQLException e) { - System.err.println(e); + logger.log(Level.SEVERE, "sql exception", e); } finally { Utils.finishSQL(rs, stmt); } @@ -46,8 +50,8 @@ public class PushQueries { return SQLHelpers.getString(sql, "SELECT url FROM winphone WHERE user_id=?", uid); } - public static ArrayList getWinPhoneSubscribers(Connection sql, int uid) { - ArrayList urls = new ArrayList(); + public static List getWinPhoneSubscribers(Connection sql, int uid) { + List urls = new ArrayList<>(); PreparedStatement stmt = null; ResultSet rs = null; @@ -60,7 +64,7 @@ public class PushQueries { urls.add(rs.getString(1)); } } catch (SQLException e) { - System.err.println(e); + logger.log(Level.SEVERE, "sql exception", e); } finally { Utils.finishSQL(rs, stmt); } @@ -72,7 +76,7 @@ public class PushQueries { } public static List getAPNSSubscribers(Connection sql, int uid) { - List urls = new ArrayList(); + List urls = new ArrayList<>(); PreparedStatement stmt = null; ResultSet rs = null; @@ -85,7 +89,7 @@ public class PushQueries { urls.add(rs.getString(1)); } } catch (SQLException e) { - System.err.println(e); + logger.log(Level.SEVERE, "sql exception", e); } finally { Utils.finishSQL(rs, stmt); } diff --git a/src/main/java/com/juick/server/SQLHelpers.java b/src/main/java/com/juick/server/SQLHelpers.java index f5569993..13ebe98a 100644 --- a/src/main/java/com/juick/server/SQLHelpers.java +++ b/src/main/java/com/juick/server/SQLHelpers.java @@ -9,6 +9,9 @@ import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; import java.util.ArrayList; +import java.util.List; +import java.util.logging.Level; +import java.util.logging.Logger; /** * @@ -16,6 +19,8 @@ import java.util.ArrayList; */ public class SQLHelpers { + private static final Logger logger = Logger.getLogger(SQLHelpers.class.getName()); + public static int execute(Connection sql, String query) { int ret = -1; PreparedStatement stmt = null; @@ -23,7 +28,7 @@ public class SQLHelpers { stmt = sql.prepareStatement(query); ret = stmt.executeUpdate(); } catch (SQLException e) { - System.err.println(e); + logger.log(Level.SEVERE, "sql exception", e); } finally { Utils.finishSQL(null, stmt); } @@ -38,7 +43,7 @@ public class SQLHelpers { stmt.setInt(1, param); ret = stmt.executeUpdate(); } catch (SQLException e) { - System.err.println(e); + logger.log(Level.SEVERE, "sql exception", e); } finally { Utils.finishSQL(null, stmt); } @@ -56,7 +61,7 @@ public class SQLHelpers { ret = rs.getInt(1); } } catch (SQLException e) { - System.err.println(e); + logger.log(Level.SEVERE, "sql exception", e); } finally { Utils.finishSQL(rs, stmt); } @@ -75,7 +80,7 @@ public class SQLHelpers { ret = rs.getInt(1); } } catch (SQLException e) { - System.err.println(e); + logger.log(Level.SEVERE, "sql exception", e); } finally { Utils.finishSQL(rs, stmt); } @@ -94,7 +99,7 @@ public class SQLHelpers { ret = rs.getInt(1); } } catch (SQLException e) { - System.err.println(e); + logger.log(Level.SEVERE, "sql exception", e); } finally { Utils.finishSQL(rs, stmt); } @@ -113,7 +118,7 @@ public class SQLHelpers { ret = rs.getString(1); } } catch (SQLException e) { - System.err.println(e); + logger.log(Level.SEVERE, "sql exception", e); } finally { Utils.finishSQL(rs, stmt); } @@ -132,15 +137,15 @@ public class SQLHelpers { ret = rs.getString(1); } } catch (SQLException e) { - System.err.println(e); + logger.log(Level.SEVERE, "sql exception", e); } finally { Utils.finishSQL(rs, stmt); } return ret; } - public static ArrayList getArrayInteger(Connection sql, String query, int param) { - ArrayList ret = new ArrayList(); + public static List getArrayInteger(Connection sql, String query, int param) { + List ret = new ArrayList<>(); PreparedStatement stmt = null; ResultSet rs = null; @@ -153,7 +158,7 @@ public class SQLHelpers { ret.add(rs.getInt(1)); } } catch (SQLException e) { - System.err.println(e); + logger.log(Level.SEVERE, "sql exception", e); } finally { Utils.finishSQL(rs, stmt); } diff --git a/src/main/java/com/juick/server/SubscriptionsQueries.java b/src/main/java/com/juick/server/SubscriptionsQueries.java index d0f5f308..637c2bcf 100644 --- a/src/main/java/com/juick/server/SubscriptionsQueries.java +++ b/src/main/java/com/juick/server/SubscriptionsQueries.java @@ -9,6 +9,9 @@ import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; import java.util.ArrayList; +import java.util.List; +import java.util.logging.Level; +import java.util.logging.Logger; /** * @@ -16,8 +19,10 @@ import java.util.ArrayList; */ public class SubscriptionsQueries { - public static ArrayList getJIDSubscribedToUser(Connection sql, int uid, boolean friendsonly) { - ArrayList jids = new ArrayList(); + private static final Logger logger = Logger.getLogger(SubscriptionsQueries.class.getName()); + + public static List getJIDSubscribedToUser(Connection sql, int uid, boolean friendsonly) { + List jids = new ArrayList<>(); PreparedStatement stmt = null; ResultSet rs = null; @@ -36,27 +41,27 @@ public class SubscriptionsQueries { jids.add(rs.getString(1)); } } catch (SQLException e) { - System.err.println(e); + logger.log(Level.SEVERE, "sql exception", e); } finally { Utils.finishSQL(rs, stmt); } return jids; } - public static ArrayList getJIDSubscribedToUserAndTags(Connection sql, int uid, int mid) { - ArrayList jids = new ArrayList(); + public static List getJIDSubscribedToUserAndTags(Connection sql, int uid, int mid) { + List jids = new ArrayList<>(); PreparedStatement stmt = null; ResultSet rs = null; String tbl = "subscr_jids_" + mid; - ArrayList tags = MessagesQueries.getMessageTagsIDs(sql, mid); + List tags = MessagesQueries.getMessageTagsIDs(sql, mid); try { stmt = sql.prepareStatement("CREATE TEMPORARY TABLE " + tbl + "(user_id INT UNSIGNED NOT NULL) ENGINE=MEMORY"); stmt.executeUpdate(); } catch (SQLException e) { - System.err.println(e); + logger.log(Level.SEVERE, "sql exception", e); } finally { Utils.finishSQL(null, stmt); } @@ -69,7 +74,7 @@ public class SubscriptionsQueries { stmt = sql.prepareStatement(query); stmt.executeUpdate(); } catch (SQLException e) { - System.err.println(e); + logger.log(Level.SEVERE, "sql exception", e); } finally { Utils.finishSQL(null, stmt); } @@ -87,7 +92,7 @@ public class SubscriptionsQueries { jids.add(rs.getString(1)); } } catch (SQLException e) { - System.err.println(e); + logger.log(Level.SEVERE, "sql exception", e); } finally { Utils.finishSQL(rs, stmt); } @@ -96,7 +101,7 @@ public class SubscriptionsQueries { stmt = sql.prepareStatement("DROP TABLE " + tbl); stmt.executeUpdate(); } catch (SQLException e) { - System.err.println(e); + logger.log(Level.SEVERE, "sql exception", e); } finally { Utils.finishSQL(null, stmt); } @@ -104,8 +109,8 @@ public class SubscriptionsQueries { return jids; } - public static ArrayList getJIDSubscribedToComments(Connection sql, int mid, int ignore_uid) { - ArrayList jids = new ArrayList(); + public static List getJIDSubscribedToComments(Connection sql, int mid, int ignore_uid) { + List jids = new ArrayList<>(); PreparedStatement stmt = null; ResultSet rs = null; @@ -119,17 +124,17 @@ public class SubscriptionsQueries { jids.add(rs.getString(1)); } } catch (SQLException e) { - System.err.println(e); + logger.log(Level.SEVERE, "sql exception", e); } finally { Utils.finishSQL(rs, stmt); } return jids; } - public static ArrayList getJIDSubscribedToUserRecommendations(Connection sql, int uid, int mid, int muid) { - ArrayList jids = new ArrayList(); + public static List getJIDSubscribedToUserRecommendations(Connection sql, int uid, int mid, int muid) { + List jids = new ArrayList<>(); - ArrayList tags = MessagesQueries.getMessageTagsIDs(sql, mid); + List tags = MessagesQueries.getMessageTagsIDs(sql, mid); PreparedStatement stmt = null; ResultSet rs = null; @@ -154,7 +159,7 @@ public class SubscriptionsQueries { jids.add(rs.getString(1)); } } catch (SQLException e) { - System.err.println(e); + logger.log(Level.SEVERE, "sql exception", e); } finally { Utils.finishSQL(rs, stmt); } diff --git a/src/main/java/com/juick/server/TagQueries.java b/src/main/java/com/juick/server/TagQueries.java index 493e8675..1c5e27d1 100644 --- a/src/main/java/com/juick/server/TagQueries.java +++ b/src/main/java/com/juick/server/TagQueries.java @@ -17,12 +17,17 @@ */ package com.juick.server; +import com.juick.Tag; + import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; import java.util.ArrayList; +import java.util.List; +import java.util.logging.Level; +import java.util.logging.Logger; /** * @@ -30,6 +35,8 @@ import java.util.ArrayList; */ public class TagQueries { + private static final Logger logger = Logger.getLogger(TagQueries.class.getName()); + public static com.juick.Tag getTag(Connection sql, int tid) { com.juick.Tag ret = null; @@ -46,7 +53,7 @@ public class TagQueries { ret.Name = rs.getString(2); } } catch (SQLException e) { - System.err.println(e); + logger.log(Level.SEVERE, "sql exception", e); } finally { Utils.finishSQL(rs, stmt); } @@ -70,7 +77,7 @@ public class TagQueries { ret.Name = rs.getString(3); } } catch (SQLException e) { - System.err.println(e); + logger.log(Level.SEVERE, "sql exception", e); } finally { Utils.finishSQL(rs, stmt); } @@ -84,12 +91,12 @@ public class TagQueries { return ret; } - public static ArrayList getTags(Connection sql, String[] tags, boolean autoCreate) { - ArrayList ret = new ArrayList(); + public static List getTags(Connection sql, String[] tags, boolean autoCreate) { + List ret = new ArrayList<>(); - for (int i = 0; i < tags.length; i++) { - if (!tags[i].isEmpty()) { - com.juick.Tag t = getTag(sql, tags[i], autoCreate); + for (String tag : tags) { + if (!tag.isEmpty()) { + Tag t = getTag(sql, tag, autoCreate); if (t != null) { ret.add(t); } @@ -112,7 +119,7 @@ public class TagQueries { ret = rs.getInt(1) == 1; } } catch (SQLException e) { - System.err.println(e); + logger.log(Level.SEVERE, "sql exception", e); } finally { Utils.finishSQL(rs, stmt); } @@ -134,7 +141,7 @@ public class TagQueries { ret = rs.getInt(1); } } catch (SQLException e) { - System.err.println(e); + logger.log(Level.SEVERE, "sql exception", e); } finally { Utils.finishSQL(rs, stmt); } @@ -142,8 +149,8 @@ public class TagQueries { return ret; } - public static ArrayList getUserTagsAll(Connection sql, int uid) { - ArrayList tags = new ArrayList(); + public static List getUserTagsAll(Connection sql, int uid) { + List tags = new ArrayList<>(); PreparedStatement stmt = null; ResultSet rs = null; @@ -159,15 +166,15 @@ public class TagQueries { tags.add(t); } } catch (SQLException e) { - System.err.println(e); + logger.log(Level.SEVERE, "sql exception", e); } finally { Utils.finishSQL(rs, stmt); } return tags; } - public static ArrayList getUserBLTags(Connection sql, int uid) { - ArrayList tags = new ArrayList(); + public static List getUserBLTags(Connection sql, int uid) { + List tags = new ArrayList<>(); PreparedStatement stmt = null; ResultSet rs = null; @@ -180,7 +187,7 @@ public class TagQueries { tags.add(rs.getString(1)); } } catch (SQLException e) { - System.err.println(e); + logger.log(Level.SEVERE, "sql exception", e); } finally { Utils.finishSQL(rs, stmt); } diff --git a/src/main/java/com/juick/server/UserQueries.java b/src/main/java/com/juick/server/UserQueries.java index 767a68d2..98573bfb 100644 --- a/src/main/java/com/juick/server/UserQueries.java +++ b/src/main/java/com/juick/server/UserQueries.java @@ -25,6 +25,7 @@ import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; import java.util.ArrayList; +import java.util.List; import java.util.Random; import java.util.UUID; import java.util.logging.Level; @@ -52,7 +53,7 @@ public class UserQueries { stmt.setString(2, hash); stmt.executeUpdate(); } catch (SQLException e) { - System.err.println(e); + logger.log(Level.SEVERE, "sql exception", e); } finally { Utils.finishSQL(null, stmt); } @@ -76,7 +77,7 @@ public class UserQueries { uid = rs.getInt(1); } } catch (SQLException e) { - System.err.println(e); + logger.log(Level.SEVERE, "sql exception", e); } finally { Utils.finishSQL(rs, stmt); } @@ -103,7 +104,7 @@ public class UserQueries { user.Banned = rs.getBoolean(2); } } catch (SQLException e) { - System.err.println(e); + logger.log(Level.SEVERE, "sql exception", e); } finally { Utils.finishSQL(rs, stmt); } @@ -126,7 +127,7 @@ public class UserQueries { user.Banned = rs.getBoolean(3); } } catch (SQLException e) { - System.err.println(e); + logger.log(Level.SEVERE, "sql exception", e); } finally { Utils.finishSQL(rs, stmt); } @@ -149,15 +150,15 @@ public class UserQueries { user.JID = jid; } } catch (SQLException e) { - System.err.println(e); + logger.log(Level.SEVERE, "sql exception", e); } finally { Utils.finishSQL(rs, stmt); } return user; } - public static ArrayList getUsersByName(Connection sql, ArrayList unames) { - ArrayList users = new ArrayList(); + public static List getUsersByName(Connection sql, List unames) { + List users = new ArrayList<>(); PreparedStatement stmt = null; ResultSet rs = null; @@ -172,15 +173,15 @@ public class UserQueries { users.add(user); } } catch (SQLException e) { - System.err.println(e); + logger.log(Level.SEVERE, "sql exception", e); } finally { Utils.finishSQL(rs, stmt); } return users; } - public static ArrayList getUsersByID(Connection sql, ArrayList uids) { - ArrayList users = new ArrayList(); + public static List getUsersByID(Connection sql, List uids) { + List users = new ArrayList<>(); PreparedStatement stmt = null; ResultSet rs = null; @@ -195,7 +196,7 @@ public class UserQueries { users.add(u); } } catch (SQLException e) { - System.err.println(e); + logger.log(Level.SEVERE, "sql exception", e); } finally { Utils.finishSQL(rs, stmt); } @@ -203,7 +204,7 @@ public class UserQueries { return users; } - public static boolean fillUsersByID(Connection sql, ArrayList users) { + public static boolean fillUsersByID(Connection sql, List users) { boolean ret = false; String uids = ""; @@ -231,7 +232,7 @@ public class UserQueries { } } } catch (SQLException e) { - System.err.println(e); + logger.log(Level.SEVERE, "sql exception", e); } finally { Utils.finishSQL(rs, stmt); } @@ -239,8 +240,8 @@ public class UserQueries { return ret; } - public static ArrayList getUsersByJID(Connection sql, ArrayList jids) { - ArrayList users = new ArrayList(); + public static List getUsersByJID(Connection sql, List jids) { + List users = new ArrayList<>(); PreparedStatement stmt = null; ResultSet rs = null; @@ -256,7 +257,7 @@ public class UserQueries { users.add(user); } } catch (SQLException e) { - System.err.println(e); + logger.log(Level.SEVERE, "sql exception", e); } finally { Utils.finishSQL(rs, stmt); } @@ -296,7 +297,7 @@ public class UserQueries { user.AuthHash = hash; } } catch (SQLException e) { - System.err.println(e); + logger.log(Level.SEVERE, "sql exception", e); } finally { Utils.finishSQL(rs, stmt); } @@ -315,7 +316,7 @@ public class UserQueries { stmt.setString(2, hash); stmt.executeUpdate(); } catch (SQLException e) { - System.err.println(e); + logger.log(Level.SEVERE, "sql exception", e); } finally { Utils.finishSQL(null, stmt); } @@ -353,7 +354,7 @@ public class UserQueries { } } } catch (SQLException e) { - System.err.println(e); + logger.log(Level.SEVERE, "sql exception", e); } finally { Utils.finishSQL(rs, stmt); } @@ -373,7 +374,7 @@ public class UserQueries { ret = rs.getInt(1); } } catch (SQLException e) { - System.err.println(e); + logger.log(Level.SEVERE, "sql exception", e); } finally { Utils.finishSQL(rs, stmt); } @@ -388,7 +389,7 @@ public class UserQueries { stmt.setInt(2, uid); stmt.executeUpdate(); } catch (SQLException e) { - System.err.println(e); + logger.log(Level.SEVERE, "sql exception", e); } finally { Utils.finishSQL(null, stmt); } @@ -407,7 +408,7 @@ public class UserQueries { ret = rs.getInt(1) < 3600; } } catch (SQLException e) { - System.err.println(e); + logger.log(Level.SEVERE, "sql exception", e); } finally { Utils.finishSQL(rs, stmt); } @@ -428,7 +429,7 @@ public class UserQueries { ret = rs.getInt(1) == 1; } } catch (SQLException e) { - System.err.println(e); + logger.log(Level.SEVERE, "sql exception", e); } finally { Utils.finishSQL(rs, stmt); } @@ -449,7 +450,7 @@ public class UserQueries { ret = rs.getInt(1) == 1; } } catch (SQLException e) { - System.err.println(e); + logger.log(Level.SEVERE, "sql exception", e); } finally { Utils.finishSQL(rs, stmt); } @@ -472,15 +473,15 @@ public class UserQueries { ret = rs.getInt(1) == 1; } } catch (SQLException e) { - System.err.println(e); + logger.log(Level.SEVERE, "sql exception", e); } finally { Utils.finishSQL(rs, stmt); } return ret; } - public static ArrayList checkBL(Connection sql, int visitor, ArrayList uids) { - ArrayList ret = new ArrayList(); + public static List checkBL(Connection sql, int visitor, List uids) { + List ret = new ArrayList<>(); PreparedStatement stmt = null; ResultSet rs = null; @@ -493,7 +494,7 @@ public class UserQueries { ret.add(rs.getInt(1)); } } catch (SQLException e) { - System.err.println(e); + logger.log(Level.SEVERE, "sql exception", e); } finally { Utils.finishSQL(rs, stmt); } @@ -515,19 +516,19 @@ public class UserQueries { ret = rs.getInt(1) == 1; } } catch (SQLException e) { - System.err.println(e); + logger.log(Level.SEVERE, "sql exception", e); } finally { Utils.finishSQL(rs, stmt); } return ret; } - public static ArrayList getUserRead(Connection sql, int uid) { + public static List getUserRead(Connection sql, int uid) { return SQLHelpers.getArrayInteger(sql, "SELECT user_id FROM subscr_users WHERE suser_id=?", uid); } - public static ArrayList getUserReadLeastPopular(Connection sql, int uid, int cnt) { - ArrayList users = new ArrayList(cnt); + public static List getUserReadLeastPopular(Connection sql, int uid, int cnt) { + List users = new ArrayList<>(cnt); PreparedStatement stmt = null; ResultSet rs = null; @@ -544,7 +545,7 @@ public class UserQueries { users.add(u); } } catch (SQLException e) { - System.err.println(e); + logger.log(Level.SEVERE, "sql exception", e); } finally { Utils.finishSQL(rs, stmt); } @@ -552,12 +553,12 @@ public class UserQueries { return users; } - public static ArrayList getUserReaders(Connection sql, int uid) { + public static List getUserReaders(Connection sql, int uid) { return SQLHelpers.getArrayInteger(sql, "SELECT suser_id FROM subscr_users WHERE user_id=?", uid); } - public static ArrayList getUserBLUsers(Connection sql, int uid) { - ArrayList users = new ArrayList(); + public static List getUserBLUsers(Connection sql, int uid) { + List users = new ArrayList<>(); PreparedStatement stmt = null; ResultSet rs = null; @@ -573,7 +574,7 @@ public class UserQueries { users.add(u); } } catch (SQLException e) { - System.err.println(e); + logger.log(Level.SEVERE, "sql exception", e); } finally { Utils.finishSQL(rs, stmt); } @@ -603,7 +604,7 @@ public class UserQueries { return stmt2.execute(); } } catch (SQLException e) { - logger.throwing(UserQueries.class.getName(), "linkTwitterAccount", e); + logger.log(Level.SEVERE, "sql exception", e); } return false; } @@ -642,7 +643,7 @@ public class UserQueries { preparedStatement.setString(3, JID); return preparedStatement.executeUpdate() >= 0; } catch (SQLException e) { - logger.log(Level.SEVERE, "sql error", e); + logger.log(Level.SEVERE, "sql exception", e); } finally { Utils.finishSQL(null, preparedStatement); } diff --git a/src/main/java/com/juick/server/Utils.java b/src/main/java/com/juick/server/Utils.java index f97797d7..1968150e 100644 --- a/src/main/java/com/juick/server/Utils.java +++ b/src/main/java/com/juick/server/Utils.java @@ -21,7 +21,7 @@ import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; -import java.util.ArrayList; +import java.util.List; /** * @@ -29,7 +29,7 @@ import java.util.ArrayList; */ public class Utils { - public static String convertArrayInt2String(ArrayList mids) { + public static String convertArrayInt2String(List mids) { String q = ""; for (int i = 0; i < mids.size(); i++) { if (i > 0) { @@ -40,7 +40,7 @@ public class Utils { return q; } - public static String convertArrayString2String(ArrayList unames) { + public static String convertArrayString2String(List unames) { String q = ""; for (int i = 0; i < unames.size(); i++) { if (i > 0) { -- cgit v1.2.3