@SuppressWarnings("deprecation") @Override public Future<int[]> findAll(int playerId) { return worker.submit( () -> { try (Connection connection = dataSource.getConnection(); PreparedStatement statement = connection.prepareStatement(FIND_NOTIFS_BY_PLAYER_SQL)) { statement.setInt(1, playerId); try (ResultSet resultSet = statement.executeQuery()) { if (!resultSet.last()) { return new int[0]; } int[] ids = new int[resultSet.getRow() + 1]; resultSet.beforeFirst(); for (int i = 0; i < ids.length && resultSet.next(); i++) { ids[i] = resultSet.getInt(1); } return ids; } } }); }
@Override public Future<Unit> removeAll(int playerId) { return worker.cast( () -> { try (Connection co = dataSource.getConnection()) { try (PreparedStatement s = co.prepareStatement("delete from player_notifs where player_id=?")) { s.setInt(1, playerId); s.executeUpdate(); } } }); }
@Override public Future<Unit> save(int playerId, int notifId) { return worker.cast( () -> { try (Connection co = dataSource.getConnection()) { try (PreparedStatement s = co.prepareStatement( "insert into player_notifs(player_id, notif_id) values(?, ?)")) { s.setInt(1, playerId); s.setInt(2, notifId); s.executeUpdate(); } } }); }