Skip to content

Commit bfaa81e

Browse files
committed
Polishing.
Reformat code. Reuse PersistentEntity for mapping instead of resolving TypeInformation from Class. Original pull request: #4892 See: #4860
1 parent 279a28d commit bfaa81e

File tree

3 files changed

+14
-8
lines changed

3 files changed

+14
-8
lines changed

spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/ExecutableFindOperationSupport.java

+4-1
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,10 @@
2020
import java.util.stream.Stream;
2121

2222
import org.bson.Document;
23+
2324
import org.springframework.dao.IncorrectResultSizeDataAccessException;
24-
import org.springframework.data.domain.Window;
2525
import org.springframework.data.domain.ScrollPosition;
26+
import org.springframework.data.domain.Window;
2627
import org.springframework.data.mongodb.core.query.NearQuery;
2728
import org.springframework.data.mongodb.core.query.Query;
2829
import org.springframework.data.mongodb.core.query.SerializationUtils;
@@ -228,11 +229,13 @@ CursorPreparer limit(int limit) {
228229
}
229230

230231
@Override
232+
@Nullable
231233
public ReadPreference getReadPreference() {
232234
return delegate.getReadPreference();
233235
}
234236

235237
@Override
238+
@Nullable
236239
public Document getSortObject() {
237240
return delegate instanceof SortingQueryCursorPreparer sqcp ? sqcp.getSortObject() : null;
238241
}

spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/MongoTemplate.java

+4-5
Original file line numberDiff line numberDiff line change
@@ -2624,7 +2624,9 @@ <S, T> List<T> doFind(CollectionPreparer<MongoCollection<Document>> collectionPr
26242624

26252625
if (LOGGER.isDebugEnabled()) {
26262626

2627-
Document mappedSort = preparer instanceof SortingQueryCursorPreparer sqcp ? getMappedSortObject(sqcp.getSortObject(), sourceClass) : null;
2627+
Document mappedSort = preparer instanceof SortingQueryCursorPreparer sqcp
2628+
? getMappedSortObject(sqcp.getSortObject(), entity)
2629+
: null;
26282630
LOGGER.debug(String.format("find using query: %s fields: %s sort: %s for class: %s in collection: %s",
26292631
serializeToJsonSafely(mappedQuery), mappedFields, serializeToJsonSafely(mappedSort), sourceClass,
26302632
collectionName));
@@ -2993,7 +2995,7 @@ private Document getMappedSortObject(Document sortObject, Class<?> type) {
29932995
}
29942996

29952997
@Nullable
2996-
private Document getMappedSortObject(Document sortObject, MongoPersistentEntity<?> entity) {
2998+
private Document getMappedSortObject(Document sortObject, @Nullable MongoPersistentEntity<?> entity) {
29972999

29983000
if (ObjectUtils.isEmpty(sortObject)) {
29993001
return null;
@@ -3355,11 +3357,8 @@ public T doWith(Document document) {
33553357
class QueryCursorPreparer implements SortingQueryCursorPreparer {
33563358

33573359
private final Query query;
3358-
33593360
private final Document sortObject;
3360-
33613361
private final int limit;
3362-
33633362
private final long skip;
33643363
private final @Nullable Class<?> type;
33653364

spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/SortingQueryCursorPreparer.java

+6-2
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,14 @@
1919
import org.springframework.lang.Nullable;
2020

2121
/**
22+
* {@link CursorPreparer} that exposes its {@link Document sort document}.
23+
*
2224
* @author Christoph Strobl
25+
* @since 4.4.3
2326
*/
2427
interface SortingQueryCursorPreparer extends CursorPreparer {
2528

26-
@Nullable
27-
Document getSortObject();
29+
@Nullable
30+
Document getSortObject();
31+
2832
}

0 commit comments

Comments
 (0)