From 728a83bc747e2ac10aaa99eda1b7a04a59f1213c Mon Sep 17 00:00:00 2001 From: Mark Paluch Date: Thu, 8 Aug 2024 14:56:16 +0200 Subject: [PATCH] Switch from `DataAccessUtils.requiredSingleResult` to `nullableSingleResult`. Closes #1514 --- .../data/cassandra/core/AsyncCassandraTemplate.java | 2 +- .../data/cassandra/core/CassandraTemplate.java | 2 +- .../data/cassandra/core/ReactiveCassandraTemplate.java | 2 +- .../data/cassandra/core/cql/AsyncCqlTemplate.java | 6 +++--- .../data/cassandra/core/cql/CqlTemplate.java | 6 +++--- .../data/cassandra/core/cql/ReactiveCqlTemplate.java | 6 +++--- .../data/cassandra/core/cql/legacy/AsyncCqlTemplate.java | 6 +++--- .../data/cassandra/core/legacy/AsyncCassandraTemplate.java | 2 +- 8 files changed, 16 insertions(+), 16 deletions(-) diff --git a/spring-data-cassandra/src/main/java/org/springframework/data/cassandra/core/AsyncCassandraTemplate.java b/spring-data-cassandra/src/main/java/org/springframework/data/cassandra/core/AsyncCassandraTemplate.java index e2e1c8cc7..525486433 100644 --- a/spring-data-cassandra/src/main/java/org/springframework/data/cassandra/core/AsyncCassandraTemplate.java +++ b/spring-data-cassandra/src/main/java/org/springframework/data/cassandra/core/AsyncCassandraTemplate.java @@ -504,7 +504,7 @@ CompletableFuture doCount(Query query, Class entityClass, CqlIdentifier SingleColumnRowMapper 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); }); diff --git a/spring-data-cassandra/src/main/java/org/springframework/data/cassandra/core/CassandraTemplate.java b/spring-data-cassandra/src/main/java/org/springframework/data/cassandra/core/CassandraTemplate.java index cfc455973..9556b7ae3 100644 --- a/spring-data-cassandra/src/main/java/org/springframework/data/cassandra/core/CassandraTemplate.java +++ b/spring-data-cassandra/src/main/java/org/springframework/data/cassandra/core/CassandraTemplate.java @@ -846,7 +846,7 @@ private List doQuery(Statement statement, RowMapper rowMapper) { } private T doQueryForObject(Statement statement, Class resultType) { - return DataAccessUtils.requiredSingleResult(doQuery(statement, SingleColumnRowMapper.newInstance(resultType))); + return DataAccessUtils.nullableSingleResult(doQuery(statement, SingleColumnRowMapper.newInstance(resultType))); } private Stream doQueryForStream(Statement statement, RowMapper rowMapper) { diff --git a/spring-data-cassandra/src/main/java/org/springframework/data/cassandra/core/ReactiveCassandraTemplate.java b/spring-data-cassandra/src/main/java/org/springframework/data/cassandra/core/ReactiveCassandraTemplate.java index 18868a9e6..11db35e4a 100644 --- a/spring-data-cassandra/src/main/java/org/springframework/data/cassandra/core/ReactiveCassandraTemplate.java +++ b/spring-data-cassandra/src/main/java/org/springframework/data/cassandra/core/ReactiveCassandraTemplate.java @@ -502,7 +502,7 @@ Mono doCount(Query query, Class entityClass, CqlIdentifier tableName) { Mono 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)); } diff --git a/spring-data-cassandra/src/main/java/org/springframework/data/cassandra/core/cql/AsyncCqlTemplate.java b/spring-data-cassandra/src/main/java/org/springframework/data/cassandra/core/cql/AsyncCqlTemplate.java index 85a68478f..f5e6efff2 100644 --- a/spring-data-cassandra/src/main/java/org/springframework/data/cassandra/core/cql/AsyncCqlTemplate.java +++ b/spring-data-cassandra/src/main/java/org/springframework/data/cassandra/core/cql/AsyncCqlTemplate.java @@ -202,7 +202,7 @@ public CompletableFuture queryForObject(String cql, RowMapper rowMappe CompletableFuture> results = query(cql, newAsyncResultSetExtractor(rowMapper)); - return results.thenApply(DataAccessUtils::requiredSingleResult); + return results.thenApply(DataAccessUtils::nullableSingleResult); } @Override @@ -290,7 +290,7 @@ public CompletableFuture queryForObject(Statement statement, RowMapper CompletableFuture> results = query(statement, newAsyncResultSetExtractor(rowMapper)); - return results.thenApply(DataAccessUtils::requiredSingleResult); + return results.thenApply(DataAccessUtils::nullableSingleResult); } @Override @@ -518,7 +518,7 @@ public CompletableFuture queryForObject(String cql, RowMapper rowMappe CompletableFuture> results = query(newAsyncPreparedStatementCreator(cql), newPreparedStatementBinder(args), newAsyncResultSetExtractor(rowMapper)); - return results.thenApply(DataAccessUtils::requiredSingleResult); + return results.thenApply(DataAccessUtils::nullableSingleResult); } @Override diff --git a/spring-data-cassandra/src/main/java/org/springframework/data/cassandra/core/cql/CqlTemplate.java b/spring-data-cassandra/src/main/java/org/springframework/data/cassandra/core/cql/CqlTemplate.java index 7bd5bad1d..6c835cf01 100644 --- a/spring-data-cassandra/src/main/java/org/springframework/data/cassandra/core/cql/CqlTemplate.java +++ b/spring-data-cassandra/src/main/java/org/springframework/data/cassandra/core/cql/CqlTemplate.java @@ -202,7 +202,7 @@ public T queryForObject(String cql, Class requiredType) throws DataAccess @Override public T queryForObject(String cql, RowMapper rowMapper) throws DataAccessException { - return DataAccessUtils.requiredSingleResult(query(cql, newResultSetExtractor(rowMapper))); + return DataAccessUtils.nullableSingleResult(query(cql, newResultSetExtractor(rowMapper))); } @Override @@ -286,7 +286,7 @@ public T queryForObject(Statement statement, Class requiredType) throw @Override public T queryForObject(Statement statement, RowMapper rowMapper) throws DataAccessException { - return DataAccessUtils.requiredSingleResult(query(statement, newResultSetExtractor(rowMapper))); + return DataAccessUtils.nullableSingleResult(query(statement, newResultSetExtractor(rowMapper))); } @Override @@ -501,7 +501,7 @@ public T queryForObject(String cql, Class requiredType, Object... args) t @Override public T queryForObject(String cql, RowMapper rowMapper, Object... args) throws DataAccessException { - return DataAccessUtils.requiredSingleResult( + return DataAccessUtils.nullableSingleResult( query(newPreparedStatementCreator(cql), newPreparedStatementBinder(args), newResultSetExtractor(rowMapper, 1))); } diff --git a/spring-data-cassandra/src/main/java/org/springframework/data/cassandra/core/cql/ReactiveCqlTemplate.java b/spring-data-cassandra/src/main/java/org/springframework/data/cassandra/core/cql/ReactiveCqlTemplate.java index bcced2108..8cffc5943 100644 --- a/spring-data-cassandra/src/main/java/org/springframework/data/cassandra/core/cql/ReactiveCqlTemplate.java +++ b/spring-data-cassandra/src/main/java/org/springframework/data/cassandra/core/cql/ReactiveCqlTemplate.java @@ -331,7 +331,7 @@ public Flux query(String cql, RowMapper rowMapper) throws DataAccessEx @Override public Mono queryForObject(String cql, RowMapper 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(); } @@ -414,7 +414,7 @@ public Flux query(Statement statement, RowMapper rowMapper) throws @Override public Mono queryForObject(Statement statement, RowMapper 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(); } @@ -562,7 +562,7 @@ public Flux query(String cql, RowMapper rowMapper, Object... args) thr @Override public Mono queryForObject(String cql, RowMapper 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(); } diff --git a/spring-data-cassandra/src/main/java/org/springframework/data/cassandra/core/cql/legacy/AsyncCqlTemplate.java b/spring-data-cassandra/src/main/java/org/springframework/data/cassandra/core/cql/legacy/AsyncCqlTemplate.java index 1ec9b5bd7..ebb4b1624 100644 --- a/spring-data-cassandra/src/main/java/org/springframework/data/cassandra/core/cql/legacy/AsyncCqlTemplate.java +++ b/spring-data-cassandra/src/main/java/org/springframework/data/cassandra/core/cql/legacy/AsyncCqlTemplate.java @@ -216,7 +216,7 @@ public ListenableFuture queryForObject(String cql, RowMapper rowMapper ListenableFuture> results = query(cql, newAsyncResultSetExtractor(rowMapper)); return new ExceptionTranslatingListenableFutureAdapter<>( - new MappingListenableFutureAdapter<>(results, DataAccessUtils::requiredSingleResult), getExceptionTranslator()); + new MappingListenableFutureAdapter<>(results, DataAccessUtils::nullableSingleResult), getExceptionTranslator()); } @Override @@ -304,7 +304,7 @@ public ListenableFuture queryForObject(Statement statement, RowMapper< ListenableFuture> results = query(statement, newAsyncResultSetExtractor(rowMapper)); return new ExceptionTranslatingListenableFutureAdapter<>( - new MappingListenableFutureAdapter<>(results, DataAccessUtils::requiredSingleResult), getExceptionTranslator()); + new MappingListenableFutureAdapter<>(results, DataAccessUtils::nullableSingleResult), getExceptionTranslator()); } @Override @@ -536,7 +536,7 @@ public ListenableFuture queryForObject(String cql, RowMapper rowMapper newAsyncResultSetExtractor(rowMapper)); return new ExceptionTranslatingListenableFutureAdapter<>( - new MappingListenableFutureAdapter<>(results, DataAccessUtils::requiredSingleResult), getExceptionTranslator()); + new MappingListenableFutureAdapter<>(results, DataAccessUtils::nullableSingleResult), getExceptionTranslator()); } @Override diff --git a/spring-data-cassandra/src/main/java/org/springframework/data/cassandra/core/legacy/AsyncCassandraTemplate.java b/spring-data-cassandra/src/main/java/org/springframework/data/cassandra/core/legacy/AsyncCassandraTemplate.java index 23972165d..92a2017b0 100644 --- a/spring-data-cassandra/src/main/java/org/springframework/data/cassandra/core/legacy/AsyncCassandraTemplate.java +++ b/spring-data-cassandra/src/main/java/org/springframework/data/cassandra/core/legacy/AsyncCassandraTemplate.java @@ -533,7 +533,7 @@ ListenableFuture doCount(Query query, Class entityClass, CqlIdentifier SingleColumnRowMapper 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); });