aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/com/juick/server/UserQueries.java
diff options
context:
space:
mode:
authorGravatar Vitaly Takmazov2016-01-16 23:36:20 +0300
committerGravatar Vitaly Takmazov2016-01-16 23:36:20 +0300
commitde32a6e9e994b830fdf0768d0825559a85d19654 (patch)
treeeb33c84a3476055e7bfd312476d28f77155e07e7 /src/main/java/com/juick/server/UserQueries.java
parent279765857724cf35addc0e3f5e7180a8724d23b9 (diff)
message queries almost done
Diffstat (limited to 'src/main/java/com/juick/server/UserQueries.java')
-rw-r--r--src/main/java/com/juick/server/UserQueries.java42
1 files changed, 15 insertions, 27 deletions
diff --git a/src/main/java/com/juick/server/UserQueries.java b/src/main/java/com/juick/server/UserQueries.java
index 5588d8e4..21373b7d 100644
--- a/src/main/java/com/juick/server/UserQueries.java
+++ b/src/main/java/com/juick/server/UserQueries.java
@@ -18,6 +18,7 @@
package com.juick.server;
import com.juick.User;
+import org.springframework.dao.EmptyResultDataAccessException;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.jdbc.support.GeneratedKeyHolder;
@@ -46,9 +47,9 @@ public class UserQueries {
@Override
public User mapRow(ResultSet rs, int rowNum) throws SQLException {
User user = new User();
- user.setUID(rs.getInt("id"));
- user.setUName(rs.getString("nick"));
- user.Banned = rs.getBoolean("banned");
+ user.setUID(rs.getInt(1));
+ user.setUName(rs.getString(2));
+ user.Banned = rs.getBoolean(3);
return user;
}
}
@@ -88,9 +89,13 @@ public class UserQueries {
}
public static User getUserByName(JdbcTemplate sql, String username) {
- return sql.queryForObject("SELECT id,nick,banned FROM users WHERE nick=?",
- new Object[] {username},
- new UserMapper());
+ try {
+ return sql.queryForObject("SELECT id,nick,banned FROM users WHERE nick=?",
+ new Object[]{username},
+ new UserMapper());
+ } catch (EmptyResultDataAccessException e) {
+ return null;
+ }
}
public static User getUserByJID(JdbcTemplate sql, String jid) {
@@ -107,8 +112,7 @@ public class UserQueries {
public static List<User> getUsersByID(JdbcTemplate sql, List<Integer> uids) {
return sql.query("SELECT id,nick,banned FROM users WHERE id IN (" + Utils.convertArrayInt2String(uids) + ")",
- new UserMapper(),
- uids.toArray());
+ new UserMapper());
}
public static boolean fillUsersByID(JdbcTemplate sql, List<User> users) {
@@ -262,25 +266,9 @@ 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) {
- LOGGER.log(Level.SEVERE, "sql exception", e);
- } finally {
- Utils.finishSQL(rs, stmt);
- }
- return ret;
+ public static boolean isInWL(JdbcTemplate sql, int uid, int check) {
+ return sql.queryForObject("SELECT 1 FROM wl_users WHERE user_id=? AND wl_user_id=?",
+ new Object[] {uid, check}, Integer.class) == 1;
}
public static boolean isInBL(Connection sql, int uid, int check) {