aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Vitaly Takmazov2016-05-19 23:22:07 +0300
committerGravatar Vitaly Takmazov2016-05-19 23:22:07 +0300
commitb633724c75081eb05b70ceee74636f19576a4483 (patch)
tree36ddf50cf4a8bac92b9b8b4ff603147f5c7c9cc3
parenta41109795f6f6a3803d52606df9bd1a0da641f43 (diff)
optional getUserByUID
-rw-r--r--src/main/java/com/juick/server/UserQueries.java11
1 files changed, 7 insertions, 4 deletions
diff --git a/src/main/java/com/juick/server/UserQueries.java b/src/main/java/com/juick/server/UserQueries.java
index af7997ea..068f0c4b 100644
--- a/src/main/java/com/juick/server/UserQueries.java
+++ b/src/main/java/com/juick/server/UserQueries.java
@@ -92,10 +92,13 @@ public class UserQueries {
return uid;
}
- public static User getUserByUID(JdbcTemplate sql, int uid) {
- return sql.queryForObject("SELECT id, nick,banned FROM users WHERE id=?",
- new Object[] {uid},
- new UserMapper());
+ public static Optional<User> getUserByUID(JdbcTemplate sql, int uid) {
+ try {
+ return Optional.of(sql.queryForObject("SELECT id, nick,banned FROM users WHERE id=?",
+ new UserMapper(), uid));
+ } catch (EmptyResultDataAccessException e) {
+ return Optional.empty();
+ }
}
public static User getUserByName(JdbcTemplate sql, String username) {