1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
|
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package com.juick.server;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
/**
*
* @author ugnich
*/
public class SubscriptionsQueries {
public static ArrayList<String> getJIDSubscribedToUser(Connection sql, int uid, boolean friendsonly) {
ArrayList<String> jids = new ArrayList<String>();
PreparedStatement stmt = null;
ResultSet rs = null;
try {
if (friendsonly == false) {
stmt = sql.prepareStatement("SELECT jids.jid FROM subscr_users INNER JOIN jids ON (subscr_users.user_id=? AND subscr_users.suser_id=jids.user_id) WHERE jids.active=1");
stmt.setInt(1, uid);
} else {
stmt = sql.prepareStatement("SELECT jids.jid FROM subscr_users INNER JOIN jids ON (subscr_users.user_id=? AND subscr_users.suser_id=jids.user_id) WHERE jids.active=1 AND jids.user_id IN (SELECT wl_user_id FROM wl_users WHERE user_id=?)");
stmt.setInt(1, uid);
stmt.setInt(2, uid);
}
rs = stmt.executeQuery();
rs.beforeFirst();
while (rs.next()) {
jids.add(rs.getString(1));
}
} catch (SQLException e) {
System.err.println(e);
} finally {
Utils.finishSQL(rs, stmt);
}
return jids;
}
public static ArrayList<String> getJIDSubscribedToUserAndTags(Connection sql, int uid, int mid) {
ArrayList<String> jids = new ArrayList<String>();
PreparedStatement stmt = null;
ResultSet rs = null;
try {
stmt = sql.prepareStatement("SELECT DISTINCT jid FROM jids WHERE active=1 AND user_id!=? AND user_id IN (SELECT suser_id FROM subscr_users WHERE user_id=? UNION SELECT suser_id FROM subscr_tags INNER JOIN messages_tags ON (messages_tags.message_id=? AND subscr_tags.tag_id=messages_tags.tag_id))");
stmt.setInt(1, uid);
stmt.setInt(2, uid);
stmt.setInt(3, mid);
rs = stmt.executeQuery();
rs.beforeFirst();
while (rs.next()) {
jids.add(rs.getString(1));
}
} catch (SQLException e) {
System.err.println(e);
} finally {
Utils.finishSQL(rs, stmt);
}
return jids;
}
public static ArrayList<String> getJIDSubscribedToComments(Connection sql, int mid, int ignore_uid) {
ArrayList<String> jids = new ArrayList<String>();
PreparedStatement stmt = null;
ResultSet rs = null;
try {
stmt = sql.prepareStatement("SELECT jids.jid FROM subscr_messages INNER JOIN jids ON (subscr_messages.message_id=? AND subscr_messages.suser_id=jids.user_id) WHERE jids.user_id!=? AND jids.active=1");
stmt.setInt(1, mid);
stmt.setInt(2, ignore_uid);
rs = stmt.executeQuery();
rs.beforeFirst();
while (rs.next()) {
jids.add(rs.getString(1));
}
} catch (SQLException e) {
System.err.println(e);
} finally {
Utils.finishSQL(rs, stmt);
}
return jids;
}
}
|