DATAMONGO-2365 - Polishing.

Reformat code. Fix method name and generics. Whitespaces.

Original pull request: #828.
This commit is contained in:
Mark Paluch
2020-01-29 13:40:01 +01:00
parent c7f9274480
commit f8ee9648da
3 changed files with 29 additions and 26 deletions

View File

@@ -17,7 +17,6 @@ package org.springframework.data.mongodb.core;
import static org.springframework.data.mongodb.core.query.SerializationUtils.*;
import com.mongodb.client.MongoClient;
import lombok.AccessLevel;
import lombok.AllArgsConstructor;
import lombok.NonNull;
@@ -34,6 +33,7 @@ import org.bson.Document;
import org.bson.conversions.Bson;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
@@ -54,8 +54,8 @@ import org.springframework.data.geo.GeoResults;
import org.springframework.data.geo.Metric;
import org.springframework.data.mapping.callback.EntityCallbacks;
import org.springframework.data.mapping.context.MappingContext;
import org.springframework.data.mongodb.MongoDatabaseUtils;
import org.springframework.data.mongodb.MongoDatabaseFactory;
import org.springframework.data.mongodb.MongoDatabaseUtils;
import org.springframework.data.mongodb.SessionSynchronization;
import org.springframework.data.mongodb.core.BulkOperations.BulkMode;
import org.springframework.data.mongodb.core.DefaultBulkOperations.BulkOperationContext;
@@ -134,6 +134,7 @@ import com.mongodb.client.ClientSession;
import com.mongodb.client.DistinctIterable;
import com.mongodb.client.FindIterable;
import com.mongodb.client.MapReduceIterable;
import com.mongodb.client.MongoClient;
import com.mongodb.client.MongoCollection;
import com.mongodb.client.MongoCursor;
import com.mongodb.client.MongoDatabase;
@@ -904,7 +905,7 @@ public class MongoTemplate implements MongoOperations, ApplicationContextAware,
Assert.notNull(resultClass, "ResultClass must not be null!");
MongoPersistentEntity<?> entity = entityClass != Object.class ? getPersistentEntity(entityClass) : null;
DistinctQueryContext distinctQueryContext = queryOperations.distincQueryContext(query, field);
DistinctQueryContext distinctQueryContext = queryOperations.distinctQueryContext(query, field);
Document mappedQuery = distinctQueryContext.getMappedQuery(entity);
String mappedFieldName = distinctQueryContext.getMappedFieldName(entity);
@@ -1668,7 +1669,8 @@ public class MongoTemplate implements MongoOperations, ApplicationContextAware,
MongoPersistentEntity<?> entity = getPersistentEntity(entityClass);
DeleteContext deleteContext = multi ? queryOperations.deleteQueryContext(query) : queryOperations.deleteSingleContext(query);
DeleteContext deleteContext = multi ? queryOperations.deleteQueryContext(query)
: queryOperations.deleteSingleContext(query);
Document queryObject = deleteContext.getMappedQuery(entity);
DeleteOptions options = deleteContext.getDeleteOptions(entityClass);

View File

@@ -56,7 +56,7 @@ import com.mongodb.client.model.UpdateOptions;
* {@link QueryOperations} centralizes common operations required before an operation is actually ready to be executed.
* This involves mapping {@link Query queries} into their respective MongoDB representation, computing execution options
* for {@literal count}, {@literal remove}, ... <br />
*
*
* @author Christoph Strobl
* @since 3.0
*/
@@ -104,7 +104,7 @@ class QueryOperations {
* @param query must not be {@literal null}.
* @return new instance of {@link DistinctQueryContext}.
*/
DistinctQueryContext distincQueryContext(Query query, String fieldName) {
DistinctQueryContext distinctQueryContext(Query query, String fieldName) {
return new DistinctQueryContext(query, fieldName);
}
@@ -203,7 +203,7 @@ class QueryOperations {
/**
* Extract the raw {@link Query#getQueryObject() unmapped document} from the {@link Query}.
*
*
* @return
*/
Document getQueryObject() {
@@ -212,20 +212,21 @@ class QueryOperations {
/**
* Get the already mapped MongoDB query representation.
*
*
* @param domainType can be {@literal null}.
* @param entityLookup the {@link Function lookup} used to provide the {@link MongoPersistentEntity} for the
* given{@literal domainType}
* @param <T>
* @return never {@literal null}.
*/
<T> Document getMappedQuery(@Nullable Class domainType, Function<Class<T>, MongoPersistentEntity> entityLookup) {
<T> Document getMappedQuery(@Nullable Class<T> domainType,
Function<Class<T>, MongoPersistentEntity<?>> entityLookup) {
return getMappedQuery(domainType == null ? null : entityLookup.apply(domainType));
}
/**
* Get the already mapped MongoDB query representation.
*
*
* @param entity the Entity to map field names to. Can be {@literal null}.
* @param <T>
* @return never {@literal null}.
@@ -259,7 +260,7 @@ class QueryOperations {
* Apply the {@link com.mongodb.client.model.Collation} if present extracted from the {@link Query} or fall back to
* the {@literal domain types} default {@link org.springframework.data.mongodb.core.mapping.Document#collation()
* collation}.
*
*
* @param domainType can be {@literal null}.
* @param consumer must not be {@literal null}.
*/
@@ -271,7 +272,7 @@ class QueryOperations {
* Get the {@link com.mongodb.client.model.Collation} extracted from the {@link Query} if present or fall back to
* the {@literal domain types} default {@link org.springframework.data.mongodb.core.mapping.Document#collation()
* collation}.
*
*
* @param domainType can be {@literal null}.
* @return never {@literal null}.
*/
@@ -284,7 +285,7 @@ class QueryOperations {
/**
* A {@link QueryContext} that encapsulates common tasks required when running {@literal distinct} queries.
*
*
* @author Christoph Strobl
*/
class DistinctQueryContext extends QueryContext {
@@ -325,6 +326,7 @@ class QueryOperations {
* @param <T>
* @return never {@literal null}.
*/
@SuppressWarnings("unchecked")
<T> Class<T> getDriverCompatibleClass(Class<T> type) {
return codecRegistryProvider.getCodecFor(type) //
@@ -369,7 +371,7 @@ class QueryOperations {
/**
* Creates a new {@link CountContext} instance.
*
*
* @param query can be {@literal null}.
*/
CountContext(@Nullable Query query) {
@@ -431,7 +433,7 @@ class QueryOperations {
*/
class DeleteContext extends QueryContext {
private boolean multi;
private final boolean multi;
/**
* Crate a new {@link DeleteContext} instance.
@@ -602,7 +604,7 @@ class QueryOperations {
/**
* Get the already mapped aggregation pipeline to use with an {@link #isAggregationUpdate()}.
*
*
* @param domainType must not be {@literal null}.
* @return never {@literal null}.
*/
@@ -630,7 +632,7 @@ class QueryOperations {
/**
* Increase a potential {@link MongoPersistentEntity#getVersionProperty() version property} prior to update if not
* already done in the actual {@link UpdateDefinition}
*
*
* @param persistentEntity can be {@literal null}.
*/
void increaseVersionForUpdateIfNecessary(@Nullable MongoPersistentEntity<?> persistentEntity) {

View File

@@ -17,7 +17,6 @@ package org.springframework.data.mongodb.core;
import static org.springframework.data.mongodb.core.query.SerializationUtils.*;
import com.mongodb.client.result.InsertOneResult;
import lombok.AccessLevel;
import lombok.NonNull;
import lombok.RequiredArgsConstructor;
@@ -40,6 +39,7 @@ import org.reactivestreams.Publisher;
import org.reactivestreams.Subscriber;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
@@ -140,6 +140,7 @@ import com.mongodb.client.model.UpdateOptions;
import com.mongodb.client.model.ValidationOptions;
import com.mongodb.client.model.changestream.FullDocument;
import com.mongodb.client.result.DeleteResult;
import com.mongodb.client.result.InsertOneResult;
import com.mongodb.client.result.UpdateResult;
import com.mongodb.reactivestreams.client.AggregatePublisher;
import com.mongodb.reactivestreams.client.ChangeStreamPublisher;
@@ -922,7 +923,7 @@ public class ReactiveMongoTemplate implements ReactiveMongoOperations, Applicati
Assert.notNull(resultClass, "ResultClass must not be null!");
MongoPersistentEntity<?> entity = getPersistentEntity(entityClass);
DistinctQueryContext distinctQueryContext = queryOperations.distincQueryContext(query, field);
DistinctQueryContext distinctQueryContext = queryOperations.distinctQueryContext(query, field);
Document mappedQuery = distinctQueryContext.getMappedQuery(entity);
String mappedFieldName = distinctQueryContext.getMappedFieldName(entity);
@@ -2284,12 +2285,10 @@ public class ReactiveMongoTemplate implements ReactiveMongoOperations, Applicati
return createMono(db -> db.createCollection(collectionName, collectionOptions)).doOnSuccess(it -> {
// TODO: Emit a collection created event
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("Created collection [{}]", collectionName);
}
// TODO: Emit a collection created event
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("Created collection [{}]", collectionName);
}
}).thenReturn(getCollection(collectionName));
}
@@ -2934,7 +2933,7 @@ public class ReactiveMongoTemplate implements ReactiveMongoOperations, Applicati
result = options.getCollation().map(Collation::toMongoCollation).map(result::collation).orElse(result);
if(!CollectionUtils.isEmpty(arrayFilters)) {
if (!CollectionUtils.isEmpty(arrayFilters)) {
result.arrayFilters(arrayFilters);
}