diff options
author | 2013-08-30 13:50:25 +0700 | |
---|---|---|
committer | 2013-08-30 13:50:25 +0700 | |
commit | 102925eebf91f45f02824c597c8ec393017aa1cb (patch) | |
tree | 23f6ae591b823a35cb1b29bb2887847d91d5996f | |
parent | b944a64c6b54b9819542ab2d43d85114ef2908e1 (diff) |
PMQueries.inroster; UserQueries.getUserByJID
-rw-r--r-- | src/com/juick/server/PMQueries.java | 74 | ||||
-rw-r--r-- | src/com/juick/server/PushQueries.java | 9 | ||||
-rw-r--r-- | src/com/juick/server/UserQueries.java | 23 |
3 files changed, 105 insertions, 1 deletions
diff --git a/src/com/juick/server/PMQueries.java b/src/com/juick/server/PMQueries.java index 42f3aefd..91ebbee2 100644 --- a/src/com/juick/server/PMQueries.java +++ b/src/com/juick/server/PMQueries.java @@ -61,6 +61,80 @@ public class PMQueries { return ret; } + public static boolean addPMinRoster(Connection sql, int uid, String jid) { + boolean ret = false; + PreparedStatement stmt = null; + try { + stmt = sql.prepareStatement("INSERT INTO pm_inroster(user_id,jid) VALUES (?,?)"); + stmt.setInt(1, uid); + stmt.setString(2, jid); + ret = stmt.executeUpdate() > 0; + } catch (SQLException e) { + System.err.println(e); + } finally { + Utils.finishSQL(null, stmt); + } + return ret; + } + + public static boolean removePMinRoster(Connection sql, int uid, String jid) { + boolean ret = false; + PreparedStatement stmt = null; + try { + stmt = sql.prepareStatement("DELETE FROM pm_inroster WHERE user_id=? AND jid=?"); + stmt.setInt(1, uid); + stmt.setString(2, jid); + ret = stmt.executeUpdate() > 0; + } catch (SQLException e) { + System.err.println(e); + } finally { + Utils.finishSQL(null, stmt); + } + return ret; + } + + public static boolean havePMinRoster(Connection sql, int uid, String jid) { + boolean ret = false; + + PreparedStatement stmt = null; + ResultSet rs = null; + try { + stmt = sql.prepareStatement("SELECT 1 FROM pm_inroster WHERE user_id=? AND jid=?"); + stmt.setInt(1, uid); + stmt.setString(2, jid); + rs = stmt.executeQuery(); + if (rs.first()) { + ret = true; + } + } catch (SQLException e) { + System.err.println(e); + } finally { + Utils.finishSQL(rs, stmt); + } + return ret; + } + + public static String getLastView(Connection sql, int uid_from, int uid_to) { + String ret = null; + + PreparedStatement stmt = null; + ResultSet rs = null; + try { + stmt = sql.prepareStatement("SELECT lastview FROM pm_streams WHERE user_id=? AND user_id_to=?"); + stmt.setInt(1, uid_from); + stmt.setInt(2, uid_to); + rs = stmt.executeQuery(); + if (rs.first()) { + ret = rs.getString(1); + } + } catch (SQLException e) { + System.err.println(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>(); diff --git a/src/com/juick/server/PushQueries.java b/src/com/juick/server/PushQueries.java index a532622a..84f42722 100644 --- a/src/com/juick/server/PushQueries.java +++ b/src/com/juick/server/PushQueries.java @@ -16,6 +16,10 @@ import java.util.ArrayList; */ public class PushQueries { + 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>(); @@ -37,6 +41,10 @@ public class PushQueries { return regids; } + public static String getWinPhoneURL(Connection sql, int uid) { + 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>(); @@ -57,5 +65,4 @@ public class PushQueries { } return urls; } - } diff --git a/src/com/juick/server/UserQueries.java b/src/com/juick/server/UserQueries.java index bb4d19df..e56accdb 100644 --- a/src/com/juick/server/UserQueries.java +++ b/src/com/juick/server/UserQueries.java @@ -123,6 +123,29 @@ public class UserQueries { return user; } + public static com.juick.User getUserByJID(Connection sql, String jid) { + com.juick.User user = null; + + PreparedStatement stmt = null; + ResultSet rs = null; + try { + stmt = sql.prepareStatement("SELECT id,nick FROM users WHERE id=(SELECT user_id FROM jids WHERE jid=?)"); + stmt.setString(1, jid); + rs = stmt.executeQuery(); + if (rs.first()) { + user = new com.juick.User(); + user.UID = rs.getInt(1); + user.UName = rs.getString(2); + user.JID = jid; + } + } catch (SQLException e) { + System.err.println(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>(); |