From b633724c75081eb05b70ceee74636f19576a4483 Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Thu, 19 May 2016 23:22:07 +0300 Subject: optional getUserByUID --- src/main/java/com/juick/server/UserQueries.java | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'src/main') 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 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) { -- cgit v1.2.3