Browse Source

Polishing.

Refine deprecation messages. Simplify conversion, use Stream methods directly.

See #2138
Original pull request #2161
pull/2163/head
Mark Paluch 2 months ago
parent
commit
d194b7d4e0
No known key found for this signature in database
GPG Key ID: 55BC6374BAA9D973
  1. 12
      spring-data-jdbc/src/main/java/org/springframework/data/jdbc/core/JdbcAggregateOperations.java
  2. 8
      spring-data-jdbc/src/main/java/org/springframework/data/jdbc/core/JdbcAggregateTemplate.java
  3. 39
      spring-data-jdbc/src/main/java/org/springframework/data/jdbc/repository/support/FetchableFluentQueryByExample.java
  4. 11
      spring-data-jdbc/src/main/java/org/springframework/data/jdbc/repository/support/SimpleJdbcRepository.java
  5. 3
      spring-data-jdbc/src/main/kotlin/org/springframework/data/jdbc/core/JdbcAggregateOperationsExtensions.kt

12
spring-data-jdbc/src/main/java/org/springframework/data/jdbc/core/JdbcAggregateOperations.java

@ -230,9 +230,11 @@ public interface JdbcAggregateOperations { @@ -230,9 +230,11 @@ public interface JdbcAggregateOperations {
* @param pageable the pagination information. Must not be {@code null}.
* @return Guaranteed to be not {@code null}.
* @since 2.0
* @deprecated use a combination of other methods of this class to construct results of type {@link Page}.
* @deprecated since 4.0. Use {@link #findAll(Class, Sort)} together with {@link #count(Class)} to construct results
* of type {@link Page}.The API design is conflicts regarding pagination information. Also, pagination is
* primarily a feature of the repository and not the template API.
*/
@Deprecated(since = "4.0")
@Deprecated(since = "4.0", forRemoval = true)
<T> Page<T> findAll(Class<T> domainType, Pageable pageable);
/**
@ -277,9 +279,11 @@ public interface JdbcAggregateOperations { @@ -277,9 +279,11 @@ public interface JdbcAggregateOperations {
* @param pageable can be null.
* @return a {@link Page} of entities matching the given {@link Example}.
* @since 3.0
* @deprecated use a combination of other methods of this class to construct results of type {@link Page}.
* @deprecated since 4.0. Use {@link #findAll(Query, Class)} together with {@link #count(Query, Class)} to construct
* results of type {@link Page}. The API design is conflicts regarding pagination information. Also,
* pagination is primarily a feature of the repository and not the template API.
*/
@Deprecated(since = "4.0")
@Deprecated(since = "4.0", forRemoval = true)
<T> Page<T> findAll(Query query, Class<T> domainType, Pageable pageable);
/**

8
spring-data-jdbc/src/main/java/org/springframework/data/jdbc/core/JdbcAggregateTemplate.java

@ -31,6 +31,7 @@ import java.util.stream.Stream; @@ -31,6 +31,7 @@ import java.util.stream.Stream;
import java.util.stream.StreamSupport;
import org.jspecify.annotations.Nullable;
import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
@ -41,7 +42,6 @@ import org.springframework.data.domain.Sort; @@ -41,7 +42,6 @@ import org.springframework.data.domain.Sort;
import org.springframework.data.jdbc.core.convert.DataAccessStrategy;
import org.springframework.data.jdbc.core.convert.EntityRowMapper;
import org.springframework.data.jdbc.core.convert.JdbcConverter;
import org.springframework.data.jdbc.core.convert.QueryMappingConfiguration;
import org.springframework.data.mapping.IdentifierAccessor;
import org.springframework.data.mapping.callback.EntityCallbacks;
import org.springframework.data.relational.core.EntityLifecycleEventDelegate;
@ -78,6 +78,7 @@ import org.springframework.util.ClassUtils; @@ -78,6 +78,7 @@ import org.springframework.util.ClassUtils;
* @author Sergey Korotaev
* @author Mikhail Polivakha
*/
@SuppressWarnings("removal")
public class JdbcAggregateTemplate implements JdbcAggregateOperations, ApplicationContextAware {
private final EntityLifecycleEventDelegate eventDelegate = new EntityLifecycleEventDelegate();
@ -88,7 +89,6 @@ public class JdbcAggregateTemplate implements JdbcAggregateOperations, Applicati @@ -88,7 +89,6 @@ public class JdbcAggregateTemplate implements JdbcAggregateOperations, Applicati
private final JdbcConverter converter;
private @Nullable EntityCallbacks entityCallbacks;
private QueryMappingConfiguration queryMappingConfiguration = QueryMappingConfiguration.EMPTY;
/**
* Creates a new {@link JdbcAggregateTemplate} given {@link RelationalMappingContext} and {@link DataAccessStrategy}.
@ -359,8 +359,8 @@ public class JdbcAggregateTemplate implements JdbcAggregateOperations, Applicati @@ -359,8 +359,8 @@ public class JdbcAggregateTemplate implements JdbcAggregateOperations, Applicati
return allStreamable.map(this::triggerAfterConvert);
}
@Deprecated
@Override
@Deprecated(since = "4.0", forRemoval = true)
public <T> Page<T> findAll(Class<T> domainType, Pageable pageable) {
Assert.notNull(domainType, "Domain type must not be null");
@ -389,8 +389,8 @@ public class JdbcAggregateTemplate implements JdbcAggregateOperations, Applicati @@ -389,8 +389,8 @@ public class JdbcAggregateTemplate implements JdbcAggregateOperations, Applicati
return accessStrategy.streamAll(query, domainType).map(this::triggerAfterConvert);
}
@Deprecated
@Override
@Deprecated(since = "4.0", forRemoval = true)
public <T> Page<T> findAll(Query query, Class<T> domainType, Pageable pageable) {
Iterable<T> items = triggerAfterConvert(accessStrategy.findAll(query, domainType, pageable));

39
spring-data-jdbc/src/main/java/org/springframework/data/jdbc/repository/support/FetchableFluentQueryByExample.java

@ -16,13 +16,11 @@ @@ -16,13 +16,11 @@
package org.springframework.data.jdbc.repository.support;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.function.Function;
import java.util.function.UnaryOperator;
import java.util.stream.Stream;
import java.util.stream.StreamSupport;
import org.springframework.data.domain.Example;
import org.springframework.data.domain.OffsetScrollPosition;
@ -89,16 +87,8 @@ class FetchableFluentQueryByExample<S, R> extends FluentQuerySupport<S, R> { @@ -89,16 +87,8 @@ class FetchableFluentQueryByExample<S, R> extends FluentQuerySupport<S, R> {
private List<R> findAll(Query query) {
Function<Object, R> conversionFunction = this.getConversionFunction();
Iterable<S> raw = this.entityOperations.findAll(query, getExampleType());
List<R> result = new ArrayList<>(raw instanceof Collections ? ((Collection<?>) raw).size() : 16);
for (S s : raw) {
result.add(conversionFunction.apply(s));
}
return result;
List<S> raw = this.entityOperations.findAll(query, getExampleType());
return mapContent(raw);
}
@Override
@ -129,21 +119,33 @@ class FetchableFluentQueryByExample<S, R> extends FluentQuerySupport<S, R> { @@ -129,21 +119,33 @@ class FetchableFluentQueryByExample<S, R> extends FluentQuerySupport<S, R> {
Query contentQuery = createQuery(p -> p.with(pageable));
List<S> content = this.entityOperations.findAll(contentQuery, getExampleType());
List<R> result = mapContent(content);
return PageableExecutionUtils.getPage(result, pageable,
() -> this.entityOperations.count(createQuery(), getExampleType()));
}
@SuppressWarnings("unchecked")
private List<R> mapContent(List<S> content) {
Function<Object, R> conversionFunction = getConversionFunction();
if (conversionFunction == Function.identity()) {
return (List<R>) content;
}
List<R> result = new ArrayList<>(content.size());
for (S s : content) {
result.add(getConversionFunction().apply(s));
result.add(conversionFunction.apply(s));
}
return PageableExecutionUtils.getPage(result, pageable, () -> this.entityOperations.count(createQuery(), getExampleType()));
return result;
}
@Override
public Stream<R> stream() {
return StreamSupport
.stream(this.entityOperations.findAll(createQuery().sort(getSort()), getExampleType()).spliterator(), false)
.map(item -> this.getConversionFunction().apply(item));
return this.entityOperations.streamAll(createQuery().sort(getSort()), getExampleType())
.map(getConversionFunction());
}
@Override
@ -169,7 +171,6 @@ class FetchableFluentQueryByExample<S, R> extends FluentQuerySupport<S, R> { @@ -169,7 +171,6 @@ class FetchableFluentQueryByExample<S, R> extends FluentQuerySupport<S, R> {
}
query = query.limit(getLimit());
query = queryCustomizer.apply(query);
return query;

11
spring-data-jdbc/src/main/java/org/springframework/data/jdbc/repository/support/SimpleJdbcRepository.java

@ -145,10 +145,7 @@ public class SimpleJdbcRepository<T, ID> @@ -145,10 +145,7 @@ public class SimpleJdbcRepository<T, ID>
Assert.notNull(pageable, "Pageable must not be null");
Query query1 = Query.query(CriteriaDefinition.empty());
Query query = query1.with(pageable);
Query query = Query.query(CriteriaDefinition.empty()).with(pageable);
List<T> content = entityOperations.findAll(query, entity.getType());
return PageableExecutionUtils.getPage(content, pageable, () -> entityOperations.count(entity.getType()));
@ -187,11 +184,7 @@ public class SimpleJdbcRepository<T, ID> @@ -187,11 +184,7 @@ public class SimpleJdbcRepository<T, ID>
Assert.notNull(pageable, "Pageable must not be null");
Query mappedQuery = this.exampleMapper.getMappedExample(example);
Query contentQuery = mappedQuery.with(pageable);
List<S> content = this.entityOperations.findAll(contentQuery, example.getProbeType());
List<S> content = this.entityOperations.findAll(mappedQuery.with(pageable), example.getProbeType());
return PageableExecutionUtils.getPage(content, pageable,
() -> this.entityOperations.count(mappedQuery, example.getProbeType()));

3
spring-data-jdbc/src/main/kotlin/org/springframework/data/jdbc/core/JdbcAggregateOperationsExtensions.kt

@ -80,7 +80,7 @@ inline fun <reified T : Any> JdbcAggregateOperations.findAll(sort: Sort): List<T @@ -80,7 +80,7 @@ inline fun <reified T : Any> JdbcAggregateOperations.findAll(sort: Sort): List<T
/**
* Extension for [JdbcAggregateOperations.findAll] with pagination.
*/
@Deprecated("Use a combination of operations of this class to construct results of type Page")
@Deprecated("Since 4.0, use a findAll<T>() and count<T>() to construct results of type Page")
inline fun <reified T : Any> JdbcAggregateOperations.findAll(pageable: Pageable): Page<T> =
findAll(T::class.java, pageable)
@ -99,6 +99,7 @@ inline fun <reified T : Any> JdbcAggregateOperations.findAll(query: Query): List @@ -99,6 +99,7 @@ inline fun <reified T : Any> JdbcAggregateOperations.findAll(query: Query): List
/**
* Extension for [JdbcAggregateOperations.findAll] with query and pagination.
*/
@Deprecated("Since 4.0, use a findAll<T>(Query) and count<T>(Query) to construct results of type Page")
inline fun <reified T : Any> JdbcAggregateOperations.findAll(
query: Query,
pageable: Pageable

Loading…
Cancel
Save