From 55f03c70caeec32ae71e5afe99c4eae5b6b192d3 Mon Sep 17 00:00:00 2001
From: Ugnich Anton
Date: Sat, 24 Dec 2011 23:05:48 +0700
Subject: Initial commit
---
.gitignore | 3 +
build.xml | 74 ++
nbproject/build-impl.xml | 1056 +++++++++++++++++++++++++++++
nbproject/genfiles.properties | 8 +
nbproject/project.properties | 73 ++
nbproject/project.xml | 25 +
src/com/juick/server/ChatQueries.java | 86 +++
src/com/juick/server/MessagesQueries.java | 551 +++++++++++++++
src/com/juick/server/PlacesQueries.java | 55 ++
src/com/juick/server/TagQueries.java | 68 ++
src/com/juick/server/UserQueries.java | 218 ++++++
src/com/juick/server/Utils.java | 56 ++
12 files changed, 2273 insertions(+)
create mode 100644 .gitignore
create mode 100644 build.xml
create mode 100644 nbproject/build-impl.xml
create mode 100644 nbproject/genfiles.properties
create mode 100644 nbproject/project.properties
create mode 100644 nbproject/project.xml
create mode 100644 src/com/juick/server/ChatQueries.java
create mode 100644 src/com/juick/server/MessagesQueries.java
create mode 100644 src/com/juick/server/PlacesQueries.java
create mode 100644 src/com/juick/server/TagQueries.java
create mode 100644 src/com/juick/server/UserQueries.java
create mode 100644 src/com/juick/server/Utils.java
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 00000000..315ea15c
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,3 @@
+/dist/
+/build/
+/nbproject/private/
\ No newline at end of file
diff --git a/build.xml b/build.xml
new file mode 100644
index 00000000..cb4ef59d
--- /dev/null
+++ b/build.xml
@@ -0,0 +1,74 @@
+
+
+
+
+
+
+
+
+
+
+ Builds, tests, and runs the project com.juick.server.
+
+
+
diff --git a/nbproject/build-impl.xml b/nbproject/build-impl.xml
new file mode 100644
index 00000000..278d2839
--- /dev/null
+++ b/nbproject/build-impl.xml
@@ -0,0 +1,1056 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Must set src.dir
+ Must set test.src.dir
+ Must set build.dir
+ Must set dist.dir
+ Must set build.classes.dir
+ Must set dist.javadoc.dir
+ Must set build.test.classes.dir
+ Must set build.test.results.dir
+ Must set build.classes.excludes
+ Must set dist.jar
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Must set javac.includes
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Must set JVM to use for profiling in profiler.info.jvm
+ Must set profiler agent JVM arguments in profiler.info.jvmargs.agent
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Must select some files in the IDE or set javac.includes
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ To run this application from the command line without Ant, try:
+
+
+
+
+
+
+ java -cp "${run.classpath.with.dist.jar}" ${main.class}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ To run this application from the command line without Ant, try:
+
+ java -jar "${dist.jar.resolved}"
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Must select one file in the IDE or set run.class
+
+
+
+ Must select one file in the IDE or set run.class
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Must select one file in the IDE or set debug.class
+
+
+
+
+ Must select one file in the IDE or set debug.class
+
+
+
+
+ Must set fix.includes
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Must select one file in the IDE or set profile.class
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Must select some files in the IDE or set javac.includes
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Some tests failed; see details above.
+
+
+
+
+
+
+
+
+ Must select some files in the IDE or set test.includes
+
+
+
+ Some tests failed; see details above.
+
+
+
+
+ Must select one file in the IDE or set test.class
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Must select one file in the IDE or set applet.url
+
+
+
+
+
+
+
+
+ Must select one file in the IDE or set applet.url
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/nbproject/genfiles.properties b/nbproject/genfiles.properties
new file mode 100644
index 00000000..972737f5
--- /dev/null
+++ b/nbproject/genfiles.properties
@@ -0,0 +1,8 @@
+build.xml.data.CRC32=d216b2d6
+build.xml.script.CRC32=8a81d8ba
+build.xml.stylesheet.CRC32=28e38971@1.44.1.45
+# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml.
+# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you.
+nbproject/build-impl.xml.data.CRC32=d216b2d6
+nbproject/build-impl.xml.script.CRC32=6acf7607
+nbproject/build-impl.xml.stylesheet.CRC32=0ae3a408@1.44.1.45
diff --git a/nbproject/project.properties b/nbproject/project.properties
new file mode 100644
index 00000000..666e31d1
--- /dev/null
+++ b/nbproject/project.properties
@@ -0,0 +1,73 @@
+annotation.processing.enabled=true
+annotation.processing.enabled.in.editor=false
+annotation.processing.run.all.processors=true
+annotation.processing.source.output=${build.generated.sources.dir}/ap-source-output
+application.title=com.juick.server
+application.vendor=ugnich
+build.classes.dir=${build.dir}/classes
+build.classes.excludes=**/*.java,**/*.form
+# This directory is removed when the project is cleaned:
+build.dir=build
+build.generated.dir=${build.dir}/generated
+build.generated.sources.dir=${build.dir}/generated-sources
+# Only compile against the classpath explicitly listed here:
+build.sysclasspath=ignore
+build.test.classes.dir=${build.dir}/test/classes
+build.test.results.dir=${build.dir}/test/results
+# Uncomment to specify the preferred debugger connection transport:
+#debug.transport=dt_socket
+debug.classpath=\
+ ${run.classpath}
+debug.test.classpath=\
+ ${run.test.classpath}
+# This directory is removed when the project is cleaned:
+dist.dir=dist
+dist.jar=${dist.dir}/com.juick.server.jar
+dist.javadoc.dir=${dist.dir}/javadoc
+endorsed.classpath=
+excludes=
+includes=**
+jar.compress=false
+javac.classpath=\
+ ${reference.com_juick.jar}
+# Space-separated list of extra javac options
+javac.compilerargs=
+javac.deprecation=false
+javac.processorpath=\
+ ${javac.classpath}
+javac.source=1.6
+javac.target=1.6
+javac.test.classpath=\
+ ${javac.classpath}:\
+ ${build.classes.dir}
+javac.test.processorpath=\
+ ${javac.test.classpath}
+javadoc.additionalparam=
+javadoc.author=false
+javadoc.encoding=${source.encoding}
+javadoc.noindex=false
+javadoc.nonavbar=false
+javadoc.notree=false
+javadoc.private=false
+javadoc.splitindex=true
+javadoc.use=true
+javadoc.version=false
+javadoc.windowtitle=
+meta.inf.dir=${src.dir}/META-INF
+mkdist.disabled=true
+platform.active=default_platform
+project.com_juick=../com.juick
+reference.com_juick.jar=${project.com_juick}/dist/com.juick.jar
+run.classpath=\
+ ${javac.classpath}:\
+ ${build.classes.dir}
+# Space-separated list of JVM arguments used when running the project
+# (you may also define separate properties like run-sys-prop.name=value instead of -Dname=value
+# or test-sys-prop.name=value to set system properties for unit tests):
+run.jvmargs=
+run.test.classpath=\
+ ${javac.test.classpath}:\
+ ${build.test.classes.dir}
+source.encoding=UTF-8
+src.dir=src
+test.src.dir=test
diff --git a/nbproject/project.xml b/nbproject/project.xml
new file mode 100644
index 00000000..3a3d1bf9
--- /dev/null
+++ b/nbproject/project.xml
@@ -0,0 +1,25 @@
+
+
+ org.netbeans.modules.java.j2seproject
+
+
+ com.juick.server
+
+
+
+
+
+
+
+
+
+ com_juick
+ jar
+
+ jar
+ clean
+ jar
+
+
+
+
diff --git a/src/com/juick/server/ChatQueries.java b/src/com/juick/server/ChatQueries.java
new file mode 100644
index 00000000..19f95637
--- /dev/null
+++ b/src/com/juick/server/ChatQueries.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.Connection;
+import java.sql.PreparedStatement;
+import java.sql.SQLException;
+
+/**
+ *
+ * @author Ugnich Anton
+ */
+public class ChatQueries {
+
+ public static boolean subscribeTag(Connection sql, int uid, int tagid) {
+ boolean ret = false;
+ PreparedStatement stmt = null;
+ try {
+ stmt = sql.prepareStatement("INSERT INTO chat_subscr_tags(tag_id,user_id) VALUES (?,?)");
+ stmt.setInt(1, tagid);
+ stmt.setInt(2, uid);
+ if (stmt.executeUpdate() > 0) {
+ ret = true;
+ }
+ } catch (SQLException e) {
+ System.err.println(e);
+ } finally {
+ Utils.finishSQL(null, stmt);
+ }
+
+ return ret;
+ }
+
+ public static boolean unsubscribeTag(Connection sql, int uid, int tagid) {
+ boolean ret = false;
+ PreparedStatement stmt = null;
+ try {
+ stmt = sql.prepareStatement("DELETE FROM chat_subscr_tags WHERE tag_id=? AND user_id=?");
+ stmt.setInt(1, tagid);
+ stmt.setInt(2, uid);
+ if (stmt.executeUpdate() > 0) {
+ ret = true;
+ }
+ } catch (SQLException e) {
+ System.err.println(e);
+ } finally {
+ Utils.finishSQL(null, stmt);
+ }
+
+ return ret;
+ }
+
+ public static boolean setSubscriptionsActive(Connection sql, int uid, boolean enabled) {
+ boolean ret = false;
+ PreparedStatement stmt = null;
+ try {
+ stmt = sql.prepareStatement("UPDATE chat_subscr_tags SET active=? WHERE user_id=?");
+ stmt.setInt(1, enabled ? 1 : 0);
+ stmt.setInt(2, uid);
+ if (stmt.executeUpdate() > 0) {
+ ret = true;
+ }
+ } catch (SQLException e) {
+ System.err.println(e);
+ } finally {
+ Utils.finishSQL(null, stmt);
+ }
+
+ return ret;
+ }
+}
diff --git a/src/com/juick/server/MessagesQueries.java b/src/com/juick/server/MessagesQueries.java
new file mode 100644
index 00000000..3ff47ca7
--- /dev/null
+++ b/src/com/juick/server/MessagesQueries.java
@@ -0,0 +1,551 @@
+/*
+ * 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 MessagesQueries {
+
+ 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,messages.ts,messages.readonly,messages.attach,messages.place_id,messages.lat,messages.lon 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.TimestampString = rs.getString(3);
+ msg.ReadOnly = rs.getBoolean(4);
+ msg.AttachmentType = rs.getString(5);
+ if (rs.getInt(6) > 0) {
+ msg.place = PlacesQueries.getPlace(sql, rs.getInt(6));
+ }
+ if (rs.getDouble(7) != 0) {
+ msg.place = new com.juick.Place();
+ msg.place.lat = rs.getDouble(7);
+ msg.place.lon = rs.getDouble(8);
+ }
+ }
+ } catch (SQLException e) {
+ System.err.println(e);
+ } finally {
+ Utils.finishSQL(rs, stmt);
+ }
+
+ if (msg == null) {
+ return null;
+ }
+
+ try {
+ stmt = sql.prepareStatement("SELECT messages_txt.tags,messages_txt.txt FROM messages_txt WHERE message_id=?");
+ stmt.setInt(1, mid);
+ rs = stmt.executeQuery();
+ if (rs.first()) {
+ msg.parseTags(rs.getString(1));
+ msg.Text = rs.getString(2);
+ }
+ } 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,replies.ts,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 getAll(Connection sql, 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 WHERE messages.message_id AND messages.privacy>0 ORDER BY messages.message_id DESC LIMIT 20");
+ stmt.setInt(1, before);
+ } else {
+ stmt = sql.prepareStatement("SELECT messages.message_id FROM messages WHERE messages.privacy>0 ORDER BY messages.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 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_tags.tag_id=? AND messages.message_id AND messages.privacy>0 ORDER BY messages.message_id DESC LIMIT 20");
+ stmt.setInt(1, tid);
+ stmt.setInt(2, before);
+ } else {
+ stmt = sql.prepareStatement("SELECT messages.message_id FROM messages_tags INNER JOIN messages USING(message_id) WHERE messages_tags.tag_id=? AND messages.privacy>0 ORDER BY messages.message_id DESC LIMIT 20");
+ stmt.setInt(1, 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 getMyFeed(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 feed 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 feed 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 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_access 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_access 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 getIncoming(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 IN (SELECT suser_id FROM subscr_users 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 IN (SELECT suser_id FROM subscr_users 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 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 messages.message_id IN (SELECT message_id FROM favorites WHERE user_id=11574) ORDER BY message_id DESC LIMIT 20");
+ stmt.setInt(1, before);
+ } else {
+ stmt = sql.prepareStatement("SELECT message_id FROM messages WHERE privacy>0 AND messages.message_id IN (SELECT message_id FROM favorites WHERE user_id=11574) 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 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 attach IS NOT NULL ORDER BY message_id DESC LIMIT 20");
+ stmt.setInt(1, before);
+ } else {
+ stmt = sql.prepareStatement("SELECT message_id FROM messages WHERE privacy>0 AND attach IS NOT NULL 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 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 20");
+ 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 20");
+ 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.convertArray2String(mids0) + ") AND privacy>0 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 getUserBlog(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 message_id AND privacy>0 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 getUserTag(Connection sql, int UID, int TID, 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>0 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>0 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 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>0 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>0 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 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.convertArray2String(mids0) + ") AND privacy>0 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;
+ }
+}
diff --git a/src/com/juick/server/PlacesQueries.java b/src/com/juick/server/PlacesQueries.java
new file mode 100644
index 00000000..d61c89c3
--- /dev/null
+++ b/src/com/juick/server/PlacesQueries.java
@@ -0,0 +1,55 @@
+/*
+ * 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;
+
+/**
+ *
+ * @author Ugnich Anton
+ */
+public class PlacesQueries {
+
+ public static com.juick.Place getPlace(Connection sql, int pid) {
+ com.juick.Place place = null;
+
+ PreparedStatement stmt = null;
+ ResultSet rs = null;
+ try {
+ stmt = sql.prepareStatement("SELECT lat,lon,name FROM places WHERE place_id=?");
+ stmt.setInt(1, pid);
+ rs = stmt.executeQuery();
+ if (rs.first()) {
+ place = new com.juick.Place();
+ place.pid = pid;
+ place.lat = rs.getDouble(1);
+ place.lon = rs.getDouble(2);
+ place.name = rs.getString(3);
+ }
+ } catch (SQLException e) {
+ System.err.println(e);
+ } finally {
+ Utils.finishSQL(rs, stmt);
+ }
+
+ return place;
+ }
+}
diff --git a/src/com/juick/server/TagQueries.java b/src/com/juick/server/TagQueries.java
new file mode 100644
index 00000000..8cb7ee1a
--- /dev/null
+++ b/src/com/juick/server/TagQueries.java
@@ -0,0 +1,68 @@
+/*
+ * 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;
+
+/**
+ *
+ * @author Ugnich Anton
+ */
+public class TagQueries {
+
+ public static int getTagID(Connection sql, String tag, boolean autoCreate) {
+ int tid = 0;
+
+ PreparedStatement stmt = null;
+ ResultSet rs = null;
+ try {
+ stmt = sql.prepareStatement("SELECT tag_id FROM tags WHERE name=?");
+ stmt.setString(1, tag);
+ rs = stmt.executeQuery();
+ if (rs.first()) {
+ tid = rs.getInt(1);
+ }
+ } catch (SQLException e) {
+ System.err.println(e);
+ } finally {
+ Utils.finishSQL(rs, stmt);
+ }
+
+ if (tid == 0 && autoCreate) {
+ try {
+ stmt = sql.prepareStatement("INSERT INTO tags(name) VALUES (?)", Statement.RETURN_GENERATED_KEYS);
+ stmt.setString(1, tag);
+ stmt.executeUpdate();
+ rs = stmt.getGeneratedKeys();
+ if (rs.first()) {
+ tid = rs.getInt(1);
+ }
+ } catch (SQLException e) {
+ System.err.println(e);
+ } finally {
+ Utils.finishSQL(rs, stmt);
+ }
+ }
+
+ return tid;
+ }
+}
diff --git a/src/com/juick/server/UserQueries.java b/src/com/juick/server/UserQueries.java
new file mode 100644
index 00000000..97cae91f
--- /dev/null
+++ b/src/com/juick/server/UserQueries.java
@@ -0,0 +1,218 @@
+/*
+ * 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.Random;
+
+/**
+ *
+ * @author Ugnich Anton
+ */
+public class UserQueries {
+
+ static final String ABCDEF = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
+
+ public static com.juick.User getUserByNick(Connection sql, String username) {
+ com.juick.User user = null;
+
+ PreparedStatement stmt = null;
+ ResultSet rs = null;
+ try {
+ stmt = sql.prepareStatement("SELECT id,nick 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);
+ }
+ } catch (SQLException e) {
+ System.err.println(e);
+ } finally {
+ Utils.finishSQL(rs, stmt);
+ }
+ return user;
+ }
+
+ public static String getJIDbyUID(Connection sql, int UID) {
+ String jid = null;
+
+ PreparedStatement stmt = null;
+ ResultSet rs = null;
+ try {
+ stmt = sql.prepareStatement("SELECT jid FROM jids WHERE user_id=? AND active=1");
+ stmt.setInt(1, UID);
+ rs = stmt.executeQuery();
+ if (rs.first()) {
+ jid = rs.getString(1);
+ }
+ } catch (SQLException e) {
+ System.err.println(e);
+ } finally {
+ Utils.finishSQL(rs, stmt);
+ }
+
+ return jid;
+ }
+
+ public static int getUIDbyHash(Connection sql, String hash) {
+ int UID = 0;
+
+ PreparedStatement stmt = null;
+ ResultSet rs = null;
+ try {
+ stmt = sql.prepareStatement("SELECT user_id FROM logins WHERE hash=?");
+ stmt.setString(1, hash);
+ rs = stmt.executeQuery();
+ if (rs.first()) {
+ UID = rs.getInt(1);
+ }
+ } catch (SQLException e) {
+ System.err.println(e);
+ } finally {
+ Utils.finishSQL(rs, stmt);
+ }
+ return UID;
+ }
+
+ 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);
+ }
+ } catch (SQLException e) {
+ System.err.println(e);
+ } finally {
+ Utils.finishSQL(rs, stmt);
+ }
+ return user;
+ }
+
+ public static String getHashByUID(Connection sql, int uid) {
+ String hash = null;
+ PreparedStatement stmt = null;
+ ResultSet rs = null;
+ try {
+ stmt = sql.prepareStatement("SELECT logins.hash FROM logins WHERE user_id=?");
+ stmt.setInt(1, uid);
+ rs = stmt.executeQuery();
+ if (rs.first()) {
+ hash = rs.getString(2);
+ }
+ } catch (SQLException e) {
+ System.err.println(e);
+ } finally {
+ Utils.finishSQL(rs, stmt);
+ }
+
+ if (hash == null) {
+ hash = generateHash(16);
+ 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 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);
+ }
+ }
+}
diff --git a/src/com/juick/server/Utils.java b/src/com/juick/server/Utils.java
new file mode 100644
index 00000000..997c4f32
--- /dev/null
+++ b/src/com/juick/server/Utils.java
@@ -0,0 +1,56 @@
+/*
+ * 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.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
+import java.util.ArrayList;
+
+/**
+ *
+ * @author Ugnich Anton
+ */
+public class Utils {
+
+ public static String convertArray2String(ArrayList mids) {
+ String q = "";
+ for (int i = 0; i < mids.size(); i++) {
+ if (i > 0) {
+ q += ",";
+ }
+ q += mids.get(i);
+ }
+ return q;
+ }
+
+ 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 f656d844d0096cf8637746afaa1fab7dadaef261 Mon Sep 17 00:00:00 2001
From: Ugnich Anton
Date: Fri, 27 Jan 2012 08:34:31 +0700
Subject: User.getCanMedia, Tag.getUserTagsAll
---
src/com/juick/server/TagQueries.java | 25 +++++++++++++++++++++++++
src/com/juick/server/UserQueries.java | 20 ++++++++++++++++++++
2 files changed, 45 insertions(+)
diff --git a/src/com/juick/server/TagQueries.java b/src/com/juick/server/TagQueries.java
index 8cb7ee1a..7d78e345 100644
--- a/src/com/juick/server/TagQueries.java
+++ b/src/com/juick/server/TagQueries.java
@@ -22,6 +22,7 @@ import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
+import java.util.ArrayList;
/**
*
@@ -65,4 +66,28 @@ public class TagQueries {
return tid;
}
+
+ 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;
+ }
}
diff --git a/src/com/juick/server/UserQueries.java b/src/com/juick/server/UserQueries.java
index 97cae91f..906f7742 100644
--- a/src/com/juick/server/UserQueries.java
+++ b/src/com/juick/server/UserQueries.java
@@ -215,4 +215,24 @@ public class UserQueries {
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;
+ }
}
--
cgit v1.2.3
From 84de24ebd67552e8f1ee01a377a0437b00a8db0e Mon Sep 17 00:00:00 2001
From: Ugnich Anton
Date: Sun, 14 Oct 2012 11:34:26 +0700
Subject: Privacy
---
src/com/juick/server/MessagesQueries.java | 56 ++++++++++++++++++++++++++-----
src/com/juick/server/UserQueries.java | 25 ++++++++++++--
2 files changed, 70 insertions(+), 11 deletions(-)
diff --git a/src/com/juick/server/MessagesQueries.java b/src/com/juick/server/MessagesQueries.java
index 3ff47ca7..b406eb39 100644
--- a/src/com/juick/server/MessagesQueries.java
+++ b/src/com/juick/server/MessagesQueries.java
@@ -29,6 +29,30 @@ import java.util.ArrayList;
*/
public class MessagesQueries {
+ 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 || (privacy == -1 && uid > 0 && UserQueries.isInWL(sql, owner_uid, uid)) || (privacy == -2 && uid == owner_uid);
+ }
+
public static com.juick.Message getMessage(Connection sql, int mid) {
com.juick.Message msg = null;
@@ -190,7 +214,21 @@ public class MessagesQueries {
public static ArrayList getMyFeed(Connection sql, int uid, int before) {
ArrayList mids = new ArrayList(20);
-
+ /*
+ my $sql="SELECT DISTINCT t.message_id FROM (";
+ $sql.="SELECT STRAIGHT_JOIN message_id FROM subscr_users INNER JOIN messages ON subscr_users.user_id=messages.user_id WHERE privacy>=0 AND subscr_users.suser_id=$uid";
+ $sql.=" UNION SELECT message_id FROM (subscr_users INNER JOIN messages ON subscr_users.user_id=messages.user_id) INNER JOIN wl_users ON messages.user_id=wl_users.user_id WHERE privacy=-1 AND subscr_users.suser_id=$uid AND wl_users.wl_user_id=$uid";
+ $sql.=" UNION SELECT message_id FROM messages WHERE user_id=$uid";
+ $sql.=" UNION SELECT message_id FROM subscr_messages WHERE suser_id=$uid";
+ $sql.=" UNION SELECT message_id FROM favorites WHERE user_id=$uid";
+ $sql.=" UNION SELECT message_id FROM favorites INNER JOIN subscr_users ON (subscr_users.suser_id=$uid AND favorites.user_id=subscr_users.user_id)";
+ $sql.=") AS t LEFT JOIN messages_tags USING(message_id) WHERE (tag_id NOT IN (SELECT tag_id FROM bl_tags WHERE user_id=$uid) OR tag_id IS NULL)";
+ if($before_mid>0) {
+ $sql.=" AND message_id<$before_mid";
+ }
+ $sql.=" ORDER BY t.message_id DESC LIMIT 20";
+
+ */
PreparedStatement stmt = null;
ResultSet rs = null;
try {
@@ -242,18 +280,18 @@ public class MessagesQueries {
return mids;
}
- public static ArrayList getIncoming(Connection sql, int uid, int before) {
+ 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 messages WHERE user_id IN (SELECT suser_id FROM subscr_users WHERE user_id=?) AND message_id ORDER BY message_id DESC LIMIT 20");
+ 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 messages WHERE user_id IN (SELECT suser_id FROM subscr_users WHERE user_id=?) ORDER BY message_id DESC LIMIT 20");
+ 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();
@@ -400,11 +438,11 @@ public class MessagesQueries {
ResultSet rs = null;
try {
if (before > 0) {
- stmt = sql.prepareStatement("SELECT message_id FROM messages WHERE user_id=? AND message_id AND privacy>0 ORDER BY message_id DESC LIMIT 20");
+ stmt = sql.prepareStatement("SELECT message_id FROM messages WHERE user_id=? AND message_id AND privacy>=0 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 = 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();
@@ -483,11 +521,11 @@ public class MessagesQueries {
ResultSet rs = null;
try {
if (before > 0) {
- stmt = sql.prepareStatement("SELECT message_id FROM messages WHERE user_id=? AND message_id AND privacy>0 AND attach IS NOT NULL ORDER BY message_id DESC LIMIT 20");
+ stmt = sql.prepareStatement("SELECT message_id FROM messages WHERE user_id=? AND message_id AND privacy>=0 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>0 AND attach IS NOT NULL ORDER BY message_id DESC LIMIT 20");
+ stmt = sql.prepareStatement("SELECT message_id FROM messages WHERE user_id=? AND privacy>=0 AND attach IS NOT NULL ORDER BY message_id DESC LIMIT 20");
stmt.setInt(1, UID);
}
rs = stmt.executeQuery();
@@ -533,7 +571,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.convertArray2String(mids0) + ") AND privacy>0 ORDER BY message_id DESC");
+ stmt = sql.prepareStatement("SELECT message_id FROM messages WHERE message_id IN (" + Utils.convertArray2String(mids0) + ") AND privacy>=0 ORDER BY message_id DESC");
rs = stmt.executeQuery();
rs.beforeFirst();
while (rs.next()) {
diff --git a/src/com/juick/server/UserQueries.java b/src/com/juick/server/UserQueries.java
index 906f7742..bd392ade 100644
--- a/src/com/juick/server/UserQueries.java
+++ b/src/com/juick/server/UserQueries.java
@@ -121,11 +121,11 @@ public class UserQueries {
PreparedStatement stmt = null;
ResultSet rs = null;
try {
- stmt = sql.prepareStatement("SELECT logins.hash FROM logins WHERE user_id=?");
+ stmt = sql.prepareStatement("SELECT hash FROM logins WHERE user_id=?");
stmt.setInt(1, uid);
rs = stmt.executeQuery();
if (rs.first()) {
- hash = rs.getString(2);
+ hash = rs.getString(1);
}
} catch (SQLException e) {
System.err.println(e);
@@ -235,4 +235,25 @@ public class UserQueries {
}
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;
+ }
}
--
cgit v1.2.3
From 6df2be1e680adb8f9c8a186fae05dd7357280c95 Mon Sep 17 00:00:00 2001
From: Ugnich Anton
Date: Sun, 14 Oct 2012 11:45:34 +0700
Subject: getMessageRecommendations
---
src/com/juick/server/MessagesQueries.java | 25 +++++++++++++++++++++++++
1 file changed, 25 insertions(+)
diff --git a/src/com/juick/server/MessagesQueries.java b/src/com/juick/server/MessagesQueries.java
index b406eb39..3ec412b0 100644
--- a/src/com/juick/server/MessagesQueries.java
+++ b/src/com/juick/server/MessagesQueries.java
@@ -160,6 +160,31 @@ public class MessagesQueries {
return user;
}
+ public static String getMessageRecommendations(Connection sql, int mid) {
+ String ret = "";
+
+ 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()) {
+ if (!ret.isEmpty()) {
+ ret += ", ";
+ }
+ ret += "@" + rs.getString(1) + "";
+ }
+ } catch (SQLException e) {
+ System.err.println(e);
+ } finally {
+ Utils.finishSQL(rs, stmt);
+ }
+
+ return ret;
+ }
+
public static ArrayList getAll(Connection sql, int before) {
ArrayList mids = new ArrayList(20);
--
cgit v1.2.3
From bde1bae2a20811cb650608b49459c18f837ba9a5 Mon Sep 17 00:00:00 2001
From: Ugnich Anton
Date: Sun, 14 Oct 2012 11:51:31 +0700
Subject: getMessageRecommendations ArrayList
---
src/com/juick/server/MessagesQueries.java | 11 ++++-------
1 file changed, 4 insertions(+), 7 deletions(-)
diff --git a/src/com/juick/server/MessagesQueries.java b/src/com/juick/server/MessagesQueries.java
index 3ec412b0..80d7a280 100644
--- a/src/com/juick/server/MessagesQueries.java
+++ b/src/com/juick/server/MessagesQueries.java
@@ -160,8 +160,8 @@ public class MessagesQueries {
return user;
}
- public static String getMessageRecommendations(Connection sql, int mid) {
- String ret = "";
+ public static ArrayList getMessageRecommendations(Connection sql, int mid) {
+ ArrayList users = new ArrayList();
PreparedStatement stmt = null;
ResultSet rs = null;
@@ -171,10 +171,7 @@ public class MessagesQueries {
rs = stmt.executeQuery();
rs.beforeFirst();
while (rs.next()) {
- if (!ret.isEmpty()) {
- ret += ", ";
- }
- ret += "@" + rs.getString(1) + "";
+ users.add(rs.getString(1));
}
} catch (SQLException e) {
System.err.println(e);
@@ -182,7 +179,7 @@ public class MessagesQueries {
Utils.finishSQL(rs, stmt);
}
- return ret;
+ return users;
}
public static ArrayList getAll(Connection sql, int before) {
--
cgit v1.2.3
From 4d77c09e6d382548edae2509ccbd56655cbe3737 Mon Sep 17 00:00:00 2001
From: Ugnich Anton
Date: Tue, 16 Oct 2012 17:03:36 +0700
Subject: get user stats
---
src/com/juick/server/UserQueries.java | 76 +++++++++++++++++++++++++++++++++++
1 file changed, 76 insertions(+)
diff --git a/src/com/juick/server/UserQueries.java b/src/com/juick/server/UserQueries.java
index bd392ade..2de8eed7 100644
--- a/src/com/juick/server/UserQueries.java
+++ b/src/com/juick/server/UserQueries.java
@@ -256,4 +256,80 @@ public class UserQueries {
}
return ret;
}
+
+ public static int getStatsIRead(Connection sql, int uid) {
+ int ret = 0;
+ PreparedStatement stmt = null;
+ ResultSet rs = null;
+ try {
+ stmt = sql.prepareStatement("SELECT COUNT(*) FROM subscr_users WHERE suser_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 int getStatsMyReaders(Connection sql, int uid) {
+ int ret = 0;
+ PreparedStatement stmt = null;
+ ResultSet rs = null;
+ try {
+ stmt = sql.prepareStatement("SELECT COUNT(*) FROM subscr_users 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 int getStatsMessages(Connection sql, int uid) {
+ int ret = 0;
+ PreparedStatement stmt = null;
+ ResultSet rs = null;
+ try {
+ stmt = sql.prepareStatement("SELECT COUNT(*) FROM messages 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 int getStatsReplies(Connection sql, int uid) {
+ int ret = 0;
+ PreparedStatement stmt = null;
+ ResultSet rs = null;
+ try {
+ stmt = sql.prepareStatement("SELECT COUNT(*) FROM replies 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;
+ }
}
--
cgit v1.2.3
From 864552bd5e4913a674845b2a9d7fe2fbb604439b Mon Sep 17 00:00:00 2001
From: Ugnich Anton
Date: Sun, 28 Oct 2012 15:49:50 +0700
Subject: SQL optimization
---
src/com/juick/server/MessagesQueries.java | 34 ++++++++++++-------------------
1 file changed, 13 insertions(+), 21 deletions(-)
diff --git a/src/com/juick/server/MessagesQueries.java b/src/com/juick/server/MessagesQueries.java
index 80d7a280..87784f63 100644
--- a/src/com/juick/server/MessagesQueries.java
+++ b/src/com/juick/server/MessagesQueries.java
@@ -236,31 +236,20 @@ public class MessagesQueries {
public static ArrayList getMyFeed(Connection sql, int uid, int before) {
ArrayList mids = new ArrayList(20);
- /*
- my $sql="SELECT DISTINCT t.message_id FROM (";
- $sql.="SELECT STRAIGHT_JOIN message_id FROM subscr_users INNER JOIN messages ON subscr_users.user_id=messages.user_id WHERE privacy>=0 AND subscr_users.suser_id=$uid";
- $sql.=" UNION SELECT message_id FROM (subscr_users INNER JOIN messages ON subscr_users.user_id=messages.user_id) INNER JOIN wl_users ON messages.user_id=wl_users.user_id WHERE privacy=-1 AND subscr_users.suser_id=$uid AND wl_users.wl_user_id=$uid";
- $sql.=" UNION SELECT message_id FROM messages WHERE user_id=$uid";
- $sql.=" UNION SELECT message_id FROM subscr_messages WHERE suser_id=$uid";
- $sql.=" UNION SELECT message_id FROM favorites WHERE user_id=$uid";
- $sql.=" UNION SELECT message_id FROM favorites INNER JOIN subscr_users ON (subscr_users.suser_id=$uid AND favorites.user_id=subscr_users.user_id)";
- $sql.=") AS t LEFT JOIN messages_tags USING(message_id) WHERE (tag_id NOT IN (SELECT tag_id FROM bl_tags WHERE user_id=$uid) OR tag_id IS NULL)";
- if($before_mid>0) {
- $sql.=" AND message_id<$before_mid";
- }
- $sql.=" ORDER BY t.message_id DESC LIMIT 20";
-
- */
PreparedStatement stmt = null;
ResultSet rs = null;
try {
if (before > 0) {
- stmt = sql.prepareStatement("SELECT message_id FROM feed WHERE user_id=? AND message_id ORDER BY message_id DESC LIMIT 20");
+ 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=-1 AND messages.user_id IN (SELECT user_id FROM wl_users WHERE wl_user_id=?)) AND message_id NOT IN (SELECT message_id FROM messages_tags WHERE tag_id IN (SELECT tag_id FROM bl_tags WHERE user_id=?)) ORDER BY message_id DESC LIMIT 20");
stmt.setInt(1, uid);
stmt.setInt(2, before);
+ stmt.setInt(3, uid);
+ stmt.setInt(4, uid);
} else {
- stmt = sql.prepareStatement("SELECT message_id FROM feed WHERE user_id=? ORDER BY message_id DESC LIMIT 20");
+ 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=-1 AND messages.user_id IN (SELECT user_id FROM wl_users WHERE wl_user_id=?)) AND message_id NOT IN (SELECT message_id FROM messages_tags WHERE tag_id IN (SELECT tag_id FROM bl_tags WHERE user_id=?)) ORDER BY message_id DESC LIMIT 20");
stmt.setInt(1, uid);
+ stmt.setInt(2, uid);
+ stmt.setInt(3, uid);
}
rs = stmt.executeQuery();
rs.beforeFirst();
@@ -282,12 +271,15 @@ public class MessagesQueries {
ResultSet rs = null;
try {
if (before > 0) {
- stmt = sql.prepareStatement("SELECT message_id FROM messages_access WHERE user_id=? AND message_id ORDER BY message_id DESC LIMIT 20");
+ stmt = sql.prepareStatement("SELECT message_id FROM (SELECT message_id FROM messages_access WHERE user_id=? AND message_id UNION SELECT message_id FROM messages WHERE user_id=? AND privacy<-1 AND message_id) AS t ORDER BY message_id DESC LIMIT 20");
stmt.setInt(1, uid);
stmt.setInt(2, before);
+ stmt.setInt(3, uid);
+ stmt.setInt(4, before);
} else {
- stmt = sql.prepareStatement("SELECT message_id FROM messages_access WHERE user_id=? ORDER BY message_id DESC LIMIT 20");
+ stmt = sql.prepareStatement("SELECT message_id FROM (SELECT message_id FROM messages_access WHERE user_id=? UNION SELECT message_id FROM messages WHERE user_id=? AND privacy<-1) AS t ORDER BY message_id DESC LIMIT 20");
stmt.setInt(1, uid);
+ stmt.setInt(2, uid);
}
rs = stmt.executeQuery();
rs.beforeFirst();
@@ -366,10 +358,10 @@ public class MessagesQueries {
ResultSet rs = null;
try {
if (before > 0) {
- stmt = sql.prepareStatement("SELECT message_id FROM messages WHERE message_id AND privacy>0 AND messages.message_id IN (SELECT message_id FROM favorites WHERE user_id=11574) ORDER BY message_id DESC LIMIT 20");
+ stmt = sql.prepareStatement("SELECT messages.message_id FROM messages INNER JOIN favorites ON (favorites.user_id=11574 AND favorites.message_id=messages.message_id) WHERE messages.message_id AND messages.privacy>0 ORDER BY messages.message_id DESC LIMIT 20");
stmt.setInt(1, before);
} else {
- stmt = sql.prepareStatement("SELECT message_id FROM messages WHERE privacy>0 AND messages.message_id IN (SELECT message_id FROM favorites WHERE user_id=11574) ORDER BY message_id DESC LIMIT 20");
+ stmt = sql.prepareStatement("SELECT messages.message_id FROM messages INNER JOIN favorites ON (favorites.user_id=11574 AND favorites.message_id=messages.message_id) WHERE messages.privacy>0 ORDER BY messages.message_id DESC LIMIT 20");
}
rs = stmt.executeQuery();
rs.beforeFirst();
--
cgit v1.2.3
From 691738fa2c9f4b8ac3789b21767e52f35ae72b5a Mon Sep 17 00:00:00 2001
From: Ugnich Anton
Date: Mon, 29 Oct 2012 00:22:13 +0700
Subject: isInBL, isSubscribed
---
src/com/juick/server/UserQueries.java | 42 +++++++++++++++++++++++++++++++++++
1 file changed, 42 insertions(+)
diff --git a/src/com/juick/server/UserQueries.java b/src/com/juick/server/UserQueries.java
index 2de8eed7..a49da34f 100644
--- a/src/com/juick/server/UserQueries.java
+++ b/src/com/juick/server/UserQueries.java
@@ -257,6 +257,48 @@ public class UserQueries {
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 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 int getStatsIRead(Connection sql, int uid) {
int ret = 0;
PreparedStatement stmt = null;
--
cgit v1.2.3
From 860b00003367e5a66ffc8ffe373542e424516249 Mon Sep 17 00:00:00 2001
From: Ugnich Anton
Date: Fri, 2 Nov 2012 14:44:28 +0700
Subject: MessagesQueries.isSubscribed
---
src/com/juick/server/MessagesQueries.java | 21 +++++++++++++++++++++
1 file changed, 21 insertions(+)
diff --git a/src/com/juick/server/MessagesQueries.java b/src/com/juick/server/MessagesQueries.java
index 87784f63..1df45803 100644
--- a/src/com/juick/server/MessagesQueries.java
+++ b/src/com/juick/server/MessagesQueries.java
@@ -53,6 +53,27 @@ public class MessagesQueries {
return privacy >= 0 || (privacy == -1 && uid > 0 && UserQueries.isInWL(sql, owner_uid, uid)) || (privacy == -2 && uid == owner_uid);
}
+ 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 com.juick.Message getMessage(Connection sql, int mid) {
com.juick.Message msg = null;
--
cgit v1.2.3
From 4c311735dcf5d6e54dfb1d2d751a2bd42193e168 Mon Sep 17 00:00:00 2001
From: Ugnich Anton
Date: Fri, 2 Nov 2012 17:32:20 +0700
Subject: getMessages checkBL
---
src/com/juick/server/MessagesQueries.java | 52 ++++++++++++++++++++++++++++---
src/com/juick/server/UserQueries.java | 23 ++++++++++++++
2 files changed, 71 insertions(+), 4 deletions(-)
diff --git a/src/com/juick/server/MessagesQueries.java b/src/com/juick/server/MessagesQueries.java
index 1df45803..abcdd285 100644
--- a/src/com/juick/server/MessagesQueries.java
+++ b/src/com/juick/server/MessagesQueries.java
@@ -93,12 +93,12 @@ public class MessagesQueries {
msg.ReadOnly = rs.getBoolean(4);
msg.AttachmentType = rs.getString(5);
if (rs.getInt(6) > 0) {
- msg.place = PlacesQueries.getPlace(sql, rs.getInt(6));
+ msg.Place = PlacesQueries.getPlace(sql, rs.getInt(6));
}
if (rs.getDouble(7) != 0) {
- msg.place = new com.juick.Place();
- msg.place.lat = rs.getDouble(7);
- msg.place.lon = rs.getDouble(8);
+ msg.Place = new com.juick.Place();
+ msg.Place.lat = rs.getDouble(7);
+ msg.Place.lon = rs.getDouble(8);
}
}
} catch (SQLException e) {
@@ -621,4 +621,48 @@ public class MessagesQueries {
return mids;
}
+
+ public static ArrayList 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()),messages.ts,messages.replies,messages_txt.repliesby,messages.attach,messages.place_id,places.name,messages.lat,messages.lon FROM ((messages INNER JOIN messages_txt ON messages.message_id=messages_txt.message_id) INNER JOIN users ON messages.user_id=users.id) LEFT JOIN places ON messages.place_id=places.place_id WHERE messages.message_id IN (" + Utils.convertArray2String(mids) + ") ORDER BY messages.message_id DESC");
+ rs = stmt.executeQuery();
+ rs.beforeFirst();
+ while (rs.next()) {
+ com.juick.Message msg = new com.juick.Message();
+ msg.User = new com.juick.User();
+
+ msg.MID = rs.getInt(1);
+ msg.User.UID = rs.getInt(2);
+ msg.User.UName = rs.getString(3);
+ msg.parseTags(rs.getString(4));
+ msg.ReadOnly = rs.getInt(5) == 1;
+ msg.Privacy = rs.getInt(6);
+ msg.Text = rs.getString(7);
+ msg.TimeAgo = rs.getInt(8);
+ msg.TimestampString = rs.getString(9);
+ msg.Replies = rs.getInt(10);
+ msg.RepliesBy = rs.getString(11);
+ msg.AttachmentType = rs.getString(12);
+ if (rs.getInt(13) > 0) {
+ msg.Place = new com.juick.Place();
+ msg.Place.pid = rs.getInt(13);
+ msg.Place.name = rs.getString(14);
+ msg.Place.lat = rs.getDouble(15);
+ msg.Place.lon = rs.getDouble(16);
+ }
+
+ msgs.add(msg);
+ }
+ } catch (SQLException e) {
+ System.err.println(e);
+ } finally {
+ Utils.finishSQL(rs, stmt);
+ }
+
+ return msgs;
+ }
}
diff --git a/src/com/juick/server/UserQueries.java b/src/com/juick/server/UserQueries.java
index a49da34f..ff1d0e24 100644
--- a/src/com/juick/server/UserQueries.java
+++ b/src/com/juick/server/UserQueries.java
@@ -21,6 +21,7 @@ import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
+import java.util.ArrayList;
import java.util.Random;
/**
@@ -278,6 +279,28 @@ public class UserQueries {
return ret;
}
+ public static ArrayList 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.convertArray2String(uids) + ")");
+ stmt.setInt(1, visitor);
+ rs = stmt.executeQuery();
+ rs.beforeFirst();
+ while (rs.next()) {
+ ret.add(rs.getInt(1));
+ }
+ } catch (SQLException e) {
+ System.err.println(e);
+ } finally {
+ Utils.finishSQL(rs, stmt);
+ }
+
+ return ret;
+ }
+
public static boolean isSubscribed(Connection sql, int uid, int check) {
boolean ret = false;
--
cgit v1.2.3
From 83a82852057e48ef595057987b057496d5b562c6 Mon Sep 17 00:00:00 2001
From: Ugnich Anton
Date: Fri, 2 Nov 2012 18:32:24 +0700
Subject: getReplies isReadonly
---
src/com/juick/server/MessagesQueries.java | 58 ++++++++++++++++++++++++++++++-
1 file changed, 57 insertions(+), 1 deletion(-)
diff --git a/src/com/juick/server/MessagesQueries.java b/src/com/juick/server/MessagesQueries.java
index abcdd285..f7625a19 100644
--- a/src/com/juick/server/MessagesQueries.java
+++ b/src/com/juick/server/MessagesQueries.java
@@ -53,6 +53,26 @@ public class MessagesQueries {
return privacy >= 0 || (privacy == -1 && uid > 0 && UserQueries.isInWL(sql, owner_uid, uid)) || (privacy == -2 && uid == owner_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;
@@ -638,7 +658,9 @@ public class MessagesQueries {
msg.MID = rs.getInt(1);
msg.User.UID = rs.getInt(2);
msg.User.UName = rs.getString(3);
- msg.parseTags(rs.getString(4));
+ if (rs.getString(4) != null) {
+ msg.parseTags(rs.getString(4));
+ }
msg.ReadOnly = rs.getInt(5) == 1;
msg.Privacy = rs.getInt(6);
msg.Text = rs.getString(7);
@@ -665,4 +687,38 @@ public class MessagesQueries {
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,replies.txt,TIMESTAMPDIFF(MINUTE,replies.ts,NOW()),replies.ts,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.Text = rs.getString(5);
+ msg.TimeAgo = rs.getInt(6);
+ msg.TimestampString = rs.getString(7);
+ msg.AttachmentType = rs.getString(8);
+
+ replies.add(msg);
+ }
+ } catch (SQLException e) {
+ System.err.println(e);
+ } finally {
+ Utils.finishSQL(rs, stmt);
+ }
+
+ return replies;
+ }
}
--
cgit v1.2.3
From ac4323e6d01264e9830f952ceacb192795845455 Mon Sep 17 00:00:00 2001
From: Ugnich Anton
Date: Sun, 4 Nov 2012 22:54:16 +0700
Subject: getMessage improvement
---
src/com/juick/server/MessagesQueries.java | 30 ++++++++++++++++++------------
1 file changed, 18 insertions(+), 12 deletions(-)
diff --git a/src/com/juick/server/MessagesQueries.java b/src/com/juick/server/MessagesQueries.java
index f7625a19..7b4b800d 100644
--- a/src/com/juick/server/MessagesQueries.java
+++ b/src/com/juick/server/MessagesQueries.java
@@ -100,7 +100,7 @@ public class MessagesQueries {
PreparedStatement stmt = null;
ResultSet rs = null;
try {
- stmt = sql.prepareStatement("SELECT messages.user_id,users.nick,messages.ts,messages.readonly,messages.attach,messages.place_id,messages.lat,messages.lon FROM messages INNER JOIN users ON messages.user_id=users.id WHERE messages.message_id=?");
+ stmt = sql.prepareStatement("SELECT messages.user_id,users.nick,TIMESTAMPDIFF(MINUTE,messages.ts,NOW()),messages.ts,messages.readonly,messages.privacy,messages.replies,messages.attach,messages.place_id,messages.lat,messages.lon 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()) {
@@ -109,16 +109,19 @@ public class MessagesQueries {
msg.User = new com.juick.User();
msg.User.UID = rs.getInt(1);
msg.User.UName = rs.getString(2);
- msg.TimestampString = rs.getString(3);
- msg.ReadOnly = rs.getBoolean(4);
- msg.AttachmentType = rs.getString(5);
- if (rs.getInt(6) > 0) {
- msg.Place = PlacesQueries.getPlace(sql, rs.getInt(6));
+ msg.TimeAgo = rs.getInt(3);
+ msg.TimestampString = rs.getString(4);
+ msg.ReadOnly = rs.getBoolean(5);
+ msg.Privacy = rs.getInt(6);
+ 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(7) != 0) {
+ if (rs.getDouble(10) != 0) {
msg.Place = new com.juick.Place();
- msg.Place.lat = rs.getDouble(7);
- msg.Place.lon = rs.getDouble(8);
+ msg.Place.lat = rs.getDouble(10);
+ msg.Place.lon = rs.getDouble(11);
}
}
} catch (SQLException e) {
@@ -132,12 +135,15 @@ public class MessagesQueries {
}
try {
- stmt = sql.prepareStatement("SELECT messages_txt.tags,messages_txt.txt FROM messages_txt WHERE message_id=?");
+ stmt = sql.prepareStatement("SELECT tags,repliesby,txt FROM messages_txt WHERE message_id=?");
stmt.setInt(1, mid);
rs = stmt.executeQuery();
if (rs.first()) {
- msg.parseTags(rs.getString(1));
- msg.Text = rs.getString(2);
+ 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);
--
cgit v1.2.3
From 55b0d951675383f1973c334608c9d6b9e04b9b04 Mon Sep 17 00:00:00 2001
From: Ugnich Anton
Date: Sun, 11 Nov 2012 14:58:24 +0700
Subject: hasAccessToMessage
---
src/com/juick/server/MessagesQueries.java | 154 +++++++++++++++++-------------
1 file changed, 89 insertions(+), 65 deletions(-)
diff --git a/src/com/juick/server/MessagesQueries.java b/src/com/juick/server/MessagesQueries.java
index 7b4b800d..90c90ceb 100644
--- a/src/com/juick/server/MessagesQueries.java
+++ b/src/com/juick/server/MessagesQueries.java
@@ -28,12 +28,12 @@ import java.util.ArrayList;
* @author Ugnich Anton
*/
public class MessagesQueries {
-
+
public static boolean canViewThread(Connection sql, int mid, int uid) {
-
+
int privacy = 0;
int owner_uid = 0;
-
+
PreparedStatement stmt = null;
ResultSet rs = null;
try {
@@ -49,13 +49,37 @@ public class MessagesQueries {
} finally {
Utils.finishSQL(rs, stmt);
}
-
- return privacy >= 0 || (privacy == -1 && uid > 0 && UserQueries.isInWL(sql, owner_uid, uid)) || (privacy == -2 && uid == owner_uid);
+
+ return privacy >= 0
+ || (privacy == -1 && uid > 0 && UserQueries.isInWL(sql, owner_uid, uid))
+ || (privacy == -2 && (uid == owner_uid || hasAccessToMessage(sql, mid, uid)));
}
-
+
+ public static boolean hasAccessToMessage(Connection sql, int mid, int uid) {
+ boolean ret = false;
+
+ PreparedStatement stmt = null;
+ ResultSet rs = null;
+ try {
+ stmt = sql.prepareStatement("SELECT 1 FROM messages_access WHERE message_id=? AND user_id=?");
+ stmt.setInt(1, mid);
+ stmt.setInt(2, 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 boolean isReadOnly(Connection sql, int mid) {
boolean ret = false;
-
+
PreparedStatement stmt = null;
ResultSet rs = null;
try {
@@ -72,10 +96,10 @@ public class MessagesQueries {
}
return ret;
}
-
+
public static boolean isSubscribed(Connection sql, int uid, int mid) {
boolean ret = false;
-
+
PreparedStatement stmt = null;
ResultSet rs = null;
try {
@@ -93,10 +117,10 @@ public class MessagesQueries {
}
return ret;
}
-
+
public static com.juick.Message getMessage(Connection sql, int mid) {
com.juick.Message msg = null;
-
+
PreparedStatement stmt = null;
ResultSet rs = null;
try {
@@ -129,11 +153,11 @@ public class MessagesQueries {
} 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);
@@ -150,13 +174,13 @@ public class MessagesQueries {
} 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 {
@@ -181,13 +205,13 @@ public class MessagesQueries {
} 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 {
@@ -206,10 +230,10 @@ public class MessagesQueries {
}
return user;
}
-
+
public static ArrayList getMessageRecommendations(Connection sql, int mid) {
ArrayList users = new ArrayList();
-
+
PreparedStatement stmt = null;
ResultSet rs = null;
try {
@@ -225,13 +249,13 @@ public class MessagesQueries {
} finally {
Utils.finishSQL(rs, stmt);
}
-
+
return users;
}
-
+
public static ArrayList getAll(Connection sql, int before) {
ArrayList mids = new ArrayList(20);
-
+
PreparedStatement stmt = null;
ResultSet rs = null;
try {
@@ -253,10 +277,10 @@ public class MessagesQueries {
}
return mids;
}
-
+
public static ArrayList getTag(Connection sql, int tid, int before) {
ArrayList mids = new ArrayList(20);
-
+
PreparedStatement stmt = null;
ResultSet rs = null;
try {
@@ -280,7 +304,7 @@ public class MessagesQueries {
}
return mids;
}
-
+
public static ArrayList getMyFeed(Connection sql, int uid, int before) {
ArrayList mids = new ArrayList(20);
PreparedStatement stmt = null;
@@ -310,10 +334,10 @@ public class MessagesQueries {
}
return mids;
}
-
+
public static ArrayList getPrivate(Connection sql, int uid, int before) {
ArrayList mids = new ArrayList(20);
-
+
PreparedStatement stmt = null;
ResultSet rs = null;
try {
@@ -340,10 +364,10 @@ public class MessagesQueries {
}
return mids;
}
-
+
public static ArrayList getDiscussions(Connection sql, int uid, int before) {
ArrayList mids = new ArrayList(20);
-
+
PreparedStatement stmt = null;
ResultSet rs = null;
try {
@@ -365,13 +389,13 @@ public class MessagesQueries {
} 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 {
@@ -393,14 +417,14 @@ public class MessagesQueries {
} 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 {
@@ -422,10 +446,10 @@ public class MessagesQueries {
}
return mids;
}
-
+
public static ArrayList getPhotos(Connection sql, int before) {
ArrayList mids = new ArrayList(20);
-
+
PreparedStatement stmt = null;
ResultSet rs = null;
try {
@@ -447,10 +471,10 @@ public class MessagesQueries {
}
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 {
@@ -472,7 +496,7 @@ public class MessagesQueries {
} finally {
Utils.finishSQL(rs, stmt);
}
-
+
ArrayList mids = new ArrayList(20);
if (mids0.size() > 0) {
try {
@@ -488,13 +512,13 @@ public class MessagesQueries {
Utils.finishSQL(rs, stmt);
}
}
-
+
return mids;
}
-
+
public static ArrayList getUserBlog(Connection sql, int UID, int before) {
ArrayList mids = new ArrayList(20);
-
+
PreparedStatement stmt = null;
ResultSet rs = null;
try {
@@ -518,10 +542,10 @@ public class MessagesQueries {
}
return mids;
}
-
+
public static ArrayList getUserTag(Connection sql, int UID, int TID, int before) {
ArrayList mids = new ArrayList(20);
-
+
PreparedStatement stmt = null;
ResultSet rs = null;
try {
@@ -547,10 +571,10 @@ public class MessagesQueries {
}
return mids;
}
-
+
public static ArrayList getUserRecommendations(Connection sql, int UID, int before) {
ArrayList mids = new ArrayList(20);
-
+
PreparedStatement stmt = null;
ResultSet rs = null;
try {
@@ -574,10 +598,10 @@ public class MessagesQueries {
}
return mids;
}
-
+
public static ArrayList getUserPhotos(Connection sql, int UID, int before) {
ArrayList mids = new ArrayList(20);
-
+
PreparedStatement stmt = null;
ResultSet rs = null;
try {
@@ -601,10 +625,10 @@ public class MessagesQueries {
}
return mids;
}
-
+
public static ArrayList getUserSearch(Connection sql, Connection sqlSearch, int UID, String search, int before) {
ArrayList mids0 = new ArrayList(20);
-
+
PreparedStatement stmt = null;
ResultSet rs = null;
try {
@@ -628,7 +652,7 @@ public class MessagesQueries {
} finally {
Utils.finishSQL(rs, stmt);
}
-
+
ArrayList mids = new ArrayList(20);
if (mids0.size() > 0) {
try {
@@ -644,13 +668,13 @@ public class MessagesQueries {
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 {
@@ -660,7 +684,7 @@ public class MessagesQueries {
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);
@@ -682,7 +706,7 @@ public class MessagesQueries {
msg.Place.lat = rs.getDouble(15);
msg.Place.lon = rs.getDouble(16);
}
-
+
msgs.add(msg);
}
} catch (SQLException e) {
@@ -690,13 +714,13 @@ public class MessagesQueries {
} 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 {
@@ -716,7 +740,7 @@ public class MessagesQueries {
msg.TimeAgo = rs.getInt(6);
msg.TimestampString = rs.getString(7);
msg.AttachmentType = rs.getString(8);
-
+
replies.add(msg);
}
} catch (SQLException e) {
@@ -724,7 +748,7 @@ public class MessagesQueries {
} finally {
Utils.finishSQL(rs, stmt);
}
-
+
return replies;
}
}
--
cgit v1.2.3
From 9010502f7e50688b72300b60646eac5b89a80d9e Mon Sep 17 00:00:00 2001
From: Ugnich Anton
Date: Sun, 16 Dec 2012 12:00:31 +0700
Subject: messages privacy fix
---
src/com/juick/server/MessagesQueries.java | 139 +++++++++++++++---------------
1 file changed, 70 insertions(+), 69 deletions(-)
diff --git a/src/com/juick/server/MessagesQueries.java b/src/com/juick/server/MessagesQueries.java
index 90c90ceb..c17b9d3d 100644
--- a/src/com/juick/server/MessagesQueries.java
+++ b/src/com/juick/server/MessagesQueries.java
@@ -28,12 +28,12 @@ import java.util.ArrayList;
* @author Ugnich Anton
*/
public class MessagesQueries {
-
+
public static boolean canViewThread(Connection sql, int mid, int uid) {
-
+
int privacy = 0;
int owner_uid = 0;
-
+
PreparedStatement stmt = null;
ResultSet rs = null;
try {
@@ -49,15 +49,16 @@ public class MessagesQueries {
} finally {
Utils.finishSQL(rs, stmt);
}
-
+
return privacy >= 0
- || (privacy == -1 && uid > 0 && UserQueries.isInWL(sql, owner_uid, uid))
- || (privacy == -2 && (uid == owner_uid || hasAccessToMessage(sql, mid, uid)));
+ || uid == owner_uid
+ || ((privacy == -1 || privacy == -2) && uid > 0 && UserQueries.isInWL(sql, owner_uid, uid))
+ || (privacy == -3 && uid > 0 && hasAccessToMessage(sql, mid, uid));
}
-
+
public static boolean hasAccessToMessage(Connection sql, int mid, int uid) {
boolean ret = false;
-
+
PreparedStatement stmt = null;
ResultSet rs = null;
try {
@@ -73,13 +74,13 @@ public class MessagesQueries {
} finally {
Utils.finishSQL(rs, stmt);
}
-
+
return ret;
}
-
+
public static boolean isReadOnly(Connection sql, int mid) {
boolean ret = false;
-
+
PreparedStatement stmt = null;
ResultSet rs = null;
try {
@@ -96,10 +97,10 @@ public class MessagesQueries {
}
return ret;
}
-
+
public static boolean isSubscribed(Connection sql, int uid, int mid) {
boolean ret = false;
-
+
PreparedStatement stmt = null;
ResultSet rs = null;
try {
@@ -117,10 +118,10 @@ public class MessagesQueries {
}
return ret;
}
-
+
public static com.juick.Message getMessage(Connection sql, int mid) {
com.juick.Message msg = null;
-
+
PreparedStatement stmt = null;
ResultSet rs = null;
try {
@@ -153,11 +154,11 @@ public class MessagesQueries {
} 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);
@@ -174,13 +175,13 @@ public class MessagesQueries {
} 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 {
@@ -205,13 +206,13 @@ public class MessagesQueries {
} 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 {
@@ -230,10 +231,10 @@ public class MessagesQueries {
}
return user;
}
-
+
public static ArrayList getMessageRecommendations(Connection sql, int mid) {
ArrayList users = new ArrayList();
-
+
PreparedStatement stmt = null;
ResultSet rs = null;
try {
@@ -249,13 +250,13 @@ public class MessagesQueries {
} finally {
Utils.finishSQL(rs, stmt);
}
-
+
return users;
}
-
+
public static ArrayList getAll(Connection sql, int before) {
ArrayList mids = new ArrayList(20);
-
+
PreparedStatement stmt = null;
ResultSet rs = null;
try {
@@ -277,10 +278,10 @@ public class MessagesQueries {
}
return mids;
}
-
+
public static ArrayList getTag(Connection sql, int tid, int before) {
ArrayList mids = new ArrayList(20);
-
+
PreparedStatement stmt = null;
ResultSet rs = null;
try {
@@ -304,7 +305,7 @@ public class MessagesQueries {
}
return mids;
}
-
+
public static ArrayList getMyFeed(Connection sql, int uid, int before) {
ArrayList mids = new ArrayList(20);
PreparedStatement stmt = null;
@@ -334,10 +335,10 @@ public class MessagesQueries {
}
return mids;
}
-
+
public static ArrayList getPrivate(Connection sql, int uid, int before) {
ArrayList mids = new ArrayList(20);
-
+
PreparedStatement stmt = null;
ResultSet rs = null;
try {
@@ -364,10 +365,10 @@ public class MessagesQueries {
}
return mids;
}
-
+
public static ArrayList getDiscussions(Connection sql, int uid, int before) {
ArrayList mids = new ArrayList(20);
-
+
PreparedStatement stmt = null;
ResultSet rs = null;
try {
@@ -389,13 +390,13 @@ public class MessagesQueries {
} 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 {
@@ -417,14 +418,14 @@ public class MessagesQueries {
} 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 {
@@ -446,10 +447,10 @@ public class MessagesQueries {
}
return mids;
}
-
+
public static ArrayList getPhotos(Connection sql, int before) {
ArrayList mids = new ArrayList(20);
-
+
PreparedStatement stmt = null;
ResultSet rs = null;
try {
@@ -471,10 +472,10 @@ public class MessagesQueries {
}
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 {
@@ -496,7 +497,7 @@ public class MessagesQueries {
} finally {
Utils.finishSQL(rs, stmt);
}
-
+
ArrayList mids = new ArrayList(20);
if (mids0.size() > 0) {
try {
@@ -512,13 +513,13 @@ public class MessagesQueries {
Utils.finishSQL(rs, stmt);
}
}
-
+
return mids;
}
-
+
public static ArrayList getUserBlog(Connection sql, int UID, int before) {
ArrayList mids = new ArrayList(20);
-
+
PreparedStatement stmt = null;
ResultSet rs = null;
try {
@@ -542,10 +543,10 @@ public class MessagesQueries {
}
return mids;
}
-
+
public static ArrayList getUserTag(Connection sql, int UID, int TID, int before) {
ArrayList mids = new ArrayList(20);
-
+
PreparedStatement stmt = null;
ResultSet rs = null;
try {
@@ -571,10 +572,10 @@ public class MessagesQueries {
}
return mids;
}
-
+
public static ArrayList getUserRecommendations(Connection sql, int UID, int before) {
ArrayList mids = new ArrayList(20);
-
+
PreparedStatement stmt = null;
ResultSet rs = null;
try {
@@ -598,10 +599,10 @@ public class MessagesQueries {
}
return mids;
}
-
+
public static ArrayList getUserPhotos(Connection sql, int UID, int before) {
ArrayList mids = new ArrayList(20);
-
+
PreparedStatement stmt = null;
ResultSet rs = null;
try {
@@ -625,10 +626,10 @@ public class MessagesQueries {
}
return mids;
}
-
+
public static ArrayList getUserSearch(Connection sql, Connection sqlSearch, int UID, String search, int before) {
ArrayList mids0 = new ArrayList(20);
-
+
PreparedStatement stmt = null;
ResultSet rs = null;
try {
@@ -652,7 +653,7 @@ public class MessagesQueries {
} finally {
Utils.finishSQL(rs, stmt);
}
-
+
ArrayList mids = new ArrayList(20);
if (mids0.size() > 0) {
try {
@@ -668,13 +669,13 @@ public class MessagesQueries {
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 {
@@ -684,7 +685,7 @@ public class MessagesQueries {
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);
@@ -706,7 +707,7 @@ public class MessagesQueries {
msg.Place.lat = rs.getDouble(15);
msg.Place.lon = rs.getDouble(16);
}
-
+
msgs.add(msg);
}
} catch (SQLException e) {
@@ -714,13 +715,13 @@ public class MessagesQueries {
} 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 {
@@ -740,7 +741,7 @@ public class MessagesQueries {
msg.TimeAgo = rs.getInt(6);
msg.TimestampString = rs.getString(7);
msg.AttachmentType = rs.getString(8);
-
+
replies.add(msg);
}
} catch (SQLException e) {
@@ -748,7 +749,7 @@ public class MessagesQueries {
} finally {
Utils.finishSQL(rs, stmt);
}
-
+
return replies;
}
}
--
cgit v1.2.3
From 10f1681919c312597a71be2597626daa4d3739be Mon Sep 17 00:00:00 2001
From: Ugnich Anton
Date: Wed, 26 Dec 2012 17:48:00 +0700
Subject: MessagesQueries.getPlace
---
src/com/juick/server/MessagesQueries.java | 27 +++++++++++++++++++++++++++
1 file changed, 27 insertions(+)
diff --git a/src/com/juick/server/MessagesQueries.java b/src/com/juick/server/MessagesQueries.java
index c17b9d3d..b2251048 100644
--- a/src/com/juick/server/MessagesQueries.java
+++ b/src/com/juick/server/MessagesQueries.java
@@ -306,6 +306,33 @@ public class MessagesQueries {
return mids;
}
+ public static ArrayList getPlace(Connection sql, int place_id, 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 ORDER BY message_id DESC LIMIT 20");
+ stmt.setInt(1, place_id);
+ stmt.setInt(2, before);
+ } else {
+ stmt = sql.prepareStatement("SELECT message_id FROM messages WHERE place_id=? AND privacy>0 ORDER BY message_id DESC LIMIT 20");
+ stmt.setInt(1, place_id);
+ }
+ 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(20);
PreparedStatement stmt = null;
--
cgit v1.2.3
From b74e6c267498e6fda56a5167346623bf55a8f01e Mon Sep 17 00:00:00 2001
From: Ugnich Anton
Date: Mon, 31 Dec 2012 16:34:51 +0700
Subject: MessagesQueries privacy
---
src/com/juick/server/MessagesQueries.java | 22 +++++++++++-----------
1 file changed, 11 insertions(+), 11 deletions(-)
diff --git a/src/com/juick/server/MessagesQueries.java b/src/com/juick/server/MessagesQueries.java
index b2251048..227b3fea 100644
--- a/src/com/juick/server/MessagesQueries.java
+++ b/src/com/juick/server/MessagesQueries.java
@@ -544,18 +544,18 @@ public class MessagesQueries {
return mids;
}
- public static ArrayList getUserBlog(Connection sql, int UID, int before) {
+ 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>=0 ORDER BY message_id DESC LIMIT 20");
+ 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>=0 ORDER BY message_id DESC LIMIT 20");
+ 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();
@@ -571,19 +571,19 @@ public class MessagesQueries {
return mids;
}
- public static ArrayList getUserTag(Connection sql, int UID, int TID, int before) {
+ 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>0 ORDER BY messages.message_id DESC LIMIT 20");
+ 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>0 ORDER BY messages.message_id DESC LIMIT 20");
+ 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);
}
@@ -627,18 +627,18 @@ public class MessagesQueries {
return mids;
}
- public static ArrayList getUserPhotos(Connection sql, int UID, int before) {
+ 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>=0 AND attach IS NOT NULL ORDER BY message_id DESC LIMIT 20");
+ 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>=0 AND attach IS NOT NULL ORDER BY message_id DESC LIMIT 20");
+ 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();
@@ -654,7 +654,7 @@ public class MessagesQueries {
return mids;
}
- public static ArrayList getUserSearch(Connection sql, Connection sqlSearch, int UID, String search, int before) {
+ public static ArrayList getUserSearch(Connection sql, Connection sqlSearch, int UID, String search, int privacy, int before) {
ArrayList mids0 = new ArrayList(20);
PreparedStatement stmt = null;
@@ -684,7 +684,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.convertArray2String(mids0) + ") AND privacy>=0 ORDER BY message_id DESC");
+ stmt = sql.prepareStatement("SELECT message_id FROM messages WHERE message_id IN (" + Utils.convertArray2String(mids0) + ") AND privacy>=" + privacy + " ORDER BY message_id DESC");
rs = stmt.executeQuery();
rs.beforeFirst();
while (rs.next()) {
--
cgit v1.2.3
From 917e44c66ee99f31b0ac655c56b598d71014652e Mon Sep 17 00:00:00 2001
From: Ugnich Anton
Date: Wed, 6 Mar 2013 18:25:50 +0700
Subject: MessagesQueries.getMessageTagsIDs MessagesQueries visitor_id
UserQueries.createUser
---
src/com/juick/server/MessagesQueries.java | 68 ++++++++++++++++++++++---------
src/com/juick/server/UserQueries.java | 24 +++++++++++
2 files changed, 73 insertions(+), 19 deletions(-)
diff --git a/src/com/juick/server/MessagesQueries.java b/src/com/juick/server/MessagesQueries.java
index 227b3fea..ad00b9d2 100644
--- a/src/com/juick/server/MessagesQueries.java
+++ b/src/com/juick/server/MessagesQueries.java
@@ -232,6 +232,28 @@ public class MessagesQueries {
return user;
}
+ 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();
@@ -254,17 +276,19 @@ public class MessagesQueries {
return users;
}
- public static ArrayList getAll(Connection sql, int before) {
+ public static ArrayList getAll(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 messages.message_id FROM messages WHERE messages.message_id AND messages.privacy>0 ORDER BY messages.message_id DESC LIMIT 20");
+ stmt = sql.prepareStatement("SELECT message_id FROM messages WHERE message_id AND (privacy>0 OR user_id=?) ORDER BY message_id DESC LIMIT 20");
stmt.setInt(1, before);
+ stmt.setInt(2, visitor_uid);
} else {
- stmt = sql.prepareStatement("SELECT messages.message_id FROM messages WHERE messages.privacy>0 ORDER BY messages.message_id DESC LIMIT 20");
+ stmt = sql.prepareStatement("SELECT message_id FROM messages WHERE (privacy>0 OR user_id=?) ORDER BY message_id DESC LIMIT 20");
+ stmt.setInt(1, visitor_uid);
}
rs = stmt.executeQuery();
rs.beforeFirst();
@@ -279,19 +303,21 @@ public class MessagesQueries {
return mids;
}
- public static ArrayList getTag(Connection sql, int tid, int before) {
+ public static ArrayList getTag(Connection sql, int tid, int visitor_uid, 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_tags.tag_id=? AND messages.message_id AND messages.privacy>0 ORDER BY messages.message_id DESC LIMIT 20");
+ stmt = sql.prepareStatement("SELECT messages.message_id FROM messages_tags INNER JOIN messages USING(message_id) WHERE messages_tags.tag_id=? AND messages.message_id AND (messages.privacy>0 OR messages.user_id=?) ORDER BY messages.message_id DESC LIMIT 20");
stmt.setInt(1, tid);
stmt.setInt(2, before);
+ stmt.setInt(3, visitor_uid);
} else {
- stmt = sql.prepareStatement("SELECT messages.message_id FROM messages_tags INNER JOIN messages USING(message_id) WHERE messages_tags.tag_id=? AND messages.privacy>0 ORDER BY messages.message_id DESC LIMIT 20");
+ stmt = sql.prepareStatement("SELECT messages.message_id FROM messages_tags INNER JOIN messages USING(message_id) WHERE messages_tags.tag_id=? AND (messages.privacy>0 OR messages.user_id=?) ORDER BY messages.message_id DESC LIMIT 20");
stmt.setInt(1, tid);
+ stmt.setInt(2, visitor_uid);
}
rs = stmt.executeQuery();
rs.beforeFirst();
@@ -306,19 +332,21 @@ public class MessagesQueries {
return mids;
}
- public static ArrayList getPlace(Connection sql, int place_id, int before) {
+ 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 ORDER BY message_id DESC LIMIT 20");
+ 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 ORDER BY message_id DESC LIMIT 20");
+ 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();
@@ -339,13 +367,13 @@ public class MessagesQueries {
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=-1 AND messages.user_id IN (SELECT user_id FROM wl_users WHERE wl_user_id=?)) AND message_id NOT IN (SELECT message_id FROM messages_tags WHERE tag_id IN (SELECT tag_id FROM bl_tags WHERE user_id=?)) ORDER BY message_id DESC LIMIT 20");
+ 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=?)) AND message_id NOT IN (SELECT message_id FROM messages_tags WHERE tag_id IN (SELECT tag_id FROM bl_tags WHERE user_id=?)) ORDER BY message_id DESC LIMIT 20");
stmt.setInt(1, uid);
stmt.setInt(2, before);
stmt.setInt(3, uid);
stmt.setInt(4, 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=-1 AND messages.user_id IN (SELECT user_id FROM wl_users WHERE wl_user_id=?)) AND message_id NOT IN (SELECT message_id FROM messages_tags WHERE tag_id IN (SELECT tag_id FROM bl_tags WHERE user_id=?)) ORDER BY message_id DESC LIMIT 20");
+ 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=?)) AND message_id NOT IN (SELECT message_id FROM messages_tags WHERE tag_id IN (SELECT tag_id FROM bl_tags WHERE user_id=?)) ORDER BY message_id DESC LIMIT 20");
stmt.setInt(1, uid);
stmt.setInt(2, uid);
stmt.setInt(3, uid);
@@ -475,17 +503,19 @@ public class MessagesQueries {
return mids;
}
- public static ArrayList getPhotos(Connection sql, int before) {
+ 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 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 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 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 ORDER BY message_id DESC LIMIT 20");
+ stmt.setInt(1, visitor_uid);
}
rs = stmt.executeQuery();
rs.beforeFirst();
@@ -507,11 +537,11 @@ public class MessagesQueries {
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 20");
+ 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 20");
+ 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();
@@ -528,7 +558,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.convertArray2String(mids0) + ") AND privacy>0 ORDER BY message_id DESC");
+ stmt = sql.prepareStatement("SELECT message_id FROM messages WHERE message_id IN (" + Utils.convertArray2String(mids0) + ") AND privacy>0 ORDER BY message_id DESC LIMIT 20");
rs = stmt.executeQuery();
rs.beforeFirst();
while (rs.next()) {
@@ -578,12 +608,12 @@ public class MessagesQueries {
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 = 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 = 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);
}
diff --git a/src/com/juick/server/UserQueries.java b/src/com/juick/server/UserQueries.java
index ff1d0e24..17873676 100644
--- a/src/com/juick/server/UserQueries.java
+++ b/src/com/juick/server/UserQueries.java
@@ -21,6 +21,7 @@ import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
+import java.sql.Statement;
import java.util.ArrayList;
import java.util.Random;
@@ -32,6 +33,29 @@ public class UserQueries {
static final String ABCDEF = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
+ public static int createUser(Connection sql, String username, String password, String lang) {
+ int uid = 0;
+
+ PreparedStatement stmt = null;
+ ResultSet rs = null;
+ try {
+ stmt = sql.prepareStatement("INSERT INTO users(nick,passw,lang) VALUES (?,?,?)", Statement.RETURN_GENERATED_KEYS);
+ stmt.setString(1, username);
+ stmt.setString(2, password);
+ stmt.setString(3, lang);
+ stmt.executeUpdate();
+ rs = stmt.getGeneratedKeys();
+ if (rs.first()) {
+ uid = rs.getInt(1);
+ }
+ } catch (SQLException e) {
+ System.err.println(e);
+ } finally {
+ Utils.finishSQL(rs, stmt);
+ }
+ return uid;
+ }
+
public static com.juick.User getUserByNick(Connection sql, String username) {
com.juick.User user = null;
--
cgit v1.2.3
From de81a033905d1c4cd18ac9b5af8a7f8fb853b121 Mon Sep 17 00:00:00 2001
From: Ugnich Anton
Date: Sun, 14 Apr 2013 06:44:35 +0700
Subject: PushQueries
---
src/com/juick/server/MessagesQueries.java | 4 +-
src/com/juick/server/PushQueries.java | 61 +++++++++++++++++++++++++++++++
src/com/juick/server/UserQueries.java | 12 ++++++
3 files changed, 75 insertions(+), 2 deletions(-)
create mode 100644 src/com/juick/server/PushQueries.java
diff --git a/src/com/juick/server/MessagesQueries.java b/src/com/juick/server/MessagesQueries.java
index ad00b9d2..42b45c24 100644
--- a/src/com/juick/server/MessagesQueries.java
+++ b/src/com/juick/server/MessagesQueries.java
@@ -283,11 +283,11 @@ 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=?) 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 lang!='fa' 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=?) ORDER BY message_id DESC LIMIT 20");
+ stmt = sql.prepareStatement("SELECT message_id FROM messages WHERE (privacy>0 OR user_id=?) AND lang!='fa' ORDER BY message_id DESC LIMIT 20");
stmt.setInt(1, visitor_uid);
}
rs = stmt.executeQuery();
diff --git a/src/com/juick/server/PushQueries.java b/src/com/juick/server/PushQueries.java
new file mode 100644
index 00000000..a532622a
--- /dev/null
+++ b/src/com/juick/server/PushQueries.java
@@ -0,0 +1,61 @@
+/*
+ * 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 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 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/com/juick/server/UserQueries.java b/src/com/juick/server/UserQueries.java
index 17873676..a9f00f94 100644
--- a/src/com/juick/server/UserQueries.java
+++ b/src/com/juick/server/UserQueries.java
@@ -53,6 +53,18 @@ public class UserQueries {
} finally {
Utils.finishSQL(rs, stmt);
}
+
+ PreparedStatement stmt2 = null;
+ try {
+ stmt2 = sql.prepareStatement("INSERT INTO useroptions(user_id) VALUES (?)");
+ stmt2.setInt(1, uid);
+ stmt2.executeUpdate();
+ } catch (SQLException e) {
+ System.err.println(e);
+ } finally {
+ Utils.finishSQL(null, stmt);
+ }
+
return uid;
}
--
cgit v1.2.3
From a1ecda62eef3b802dbfa044f75ec0050de6ba75e Mon Sep 17 00:00:00 2001
From: Ugnich Anton
Date: Thu, 20 Jun 2013 18:22:12 +0700
Subject: SQLHelpers.getArrayInteger Users.getUserRead Users.getUserReaders
---
src/com/juick/server/MessagesQueries.java | 8 +++----
src/com/juick/server/SQLHelpers.java | 40 +++++++++++++++++++++++++++++++
src/com/juick/server/UserQueries.java | 10 +++++++-
3 files changed, 53 insertions(+), 5 deletions(-)
create mode 100644 src/com/juick/server/SQLHelpers.java
diff --git a/src/com/juick/server/MessagesQueries.java b/src/com/juick/server/MessagesQueries.java
index 42b45c24..55fc3898 100644
--- a/src/com/juick/server/MessagesQueries.java
+++ b/src/com/juick/server/MessagesQueries.java
@@ -283,11 +283,11 @@ 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 lang!='fa' 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 lang='ru' 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 lang!='fa' ORDER BY message_id DESC LIMIT 20");
+ stmt = sql.prepareStatement("SELECT message_id FROM messages WHERE (privacy>0 OR user_id=?) AND lang='ru' ORDER BY message_id DESC LIMIT 20");
stmt.setInt(1, visitor_uid);
}
rs = stmt.executeQuery();
@@ -367,13 +367,13 @@ public class MessagesQueries {
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=?)) AND message_id NOT IN (SELECT message_id FROM messages_tags WHERE tag_id IN (SELECT tag_id FROM bl_tags WHERE user_id=?)) ORDER BY message_id DESC LIMIT 20");
+ 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=?))) AND message_id NOT IN (SELECT message_id FROM messages_tags WHERE tag_id IN (SELECT tag_id FROM bl_tags WHERE user_id=?)) ORDER BY message_id DESC LIMIT 20");
stmt.setInt(1, uid);
stmt.setInt(2, before);
stmt.setInt(3, uid);
stmt.setInt(4, 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=?)) AND message_id NOT IN (SELECT message_id FROM messages_tags WHERE tag_id IN (SELECT tag_id FROM bl_tags WHERE user_id=?)) ORDER BY message_id DESC LIMIT 20");
+ 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=?))) AND message_id NOT IN (SELECT message_id FROM messages_tags WHERE tag_id IN (SELECT tag_id FROM bl_tags WHERE user_id=?)) ORDER BY message_id DESC LIMIT 20");
stmt.setInt(1, uid);
stmt.setInt(2, uid);
stmt.setInt(3, uid);
diff --git a/src/com/juick/server/SQLHelpers.java b/src/com/juick/server/SQLHelpers.java
new file mode 100644
index 00000000..dd83a915
--- /dev/null
+++ b/src/com/juick/server/SQLHelpers.java
@@ -0,0 +1,40 @@
+/*
+ * 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 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/com/juick/server/UserQueries.java b/src/com/juick/server/UserQueries.java
index a9f00f94..652809d6 100644
--- a/src/com/juick/server/UserQueries.java
+++ b/src/com/juick/server/UserQueries.java
@@ -64,7 +64,7 @@ public class UserQueries {
} finally {
Utils.finishSQL(null, stmt);
}
-
+
return uid;
}
@@ -358,6 +358,14 @@ public class UserQueries {
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 getUserReaders(Connection sql, int uid) {
+ return SQLHelpers.getArrayInteger(sql, "SELECT suser_id FROM subscr_users WHERE user_id=?", uid);
+ }
+
public static int getStatsIRead(Connection sql, int uid) {
int ret = 0;
PreparedStatement stmt = null;
--
cgit v1.2.3
From 505feda055a1f5c59aea53f26680bbbbb0553a0a Mon Sep 17 00:00:00 2001
From: Ugnich Anton
Date: Thu, 20 Jun 2013 18:26:34 +0700
Subject: SQLHelpers.getInt
---
src/com/juick/server/SQLHelpers.java | 19 ++++++++++
src/com/juick/server/UserQueries.java | 68 +++--------------------------------
2 files changed, 23 insertions(+), 64 deletions(-)
diff --git a/src/com/juick/server/SQLHelpers.java b/src/com/juick/server/SQLHelpers.java
index dd83a915..7879c244 100644
--- a/src/com/juick/server/SQLHelpers.java
+++ b/src/com/juick/server/SQLHelpers.java
@@ -16,6 +16,25 @@ import java.util.ArrayList;
*/
public class SQLHelpers {
+ 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 ArrayList getArrayInteger(Connection sql, String query, int param) {
ArrayList ret = new ArrayList();
diff --git a/src/com/juick/server/UserQueries.java b/src/com/juick/server/UserQueries.java
index 652809d6..e44017fa 100644
--- a/src/com/juick/server/UserQueries.java
+++ b/src/com/juick/server/UserQueries.java
@@ -367,78 +367,18 @@ public class UserQueries {
}
public static int getStatsIRead(Connection sql, int uid) {
- int ret = 0;
- PreparedStatement stmt = null;
- ResultSet rs = null;
- try {
- stmt = sql.prepareStatement("SELECT COUNT(*) FROM subscr_users WHERE suser_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;
+ return SQLHelpers.getInt(sql, "SELECT COUNT(*) FROM subscr_users WHERE suser_id=?", uid, 0);
}
public static int getStatsMyReaders(Connection sql, int uid) {
- int ret = 0;
- PreparedStatement stmt = null;
- ResultSet rs = null;
- try {
- stmt = sql.prepareStatement("SELECT COUNT(*) FROM subscr_users 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;
+ return SQLHelpers.getInt(sql, "SELECT COUNT(*) FROM subscr_users WHERE user_id=?", uid, 0);
}
public static int getStatsMessages(Connection sql, int uid) {
- int ret = 0;
- PreparedStatement stmt = null;
- ResultSet rs = null;
- try {
- stmt = sql.prepareStatement("SELECT COUNT(*) FROM messages 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;
+ return SQLHelpers.getInt(sql, "SELECT COUNT(*) FROM messages WHERE user_id=?", uid, 0);
}
public static int getStatsReplies(Connection sql, int uid) {
- int ret = 0;
- PreparedStatement stmt = null;
- ResultSet rs = null;
- try {
- stmt = sql.prepareStatement("SELECT COUNT(*) FROM replies 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;
+ return SQLHelpers.getInt(sql, "SELECT COUNT(*) FROM replies WHERE user_id=?", uid, 0);
}
}
--
cgit v1.2.3
From 781648961858a5180098954fc32463c32c88eaa6 Mon Sep 17 00:00:00 2001
From: Ugnich Anton
Date: Thu, 20 Jun 2013 18:30:54 +0700
Subject: User.getUsersByID
---
src/com/juick/server/UserQueries.java | 24 ++++++++++++++++++++++++
1 file changed, 24 insertions(+)
diff --git a/src/com/juick/server/UserQueries.java b/src/com/juick/server/UserQueries.java
index e44017fa..d6f6045c 100644
--- a/src/com/juick/server/UserQueries.java
+++ b/src/com/juick/server/UserQueries.java
@@ -90,6 +90,30 @@ public class UserQueries {
return user;
}
+ public static ArrayList