From 102925eebf91f45f02824c597c8ec393017aa1cb Mon Sep 17 00:00:00 2001 From: Ugnich Anton Date: Fri, 30 Aug 2013 13:50:25 +0700 Subject: PMQueries.inroster; UserQueries.getUserByJID --- src/com/juick/server/PMQueries.java | 74 +++++++++++++++++++++++++++++++++++ src/com/juick/server/PushQueries.java | 9 ++++- src/com/juick/server/UserQueries.java | 23 +++++++++++ 3 files changed, 105 insertions(+), 1 deletion(-) (limited to 'src/com') 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 getPMLastConversationsUsers(Connection sql, int uid, int cnt) { ArrayList users = new ArrayList(); 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 getAndroidSubscribers(Connection sql, int uid) { ArrayList regids = new ArrayList(); @@ -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 getWinPhoneSubscribers(Connection sql, int uid) { ArrayList urls = new ArrayList(); @@ -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 getUsersByName(Connection sql, ArrayList unames) { ArrayList users = new ArrayList(); -- cgit v1.2.3