Skip to content

Commit d194b7d

Browse files
committed
Polishing.
Refine deprecation messages. Simplify conversion, use Stream methods directly. See #2138 Original pull request #2161
1 parent dc8195f commit d194b7d

File tree

5 files changed

+36
-37
lines changed

5 files changed

+36
-37
lines changed

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

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -230,9 +230,11 @@ public interface JdbcAggregateOperations {
230230
* @param pageable the pagination information. Must not be {@code null}.
231231
* @return Guaranteed to be not {@code null}.
232232
* @since 2.0
233-
* @deprecated use a combination of other methods of this class to construct results of type {@link Page}.
233+
* @deprecated since 4.0. Use {@link #findAll(Class, Sort)} together with {@link #count(Class)} to construct results
234+
* of type {@link Page}.The API design is conflicts regarding pagination information. Also, pagination is
235+
* primarily a feature of the repository and not the template API.
234236
*/
235-
@Deprecated(since = "4.0")
237+
@Deprecated(since = "4.0", forRemoval = true)
236238
<T> Page<T> findAll(Class<T> domainType, Pageable pageable);
237239

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

285289
/**

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
import java.util.stream.StreamSupport;
3232

3333
import org.jspecify.annotations.Nullable;
34+
3435
import org.springframework.beans.BeansException;
3536
import org.springframework.context.ApplicationContext;
3637
import org.springframework.context.ApplicationContextAware;
@@ -41,7 +42,6 @@
4142
import org.springframework.data.jdbc.core.convert.DataAccessStrategy;
4243
import org.springframework.data.jdbc.core.convert.EntityRowMapper;
4344
import org.springframework.data.jdbc.core.convert.JdbcConverter;
44-
import org.springframework.data.jdbc.core.convert.QueryMappingConfiguration;
4545
import org.springframework.data.mapping.IdentifierAccessor;
4646
import org.springframework.data.mapping.callback.EntityCallbacks;
4747
import org.springframework.data.relational.core.EntityLifecycleEventDelegate;
@@ -78,6 +78,7 @@
7878
* @author Sergey Korotaev
7979
* @author Mikhail Polivakha
8080
*/
81+
@SuppressWarnings("removal")
8182
public class JdbcAggregateTemplate implements JdbcAggregateOperations, ApplicationContextAware {
8283

8384
private final EntityLifecycleEventDelegate eventDelegate = new EntityLifecycleEventDelegate();
@@ -88,7 +89,6 @@ public class JdbcAggregateTemplate implements JdbcAggregateOperations, Applicati
8889
private final JdbcConverter converter;
8990

9091
private @Nullable EntityCallbacks entityCallbacks;
91-
private QueryMappingConfiguration queryMappingConfiguration = QueryMappingConfiguration.EMPTY;
9292

9393
/**
9494
* Creates a new {@link JdbcAggregateTemplate} given {@link RelationalMappingContext} and {@link DataAccessStrategy}.
@@ -359,8 +359,8 @@ public <T> Stream<T> streamAll(Class<T> domainType, Sort sort) {
359359
return allStreamable.map(this::triggerAfterConvert);
360360
}
361361

362-
@Deprecated
363362
@Override
363+
@Deprecated(since = "4.0", forRemoval = true)
364364
public <T> Page<T> findAll(Class<T> domainType, Pageable pageable) {
365365

366366
Assert.notNull(domainType, "Domain type must not be null");
@@ -389,8 +389,8 @@ public <T> Stream<T> streamAll(Query query, Class<T> domainType) {
389389
return accessStrategy.streamAll(query, domainType).map(this::triggerAfterConvert);
390390
}
391391

392-
@Deprecated
393392
@Override
393+
@Deprecated(since = "4.0", forRemoval = true)
394394
public <T> Page<T> findAll(Query query, Class<T> domainType, Pageable pageable) {
395395

396396
Iterable<T> items = triggerAfterConvert(accessStrategy.findAll(query, domainType, pageable));

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

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,11 @@
1616
package org.springframework.data.jdbc.repository.support;
1717

1818
import java.util.ArrayList;
19-
import java.util.Collection;
2019
import java.util.Collections;
2120
import java.util.List;
2221
import java.util.function.Function;
2322
import java.util.function.UnaryOperator;
2423
import java.util.stream.Stream;
25-
import java.util.stream.StreamSupport;
2624

2725
import org.springframework.data.domain.Example;
2826
import org.springframework.data.domain.OffsetScrollPosition;
@@ -89,16 +87,8 @@ public List<R> all() {
8987

9088
private List<R> findAll(Query query) {
9189

92-
Function<Object, R> conversionFunction = this.getConversionFunction();
93-
Iterable<S> raw = this.entityOperations.findAll(query, getExampleType());
94-
95-
List<R> result = new ArrayList<>(raw instanceof Collections ? ((Collection<?>) raw).size() : 16);
96-
97-
for (S s : raw) {
98-
result.add(conversionFunction.apply(s));
99-
}
100-
101-
return result;
90+
List<S> raw = this.entityOperations.findAll(query, getExampleType());
91+
return mapContent(raw);
10292
}
10393

10494
@Override
@@ -129,21 +119,33 @@ public Page<R> page(Pageable pageable) {
129119

130120
Query contentQuery = createQuery(p -> p.with(pageable));
131121
List<S> content = this.entityOperations.findAll(contentQuery, getExampleType());
122+
List<R> result = mapContent(content);
123+
124+
return PageableExecutionUtils.getPage(result, pageable,
125+
() -> this.entityOperations.count(createQuery(), getExampleType()));
126+
}
127+
128+
@SuppressWarnings("unchecked")
129+
private List<R> mapContent(List<S> content) {
130+
131+
Function<Object, R> conversionFunction = getConversionFunction();
132+
133+
if (conversionFunction == Function.identity()) {
134+
return (List<R>) content;
135+
}
132136

133137
List<R> result = new ArrayList<>(content.size());
134138
for (S s : content) {
135-
result.add(getConversionFunction().apply(s));
139+
result.add(conversionFunction.apply(s));
136140
}
137141

138-
return PageableExecutionUtils.getPage(result, pageable, () -> this.entityOperations.count(createQuery(), getExampleType()));
142+
return result;
139143
}
140144

141145
@Override
142146
public Stream<R> stream() {
143-
144-
return StreamSupport
145-
.stream(this.entityOperations.findAll(createQuery().sort(getSort()), getExampleType()).spliterator(), false)
146-
.map(item -> this.getConversionFunction().apply(item));
147+
return this.entityOperations.streamAll(createQuery().sort(getSort()), getExampleType())
148+
.map(getConversionFunction());
147149
}
148150

149151
@Override
@@ -169,7 +171,6 @@ private Query createQuery(UnaryOperator<Query> queryCustomizer) {
169171
}
170172

171173
query = query.limit(getLimit());
172-
173174
query = queryCustomizer.apply(query);
174175

175176
return query;

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

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -145,10 +145,7 @@ public Page<T> findAll(Pageable pageable) {
145145

146146
Assert.notNull(pageable, "Pageable must not be null");
147147

148-
Query query1 = Query.query(CriteriaDefinition.empty());
149-
150-
151-
Query query = query1.with(pageable);
148+
Query query = Query.query(CriteriaDefinition.empty()).with(pageable);
152149
List<T> content = entityOperations.findAll(query, entity.getType());
153150

154151
return PageableExecutionUtils.getPage(content, pageable, () -> entityOperations.count(entity.getType()));
@@ -187,11 +184,7 @@ public <S extends T> Page<S> findAll(Example<S> example, Pageable pageable) {
187184
Assert.notNull(pageable, "Pageable must not be null");
188185

189186
Query mappedQuery = this.exampleMapper.getMappedExample(example);
190-
191-
192-
Query contentQuery = mappedQuery.with(pageable);
193-
194-
List<S> content = this.entityOperations.findAll(contentQuery, example.getProbeType());
187+
List<S> content = this.entityOperations.findAll(mappedQuery.with(pageable), example.getProbeType());
195188

196189
return PageableExecutionUtils.getPage(content, pageable,
197190
() -> this.entityOperations.count(mappedQuery, example.getProbeType()));

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ inline fun <reified T : Any> JdbcAggregateOperations.findAll(sort: Sort): List<T
8080
/**
8181
* Extension for [JdbcAggregateOperations.findAll] with pagination.
8282
*/
83-
@Deprecated("Use a combination of operations of this class to construct results of type Page")
83+
@Deprecated("Since 4.0, use a findAll<T>() and count<T>() to construct results of type Page")
8484
inline fun <reified T : Any> JdbcAggregateOperations.findAll(pageable: Pageable): Page<T> =
8585
findAll(T::class.java, pageable)
8686

@@ -99,6 +99,7 @@ inline fun <reified T : Any> JdbcAggregateOperations.findAll(query: Query): List
9999
/**
100100
* Extension for [JdbcAggregateOperations.findAll] with query and pagination.
101101
*/
102+
@Deprecated("Since 4.0, use a findAll<T>(Query) and count<T>(Query) to construct results of type Page")
102103
inline fun <reified T : Any> JdbcAggregateOperations.findAll(
103104
query: Query,
104105
pageable: Pageable

0 commit comments

Comments
 (0)