Adopt to deprecation removals in Commons.

Closes #4837
This commit is contained in:
Mark Paluch
2024-11-19 15:30:17 +01:00
parent 8b924f42e1
commit 59491d8f36
42 changed files with 101 additions and 557 deletions

View File

@@ -71,7 +71,6 @@ import org.springframework.data.mapping.model.ParameterValueProvider;
import org.springframework.data.mapping.model.PersistentEntityParameterValueProvider;
import org.springframework.data.mapping.model.PropertyValueProvider;
import org.springframework.data.mapping.model.SpELContext;
import org.springframework.data.mapping.model.SpELExpressionParameterValueProvider;
import org.springframework.data.mapping.model.ValueExpressionEvaluator;
import org.springframework.data.mapping.model.ValueExpressionParameterValueProvider;
import org.springframework.data.mongodb.CodecRegistryProvider;
@@ -2059,7 +2058,7 @@ public class MappingMongoConverter extends AbstractMongoConverter
}
/**
* Extension of {@link SpELExpressionParameterValueProvider} to recursively trigger value conversion on the raw
* Extension of {@link ValueExpressionParameterValueProvider} to recursively trigger value conversion on the raw
* resolved SpEL value.
*
* @author Oliver Gierke

View File

@@ -98,13 +98,7 @@ class UnwrappedMongoPersistentEntity<T> implements MongoPersistentEntity<T> {
return delegate.getName();
}
@Override
@Nullable
@Deprecated
public PreferredConstructor<T, MongoPersistentProperty> getPersistenceConstructor() {
return delegate.getPersistenceConstructor();
}
@Override
public InstanceCreatorMetadata<MongoPersistentProperty> getInstanceCreatorMetadata() {
return delegate.getInstanceCreatorMetadata();

View File

@@ -21,11 +21,8 @@ import java.util.List;
import org.bson.Document;
import org.bson.codecs.configuration.CodecRegistry;
import org.springframework.core.env.StandardEnvironment;
import org.springframework.data.expression.ValueEvaluationContextProvider;
import org.springframework.data.expression.ValueExpression;
import org.springframework.data.expression.ValueExpressionParser;
import org.springframework.data.mapping.model.SpELExpressionEvaluator;
import org.springframework.data.mapping.model.ValueExpressionEvaluator;
import org.springframework.data.mongodb.core.ExecutableFindOperation.ExecutableFind;
import org.springframework.data.mongodb.core.ExecutableFindOperation.FindWithQuery;
@@ -47,16 +44,10 @@ import org.springframework.data.mongodb.repository.query.MongoQueryExecution.Upd
import org.springframework.data.mongodb.util.json.ParameterBindingContext;
import org.springframework.data.mongodb.util.json.ParameterBindingDocumentCodec;
import org.springframework.data.repository.query.ParameterAccessor;
import org.springframework.data.repository.query.QueryMethodEvaluationContextProvider;
import org.springframework.data.repository.query.QueryMethodValueEvaluationContextAccessor;
import org.springframework.data.repository.query.RepositoryQuery;
import org.springframework.data.repository.query.ResultProcessor;
import org.springframework.data.repository.query.ValueExpressionDelegate;
import org.springframework.data.spel.ExpressionDependencies;
import org.springframework.data.util.Lazy;
import org.springframework.expression.EvaluationContext;
import org.springframework.expression.ExpressionParser;
import org.springframework.expression.spel.standard.SpelExpressionParser;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
import org.springframework.util.ObjectUtils;
@@ -84,36 +75,6 @@ public abstract class AbstractMongoQuery implements RepositoryQuery {
private final ValueExpressionDelegate valueExpressionDelegate;
private final ValueEvaluationContextProvider valueEvaluationContextProvider;
/**
* Creates a new {@link AbstractMongoQuery} from the given {@link MongoQueryMethod} and {@link MongoOperations}.
*
* @param method must not be {@literal null}.
* @param operations must not be {@literal null}.
* @param expressionParser must not be {@literal null}.
* @param evaluationContextProvider must not be {@literal null}.
* @deprecated use the constructor version with {@link ValueExpressionDelegate}
*/
@Deprecated(since = "4.4.0")
public AbstractMongoQuery(MongoQueryMethod method, MongoOperations operations, ExpressionParser expressionParser,
QueryMethodEvaluationContextProvider evaluationContextProvider) {
Assert.notNull(operations, "MongoOperations must not be null");
Assert.notNull(method, "MongoQueryMethod must not be null");
Assert.notNull(expressionParser, "SpelExpressionParser must not be null");
Assert.notNull(evaluationContextProvider, "QueryMethodEvaluationContextProvider must not be null");
this.method = method;
this.operations = operations;
MongoEntityMetadata<?> metadata = method.getEntityInformation();
Class<?> type = metadata.getCollectionEntity().getType();
this.executableFind = operations.query(type);
this.executableUpdate = operations.update(type);
this.valueExpressionDelegate = new ValueExpressionDelegate(new QueryMethodValueEvaluationContextAccessor(new StandardEnvironment(), evaluationContextProvider.getEvaluationContextProvider()), ValueExpressionParser.create(() -> expressionParser));
this.valueEvaluationContextProvider = valueExpressionDelegate.createValueContextProvider(method.getParameters());
}
/**
* Creates a new {@link AbstractMongoQuery} from the given {@link MongoQueryMethod} and {@link MongoOperations}.
*
@@ -185,7 +146,8 @@ public abstract class AbstractMongoQuery implements RepositoryQuery {
}
/**
* If present apply the {@link com.mongodb.ReadPreference} from the {@link org.springframework.data.mongodb.repository.ReadPreference} annotation.
* If present apply the {@link com.mongodb.ReadPreference} from the
* {@link org.springframework.data.mongodb.repository.ReadPreference} annotation.
*
* @param query must not be {@literal null}.
* @return never {@literal null}.
@@ -396,20 +358,6 @@ public abstract class AbstractMongoQuery implements RepositoryQuery {
return codec.get();
}
/**
* Obtain a the {@link EvaluationContext} suitable to evaluate expressions backed by the given dependencies.
*
* @param dependencies must not be {@literal null}.
* @param accessor must not be {@literal null}.
* @return the {@link SpELExpressionEvaluator}.
* @since 2.4
*/
protected SpELExpressionEvaluator getSpELExpressionEvaluatorFor(ExpressionDependencies dependencies,
ConvertingParameterAccessor accessor) {
return new DefaultSpELExpressionEvaluator(new SpelExpressionParser(), valueEvaluationContextProvider.getEvaluationContext(accessor.getValues(), dependencies).getEvaluationContext());
}
/**
* Obtain a {@link ValueExpressionEvaluator} suitable to evaluate expressions.
*
@@ -418,8 +366,9 @@ public abstract class AbstractMongoQuery implements RepositoryQuery {
* @since 4.4.0
*/
protected ValueExpressionEvaluator getExpressionEvaluatorFor(MongoParameterAccessor accessor) {
return new ValueExpressionDelegateValueExpressionEvaluator(valueExpressionDelegate, (ValueExpression expression) ->
valueEvaluationContextProvider.getEvaluationContext(accessor.getValues(), expression.getExpressionDependencies()));
return new ValueExpressionDelegateValueExpressionEvaluator(valueExpressionDelegate,
(ValueExpression expression) -> valueEvaluationContextProvider.getEvaluationContext(accessor.getValues(),
expression.getExpressionDependencies()));
}
/**

View File

@@ -27,14 +27,11 @@ import org.bson.codecs.configuration.CodecRegistry;
import org.reactivestreams.Publisher;
import org.springframework.core.convert.converter.Converter;
import org.springframework.core.env.StandardEnvironment;
import org.springframework.data.expression.ReactiveValueEvaluationContextProvider;
import org.springframework.data.expression.ValueEvaluationContext;
import org.springframework.data.expression.ValueEvaluationContextProvider;
import org.springframework.data.expression.ValueExpression;
import org.springframework.data.expression.ValueExpressionParser;
import org.springframework.data.mapping.model.EntityInstantiators;
import org.springframework.data.mapping.model.SpELExpressionEvaluator;
import org.springframework.data.mapping.model.ValueExpressionEvaluator;
import org.springframework.data.mongodb.core.MongoOperations;
import org.springframework.data.mongodb.core.ReactiveFindOperation.FindWithProjection;
@@ -56,14 +53,10 @@ import org.springframework.data.mongodb.repository.query.ReactiveMongoQueryExecu
import org.springframework.data.mongodb.util.json.ParameterBindingContext;
import org.springframework.data.mongodb.util.json.ParameterBindingDocumentCodec;
import org.springframework.data.repository.query.ParameterAccessor;
import org.springframework.data.repository.query.QueryMethodValueEvaluationContextAccessor;
import org.springframework.data.repository.query.ReactiveQueryMethodEvaluationContextProvider;
import org.springframework.data.repository.query.RepositoryQuery;
import org.springframework.data.repository.query.ResultProcessor;
import org.springframework.data.repository.query.ValueExpressionDelegate;
import org.springframework.data.spel.ExpressionDependencies;
import org.springframework.expression.ExpressionParser;
import org.springframework.expression.spel.standard.SpelExpressionParser;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
import org.springframework.util.ObjectUtils;
@@ -89,45 +82,6 @@ public abstract class AbstractReactiveMongoQuery implements RepositoryQuery {
private final ValueExpressionDelegate valueExpressionDelegate;
private final ReactiveValueEvaluationContextProvider valueEvaluationContextProvider;
/**
* Creates a new {@link AbstractReactiveMongoQuery} from the given {@link MongoQueryMethod} and
* {@link MongoOperations}.
*
* @param method must not be {@literal null}.
* @param operations must not be {@literal null}.
* @param expressionParser must not be {@literal null}.
* @param evaluationContextProvider must not be {@literal null}.
* @deprecated use the constructor version with {@link ValueExpressionDelegate}
*/
@Deprecated(since = "4.4.0")
public AbstractReactiveMongoQuery(ReactiveMongoQueryMethod method, ReactiveMongoOperations operations,
ExpressionParser expressionParser, ReactiveQueryMethodEvaluationContextProvider evaluationContextProvider) {
Assert.notNull(method, "MongoQueryMethod must not be null");
Assert.notNull(operations, "ReactiveMongoOperations must not be null");
Assert.notNull(expressionParser, "SpelExpressionParser must not be null");
Assert.notNull(evaluationContextProvider, "ReactiveEvaluationContextExtension must not be null");
this.method = method;
this.operations = operations;
this.instantiators = new EntityInstantiators();
this.valueExpressionDelegate = new ValueExpressionDelegate(
new QueryMethodValueEvaluationContextAccessor(new StandardEnvironment(),
evaluationContextProvider.getEvaluationContextProvider()),
ValueExpressionParser.create(() -> expressionParser));
MongoEntityMetadata<?> metadata = method.getEntityInformation();
Class<?> type = metadata.getCollectionEntity().getType();
this.findOperationWithProjection = operations.query(type);
this.updateOps = operations.update(type);
ValueEvaluationContextProvider valueContextProvider = valueExpressionDelegate
.createValueContextProvider(method.getParameters());
Assert.isInstanceOf(ReactiveValueEvaluationContextProvider.class, valueContextProvider,
"ValueEvaluationContextProvider must be reactive");
this.valueEvaluationContextProvider = (ReactiveValueEvaluationContextProvider) valueContextProvider;
}
/**
* Creates a new {@link AbstractReactiveMongoQuery} from the given {@link MongoQueryMethod} and
* {@link MongoOperations}.
@@ -460,26 +414,6 @@ public abstract class AbstractReactiveMongoQuery implements RepositoryQuery {
return getCodecRegistry().map(ParameterBindingDocumentCodec::new);
}
/**
* Obtain a {@link Mono publisher} emitting the {@link SpELExpressionEvaluator} suitable to evaluate expressions
* backed by the given dependencies.
*
* @param dependencies must not be {@literal null}.
* @param accessor must not be {@literal null}.
* @return a {@link Mono} emitting the {@link SpELExpressionEvaluator} when ready.
* @since 3.4
* @deprecated since 4.4.0, use
* {@link #getValueExpressionEvaluatorLater(ExpressionDependencies, MongoParameterAccessor)} instead
*/
@Deprecated(since = "4.4.0")
protected Mono<SpELExpressionEvaluator> getSpelEvaluatorFor(ExpressionDependencies dependencies,
MongoParameterAccessor accessor) {
return valueEvaluationContextProvider.getEvaluationContextLater(accessor.getValues(), dependencies)
.map(evaluationContext -> (SpELExpressionEvaluator) new DefaultSpELExpressionEvaluator(
new SpelExpressionParser(), evaluationContext.getEvaluationContext()))
.defaultIfEmpty(DefaultSpELExpressionEvaluator.unsupported());
}
/**
* Obtain a {@link ValueExpressionEvaluator} suitable to evaluate expressions.
*

View File

@@ -1,69 +0,0 @@
/*
* Copyright 2020-2025 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.data.mongodb.repository.query;
import org.springframework.data.mapping.model.SpELExpressionEvaluator;
import org.springframework.expression.EvaluationContext;
import org.springframework.expression.ExpressionParser;
/**
* Simple {@link SpELExpressionEvaluator} implementation using {@link ExpressionParser} and {@link EvaluationContext}.
*
* @author Mark Paluch
* @since 3.1
*/
class DefaultSpELExpressionEvaluator implements SpELExpressionEvaluator {
private final ExpressionParser parser;
private final EvaluationContext context;
DefaultSpELExpressionEvaluator(ExpressionParser parser, EvaluationContext context) {
this.parser = parser;
this.context = context;
}
/**
* Return a {@link SpELExpressionEvaluator} that does not support expression evaluation.
*
* @return a {@link SpELExpressionEvaluator} that does not support expression evaluation.
* @since 3.1
*/
public static SpELExpressionEvaluator unsupported() {
return NoOpExpressionEvaluator.INSTANCE;
}
@Override
@SuppressWarnings("unchecked")
public <T> T evaluate(String expression) {
return (T) parser.parseExpression(expression).getValue(context, Object.class);
}
/**
* {@link SpELExpressionEvaluator} that does not support SpEL evaluation.
*
* @author Mark Paluch
* @since 3.1
*/
enum NoOpExpressionEvaluator implements SpELExpressionEvaluator {
INSTANCE;
@Override
public <T> T evaluate(String expression) {
throw new UnsupportedOperationException("Expression evaluation not supported");
}
}
}

View File

@@ -18,8 +18,6 @@ package org.springframework.data.mongodb.repository.query;
import org.bson.Document;
import org.bson.json.JsonParseException;
import org.springframework.core.env.StandardEnvironment;
import org.springframework.data.expression.ValueExpressionParser;
import org.springframework.data.mapping.context.MappingContext;
import org.springframework.data.mongodb.core.MongoOperations;
import org.springframework.data.mongodb.core.MongoTemplate;
@@ -29,14 +27,11 @@ import org.springframework.data.mongodb.core.query.Field;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.data.mongodb.core.query.TextCriteria;
import org.springframework.data.repository.query.QueryMethod;
import org.springframework.data.repository.query.QueryMethodEvaluationContextProvider;
import org.springframework.data.repository.query.QueryMethodValueEvaluationContextAccessor;
import org.springframework.data.repository.query.RepositoryQuery;
import org.springframework.data.repository.query.ResultProcessor;
import org.springframework.data.repository.query.ReturnedType;
import org.springframework.data.repository.query.ValueExpressionDelegate;
import org.springframework.data.repository.query.parser.PartTree;
import org.springframework.expression.ExpressionParser;
import org.springframework.util.StringUtils;
/**
@@ -54,26 +49,6 @@ public class PartTreeMongoQuery extends AbstractMongoQuery {
private final MappingContext<?, MongoPersistentProperty> context;
private final ResultProcessor processor;
/**
* Creates a new {@link PartTreeMongoQuery} from the given {@link QueryMethod} and {@link MongoTemplate}.
*
* @param method must not be {@literal null}.
* @param mongoOperations must not be {@literal null}.
* @param expressionParser must not be {@literal null}.
* @param evaluationContextProvider must not be {@literal null}.
* @deprecated since 4.4, use the constructors accepting {@link QueryMethodValueEvaluationContextAccessor} instead.
*/
@Deprecated(since = "4.4.0")
public PartTreeMongoQuery(MongoQueryMethod method, MongoOperations mongoOperations, ExpressionParser expressionParser,
QueryMethodEvaluationContextProvider evaluationContextProvider) {
super(method, mongoOperations, expressionParser, evaluationContextProvider);
this.processor = method.getResultProcessor();
this.tree = new PartTree(method.getName(), processor.getReturnedType().getDomainType());
this.isGeoNearQuery = method.isGeoNearQuery();
this.context = mongoOperations.getConverter().getMappingContext();
}
/**
* Creates a new {@link PartTreeMongoQuery} from the given {@link QueryMethod} and {@link MongoTemplate}.
*

View File

@@ -28,14 +28,11 @@ import org.springframework.data.mongodb.core.query.BasicQuery;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.data.mongodb.core.query.TextCriteria;
import org.springframework.data.repository.query.QueryMethod;
import org.springframework.data.repository.query.QueryMethodValueEvaluationContextAccessor;
import org.springframework.data.repository.query.ReactiveQueryMethodEvaluationContextProvider;
import org.springframework.data.repository.query.RepositoryQuery;
import org.springframework.data.repository.query.ResultProcessor;
import org.springframework.data.repository.query.ReturnedType;
import org.springframework.data.repository.query.ValueExpressionDelegate;
import org.springframework.data.repository.query.parser.PartTree;
import org.springframework.expression.ExpressionParser;
import org.springframework.util.StringUtils;
/**
@@ -52,26 +49,6 @@ public class ReactivePartTreeMongoQuery extends AbstractReactiveMongoQuery {
private final MappingContext<?, MongoPersistentProperty> context;
private final ResultProcessor processor;
/**
* Creates a new {@link ReactivePartTreeMongoQuery} from the given {@link QueryMethod} and {@link MongoTemplate}.
*
* @param method must not be {@literal null}.
* @param mongoOperations must not be {@literal null}.
* @param expressionParser must not be {@literal null}.
* @param evaluationContextProvider must not be {@literal null}.
* @deprecated since 4.4.0, use the constructors accepting {@link QueryMethodValueEvaluationContextAccessor} instead.
*/
@Deprecated(since = "4.4.0")
public ReactivePartTreeMongoQuery(ReactiveMongoQueryMethod method, ReactiveMongoOperations mongoOperations,
ExpressionParser expressionParser, ReactiveQueryMethodEvaluationContextProvider evaluationContextProvider) {
super(method, mongoOperations, expressionParser, evaluationContextProvider);
this.processor = method.getResultProcessor();
this.tree = new PartTree(method.getName(), processor.getReturnedType().getDomainType());
this.isGeoNearQuery = method.isGeoNearQuery();
this.context = mongoOperations.getConverter().getMappingContext();
}
/**
* Creates a new {@link ReactivePartTreeMongoQuery} from the given {@link QueryMethod} and {@link MongoTemplate}.
*

View File

@@ -29,11 +29,9 @@ import org.springframework.data.mongodb.core.aggregation.AggregationPipeline;
import org.springframework.data.mongodb.core.convert.MongoConverter;
import org.springframework.data.mongodb.core.mapping.MongoSimpleTypes;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.data.repository.query.ReactiveQueryMethodEvaluationContextProvider;
import org.springframework.data.repository.query.ResultProcessor;
import org.springframework.data.repository.query.ValueExpressionDelegate;
import org.springframework.data.util.ReflectionUtils;
import org.springframework.expression.ExpressionParser;
import org.springframework.lang.Nullable;
/**
@@ -49,24 +47,6 @@ public class ReactiveStringBasedAggregation extends AbstractReactiveMongoQuery {
private final ReactiveMongoOperations reactiveMongoOperations;
private final MongoConverter mongoConverter;
/**
* @param method must not be {@literal null}.
* @param reactiveMongoOperations must not be {@literal null}.
* @param expressionParser must not be {@literal null}.
* @param evaluationContextProvider must not be {@literal null}.
* @deprecated since 4.4.0, use the constructors accepting {@link ValueExpressionDelegate} instead.
*/
@Deprecated(since = "4.4.0")
public ReactiveStringBasedAggregation(ReactiveMongoQueryMethod method,
ReactiveMongoOperations reactiveMongoOperations, ExpressionParser expressionParser,
ReactiveQueryMethodEvaluationContextProvider evaluationContextProvider) {
super(method, reactiveMongoOperations, expressionParser, evaluationContextProvider);
this.reactiveMongoOperations = reactiveMongoOperations;
this.mongoConverter = reactiveMongoOperations.getConverter();
}
/**
* @param method must not be {@literal null}.
* @param reactiveMongoOperations must not be {@literal null}.

View File

@@ -28,12 +28,8 @@ import org.springframework.data.mongodb.core.query.BasicQuery;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.data.mongodb.util.json.ParameterBindingContext;
import org.springframework.data.mongodb.util.json.ParameterBindingDocumentCodec;
import org.springframework.data.repository.query.ReactiveExtensionAwareQueryMethodEvaluationContextProvider;
import org.springframework.data.repository.query.ReactiveQueryMethodEvaluationContextProvider;
import org.springframework.data.repository.query.ValueExpressionDelegate;
import org.springframework.data.spel.ExpressionDependencies;
import org.springframework.expression.ExpressionParser;
import org.springframework.expression.spel.standard.SpelExpressionParser;
import org.springframework.lang.NonNull;
import org.springframework.util.Assert;
@@ -59,67 +55,8 @@ public class ReactiveStringBasedMongoQuery extends AbstractReactiveMongoQuery {
private final boolean isDeleteQuery;
/**
* Creates a new {@link ReactiveStringBasedMongoQuery} for the given {@link MongoQueryMethod} and
* {@link MongoOperations}.
*
* @param method must not be {@literal null}.
* @param mongoOperations must not be {@literal null}.
* @param expressionParser must not be {@literal null}.
* @param evaluationContextProvider must not be {@literal null}.
* @deprecated since 4.4.0, use the constructors accepting {@link ValueExpressionDelegate} instead.
*/
@Deprecated(since = "4.4.0")
public ReactiveStringBasedMongoQuery(ReactiveMongoQueryMethod method, ReactiveMongoOperations mongoOperations,
ExpressionParser expressionParser, ReactiveQueryMethodEvaluationContextProvider evaluationContextProvider) {
this(method.getAnnotatedQuery(), method, mongoOperations, expressionParser, evaluationContextProvider);
}
/**
* Creates a new {@link ReactiveStringBasedMongoQuery} for the given {@link String}, {@link MongoQueryMethod},
* {@link MongoOperations}, {@link SpelExpressionParser} and
* {@link ReactiveExtensionAwareQueryMethodEvaluationContextProvider}.
*
* @param query must not be {@literal null}.
* @param method must not be {@literal null}.
* @param mongoOperations must not be {@literal null}.
* @param expressionParser must not be {@literal null}.
* @deprecated since 4.4.0, use the constructors accepting {@link ValueExpressionDelegate} instead.
*/
@Deprecated(since = "4.4.0")
public ReactiveStringBasedMongoQuery(String query, ReactiveMongoQueryMethod method,
ReactiveMongoOperations mongoOperations, ExpressionParser expressionParser,
ReactiveQueryMethodEvaluationContextProvider evaluationContextProvider) {
super(method, mongoOperations, expressionParser, evaluationContextProvider);
Assert.notNull(query, "Query must not be null");
this.query = query;
this.expressionParser = ValueExpressionParser.create(() -> expressionParser);
this.fieldSpec = method.getFieldSpecification();
if (method.hasAnnotatedQuery()) {
org.springframework.data.mongodb.repository.Query queryAnnotation = method.getQueryAnnotation();
this.isCountQuery = queryAnnotation.count();
this.isExistsQuery = queryAnnotation.exists();
this.isDeleteQuery = queryAnnotation.delete();
if (hasAmbiguousProjectionFlags(this.isCountQuery, this.isExistsQuery, this.isDeleteQuery)) {
throw new IllegalArgumentException(String.format(COUNT_EXISTS_AND_DELETE, method));
}
} else {
this.isCountQuery = false;
this.isExistsQuery = false;
this.isDeleteQuery = false;
}
}
/**
* Creates a new {@link ReactiveStringBasedMongoQuery} for the given {@link MongoQueryMethod},
* {@link MongoOperations} and {@link ValueExpressionDelegate}.
* Creates a new {@link ReactiveStringBasedMongoQuery} for the given {@link MongoQueryMethod}, {@link MongoOperations}
* and {@link ValueExpressionDelegate}.
*
* @param method must not be {@literal null}.
* @param mongoOperations must not be {@literal null}.

View File

@@ -29,12 +29,9 @@ import org.springframework.data.mongodb.core.aggregation.AggregationResults;
import org.springframework.data.mongodb.core.convert.MongoConverter;
import org.springframework.data.mongodb.core.mapping.MongoSimpleTypes;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.data.repository.query.QueryMethodEvaluationContextProvider;
import org.springframework.data.repository.query.QueryMethodValueEvaluationContextAccessor;
import org.springframework.data.repository.query.ResultProcessor;
import org.springframework.data.repository.query.ValueExpressionDelegate;
import org.springframework.data.util.ReflectionUtils;
import org.springframework.expression.ExpressionParser;
import org.springframework.lang.Nullable;
/**
@@ -51,30 +48,6 @@ public class StringBasedAggregation extends AbstractMongoQuery {
private final MongoOperations mongoOperations;
private final MongoConverter mongoConverter;
/**
* Creates a new {@link StringBasedAggregation} from the given {@link MongoQueryMethod} and {@link MongoOperations}.
*
* @param method must not be {@literal null}.
* @param mongoOperations must not be {@literal null}.
* @param expressionParser must not be {@literal null}.
* @param evaluationContextProvider must not be {@literal null}.
* @deprecated since 4.4.0, use the constructors accepting {@link QueryMethodValueEvaluationContextAccessor} instead.
*/
@Deprecated(since = "4.4.0")
public StringBasedAggregation(MongoQueryMethod method, MongoOperations mongoOperations,
ExpressionParser expressionParser, QueryMethodEvaluationContextProvider evaluationContextProvider) {
super(method, mongoOperations, expressionParser, evaluationContextProvider);
if (method.isPageQuery()) {
throw new InvalidMongoDbApiUsageException(String.format(
"Repository aggregation method '%s' does not support '%s' return type; Please use 'Slice' or 'List' instead",
method.getName(), method.getReturnType().getType().getSimpleName()));
}
this.mongoOperations = mongoOperations;
this.mongoConverter = mongoOperations.getConverter();
}
/**
* Creates a new {@link StringBasedAggregation} from the given {@link MongoQueryMethod} and {@link MongoOperations}.
*

View File

@@ -22,11 +22,8 @@ import org.bson.Document;
import org.springframework.data.mongodb.core.MongoOperations;
import org.springframework.data.mongodb.core.query.BasicQuery;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.data.repository.query.QueryMethodEvaluationContextProvider;
import org.springframework.data.repository.query.QueryMethodValueEvaluationContextAccessor;
import org.springframework.data.repository.query.ValueExpressionDelegate;
import org.springframework.expression.ExpressionParser;
import org.springframework.expression.spel.standard.SpelExpressionParser;
import org.springframework.util.Assert;
/**
@@ -49,47 +46,6 @@ public class StringBasedMongoQuery extends AbstractMongoQuery {
private final boolean isExistsQuery;
private final boolean isDeleteQuery;
/**
* Creates a new {@link StringBasedMongoQuery} for the given {@link MongoQueryMethod}, {@link MongoOperations},
* {@link SpelExpressionParser} and {@link QueryMethodEvaluationContextProvider}.
*
* @param method must not be {@literal null}.
* @param mongoOperations must not be {@literal null}.
* @param expressionParser must not be {@literal null}.
* @param evaluationContextProvider must not be {@literal null}.
* @deprecated since 4.4.0, use the constructors accepting {@link ValueExpressionDelegate} instead.
*/
@Deprecated(since = "4.4.0")
public StringBasedMongoQuery(MongoQueryMethod method, MongoOperations mongoOperations,
ExpressionParser expressionParser, QueryMethodEvaluationContextProvider evaluationContextProvider) {
super(method, mongoOperations, expressionParser, evaluationContextProvider);
String query = method.getAnnotatedQuery();
Assert.notNull(query, "Query must not be null");
this.query = query;
this.fieldSpec = method.getFieldSpecification();
if (method.hasAnnotatedQuery()) {
org.springframework.data.mongodb.repository.Query queryAnnotation = method.getQueryAnnotation();
this.isCountQuery = queryAnnotation.count();
this.isExistsQuery = queryAnnotation.exists();
this.isDeleteQuery = queryAnnotation.delete();
if (hasAmbiguousProjectionFlags(this.isCountQuery, this.isExistsQuery, this.isDeleteQuery)) {
throw new IllegalArgumentException(String.format(COUNT_EXISTS_AND_DELETE, method));
}
} else {
this.isCountQuery = false;
this.isExistsQuery = false;
this.isDeleteQuery = false;
}
}
/**
* Creates a new {@link StringBasedMongoQuery} for the given {@link MongoQueryMethod}, {@link MongoOperations},
* {@link ValueExpressionDelegate}.

View File

@@ -42,7 +42,6 @@ import org.springframework.data.repository.core.support.RepositoryComposition.Re
import org.springframework.data.repository.core.support.RepositoryFactorySupport;
import org.springframework.data.repository.query.QueryLookupStrategy;
import org.springframework.data.repository.query.QueryLookupStrategy.Key;
import org.springframework.data.repository.query.QueryMethodValueEvaluationContextAccessor;
import org.springframework.data.repository.query.RepositoryQuery;
import org.springframework.data.repository.query.ValueExpressionDelegate;
import org.springframework.lang.Nullable;
@@ -61,7 +60,6 @@ public class MongoRepositoryFactory extends RepositoryFactorySupport {
private final CrudMethodMetadataPostProcessor crudMethodMetadataPostProcessor = new CrudMethodMetadataPostProcessor();
private final MongoOperations operations;
private final MappingContext<? extends MongoPersistentEntity<?>, MongoPersistentProperty> mappingContext;
@Nullable private QueryMethodValueEvaluationContextAccessor accessor;
/**
* Creates a new {@link MongoRepositoryFactory} with the given {@link MongoOperations}.

View File

@@ -21,7 +21,6 @@ import java.io.Serializable;
import java.lang.reflect.Method;
import java.util.Optional;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.data.mapping.context.MappingContext;
import org.springframework.data.mongodb.core.ReactiveMongoOperations;
@@ -44,7 +43,6 @@ import org.springframework.data.repository.core.support.RepositoryFragment;
import org.springframework.data.repository.query.QueryLookupStrategy;
import org.springframework.data.repository.query.QueryLookupStrategy.Key;
import org.springframework.data.repository.query.QueryMethodValueEvaluationContextAccessor;
import org.springframework.data.repository.query.ReactiveQueryMethodEvaluationContextProvider;
import org.springframework.data.repository.query.RepositoryQuery;
import org.springframework.data.repository.query.ValueExpressionDelegate;
import org.springframework.lang.Nullable;
@@ -77,7 +75,6 @@ public class ReactiveMongoRepositoryFactory extends ReactiveRepositoryFactorySup
this.operations = mongoOperations;
this.mappingContext = mongoOperations.getConverter().getMappingContext();
setEvaluationContextProvider(ReactiveQueryMethodEvaluationContextProvider.DEFAULT);
addRepositoryProxyPostProcessor(crudMethodMetadataPostProcessor);
}
@@ -132,7 +129,8 @@ public class ReactiveMongoRepositoryFactory extends ReactiveRepositoryFactorySup
return targetRepository;
}
@Override protected Optional<QueryLookupStrategy> getQueryLookupStrategy(Key key,
@Override
protected Optional<QueryLookupStrategy> getQueryLookupStrategy(Key key,
ValueExpressionDelegate valueExpressionDelegate) {
return Optional.of(new MongoQueryLookupStrategy(operations, mappingContext, valueExpressionDelegate));
}
@@ -159,8 +157,8 @@ public class ReactiveMongoRepositoryFactory extends ReactiveRepositoryFactorySup
* @author Christoph Strobl
*/
private record MongoQueryLookupStrategy(ReactiveMongoOperations operations,
MappingContext<? extends MongoPersistentEntity<?>, MongoPersistentProperty> mappingContext,
ValueExpressionDelegate delegate) implements QueryLookupStrategy {
MappingContext<? extends MongoPersistentEntity<?>, MongoPersistentProperty> mappingContext,
ValueExpressionDelegate delegate) implements QueryLookupStrategy {
@Override
public RepositoryQuery resolveQuery(Method method, RepositoryMetadata metadata, ProjectionFactory factory,

View File

@@ -16,17 +16,13 @@
package org.springframework.data.mongodb.repository.support;
import java.io.Serializable;
import java.util.Optional;
import org.springframework.beans.factory.ListableBeanFactory;
import org.springframework.data.mapping.context.MappingContext;
import org.springframework.data.mongodb.core.ReactiveMongoOperations;
import org.springframework.data.mongodb.core.index.IndexOperationsAdapter;
import org.springframework.data.repository.Repository;
import org.springframework.data.repository.core.support.RepositoryFactoryBeanSupport;
import org.springframework.data.repository.core.support.RepositoryFactorySupport;
import org.springframework.data.repository.query.QueryMethodEvaluationContextProvider;
import org.springframework.data.repository.query.ReactiveExtensionAwareQueryMethodEvaluationContextProvider;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
@@ -94,12 +90,6 @@ public class ReactiveMongoRepositoryFactoryBean<T extends Repository<S, ID>, S,
return factory;
}
@Override
protected Optional<QueryMethodEvaluationContextProvider> createDefaultQueryMethodEvaluationContextProvider(
ListableBeanFactory beanFactory) {
return Optional.of(new ReactiveExtensionAwareQueryMethodEvaluationContextProvider(beanFactory));
}
/**
* Creates and initializes a {@link RepositoryFactorySupport} instance.
*

View File

@@ -19,7 +19,6 @@ import java.util.Map;
import java.util.function.Function;
import java.util.function.Supplier;
import org.springframework.data.mapping.model.SpELExpressionEvaluator;
import org.springframework.data.mapping.model.ValueExpressionEvaluator;
import org.springframework.data.spel.ExpressionDependencies;
import org.springframework.data.util.Lazy;
@@ -28,7 +27,6 @@ import org.springframework.expression.Expression;
import org.springframework.expression.ExpressionParser;
import org.springframework.expression.ParseException;
import org.springframework.expression.ParserContext;
import org.springframework.expression.spel.standard.SpelExpressionParser;
import org.springframework.lang.Nullable;
/**
@@ -44,29 +42,6 @@ public class ParameterBindingContext {
private final ValueProvider valueProvider;
private final ValueExpressionEvaluator expressionEvaluator;
/**
* @param valueProvider
* @param expressionParser
* @param evaluationContext
* @deprecated since 4.4.0, use {@link #ParameterBindingContext(ValueProvider, ExpressionParser, Supplier)} instead.
*/
@Deprecated(since = "4.4.0")
public ParameterBindingContext(ValueProvider valueProvider, SpelExpressionParser expressionParser,
EvaluationContext evaluationContext) {
this(valueProvider, expressionParser, () -> evaluationContext);
}
/**
* @param valueProvider
* @param expressionEvaluator
* @since 3.1
* @deprecated since 4.4.0, use {@link #ParameterBindingContext(ValueProvider, ValueExpressionEvaluator)} instead.
*/
@Deprecated(since = "4.4.0")
public ParameterBindingContext(ValueProvider valueProvider, SpELExpressionEvaluator expressionEvaluator) {
this(valueProvider, (ValueExpressionEvaluator) expressionEvaluator);
}
/**
* @param valueProvider
* @param expressionParser

View File

@@ -170,7 +170,7 @@ public class ParameterBindingDocumentCodec implements CollectibleCodec<Document>
public Document decode(@Nullable String json, Object[] values) {
return decode(json, new ParameterBindingContext((index) -> values[index], new SpelExpressionParser(),
EvaluationContextProvider.DEFAULT.getEvaluationContext(values)));
() -> EvaluationContextProvider.DEFAULT.getEvaluationContext(values)));
}
public Document decode(@Nullable String json, ParameterBindingContext bindingContext) {

View File

@@ -49,7 +49,7 @@ import org.springframework.dao.InvalidDataAccessApiUsageException;
import org.springframework.dao.OptimisticLockingFailureException;
import org.springframework.data.annotation.Id;
import org.springframework.data.annotation.LastModifiedDate;
import org.springframework.data.annotation.PersistenceConstructor;
import org.springframework.data.annotation.PersistenceCreator;
import org.springframework.data.annotation.Version;
import org.springframework.data.auditing.IsNewAwareAuditingHandler;
import org.springframework.data.domain.PageRequest;
@@ -4482,7 +4482,7 @@ public class MongoTemplateTests {
LocalDateTime myDate;
@PersistenceConstructor
@PersistenceCreator
TestClass(LocalDateTime myDate) {
this.myDate = myDate;
}
@@ -4739,7 +4739,7 @@ public class MongoTemplateTests {
@org.springframework.data.mongodb.core.mapping.DBRef(lazy = true) Document refToDocUsedInCtor;
@org.springframework.data.mongodb.core.mapping.DBRef(lazy = true) Document refToDocNotUsedInCtor;
@PersistenceConstructor
@PersistenceCreator
public DocumentWithLazyDBrefUsedInPresistenceConstructor(Document refToDocUsedInCtor) {
this.refToDocUsedInCtor = refToDocUsedInCtor;
}

View File

@@ -19,7 +19,7 @@ import java.util.Arrays;
import java.util.Date;
import org.springframework.data.annotation.Id;
import org.springframework.data.annotation.PersistenceConstructor;
import org.springframework.data.annotation.PersistenceCreator;
import org.springframework.data.mongodb.core.mapping.Document;
@Document("newyork")
@@ -30,7 +30,7 @@ public class Venue {
private double[] location;
private Date openingDate;
@PersistenceConstructor
@PersistenceCreator
Venue(String name, double[] location) {
super();
this.name = name;

View File

@@ -46,7 +46,7 @@ import org.mockito.junit.jupiter.MockitoExtension;
import org.springframework.data.annotation.AccessType;
import org.springframework.data.annotation.AccessType.Type;
import org.springframework.data.annotation.Id;
import org.springframework.data.annotation.PersistenceConstructor;
import org.springframework.data.annotation.PersistenceCreator;
import org.springframework.data.mapping.PersistentPropertyAccessor;
import org.springframework.data.mapping.PropertyPath;
import org.springframework.data.mongodb.MongoDatabaseFactory;
@@ -774,7 +774,7 @@ class DbRefMappingMongoConverterUnitTests {
public LazyDbRefTargetWithPeristenceConstructor() {}
@PersistenceConstructor
@PersistenceCreator
LazyDbRefTargetWithPeristenceConstructor(String id, String value) {
super(id, value);
this.persistenceConstructorCalled = true;
@@ -790,7 +790,7 @@ class DbRefMappingMongoConverterUnitTests {
boolean persistenceConstructorCalled;
@PersistenceConstructor
@PersistenceCreator
LazyDbRefTargetWithPeristenceConstructorWithoutDefaultConstructor(String id, String value) {
super(id, value);
this.persistenceConstructorCalled = true;

View File

@@ -63,7 +63,7 @@ import org.springframework.context.support.StaticApplicationContext;
import org.springframework.core.convert.ConverterNotFoundException;
import org.springframework.core.convert.converter.Converter;
import org.springframework.data.annotation.Id;
import org.springframework.data.annotation.PersistenceConstructor;
import org.springframework.data.annotation.PersistenceCreator;
import org.springframework.data.annotation.Transient;
import org.springframework.data.annotation.TypeAlias;
import org.springframework.data.convert.ConverterBuilder;
@@ -103,7 +103,6 @@ import org.springframework.data.mongodb.core.mapping.Unwrapped;
import org.springframework.data.mongodb.core.mapping.event.AfterConvertCallback;
import org.springframework.data.projection.EntityProjection;
import org.springframework.data.projection.EntityProjectionIntrospector;
import org.springframework.data.util.ClassTypeInformation;
import org.springframework.data.util.TypeInformation;
import org.springframework.lang.NonNull;
import org.springframework.lang.Nullable;
@@ -1061,7 +1060,7 @@ class MappingMongoConverterUnitTests {
address.city = "London";
address.street = "Foo";
Object result = converter.convertToMongoType(Collections.singleton(address), ClassTypeInformation.OBJECT);
Object result = converter.convertToMongoType(Collections.singleton(address), TypeInformation.OBJECT);
assertThat(result).isInstanceOf(List.class);
Set<?> readResult = converter.read(Set.class, (org.bson.Document) result);
@@ -1393,7 +1392,7 @@ class MappingMongoConverterUnitTests {
address.street = "Foo";
Object result = converter.convertToMongoType(Collections.singletonList(address),
ClassTypeInformation.from(InterfaceType.class));
TypeInformation.of(InterfaceType.class));
assertThat(result).isInstanceOf(List.class);
@@ -1421,7 +1420,7 @@ class MappingMongoConverterUnitTests {
address.city = "London";
address.street = "Foo";
Object result = converter.convertToMongoType(new Address[] { address }, ClassTypeInformation.OBJECT);
Object result = converter.convertToMongoType(new Address[] { address }, TypeInformation.OBJECT);
assertThat(result).isInstanceOf(List.class);
@@ -1712,7 +1711,7 @@ class MappingMongoConverterUnitTests {
}
@Test // DATAMONGO-1001, DATAMONGO-1509
void shouldWriteCglibProxiedClassTypeInformationCorrectly() {
void shouldWriteCglibProxiedTypeInformationCorrectly() {
ProxyFactory factory = new ProxyFactory();
factory.setTargetClass(GenericType.class);
@@ -2318,7 +2317,7 @@ class MappingMongoConverterUnitTests {
Mockito.doReturn(cluster).when(spyConverter).readRef(dbRef);
Map<Object, Object> result = spyConverter.readMap(spyConverter.getConversionContext(ObjectPath.ROOT), data,
ClassTypeInformation.MAP);
TypeInformation.MAP);
assertThat(((Map) result.get("cluster")).get("_id")).isEqualTo(100L);
}
@@ -3522,7 +3521,7 @@ class MappingMongoConverterUnitTests {
}
@PersistenceConstructor
@PersistenceCreator
public Person(Set<Address> addresses) {
this.addresses = addresses;
}
@@ -3802,7 +3801,7 @@ class MappingMongoConverterUnitTests {
@Field("property") private int m_property;
@PersistenceConstructor
@PersistenceCreator
public PrimitiveContainer(@Value("#root.property") int a_property) {
m_property = a_property;
}
@@ -3817,7 +3816,7 @@ class MappingMongoConverterUnitTests {
@Field("property") private PrimitiveContainer m_property;
@PersistenceConstructor
@PersistenceCreator
public ObjectContainer(@Value("#root.property") PrimitiveContainer a_property) {
m_property = a_property;
}

View File

@@ -23,7 +23,7 @@ import org.junit.jupiter.api.Test;
import org.springframework.data.mongodb.core.mapping.BasicMongoPersistentEntity;
import org.springframework.data.mongodb.core.mapping.Document;
import org.springframework.data.mongodb.core.mapping.MongoPersistentEntity;
import org.springframework.data.util.ClassTypeInformation;
import org.springframework.data.util.TypeInformation;
/**
* Unit tests for {@link ObjectPath}.
@@ -39,9 +39,9 @@ public class ObjectPathUnitTests {
@BeforeEach
public void setUp() {
one = new BasicMongoPersistentEntity<>(ClassTypeInformation.from(EntityOne.class));
two = new BasicMongoPersistentEntity<>(ClassTypeInformation.from(EntityTwo.class));
three = new BasicMongoPersistentEntity<>(ClassTypeInformation.from(EntityThree.class));
one = new BasicMongoPersistentEntity<>(TypeInformation.of(EntityOne.class));
two = new BasicMongoPersistentEntity<>(TypeInformation.of(EntityTwo.class));
three = new BasicMongoPersistentEntity<>(TypeInformation.of(EntityThree.class));
}
@Test // DATAMONGO-1703

View File

@@ -544,7 +544,7 @@ class UpdateMapperUnitTests {
}
@Test // DATAMONG0-471
void testUpdateShouldRetainClassTypeInformationWhenUsing$addToSetWith$eachForCustomTypes() {
void testUpdateShouldRetainTypeInformationWhenUsing$addToSetWith$eachForCustomTypes() {
Update update = new Update().addToSet("models").each(new ModelImpl(2014), new ModelImpl(1), new ModelImpl(28));
Document mappedObject = mapper.getMappedObject(update.getUpdateObject(),

View File

@@ -33,7 +33,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.dao.DataAccessException;
import org.springframework.data.annotation.Id;
import org.springframework.data.annotation.PersistenceConstructor;
import org.springframework.data.annotation.PersistenceCreator;
import org.springframework.data.geo.GeoResults;
import org.springframework.data.geo.Metrics;
import org.springframework.data.geo.Point;
@@ -536,7 +536,7 @@ public class GeoJsonTests {
private String name;
private @GeoSpatialIndexed(type = GeoSpatialIndexType.GEO_2DSPHERE) double[] location;
@PersistenceConstructor
@PersistenceCreator
public Venue2DSphere(String name, double[] location) {
this.name = name;
this.location = location;

View File

@@ -53,7 +53,7 @@ import org.springframework.data.mongodb.core.mapping.MongoMappingContext;
import org.springframework.data.mongodb.core.mapping.MongoPersistentEntity;
import org.springframework.data.mongodb.core.mapping.MongoPersistentProperty;
import org.springframework.data.mongodb.core.mapping.Unwrapped;
import org.springframework.data.util.ClassTypeInformation;
import org.springframework.data.util.TypeInformation;
/**
* Tests for {@link MongoPersistentEntityIndexResolver}.
@@ -1186,7 +1186,7 @@ public class MongoPersistentEntityIndexResolverUnitTests {
@SuppressWarnings({ "rawtypes", "unchecked" })
public void shouldCatchCyclicReferenceExceptionOnRoot() {
MongoPersistentEntity entity = new BasicMongoPersistentEntity<>(ClassTypeInformation.from(Object.class));
MongoPersistentEntity entity = new BasicMongoPersistentEntity<>(TypeInformation.of(Object.class));
MongoPersistentProperty propertyMock = mock(MongoPersistentProperty.class);
when(propertyMock.isEntity()).thenReturn(true);
@@ -1195,7 +1195,7 @@ public class MongoPersistentEntityIndexResolverUnitTests {
new MongoPersistentEntityIndexResolver.CyclicPropertyReferenceException("foo", Object.class, "bar"));
MongoPersistentEntity<SelfCyclingViaCollectionType> selfCyclingEntity = new BasicMongoPersistentEntity<>(
ClassTypeInformation.from(SelfCyclingViaCollectionType.class));
TypeInformation.of(SelfCyclingViaCollectionType.class));
new MongoPersistentEntityIndexResolver(prepareMappingContext(SelfCyclingViaCollectionType.class))
.resolveIndexForEntity(selfCyclingEntity);

View File

@@ -39,7 +39,7 @@ import org.springframework.data.mapping.model.FieldNamingStrategy;
import org.springframework.data.mapping.model.Property;
import org.springframework.data.mapping.model.PropertyNameFieldNamingStrategy;
import org.springframework.data.mapping.model.SimpleTypeHolder;
import org.springframework.data.util.ClassTypeInformation;
import org.springframework.data.util.TypeInformation;
import org.springframework.util.ReflectionUtils;
/**
@@ -56,7 +56,7 @@ public class BasicMongoPersistentPropertyUnitTests {
@BeforeEach
void setup() {
entity = new BasicMongoPersistentEntity<>(ClassTypeInformation.from(Person.class));
entity = new BasicMongoPersistentEntity<>(TypeInformation.of(Person.class));
}
@Test
@@ -90,7 +90,7 @@ public class BasicMongoPersistentPropertyUnitTests {
void usesPropertyAccessForThrowableCause() {
BasicMongoPersistentEntity<Throwable> entity = new BasicMongoPersistentEntity<>(
ClassTypeInformation.from(Throwable.class));
TypeInformation.of(Throwable.class));
MongoPersistentProperty property = getPropertyFor(entity, "cause");
assertThat(property.usePropertyAccess()).isTrue();
@@ -99,7 +99,7 @@ public class BasicMongoPersistentPropertyUnitTests {
@Test // DATAMONGO-607
void usesCustomFieldNamingStrategyByDefault() throws Exception {
ClassTypeInformation<Person> type = ClassTypeInformation.from(Person.class);
TypeInformation<Person> type = TypeInformation.of(Person.class);
Field field = ReflectionUtils.findField(Person.class, "lastname");
MongoPersistentProperty property = new BasicMongoPersistentProperty(Property.of(type, field), entity,
@@ -116,7 +116,7 @@ public class BasicMongoPersistentPropertyUnitTests {
@Test // DATAMONGO-607
void rejectsInvalidValueReturnedByFieldNamingStrategy() {
ClassTypeInformation<Person> type = ClassTypeInformation.from(Person.class);
TypeInformation<Person> type = TypeInformation.of(Person.class);
Field field = ReflectionUtils.findField(Person.class, "lastname");
MongoPersistentProperty property = new BasicMongoPersistentProperty(Property.of(type, field), entity,
@@ -255,7 +255,7 @@ public class BasicMongoPersistentPropertyUnitTests {
}
private static <T> MongoPersistentProperty getPropertyFor(Class<T> type, String fieldname) {
return getPropertyFor(new BasicMongoPersistentEntity<>(ClassTypeInformation.from(type)), fieldname);
return getPropertyFor(new BasicMongoPersistentEntity<>(TypeInformation.of(type)), fieldname);
}
private static MongoPersistentProperty getPropertyFor(MongoPersistentEntity<?> entity, String fieldname) {

View File

@@ -18,7 +18,7 @@ package org.springframework.data.mongodb.core.mapping;
import java.util.List;
import org.springframework.data.annotation.Id;
import org.springframework.data.annotation.PersistenceConstructor;
import org.springframework.data.annotation.PersistenceCreator;
import org.springframework.data.annotation.Transient;
import org.springframework.data.mongodb.core.index.CompoundIndex;
import org.springframework.data.mongodb.core.index.CompoundIndexes;
@@ -44,7 +44,7 @@ public class Person<T extends Address> {
this.ssn = ssn;
}
@PersistenceConstructor
@PersistenceCreator
public Person(Integer ssn, String firstName, String lastName, Integer age, T address) {
this.ssn = ssn;
this.firstName = firstName;

View File

@@ -16,7 +16,7 @@
package org.springframework.data.mongodb.core.mapping;
import org.springframework.data.annotation.Id;
import org.springframework.data.annotation.PersistenceConstructor;
import org.springframework.data.annotation.PersistenceCreator;
/**
* @author Jon Brisbin <jbrisbin@vmware.com>
@@ -30,7 +30,7 @@ public class PersonCustomIdName extends BasePerson {
this.firstName = firstName;
}
@PersistenceConstructor
@PersistenceCreator
public PersonCustomIdName(Integer ssn, String firstName, String lastName) {
this.ssn = ssn;
this.firstName = firstName;

View File

@@ -28,7 +28,7 @@ import org.bson.types.ObjectId;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.core.Constants;
import org.springframework.data.annotation.PersistenceConstructor;
import org.springframework.data.annotation.PersistenceCreator;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.SimpleMongoClientDatabaseFactory;
import org.springframework.data.mongodb.core.convert.DefaultDbRefResolver;
@@ -454,7 +454,7 @@ public class PerformanceTests {
this(zipCode, city, new HashSet<AddressType>(pickRandomNumerOfItemsFrom(Arrays.asList(AddressType.values()))));
}
@PersistenceConstructor
@PersistenceCreator
public Address(String zipCode, String city, Set<AddressType> types) {
this.zipCode = zipCode;
this.city = city;
@@ -512,7 +512,7 @@ public class PerformanceTests {
this.status = Status.ORDERED;
}
@PersistenceConstructor
@PersistenceCreator
public Order(List<LineItem> lineItems, Date createdAt, Status status) {
this.lineItems = lineItems;
this.createdAt = createdAt;

View File

@@ -32,7 +32,7 @@ import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.core.Constants;
import org.springframework.data.annotation.PersistenceConstructor;
import org.springframework.data.annotation.PersistenceCreator;
import org.springframework.data.mongodb.core.ReactiveMongoOperations;
import org.springframework.data.mongodb.core.ReactiveMongoTemplate;
import org.springframework.data.mongodb.core.SimpleReactiveMongoDatabaseFactory;
@@ -513,7 +513,7 @@ public class ReactivePerformanceTests {
this(zipCode, city, new HashSet<AddressType>(pickRandomNumerOfItemsFrom(Arrays.asList(AddressType.values()))));
}
@PersistenceConstructor
@PersistenceCreator
public Address(String zipCode, String city, Set<AddressType> types) {
this.zipCode = zipCode;
this.city = city;
@@ -571,7 +571,7 @@ public class ReactivePerformanceTests {
this.status = Status.ORDERED;
}
@PersistenceConstructor
@PersistenceCreator
public Order(List<LineItem> lineItems, Date createdAt, Status status) {
this.lineItems = lineItems;
this.createdAt = createdAt;

View File

@@ -22,7 +22,7 @@ import java.util.Objects;
import java.util.Set;
import org.springframework.data.annotation.Id;
import org.springframework.data.annotation.PersistenceConstructor;
import org.springframework.data.annotation.PersistenceCreator;
/**
* @author Christoph Strobl
@@ -37,7 +37,7 @@ final class PersonAggregate {
this(lastname, Collections.singletonList(name));
}
@PersistenceConstructor
@PersistenceCreator
public PersonAggregate(String lastname, Collection<String> names) {
this.lastname = lastname;

View File

@@ -72,7 +72,6 @@ import org.springframework.data.mongodb.test.util.EnableIfMongoServerVersion;
import org.springframework.data.mongodb.test.util.ReactiveMongoClientClosingTestConfiguration;
import org.springframework.data.querydsl.ReactiveQuerydslPredicateExecutor;
import org.springframework.data.repository.Repository;
import org.springframework.data.repository.query.ReactiveQueryMethodEvaluationContextProvider;
import org.springframework.test.context.junit.jupiter.SpringExtension;
/**
@@ -111,7 +110,6 @@ class ReactiveMongoRepositoryTests implements DirtiesStateExtension.StateFunctio
factory.setRepositoryBaseClass(SimpleReactiveMongoRepository.class);
factory.setBeanClassLoader(beanFactory.getClass().getClassLoader());
factory.setBeanFactory(beanFactory);
factory.setEvaluationContextProvider(ReactiveQueryMethodEvaluationContextProvider.DEFAULT);
return factory;
}

View File

@@ -48,7 +48,6 @@ import org.springframework.data.mongodb.repository.support.ReactiveMongoReposito
import org.springframework.data.mongodb.repository.support.SimpleReactiveMongoRepository;
import org.springframework.data.mongodb.test.util.EnableIfReplicaSetAvailable;
import org.springframework.data.repository.query.FluentQuery;
import org.springframework.data.repository.query.ReactiveQueryMethodEvaluationContextProvider;
import org.springframework.lang.Nullable;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit.jupiter.SpringExtension;
@@ -96,7 +95,6 @@ public class SimpleReactiveMongoRepositoryTests implements BeanClassLoaderAware,
factory.setRepositoryBaseClass(SimpleReactiveMongoRepository.class);
factory.setBeanClassLoader(classLoader);
factory.setBeanFactory(beanFactory);
factory.setEvaluationContextProvider(ReactiveQueryMethodEvaluationContextProvider.DEFAULT);
repository = factory.getRepository(ReactivePersonRepository.class);
immutableRepository = factory.getRepository(ReactiveImmutablePersonRepository.class);

View File

@@ -27,7 +27,7 @@ import org.springframework.core.env.Environment;
import org.springframework.core.env.StandardEnvironment;
import org.springframework.core.io.ResourceLoader;
import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
import org.springframework.core.type.StandardAnnotationMetadata;
import org.springframework.core.type.AnnotationMetadata;
import org.springframework.data.mongodb.core.mapping.Document;
import org.springframework.data.mongodb.repository.MongoRepository;
import org.springframework.data.repository.Repository;
@@ -43,13 +43,13 @@ import org.springframework.data.repository.config.RepositoryConfigurationSource;
*/
public class MongoRepositoryConfigurationExtensionUnitTests {
StandardAnnotationMetadata metadata = new StandardAnnotationMetadata(Config.class, true);
AnnotationMetadata metadata = AnnotationMetadata.introspect(Config.class);
ResourceLoader loader = new PathMatchingResourcePatternResolver();
Environment environment = new StandardEnvironment();
BeanDefinitionRegistry registry = new DefaultListableBeanFactory();
RepositoryConfigurationSource configurationSource = new AnnotationRepositoryConfigurationSource(metadata,
EnableMongoRepositories.class, loader, environment, registry);
EnableMongoRepositories.class, loader, environment, registry, null);
@Test // DATAMONGO-1009
public void isStrictMatchIfDomainTypeIsAnnotatedWithDocument() {

View File

@@ -27,7 +27,7 @@ import org.springframework.core.env.Environment;
import org.springframework.core.env.StandardEnvironment;
import org.springframework.core.io.ResourceLoader;
import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
import org.springframework.core.type.StandardAnnotationMetadata;
import org.springframework.core.type.AnnotationMetadata;
import org.springframework.data.mongodb.core.mapping.Document;
import org.springframework.data.mongodb.repository.ReactiveMongoRepository;
import org.springframework.data.repository.config.AnnotationRepositoryConfigurationSource;
@@ -43,13 +43,13 @@ import org.springframework.data.repository.reactive.RxJava3CrudRepository;
*/
public class ReactiveMongoRepositoryConfigurationExtensionUnitTests {
StandardAnnotationMetadata metadata = new StandardAnnotationMetadata(Config.class, true);
AnnotationMetadata metadata = AnnotationMetadata.introspect(Config.class);
ResourceLoader loader = new PathMatchingResourcePatternResolver();
Environment environment = new StandardEnvironment();
BeanDefinitionRegistry registry = new DefaultListableBeanFactory();
RepositoryConfigurationSource configurationSource = new AnnotationRepositoryConfigurationSource(metadata,
EnableReactiveMongoRepositories.class, loader, environment, registry);
EnableReactiveMongoRepositories.class, loader, environment, registry, null);
@Test // DATAMONGO-1444
public void isStrictMatchIfDomainTypeIsAnnotatedWithDocument() {

View File

@@ -56,8 +56,7 @@ import org.springframework.data.projection.SpelAwareProxyProjectionFactory;
import org.springframework.data.repository.Repository;
import org.springframework.data.repository.core.RepositoryMetadata;
import org.springframework.data.repository.core.support.DefaultRepositoryMetadata;
import org.springframework.data.repository.query.QueryMethodEvaluationContextProvider;
import org.springframework.expression.spel.standard.SpelExpressionParser;
import org.springframework.data.repository.query.ValueExpressionDelegate;
import org.springframework.util.ReflectionUtils;
import com.mongodb.client.result.DeleteResult;
@@ -81,15 +80,13 @@ class MongoQueryExecutionUnitTests {
@Mock TerminatingFindNear<Object> terminatingGeoMock;
@Mock DbRefResolver dbRefResolver;
private SpelExpressionParser EXPRESSION_PARSER = new SpelExpressionParser();
private Point POINT = new Point(10, 20);
private Distance DISTANCE = new Distance(2.5, Metrics.KILOMETERS);
private RepositoryMetadata metadata = new DefaultRepositoryMetadata(PersonRepository.class);
private MongoMappingContext context = new MongoMappingContext();
private ProjectionFactory factory = new SpelAwareProxyProjectionFactory();
private Method method = ReflectionUtils.findMethod(PersonRepository.class, "findByLocationNear", Point.class,
Distance.class,
Pageable.class);
Distance.class, Pageable.class);
private MongoQueryMethod queryMethod = new MongoQueryMethod(method, metadata, factory, context);
private MappingMongoConverter converter;
@@ -152,8 +149,8 @@ class MongoQueryExecutionUnitTests {
ConvertingParameterAccessor accessor = new ConvertingParameterAccessor(converter,
new MongoParametersParameterAccessor(queryMethod, new Object[] { POINT, DISTANCE, PageRequest.of(0, 10) }));
PartTreeMongoQuery query = new PartTreeMongoQuery(queryMethod, mongoOperationsMock, EXPRESSION_PARSER,
QueryMethodEvaluationContextProvider.DEFAULT);
PartTreeMongoQuery query = new PartTreeMongoQuery(queryMethod, mongoOperationsMock,
ValueExpressionDelegate.create());
PagingGeoNearExecution execution = new PagingGeoNearExecution(findOperationMock, queryMethod, accessor, query);
execution.execute(new Query());
@@ -173,8 +170,8 @@ class MongoQueryExecutionUnitTests {
ConvertingParameterAccessor accessor = new ConvertingParameterAccessor(converter,
new MongoParametersParameterAccessor(queryMethod, new Object[] { POINT, DISTANCE, PageRequest.of(2, 10) }));
PartTreeMongoQuery query = new PartTreeMongoQuery(queryMethod, mongoOperationsMock, EXPRESSION_PARSER,
QueryMethodEvaluationContextProvider.DEFAULT);
PartTreeMongoQuery query = new PartTreeMongoQuery(queryMethod, mongoOperationsMock,
ValueExpressionDelegate.create());
PagingGeoNearExecution execution = new PagingGeoNearExecution(findOperationMock, queryMethod, accessor, query);
execution.execute(new Query());

View File

@@ -45,8 +45,7 @@ import org.springframework.data.mongodb.repository.Query;
import org.springframework.data.projection.ProjectionFactory;
import org.springframework.data.projection.SpelAwareProxyProjectionFactory;
import org.springframework.data.repository.core.support.DefaultRepositoryMetadata;
import org.springframework.data.repository.query.QueryMethodEvaluationContextProvider;
import org.springframework.expression.spel.standard.SpelExpressionParser;
import org.springframework.data.repository.query.ValueExpressionDelegate;
/**
* Unit tests for {@link PartTreeMongoQuery}.
@@ -206,8 +205,7 @@ class PartTreeMongoQueryUnitTests {
MongoQueryMethod queryMethod = new MongoQueryMethod(method, new DefaultRepositoryMetadata(Repo.class), factory,
mappingContext);
return new PartTreeMongoQuery(queryMethod, mongoOperationsMock, new SpelExpressionParser(),
QueryMethodEvaluationContextProvider.DEFAULT);
return new PartTreeMongoQuery(queryMethod, mongoOperationsMock, ValueExpressionDelegate.create());
} catch (Exception e) {
throw new IllegalArgumentException(e.getMessage(), e);
}

View File

@@ -46,7 +46,7 @@ import org.springframework.data.mongodb.core.query.Query;
import org.springframework.data.mongodb.repository.Person;
import org.springframework.data.mongodb.repository.query.ReactiveMongoQueryExecution.DeleteExecution;
import org.springframework.data.mongodb.repository.query.ReactiveMongoQueryExecution.GeoNearExecution;
import org.springframework.data.util.ClassTypeInformation;
import org.springframework.data.util.TypeInformation;
import org.springframework.util.ClassUtils;
import com.mongodb.client.result.DeleteResult;
@@ -74,7 +74,7 @@ public class ReactiveMongoQueryExecutionUnitTests {
.thenReturn(Range.from(Bound.inclusive(new Distance(10))).to(Bound.inclusive(new Distance(15))));
when(parameterAccessor.getPageable()).thenReturn(PageRequest.of(1, 10));
new GeoNearExecution(operations, parameterAccessor, ClassTypeInformation.fromReturnTypeOf(geoNear)).execute(query,
new GeoNearExecution(operations, parameterAccessor, TypeInformation.fromReturnTypeOf(geoNear)).execute(query,
Person.class, "person");
ArgumentCaptor<NearQuery> queryArgumentCaptor = ArgumentCaptor.forClass(NearQuery.class);
@@ -96,7 +96,7 @@ public class ReactiveMongoQueryExecutionUnitTests {
when(parameterAccessor.getGeoNearLocation()).thenReturn(new Point(1, 2));
when(parameterAccessor.getDistanceRange()).thenReturn(Range.unbounded());
new GeoNearExecution(operations, parameterAccessor, ClassTypeInformation.fromReturnTypeOf(geoNear)).execute(query,
new GeoNearExecution(operations, parameterAccessor, TypeInformation.fromReturnTypeOf(geoNear)).execute(query,
Person.class, "person");
ArgumentCaptor<NearQuery> queryArgumentCaptor = ArgumentCaptor.forClass(NearQuery.class);

View File

@@ -34,6 +34,7 @@ import org.mockito.ArgumentCaptor;
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;
import org.reactivestreams.Publisher;
import org.springframework.data.domain.Sort;
import org.springframework.data.domain.Sort.Direction;
import org.springframework.data.mongodb.core.ReactiveMongoOperations;
@@ -54,9 +55,8 @@ import org.springframework.data.mongodb.repository.Person;
import org.springframework.data.projection.ProjectionFactory;
import org.springframework.data.projection.SpelAwareProxyProjectionFactory;
import org.springframework.data.repository.core.support.DefaultRepositoryMetadata;
import org.springframework.data.repository.query.ReactiveQueryMethodEvaluationContextProvider;
import org.springframework.data.repository.query.ValueExpressionDelegate;
import org.springframework.data.repository.reactive.ReactiveCrudRepository;
import org.springframework.expression.spel.standard.SpelExpressionParser;
import org.springframework.lang.Nullable;
import org.springframework.util.ClassUtils;
@@ -71,8 +71,6 @@ import com.mongodb.ReadPreference;
@ExtendWith(MockitoExtension.class)
public class ReactiveStringBasedAggregationUnitTests {
SpelExpressionParser PARSER = new SpelExpressionParser();
@Mock ReactiveMongoOperations operations;
@Mock DbRefResolver dbRefResolver;
MongoConverter converter;
@@ -226,8 +224,7 @@ public class ReactiveStringBasedAggregationUnitTests {
ProjectionFactory factory = new SpelAwareProxyProjectionFactory();
ReactiveMongoQueryMethod queryMethod = new ReactiveMongoQueryMethod(method,
new DefaultRepositoryMetadata(SampleRepository.class), factory, converter.getMappingContext());
return new ReactiveStringBasedAggregation(queryMethod, operations, PARSER,
ReactiveQueryMethodEvaluationContextProvider.DEFAULT);
return new ReactiveStringBasedAggregation(queryMethod, operations, ValueExpressionDelegate.create());
}
private List<Document> pipelineOf(AggregationInvocation invocation) {
@@ -250,19 +247,18 @@ public class ReactiveStringBasedAggregationUnitTests {
@Nullable
private Object hintOf(AggregationInvocation invocation) {
return invocation.aggregation.getOptions() != null ? invocation.aggregation.getOptions().getHintObject().orElse(null)
return invocation.aggregation.getOptions() != null
? invocation.aggregation.getOptions().getHintObject().orElse(null)
: null;
}
private Boolean skipResultsOf(AggregationInvocation invocation) {
return invocation.aggregation.getOptions() != null ? invocation.aggregation.getOptions().isSkipResults()
: false;
return invocation.aggregation.getOptions() != null ? invocation.aggregation.getOptions().isSkipResults() : false;
}
@Nullable
private ReadPreference readPreferenceOf(AggregationInvocation invocation) {
return invocation.aggregation.getOptions() != null ? invocation.aggregation.getOptions().getReadPreference()
: null;
return invocation.aggregation.getOptions() != null ? invocation.aggregation.getOptions().getReadPreference() : null;
}
private Class<?> targetTypeOf(AggregationInvocation invocation) {
@@ -284,7 +280,7 @@ public class ReactiveStringBasedAggregationUnitTests {
@Aggregation(GROUP_BY_LASTNAME_STRING_WITH_SPEL_PARAMETER_PLACEHOLDER)
Mono<PersonAggregate> spelParameterReplacementAggregation(String arg0);
@Aggregation(pipeline = {RAW_GROUP_BY_LASTNAME_STRING, GROUP_BY_LASTNAME_STRING_WITH_SPEL_PARAMETER_PLACEHOLDER})
@Aggregation(pipeline = { RAW_GROUP_BY_LASTNAME_STRING, GROUP_BY_LASTNAME_STRING_WITH_SPEL_PARAMETER_PLACEHOLDER })
Mono<PersonAggregate> multiOperationPipeline(String arg0);
@Aggregation(pipeline = RAW_GROUP_BY_LASTNAME_STRING, collation = "de_AT")

View File

@@ -56,8 +56,6 @@ import org.springframework.data.projection.SpelAwareProxyProjectionFactory;
import org.springframework.data.repository.Repository;
import org.springframework.data.repository.core.support.DefaultRepositoryMetadata;
import org.springframework.data.repository.query.QueryMethodValueEvaluationContextAccessor;
import org.springframework.data.repository.query.ReactiveExtensionAwareQueryMethodEvaluationContextProvider;
import org.springframework.data.repository.query.ReactiveQueryMethodEvaluationContextProvider;
import org.springframework.data.repository.query.ValueExpressionDelegate;
import org.springframework.data.spel.spi.EvaluationContextExtension;
import org.springframework.data.spel.spi.ReactiveEvaluationContextExtension;
@@ -248,8 +246,8 @@ public class ReactiveStringBasedMongoQueryUnitTests {
ReactiveStringBasedMongoQuery mongoQuery = createQueryForMethod("findByLastnameAsBinary", byte[].class);
org.springframework.data.mongodb.core.query.Query query = mongoQuery.createQuery(accesor).block();
org.springframework.data.mongodb.core.query.Query reference = new BasicQuery(
"{'lastname' : { '$binary' : '" + Base64.getEncoder().encodeToString(binaryData) + "', '$type' : '" + 0 + "'}}");
org.springframework.data.mongodb.core.query.Query reference = new BasicQuery("{'lastname' : { '$binary' : '"
+ Base64.getEncoder().encodeToString(binaryData) + "', '$type' : '" + 0 + "'}}");
assertThat(query.getQueryObject().toJson()).isEqualTo(reference.getQueryObject().toJson());
}
@@ -266,16 +264,14 @@ public class ReactiveStringBasedMongoQueryUnitTests {
assertThat(query.getQueryObject().toJson()).isEqualTo(reference.getQueryObject().toJson());
}
private ReactiveStringBasedMongoQuery createQueryForMethod(
String name, Class<?>... parameters)
throws Exception {
private ReactiveStringBasedMongoQuery createQueryForMethod(String name, Class<?>... parameters) throws Exception {
Method method = SampleRepository.class.getMethod(name, parameters);
ProjectionFactory factory = new SpelAwareProxyProjectionFactory();
ReactiveMongoQueryMethod queryMethod = new ReactiveMongoQueryMethod(method,
new DefaultRepositoryMetadata(SampleRepository.class), factory, converter.getMappingContext());
QueryMethodValueEvaluationContextAccessor accessor = new QueryMethodValueEvaluationContextAccessor(
environment, Collections.singletonList(ReactiveSpelExtension.INSTANCE));
QueryMethodValueEvaluationContextAccessor accessor = new QueryMethodValueEvaluationContextAccessor(environment,
Collections.singletonList(ReactiveSpelExtension.INSTANCE));
return new ReactiveStringBasedMongoQuery(queryMethod, operations, new ValueExpressionDelegate(accessor, PARSER));
}

View File

@@ -35,6 +35,7 @@ import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;
import org.mockito.junit.jupiter.MockitoSettings;
import org.mockito.quality.Strictness;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
@@ -62,8 +63,7 @@ import org.springframework.data.projection.ProjectionFactory;
import org.springframework.data.projection.SpelAwareProxyProjectionFactory;
import org.springframework.data.repository.Repository;
import org.springframework.data.repository.core.support.DefaultRepositoryMetadata;
import org.springframework.data.repository.query.QueryMethodEvaluationContextProvider;
import org.springframework.expression.spel.standard.SpelExpressionParser;
import org.springframework.data.repository.query.ValueExpressionDelegate;
import org.springframework.lang.Nullable;
import org.springframework.util.ClassUtils;
@@ -81,8 +81,6 @@ import com.mongodb.ReadPreference;
@MockitoSettings(strictness = Strictness.LENIENT)
public class StringBasedAggregationUnitTests {
private SpelExpressionParser PARSER = new SpelExpressionParser();
@Mock MongoOperations operations;
@Mock DbRefResolver dbRefResolver;
@Mock AggregationResults aggregationResults;
@@ -254,8 +252,7 @@ public class StringBasedAggregationUnitTests {
factory, converter.getMappingContext());
assertThatExceptionOfType(InvalidMongoDbApiUsageException.class) //
.isThrownBy(() -> new StringBasedAggregation(queryMethod, operations, PARSER,
QueryMethodEvaluationContextProvider.DEFAULT)) //
.isThrownBy(() -> new StringBasedAggregation(queryMethod, operations, ValueExpressionDelegate.create())) //
.withMessageContaining("pageIsUnsupported") //
.withMessageContaining("Page");
}
@@ -311,7 +308,7 @@ public class StringBasedAggregationUnitTests {
ProjectionFactory factory = new SpelAwareProxyProjectionFactory();
MongoQueryMethod queryMethod = new MongoQueryMethod(method, new DefaultRepositoryMetadata(SampleRepository.class),
factory, converter.getMappingContext());
return new StringBasedAggregation(queryMethod, operations, PARSER, QueryMethodEvaluationContextProvider.DEFAULT);
return new StringBasedAggregation(queryMethod, operations, ValueExpressionDelegate.create());
}
private List<Document> pipelineOf(AggregationInvocation invocation) {
@@ -334,19 +331,18 @@ public class StringBasedAggregationUnitTests {
@Nullable
private Object hintOf(AggregationInvocation invocation) {
return invocation.aggregation.getOptions() != null ? invocation.aggregation.getOptions().getHintObject().orElse(null)
return invocation.aggregation.getOptions() != null
? invocation.aggregation.getOptions().getHintObject().orElse(null)
: null;
}
private Boolean skipResultsOf(AggregationInvocation invocation) {
return invocation.aggregation.getOptions() != null ? invocation.aggregation.getOptions().isSkipResults()
: false;
return invocation.aggregation.getOptions() != null ? invocation.aggregation.getOptions().isSkipResults() : false;
}
@Nullable
private ReadPreference readPreferenceOf(AggregationInvocation invocation) {
return invocation.aggregation.getOptions() != null ? invocation.aggregation.getOptions().getReadPreference()
: null;
return invocation.aggregation.getOptions() != null ? invocation.aggregation.getOptions().getReadPreference() : null;
}
private Class<?> targetTypeOf(AggregationInvocation invocation) {

View File

@@ -465,7 +465,7 @@ This can be a single value (the _id_ by default), or a `Document` provided via a
* `@Transient`: By default, all fields are mapped to the document.
This annotation excludes the field where it is applied from being stored in the database.
Transient properties cannot be used within a persistence constructor as the converter cannot materialize a value for the constructor argument.
* `@PersistenceConstructor`: Marks a given constructor - even a package protected one - to use when instantiating the object from the database.
* `@PersistenceCreator`: Marks a given constructor or a `static` factory method - even a package protected one - to use when instantiating the object from the database.
Constructor arguments are mapped by name to the key values in the retrieved Document.
* `@Value`: This annotation is part of the Spring Framework . Within the mapping framework it can be applied to constructor arguments.
This lets you use a Spring Expression Language statement to transform a key's value retrieved in the database before it is used to construct a domain object.
@@ -513,7 +513,7 @@ public class Person<T extends Address> {
this.ssn = ssn;
}
@PersistenceConstructor
@PersistenceCreator
public Person(Integer ssn, String firstName, String lastName, Integer age, T address) {
this.ssn = ssn;
this.firstName = firstName;
@@ -673,7 +673,7 @@ Increased levels of nesting increase the complexity of the aggregation expressio
[[mapping-custom-object-construction]]
=== Customized Object Construction
The mapping subsystem allows the customization of the object construction by annotating a constructor with the `@PersistenceConstructor` annotation.
The mapping subsystem allows the customization of the object construction by annotating a constructor with the `@PersistenceCreator` annotation.
The values to be used for the constructor parameters are resolved in the following way:
* If a parameter is annotated with the `@Value` annotation, the given expression is evaluated and the result is used as the parameter value.
@@ -706,7 +706,7 @@ OrderItem item = converter.read(OrderItem.class, input);
NOTE: The SpEL expression in the `@Value` annotation of the `quantity` parameter falls back to the value `0` if the given property path cannot be resolved.
Additional examples for using the `@PersistenceConstructor` annotation can be found in the https://github.com/spring-projects/spring-data-mongodb/blob/master/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/convert/MappingMongoConverterUnitTests.java[MappingMongoConverterUnitTests] test suite.
Additional examples for using the `@PersistenceCreator` annotation can be found in the https://github.com/spring-projects/spring-data-mongodb/blob/master/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/convert/MappingMongoConverterUnitTests.java[MappingMongoConverterUnitTests] test suite.
[[mapping-usage-events]]
=== Mapping Framework Events

View File

@@ -342,7 +342,7 @@ public class Venue {
private String name;
private double[] location;
@PersistenceConstructor
@PersistenceCreator
Venue(String name, double[] location) {
super();
this.name = name;