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/juick/server/PMQueries.java | |
parent | 439d42ef6d60f0a535fdfa2457da8417b70d966a (diff) |
logger, diamond and arraylist refactoring
Diffstat (limited to 'src/main/java/com/juick/server/PMQueries.java')
-rw-r--r-- | src/main/java/com/juick/server/PMQueries.java | 54 |
1 files changed, 30 insertions, 24 deletions
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); } |