Skip to content

Commit f527834

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

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
@@ -2643,7 +2643,9 @@ <S, T> List<T> doFind(CollectionPreparer<MongoCollection<Document>> collectionPr
26432643

26442644
if (LOGGER.isDebugEnabled()) {
26452645

2646-
Document mappedSort = preparer instanceof SortingQueryCursorPreparer sqcp ? getMappedSortObject(sqcp.getSortObject(), sourceClass) : null;
2646+
Document mappedSort = preparer instanceof SortingQueryCursorPreparer sqcp
2647+
? getMappedSortObject(sqcp.getSortObject(), entity)
2648+
: null;
26472649
LOGGER.debug(String.format("find using query: %s fields: %s sort: %s for class: %s in collection: %s",
26482650
serializeToJsonSafely(mappedQuery), mappedFields, serializeToJsonSafely(mappedSort), sourceClass,
26492651
collectionName));
@@ -3011,7 +3013,7 @@ private Document getMappedSortObject(Document sortObject, Class<?> type) {
30113013
}
30123014

30133015
@Nullable
3014-
private Document getMappedSortObject(Document sortObject, MongoPersistentEntity<?> entity) {
3016+
private Document getMappedSortObject(Document sortObject, @Nullable MongoPersistentEntity<?> entity) {
30153017

30163018
if (ObjectUtils.isEmpty(sortObject)) {
30173019
return null;
@@ -3373,11 +3375,8 @@ public T doWith(Document document) {
33733375
class QueryCursorPreparer implements SortingQueryCursorPreparer {
33743376

33753377
private final Query query;
3376-
33773378
private final Document sortObject;
3378-
33793379
private final int limit;
3380-
33813380
private final long skip;
33823381
private final @Nullable Class<?> type;
33833382

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)