From d00fd7705cb1a4b085eed7f34df2f1c6d9a69f76 Mon Sep 17 00:00:00 2001
From: Vitaly Takmazov
Date: Sat, 24 Oct 2015 18:09:15 +0300
Subject: moving to Gradle
---
src/main/java/com/juick/server/AdsQueries.java | 51 +
.../java/com/juick/server/CrosspostQueries.java | 80 ++
.../java/com/juick/server/MessagesQueries.java | 1065 ++++++++++++++++++++
src/main/java/com/juick/server/PMQueries.java | 303 ++++++
src/main/java/com/juick/server/PushQueries.java | 68 ++
src/main/java/com/juick/server/SQLHelpers.java | 163 +++
.../com/juick/server/SubscriptionsQueries.java | 168 +++
src/main/java/com/juick/server/TagQueries.java | 189 ++++
src/main/java/com/juick/server/UserQueries.java | 592 +++++++++++
src/main/java/com/juick/server/Utils.java | 86 ++
10 files changed, 2765 insertions(+)
create mode 100644 src/main/java/com/juick/server/AdsQueries.java
create mode 100644 src/main/java/com/juick/server/CrosspostQueries.java
create mode 100644 src/main/java/com/juick/server/MessagesQueries.java
create mode 100644 src/main/java/com/juick/server/PMQueries.java
create mode 100644 src/main/java/com/juick/server/PushQueries.java
create mode 100644 src/main/java/com/juick/server/SQLHelpers.java
create mode 100644 src/main/java/com/juick/server/SubscriptionsQueries.java
create mode 100644 src/main/java/com/juick/server/TagQueries.java
create mode 100644 src/main/java/com/juick/server/UserQueries.java
create mode 100644 src/main/java/com/juick/server/Utils.java
(limited to 'src/main')
diff --git a/src/main/java/com/juick/server/AdsQueries.java b/src/main/java/com/juick/server/AdsQueries.java
new file mode 100644
index 00000000..0fb4c0a6
--- /dev/null
+++ b/src/main/java/com/juick/server/AdsQueries.java
@@ -0,0 +1,51 @@
+/*
+ * Juick
+ * Copyright (C) 2008-2011, ugnich
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see .
+ */
+package com.juick.server;
+
+import java.sql.Connection;
+import java.sql.PreparedStatement;
+import java.sql.SQLException;
+
+/**
+ *
+ * @author ugnich
+ */
+public class AdsQueries {
+
+ 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);
+ } else {
+ return SQLHelpers.getInt(sql, "SELECT message_id FROM ads_messages ORDER BY RAND() LIMIT 1", 0);
+ }
+ }
+
+ public static void logAdMID(Connection sql, int uid, int mid) {
+ PreparedStatement stmt = null;
+ try {
+ stmt = sql.prepareStatement("INSERT INTO ads_messages_log(user_id,message_id,ts) VALUES (?,?,UNIX_TIMESTAMP())");
+ stmt.setInt(1, uid);
+ stmt.setInt(2, mid);
+ stmt.executeUpdate();
+ } catch (SQLException e) {
+ System.err.println(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
new file mode 100644
index 00000000..fd677048
--- /dev/null
+++ b/src/main/java/com/juick/server/CrosspostQueries.java
@@ -0,0 +1,80 @@
+/*
+ * Juick
+ * Copyright (C) 2008-2013, Ugnich Anton
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see .
+ */
+package com.juick.server;
+
+import java.sql.Connection;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+
+/**
+ *
+ * @author ugnich
+ */
+public class CrosspostQueries {
+
+ public static String[] getTwitterTokens(Connection sql, int uid) {
+ String tokens[] = null;
+
+ PreparedStatement stmt = null;
+ ResultSet rs = null;
+ try {
+ stmt = sql.prepareStatement("SELECT access_token,access_token_secret FROM twitter WHERE user_id=? AND crosspost=1");
+ stmt.setInt(1, uid);
+ rs = stmt.executeQuery();
+ if (rs.first()) {
+ tokens = new String[2];
+ tokens[0] = rs.getString(1);
+ tokens[1] = rs.getString(2);
+ }
+ } catch (SQLException e) {
+ System.err.println(e);
+ } finally {
+ Utils.finishSQL(rs, stmt);
+ }
+
+ return tokens;
+ }
+
+ public static String getFacebookToken(Connection sql, int uid) {
+ return SQLHelpers.getString(sql, "SELECT access_token FROM facebook WHERE user_id=? AND access_token IS NOT NULL AND crosspost=1", uid);
+ }
+
+ public static String[] getVKTokens(Connection sql, int uid) {
+ String tokens[] = null;
+
+ PreparedStatement stmt = null;
+ ResultSet rs = null;
+ try {
+ stmt = sql.prepareStatement("SELECT vk_id,access_token FROM vk WHERE user_id=? AND crosspost=1");
+ stmt.setInt(1, uid);
+ rs = stmt.executeQuery();
+ if (rs.first()) {
+ tokens = new String[2];
+ tokens[0] = rs.getString(1);
+ tokens[1] = rs.getString(2);
+ }
+ } catch (SQLException e) {
+ System.err.println(e);
+ } finally {
+ Utils.finishSQL(rs, stmt);
+ }
+
+ return tokens;
+ }
+}
diff --git a/src/main/java/com/juick/server/MessagesQueries.java b/src/main/java/com/juick/server/MessagesQueries.java
new file mode 100644
index 00000000..8bef9018
--- /dev/null
+++ b/src/main/java/com/juick/server/MessagesQueries.java
@@ -0,0 +1,1065 @@
+/*
+ * Juick
+ * Copyright (C) 2008-2011, Ugnich Anton
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see .
+ */
+package com.juick.server;
+
+import java.sql.Connection;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
+import java.sql.Types;
+import java.util.ArrayList;
+import java.util.Collections;
+
+/**
+ *
+ * @author Ugnich Anton
+ */
+public class MessagesQueries {
+
+ public static int createMessage(Connection sql, int uid, String txt, String attachment, ArrayList tags) {
+ int mid = 0;
+
+ PreparedStatement stmt = null;
+ ResultSet rs = null;
+ try {
+ stmt = sql.prepareStatement("INSERT INTO messages(user_id,attach) VALUES (?,?)", Statement.RETURN_GENERATED_KEYS);
+ stmt.setInt(1, uid);
+ if (attachment != null) {
+ stmt.setString(2, attachment);
+ } else {
+ stmt.setNull(2, Types.VARCHAR);
+ }
+ stmt.executeUpdate();
+ rs = stmt.getGeneratedKeys();
+ if (rs.first()) {
+ mid = rs.getInt(1);
+ }
+ } catch (SQLException e) {
+ System.err.println(e);
+ } finally {
+ Utils.finishSQL(null, stmt);
+ }
+
+ if (mid > 0) {
+ String tagsNames = "";
+ String tagsIDs = "";
+
+ for (int i = 0; i < tags.size(); i++) {
+ if (i > 0) {
+ tagsNames += " ";
+ tagsIDs += ",";
+ }
+ tagsNames += tags.get(i).Name;
+ tagsIDs += "(" + mid + "," + tags.get(i).TID + ")";
+ }
+
+ try {
+ stmt = sql.prepareStatement("INSERT INTO messages_tags(message_id,tag_id) VALUES " + tagsIDs);
+ stmt.executeUpdate();
+ } catch (SQLException e) {
+ System.err.println(e);
+ } finally {
+ Utils.finishSQL(null, stmt);
+ }
+
+ try {
+ stmt = sql.prepareStatement("INSERT INTO messages_txt(message_id,tags,txt) VALUES (?,?,?)");
+ stmt.setInt(1, mid);
+ stmt.setString(2, tagsNames);
+ stmt.setString(3, txt);
+ stmt.executeUpdate();
+ } catch (SQLException e) {
+ System.err.println(e);
+ } finally {
+ Utils.finishSQL(null, stmt);
+ }
+ }
+
+ return mid;
+ }
+
+ public static int createReply(Connection sql, int mid, int rid, int uid, String txt, String attachment) {
+ int ridnew = getReplyIDIncrement(sql, mid);
+
+ PreparedStatement stmt = null;
+ try {
+ stmt = sql.prepareStatement("INSERT INTO replies(message_id,reply_id,user_id,replyto,attach,txt) VALUES (?,?,?,?,?,?)");
+ stmt.setInt(1, mid);
+ stmt.setInt(2, ridnew);
+ stmt.setInt(3, uid);
+ stmt.setInt(4, rid);
+ if (attachment != null) {
+ stmt.setString(5, attachment);
+ } else {
+ stmt.setNull(5, Types.VARCHAR);
+ }
+ stmt.setString(6, txt);
+ if (stmt.executeUpdate() == 0) {
+ ridnew = 0;
+ }
+ } catch (SQLException e) {
+ System.err.println(e);
+ } finally {
+ Utils.finishSQL(null, stmt);
+ }
+
+ if (ridnew > 0) {
+ SQLHelpers.executeInt(sql, "UPDATE messages SET replies=replies+1 WHERE message_id=?", mid);
+ }
+
+ return ridnew;
+ }
+
+ public static int getReplyIDIncrement(Connection sql, int mid) {
+ int rid = 0;
+
+ SQLHelpers.execute(sql, "LOCK TABLES messages WRITE");
+ if (SQLHelpers.executeInt(sql, "UPDATE messages SET maxreplyid=maxreplyid+1 WHERE message_id=?", mid) == 1) {
+ rid = SQLHelpers.getInt(sql, "SELECT maxreplyid FROM messages WHERE message_id=?", mid, 0);
+ }
+ SQLHelpers.execute(sql, "UNLOCK TABLES");
+
+ return rid;
+ }
+
+ public static boolean recommendMessage(Connection sql, int mid, int vuid) {
+ boolean res = SQLHelpers.execute(sql, "INSERT IGNORE INTO favorites(user_id,message_id) VALUES (" + vuid + "," + mid + ")") == 1;
+ if (res) {
+ SQLHelpers.executeInt(sql, "UPDATE messages SET likes=likes+1 WHERE message_id=?", mid);
+ }
+ return res;
+ }
+
+ public static boolean canViewThread(Connection sql, int mid, int uid) {
+
+ int privacy = 0;
+ int owner_uid = 0;
+
+ PreparedStatement stmt = null;
+ ResultSet rs = null;
+ try {
+ stmt = sql.prepareStatement("SELECT user_id,privacy FROM messages WHERE messages.message_id=?");
+ stmt.setInt(1, mid);
+ rs = stmt.executeQuery();
+ if (rs.first()) {
+ owner_uid = rs.getInt(1);
+ privacy = rs.getInt(2);
+ }
+ } catch (SQLException e) {
+ System.err.println(e);
+ } finally {
+ Utils.finishSQL(rs, stmt);
+ }
+
+ return privacy >= 0
+ || uid == owner_uid
+ || ((privacy == -1 || privacy == -2) && uid > 0 && UserQueries.isInWL(sql, owner_uid, uid));
+ }
+
+ public static boolean isReadOnly(Connection sql, int mid) {
+ boolean ret = false;
+
+ PreparedStatement stmt = null;
+ ResultSet rs = null;
+ try {
+ stmt = sql.prepareStatement("SELECT readonly FROM messages WHERE message_id=?");
+ stmt.setInt(1, mid);
+ rs = stmt.executeQuery();
+ if (rs.first()) {
+ ret = rs.getInt(1) == 1;
+ }
+ } catch (SQLException e) {
+ System.err.println(e);
+ } finally {
+ Utils.finishSQL(rs, stmt);
+ }
+ return ret;
+ }
+
+ public static boolean isSubscribed(Connection sql, int uid, int mid) {
+ boolean ret = false;
+
+ PreparedStatement stmt = null;
+ ResultSet rs = null;
+ try {
+ stmt = sql.prepareStatement("SELECT 1 FROM subscr_messages WHERE suser_id=? AND message_id=?");
+ stmt.setInt(1, uid);
+ stmt.setInt(2, mid);
+ rs = stmt.executeQuery();
+ if (rs.first()) {
+ ret = rs.getInt(1) == 1;
+ }
+ } catch (SQLException e) {
+ System.err.println(e);
+ } finally {
+ Utils.finishSQL(rs, stmt);
+ }
+ return ret;
+ }
+
+ public static int getMessagePrivacy(Connection sql, int mid) {
+ return SQLHelpers.getInt(sql, "SELECT privacy FROM messages WHERE message_id=?", mid, -4);
+ }
+
+ public static com.juick.Message getMessage(Connection sql, int mid) {
+ com.juick.Message msg = null;
+
+ PreparedStatement stmt = null;
+ ResultSet rs = null;
+ try {
+ stmt = sql.prepareStatement("SELECT messages.user_id,users.nick,TIMESTAMPDIFF(MINUTE,messages.ts,NOW()),DATE_FORMAT(messages.ts,'%Y-%m-%d %H:%i:%s'),messages.readonly,messages.privacy,messages.replies,messages.attach,messages.place_id,messages.lat,messages.lon,messages.likes,messages.hidden FROM messages INNER JOIN users ON messages.user_id=users.id WHERE messages.message_id=?");
+ stmt.setInt(1, mid);
+ rs = stmt.executeQuery();
+ if (rs.first()) {
+ msg = new com.juick.Message();
+ msg.MID = mid;
+ msg.User = new com.juick.User();
+ msg.User.UID = rs.getInt(1);
+ msg.User.UName = rs.getString(2);
+ msg.TimeAgo = rs.getInt(3);
+ msg.TimestampString = rs.getString(4);
+ msg.ReadOnly = rs.getBoolean(5);
+ msg.Privacy = rs.getInt(6);
+ msg.FriendsOnly = msg.Privacy < 0;
+ msg.Replies = rs.getInt(7);
+ msg.AttachmentType = rs.getString(8);
+ //if (rs.getInt(9) > 0) {
+ // msg.Place = PlacesQueries.getPlace(sql, rs.getInt(9));
+ //}
+ if (rs.getDouble(10) != 0) {
+ msg.Place = new com.juick.Place();
+ msg.Place.lat = rs.getDouble(10);
+ msg.Place.lon = rs.getDouble(11);
+ }
+ msg.Likes = rs.getInt(12);
+ msg.Hidden = rs.getBoolean(13);
+ }
+ } catch (SQLException e) {
+ System.err.println(e);
+ } finally {
+ Utils.finishSQL(rs, stmt);
+ }
+
+ if (msg == null) {
+ return null;
+ }
+
+ try {
+ stmt = sql.prepareStatement("SELECT tags,repliesby,txt FROM messages_txt WHERE message_id=?");
+ stmt.setInt(1, mid);
+ rs = stmt.executeQuery();
+ if (rs.first()) {
+ if (rs.getString(1) != null) {
+ msg.parseTags(rs.getString(1));
+ }
+ msg.RepliesBy = rs.getString(2);
+ msg.Text = rs.getString(3);
+ }
+ } catch (SQLException e) {
+ System.err.println(e);
+ } finally {
+ Utils.finishSQL(rs, stmt);
+ }
+
+ return msg;
+ }
+
+ public static com.juick.Message getReply(Connection sql, int mid, int rid) {
+ com.juick.Message msg = null;
+
+ PreparedStatement stmt = null;
+ ResultSet rs = null;
+ try {
+ stmt = sql.prepareStatement("SELECT replies.user_id,users.nick,replies.replyto,DATE_FORMAT(replies.ts,'%Y-%m-%d %H:%i:%s'),replies.attach,replies.txt FROM replies INNER JOIN users ON replies.user_id=users.id WHERE replies.message_id=? AND replies.reply_id=?");
+ stmt.setInt(1, mid);
+ stmt.setInt(2, rid);
+ rs = stmt.executeQuery();
+ if (rs.first()) {
+ msg = new com.juick.Message();
+ msg.MID = mid;
+ msg.RID = rid;
+ msg.User = new com.juick.User();
+ msg.User.UID = rs.getInt(1);
+ msg.User.UName = rs.getString(2);
+ msg.ReplyTo = rs.getInt(3);
+ msg.TimestampString = rs.getString(4);
+ msg.AttachmentType = rs.getString(5);
+ msg.Text = rs.getString(6);
+ }
+ } catch (SQLException e) {
+ System.err.println(e);
+ } finally {
+ Utils.finishSQL(rs, stmt);
+ }
+
+ return msg;
+ }
+
+ public static com.juick.User getMessageAuthor(Connection sql, int mid) {
+ com.juick.User user = null;
+
+ PreparedStatement stmt = null;
+ ResultSet rs = null;
+ try {
+ stmt = sql.prepareStatement("SELECT messages.user_id,users.nick FROM messages INNER JOIN users ON messages.user_id=users.id WHERE messages.message_id=?");
+ stmt.setInt(1, mid);
+ rs = stmt.executeQuery();
+ if (rs.first()) {
+ user = new com.juick.User();
+ user.UID = rs.getInt(1);
+ user.UName = rs.getString(2);
+ }
+ } catch (SQLException e) {
+ System.err.println(e);
+ } finally {
+ Utils.finishSQL(rs, stmt);
+ }
+ return user;
+ }
+
+ public static ArrayList getMessageTags(Connection sql, int mid) {
+ ArrayList tags = new ArrayList();
+
+ PreparedStatement stmt = null;
+ ResultSet rs = null;
+ try {
+ stmt = sql.prepareStatement("SELECT tags.tag_id,synonym_id,name,stat_messages FROM tags INNER JOIN messages_tags ON (messages_tags.message_id=? AND messages_tags.tag_id=tags.tag_id)");
+ stmt.setInt(1, mid);
+ rs = stmt.executeQuery();
+ rs.beforeFirst();
+ while (rs.next()) {
+ com.juick.Tag t = new com.juick.Tag();
+ t.TID = rs.getInt(1);
+ t.SynonymID = rs.getInt(2);
+ t.Name = rs.getString(3);
+ t.UsageCnt = rs.getInt(4);
+ tags.add(t);
+ }
+ } catch (SQLException e) {
+ System.err.println(e);
+ } finally {
+ Utils.finishSQL(rs, stmt);
+ }
+
+ return tags;
+ }
+
+ public static ArrayList getMessageTagsIDs(Connection sql, int mid) {
+ ArrayList tids = new ArrayList();
+
+ PreparedStatement stmt = null;
+ ResultSet rs = null;
+ try {
+ stmt = sql.prepareStatement("SELECT tag_id FROM messages_tags WHERE message_id=?");
+ stmt.setInt(1, mid);
+ rs = stmt.executeQuery();
+ rs.beforeFirst();
+ while (rs.next()) {
+ tids.add(rs.getInt(1));
+ }
+ } catch (SQLException e) {
+ System.err.println(e);
+ } finally {
+ Utils.finishSQL(rs, stmt);
+ }
+
+ return tids;
+ }
+
+ public static ArrayList getMessageRecommendations(Connection sql, int mid) {
+ ArrayList users = new ArrayList();
+
+ PreparedStatement stmt = null;
+ ResultSet rs = null;
+ try {
+ stmt = sql.prepareStatement("SELECT users.nick FROM favorites INNER JOIN users ON (favorites.message_id=? AND favorites.user_id=users.id)");
+ stmt.setInt(1, mid);
+ rs = stmt.executeQuery();
+ rs.beforeFirst();
+ while (rs.next()) {
+ users.add(rs.getString(1));
+ }
+ } catch (SQLException e) {
+ System.err.println(e);
+ } finally {
+ Utils.finishSQL(rs, stmt);
+ }
+
+ return users;
+ }
+
+ public static ArrayList getAll(Connection sql, int visitor_uid, int before) {
+ ArrayList mids = new ArrayList(20);
+
+ PreparedStatement stmt = null;
+ ResultSet rs = null;
+ try {
+ if (visitor_uid > 1) {
+ if (before > 0) {
+ stmt = sql.prepareStatement("SELECT message_id FROM messages WHERE message_id AND hidden=0 AND (privacy>0 OR user_id=?) AND user_id NOT IN (SELECT bl_user_id FROM bl_users WHERE user_id=?) ORDER BY message_id DESC LIMIT 20");
+ stmt.setInt(1, before);
+ stmt.setInt(2, visitor_uid);
+ stmt.setInt(3, visitor_uid);
+ } else {
+ stmt = sql.prepareStatement("SELECT message_id FROM messages WHERE hidden=0 AND (privacy>0 OR user_id=?) AND user_id NOT IN (SELECT bl_user_id FROM bl_users WHERE user_id=?) ORDER BY message_id DESC LIMIT 20");
+ stmt.setInt(1, visitor_uid);
+ stmt.setInt(2, visitor_uid);
+ }
+ } else {
+ if (before > 0) {
+ stmt = sql.prepareStatement("SELECT message_id FROM messages WHERE message_id AND hidden=0 AND privacy>0 ORDER BY message_id DESC LIMIT 20");
+ stmt.setInt(1, before);
+ } else {
+ stmt = sql.prepareStatement("SELECT message_id FROM messages WHERE hidden=0 AND privacy>0 ORDER BY message_id DESC LIMIT 20");
+ }
+
+ }
+ rs = stmt.executeQuery();
+ rs.beforeFirst();
+ while (rs.next()) {
+ mids.add(rs.getInt(1));
+ }
+ } catch (SQLException e) {
+ System.err.println(e);
+ } finally {
+ Utils.finishSQL(rs, stmt);
+ }
+ return mids;
+ }
+
+ public static ArrayList getTag(Connection sql, int tid, int visitor_uid, int before, int cnt) {
+ ArrayList mids = new ArrayList(20);
+
+ PreparedStatement stmt = null;
+ ResultSet rs = null;
+ try {
+ if (before > 0) {
+// stmt = sql.prepareStatement("SELECT messages.message_id FROM messages_tags INNER JOIN messages USING(message_id) WHERE messages_tags.tag_id IN (SELECT tag_id FROM tags WHERE tag_id=? OR synonym_id=?) AND messages.message_id AND (messages.privacy>0 OR messages.user_id=?) ORDER BY messages.message_id DESC LIMIT ?");
+ stmt = sql.prepareStatement("SELECT message_id FROM (tags INNER JOIN messages_tags ON ((tags.synonym_id=? OR tags.tag_id=?) AND tags.tag_id=messages_tags.tag_id)) INNER JOIN messages USING(message_id) WHERE messages.message_id AND (messages.privacy>0 OR messages.user_id=?) ORDER BY message_id DESC LIMIT ?");
+ stmt.setInt(1, tid);
+ stmt.setInt(2, tid);
+ stmt.setInt(3, before);
+ stmt.setInt(4, visitor_uid);
+ stmt.setInt(5, cnt);
+ } else {
+ //stmt = sql.prepareStatement("SELECT messages.message_id FROM messages_tags INNER JOIN messages USING(message_id) WHERE messages_tags.tag_id IN (SELECT tag_id FROM tags WHERE tag_id=? OR synonym_id=?) AND (messages.privacy>0 OR messages.user_id=?) ORDER BY messages.message_id DESC LIMIT ?");
+ stmt = sql.prepareStatement("SELECT message_id FROM (tags INNER JOIN messages_tags ON ((tags.synonym_id=? OR tags.tag_id=?) AND tags.tag_id=messages_tags.tag_id)) INNER JOIN messages USING(message_id) WHERE messages.privacy>0 OR messages.user_id=? ORDER BY message_id DESC LIMIT ?");
+ stmt.setInt(1, tid);
+ stmt.setInt(2, tid);
+ stmt.setInt(3, visitor_uid);
+ stmt.setInt(4, cnt);
+ }
+ rs = stmt.executeQuery();
+ rs.beforeFirst();
+ while (rs.next()) {
+ mids.add(rs.getInt(1));
+ }
+ } catch (SQLException e) {
+ System.err.println(e);
+ } finally {
+ Utils.finishSQL(rs, stmt);
+ }
+ return mids;
+ }
+
+ public static ArrayList getTags(Connection sql, String tids, int visitor_uid, int before, int cnt) {
+ ArrayList mids = new ArrayList(20);
+
+ PreparedStatement stmt = null;
+ ResultSet rs = null;
+ try {
+ if (before > 0) {
+ stmt = sql.prepareStatement("SELECT messages.message_id FROM messages_tags INNER JOIN messages USING(message_id) WHERE messages_tags.tag_id IN (" + tids + ") AND messages.message_id AND (messages.privacy>0 OR messages.user_id=?) ORDER BY messages.message_id DESC LIMIT ?");
+ stmt.setInt(1, before);
+ stmt.setInt(2, visitor_uid);
+ stmt.setInt(3, cnt);
+ } else {
+ stmt = sql.prepareStatement("SELECT messages.message_id FROM messages_tags INNER JOIN messages USING(message_id) WHERE messages_tags.tag_id IN (" + tids + ") AND (messages.privacy>0 OR messages.user_id=?) ORDER BY messages.message_id DESC LIMIT ?");
+ stmt.setInt(1, visitor_uid);
+ stmt.setInt(2, cnt);
+ }
+ rs = stmt.executeQuery();
+ rs.beforeFirst();
+ while (rs.next()) {
+ mids.add(rs.getInt(1));
+ }
+ } catch (SQLException e) {
+ System.err.println(e);
+ } finally {
+ Utils.finishSQL(rs, stmt);
+ }
+ return mids;
+ }
+
+ public static ArrayList getPlace(Connection sql, int place_id, int visitor_uid, int before) {
+ ArrayList mids = new ArrayList(20);
+
+ PreparedStatement stmt = null;
+ ResultSet rs = null;
+ try {
+ if (before > 0) {
+ stmt = sql.prepareStatement("SELECT message_id FROM messages WHERE place_id=? AND message_id AND (privacy>0 OR user_id=?) ORDER BY message_id DESC LIMIT 20");
+ stmt.setInt(1, place_id);
+ stmt.setInt(2, before);
+ stmt.setInt(3, visitor_uid);
+ } else {
+ stmt = sql.prepareStatement("SELECT message_id FROM messages WHERE place_id=? AND (privacy>0 OR user_id=?) ORDER BY message_id DESC LIMIT 20");
+ stmt.setInt(1, place_id);
+ stmt.setInt(2, visitor_uid);
+ }
+ rs = stmt.executeQuery();
+ rs.beforeFirst();
+ while (rs.next()) {
+ mids.add(rs.getInt(1));
+ }
+ } catch (SQLException e) {
+ System.err.println(e);
+ } finally {
+ Utils.finishSQL(rs, stmt);
+ }
+ return mids;
+ }
+
+ public static ArrayList getMyFeed(Connection sql, int uid, int before) {
+ ArrayList mids = new ArrayList(40);
+ PreparedStatement stmt = null;
+ ResultSet rs = null;
+ try {
+ if (before > 0) {
+ stmt = sql.prepareStatement("SELECT message_id FROM messages INNER JOIN subscr_users ON (subscr_users.suser_id=? AND subscr_users.user_id=messages.user_id) WHERE message_id AND (privacy>=0 OR (privacy>=-2 AND privacy<=-1 AND messages.user_id IN (SELECT user_id FROM wl_users WHERE wl_user_id=?))) ORDER BY message_id DESC LIMIT 20");
+ stmt.setInt(1, uid);
+ stmt.setInt(2, before);
+ stmt.setInt(3, uid);
+ } else {
+ stmt = sql.prepareStatement("SELECT message_id FROM messages INNER JOIN subscr_users ON (subscr_users.suser_id=? AND subscr_users.user_id=messages.user_id) WHERE (privacy>=0 OR (privacy>=-2 AND privacy<=-1 AND messages.user_id IN (SELECT user_id FROM wl_users WHERE wl_user_id=?))) ORDER BY message_id DESC LIMIT 20");
+ stmt.setInt(1, uid);
+ stmt.setInt(2, uid);
+ }
+ rs = stmt.executeQuery();
+ rs.beforeFirst();
+ while (rs.next()) {
+ mids.add(rs.getInt(1));
+ }
+ } catch (SQLException e) {
+ System.err.println(e);
+ } finally {
+ Utils.finishSQL(rs, stmt);
+ }
+
+ try {
+ if (before > 0) {
+ stmt = sql.prepareStatement("SELECT message_id FROM messages WHERE user_id=? AND message_id ORDER BY message_id DESC LIMIT 20");
+ stmt.setInt(1, uid);
+ stmt.setInt(2, before);
+ } else {
+ stmt = sql.prepareStatement("SELECT message_id FROM messages WHERE user_id=? ORDER BY message_id DESC LIMIT 20");
+ stmt.setInt(1, uid);
+ }
+ rs = stmt.executeQuery();
+ rs.beforeFirst();
+ while (rs.next()) {
+ mids.add(rs.getInt(1));
+ }
+ } catch (SQLException e) {
+ System.err.println(e);
+ } finally {
+ Utils.finishSQL(rs, stmt);
+ }
+
+ Collections.sort(mids, Collections.reverseOrder());
+ int remove = mids.size() - 20;
+ for (int i = 0; i < remove; i++) {
+ mids.remove(20);
+ }
+
+ return mids;
+ }
+
+ public static ArrayList getPrivate(Connection sql, int uid, int before) {
+ ArrayList mids = new ArrayList(20);
+
+ PreparedStatement stmt = null;
+ ResultSet rs = null;
+ try {
+ if (before > 0) {
+ stmt = sql.prepareStatement("SELECT message_id FROM messages WHERE user_id=? AND privacy<0 AND message_id ORDER BY message_id DESC LIMIT 20");
+ stmt.setInt(1, uid);
+ stmt.setInt(2, before);
+ } else {
+ stmt = sql.prepareStatement("SELECT message_id FROM messages WHERE user_id=? AND privacy<0 ORDER BY message_id DESC LIMIT 20");
+ stmt.setInt(1, uid);
+ }
+ rs = stmt.executeQuery();
+ rs.beforeFirst();
+ while (rs.next()) {
+ mids.add(rs.getInt(1));
+ }
+ } catch (SQLException e) {
+ System.err.println(e);
+ } finally {
+ Utils.finishSQL(rs, stmt);
+ }
+ return mids;
+ }
+
+ public static ArrayList getDiscussions(Connection sql, int uid, int before) {
+ ArrayList mids = new ArrayList(20);
+
+ PreparedStatement stmt = null;
+ ResultSet rs = null;
+ try {
+ if (before > 0) {
+ stmt = sql.prepareStatement("SELECT message_id FROM subscr_messages WHERE suser_id=? AND message_id ORDER BY message_id DESC LIMIT 20");
+ stmt.setInt(1, uid);
+ stmt.setInt(2, before);
+ } else {
+ stmt = sql.prepareStatement("SELECT message_id FROM subscr_messages WHERE suser_id=? ORDER BY message_id DESC LIMIT 20");
+ stmt.setInt(1, uid);
+ }
+ rs = stmt.executeQuery();
+ rs.beforeFirst();
+ while (rs.next()) {
+ mids.add(rs.getInt(1));
+ }
+ } catch (SQLException e) {
+ System.err.println(e);
+ } finally {
+ Utils.finishSQL(rs, stmt);
+ }
+
+ return mids;
+ }
+
+ public static ArrayList getRecommended(Connection sql, int uid, int before) {
+ ArrayList mids = new ArrayList(20);
+
+ PreparedStatement stmt = null;
+ ResultSet rs = null;
+ try {
+ if (before > 0) {
+ stmt = sql.prepareStatement("SELECT message_id FROM favorites WHERE user_id IN (SELECT user_id FROM subscr_users WHERE suser_id=?) AND message_id ORDER BY message_id DESC LIMIT 20");
+ stmt.setInt(1, uid);
+ stmt.setInt(2, before);
+ } else {
+ stmt = sql.prepareStatement("SELECT message_id FROM favorites WHERE user_id IN (SELECT user_id FROM subscr_users WHERE suser_id=?) ORDER BY message_id DESC LIMIT 20");
+ stmt.setInt(1, uid);
+ }
+ rs = stmt.executeQuery();
+ rs.beforeFirst();
+ while (rs.next()) {
+ mids.add(rs.getInt(1));
+ }
+ } catch (SQLException e) {
+ System.err.println(e);
+ } finally {
+ Utils.finishSQL(rs, stmt);
+ }
+
+
+ return mids;
+ }
+
+ public static ArrayList getPopular(Connection sql, int before) {
+ ArrayList mids = new ArrayList(20);
+
+ PreparedStatement stmt = null;
+ ResultSet rs = null;
+ try {
+ if (before > 0) {
+ stmt = sql.prepareStatement("SELECT message_id FROM messages WHERE message_id AND privacy>0 AND popular>0 ORDER BY message_id DESC LIMIT 20");
+ stmt.setInt(1, before);
+ } else {
+ stmt = sql.prepareStatement("SELECT message_id FROM messages WHERE privacy>0 AND popular>0 ORDER BY message_id DESC LIMIT 20");
+ }
+ rs = stmt.executeQuery();
+ rs.beforeFirst();
+ while (rs.next()) {
+ mids.add(rs.getInt(1));
+ }
+ } catch (SQLException e) {
+ System.err.println(e);
+ } finally {
+ Utils.finishSQL(rs, stmt);
+ }
+ return mids;
+ }
+
+ public static ArrayList getPhotos(Connection sql, int visitor_uid, int before) {
+ ArrayList mids = new ArrayList(20);
+
+ PreparedStatement stmt = null;
+ ResultSet rs = null;
+ try {
+ if (before > 0) {
+ stmt = sql.prepareStatement("SELECT message_id FROM messages WHERE message_id AND (privacy>0 OR user_id=?) AND attach IS NOT NULL ORDER BY message_id DESC LIMIT 20");
+ stmt.setInt(1, before);
+ stmt.setInt(2, visitor_uid);
+ } else {
+ stmt = sql.prepareStatement("SELECT message_id FROM messages WHERE (privacy>0 OR user_id=?) AND attach IS NOT NULL ORDER BY message_id DESC LIMIT 20");
+ stmt.setInt(1, visitor_uid);
+ }
+ rs = stmt.executeQuery();
+ rs.beforeFirst();
+ while (rs.next()) {
+ mids.add(rs.getInt(1));
+ }
+ } catch (SQLException e) {
+ System.err.println(e);
+ } finally {
+ Utils.finishSQL(rs, stmt);
+ }
+ return mids;
+ }
+
+ public static ArrayList getSearch(Connection sql, Connection sqlSearch, String search, int before) {
+ ArrayList mids0 = new ArrayList(20);
+
+ PreparedStatement stmt = null;
+ ResultSet rs = null;
+ try {
+ if (before > 0) {
+ stmt = sqlSearch.prepareStatement("SELECT id AS message_id FROM messages WHERE MATCH(?) AND id ORDER BY id DESC LIMIT 25");
+ stmt.setString(1, search);
+ stmt.setInt(2, before);
+ } else {
+ stmt = sqlSearch.prepareStatement("SELECT id AS message_id FROM messages WHERE MATCH(?) ORDER BY id DESC LIMIT 25");
+ stmt.setString(1, search);
+ }
+ rs = stmt.executeQuery();
+ rs.beforeFirst();
+ while (rs.next()) {
+ mids0.add(rs.getInt(1));
+ }
+ } catch (SQLException e) {
+ System.err.println(e);
+ } finally {
+ Utils.finishSQL(rs, stmt);
+ }
+
+ ArrayList 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");
+ rs = stmt.executeQuery();
+ rs.beforeFirst();
+ while (rs.next()) {
+ mids.add(rs.getInt(1));
+ }
+ } catch (SQLException e) {
+ System.err.println(e);
+ } finally {
+ Utils.finishSQL(rs, stmt);
+ }
+ }
+
+ return mids;
+ }
+
+ public static ArrayList getUserBlog(Connection sql, int UID, int privacy, int before) {
+ ArrayList mids = new ArrayList(20);
+
+ PreparedStatement stmt = null;
+ ResultSet rs = null;
+ try {
+ if (before > 0) {
+ stmt = sql.prepareStatement("SELECT message_id FROM messages WHERE user_id=? AND message_id AND privacy>=" + privacy + " ORDER BY message_id DESC LIMIT 20");
+ stmt.setInt(1, UID);
+ stmt.setInt(2, before);
+ } else {
+ stmt = sql.prepareStatement("SELECT message_id FROM messages WHERE user_id=? AND privacy>=" + privacy + " ORDER BY message_id DESC LIMIT 20");
+ stmt.setInt(1, UID);
+ }
+ rs = stmt.executeQuery();
+ rs.beforeFirst();
+ while (rs.next()) {
+ mids.add(rs.getInt(1));
+ }
+ } catch (SQLException e) {
+ System.err.println(e);
+ } finally {
+ Utils.finishSQL(rs, stmt);
+ }
+ return mids;
+ }
+
+ public static ArrayList getUserTag(Connection sql, int UID, int TID, int privacy, int before) {
+ ArrayList mids = new ArrayList(20);
+
+ PreparedStatement stmt = null;
+ ResultSet rs = null;
+ try {
+ if (before > 0) {
+ stmt = sql.prepareStatement("SELECT messages.message_id FROM messages_tags INNER JOIN messages USING(message_id) WHERE messages.user_id=? AND messages_tags.tag_id=? AND messages.message_id AND messages.privacy>=" + privacy + " ORDER BY messages.message_id DESC LIMIT 20");
+ stmt.setInt(1, UID);
+ stmt.setInt(2, TID);
+ stmt.setInt(3, before);
+ } else {
+ stmt = sql.prepareStatement("SELECT messages.message_id FROM messages_tags INNER JOIN messages USING(message_id) WHERE messages.user_id=? AND messages_tags.tag_id=? AND messages.privacy>=" + privacy + " ORDER BY messages.message_id DESC LIMIT 20");
+ stmt.setInt(1, UID);
+ stmt.setInt(2, TID);
+ }
+ rs = stmt.executeQuery();
+ rs.beforeFirst();
+ while (rs.next()) {
+ mids.add(rs.getInt(1));
+ }
+ } catch (SQLException e) {
+ System.err.println(e);
+ } finally {
+ Utils.finishSQL(rs, stmt);
+ }
+ return mids;
+ }
+
+ public static ArrayList getUserRecommendations(Connection sql, int UID, int before) {
+ ArrayList mids = new ArrayList(20);
+
+ PreparedStatement stmt = null;
+ ResultSet rs = null;
+ try {
+ if (before > 0) {
+ stmt = sql.prepareStatement("SELECT message_id FROM favorites WHERE user_id=? AND message_id ORDER BY message_id DESC LIMIT 20");
+ stmt.setInt(1, UID);
+ stmt.setInt(2, before);
+ } else {
+ stmt = sql.prepareStatement("SELECT message_id FROM favorites WHERE user_id=? ORDER BY message_id DESC LIMIT 20");
+ stmt.setInt(1, UID);
+ }
+ rs = stmt.executeQuery();
+ rs.beforeFirst();
+ while (rs.next()) {
+ mids.add(rs.getInt(1));
+ }
+ } catch (SQLException e) {
+ System.err.println(e);
+ } finally {
+ Utils.finishSQL(rs, stmt);
+ }
+ return mids;
+ }
+
+ public static ArrayList getUserPhotos(Connection sql, int UID, int privacy, int before) {
+ ArrayList mids = new ArrayList(20);
+
+ PreparedStatement stmt = null;
+ ResultSet rs = null;
+ try {
+ if (before > 0) {
+ stmt = sql.prepareStatement("SELECT message_id FROM messages WHERE user_id=? AND message_id AND privacy>=" + privacy + " AND attach IS NOT NULL ORDER BY message_id DESC LIMIT 20");
+ stmt.setInt(1, UID);
+ stmt.setInt(2, before);
+ } else {
+ stmt = sql.prepareStatement("SELECT message_id FROM messages WHERE user_id=? AND privacy>=" + privacy + " AND attach IS NOT NULL ORDER BY message_id DESC LIMIT 20");
+ stmt.setInt(1, UID);
+ }
+ rs = stmt.executeQuery();
+ rs.beforeFirst();
+ while (rs.next()) {
+ mids.add(rs.getInt(1));
+ }
+ } catch (SQLException e) {
+ System.err.println(e);
+ } finally {
+ Utils.finishSQL(rs, stmt);
+ }
+ return mids;
+ }
+
+ public static ArrayList getUserSearch(Connection sql, Connection sqlSearch, int UID, String search, int privacy, int before) {
+ ArrayList mids0 = new ArrayList(20);
+
+ PreparedStatement stmt = null;
+ ResultSet rs = null;
+ try {
+ if (before > 0) {
+ stmt = sqlSearch.prepareStatement("SELECT id AS message_id FROM messages WHERE user_id=? AND MATCH(?) AND id ORDER BY id DESC LIMIT 20");
+ stmt.setInt(1, UID);
+ stmt.setString(2, search);
+ stmt.setInt(3, before);
+ } else {
+ stmt = sqlSearch.prepareStatement("SELECT id AS message_id FROM messages WHERE user_id=? AND MATCH(?) ORDER BY id DESC LIMIT 20");
+ stmt.setInt(1, UID);
+ stmt.setString(2, search);
+ }
+ rs = stmt.executeQuery();
+ rs.beforeFirst();
+ while (rs.next()) {
+ mids0.add(rs.getInt(1));
+ }
+ } catch (SQLException e) {
+ System.err.println(e);
+ } finally {
+ Utils.finishSQL(rs, stmt);
+ }
+
+ ArrayList 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");
+ rs = stmt.executeQuery();
+ rs.beforeFirst();
+ while (rs.next()) {
+ mids.add(rs.getInt(1));
+ }
+ } catch (SQLException e) {
+ System.err.println(e);
+ } finally {
+ Utils.finishSQL(rs, stmt);
+ }
+ }
+
+ return mids;
+ }
+
+ public static ArrayList getMessages(Connection sql, ArrayList mids) {
+ ArrayList msgs = new ArrayList(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()),DATE_FORMAT(messages.ts,'%Y-%m-%d %H:%i:%s'),messages.replies,messages_txt.repliesby,messages.attach,messages.lat,messages.lon,messages.likes FROM (messages INNER JOIN messages_txt ON messages.message_id=messages_txt.message_id) INNER JOIN users ON messages.user_id=users.id WHERE messages.message_id IN (" + Utils.convertArrayInt2String(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);
+ if (rs.getString(4) != null) {
+ msg.parseTags(rs.getString(4));
+ }
+ msg.ReadOnly = rs.getInt(5) == 1;
+ msg.Privacy = rs.getInt(6);
+ msg.FriendsOnly = msg.Privacy < 0;
+ 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.getDouble(13) != 0) {
+ msg.Place = new com.juick.Place();
+ msg.Place.lat = rs.getDouble(13);
+ msg.Place.lon = rs.getDouble(14);
+ }
+ msg.Likes = rs.getInt(15);
+
+ msgs.add(msg);
+ }
+ } catch (SQLException e) {
+ System.err.println(e);
+ } finally {
+ Utils.finishSQL(rs, stmt);
+ }
+
+ return msgs;
+ }
+
+ public static ArrayList getReplies(Connection sql, int mid) {
+ ArrayList replies = new ArrayList();
+
+ PreparedStatement stmt = null;
+ ResultSet rs = null;
+ try {
+ stmt = sql.prepareStatement("SELECT replies.reply_id,replies.replyto,replies.user_id,users.nick,users.banned,replies.txt,TIMESTAMPDIFF(MINUTE,replies.ts,NOW()),DATE_FORMAT(replies.ts,'%Y-%m-%d %H:%i:%s'),replies.attach FROM replies INNER JOIN users ON replies.user_id=users.id WHERE replies.message_id=? ORDER BY replies.reply_id ASC");
+ stmt.setInt(1, mid);
+ rs = stmt.executeQuery();
+ rs.beforeFirst();
+ while (rs.next()) {
+ com.juick.Message msg = new com.juick.Message();
+ msg.MID = mid;
+ msg.RID = rs.getInt(1);
+ msg.ReplyTo = rs.getInt(2);
+ msg.User = new com.juick.User();
+ msg.User.UID = rs.getInt(3);
+ msg.User.UName = rs.getString(4);
+ msg.User.Banned = rs.getBoolean(5);
+ msg.Text = rs.getString(6);
+ msg.TimeAgo = rs.getInt(7);
+ msg.TimestampString = rs.getString(8);
+ msg.AttachmentType = rs.getString(9);
+
+ replies.add(msg);
+ }
+ } catch (SQLException e) {
+ System.err.println(e);
+ } finally {
+ Utils.finishSQL(rs, stmt);
+ }
+
+ return replies;
+ }
+
+ public static boolean setMessagePopular(Connection sql, int mid, int popular) {
+ boolean ret = false;
+
+ PreparedStatement stmt = null;
+ try {
+ if (popular == -2) {
+ stmt = sql.prepareStatement("UPDATE messages SET hidden=1 WHERE message_id=?");
+ stmt.setInt(1, mid);
+ } else if (popular == -1) {
+ stmt = sql.prepareStatement("UPDATE messages SET popular=0 WHERE message_id=?");
+ stmt.setInt(1, mid);
+ } else {
+ stmt = sql.prepareStatement("UPDATE messages SET popular=? WHERE message_id=?");
+ stmt.setInt(1, popular);
+ stmt.setInt(2, mid);
+ }
+ ret = stmt.executeUpdate() > 0;
+ } catch (SQLException e) {
+ System.err.println(e);
+ } finally {
+ Utils.finishSQL(null, stmt);
+ }
+
+ if (popular == -1) {
+ try {
+ stmt = sql.prepareStatement("INSERT INTO top_ignore_messages VALUES (?)");
+ stmt.setInt(1, mid);
+ stmt.executeUpdate();
+ } catch (SQLException e) {
+ System.err.println(e);
+ } finally {
+ Utils.finishSQL(null, stmt);
+ }
+ }
+
+ return ret;
+ }
+
+ public static boolean setMessagePrivacy(Connection sql, int mid) {
+ boolean ret = false;
+
+ PreparedStatement stmt = null;
+ try {
+ stmt = sql.prepareStatement("UPDATE messages SET privacy=1 WHERE message_id=?");
+ stmt.setInt(1, mid);
+ ret = stmt.executeUpdate() > 0;
+ } catch (SQLException e) {
+ System.err.println(e);
+ } finally {
+ Utils.finishSQL(null, stmt);
+ }
+
+ return ret;
+ }
+}
diff --git a/src/main/java/com/juick/server/PMQueries.java b/src/main/java/com/juick/server/PMQueries.java
new file mode 100644
index 00000000..56b91abf
--- /dev/null
+++ b/src/main/java/com/juick/server/PMQueries.java
@@ -0,0 +1,303 @@
+/*
+ * Juick
+ * Copyright (C) 2008-2011, Ugnich Anton
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see .
+ */
+package com.juick.server;
+
+import java.sql.Connection;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.util.ArrayList;
+
+/**
+ *
+ * @author Ugnich Anton
+ */
+public class PMQueries {
+
+ public static boolean createPM(Connection sql, int uid_from, int uid_to, String body) {
+ boolean ret = false;
+ PreparedStatement stmt = null;
+ try {
+ stmt = sql.prepareStatement("INSERT INTO pm(user_id,user_id_to,txt) VALUES (?,?,?)");
+ stmt.setInt(1, uid_from);
+ stmt.setInt(2, uid_to);
+ stmt.setString(3, body);
+ ret = stmt.executeUpdate() > 0;
+ } catch (SQLException e) {
+ System.err.println(e);
+ } finally {
+ Utils.finishSQL(null, stmt);
+ }
+
+ if (ret) {
+ PreparedStatement stmt2 = null;
+ try {
+ stmt2 = sql.prepareStatement("INSERT INTO pm_streams(user_id,user_id_to,lastmessage,unread) VALUES (?,?,NOW(),1) ON DUPLICATE KEY UPDATE lastmessage=NOW(),unread=unread+1");
+ stmt2.setInt(1, uid_from);
+ stmt2.setInt(2, uid_to);
+ stmt2.executeUpdate();
+ } catch (SQLException e) {
+ System.err.println(e);
+ } finally {
+ Utils.finishSQL(null, stmt2);
+ }
+ }
+
+ 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();
+
+ PreparedStatement stmt = null;
+ ResultSet rs = null;
+ try {
+ stmt = sql.prepareStatement("SELECT user_id,unread FROM pm_streams WHERE user_id_to=? AND unread>0 ORDER BY lastmessage DESC LIMIT " + cnt);
+ stmt.setInt(1, uid);
+ rs = stmt.executeQuery();
+ rs.beforeFirst();
+ while (rs.next()) {
+ com.juick.User u = new com.juick.User();
+ u.UID = rs.getInt(1);
+ u.MessagesCount = rs.getInt(2);
+ users.add(u);
+ }
+ } catch (SQLException e) {
+ System.err.println(e);
+ } finally {
+ Utils.finishSQL(rs, stmt);
+ }
+
+ if (users.size() < cnt) {
+ try {
+ stmt = sql.prepareStatement("SELECT user_id,user_id_to FROM pm_streams WHERE (user_id=? OR user_id_to=?) AND lastmessage>TIMESTAMPADD(MONTH,-1,NOW()) ORDER BY lastmessage DESC LIMIT ?");
+ stmt.setInt(1, uid);
+ stmt.setInt(2, uid);
+ stmt.setInt(3, cnt * 2);
+ rs = stmt.executeQuery();
+ rs.beforeFirst();
+ while (rs.next()) {
+ int uuid = rs.getInt(1) + rs.getInt(2) - uid;
+ if (!haveUserInArray(users, uuid)) {
+ com.juick.User u = new com.juick.User();
+ u.UID = uuid;
+ users.add(u);
+ if (users.size() >= cnt) {
+ break;
+ }
+ }
+ }
+ } catch (SQLException e) {
+ System.err.println(e);
+ } finally {
+ Utils.finishSQL(rs, stmt);
+ }
+ }
+
+ if (!users.isEmpty()) {
+ UserQueries.fillUsersByID(sql, users);
+ }
+
+ return users;
+ }
+
+ public static boolean haveUserInArray(ArrayList arr, int uid) {
+ int s = arr.size();
+ for (int i = 0; i < s; i++) {
+ if (arr.get(i).UID == uid) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ public static ArrayList getPMMessages(Connection sql, int uid, int uid_to) {
+ ArrayList msgs = new ArrayList(20);
+
+ PreparedStatement stmt = null;
+ ResultSet rs = null;
+ try {
+ stmt = sql.prepareStatement("SELECT user_id,txt,ts FROM pm WHERE (user_id=? AND user_id_to=?) OR (user_id_to=? AND user_id=?) ORDER BY ts DESC LIMIT 20");
+ stmt.setInt(1, uid);
+ stmt.setInt(2, uid_to);
+ stmt.setInt(3, uid);
+ stmt.setInt(4, uid_to);
+ rs = stmt.executeQuery();
+ rs.beforeFirst();
+ while (rs.next()) {
+ com.juick.Message msg = new com.juick.Message();
+ int uuid = rs.getInt(1);
+ msg.User = new com.juick.User();
+ msg.User.UID = uuid;
+ msg.Text = rs.getString(2);
+ msg.TimestampString = rs.getString(3);
+ msgs.add(0, msg);
+ }
+ } catch (SQLException e) {
+ System.err.println(e);
+ } finally {
+ Utils.finishSQL(rs, stmt);
+ }
+
+ PreparedStatement stmt2 = null;
+ try {
+ stmt2 = sql.prepareStatement("UPDATE pm_streams SET lastview=NOW(),unread=0 WHERE user_id_to=? AND user_id=?");
+ stmt2.setInt(1, uid);
+ stmt2.setInt(2, uid_to);
+ stmt2.executeUpdate();
+ } catch (SQLException e) {
+ System.err.println(e);
+ } finally {
+ Utils.finishSQL(null, stmt2);
+ }
+
+ return msgs;
+ }
+
+ public static ArrayList getLastPMInbox(Connection sql, int uid) {
+ ArrayList msgs = new ArrayList(20);
+
+ PreparedStatement stmt = null;
+ ResultSet rs = null;
+ try {
+ stmt = sql.prepareStatement("SELECT pm.user_id,users.nick,pm.txt,TIMESTAMPDIFF(MINUTE,pm.ts,NOW()),DATE_FORMAT(pm.ts,'%Y-%m-%d %H:%i:%s') FROM pm INNER JOIN users ON pm.user_id=users.id WHERE pm.user_id_to=? ORDER BY pm.ts DESC LIMIT 20");
+ stmt.setInt(1, uid);
+ rs = stmt.executeQuery();
+ rs.beforeFirst();
+ while (rs.next()) {
+ com.juick.Message msg = new com.juick.Message();
+ msg.User = new com.juick.User();
+ msg.User.UID = rs.getInt(1);
+ msg.User.UName = rs.getString(2);
+ msg.Text = rs.getString(3);
+ msg.TimeAgo = rs.getInt(4);
+ msg.TimestampString = rs.getString(5);
+ msgs.add(0, msg);
+ }
+ } catch (SQLException e) {
+ System.err.println(e);
+ } finally {
+ Utils.finishSQL(rs, stmt);
+ }
+
+ return msgs;
+ }
+
+ public static ArrayList getLastPMSent(Connection sql, int uid) {
+ ArrayList msgs = new ArrayList(20);
+
+ PreparedStatement stmt = null;
+ ResultSet rs = null;
+ try {
+ stmt = sql.prepareStatement("SELECT pm.user_id_to,users.nick,pm.txt,TIMESTAMPDIFF(MINUTE,pm.ts,NOW()),DATE_FORMAT(pm.ts,'%Y-%m-%d %H:%i:%s') FROM pm INNER JOIN users ON pm.user_id_to=users.id WHERE pm.user_id=? ORDER BY pm.ts DESC LIMIT 20");
+ stmt.setInt(1, uid);
+ rs = stmt.executeQuery();
+ rs.beforeFirst();
+ while (rs.next()) {
+ com.juick.Message msg = new com.juick.Message();
+ msg.User = new com.juick.User();
+ msg.User.UID = rs.getInt(1);
+ msg.User.UName = rs.getString(2);
+ msg.Text = rs.getString(3);
+ msg.TimeAgo = rs.getInt(4);
+ msg.TimestampString = rs.getString(5);
+ msgs.add(0, msg);
+ }
+ } catch (SQLException e) {
+ System.err.println(e);
+ } finally {
+ Utils.finishSQL(rs, stmt);
+ }
+
+ return msgs;
+ }
+}
diff --git a/src/main/java/com/juick/server/PushQueries.java b/src/main/java/com/juick/server/PushQueries.java
new file mode 100644
index 00000000..84f42722
--- /dev/null
+++ b/src/main/java/com/juick/server/PushQueries.java
@@ -0,0 +1,68 @@
+/*
+ * To change this template, choose Tools | Templates
+ * and open the template in the editor.
+ */
+package com.juick.server;
+
+import java.sql.Connection;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.util.ArrayList;
+
+/**
+ *
+ * @author ugnich
+ */
+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();
+
+ PreparedStatement stmt = null;
+ ResultSet rs = null;
+ try {
+ stmt = sql.prepareStatement("SELECT regid FROM android INNER JOIN subscr_users ON (subscr_users.user_id=? AND android.user_id=subscr_users.suser_id)");
+ stmt.setInt(1, uid);
+ rs = stmt.executeQuery();
+ rs.beforeFirst();
+ while (rs.next()) {
+ regids.add(rs.getString(1));
+ }
+ } catch (SQLException e) {
+ System.err.println(e);
+ } finally {
+ Utils.finishSQL(rs, stmt);
+ }
+ 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();
+
+ PreparedStatement stmt = null;
+ ResultSet rs = null;
+ try {
+ stmt = sql.prepareStatement("SELECT url FROM winphone INNER JOIN subscr_users ON (subscr_users.user_id=? AND winphone.user_id=subscr_users.suser_id)");
+ stmt.setInt(1, uid);
+ rs = stmt.executeQuery();
+ rs.beforeFirst();
+ while (rs.next()) {
+ urls.add(rs.getString(1));
+ }
+ } catch (SQLException e) {
+ System.err.println(e);
+ } finally {
+ Utils.finishSQL(rs, stmt);
+ }
+ return urls;
+ }
+}
diff --git a/src/main/java/com/juick/server/SQLHelpers.java b/src/main/java/com/juick/server/SQLHelpers.java
new file mode 100644
index 00000000..f5569993
--- /dev/null
+++ b/src/main/java/com/juick/server/SQLHelpers.java
@@ -0,0 +1,163 @@
+/*
+ * To change this template, choose Tools | Templates
+ * and open the template in the editor.
+ */
+package com.juick.server;
+
+import java.sql.Connection;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.util.ArrayList;
+
+/**
+ *
+ * @author ugnich
+ */
+public class SQLHelpers {
+
+ public static int execute(Connection sql, String query) {
+ int ret = -1;
+ PreparedStatement stmt = null;
+ try {
+ stmt = sql.prepareStatement(query);
+ ret = stmt.executeUpdate();
+ } catch (SQLException e) {
+ System.err.println(e);
+ } finally {
+ Utils.finishSQL(null, stmt);
+ }
+ return ret;
+ }
+
+ public static int executeInt(Connection sql, String query, int param) {
+ int ret = -1;
+ PreparedStatement stmt = null;
+ try {
+ stmt = sql.prepareStatement(query);
+ stmt.setInt(1, param);
+ ret = stmt.executeUpdate();
+ } catch (SQLException e) {
+ System.err.println(e);
+ } finally {
+ Utils.finishSQL(null, stmt);
+ }
+ return ret;
+ }
+
+ public static int getInt(Connection sql, String query, int defvalue) {
+ int ret = defvalue;
+ PreparedStatement stmt = null;
+ ResultSet rs = null;
+ try {
+ stmt = sql.prepareStatement(query);
+ rs = stmt.executeQuery();
+ if (rs.first()) {
+ ret = rs.getInt(1);
+ }
+ } catch (SQLException e) {
+ System.err.println(e);
+ } finally {
+ Utils.finishSQL(rs, stmt);
+ }
+ return ret;
+ }
+
+ public static int getInt(Connection sql, String query, int param, int defvalue) {
+ int ret = defvalue;
+ PreparedStatement stmt = null;
+ ResultSet rs = null;
+ try {
+ stmt = sql.prepareStatement(query);
+ stmt.setInt(1, param);
+ rs = stmt.executeQuery();
+ if (rs.first()) {
+ ret = rs.getInt(1);
+ }
+ } catch (SQLException e) {
+ System.err.println(e);
+ } finally {
+ Utils.finishSQL(rs, stmt);
+ }
+ return ret;
+ }
+
+ public static int getInt(Connection sql, String query, String param, int defvalue) {
+ int ret = defvalue;
+ PreparedStatement stmt = null;
+ ResultSet rs = null;
+ try {
+ stmt = sql.prepareStatement(query);
+ stmt.setString(1, param);
+ rs = stmt.executeQuery();
+ if (rs.first()) {
+ ret = rs.getInt(1);
+ }
+ } catch (SQLException e) {
+ System.err.println(e);
+ } finally {
+ Utils.finishSQL(rs, stmt);
+ }
+ return ret;
+ }
+
+ public static String getString(Connection sql, String query, int param) {
+ String ret = null;
+ PreparedStatement stmt = null;
+ ResultSet rs = null;
+ try {
+ stmt = sql.prepareStatement(query);
+ stmt.setInt(1, param);
+ 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 String getString(Connection sql, String query, String param) {
+ String ret = null;
+ PreparedStatement stmt = null;
+ ResultSet rs = null;
+ try {
+ stmt = sql.prepareStatement(query);
+ stmt.setString(1, param);
+ 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 getArrayInteger(Connection sql, String query, int param) {
+ ArrayList ret = new ArrayList();
+
+ PreparedStatement stmt = null;
+ ResultSet rs = null;
+ try {
+ stmt = sql.prepareStatement(query);
+ stmt.setInt(1, param);
+ 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;
+ }
+}
diff --git a/src/main/java/com/juick/server/SubscriptionsQueries.java b/src/main/java/com/juick/server/SubscriptionsQueries.java
new file mode 100644
index 00000000..d0f5f308
--- /dev/null
+++ b/src/main/java/com/juick/server/SubscriptionsQueries.java
@@ -0,0 +1,168 @@
+/*
+ * To change this template, choose Tools | Templates
+ * and open the template in the editor.
+ */
+package com.juick.server;
+
+import java.sql.Connection;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.util.ArrayList;
+
+/**
+ *
+ * @author ugnich
+ */
+public class SubscriptionsQueries {
+
+ public static ArrayList getJIDSubscribedToUser(Connection sql, int uid, boolean friendsonly) {
+ ArrayList jids = new ArrayList();
+
+ PreparedStatement stmt = null;
+ ResultSet rs = null;
+ try {
+ if (friendsonly == false) {
+ stmt = sql.prepareStatement("SELECT jids.jid FROM subscr_users INNER JOIN jids ON (subscr_users.user_id=? AND subscr_users.suser_id=jids.user_id) WHERE jids.active=1");
+ stmt.setInt(1, uid);
+ } else {
+ stmt = sql.prepareStatement("SELECT jids.jid FROM subscr_users INNER JOIN jids ON (subscr_users.user_id=? AND subscr_users.suser_id=jids.user_id) WHERE jids.active=1 AND jids.user_id IN (SELECT wl_user_id FROM wl_users WHERE user_id=?)");
+ stmt.setInt(1, uid);
+ stmt.setInt(2, uid);
+ }
+ rs = stmt.executeQuery();
+ rs.beforeFirst();
+ while (rs.next()) {
+ jids.add(rs.getString(1));
+ }
+ } catch (SQLException e) {
+ System.err.println(e);
+ } finally {
+ Utils.finishSQL(rs, stmt);
+ }
+ return jids;
+ }
+
+ public static ArrayList getJIDSubscribedToUserAndTags(Connection sql, int uid, int mid) {
+ ArrayList jids = new ArrayList();
+
+ PreparedStatement stmt = null;
+ ResultSet rs = null;
+
+ String tbl = "subscr_jids_" + mid;
+ ArrayList 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);
+ } finally {
+ Utils.finishSQL(null, stmt);
+ }
+
+ try {
+ String query = "INSERT INTO " + tbl + " SELECT suser_id FROM subscr_users WHERE user_id=" + uid;
+ if (!tags.isEmpty()) {
+ query += " UNION DISTINCT SELECT suser_id FROM subscr_tags WHERE tag_id IN (" + Utils.convertArrayInt2String(tags) + ") AND suser_id!=" + uid;
+ }
+ stmt = sql.prepareStatement(query);
+ stmt.executeUpdate();
+ } catch (SQLException e) {
+ System.err.println(e);
+ } finally {
+ Utils.finishSQL(null, stmt);
+ }
+
+
+ try {
+ String query = "SELECT jids.jid FROM " + tbl + " INNER JOIN jids ON (" + tbl + ".user_id=jids.user_id) WHERE jids.active=1 AND " + tbl + ".user_id NOT IN (SELECT user_id FROM bl_users WHERE bl_user_id=" + uid + ")";
+ if (!tags.isEmpty()) {
+ query += " AND " + tbl + ".user_id NOT IN (SELECT user_id FROM bl_tags WHERE tag_id IN (" + Utils.convertArrayInt2String(tags) + "))";
+ }
+ stmt = sql.prepareStatement(query);
+ rs = stmt.executeQuery();
+ rs.beforeFirst();
+ while (rs.next()) {
+ jids.add(rs.getString(1));
+ }
+ } catch (SQLException e) {
+ System.err.println(e);
+ } finally {
+ Utils.finishSQL(rs, stmt);
+ }
+
+ try {
+ stmt = sql.prepareStatement("DROP TABLE " + tbl);
+ stmt.executeUpdate();
+ } catch (SQLException e) {
+ System.err.println(e);
+ } finally {
+ Utils.finishSQL(null, stmt);
+ }
+
+ return jids;
+ }
+
+ public static ArrayList getJIDSubscribedToComments(Connection sql, int mid, int ignore_uid) {
+ ArrayList jids = new ArrayList();
+
+ PreparedStatement stmt = null;
+ ResultSet rs = null;
+ try {
+ stmt = sql.prepareStatement("SELECT jids.jid FROM subscr_messages INNER JOIN jids ON (subscr_messages.message_id=? AND subscr_messages.suser_id=jids.user_id) WHERE jids.user_id!=? AND jids.active=1");
+ stmt.setInt(1, mid);
+ stmt.setInt(2, ignore_uid);
+ rs = stmt.executeQuery();
+ rs.beforeFirst();
+ while (rs.next()) {
+ jids.add(rs.getString(1));
+ }
+ } catch (SQLException e) {
+ System.err.println(e);
+ } finally {
+ Utils.finishSQL(rs, stmt);
+ }
+ return jids;
+ }
+
+ public static ArrayList getJIDSubscribedToUserRecommendations(Connection sql, int uid, int mid, int muid) {
+ ArrayList jids = new ArrayList();
+
+ ArrayList tags = MessagesQueries.getMessageTagsIDs(sql, mid);
+
+ PreparedStatement stmt = null;
+ ResultSet rs = null;
+ try {
+ String query = "SELECT jid FROM jids WHERE active=1 AND user_id!=" + uid;
+ query += " AND user_id IN (SELECT suser_id FROM subscr_users WHERE user_id=" + uid + ")";
+ query += " AND user_id NOT IN (SELECT user_id FROM bl_users WHERE bl_user_id=" + muid + ")";
+ query += " AND user_id NOT IN (SELECT suser_id FROM subscr_users WHERE user_id=" + muid + ")";
+ query += " AND user_id NOT IN (SELECT suser_id FROM subscr_messages WHERE message_id=" + mid + ")";
+ query += " AND user_id NOT IN (SELECT user_id FROM favorites WHERE message_id=" + mid + ")";
+ query += " AND user_id NOT IN (SELECT subscr_users.suser_id FROM subscr_users INNER JOIN favorites ON (favorites.message_id=" + mid + " AND subscr_users.user_id=favorites.user_id AND favorites.user_id!=" + uid + "))";
+ if (!tags.isEmpty()) {
+ String tagsStr = Utils.convertArrayInt2String(tags);
+ query += " AND user_id NOT IN (SELECT suser_id FROM subscr_tags WHERE tag_id IN (" + tagsStr + "))";
+ query += " AND user_id NOT IN (SELECT user_id FROM bl_tags WHERE tag_id IN (" + tagsStr + "))";
+ }
+
+ stmt = sql.prepareStatement(query);
+ rs = stmt.executeQuery();
+ rs.beforeFirst();
+ while (rs.next()) {
+ jids.add(rs.getString(1));
+ }
+ } catch (SQLException e) {
+ System.err.println(e);
+ } finally {
+ Utils.finishSQL(rs, stmt);
+ }
+
+ return jids;
+ }
+
+ public static boolean subscribeMessage(Connection sql, int mid, int vuid) {
+ return SQLHelpers.execute(sql, "INSERT IGNORE INTO subscr_messages(suser_id,message_id) VALUES (" + vuid + "," + mid + ")") == 1;
+ }
+}
diff --git a/src/main/java/com/juick/server/TagQueries.java b/src/main/java/com/juick/server/TagQueries.java
new file mode 100644
index 00000000..493e8675
--- /dev/null
+++ b/src/main/java/com/juick/server/TagQueries.java
@@ -0,0 +1,189 @@
+/*
+ * Juick
+ * Copyright (C) 2008-2011, Ugnich Anton
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see .
+ */
+package com.juick.server;
+
+import java.sql.Connection;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
+import java.util.ArrayList;
+
+/**
+ *
+ * @author Ugnich Anton
+ */
+public class TagQueries {
+
+ public static com.juick.Tag getTag(Connection sql, int tid) {
+ com.juick.Tag ret = null;
+
+ PreparedStatement stmt = null;
+ ResultSet rs = null;
+ try {
+ stmt = sql.prepareStatement("SELECT synonym_id,name FROM tags WHERE tag_id=?");
+ stmt.setInt(1, tid);
+ rs = stmt.executeQuery();
+ if (rs.first()) {
+ ret = new com.juick.Tag();
+ ret.TID = tid;
+ ret.SynonymID = rs.getInt(1);
+ ret.Name = rs.getString(2);
+ }
+ } catch (SQLException e) {
+ System.err.println(e);
+ } finally {
+ Utils.finishSQL(rs, stmt);
+ }
+
+ return ret;
+ }
+
+ public static com.juick.Tag getTag(Connection sql, String tag, boolean autoCreate) {
+ com.juick.Tag ret = null;
+
+ PreparedStatement stmt = null;
+ ResultSet rs = null;
+ try {
+ stmt = sql.prepareStatement("SELECT tag_id,synonym_id,name FROM tags WHERE name=?");
+ stmt.setString(1, tag);
+ rs = stmt.executeQuery();
+ if (rs.first()) {
+ ret = new com.juick.Tag();
+ ret.TID = rs.getInt(1);
+ ret.SynonymID = rs.getInt(2);
+ ret.Name = rs.getString(3);
+ }
+ } catch (SQLException e) {
+ System.err.println(e);
+ } finally {
+ Utils.finishSQL(rs, stmt);
+ }
+
+ if (ret == null && autoCreate) {
+ ret = new com.juick.Tag();
+ ret.TID = createTag(sql, tag);
+ ret.Name = tag;
+ }
+
+ return ret;
+ }
+
+ public static ArrayList getTags(Connection sql, String[] tags, boolean autoCreate) {
+ ArrayList ret = new ArrayList();
+
+ for (int i = 0; i < tags.length; i++) {
+ if (!tags[i].isEmpty()) {
+ com.juick.Tag t = getTag(sql, tags[i], autoCreate);
+ if (t != null) {
+ ret.add(t);
+ }
+ }
+ }
+
+ return ret;
+ }
+
+ public static boolean getTagNoIndex(Connection sql, int tag_id) {
+ boolean ret = false;
+
+ PreparedStatement stmt = null;
+ ResultSet rs = null;
+ try {
+ stmt = sql.prepareStatement("SELECT noindex FROM tags WHERE tag_id=?");
+ stmt.setInt(1, tag_id);
+ rs = stmt.executeQuery();
+ if (rs.first()) {
+ ret = rs.getInt(1) == 1;
+ }
+ } catch (SQLException e) {
+ System.err.println(e);
+ } finally {
+ Utils.finishSQL(rs, stmt);
+ }
+
+ return ret;
+ }
+
+ public static int createTag(Connection sql, String name) {
+ int ret = 0;
+
+ PreparedStatement stmt = null;
+ ResultSet rs = null;
+ try {
+ stmt = sql.prepareStatement("INSERT INTO tags(name) VALUES (?)", Statement.RETURN_GENERATED_KEYS);
+ stmt.setString(1, name);
+ stmt.executeUpdate();
+ rs = stmt.getGeneratedKeys();
+ if (rs.first()) {
+ ret = rs.getInt(1);
+ }
+ } catch (SQLException e) {
+ System.err.println(e);
+ } finally {
+ Utils.finishSQL(rs, stmt);
+ }
+
+ return ret;
+ }
+
+ public static ArrayList getUserTagsAll(Connection sql, int uid) {
+ ArrayList tags = new ArrayList();
+
+ PreparedStatement stmt = null;
+ ResultSet rs = null;
+ try {
+ stmt = sql.prepareStatement("SELECT tags.name,COUNT(messages.message_id) FROM (messages INNER JOIN messages_tags ON (messages.user_id=? AND messages.message_id=messages_tags.message_id)) INNER JOIN tags ON messages_tags.tag_id=tags.tag_id GROUP BY tags.tag_id ORDER BY tags.name ASC");
+ stmt.setInt(1, uid);
+ rs = stmt.executeQuery();
+ rs.beforeFirst();
+ while (rs.next()) {
+ com.juick.Tag t = new com.juick.Tag();
+ t.Name = rs.getString(1);
+ t.UsageCnt = rs.getInt(2);
+ tags.add(t);
+ }
+ } catch (SQLException e) {
+ System.err.println(e);
+ } finally {
+ Utils.finishSQL(rs, stmt);
+ }
+ return tags;
+ }
+
+ public static ArrayList getUserBLTags(Connection sql, int uid) {
+ ArrayList tags = new ArrayList();
+
+ PreparedStatement stmt = null;
+ ResultSet rs = null;
+ try {
+ stmt = sql.prepareStatement("SELECT tags.name FROM tags INNER JOIN bl_tags ON (bl_tags.user_id=? AND bl_tags.tag_id=tags.tag_id) ORDER BY tags.name");
+ stmt.setInt(1, uid);
+ rs = stmt.executeQuery();
+ rs.beforeFirst();
+ while (rs.next()) {
+ tags.add(rs.getString(1));
+ }
+ } catch (SQLException e) {
+ System.err.println(e);
+ } finally {
+ Utils.finishSQL(rs, stmt);
+ }
+ return tags;
+ }
+}
diff --git a/src/main/java/com/juick/server/UserQueries.java b/src/main/java/com/juick/server/UserQueries.java
new file mode 100644
index 00000000..d1313715
--- /dev/null
+++ b/src/main/java/com/juick/server/UserQueries.java
@@ -0,0 +1,592 @@
+/*
+ * Juick
+ * Copyright (C) 2008-2011, Ugnich Anton
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see .
+ */
+package com.juick.server;
+
+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.Random;
+import java.util.UUID;
+
+/**
+ *
+ * @author Ugnich Anton
+ */
+public class UserQueries {
+
+ static final String ABCDEF = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
+
+ public static String getSignUpHashByJID(Connection sql, String jid) {
+ String hash = SQLHelpers.getString(sql, "SELECT loginhash FROM jids WHERE jid=? AND user_id IS NULL", jid);
+
+ if (hash == null) {
+ hash = UUID.randomUUID().toString();
+ PreparedStatement stmt = null;
+ try {
+ stmt = sql.prepareStatement("INSERT INTO jids(jid,loginhash) VALUES (?,?)");
+ stmt.setString(1, jid);
+ stmt.setString(2, hash);
+ stmt.executeUpdate();
+ } catch (SQLException e) {
+ System.err.println(e);
+ } finally {
+ Utils.finishSQL(null, stmt);
+ }
+ }
+
+ return hash;
+ }
+
+ public static int createUser(Connection sql, String username, String password) {
+ int uid = 0;
+
+ PreparedStatement stmt = null;
+ ResultSet rs = null;
+ try {
+ stmt = sql.prepareStatement("INSERT INTO users(nick,passw) VALUES (?,?)", Statement.RETURN_GENERATED_KEYS);
+ stmt.setString(1, username);
+ stmt.setString(2, password);
+ stmt.executeUpdate();
+ rs = stmt.getGeneratedKeys();
+ if (rs.first()) {
+ uid = rs.getInt(1);
+ }
+ } catch (SQLException e) {
+ System.err.println(e);
+ } finally {
+ Utils.finishSQL(rs, stmt);
+ }
+
+ SQLHelpers.executeInt(sql, "INSERT INTO useroptions(user_id) VALUES (?)", uid);
+ SQLHelpers.executeInt(sql, "INSERT INTO subscr_users(user_id,suser_id) VALUES (2,?)", uid);
+
+ return uid;
+ }
+
+ public static com.juick.User getUserByUID(Connection sql, int uid) {
+ com.juick.User user = null;
+
+ PreparedStatement stmt = null;
+ ResultSet rs = null;
+ try {
+ stmt = sql.prepareStatement("SELECT nick,banned FROM users WHERE id=?");
+ stmt.setInt(1, uid);
+ rs = stmt.executeQuery();
+ if (rs.first()) {
+ user = new com.juick.User();
+ user.UID = uid;
+ user.UName = rs.getString(1);
+ user.Banned = rs.getBoolean(2);
+ }
+ } catch (SQLException e) {
+ System.err.println(e);
+ } finally {
+ Utils.finishSQL(rs, stmt);
+ }
+ return user;
+ }
+
+ public static com.juick.User getUserByName(Connection sql, String username) {
+ com.juick.User user = null;
+
+ PreparedStatement stmt = null;
+ ResultSet rs = null;
+ try {
+ stmt = sql.prepareStatement("SELECT id,nick,banned FROM users WHERE nick=?");
+ stmt.setString(1, username);
+ rs = stmt.executeQuery();
+ if (rs.first()) {
+ user = new com.juick.User();
+ user.UID = rs.getInt(1);
+ user.UName = rs.getString(2);
+ user.Banned = rs.getBoolean(3);
+ }
+ } catch (SQLException e) {
+ System.err.println(e);
+ } finally {
+ Utils.finishSQL(rs, stmt);
+ }
+ 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();
+
+ PreparedStatement stmt = null;
+ ResultSet rs = null;
+ try {
+ stmt = sql.prepareStatement("SELECT id,nick FROM users WHERE nick IN (" + Utils.convertArrayString2String(unames) + ")");
+ rs = stmt.executeQuery();
+ rs.beforeFirst();
+ while (rs.next()) {
+ com.juick.User user = new com.juick.User();
+ user.UID = rs.getInt(1);
+ user.UName = rs.getString(2);
+ users.add(user);
+ }
+ } catch (SQLException e) {
+ System.err.println(e);
+ } finally {
+ Utils.finishSQL(rs, stmt);
+ }
+ return users;
+ }
+
+ public static ArrayList getUsersByID(Connection sql, ArrayList uids) {
+ ArrayList users = new ArrayList();
+
+ PreparedStatement stmt = null;
+ ResultSet rs = null;
+ try {
+ stmt = sql.prepareStatement("SELECT id,nick FROM users WHERE id IN (" + Utils.convertArrayInt2String(uids) + ")");
+ rs = stmt.executeQuery();
+ rs.beforeFirst();
+ while (rs.next()) {
+ com.juick.User u = new com.juick.User();
+ u.UID = rs.getInt(1);
+ u.UName = rs.getString(2);
+ users.add(u);
+ }
+ } catch (SQLException e) {
+ System.err.println(e);
+ } finally {
+ Utils.finishSQL(rs, stmt);
+ }
+
+ return users;
+ }
+
+ public static boolean fillUsersByID(Connection sql, ArrayList users) {
+ boolean ret = false;
+
+ String uids = "";
+ final int usersSize = users.size();
+ for (int i = 0; i < usersSize; i++) {
+ if (i > 0) {
+ uids += ",";
+ }
+ uids += users.get(i).UID;
+ }
+
+ PreparedStatement stmt = null;
+ ResultSet rs = null;
+ try {
+ stmt = sql.prepareStatement("SELECT id,nick FROM users WHERE id IN (" + uids + ")");
+ rs = stmt.executeQuery();
+ rs.beforeFirst();
+ while (rs.next()) {
+ int uid = rs.getInt(1);
+ for (int i = 0; i < usersSize; i++) {
+ if (users.get(i).UID == uid) {
+ users.get(i).UName = rs.getString(2);
+ ret = true;
+ }
+ }
+ }
+ } catch (SQLException e) {
+ System.err.println(e);
+ } finally {
+ Utils.finishSQL(rs, stmt);
+ }
+
+ return ret;
+ }
+
+ public static ArrayList getUsersByJID(Connection sql, ArrayList jids) {
+ ArrayList users = new ArrayList();
+
+ PreparedStatement stmt = null;
+ ResultSet rs = null;
+ try {
+ stmt = sql.prepareStatement("SELECT users.id,users.nick,jids.jid FROM users INNER JOIN jids ON jids.user_id=users.id WHERE jids.jid IN (" + Utils.convertArrayString2String(jids) + ")");
+ rs = stmt.executeQuery();
+ rs.beforeFirst();
+ while (rs.next()) {
+ com.juick.User user = new com.juick.User();
+ user.UID = rs.getInt(1);
+ user.UName = rs.getString(2);
+ user.JID = rs.getString(3);
+ users.add(user);
+ }
+ } catch (SQLException e) {
+ System.err.println(e);
+ } finally {
+ Utils.finishSQL(rs, stmt);
+ }
+ return users;
+ }
+
+ public static String getJIDbyUID(Connection sql, int uid) {
+ return SQLHelpers.getString(sql, "SELECT jid FROM jids WHERE user_id=? AND active=1", uid);
+ }
+
+ public static int getUIDbyJID(Connection sql, String jid) {
+ return SQLHelpers.getInt(sql, "SELECT user_id FROM jids WHERE jid=?", jid, 0);
+ }
+
+ public static int getUIDbyName(Connection sql, String uname) {
+ return SQLHelpers.getInt(sql, "SELECT id FROM users WHERE nick=?", uname, 0);
+ }
+
+ public static int getUIDbyHash(Connection sql, String hash) {
+ return SQLHelpers.getInt(sql, "SELECT user_id FROM logins WHERE hash=?", hash, 0);
+ }
+
+ public static com.juick.User getUserByHash(Connection sql, String hash) {
+ com.juick.User user = null;
+
+ PreparedStatement stmt = null;
+ ResultSet rs = null;
+ try {
+ stmt = sql.prepareStatement("SELECT logins.user_id,users.nick FROM logins INNER JOIN users ON logins.user_id=users.id WHERE logins.hash=?");
+ stmt.setString(1, hash);
+ rs = stmt.executeQuery();
+ if (rs.first()) {
+ user = new com.juick.User();
+ user.UID = rs.getInt(1);
+ user.UName = rs.getString(2);
+ user.AuthHash = hash;
+ }
+ } catch (SQLException e) {
+ System.err.println(e);
+ } finally {
+ Utils.finishSQL(rs, stmt);
+ }
+ return user;
+ }
+
+ public static String getHashByUID(Connection sql, int uid) {
+ String hash = SQLHelpers.getString(sql, "SELECT hash FROM logins WHERE user_id=?", uid);
+
+ if (hash == null) {
+ hash = generateHash(16);
+ PreparedStatement stmt = null;
+ try {
+ stmt = sql.prepareStatement("INSERT INTO logins(user_id,hash) VALUES (?,?)");
+ stmt.setInt(1, uid);
+ stmt.setString(2, hash);
+ stmt.executeUpdate();
+ } catch (SQLException e) {
+ System.err.println(e);
+ } finally {
+ Utils.finishSQL(null, stmt);
+ }
+ }
+
+ return hash;
+ }
+
+ public static String generateHash(int len) {
+ Random rnd = new Random();
+ StringBuilder sb = new StringBuilder(len);
+ for (int i = 0; i < len; i++) {
+ sb.append(ABCDEF.charAt(rnd.nextInt(ABCDEF.length())));
+ }
+ return sb.toString();
+ }
+
+ public static boolean checkUserNameValid(String uname) {
+ return uname != null && uname.length() >= 2 && uname.length() <= 16 && uname.matches("[a-zA-Z0-9\\-]+");
+ }
+
+ public static int checkPassword(Connection sql, String username, String password) {
+ int uid = 0;
+ PreparedStatement stmt = null;
+ ResultSet rs = null;
+ try {
+ stmt = sql.prepareStatement("SELECT id,passw FROM users WHERE nick=?");
+ stmt.setString(1, username);
+ rs = stmt.executeQuery();
+ if (rs.first()) {
+ if (password.equals(rs.getString(2))) {
+ uid = rs.getInt(1);
+ } else {
+ uid = -1;
+ }
+ }
+ } catch (SQLException e) {
+ System.err.println(e);
+ } finally {
+ Utils.finishSQL(rs, stmt);
+ }
+ return uid;
+ }
+
+ public static int getUserOptionInt(Connection sql, int uid, String option, int defaultValue) {
+ int ret = defaultValue;
+
+ PreparedStatement stmt = null;
+ ResultSet rs = null;
+ try {
+ stmt = sql.prepareStatement("SELECT " + option + " FROM useroptions WHERE user_id=?");
+ stmt.setInt(1, uid);
+ rs = stmt.executeQuery();
+ if (rs.first()) {
+ ret = rs.getInt(1);
+ }
+ } catch (SQLException e) {
+ System.err.println(e);
+ } finally {
+ Utils.finishSQL(rs, stmt);
+ }
+ return ret;
+ }
+
+ public static void setUserOptionInt(Connection sql, int uid, String option, int value) {
+ PreparedStatement stmt = null;
+ try {
+ stmt = sql.prepareStatement("UPDATE useroptions SET " + option + "=? WHERE user_id=?");
+ stmt.setInt(1, value);
+ stmt.setInt(2, uid);
+ stmt.executeUpdate();
+ } catch (SQLException e) {
+ System.err.println(e);
+ } finally {
+ Utils.finishSQL(null, stmt);
+ }
+ }
+
+ public static boolean getCanMedia(Connection sql, int uid) {
+ boolean ret = false;
+
+ PreparedStatement stmt = null;
+ ResultSet rs = null;
+ try {
+ stmt = sql.prepareStatement("SELECT users.lastphoto-UNIX_TIMESTAMP() FROM users WHERE id=?");
+ stmt.setInt(1, uid);
+ rs = stmt.executeQuery();
+ if (rs.first()) {
+ ret = rs.getInt(1) < 3600;
+ }
+ } catch (SQLException e) {
+ System.err.println(e);
+ } finally {
+ Utils.finishSQL(rs, stmt);
+ }
+ return ret;
+ }
+
+ public static boolean isInWL(Connection sql, int uid, int check) {
+ boolean ret = false;
+
+ PreparedStatement stmt = null;
+ ResultSet rs = null;
+ try {
+ stmt = sql.prepareStatement("SELECT 1 FROM wl_users WHERE user_id=? AND wl_user_id=?");
+ stmt.setInt(1, uid);
+ stmt.setInt(2, check);
+ rs = stmt.executeQuery();
+ if (rs.first()) {
+ ret = rs.getInt(1) == 1;
+ }
+ } catch (SQLException e) {
+ System.err.println(e);
+ } finally {
+ Utils.finishSQL(rs, stmt);
+ }
+ return ret;
+ }
+
+ public static boolean isInBL(Connection sql, int uid, int check) {
+ boolean ret = false;
+
+ PreparedStatement stmt = null;
+ ResultSet rs = null;
+ try {
+ stmt = sql.prepareStatement("SELECT 1 FROM bl_users WHERE user_id=? AND bl_user_id=?");
+ stmt.setInt(1, uid);
+ stmt.setInt(2, check);
+ rs = stmt.executeQuery();
+ if (rs.first()) {
+ ret = rs.getInt(1) == 1;
+ }
+ } catch (SQLException e) {
+ System.err.println(e);
+ } finally {
+ Utils.finishSQL(rs, stmt);
+ }
+ return ret;
+ }
+
+ public static boolean isInBLAny(Connection sql, int uid, int uid2) {
+ boolean ret = false;
+
+ PreparedStatement stmt = null;
+ ResultSet rs = null;
+ try {
+ stmt = sql.prepareStatement("SELECT 1 FROM bl_users WHERE (user_id=? AND bl_user_id=?) OR (user_id=? AND bl_user_id=?)");
+ stmt.setInt(1, uid);
+ stmt.setInt(2, uid2);
+ stmt.setInt(3, uid2);
+ stmt.setInt(4, uid);
+ rs = stmt.executeQuery();
+ if (rs.first()) {
+ ret = rs.getInt(1) == 1;
+ }
+ } catch (SQLException e) {
+ System.err.println(e);
+ } finally {
+ Utils.finishSQL(rs, stmt);
+ }
+ return ret;
+ }
+
+ public static ArrayList checkBL(Connection sql, int visitor, ArrayList uids) {
+ ArrayList ret = new ArrayList();
+
+ 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.convertArrayInt2String(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;
+
+ PreparedStatement stmt = null;
+ ResultSet rs = null;
+ try {
+ stmt = sql.prepareStatement("SELECT 1 FROM subscr_users WHERE suser_id=? AND user_id=?");
+ stmt.setInt(1, uid);
+ stmt.setInt(2, check);
+ rs = stmt.executeQuery();
+ if (rs.first()) {
+ ret = rs.getInt(1) == 1;
+ }
+ } catch (SQLException e) {
+ System.err.println(e);
+ } finally {
+ Utils.finishSQL(rs, stmt);
+ }
+ return ret;
+ }
+
+ public static ArrayList getUserRead(Connection sql, int uid) {
+ return SQLHelpers.getArrayInteger(sql, "SELECT user_id FROM subscr_users WHERE suser_id=?", uid);
+ }
+
+ public static ArrayList getUserReadLeastPopular(Connection sql, int uid, int cnt) {
+ ArrayList users = new ArrayList(cnt);
+
+ PreparedStatement stmt = null;
+ ResultSet rs = null;
+ try {
+ stmt = sql.prepareStatement("SELECT users.id,users.nick FROM (subscr_users INNER JOIN users_subscr ON (subscr_users.suser_id=? AND subscr_users.user_id=users_subscr.user_id)) INNER JOIN users ON subscr_users.user_id=users.id ORDER BY cnt LIMIT ?");
+ stmt.setInt(1, uid);
+ stmt.setInt(2, cnt);
+ rs = stmt.executeQuery();
+ rs.beforeFirst();
+ while (rs.next()) {
+ com.juick.User u = new com.juick.User();
+ u.UID = rs.getInt(1);
+ u.UName = rs.getString(2);
+ users.add(u);
+ }
+ } catch (SQLException e) {
+ System.err.println(e);
+ } finally {
+ Utils.finishSQL(rs, stmt);
+ }
+
+ return users;
+ }
+
+ public static ArrayList getUserReaders(Connection sql, int uid) {
+ return SQLHelpers.getArrayInteger(sql, "SELECT suser_id FROM subscr_users WHERE user_id=?", uid);
+ }
+
+ public static ArrayList getUserBLUsers(Connection sql, int uid) {
+ ArrayList users = new ArrayList();
+
+ PreparedStatement stmt = null;
+ ResultSet rs = null;
+ try {
+ stmt = sql.prepareStatement("SELECT users.id,users.nick FROM users INNER JOIN bl_users ON(bl_users.bl_user_id=users.id) WHERE bl_users.user_id=? ORDER BY users.nick");
+ stmt.setInt(1, uid);
+ rs = stmt.executeQuery();
+ rs.beforeFirst();
+ while (rs.next()) {
+ com.juick.User u = new com.juick.User();
+ u.UID = rs.getInt(1);
+ u.UName = rs.getString(2);
+ users.add(u);
+ }
+ } catch (SQLException e) {
+ System.err.println(e);
+ } finally {
+ Utils.finishSQL(rs, stmt);
+ }
+
+ return users;
+ }
+
+ public static int getStatsIRead(Connection sql, int uid) {
+ return SQLHelpers.getInt(sql, "SELECT COUNT(*) FROM subscr_users WHERE suser_id=?", uid, 0);
+ }
+
+ public static int getStatsMyReaders(Connection sql, int uid) {
+ return SQLHelpers.getInt(sql, "SELECT COUNT(*) FROM subscr_users WHERE user_id=?", uid, 0);
+ }
+
+ public static int getStatsMessages(Connection sql, int uid) {
+ return SQLHelpers.getInt(sql, "SELECT COUNT(*) FROM messages WHERE user_id=?", uid, 0);
+ }
+
+ public static int getStatsReplies(Connection sql, int uid) {
+ return SQLHelpers.getInt(sql, "SELECT COUNT(*) FROM replies WHERE user_id=?", uid, 0);
+ }
+}
diff --git a/src/main/java/com/juick/server/Utils.java b/src/main/java/com/juick/server/Utils.java
new file mode 100644
index 00000000..f97797d7
--- /dev/null
+++ b/src/main/java/com/juick/server/Utils.java
@@ -0,0 +1,86 @@
+/*
+ * Juick
+ * Copyright (C) 2008-2011, Ugnich Anton
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see .
+ */
+package com.juick.server;
+
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
+import java.util.ArrayList;
+
+/**
+ *
+ * @author Ugnich Anton
+ */
+public class Utils {
+
+ public static String convertArrayInt2String(ArrayList mids) {
+ String q = "";
+ for (int i = 0; i < mids.size(); i++) {
+ if (i > 0) {
+ q += ",";
+ }
+ q += mids.get(i);
+ }
+ return q;
+ }
+
+ public static String convertArrayString2String(ArrayList unames) {
+ String q = "";
+ for (int i = 0; i < unames.size(); i++) {
+ if (i > 0) {
+ q += ",";
+ }
+ q += "\"" + unames.get(i) + "\"";
+ }
+ return q;
+ }
+
+ public static String buildQueryArray(String query1, int length, String query2) {
+ String ret = query1;
+ for (int i = 0; i < length; i++) {
+ if (i > 0) {
+ ret += ",";
+ }
+ ret += "?";
+ }
+ ret += query2;
+ return ret;
+ }
+
+ public static void stmtSetStringArray(PreparedStatement stmt, int offset, String strs[]) throws SQLException {
+ for (int i = 0; i < strs.length; i++) {
+ stmt.setString(offset + i, strs[i]);
+ }
+ }
+
+ public static void finishSQL(ResultSet rs, Statement stmt) {
+ if (rs != null) {
+ try {
+ rs.close();
+ } catch (SQLException e) {
+ }
+ }
+ if (stmt != null) {
+ try {
+ stmt.close();
+ } catch (SQLException e) {
+ }
+ }
+ }
+}
--
cgit v1.2.3
From 5f981ff945d7bad508d0fb56d037bfe3dccd0cf3 Mon Sep 17 00:00:00 2001
From: Vitaly Takmazov
Date: Sat, 31 Oct 2015 00:36:58 +0300
Subject: Do not show banned users in feed
---
src/main/java/com/juick/server/MessagesQueries.java | 16 ++++++++++++----
1 file changed, 12 insertions(+), 4 deletions(-)
(limited to 'src/main')
diff --git a/src/main/java/com/juick/server/MessagesQueries.java b/src/main/java/com/juick/server/MessagesQueries.java
index 17e9f832..d8d4887d 100644
--- a/src/main/java/com/juick/server/MessagesQueries.java
+++ b/src/main/java/com/juick/server/MessagesQueries.java
@@ -416,21 +416,29 @@ public class MessagesQueries {
try {
if (visitor_uid > 1) {
if (before > 0) {
- stmt = sql.prepareStatement("SELECT message_id FROM messages WHERE message_id AND hidden=0 AND (privacy>0 OR user_id=?) AND user_id NOT IN (SELECT bl_user_id FROM bl_users WHERE user_id=?) ORDER BY message_id DESC LIMIT 20");
+ stmt = sql.prepareStatement("SELECT message_id FROM messages WHERE message_id AND hidden=0" +
+ " AND (privacy>0 OR user_id=?) AND user_id NOT IN (SELECT bl_user_id FROM bl_users WHERE user_id=?)" +
+ " AND user_id NOT IN (SELECT id from users WHERE banned=1) ORDER BY message_id DESC LIMIT 20");
stmt.setInt(1, before);
stmt.setInt(2, visitor_uid);
stmt.setInt(3, visitor_uid);
} else {
- stmt = sql.prepareStatement("SELECT message_id FROM messages WHERE hidden=0 AND (privacy>0 OR user_id=?) AND user_id NOT IN (SELECT bl_user_id FROM bl_users WHERE user_id=?) ORDER BY message_id DESC LIMIT 20");
+ stmt = sql.prepareStatement("SELECT message_id FROM messages WHERE hidden=0" +
+ " AND (privacy>0 OR user_id=?)" +
+ " AND user_id NOT IN (SELECT bl_user_id FROM bl_users WHERE user_id=?)" +
+ " AND user_id NOT IN (SELECT id from users WHERE banned=1) ORDER BY message_id DESC LIMIT 20");
stmt.setInt(1, visitor_uid);
stmt.setInt(2, visitor_uid);
}
} else {
if (before > 0) {
- stmt = sql.prepareStatement("SELECT message_id FROM messages WHERE message_id AND hidden=0 AND privacy>0 ORDER BY message_id DESC LIMIT 20");
+ stmt = sql.prepareStatement("SELECT message_id FROM messages WHERE message_id" +
+ " AND hidden=0 AND privacy>0 AND user_id NOT IN (SELECT id from users WHERE banned=1) " +
+ " ORDER BY message_id DESC LIMIT 20");
stmt.setInt(1, before);
} else {
- stmt = sql.prepareStatement("SELECT message_id FROM messages WHERE hidden=0 AND privacy>0 ORDER BY message_id DESC LIMIT 20");
+ stmt = sql.prepareStatement("SELECT message_id FROM messages WHERE hidden=0 AND privacy>0" +
+ " AND user_id NOT IN (SELECT id from users WHERE banned=1) ORDER BY message_id DESC LIMIT 20");
}
}
--
cgit v1.2.3
From caf7d95837e0dae5056b2b297a47928f0adc5900 Mon Sep 17 00:00:00 2001
From: Vitaly Takmazov
Date: Thu, 26 Nov 2015 02:37:01 +0300
Subject: APNS
---
src/main/java/com/juick/server/PushQueries.java | 26 +++++++++++++++++++++++++
1 file changed, 26 insertions(+)
(limited to 'src/main')
diff --git a/src/main/java/com/juick/server/PushQueries.java b/src/main/java/com/juick/server/PushQueries.java
index 84f42722..bf7505ca 100644
--- a/src/main/java/com/juick/server/PushQueries.java
+++ b/src/main/java/com/juick/server/PushQueries.java
@@ -9,6 +9,7 @@ import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
+import java.util.List;
/**
*
@@ -65,4 +66,29 @@ public class PushQueries {
}
return urls;
}
+
+ public static String getAPNSToken(Connection sql, int uid) {
+ return SQLHelpers.getString(sql, "SELECT token from ios WHERE user_id=?", uid);
+ }
+
+ public static List getAPNSSubscribers(Connection sql, int uid) {
+ List urls = new ArrayList();
+
+ PreparedStatement stmt = null;
+ ResultSet rs = null;
+ try {
+ stmt = sql.prepareStatement("SELECT token FROM ios INNER JOIN subscr_users ON (subscr_users.user_id=? AND ios.user_id=subscr_users.suser_id)");
+ stmt.setInt(1, uid);
+ rs = stmt.executeQuery();
+ rs.beforeFirst();
+ while (rs.next()) {
+ urls.add(rs.getString(1));
+ }
+ } catch (SQLException e) {
+ System.err.println(e);
+ } finally {
+ Utils.finishSQL(rs, stmt);
+ }
+ return urls;
+ }
}
--
cgit v1.2.3
From c49596ab050db2f30d97d6f7129b8239bb4f33e3 Mon Sep 17 00:00:00 2001
From: Vitaly Takmazov
Date: Mon, 30 Nov 2015 20:26:20 +0300
Subject: do not show bl_users in photos
---
src/main/java/com/juick/server/MessagesQueries.java | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
(limited to 'src/main')
diff --git a/src/main/java/com/juick/server/MessagesQueries.java b/src/main/java/com/juick/server/MessagesQueries.java
index 8bef9018..99ab1ce4 100644
--- a/src/main/java/com/juick/server/MessagesQueries.java
+++ b/src/main/java/com/juick/server/MessagesQueries.java
@@ -707,12 +707,14 @@ public class MessagesQueries {
ResultSet rs = null;
try {
if (before > 0) {
- stmt = sql.prepareStatement("SELECT message_id FROM messages WHERE message_id AND (privacy>0 OR user_id=?) AND attach IS NOT NULL ORDER BY message_id DESC LIMIT 20");
+ stmt = sql.prepareStatement("SELECT message_id FROM messages WHERE message_id AND (privacy>0 OR user_id=?) AND attach IS NOT NULL AND user_id NOT IN (SELECT bl_user_id FROM bl_users WHERE user_id=?) ORDER BY message_id DESC LIMIT 20");
stmt.setInt(1, before);
stmt.setInt(2, visitor_uid);
+ stmt.setInt(3, visitor_uid);
} else {
- stmt = sql.prepareStatement("SELECT message_id FROM messages WHERE (privacy>0 OR user_id=?) AND attach IS NOT NULL ORDER BY message_id DESC LIMIT 20");
+ stmt = sql.prepareStatement("SELECT message_id FROM messages WHERE (privacy>0 OR user_id=?) AND attach IS NOT NULL AND user_id NOT IN (SELECT bl_user_id FROM bl_users WHERE user_id=?) ORDER BY message_id DESC LIMIT 20");
stmt.setInt(1, visitor_uid);
+ stmt.setInt(2, visitor_uid);
}
rs = stmt.executeQuery();
rs.beforeFirst();
--
cgit v1.2.3
From 0c451fd02654ffbd56b6422affe8da38ed810644 Mon Sep 17 00:00:00 2001
From: Vitaly Takmazov
Date: Mon, 30 Nov 2015 20:31:53 +0300
Subject: fix previous query
---
src/main/java/com/juick/server/MessagesQueries.java | 6 ++----
1 file changed, 2 insertions(+), 4 deletions(-)
(limited to 'src/main')
diff --git a/src/main/java/com/juick/server/MessagesQueries.java b/src/main/java/com/juick/server/MessagesQueries.java
index 7501e869..82fef672 100644
--- a/src/main/java/com/juick/server/MessagesQueries.java
+++ b/src/main/java/com/juick/server/MessagesQueries.java
@@ -719,14 +719,12 @@ public class MessagesQueries {
ResultSet rs = null;
try {
if (before > 0) {
- stmt = sql.prepareStatement("SELECT message_id FROM messages WHERE message_id AND (privacy>0 OR user_id=?) AND attach IS NOT NULL AND user_id NOT IN (SELECT bl_user_id FROM bl_users WHERE user_id=?) ORDER BY message_id DESC LIMIT 20");
+ stmt = sql.prepareStatement("SELECT message_id FROM messages WHERE message_id AND (privacy>0 OR user_id=?) AND attach IS NOT NULL AND user_id NOT IN (SELECT id from users WHERE banned=1) ORDER BY message_id DESC LIMIT 20");
stmt.setInt(1, before);
stmt.setInt(2, visitor_uid);
- stmt.setInt(3, visitor_uid);
} else {
- stmt = sql.prepareStatement("SELECT message_id FROM messages WHERE (privacy>0 OR user_id=?) AND attach IS NOT NULL AND user_id NOT IN (SELECT bl_user_id FROM bl_users WHERE user_id=?) ORDER BY message_id DESC LIMIT 20");
+ stmt = sql.prepareStatement("SELECT message_id FROM messages WHERE (privacy>0 OR user_id=?) AND attach IS NOT NULL AND user_id NOT IN (SELECT id from users WHERE banned=1) ORDER BY message_id DESC LIMIT 20");
stmt.setInt(1, visitor_uid);
- stmt.setInt(2, visitor_uid);
}
rs = stmt.executeQuery();
rs.beforeFirst();
--
cgit v1.2.3
From 23666546ca2c0f1ee492b1bea8c0ea83c8c04a2b Mon Sep 17 00:00:00 2001
From: Vitaly Takmazov
Date: Mon, 30 Nov 2015 20:41:01 +0300
Subject: do not show banned users in search
---
src/main/java/com/juick/server/MessagesQueries.java | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
(limited to 'src/main')
diff --git a/src/main/java/com/juick/server/MessagesQueries.java b/src/main/java/com/juick/server/MessagesQueries.java
index 7501e869..b6e722f3 100644
--- a/src/main/java/com/juick/server/MessagesQueries.java
+++ b/src/main/java/com/juick/server/MessagesQueries.java
@@ -749,11 +749,11 @@ public class MessagesQueries {
try {
if (before > 0) {
- stmt = sqlSearch.prepareStatement("SELECT id AS message_id FROM messages WHERE MATCH(?) AND id ORDER BY id DESC LIMIT 25");
+ stmt = sqlSearch.prepareStatement("SELECT id AS message_id FROM messages WHERE MATCH(?) AND id AND user_id NOT IN (SELECT id from users WHERE banned=1) ORDER BY id DESC LIMIT 25");
stmt.setString(1, search);
stmt.setInt(2, before);
} else {
- stmt = sqlSearch.prepareStatement("SELECT id AS message_id FROM messages WHERE MATCH(?) ORDER BY id DESC LIMIT 25");
+ stmt = sqlSearch.prepareStatement("SELECT id AS message_id FROM messages WHERE MATCH(?) AND user_id NOT IN (SELECT id from users WHERE banned=1) ORDER BY id DESC LIMIT 25");
stmt.setString(1, search);
}
rs = stmt.executeQuery();
@@ -770,7 +770,7 @@ public class MessagesQueries {
ArrayList 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");
+ stmt = sql.prepareStatement("SELECT message_id FROM messages WHERE message_id IN (" + Utils.convertArrayInt2String(mids0) + ") AND privacy>0 AND user_id NOT IN (SELECT id from users WHERE banned=1) ORDER BY message_id DESC LIMIT 20");
rs = stmt.executeQuery();
rs.beforeFirst();
while (rs.next()) {
--
cgit v1.2.3
From 0a00a5e5625ea0241c0effb3ed6f715fd737a04d Mon Sep 17 00:00:00 2001
From: Vitaly Takmazov
Date: Tue, 1 Dec 2015 12:34:32 +0300
Subject: Revert "do not show banned users in search"
This reverts commit 23666546ca2c0f1ee492b1bea8c0ea83c8c04a2b.
---
src/main/java/com/juick/server/MessagesQueries.java | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
(limited to 'src/main')
diff --git a/src/main/java/com/juick/server/MessagesQueries.java b/src/main/java/com/juick/server/MessagesQueries.java
index c13aec2b..82fef672 100644
--- a/src/main/java/com/juick/server/MessagesQueries.java
+++ b/src/main/java/com/juick/server/MessagesQueries.java
@@ -747,11 +747,11 @@ public class MessagesQueries {
try {
if (before > 0) {
- stmt = sqlSearch.prepareStatement("SELECT id AS message_id FROM messages WHERE MATCH(?) AND id AND user_id NOT IN (SELECT id from users WHERE banned=1) ORDER BY id DESC LIMIT 25");
+ stmt = sqlSearch.prepareStatement("SELECT id AS message_id FROM messages WHERE MATCH(?) AND id ORDER BY id DESC LIMIT 25");
stmt.setString(1, search);
stmt.setInt(2, before);
} else {
- stmt = sqlSearch.prepareStatement("SELECT id AS message_id FROM messages WHERE MATCH(?) AND user_id NOT IN (SELECT id from users WHERE banned=1) ORDER BY id DESC LIMIT 25");
+ stmt = sqlSearch.prepareStatement("SELECT id AS message_id FROM messages WHERE MATCH(?) ORDER BY id DESC LIMIT 25");
stmt.setString(1, search);
}
rs = stmt.executeQuery();
@@ -768,7 +768,7 @@ public class MessagesQueries {
ArrayList 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 AND user_id NOT IN (SELECT id from users WHERE banned=1) ORDER BY message_id DESC LIMIT 20");
+ 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");
rs = stmt.executeQuery();
rs.beforeFirst();
while (rs.next()) {
--
cgit v1.2.3
From 79e48598873f6a2b4ec1aa850e310a689d862afa Mon Sep 17 00:00:00 2001
From: Vitaly Takmazov
Date: Tue, 1 Dec 2015 16:27:32 +0300
Subject: link twitter account query
---
src/main/java/com/juick/server/UserQueries.java | 29 +++++++++++++++++++++++++
1 file changed, 29 insertions(+)
(limited to 'src/main')
diff --git a/src/main/java/com/juick/server/UserQueries.java b/src/main/java/com/juick/server/UserQueries.java
index d1313715..470f3c8e 100644
--- a/src/main/java/com/juick/server/UserQueries.java
+++ b/src/main/java/com/juick/server/UserQueries.java
@@ -17,6 +17,8 @@
*/
package com.juick.server;
+import com.juick.User;
+
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
@@ -574,6 +576,33 @@ public class UserQueries {
return users;
}
+ public static boolean linkTwitterAccount(Connection sql, User user, String accessToken,
+ String accessTokenSecret, String screenName) {
+ try {
+ PreparedStatement stmt =
+ sql.prepareStatement("INSERT INTO twitter(user_id,access_token,access_token_secret,uname) " +
+ "VALUES (?,?,?,?)" +
+ " ON DUPLICATE KEY UPDATE access_token=?,access_token_secret=?,uname=?;");
+ stmt.setInt(1, user.UID);
+ stmt.setString(2, accessToken);
+ stmt.setString(3, accessTokenSecret);
+ stmt.setString(4, screenName);
+ stmt.setString(5, accessToken);
+ stmt.setString(6, accessTokenSecret);
+ stmt.setString(7, screenName);
+ if (stmt.execute()) {
+ PreparedStatement stmt2 =
+ sql.prepareStatement("INSERT INTO subscr_users(user_id,suser_id,jid) " +
+ "VALUES (?,1741,'juick\\@twitter.juick.com')");
+ stmt2.setInt(1, user.UID);
+ return stmt2.execute();
+ }
+ } catch (SQLException e) {
+
+ }
+ return false;
+ }
+
public static int getStatsIRead(Connection sql, int uid) {
return SQLHelpers.getInt(sql, "SELECT COUNT(*) FROM subscr_users WHERE suser_id=?", uid, 0);
}
--
cgit v1.2.3
From 512d0b353f28e241937be3fa146617ba8ff97c9c Mon Sep 17 00:00:00 2001
From: Vitaly Takmazov
Date: Wed, 16 Dec 2015 13:24:29 +0300
Subject: getUsersByHash: fetch users.banned field
---
src/main/java/com/juick/server/UserQueries.java | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
(limited to 'src/main')
diff --git a/src/main/java/com/juick/server/UserQueries.java b/src/main/java/com/juick/server/UserQueries.java
index 470f3c8e..95944ce0 100644
--- a/src/main/java/com/juick/server/UserQueries.java
+++ b/src/main/java/com/juick/server/UserQueries.java
@@ -281,13 +281,14 @@ public class UserQueries {
PreparedStatement stmt = null;
ResultSet rs = null;
try {
- stmt = sql.prepareStatement("SELECT logins.user_id,users.nick FROM logins INNER JOIN users ON logins.user_id=users.id WHERE logins.hash=?");
+ stmt = sql.prepareStatement("SELECT logins.user_id,users.nick, users.banned FROM logins INNER JOIN users ON logins.user_id=users.id WHERE logins.hash=?");
stmt.setString(1, hash);
rs = stmt.executeQuery();
if (rs.first()) {
user = new com.juick.User();
user.UID = rs.getInt(1);
user.UName = rs.getString(2);
+ user.Banned = rs.getBoolean(3);
user.AuthHash = hash;
}
} catch (SQLException e) {
--
cgit v1.2.3
From 03316e2af6989e026318e6860f27d26e6e805d4d Mon Sep 17 00:00:00 2001
From: Vitaly Takmazov
Date: Tue, 22 Dec 2015 16:40:00 +0300
Subject: initial logging
---
src/main/java/com/juick/server/UserQueries.java | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)
(limited to 'src/main')
diff --git a/src/main/java/com/juick/server/UserQueries.java b/src/main/java/com/juick/server/UserQueries.java
index 95944ce0..7e3a212b 100644
--- a/src/main/java/com/juick/server/UserQueries.java
+++ b/src/main/java/com/juick/server/UserQueries.java
@@ -27,6 +27,7 @@ import java.sql.Statement;
import java.util.ArrayList;
import java.util.Random;
import java.util.UUID;
+import java.util.logging.Logger;
/**
*
@@ -36,6 +37,8 @@ public class UserQueries {
static final String ABCDEF = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
+ private static Logger logger = Logger.getLogger(UserQueries.class.getName());
+
public static String getSignUpHashByJID(Connection sql, String jid) {
String hash = SQLHelpers.getString(sql, "SELECT loginhash FROM jids WHERE jid=? AND user_id IS NULL", jid);
@@ -583,7 +586,7 @@ public class UserQueries {
PreparedStatement stmt =
sql.prepareStatement("INSERT INTO twitter(user_id,access_token,access_token_secret,uname) " +
"VALUES (?,?,?,?)" +
- " ON DUPLICATE KEY UPDATE access_token=?,access_token_secret=?,uname=?;");
+ " ON DUPLICATE KEY UPDATE access_token=?,access_token_secret=?,uname=?");
stmt.setInt(1, user.UID);
stmt.setString(2, accessToken);
stmt.setString(3, accessTokenSecret);
@@ -599,7 +602,7 @@ public class UserQueries {
return stmt2.execute();
}
} catch (SQLException e) {
-
+ logger.throwing(UserQueries.class.getName(), "linkTwitterAccount", e);
}
return false;
}
--
cgit v1.2.3
From 98b91289a497989e2c776c7e4e333ce6df719211 Mon Sep 17 00:00:00 2001
From: Vitaly Takmazov
Date: Sun, 10 Jan 2016 15:10:16 +0300
Subject: ON/OFF
---
src/main/java/com/juick/server/UserQueries.java | 25 +++++++++++++++++++++++++
1 file changed, 25 insertions(+)
(limited to 'src/main')
diff --git a/src/main/java/com/juick/server/UserQueries.java b/src/main/java/com/juick/server/UserQueries.java
index d1313715..9140e8ea 100644
--- a/src/main/java/com/juick/server/UserQueries.java
+++ b/src/main/java/com/juick/server/UserQueries.java
@@ -589,4 +589,29 @@ public class UserQueries {
public static int getStatsReplies(Connection sql, int uid) {
return SQLHelpers.getInt(sql, "SELECT COUNT(*) FROM replies WHERE user_id=?", uid, 0);
}
+
+ public enum ActiveStatus {
+ Inactive,
+ Active
+ }
+
+ public static boolean setActiveStatusForJID(Connection sql, String JID, ActiveStatus jidStatus) {
+ User user = getUserByJID(sql, JID);
+ if (user != null) {
+ PreparedStatement preparedStatement = null;
+ try {
+ preparedStatement = sql.prepareStatement(
+ "UPDATE jids SET active=? WHERE user_id=? AND jid=?");
+ int newStatus = jidStatus == ActiveStatus.Active ? 1 : 0;
+ preparedStatement.setInt(1, newStatus);
+ preparedStatement.setInt(2, user.UID);
+ preparedStatement.setString(3, JID);
+ return preparedStatement.executeUpdate() >= 0;
+ } catch (SQLException e) {
+ e.printStackTrace();
+ } finally {
+ Utils.finishSQL(null, preparedStatement);
+ }
+ }
+ }
}
--
cgit v1.2.3
From 2713251c8503f6a0b5ba7cb45f91cf71fa8f81b2 Mon Sep 17 00:00:00 2001
From: Vitaly Takmazov
Date: Sun, 10 Jan 2016 15:36:45 +0300
Subject: fix ON/OFF
---
src/main/java/com/juick/server/UserQueries.java | 1 +
1 file changed, 1 insertion(+)
(limited to 'src/main')
diff --git a/src/main/java/com/juick/server/UserQueries.java b/src/main/java/com/juick/server/UserQueries.java
index ff819629..cb192b73 100644
--- a/src/main/java/com/juick/server/UserQueries.java
+++ b/src/main/java/com/juick/server/UserQueries.java
@@ -646,5 +646,6 @@ public class UserQueries {
Utils.finishSQL(null, preparedStatement);
}
}
+ return false;
}
}
--
cgit v1.2.3
From 439d42ef6d60f0a535fdfa2457da8417b70d966a Mon Sep 17 00:00:00 2001
From: Vitaly Takmazov
Date: Sun, 10 Jan 2016 16:19:30 +0300
Subject: ShowQueries
---
src/main/java/com/juick/server/ShowQueries.java | 72 +++++++++++++++++++++++++
src/main/java/com/juick/server/UserQueries.java | 3 +-
2 files changed, 74 insertions(+), 1 deletion(-)
create mode 100644 src/main/java/com/juick/server/ShowQueries.java
(limited to 'src/main')
diff --git a/src/main/java/com/juick/server/ShowQueries.java b/src/main/java/com/juick/server/ShowQueries.java
new file mode 100644
index 00000000..06aafb2d
--- /dev/null
+++ b/src/main/java/com/juick/server/ShowQueries.java
@@ -0,0 +1,72 @@
+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;
+
+/**
+ * Created by vt on 10/01/16.
+ */
+public class ShowQueries {
+
+ private static final Logger logger = Logger.getLogger(ShowQueries.class.getName());
+
+ public static List getRecommendedUsers(Connection sql, User forUser) {
+ List result = new ArrayList<>();
+ PreparedStatement preparedStatement = null;
+ ResultSet rs = null;
+ try {
+ preparedStatement = sql.prepareStatement("SELECT users.nick FROM subscr_users INNER JOIN users " +
+ "ON subscr_users.user_id=users.id " +
+ "WHERE subscr_users.user_id NOT IN (SELECT user_id FROM subscr_users WHERE suser_id=?) " +
+ "AND subscr_users.suser_id IN (SELECT user_id FROM subscr_users WHERE suser_id=?) " +
+ "AND subscr_users.user_id NOT IN (SELECT bl_user_id FROM bl_users WHERE user_id=?) " +
+ "AND subscr_users.user_id!=? AND users.lastmessage>UNIX_TIMESTAMP()-259200 " +
+ "GROUP BY subscr_users.user_id ORDER BY count(*) DESC LIMIT 10");
+ preparedStatement.setInt(1, forUser.UID);
+ preparedStatement.setInt(2, forUser.UID);
+ preparedStatement.setInt(3, forUser.UID);
+ preparedStatement.setInt(4, forUser.UID);
+ rs = preparedStatement.executeQuery();
+ rs.beforeFirst();
+ while (rs.next()) {
+ result.add(rs.getString(1));
+ }
+ } catch (SQLException e) {
+ logger.log(Level.SEVERE, "sql error", e);
+ } finally {
+ Utils.finishSQL(rs, preparedStatement);
+ }
+ return result;
+ }
+
+ public static List getTopUsers(Connection sql) {
+ List result = new ArrayList<>();
+ PreparedStatement preparedStatement = null;
+ ResultSet rs = null;
+ try {
+ preparedStatement = sql.prepareStatement("SELECT users.nick,COUNT(subscr_users.suser_id) AS cnt " +
+ "FROM (subscr_users INNER JOIN users ON subscr_users.user_id=users.id) " +
+ "INNER JOIN useroptions ON users.id=useroptions.user_id " +
+ "WHERE useroptions.privacy_view>0 AND users.lastmessage>UNIX_TIMESTAMP()-259200 " +
+ "AND users.id!=2 GROUP BY subscr_users.user_id ORDER BY cnt DESC LIMIT 10");
+ rs = preparedStatement.executeQuery();
+ rs.beforeFirst();
+ while (rs.next()) {
+ result.add(rs.getString(1));
+ }
+ } catch (SQLException e) {
+ logger.log(Level.SEVERE, "sql error", e);
+ } finally {
+ Utils.finishSQL(rs, preparedStatement);
+ }
+ return result;
+ }
+}
diff --git a/src/main/java/com/juick/server/UserQueries.java b/src/main/java/com/juick/server/UserQueries.java
index cb192b73..767a68d2 100644
--- a/src/main/java/com/juick/server/UserQueries.java
+++ b/src/main/java/com/juick/server/UserQueries.java
@@ -27,6 +27,7 @@ import java.sql.Statement;
import java.util.ArrayList;
import java.util.Random;
import java.util.UUID;
+import java.util.logging.Level;
import java.util.logging.Logger;
/**
@@ -641,7 +642,7 @@ public class UserQueries {
preparedStatement.setString(3, JID);
return preparedStatement.executeUpdate() >= 0;
} catch (SQLException e) {
- e.printStackTrace();
+ logger.log(Level.SEVERE, "sql error", e);
} finally {
Utils.finishSQL(null, preparedStatement);
}
--
cgit v1.2.3
From c37ed56f884661666b964e47efd23a36be9b24d4 Mon Sep 17 00:00:00 2001
From: Vitaly Takmazov
Date: Sun, 10 Jan 2016 16:56:51 +0300
Subject: logger, diamond and arraylist refactoring
---
src/main/java/com/juick/server/AdsQueries.java | 6 +-
.../java/com/juick/server/CrosspostQueries.java | 8 +-
.../java/com/juick/server/MessagesQueries.java | 173 +++++++++++----------
src/main/java/com/juick/server/PMQueries.java | 54 ++++---
src/main/java/com/juick/server/PushQueries.java | 20 ++-
src/main/java/com/juick/server/SQLHelpers.java | 25 +--
.../com/juick/server/SubscriptionsQueries.java | 39 +++--
src/main/java/com/juick/server/TagQueries.java | 37 +++--
src/main/java/com/juick/server/UserQueries.java | 79 +++++-----
src/main/java/com/juick/server/Utils.java | 6 +-
10 files changed, 244 insertions(+), 203 deletions(-)
(limited to 'src/main')
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 tags) {
+ private static final Logger logger = Logger.getLogger(MessagesQueries.class.getName());
+
+ public static int createMessage(Connection sql, int uid, String txt, String attachment, List 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 getMessageTags(Connection sql, int mid) {
- ArrayList tags = new ArrayList();
+ public static List getMessageTags(Connection sql, int mid) {
+ List 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 getMessageTagsIDs(Connection sql, int mid) {
- ArrayList tids = new ArrayList();
+ public static List getMessageTagsIDs(Connection sql, int mid) {
+ List 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 getMessageRecommendations(Connection sql, int mid) {
- ArrayList users = new ArrayList();
+ ArrayList 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 getAll(Connection sql, int visitor_uid, int before) {
- ArrayList mids = new ArrayList(20);
+ public static List getAll(Connection sql, int visitor_uid, int before) {
+ List 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 getTag(Connection sql, int tid, int visitor_uid, int before, int cnt) {
- ArrayList mids = new ArrayList(20);
+ public static List getTag(Connection sql, int tid, int visitor_uid, int before, int cnt) {
+ List 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 getTags(Connection sql, String tids, int visitor_uid, int before, int cnt) {
- ArrayList mids = new ArrayList(20);
+ public static List getTags(Connection sql, String tids, int visitor_uid, int before, int cnt) {
+ List 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 getPlace(Connection sql, int place_id, int visitor_uid, int before) {
- ArrayList mids = new ArrayList(20);
+ public static List getPlace(Connection sql, int place_id, int visitor_uid, int before) {
+ List 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 getMyFeed(Connection sql, int uid, int before) {
- ArrayList mids = new ArrayList(40);
+ public static List getMyFeed(Connection sql, int uid, int before) {
+ List 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 getPrivate(Connection sql, int uid, int before) {
- ArrayList mids = new ArrayList(20);
+ public static List getPrivate(Connection sql, int uid, int before) {
+ List 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 getDiscussions(Connection sql, int uid, int before) {
- ArrayList mids = new ArrayList(20);
+ public static List getDiscussions(Connection sql, int uid, int before) {
+ List 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 getRecommended(Connection sql, int uid, int before) {
- ArrayList mids = new ArrayList(20);
+ public static List getRecommended(Connection sql, int uid, int before) {
+ List 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 getPopular(Connection sql, int before) {
- ArrayList mids = new ArrayList(20);
+ public static List getPopular(Connection sql, int before) {
+ List 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 getPhotos(Connection sql, int visitor_uid, int before) {
- ArrayList mids = new ArrayList(20);
+ public static List getPhotos(Connection sql, int visitor_uid, int before) {
+ List 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 getSearch(Connection sql, Connection sqlSearch, String search, int before) {
- ArrayList mids0 = new ArrayList(20);
+ public static List getSearch(Connection sql, Connection sqlSearch, String search, int before) {
+ List 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 mids = new ArrayList(20);
+ List 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 getUserBlog(Connection sql, int UID, int privacy, int before) {
- ArrayList mids = new ArrayList(20);
+ public static List getUserBlog(Connection sql, int UID, int privacy, int before) {
+ List 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 getUserTag(Connection sql, int UID, int TID, int privacy, int before) {
- ArrayList mids = new ArrayList(20);
+ public static List getUserTag(Connection sql, int UID, int TID, int privacy, int before) {
+ List 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 getUserRecommendations(Connection sql, int UID, int before) {
- ArrayList mids = new ArrayList(20);
+ public static List getUserRecommendations(Connection sql, int UID, int before) {
+ List 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 getUserPhotos(Connection sql, int UID, int privacy, int before) {
- ArrayList mids = new ArrayList(20);
+ public static List getUserPhotos(Connection sql, int UID, int privacy, int before) {
+ List 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 getUserSearch(Connection sql, Connection sqlSearch, int UID, String search, int privacy, int before) {
- ArrayList mids0 = new ArrayList(20);
+ public static List getUserSearch(Connection sql, Connection sqlSearch, int UID, String search, int privacy, int before) {
+ List 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 mids = new ArrayList(20);
+ List 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