Polishing.

Reformat code. Reuse PersistentEntity for mapping instead of resolving TypeInformation from Class.

Original pull request: #4892
See: #4860
This commit is contained in:
Mark Paluch
2025-02-13 15:35:16 +01:00
parent f01b1bc996
commit 4ebcdf590b
3 changed files with 14 additions and 8 deletions

View File

@@ -20,9 +20,10 @@ import java.util.Optional;
import java.util.stream.Stream;
import org.bson.Document;
import org.springframework.dao.IncorrectResultSizeDataAccessException;
import org.springframework.data.domain.Window;
import org.springframework.data.domain.ScrollPosition;
import org.springframework.data.domain.Window;
import org.springframework.data.mongodb.core.query.NearQuery;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.data.mongodb.core.query.SerializationUtils;
@@ -228,11 +229,13 @@ class ExecutableFindOperationSupport implements ExecutableFindOperation {
}
@Override
@Nullable
public ReadPreference getReadPreference() {
return delegate.getReadPreference();
}
@Override
@Nullable
public Document getSortObject() {
return delegate instanceof SortingQueryCursorPreparer sqcp ? sqcp.getSortObject() : null;
}

View File

@@ -2624,7 +2624,9 @@ public class MongoTemplate
if (LOGGER.isDebugEnabled()) {
Document mappedSort = preparer instanceof SortingQueryCursorPreparer sqcp ? getMappedSortObject(sqcp.getSortObject(), sourceClass) : null;
Document mappedSort = preparer instanceof SortingQueryCursorPreparer sqcp
? getMappedSortObject(sqcp.getSortObject(), entity)
: null;
LOGGER.debug(String.format("find using query: %s fields: %s sort: %s for class: %s in collection: %s",
serializeToJsonSafely(mappedQuery), mappedFields, serializeToJsonSafely(mappedSort), sourceClass,
collectionName));
@@ -2993,7 +2995,7 @@ public class MongoTemplate
}
@Nullable
private Document getMappedSortObject(Document sortObject, MongoPersistentEntity<?> entity) {
private Document getMappedSortObject(Document sortObject, @Nullable MongoPersistentEntity<?> entity) {
if (ObjectUtils.isEmpty(sortObject)) {
return null;
@@ -3355,11 +3357,8 @@ public class MongoTemplate
class QueryCursorPreparer implements SortingQueryCursorPreparer {
private final Query query;
private final Document sortObject;
private final int limit;
private final long skip;
private final @Nullable Class<?> type;

View File

@@ -19,10 +19,14 @@ import org.bson.Document;
import org.springframework.lang.Nullable;
/**
* {@link CursorPreparer} that exposes its {@link Document sort document}.
*
* @author Christoph Strobl
* @since 4.3.9
*/
interface SortingQueryCursorPreparer extends CursorPreparer {
@Nullable
Document getSortObject();
@Nullable
Document getSortObject();
}