diff options
author | 2016-07-11 10:16:36 +0300 | |
---|---|---|
committer | 2016-07-11 10:16:36 +0300 | |
commit | 7eb3b141e5e4e719e1ef77ea06b6bac7610ae913 (patch) | |
tree | 1573abb9b47f5001053ed07b8ba9164c8fc5a188 /juick-core/src/main/java/com/juick/server/UserQueries.java | |
parent | f0a60dd95eff153c022bca0c71fed39b901dd547 (diff) |
cleanup sql
Diffstat (limited to 'juick-core/src/main/java/com/juick/server/UserQueries.java')
-rw-r--r-- | juick-core/src/main/java/com/juick/server/UserQueries.java | 33 |
1 files changed, 20 insertions, 13 deletions
diff --git a/juick-core/src/main/java/com/juick/server/UserQueries.java b/juick-core/src/main/java/com/juick/server/UserQueries.java index db380d7a..eb2918c0 100644 --- a/juick-core/src/main/java/com/juick/server/UserQueries.java +++ b/juick-core/src/main/java/com/juick/server/UserQueries.java @@ -118,7 +118,7 @@ public class UserQueries { public static List<User> getUsersByName(JdbcTemplate sql, List<String> unames) { if (!unames.isEmpty()) { - return sql.query("SELECT id,nick,banned FROM users WHERE nick IN (" + Utils.convertArrayString2String(unames) + ")", + return sql.query("SELECT id,nick,banned FROM users WHERE nick IN (" + StringUtils.arrayToCommaDelimitedString(unames.toArray()) + ")", new UserMapper()); } return Collections.emptyList(); @@ -126,7 +126,7 @@ public class UserQueries { public static List<User> getUsersByID(JdbcTemplate sql, List<Integer> uids) { if (!uids.isEmpty()) { - return sql.query("SELECT id,nick,banned FROM users WHERE id IN (" + Utils.convertArrayInt2String(uids) + ")", + return sql.query("SELECT id,nick,banned FROM users WHERE id IN (" + StringUtils.arrayToCommaDelimitedString(uids.toArray()) + ")", new UserMapper()); } return Collections.emptyList(); @@ -156,16 +156,19 @@ public class UserQueries { } public static List<com.juick.User> getUsersByJID(JdbcTemplate sql, List<String> jids) { - return sql.query("SELECT users.id,users.nick,jids.jid FROM users " - + "INNER JOIN jids ON jids.user_id=users.id " - + "WHERE jids.jid IN (" + Utils.convertArrayString2String(jids) + ")", - (rs, rowNum) -> { - com.juick.User user = new com.juick.User(); - user.setUID(rs.getInt(1)); - user.setUName(rs.getString(2)); - user.setJID(rs.getString(3)); - return user; - }); + if (!jids.isEmpty()) { + return sql.query("SELECT users.id,users.nick,jids.jid FROM users " + + "INNER JOIN jids ON jids.user_id=users.id " + + "WHERE jids.jid IN (" + StringUtils.arrayToCommaDelimitedString(jids.toArray()) + ")", + (rs, rowNum) -> { + com.juick.User user = new com.juick.User(); + user.setUID(rs.getInt(1)); + user.setUName(rs.getString(2)); + user.setJID(rs.getString(3)); + return user; + }); + } + return Collections.emptyList(); } public static List<String> getJIDsbyUID(JdbcTemplate sql, int uid) { @@ -173,7 +176,11 @@ public class UserQueries { } public static int getUIDbyJID(JdbcTemplate sql, String jid) { - return sql.queryForObject("SELECT user_id FROM jids WHERE jid=?", Integer.class, jid); + try { + return sql.queryForObject("SELECT user_id FROM jids WHERE jid=?", Integer.class, jid); + } catch (EmptyResultDataAccessException e) { + return 0; + } } public static int getUIDbyName(JdbcTemplate sql, String uname) { |