diff options
author | Ugnich Anton | 2012-11-02 17:32:20 +0700 |
---|---|---|
committer | Ugnich Anton | 2012-11-02 17:32:20 +0700 |
commit | 4c311735dcf5d6e54dfb1d2d751a2bd42193e168 (patch) | |
tree | 0b690f7ea4ded45d53e7e598cbc82c8edbc4d85b | |
parent | 860b00003367e5a66ffc8ffe373542e424516249 (diff) |
getMessages
checkBL
-rw-r--r-- | src/com/juick/server/MessagesQueries.java | 52 | ||||
-rw-r--r-- | src/com/juick/server/UserQueries.java | 23 |
2 files changed, 71 insertions, 4 deletions
diff --git a/src/com/juick/server/MessagesQueries.java b/src/com/juick/server/MessagesQueries.java index 1df45803..abcdd285 100644 --- a/src/com/juick/server/MessagesQueries.java +++ b/src/com/juick/server/MessagesQueries.java @@ -93,12 +93,12 @@ public class MessagesQueries { msg.ReadOnly = rs.getBoolean(4); msg.AttachmentType = rs.getString(5); if (rs.getInt(6) > 0) { - msg.place = PlacesQueries.getPlace(sql, rs.getInt(6)); + msg.Place = PlacesQueries.getPlace(sql, rs.getInt(6)); } if (rs.getDouble(7) != 0) { - msg.place = new com.juick.Place(); - msg.place.lat = rs.getDouble(7); - msg.place.lon = rs.getDouble(8); + msg.Place = new com.juick.Place(); + msg.Place.lat = rs.getDouble(7); + msg.Place.lon = rs.getDouble(8); } } } catch (SQLException e) { @@ -621,4 +621,48 @@ 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); + + PreparedStatement stmt = null; + ResultSet rs = null; + try { + stmt = sql.prepareStatement("SELECT STRAIGHT_JOIN messages.message_id,messages.user_id,users.nick,messages_txt.tags,messages.readonly,messages.privacy,messages_txt.txt,TIMESTAMPDIFF(MINUTE,messages.ts,NOW()),messages.ts,messages.replies,messages_txt.repliesby,messages.attach,messages.place_id,places.name,messages.lat,messages.lon FROM ((messages INNER JOIN messages_txt ON messages.message_id=messages_txt.message_id) INNER JOIN users ON messages.user_id=users.id) LEFT JOIN places ON messages.place_id=places.place_id WHERE messages.message_id IN (" + Utils.convertArray2String(mids) + ") ORDER BY messages.message_id DESC"); + rs = stmt.executeQuery(); + rs.beforeFirst(); + while (rs.next()) { + com.juick.Message msg = new com.juick.Message(); + msg.User = new com.juick.User(); + + msg.MID = rs.getInt(1); + msg.User.UID = rs.getInt(2); + msg.User.UName = rs.getString(3); + msg.parseTags(rs.getString(4)); + msg.ReadOnly = rs.getInt(5) == 1; + msg.Privacy = rs.getInt(6); + msg.Text = rs.getString(7); + msg.TimeAgo = rs.getInt(8); + msg.TimestampString = rs.getString(9); + msg.Replies = rs.getInt(10); + msg.RepliesBy = rs.getString(11); + msg.AttachmentType = rs.getString(12); + if (rs.getInt(13) > 0) { + msg.Place = new com.juick.Place(); + msg.Place.pid = rs.getInt(13); + msg.Place.name = rs.getString(14); + msg.Place.lat = rs.getDouble(15); + msg.Place.lon = rs.getDouble(16); + } + + msgs.add(msg); + } + } catch (SQLException e) { + System.err.println(e); + } finally { + Utils.finishSQL(rs, stmt); + } + + return msgs; + } } diff --git a/src/com/juick/server/UserQueries.java b/src/com/juick/server/UserQueries.java index a49da34f..ff1d0e24 100644 --- a/src/com/juick/server/UserQueries.java +++ b/src/com/juick/server/UserQueries.java @@ -21,6 +21,7 @@ import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; +import java.util.ArrayList; import java.util.Random; /** @@ -278,6 +279,28 @@ public class UserQueries { return ret; } + public static ArrayList<Integer> checkBL(Connection sql, int visitor, ArrayList<Integer> uids) { + ArrayList<Integer> ret = new ArrayList<Integer>(); + + PreparedStatement stmt = null; + ResultSet rs = null; + try { + stmt = sql.prepareStatement("SELECT user_id FROM bl_users WHERE bl_user_id=? and user_id IN (" + Utils.convertArray2String(uids) + ")"); + stmt.setInt(1, visitor); + rs = stmt.executeQuery(); + rs.beforeFirst(); + while (rs.next()) { + ret.add(rs.getInt(1)); + } + } catch (SQLException e) { + System.err.println(e); + } finally { + Utils.finishSQL(rs, stmt); + } + + return ret; + } + public static boolean isSubscribed(Connection sql, int uid, int check) { boolean ret = false; |