aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/com/juick/server/SubscriptionsQueries.java
diff options
context:
space:
mode:
authorGravatar Vitaly Takmazov2016-06-27 13:15:57 +0300
committerGravatar Vitaly Takmazov2016-06-27 13:15:57 +0300
commit6362eab34390b187944c7e3c12eb444e2fb2c455 (patch)
tree80c04e3a3e6fdfee25eaac03abd9a049004fbe3c /src/main/java/com/juick/server/SubscriptionsQueries.java
parent9e740f48cca7332c67a165c6cf60e09bc549e686 (diff)
more spring-jdbc
Diffstat (limited to 'src/main/java/com/juick/server/SubscriptionsQueries.java')
-rw-r--r--src/main/java/com/juick/server/SubscriptionsQueries.java38
1 files changed, 9 insertions, 29 deletions
diff --git a/src/main/java/com/juick/server/SubscriptionsQueries.java b/src/main/java/com/juick/server/SubscriptionsQueries.java
index b271435b..feebfb22 100644
--- a/src/main/java/com/juick/server/SubscriptionsQueries.java
+++ b/src/main/java/com/juick/server/SubscriptionsQueries.java
@@ -8,15 +8,10 @@ import com.juick.User;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.util.StringUtils;
-import java.sql.Connection;
-import java.sql.PreparedStatement;
-import java.sql.ResultSet;
-import java.sql.SQLException;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
-import java.util.logging.Level;
import java.util.logging.Logger;
/**
@@ -27,31 +22,16 @@ public class SubscriptionsQueries {
private static final Logger logger = Logger.getLogger(SubscriptionsQueries.class.getName());
- public static List<String> getJIDSubscribedToUser(Connection sql, int uid, boolean friendsonly) {
- List<String> jids = new ArrayList<>();
-
- PreparedStatement stmt = null;
- ResultSet rs = null;
- try {
- if (friendsonly == false) {
- stmt = sql.prepareStatement("SELECT jids.jid FROM subscr_users INNER JOIN jids ON (subscr_users.user_id=? AND subscr_users.suser_id=jids.user_id) WHERE jids.active=1");
- stmt.setInt(1, uid);
- } else {
- stmt = sql.prepareStatement("SELECT jids.jid FROM subscr_users INNER JOIN jids ON (subscr_users.user_id=? AND subscr_users.suser_id=jids.user_id) WHERE jids.active=1 AND jids.user_id IN (SELECT wl_user_id FROM wl_users WHERE user_id=?)");
- stmt.setInt(1, uid);
- stmt.setInt(2, uid);
- }
- rs = stmt.executeQuery();
- rs.beforeFirst();
- while (rs.next()) {
- jids.add(rs.getString(1));
- }
- } catch (SQLException e) {
- logger.log(Level.SEVERE, "sql exception", e);
- } finally {
- Utils.finishSQL(rs, stmt);
+ public static List<String> getJIDSubscribedToUser(JdbcTemplate sql, int uid, boolean friendsonly) {
+ if (friendsonly == false) {
+ return sql.queryForList("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",
+ String.class, uid);
+ } else {
+ return sql.queryForList("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=?)", String.class, uid, uid);
}
- return jids;
}
public static List<User> getSubscribedUsers(JdbcTemplate sql, int uid, int mid) {