Skip to content

Commit

Permalink
Switch from DataAccessUtils.requiredSingleResult to `nullableSingle…
Browse files Browse the repository at this point in the history
…Result`.

Closes #1514
  • Loading branch information
mp911de committed Aug 8, 2024
1 parent 55286db commit 728a83b
Show file tree
Hide file tree
Showing 8 changed files with 16 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -504,7 +504,7 @@ CompletableFuture<Long> doCount(Query query, Class<?> entityClass, CqlIdentifier

SingleColumnRowMapper<Long> mapper = SingleColumnRowMapper.newInstance(Long.class);

Row row = DataAccessUtils.requiredSingleResult(Streamable.of(it.currentPage()).toList());
Row row = DataAccessUtils.nullableSingleResult(Streamable.of(it.currentPage()).toList());
return mapper.mapRow(row, 0);
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -846,7 +846,7 @@ private <T> List<T> doQuery(Statement<?> statement, RowMapper<T> rowMapper) {
}

private <T> T doQueryForObject(Statement<?> statement, Class<T> resultType) {
return DataAccessUtils.requiredSingleResult(doQuery(statement, SingleColumnRowMapper.newInstance(resultType)));
return DataAccessUtils.nullableSingleResult(doQuery(statement, SingleColumnRowMapper.newInstance(resultType)));
}

private <T> Stream<T> doQueryForStream(Statement<?> statement, RowMapper<T> rowMapper) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -502,7 +502,7 @@ Mono<Long> doCount(Query query, Class<?> entityClass, CqlIdentifier tableName) {
Mono<Long> mono = doExecuteAndFlatMap(count.build(), rs -> rs.rows() //
.map(it -> mapper.mapRow(it, 0)) //
.buffer() //
.map(DataAccessUtils::requiredSingleResult).next());
.map(DataAccessUtils::nullableSingleResult).next());

return mono.switchIfEmpty(Mono.just(0L));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ public <T> CompletableFuture<T> queryForObject(String cql, RowMapper<T> rowMappe

CompletableFuture<List<T>> results = query(cql, newAsyncResultSetExtractor(rowMapper));

return results.thenApply(DataAccessUtils::requiredSingleResult);
return results.thenApply(DataAccessUtils::nullableSingleResult);
}

@Override
Expand Down Expand Up @@ -290,7 +290,7 @@ public <T> CompletableFuture<T> queryForObject(Statement<?> statement, RowMapper

CompletableFuture<List<T>> results = query(statement, newAsyncResultSetExtractor(rowMapper));

return results.thenApply(DataAccessUtils::requiredSingleResult);
return results.thenApply(DataAccessUtils::nullableSingleResult);
}

@Override
Expand Down Expand Up @@ -518,7 +518,7 @@ public <T> CompletableFuture<T> queryForObject(String cql, RowMapper<T> rowMappe
CompletableFuture<List<T>> results = query(newAsyncPreparedStatementCreator(cql), newPreparedStatementBinder(args),
newAsyncResultSetExtractor(rowMapper));

return results.thenApply(DataAccessUtils::requiredSingleResult);
return results.thenApply(DataAccessUtils::nullableSingleResult);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ public <T> T queryForObject(String cql, Class<T> requiredType) throws DataAccess

@Override
public <T> T queryForObject(String cql, RowMapper<T> rowMapper) throws DataAccessException {
return DataAccessUtils.requiredSingleResult(query(cql, newResultSetExtractor(rowMapper)));
return DataAccessUtils.nullableSingleResult(query(cql, newResultSetExtractor(rowMapper)));
}

@Override
Expand Down Expand Up @@ -286,7 +286,7 @@ public <T> T queryForObject(Statement<?> statement, Class<T> requiredType) throw

@Override
public <T> T queryForObject(Statement<?> statement, RowMapper<T> rowMapper) throws DataAccessException {
return DataAccessUtils.requiredSingleResult(query(statement, newResultSetExtractor(rowMapper)));
return DataAccessUtils.nullableSingleResult(query(statement, newResultSetExtractor(rowMapper)));
}

@Override
Expand Down Expand Up @@ -501,7 +501,7 @@ public <T> T queryForObject(String cql, Class<T> requiredType, Object... args) t

@Override
public <T> T queryForObject(String cql, RowMapper<T> rowMapper, Object... args) throws DataAccessException {
return DataAccessUtils.requiredSingleResult(
return DataAccessUtils.nullableSingleResult(
query(newPreparedStatementCreator(cql), newPreparedStatementBinder(args), newResultSetExtractor(rowMapper, 1)));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ public <T> Flux<T> query(String cql, RowMapper<T> rowMapper) throws DataAccessEx

@Override
public <T> Mono<T> queryForObject(String cql, RowMapper<T> rowMapper) throws DataAccessException {
return query(cql, rowMapper).buffer(2).flatMap(list -> Mono.just(DataAccessUtils.requiredSingleResult(list)))
return query(cql, rowMapper).buffer(2).flatMap(list -> Mono.just(DataAccessUtils.nullableSingleResult(list)))
.next();
}

Expand Down Expand Up @@ -414,7 +414,7 @@ public <T> Flux<T> query(Statement<?> statement, RowMapper<T> rowMapper) throws

@Override
public <T> Mono<T> queryForObject(Statement<?> statement, RowMapper<T> rowMapper) throws DataAccessException {
return query(statement, rowMapper).buffer(2).flatMap(list -> Mono.just(DataAccessUtils.requiredSingleResult(list)))
return query(statement, rowMapper).buffer(2).flatMap(list -> Mono.just(DataAccessUtils.nullableSingleResult(list)))
.next();
}

Expand Down Expand Up @@ -562,7 +562,7 @@ public <T> Flux<T> query(String cql, RowMapper<T> rowMapper, Object... args) thr

@Override
public <T> Mono<T> queryForObject(String cql, RowMapper<T> rowMapper, Object... args) throws DataAccessException {
return query(cql, rowMapper, args).buffer(2).flatMap(list -> Mono.just(DataAccessUtils.requiredSingleResult(list)))
return query(cql, rowMapper, args).buffer(2).flatMap(list -> Mono.just(DataAccessUtils.nullableSingleResult(list)))
.next();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ public <T> ListenableFuture<T> queryForObject(String cql, RowMapper<T> rowMapper
ListenableFuture<List<T>> results = query(cql, newAsyncResultSetExtractor(rowMapper));

return new ExceptionTranslatingListenableFutureAdapter<>(
new MappingListenableFutureAdapter<>(results, DataAccessUtils::requiredSingleResult), getExceptionTranslator());
new MappingListenableFutureAdapter<>(results, DataAccessUtils::nullableSingleResult), getExceptionTranslator());
}

@Override
Expand Down Expand Up @@ -304,7 +304,7 @@ public <T> ListenableFuture<T> queryForObject(Statement<?> statement, RowMapper<
ListenableFuture<List<T>> results = query(statement, newAsyncResultSetExtractor(rowMapper));

return new ExceptionTranslatingListenableFutureAdapter<>(
new MappingListenableFutureAdapter<>(results, DataAccessUtils::requiredSingleResult), getExceptionTranslator());
new MappingListenableFutureAdapter<>(results, DataAccessUtils::nullableSingleResult), getExceptionTranslator());
}

@Override
Expand Down Expand Up @@ -536,7 +536,7 @@ public <T> ListenableFuture<T> queryForObject(String cql, RowMapper<T> rowMapper
newAsyncResultSetExtractor(rowMapper));

return new ExceptionTranslatingListenableFutureAdapter<>(
new MappingListenableFutureAdapter<>(results, DataAccessUtils::requiredSingleResult), getExceptionTranslator());
new MappingListenableFutureAdapter<>(results, DataAccessUtils::nullableSingleResult), getExceptionTranslator());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -533,7 +533,7 @@ ListenableFuture<Long> doCount(Query query, Class<?> entityClass, CqlIdentifier

SingleColumnRowMapper<Long> mapper = SingleColumnRowMapper.newInstance(Long.class);

Row row = DataAccessUtils.requiredSingleResult(Streamable.of(it.currentPage()).toList());
Row row = DataAccessUtils.nullableSingleResult(Streamable.of(it.currentPage()).toList());
return mapper.mapRow(row, 0);
});

Expand Down

0 comments on commit 728a83b

Please sign in to comment.