From 68bff5378172fa9eb93c08a05a29e0cfccfed961 Mon Sep 17 00:00:00 2001 From: Mark Paluch Date: Wed, 10 Apr 2024 16:08:02 +0200 Subject: [PATCH] Polishing. Consistent log field ordering, serialize sort safely. See #4686 Original pull request: #4679 --- .../data/mongodb/core/MongoTemplate.java | 15 +++++++++------ .../data/mongodb/core/ReactiveMongoTemplate.java | 7 ++++--- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/MongoTemplate.java b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/MongoTemplate.java index 2b87fb191e..8ac23593db 100644 --- a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/MongoTemplate.java +++ b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/MongoTemplate.java @@ -561,8 +561,8 @@ protected void executeQuery(Query query, String collectionName, DocumentCallback Document fieldsObject = query.getFieldsObject(); if (LOGGER.isDebugEnabled()) { - LOGGER.debug(String.format("Executing query: %s sort: %s fields: %s in collection: %s", - serializeToJsonSafely(queryObject), sortObject, fieldsObject, collectionName)); + LOGGER.debug(String.format("Executing query: %s fields: %s sort: %s in collection: %s", + serializeToJsonSafely(queryObject), fieldsObject, serializeToJsonSafely(sortObject), collectionName)); } this.executeQueryInternal(new FindCallback(createDelegate(query), queryObject, fieldsObject, null), @@ -2555,7 +2555,8 @@ protected List doFind(String collectionName, if (LOGGER.isDebugEnabled()) { LOGGER.debug(String.format("find using query: %s fields: %s sort: %s for class: %s in collection: %s", - serializeToJsonSafely(mappedQuery), mappedSort, mappedFields, entityClass, collectionName)); + serializeToJsonSafely(mappedQuery), mappedFields, serializeToJsonSafely(mappedSort), entityClass, + collectionName)); } return executeFindMultiInternal(new FindCallback(collectionPreparer, mappedQuery, mappedFields, null), @@ -2581,7 +2582,8 @@ List doFind(CollectionPreparer> collectionPr if (LOGGER.isDebugEnabled()) { LOGGER.debug(String.format("find using query: %s fields: %s sort: %s for class: %s in collection: %s", - serializeToJsonSafely(mappedQuery), mappedSort, mappedFields, sourceClass, collectionName)); + serializeToJsonSafely(mappedQuery), mappedFields, serializeToJsonSafely(mappedSort), sourceClass, + collectionName)); } return executeFindMultiInternal(new FindCallback(collectionPreparer, mappedQuery, mappedFields, null), preparer, @@ -2665,7 +2667,7 @@ protected T doFindAndRemove(CollectionPreparer collectionPreparer, String co if (LOGGER.isDebugEnabled()) { LOGGER.debug(String.format("findAndRemove using query: %s fields: %s sort: %s for class: %s in collection: %s", - serializeToJsonSafely(query), fields, sort, entityClass, collectionName)); + serializeToJsonSafely(query), fields, serializeToJsonSafely(sort), entityClass, collectionName)); } MongoPersistentEntity entity = mappingContext.getPersistentEntity(entityClass); @@ -2698,7 +2700,8 @@ protected T doFindAndModify(CollectionPreparer collectionPreparer, String co if (LOGGER.isDebugEnabled()) { LOGGER.debug(String.format( "findAndModify using query: %s fields: %s sort: %s for class: %s and update: %s in collection: %s", - serializeToJsonSafely(mappedQuery), fields, sort, entityClass, serializeToJsonSafely(mappedUpdate), + serializeToJsonSafely(mappedQuery), fields, serializeToJsonSafely(sort), entityClass, + serializeToJsonSafely(mappedUpdate), collectionName)); } diff --git a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/ReactiveMongoTemplate.java b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/ReactiveMongoTemplate.java index a91ee5ed96..5c042964c5 100644 --- a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/ReactiveMongoTemplate.java +++ b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/ReactiveMongoTemplate.java @@ -2399,7 +2399,7 @@ protected Mono doFindAndRemove(String collectionName, if (LOGGER.isDebugEnabled()) { LOGGER.debug(String.format("findAndRemove using query: %s fields: %s sort: %s for class: %s in collection: %s", - serializeToJsonSafely(query), fields, sort, entityClass, collectionName)); + serializeToJsonSafely(query), fields, serializeToJsonSafely(sort), entityClass, collectionName)); } MongoPersistentEntity entity = mappingContext.getPersistentEntity(entityClass); @@ -2426,7 +2426,8 @@ protected Mono doFindAndModify(String collectionName, if (LOGGER.isDebugEnabled()) { LOGGER.debug(String.format( "findAndModify using query: %s fields: %s sort: %s for class: %s and update: %s " + "in collection: %s", - serializeToJsonSafely(mappedQuery), fields, sort, entityClass, serializeToJsonSafely(mappedUpdate), + serializeToJsonSafely(mappedQuery), fields, serializeToJsonSafely(sort), entityClass, + serializeToJsonSafely(mappedUpdate), collectionName)); } @@ -2493,7 +2494,7 @@ private Mono doFindAndReplace(String collectionName, LOGGER.debug(String.format( "findAndReplace using query: %s fields: %s sort: %s for class: %s and replacement: %s " + "in collection: %s", - serializeToJsonSafely(mappedQuery), mappedFields, mappedSort, entityType, + serializeToJsonSafely(mappedQuery), mappedFields, serializeToJsonSafely(mappedSort), entityType, serializeToJsonSafely(replacement), collectionName)); }