diff options
author | Vitaly Takmazov | 2016-01-10 16:56:51 +0300 |
---|---|---|
committer | Vitaly Takmazov | 2016-01-10 16:56:51 +0300 |
commit | c37ed56f884661666b964e47efd23a36be9b24d4 (patch) | |
tree | 64917e400d9c97fac185b4f34fd0063314bb7937 /src/main/java/com | |
parent | 439d42ef6d60f0a535fdfa2457da8417b70d966a (diff) |
logger, diamond and arraylist refactoring
Diffstat (limited to 'src/main/java/com')
-rw-r--r-- | src/main/java/com/juick/server/AdsQueries.java | 6 | ||||
-rw-r--r-- | src/main/java/com/juick/server/CrosspostQueries.java | 8 | ||||
-rw-r--r-- | src/main/java/com/juick/server/MessagesQueries.java | 173 | ||||
-rw-r--r-- | src/main/java/com/juick/server/PMQueries.java | 54 | ||||
-rw-r--r-- | src/main/java/com/juick/server/PushQueries.java | 20 | ||||
-rw-r--r-- | src/main/java/com/juick/server/SQLHelpers.java | 25 | ||||
-rw-r--r-- | src/main/java/com/juick/server/SubscriptionsQueries.java | 39 | ||||
-rw-r--r-- | src/main/java/com/juick/server/TagQueries.java | 37 | ||||
-rw-r--r-- | src/main/java/com/juick/server/UserQueries.java | 79 | ||||
-rw-r--r-- | src/main/java/com/juick/server/Utils.java | 6 |
10 files changed, 244 insertions, 203 deletions
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<com.juick.Tag> tags) { + private static final Logger logger = Logger.getLogger(MessagesQueries.class.getName()); + + public static int createMessage(Connection sql, int uid, String txt, String attachment, List<com.juick.Tag> 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<com.juick.Tag> getMessageTags(Connection sql, int mid) { - ArrayList<com.juick.Tag> tags = new ArrayList<com.juick.Tag>(); + public static List<com.juick.Tag> getMessageTags(Connection sql, int mid) { + List<com.juick.Tag> 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<Integer> getMessageTagsIDs(Connection sql, int mid) { - ArrayList<Integer> tids = new ArrayList<Integer>(); + public static List<Integer> getMessageTagsIDs(Connection sql, int mid) { + List<Integer> 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<String> getMessageRecommendations(Connection sql, int mid) { - ArrayList<String> users = new ArrayList<String>(); + ArrayList<String> 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<Integer> getAll(Connection sql, int visitor_uid, int before) { - ArrayList<Integer> mids = new ArrayList<Integer>(20); + public static List<Integer> getAll(Connection sql, int visitor_uid, int before) { + List<Integer> 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<Integer> getTag(Connection sql, int tid, int visitor_uid, int before, int cnt) { - ArrayList<Integer> mids = new ArrayList<Integer>(20); + public static List<Integer> getTag(Connection sql, int tid, int visitor_uid, int before, int cnt) { + List<Integer> 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<Integer> getTags(Connection sql, String tids, int visitor_uid, int before, int cnt) { - ArrayList<Integer> mids = new ArrayList<Integer>(20); + public static List<Integer> getTags(Connection sql, String tids, int visitor_uid, int before, int cnt) { + List<Integer> 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<Integer> getPlace(Connection sql, int place_id, int visitor_uid, int before) { - ArrayList<Integer> mids = new ArrayList<Integer>(20); + public static List<Integer> getPlace(Connection sql, int place_id, int visitor_uid, int before) { + List<Integer> 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<Integer> getMyFeed(Connection sql, int uid, int before) { - ArrayList<Integer> mids = new ArrayList<Integer>(40); + public static List<Integer> getMyFeed(Connection sql, int uid, int before) { + List<Integer> 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<Integer> getPrivate(Connection sql, int uid, int before) { - ArrayList<Integer> mids = new ArrayList<Integer>(20); + public static List<Integer> getPrivate(Connection sql, int uid, int before) { + List<Integer> 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<Integer> getDiscussions(Connection sql, int uid, int before) { - ArrayList<Integer> mids = new ArrayList<Integer>(20); + public static List<Integer> getDiscussions(Connection sql, int uid, int before) { + List<Integer> 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<Integer> getRecommended(Connection sql, int uid, int before) { - ArrayList<Integer> mids = new ArrayList<Integer>(20); + public static List<Integer> getRecommended(Connection sql, int uid, int before) { + List<Integer> 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<Integer> getPopular(Connection sql, int before) { - ArrayList<Integer> mids = new ArrayList<Integer>(20); + public static List<Integer> getPopular(Connection sql, int before) { + List<Integer> 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<Integer> getPhotos(Connection sql, int visitor_uid, int before) { - ArrayList<Integer> mids = new ArrayList<Integer>(20); + public static List<Integer> getPhotos(Connection sql, int visitor_uid, int before) { + List<Integer> 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<Integer> getSearch(Connection sql, Connection sqlSearch, String search, int before) { - ArrayList<Integer> mids0 = new ArrayList<Integer>(20); + public static List<Integer> getSearch(Connection sql, Connection sqlSearch, String search, int before) { + List<Integer> 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<Integer> mids = new ArrayList<Integer>(20); + List<Integer> 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<Integer> getUserBlog(Connection sql, int UID, int privacy, int before) { - ArrayList<Integer> mids = new ArrayList<Integer>(20); + public static List<Integer> getUserBlog(Connection sql, int UID, int privacy, int before) { + List<Integer> 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<Integer> getUserTag(Connection sql, int UID, int TID, int privacy, int before) { - ArrayList<Integer> mids = new ArrayList<Integer>(20); + public static List<Integer> getUserTag(Connection sql, int UID, int TID, int privacy, int before) { + List<Integer> 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<Integer> getUserRecommendations(Connection sql, int UID, int before) { - ArrayList<Integer> mids = new ArrayList<Integer>(20); + public static List<Integer> getUserRecommendations(Connection sql, int UID, int before) { + List<Integer> 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<Integer> getUserPhotos(Connection sql, int UID, int privacy, int before) { - ArrayList<Integer> mids = new ArrayList<Integer>(20); + public static List<Integer> getUserPhotos(Connection sql, int UID, int privacy, int before) { + List<Integer> 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<Integer> getUserSearch(Connection sql, Connection sqlSearch, int UID, String search, int privacy, int before) { - ArrayList<Integer> mids0 = new ArrayList<Integer>(20); + public static List<Integer> getUserSearch(Connection sql, Connection sqlSearch, int UID, String search, int privacy, int before) { + List<Integer> 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<Integer> mids = new ArrayList<Integer>(20); + List<Integer> 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<com.juick.Message> getMessages(Connection sql, ArrayList<Integer> mids) { - ArrayList<com.juick.Message> msgs = new ArrayList<com.juick.Message>(20); + public static List<com.juick.Message> getMessages(Connection sql, List<Integer> mids) { + List<com.juick.Message> 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<com.juick.Message> getReplies(Connection sql, int mid) { - ArrayList<com.juick.Message> replies = new ArrayList<com.juick.Message>(); + public static List<com.juick.Message> getReplies(Connection sql, int mid) { + List<com.juick.Message> 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<com.juick.User> getPMLastConversationsUsers(Connection sql, int uid, int cnt) { - ArrayList<com.juick.User> users = new ArrayList<com.juick.User>(); + public static List<com.juick.User> getPMLastConversationsUsers(Connection sql, int uid, int cnt) { + List<User> 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<com.juick.User> 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<com.juick.User> arr, int uid) { + for (User user : arr) { + if (user.UID == uid) { return true; } } return false; } - public static ArrayList<com.juick.Message> getPMMessages(Connection sql, int uid, int uid_to) { - ArrayList<com.juick.Message> msgs = new ArrayList<com.juick.Message>(20); + public static List<com.juick.Message> getPMMessages(Connection sql, int uid, int uid_to) { + List<com.juick.Message> 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<com.juick.Message> getLastPMInbox(Connection sql, int uid) { - ArrayList<com.juick.Message> msgs = new ArrayList<com.juick.Message>(20); + public static List<com.juick.Message> getLastPMInbox(Connection sql, int uid) { + List<com.juick.Message> 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<com.juick.Message> getLastPMSent(Connection sql, int uid) { - ArrayList<com.juick.Message> msgs = new ArrayList<com.juick.Message>(20); + public static List<com.juick.Message> getLastPMSent(Connection sql, int uid) { + List<com.juick.Message> 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<String> getAndroidSubscribers(Connection sql, int uid) { - ArrayList<String> regids = new ArrayList<String>(); + public static List<String> getAndroidSubscribers(Connection sql, int uid) { + List<String> 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<String> getWinPhoneSubscribers(Connection sql, int uid) { - ArrayList<String> urls = new ArrayList<String>(); + public static List<String> getWinPhoneSubscribers(Connection sql, int uid) { + List<String> 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<String> getAPNSSubscribers(Connection sql, int uid) { - List<String> urls = new ArrayList<String>(); + List<String> 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<Integer> getArrayInteger(Connection sql, String query, int param) { - ArrayList<Integer> ret = new ArrayList<Integer>(); + public static List<Integer> getArrayInteger(Connection sql, String query, int param) { + List<Integer> 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<String> getJIDSubscribedToUser(Connection sql, int uid, boolean friendsonly) { - ArrayList<String> jids = new ArrayList<String>(); + private static final Logger logger = Logger.getLogger(SubscriptionsQueries.class.getName()); + + public static List<String> getJIDSubscribedToUser(Connection sql, int uid, boolean friendsonly) { + List<String> 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<String> getJIDSubscribedToUserAndTags(Connection sql, int uid, int mid) { - ArrayList<String> jids = new ArrayList<String>(); + public static List<String> getJIDSubscribedToUserAndTags(Connection sql, int uid, int mid) { + List<String> jids = new ArrayList<>(); PreparedStatement stmt = null; ResultSet rs = null; String tbl = "subscr_jids_" + mid; - ArrayList<Integer> tags = MessagesQueries.getMessageTagsIDs(sql, mid); + List<Integer> 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<String> getJIDSubscribedToComments(Connection sql, int mid, int ignore_uid) { - ArrayList<String> jids = new ArrayList<String>(); + public static List<String> getJIDSubscribedToComments(Connection sql, int mid, int ignore_uid) { + List<String> 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<String> getJIDSubscribedToUserRecommendations(Connection sql, int uid, int mid, int muid) { - ArrayList<String> jids = new ArrayList<String>(); + public static List<String> getJIDSubscribedToUserRecommendations(Connection sql, int uid, int mid, int muid) { + List<String> jids = new ArrayList<>(); - ArrayList<Integer> tags = MessagesQueries.getMessageTagsIDs(sql, mid); + List<Integer> 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<com.juick.Tag> getTags(Connection sql, String[] tags, boolean autoCreate) { - ArrayList<com.juick.Tag> ret = new ArrayList<com.juick.Tag>(); + public static List<com.juick.Tag> getTags(Connection sql, String[] tags, boolean autoCreate) { + List<Tag> 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<com.juick.Tag> getUserTagsAll(Connection sql, int uid) { - ArrayList<com.juick.Tag> tags = new ArrayList<com.juick.Tag>(); + public static List<com.juick.Tag> getUserTagsAll(Connection sql, int uid) { + List<com.juick.Tag> 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<String> getUserBLTags(Connection sql, int uid) { - ArrayList<String> tags = new ArrayList<String>(); + public static List<String> getUserBLTags(Connection sql, int uid) { + List<String> 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<com.juick.User> getUsersByName(Connection sql, ArrayList<String> unames) { - ArrayList<com.juick.User> users = new ArrayList<com.juick.User>(); + public static List<com.juick.User> getUsersByName(Connection sql, List<String> unames) { + List<com.juick.User> 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<com.juick.User> getUsersByID(Connection sql, ArrayList<Integer> uids) { - ArrayList<com.juick.User> users = new ArrayList<com.juick.User>(); + public static List<com.juick.User> getUsersByID(Connection sql, List<Integer> uids) { + List<com.juick.User> 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<com.juick.User> users) { + public static boolean fillUsersByID(Connection sql, List<com.juick.User> 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<com.juick.User> getUsersByJID(Connection sql, ArrayList<String> jids) { - ArrayList<com.juick.User> users = new ArrayList<com.juick.User>(); + public static List<com.juick.User> getUsersByJID(Connection sql, List<String> jids) { + List<com.juick.User> 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<Integer> checkBL(Connection sql, int visitor, ArrayList<Integer> uids) { - ArrayList<Integer> ret = new ArrayList<Integer>(); + public static List<Integer> checkBL(Connection sql, int visitor, List<Integer> uids) { + List<Integer> 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<Integer> getUserRead(Connection sql, int uid) { + public static List<Integer> getUserRead(Connection sql, int uid) { return SQLHelpers.getArrayInteger(sql, "SELECT user_id FROM subscr_users WHERE suser_id=?", uid); } - public static ArrayList<com.juick.User> getUserReadLeastPopular(Connection sql, int uid, int cnt) { - ArrayList<com.juick.User> users = new ArrayList<com.juick.User>(cnt); + public static List<com.juick.User> getUserReadLeastPopular(Connection sql, int uid, int cnt) { + List<com.juick.User> 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<Integer> getUserReaders(Connection sql, int uid) { + public static List<Integer> getUserReaders(Connection sql, int uid) { return SQLHelpers.getArrayInteger(sql, "SELECT suser_id FROM subscr_users WHERE user_id=?", uid); } - public static ArrayList<com.juick.User> getUserBLUsers(Connection sql, int uid) { - ArrayList<com.juick.User> users = new ArrayList<com.juick.User>(); + public static List<com.juick.User> getUserBLUsers(Connection sql, int uid) { + List<com.juick.User> 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<Integer> mids) { + public static String convertArrayInt2String(List<Integer> 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<String> unames) { + public static String convertArrayString2String(List<String> unames) { String q = ""; for (int i = 0; i < unames.size(); i++) { if (i > 0) { |