aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/com
diff options
context:
space:
mode:
authorGravatar Vitaly Takmazov2016-01-26 02:04:46 +0300
committerGravatar Vitaly Takmazov2016-01-26 02:04:46 +0300
commit8a77f7d91311f8c4d8ef026dacb4abbe0fa764d1 (patch)
tree49ca57fb5669e75809bd3c3c80065a8d55be7e08 /src/main/java/com
parent8ae5d9e3ce643bf0b8488c4566eff133b2cb2f11 (diff)
refactoring
Diffstat (limited to 'src/main/java/com')
-rw-r--r--src/main/java/com/juick/server/MessagesQueries.java21
-rw-r--r--src/main/java/com/juick/server/UserQueries.java25
2 files changed, 26 insertions, 20 deletions
diff --git a/src/main/java/com/juick/server/MessagesQueries.java b/src/main/java/com/juick/server/MessagesQueries.java
index 422cfe7d..c4919a8d 100644
--- a/src/main/java/com/juick/server/MessagesQueries.java
+++ b/src/main/java/com/juick/server/MessagesQueries.java
@@ -349,31 +349,30 @@ public class MessagesQueries {
}
public static List<Integer> getMyFeed(JdbcTemplate sql, int uid, int before) {
- List<Integer> mids = new ArrayList<>(40);
+ List<Integer> mids;
if (before > 0) {
mids = sql.queryForList("SELECT message_id FROM messages " +
"INNER JOIN subscr_users ON (subscr_users.suser_id=? AND subscr_users.user_id=messages.user_id) " +
"WHERE message_id<? AND (privacy>=0 OR (privacy>=-2 AND privacy<=-1 AND messages.user_id " +
"IN (SELECT user_id FROM wl_users WHERE wl_user_id=?))) ORDER BY message_id DESC LIMIT 20",
- Integer.class, new Object[]{uid, before, uid});
+ Integer.class, uid, before, uid);
} else {
mids = sql.queryForList("SELECT message_id FROM messages " +
"INNER JOIN subscr_users ON (subscr_users.suser_id=? " +
"AND subscr_users.user_id=messages.user_id) " +
"WHERE (privacy>=0 OR (privacy>=-2 AND privacy<=-1 AND messages.user_id " +
"IN (SELECT user_id FROM wl_users WHERE wl_user_id=?))) ORDER BY message_id DESC LIMIT 20",
- Integer.class, new Object[]{uid, uid});
+ Integer.class, uid, uid);
}
if (before > 0) {
mids.addAll(sql.queryForList("SELECT message_id FROM messages " +
"WHERE user_id=? AND message_id<? ORDER BY message_id DESC LIMIT 20", Integer.class,
- new Object[]{uid, before}));
+ uid, before));
} else {
mids.addAll(sql.queryForList("SELECT message_id FROM messages " +
- "WHERE user_id=? ORDER BY message_id DESC LIMIT 20", Integer.class,
- new Object[]{uid}));
+ "WHERE user_id=? ORDER BY message_id DESC LIMIT 20", Integer.class, uid));
}
Collections.sort(mids, Collections.reverseOrder());
@@ -399,10 +398,10 @@ public class MessagesQueries {
public static List<Integer> getDiscussions(JdbcTemplate sql, int uid, int before) {
if (before > 0) {
return sql.queryForList("SELECT message_id FROM subscr_messages WHERE suser_id=? AND message_id<? " +
- "ORDER BY message_id DESC LIMIT 20", new Object[]{uid, before}, Integer.class);
+ "ORDER BY message_id DESC LIMIT 20", Integer.class, uid, before);
} else {
return sql.queryForList("SELECT message_id FROM subscr_messages WHERE suser_id=? " +
- "ORDER BY message_id DESC LIMIT 20", new Object[]{uid}, Integer.class);
+ "ORDER BY message_id DESC LIMIT 20", Integer.class, uid);
}
}
@@ -410,11 +409,11 @@ public class MessagesQueries {
if (before > 0) {
return sql.queryForList("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", new Object[]{uid, before}, Integer.class);
+ "ORDER BY message_id DESC LIMIT 20", Integer.class, uid, before);
} else {
return sql.queryForList("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", new Object[]{uid}, Integer.class);
+ "ORDER BY message_id DESC LIMIT 20", Integer.class, uid);
}
}
@@ -422,7 +421,7 @@ public class MessagesQueries {
if (before > 0) {
return sql.queryForList("SELECT message_id FROM messages WHERE message_id<? AND privacy>0 " +
- "AND popular>0 ORDER BY message_id DESC LIMIT 20", new Object[] {before}, Integer.class);
+ "AND popular>0 ORDER BY message_id DESC LIMIT 20", Integer.class, before);
} else {
return sql.queryForList("SELECT message_id FROM messages WHERE privacy>0 " +
"AND popular>0 ORDER BY message_id DESC LIMIT 20", Integer.class);
diff --git a/src/main/java/com/juick/server/UserQueries.java b/src/main/java/com/juick/server/UserQueries.java
index 948b42d4..226e21b1 100644
--- a/src/main/java/com/juick/server/UserQueries.java
+++ b/src/main/java/com/juick/server/UserQueries.java
@@ -100,14 +100,12 @@ public class UserQueries {
public static User getUserByJID(JdbcTemplate sql, String jid) {
return sql.queryForObject("SELECT id,nick,banned FROM users WHERE id=(SELECT user_id FROM jids WHERE jid=?)",
- new Object[] {jid},
- new UserMapper());
+ new UserMapper(), jid);
}
public static List<User> getUsersByName(JdbcTemplate sql, List<String> unames) {
- return sql.query("SELECT id,nick,banned FROM users WHERE id=(SELECT user_id FROM jids WHERE jid=?)",
- new UserMapper(),
- unames.toArray());
+ return sql.query("SELECT id,nick FROM users WHERE nick IN (" + Utils.convertArrayString2String(unames) + ")",
+ new UserMapper());
}
public static List<User> getUsersByID(JdbcTemplate sql, List<Integer> uids) {
@@ -204,10 +202,19 @@ public class UserQueries {
}
public static int checkPassword(JdbcTemplate sql, String username, String password) {
- String realPassword = sql.queryForObject("SELECT passw FROM users WHERE nick=?", String.class, username);
- if (realPassword.equals(password)) {
- return UserQueries.getUserByName(sql, username).getUID();
- } else {
+ try {
+ String realPassword = sql.queryForObject("SELECT passw FROM users WHERE nick=?", String.class, username);
+ if (realPassword.equals(password)) {
+ User user = UserQueries.getUserByName(sql, username);
+ if (user != null) {
+ return user.getUID();
+ } else {
+ return -1;
+ }
+ } else {
+ return -1;
+ }
+ } catch (EmptyResultDataAccessException e) {
return -1;
}
}