Skip to content

Commit a1e9391

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

File tree

5 files changed

+35
-36
lines changed

5 files changed

+35
-36
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
@@ -226,9 +226,11 @@ public interface JdbcAggregateOperations {
226226
* @param pageable the pagination information. Must not be {@code null}.
227227
* @return Guaranteed to be not {@code null}.
228228
* @since 2.0
229-
* @deprecated use a combination of other methods of this class to construct results of type {@link Page}.
229+
* @deprecated since 3.5.6. Use {@link #findAll(Class, Sort)} together with {@link #count(Class)} to construct results
230+
* of type {@link Page}.The API design is conflicts regarding pagination information. Also, pagination is
231+
* primarily a feature of the repository and not the template API.
230232
*/
231-
@Deprecated(since = "4.0")
233+
@Deprecated(since = "3.5.6")
232234
<T> Page<T> findAll(Class<T> domainType, Pageable pageable);
233235

234236
/**
@@ -273,9 +275,11 @@ public interface JdbcAggregateOperations {
273275
* @param pageable can be null.
274276
* @return a {@link Page} of entities matching the given {@link Example}.
275277
* @since 3.0
276-
* @deprecated use a combination of other methods of this class to construct results of type {@link Page}.
278+
* @deprecated since 3.5.6. Use {@link #findAll(Query, Class)} together with {@link #count(Query, Class)} to construct
279+
* results of type {@link Page}. The API design is conflicts regarding pagination information. Also,
280+
* pagination is primarily a feature of the repository and not the template API.
277281
*/
278-
@Deprecated(since = "4.0")
282+
@Deprecated(since = "3.5.6")
279283
<T> Page<T> findAll(Query query, Class<T> domainType, Pageable pageable);
280284

281285
/**

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -313,8 +313,8 @@ public <T> Stream<T> streamAll(Class<T> domainType, Sort sort) {
313313
return allStreamable.map(this::triggerAfterConvert);
314314
}
315315

316-
@Deprecated
317316
@Override
317+
@Deprecated(since = "3.5.6")
318318
public <T> Page<T> findAll(Class<T> domainType, Pageable pageable) {
319319

320320
Assert.notNull(domainType, "Domain type must not be null");
@@ -343,8 +343,8 @@ public <T> Stream<T> streamAll(Query query, Class<T> domainType) {
343343
return accessStrategy.streamAll(query, domainType).map(this::triggerAfterConvert);
344344
}
345345

346-
@Deprecated
347346
@Override
347+
@Deprecated(since = "3.5.6")
348348
public <T> Page<T> findAll(Query query, Class<T> domainType, Pageable pageable) {
349349

350350
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;
@@ -93,16 +91,8 @@ public List<R> all() {
9391

9492
private List<R> findAll(Query query) {
9593

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

10898
@Override
@@ -133,21 +123,33 @@ public Page<R> page(Pageable pageable) {
133123

134124
Query contentQuery = createQuery(p -> p.with(pageable));
135125
List<S> content = this.entityOperations.findAll(contentQuery, getExampleType());
126+
List<R> result = mapContent(content);
127+
128+
return PageableExecutionUtils.getPage(result, pageable,
129+
() -> this.entityOperations.count(createQuery(), getExampleType()));
130+
}
131+
132+
@SuppressWarnings("unchecked")
133+
private List<R> mapContent(List<S> content) {
134+
135+
Function<Object, R> conversionFunction = getConversionFunction();
136+
137+
if (conversionFunction == Function.identity()) {
138+
return (List<R>) content;
139+
}
136140

137141
List<R> result = new ArrayList<>(content.size());
138142
for (S s : content) {
139-
result.add(getConversionFunction().apply(s));
143+
result.add(conversionFunction.apply(s));
140144
}
141145

142-
return PageableExecutionUtils.getPage(result, pageable, () -> this.entityOperations.count(createQuery(), getExampleType()));
146+
return result;
143147
}
144148

145149
@Override
146150
public Stream<R> stream() {
147-
148-
return StreamSupport
149-
.stream(this.entityOperations.findAll(createQuery().sort(getSort()), getExampleType()).spliterator(), false)
150-
.map(item -> this.getConversionFunction().apply(item));
151+
return this.entityOperations.streamAll(createQuery().sort(getSort()), getExampleType())
152+
.map(getConversionFunction());
151153
}
152154

153155
@Override
@@ -173,7 +175,6 @@ private Query createQuery(UnaryOperator<Query> queryCustomizer) {
173175
}
174176

175177
query = query.limit(getLimit());
176-
177178
query = queryCustomizer.apply(query);
178179

179180
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
@@ -147,10 +147,7 @@ public Page<T> findAll(Pageable pageable) {
147147

148148
Assert.notNull(pageable, "Pageable must not be null");
149149

150-
Query query1 = Query.query(CriteriaDefinition.empty());
151-
152-
153-
Query query = query1.with(pageable);
150+
Query query = Query.query(CriteriaDefinition.empty()).with(pageable);
154151
List<T> content = entityOperations.findAll(query, entity.getType());
155152

156153
return PageableExecutionUtils.getPage(content, pageable, () -> entityOperations.count(entity.getType()));
@@ -189,11 +186,7 @@ public <S extends T> Page<S> findAll(Example<S> example, Pageable pageable) {
189186
Assert.notNull(pageable, "Pageable must not be null");
190187

191188
Query mappedQuery = this.exampleMapper.getMappedExample(example);
192-
193-
194-
Query contentQuery = mappedQuery.with(pageable);
195-
196-
List<S> content = this.entityOperations.findAll(contentQuery, example.getProbeType());
189+
List<S> content = this.entityOperations.findAll(mappedQuery.with(pageable), example.getProbeType());
197190

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

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import org.springframework.data.domain.Page
2020
import org.springframework.data.domain.Pageable
2121
import org.springframework.data.domain.Sort
2222
import org.springframework.data.relational.core.query.Query
23-
import java.util.Optional
23+
import java.util.*
2424

2525
/**
2626
* Kotlin extensions for [JdbcAggregateOperations].
@@ -80,7 +80,7 @@ inline fun <reified T> 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 3.5.6, use a findAll<T>() and count<T>() to construct results of type Page")
8484
inline fun <reified T> JdbcAggregateOperations.findAll(pageable: Pageable): Page<T> =
8585
findAll(T::class.java, pageable)
8686

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

0 commit comments

Comments
 (0)