diff options
Diffstat (limited to 'src/main/java/com/juick/service/UserServiceImpl.java')
-rw-r--r-- | src/main/java/com/juick/service/UserServiceImpl.java | 19 |
1 files changed, 8 insertions, 11 deletions
diff --git a/src/main/java/com/juick/service/UserServiceImpl.java b/src/main/java/com/juick/service/UserServiceImpl.java index 77fb2e72..e30be17b 100644 --- a/src/main/java/com/juick/service/UserServiceImpl.java +++ b/src/main/java/com/juick/service/UserServiceImpl.java @@ -29,6 +29,7 @@ import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Value; import org.springframework.dao.DataIntegrityViolationException; import org.springframework.dao.EmptyResultDataAccessException; +import org.springframework.jdbc.UncategorizedSQLException; import org.springframework.jdbc.core.RowMapper; import org.springframework.jdbc.core.namedparam.MapSqlParameterSource; import org.springframework.jdbc.core.simple.SimpleJdbcInsert; @@ -38,6 +39,7 @@ import org.springframework.transaction.annotation.Transactional; import java.net.URI; import java.sql.*; import java.time.Instant; +import java.time.OffsetDateTime; import java.time.ZoneOffset; import java.util.*; @@ -46,15 +48,10 @@ import java.util.*; */ @Repository public class UserServiceImpl extends BaseJdbcService implements UserService { - private static final Logger logger = LoggerFactory.getLogger("UserService"); - @Value("${juick.admin_users:}") List<String> adminUsers; - @Value("#{new Boolean('${spring.sql.init.platform}' == 'sqlserver')}") - private boolean omitRecursiveKeyword; - - private static class UserMapper implements RowMapper<User> { + private class UserMapper implements RowMapper<User> { @Override public User mapRow(@Nonnull ResultSet rs, int rowNum) throws SQLException { User user = new User(); @@ -63,7 +60,7 @@ public class UserServiceImpl extends BaseJdbcService implements UserService { user.setName(rs.getString(2)); user.setCredentials(rs.getString(3)); user.setBanned(rs.getInt(4) > 0); - Timestamp seen = rs.getTimestamp(5); + OffsetDateTime seen = UserServiceImpl.this.getOffsetDateTime(rs, 5); if (seen != null) { user.setSeen(seen.toInstant()); } @@ -105,7 +102,7 @@ public class UserServiceImpl extends BaseJdbcService implements UserService { getJdbcTemplate().update("INSERT INTO subscr_users(user_id, suser_id) VALUES (2, ?)", uid); return getUserByUID(uid); } - } catch (DataIntegrityViolationException e) { + } catch (DataIntegrityViolationException | UncategorizedSQLException e) { throw new UsernameTakenException(); } return Optional.empty(); @@ -446,15 +443,14 @@ public class UserServiceImpl extends BaseJdbcService implements UserService { "SELECT users.id,users.nick FROM (subscr_users " + "INNER JOIN users_subscr ON (subscr_users.suser_id=? " + "AND subscr_users.user_id=users_subscr.user_id)) INNER JOIN users " + - "ON subscr_users.user_id=users.id ORDER BY cnt OFFSET 0 ROWS FETCH NEXT ? ROWS ONLY", + "ON subscr_users.user_id=users.id ORDER BY cnt " + limit(cnt), (rs, num) -> { User u = new User(); u.setUid(rs.getInt(1)); u.setName(rs.getString(2)); return u; }, - uid, - cnt); + uid); } @Transactional(readOnly = true) @@ -593,6 +589,7 @@ public class UserServiceImpl extends BaseJdbcService implements UserService { } @Override + @Transactional public void updateLastSeen(User user) { getJdbcTemplate().update("UPDATE users SET last_seen=? WHERE id=?", Instant.now().atOffset(ZoneOffset.UTC), user.getUid()); } |