Skip to content

Commit e92b6b0

Browse files
mp911deschauder
authored andcommitted
Adopt to deprecation removals in Commons.
Closes #2007
1 parent d96427a commit e92b6b0

34 files changed

+252
-306
lines changed

src/main/java/org/springframework/data/couchbase/core/convert/MappingCouchbaseConverter.java

+45-22
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,7 @@
1616

1717
package org.springframework.data.couchbase.core.convert;
1818

19-
import static org.springframework.data.couchbase.core.mapping.id.GenerationStrategy.UNIQUE;
20-
import static org.springframework.data.couchbase.core.mapping.id.GenerationStrategy.USE_ATTRIBUTES;
19+
import static org.springframework.data.couchbase.core.mapping.id.GenerationStrategy.*;
2120

2221
import java.beans.Transient;
2322
import java.lang.reflect.InaccessibleObjectException;
@@ -34,10 +33,14 @@
3433
import org.springframework.beans.factory.BeanClassLoaderAware;
3534
import org.springframework.context.ApplicationContext;
3635
import org.springframework.context.ApplicationContextAware;
36+
import org.springframework.context.EnvironmentAware;
3737
import org.springframework.core.CollectionFactory;
3838
import org.springframework.core.convert.ConversionService;
3939
import org.springframework.core.convert.TypeDescriptor;
4040
import org.springframework.core.convert.support.DefaultConversionService;
41+
import org.springframework.core.env.Environment;
42+
import org.springframework.core.env.EnvironmentCapable;
43+
import org.springframework.core.env.StandardEnvironment;
4144
import org.springframework.data.convert.CustomConversions;
4245
import org.springframework.data.convert.PropertyValueConverter;
4346
import org.springframework.data.couchbase.core.mapping.CouchbaseDocument;
@@ -62,16 +65,17 @@
6265
import org.springframework.data.mapping.PropertyHandler;
6366
import org.springframework.data.mapping.callback.EntityCallbacks;
6467
import org.springframework.data.mapping.context.MappingContext;
68+
import org.springframework.data.mapping.model.CachingValueExpressionEvaluatorFactory;
6569
import org.springframework.data.mapping.model.ConvertingPropertyAccessor;
66-
import org.springframework.data.mapping.model.DefaultSpELExpressionEvaluator;
6770
import org.springframework.data.mapping.model.EntityInstantiator;
6871
import org.springframework.data.mapping.model.ParameterValueProvider;
6972
import org.springframework.data.mapping.model.PersistentEntityParameterValueProvider;
7073
import org.springframework.data.mapping.model.PropertyValueProvider;
7174
import org.springframework.data.mapping.model.SpELContext;
72-
import org.springframework.data.mapping.model.SpELExpressionEvaluator;
73-
import org.springframework.data.mapping.model.SpELExpressionParameterValueProvider;
75+
import org.springframework.data.mapping.model.ValueExpressionEvaluator;
76+
import org.springframework.data.mapping.model.ValueExpressionParameterValueProvider;
7477
import org.springframework.data.util.TypeInformation;
78+
import org.springframework.expression.spel.standard.SpelExpressionParser;
7579
import org.springframework.lang.Nullable;
7680
import org.springframework.util.Assert;
7781
import org.springframework.util.CollectionUtils;
@@ -92,7 +96,7 @@
9296
* @author Remi Bleuse
9397
* @author Vipul Gupta
9498
*/
95-
public class MappingCouchbaseConverter extends AbstractCouchbaseConverter implements ApplicationContextAware {
99+
public class MappingCouchbaseConverter extends AbstractCouchbaseConverter implements ApplicationContextAware, EnvironmentCapable, EnvironmentAware {
96100

97101
/**
98102
* The default "type key", the name of the field that will hold type information.
@@ -113,6 +117,10 @@ public class MappingCouchbaseConverter extends AbstractCouchbaseConverter implem
113117
* Spring Expression Language context.
114118
*/
115119
private final SpELContext spELContext;
120+
121+
private final SpelExpressionParser expressionParser = new SpelExpressionParser();
122+
123+
private final CachingValueExpressionEvaluatorFactory expressionEvaluatorFactory;
116124
/**
117125
* The overall application context.
118126
*/
@@ -127,6 +135,8 @@ public class MappingCouchbaseConverter extends AbstractCouchbaseConverter implem
127135
*/
128136
private @Nullable EntityCallbacks entityCallbacks;
129137

138+
private @Nullable Environment environment;
139+
130140
public MappingCouchbaseConverter() {
131141
this(new CouchbaseMappingContext(), null);
132142
}
@@ -173,6 +183,9 @@ public MappingCouchbaseConverter(
173183
((CouchbaseMappingContext) mappingContext).setSimpleTypeHolder(customConversions.getSimpleTypeHolder());
174184
typeMapper = new DefaultCouchbaseTypeMapper(typeKey != null ? typeKey : TYPEKEY_DEFAULT);
175185
spELContext = new SpELContext(CouchbaseDocumentPropertyAccessor.INSTANCE);
186+
187+
expressionEvaluatorFactory = new CachingValueExpressionEvaluatorFactory(
188+
expressionParser, this, o -> spELContext.getEvaluationContext(o));
176189
}
177190

178191
/**
@@ -200,6 +213,21 @@ private static boolean isSubtype(final Class<?> left, final Class<?> right) {
200213
return left.isAssignableFrom(right) && !left.equals(right);
201214
}
202215

216+
@Override
217+
public void setEnvironment(Environment environment) {
218+
this.environment = environment;
219+
}
220+
221+
@Override
222+
public Environment getEnvironment() {
223+
224+
if (this.environment == null) {
225+
this.environment = new StandardEnvironment();
226+
}
227+
228+
return environment;
229+
}
230+
203231
@Override
204232
public MappingContext<? extends CouchbasePersistentEntity<?>, CouchbasePersistentProperty> getMappingContext() {
205233
return mappingContext;
@@ -273,7 +301,8 @@ protected <R> R read(final TypeInformation<R> type, final CouchbaseDocument sour
273301
* @return the converted entity.
274302
*/
275303
protected <R> R read(final CouchbasePersistentEntity<R> entity, final CouchbaseDocument source, final Object parent) {
276-
final DefaultSpELExpressionEvaluator evaluator = new DefaultSpELExpressionEvaluator(source, spELContext);
304+
305+
ValueExpressionEvaluator evaluator = expressionEvaluatorFactory.create(source);
277306
ParameterValueProvider<CouchbasePersistentProperty> provider = getParameterProvider(entity, source, evaluator,
278307
parent);
279308
EntityInstantiator instantiator = instantiators.getInstantiatorFor(entity);
@@ -284,7 +313,7 @@ protected <R> R read(final CouchbasePersistentEntity<R> entity, final CouchbaseD
284313
entity.doWithProperties(new PropertyHandler<>() {
285314
@Override
286315
public void doWithPersistentProperty(final CouchbasePersistentProperty prop) {
287-
if (!doesPropertyExistInSource(prop) || entity.isConstructorArgument(prop) || isIdConstructionProperty(prop)
316+
if (!doesPropertyExistInSource(prop) || entity.isCreatorArgument(prop) || isIdConstructionProperty(prop)
288317
|| prop.isAnnotationPresent(N1qlJoin.class)) {
289318
return;
290319
}
@@ -330,7 +359,7 @@ private boolean isIdConstructionProperty(final CouchbasePersistentProperty prope
330359
*/
331360
protected Object getValueInternal(final CouchbasePersistentProperty property, final CouchbaseDocument source,
332361
final Object parent, PersistentEntity entity) {
333-
return new CouchbasePropertyValueProvider(source, spELContext, parent, entity).getPropertyValue(property);
362+
return new CouchbasePropertyValueProvider(source, expressionEvaluatorFactory.create(source), parent, entity).getPropertyValue(property);
334363
}
335364

336365
/**
@@ -344,7 +373,7 @@ protected Object getValueInternal(final CouchbasePersistentProperty property, fi
344373
*/
345374
private ParameterValueProvider<CouchbasePersistentProperty> getParameterProvider(
346375
final CouchbasePersistentEntity<?> entity, final CouchbaseDocument source,
347-
final DefaultSpELExpressionEvaluator evaluator, final Object parent) {
376+
final ValueExpressionEvaluator evaluator, final Object parent) {
348377
CouchbasePropertyValueProvider provider = new CouchbasePropertyValueProvider(source, evaluator, parent, entity);
349378
PersistentEntityParameterValueProvider<CouchbasePersistentProperty> parameterProvider = new PersistentEntityParameterValueProvider<>(
350379
entity, provider, parent);
@@ -1070,7 +1099,7 @@ private class CouchbasePropertyValueProvider implements PropertyValueProvider<Co
10701099
/**
10711100
* The expression evaluator.
10721101
*/
1073-
private final SpELExpressionEvaluator evaluator;
1102+
private final ValueExpressionEvaluator evaluator;
10741103

10751104
/**
10761105
* The optional parent object.
@@ -1082,15 +1111,10 @@ private class CouchbasePropertyValueProvider implements PropertyValueProvider<Co
10821111
*/
10831112
private final PersistentEntity entity;
10841113

1085-
public CouchbasePropertyValueProvider(final CouchbaseDocument source, final SpELContext factory,
1086-
final Object parent, final PersistentEntity entity) {
1087-
this(source, new DefaultSpELExpressionEvaluator(source, factory), parent, entity);
1088-
}
1089-
10901114
public CouchbasePropertyValueProvider(final CouchbaseDocument source,
1091-
final DefaultSpELExpressionEvaluator evaluator, final Object parent, final PersistentEntity entity) {
1115+
final ValueExpressionEvaluator evaluator, final Object parent, final PersistentEntity entity) {
10921116
Assert.notNull(source, "CouchbaseDocument must not be null!");
1093-
Assert.notNull(evaluator, "DefaultSpELExpressionEvaluator must not be null!");
1117+
Assert.notNull(evaluator, "ValueExpressionEvaluator must not be null!");
10941118

10951119
this.source = source;
10961120
this.evaluator = evaluator;
@@ -1148,20 +1172,19 @@ String maybeMangle(PersistentProperty<?> property) {
11481172
* A expression parameter value provider.
11491173
*/
11501174
private class ConverterAwareSpELExpressionParameterValueProvider
1151-
extends SpELExpressionParameterValueProvider<CouchbasePersistentProperty> {
1175+
extends ValueExpressionParameterValueProvider<CouchbasePersistentProperty> {
11521176

11531177
private final Object parent;
11541178

1155-
public ConverterAwareSpELExpressionParameterValueProvider(final SpELExpressionEvaluator evaluator,
1179+
public ConverterAwareSpELExpressionParameterValueProvider(final ValueExpressionEvaluator evaluator,
11561180
final ConversionService conversionService, final ParameterValueProvider<CouchbasePersistentProperty> delegate,
11571181
final Object parent) {
11581182
super(evaluator, conversionService, delegate);
11591183
this.parent = parent;
11601184
}
11611185

11621186
@Override
1163-
protected <T> T potentiallyConvertSpelValue(final Object object,
1164-
final Parameter<T, CouchbasePersistentProperty> parameter) {
1187+
protected <T> T potentiallyConvertExpressionValue(Object object, Parameter<T, CouchbasePersistentProperty> parameter) {
11651188
return readValue(object, parameter.getType(), parent);
11661189
}
11671190
}

src/main/java/org/springframework/data/couchbase/core/query/StringQuery.java

+11-17
Original file line numberDiff line numberDiff line change
@@ -25,47 +25,43 @@
2525
import org.springframework.data.couchbase.repository.support.MappingCouchbaseEntityInformation;
2626
import org.springframework.data.mapping.Alias;
2727
import org.springframework.data.repository.query.ParameterAccessor;
28-
import org.springframework.data.repository.query.QueryMethodEvaluationContextProvider;
28+
import org.springframework.data.repository.query.ValueExpressionDelegate;
2929
import org.springframework.data.util.TypeInformation;
30-
import org.springframework.expression.spel.standard.SpelExpressionParser;
3130

3231
import com.couchbase.client.java.json.JsonArray;
3332
import com.couchbase.client.java.json.JsonObject;
3433
import com.couchbase.client.java.json.JsonValue;
3534

3635
/**
3736
* Query created from the string in @Query annotation in the repository interface.
38-
*
37+
*
3938
* <pre>
4039
* &#64;Query("#{#n1ql.selectEntity} where #{#n1ql.filter} and firstname = $1 and lastname = $2")
4140
* List&lt;User&gt; getByFirstnameAndLastname(String firstname, String lastname);
4241
* </pre>
43-
*
42+
*
4443
* It must include the SELECT ... FROM ... preferably via the #n1ql expression, in addition to any predicates required,
4544
* including the n1ql.filter (for _class = className)
46-
*
45+
*
4746
* @author Michael Reiche
4847
*/
4948
public class StringQuery extends Query {
5049

5150
private final CouchbaseQueryMethod queryMethod;
5251
private final String inlineN1qlQuery;
53-
private final QueryMethodEvaluationContextProvider evaluationContextProvider;
52+
private final ValueExpressionDelegate valueExpressionDelegate;
5453
private final ParameterAccessor parameterAccessor;
55-
private final SpelExpressionParser spelExpressionParser;
5654

5755
public StringQuery(CouchbaseQueryMethod queryMethod, String n1qlString,
58-
QueryMethodEvaluationContextProvider queryMethodEvaluationContextProvider, ParameterAccessor parameterAccessor,
59-
SpelExpressionParser spelExpressionParser) {
56+
ValueExpressionDelegate valueExpressionDelegate, ParameterAccessor parameterAccessor) {
6057
this.queryMethod = queryMethod;
6158
this.inlineN1qlQuery = n1qlString;
62-
this.evaluationContextProvider = queryMethodEvaluationContextProvider;
59+
this.valueExpressionDelegate = valueExpressionDelegate;
6360
this.parameterAccessor = parameterAccessor;
64-
this.spelExpressionParser = spelExpressionParser;
6561
}
6662

6763
public StringQuery(String n1qlString) {
68-
this(null,n1qlString, null, null, null);
64+
this(null,n1qlString, null, null);
6965
}
7066

7167
@Override
@@ -75,8 +71,7 @@ public String toN1qlSelectString(CouchbaseConverter converter, String bucketName
7571
StringBasedN1qlQueryParser parser = getStringN1qlQueryParser(converter, bucketName, scope, collection, domainClass,
7672
distinctFields, fields);
7773

78-
N1QLExpression parsedExpression = parser.getExpression(inlineN1qlQuery, queryMethod, parameterAccessor,
79-
spelExpressionParser, evaluationContextProvider);
74+
N1QLExpression parsedExpression = parser.getExpression(inlineN1qlQuery, queryMethod, parameterAccessor, valueExpressionDelegate);
8075

8176
String queryString = parsedExpression.toString();
8277

@@ -128,8 +123,7 @@ private StringBasedN1qlQueryParser getStringN1qlQueryParser(CouchbaseConverter c
128123
}
129124
// there are no options for distinct and fields for @Query
130125
StringBasedN1qlQueryParser sbnqp = new StringBasedN1qlQueryParser(inlineN1qlQuery, queryMethod, bucketName,
131-
scopeName, collectionName, converter, typeKey, typeValue, parameterAccessor, new SpelExpressionParser(),
132-
evaluationContextProvider);
126+
scopeName, collectionName, converter, typeKey, typeValue, parameterAccessor, valueExpressionDelegate);
133127

134128
return sbnqp;
135129
}
@@ -144,7 +138,7 @@ public boolean isReadonly() {
144138

145139
/**
146140
* toN1qlRemoveString - use toN1qlSelectString
147-
*
141+
*
148142
* @param converter
149143
* @param bucketName
150144
* @param scopeName

src/main/java/org/springframework/data/couchbase/repository/query/AbstractCouchbaseQuery.java

+5-8
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,9 @@
2727
import org.springframework.data.repository.core.EntityMetadata;
2828
import org.springframework.data.repository.query.ParameterAccessor;
2929
import org.springframework.data.repository.query.ParametersParameterAccessor;
30-
import org.springframework.data.repository.query.QueryMethodEvaluationContextProvider;
3130
import org.springframework.data.repository.query.RepositoryQuery;
3231
import org.springframework.data.repository.query.ResultProcessor;
33-
import org.springframework.expression.spel.standard.SpelExpressionParser;
32+
import org.springframework.data.repository.query.ValueExpressionDelegate;
3433
import org.springframework.lang.Nullable;
3534
import org.springframework.util.Assert;
3635

@@ -52,16 +51,14 @@ public abstract class AbstractCouchbaseQuery extends AbstractCouchbaseQueryBase<
5251
*
5352
* @param method must not be {@literal null}.
5453
* @param operations must not be {@literal null}.
55-
* @param expressionParser must not be {@literal null}.
56-
* @param evaluationContextProvider must not be {@literal null}.
54+
* @param valueExpressionDelegate must not be {@literal null}.
5755
*/
5856
public AbstractCouchbaseQuery(CouchbaseQueryMethod method, CouchbaseOperations operations,
59-
SpelExpressionParser expressionParser, QueryMethodEvaluationContextProvider evaluationContextProvider) {
60-
super(method, operations, expressionParser, evaluationContextProvider);
57+
ValueExpressionDelegate valueExpressionDelegate) {
58+
super(method, operations, valueExpressionDelegate);
6159
Assert.notNull(method, "CouchbaseQueryMethod must not be null!");
6260
Assert.notNull(operations, "ReactiveCouchbaseOperations must not be null!");
63-
Assert.notNull(expressionParser, "SpelExpressionParser must not be null!");
64-
Assert.notNull(evaluationContextProvider, "QueryMethodEvaluationContextProvider must not be null!");
61+
Assert.notNull(valueExpressionDelegate, "QueryMethodEvaluationContextProvider must not be null!");
6562
EntityMetadata<?> metadata = method.getEntityInformation();
6663
Class<?> type = metadata.getJavaType();
6764
this.findOp = (ExecutableFindByQuery<?>) (operations.findByQuery(type).inScope(method.getScope())

src/main/java/org/springframework/data/couchbase/repository/query/AbstractCouchbaseQueryBase.java

+6-11
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,10 @@
2626
import org.springframework.data.repository.core.EntityMetadata;
2727
import org.springframework.data.repository.query.ParameterAccessor;
2828
import org.springframework.data.repository.query.ParametersParameterAccessor;
29-
import org.springframework.data.repository.query.QueryMethodEvaluationContextProvider;
3029
import org.springframework.data.repository.query.RepositoryQuery;
3130
import org.springframework.data.repository.query.ResultProcessor;
31+
import org.springframework.data.repository.query.ValueExpressionDelegate;
3232
import org.springframework.data.util.TypeInformation;
33-
import org.springframework.expression.spel.standard.SpelExpressionParser;
3433
import org.springframework.lang.Nullable;
3534
import org.springframework.util.Assert;
3635

@@ -47,31 +46,27 @@ public abstract class AbstractCouchbaseQueryBase<CouchbaseOperationsType> implem
4746
private final CouchbaseOperationsType operations;
4847
private final EntityInstantiators instantiators;
4948
private final ExecutableFindByQuery<?> findOperationWithProjection;
50-
private final SpelExpressionParser expressionParser;
51-
private final QueryMethodEvaluationContextProvider evaluationContextProvider;
49+
private final ValueExpressionDelegate valueExpressionDelegate;
5250

5351
/**
5452
* Creates a new {@link AbstractCouchbaseQuery} from the given {@link ReactiveCouchbaseQueryMethod} and
5553
* {@link org.springframework.data.couchbase.core.CouchbaseOperations}.
5654
*
5755
* @param method must not be {@literal null}.
5856
* @param operations must not be {@literal null}.
59-
* @param expressionParser must not be {@literal null}.
60-
* @param evaluationContextProvider must not be {@literal null}.
57+
* @param valueExpressionDelegate must not be {@literal null}.
6158
*/
6259
public AbstractCouchbaseQueryBase(CouchbaseQueryMethod method, CouchbaseOperationsType operations,
63-
SpelExpressionParser expressionParser, QueryMethodEvaluationContextProvider evaluationContextProvider) {
60+
ValueExpressionDelegate valueExpressionDelegate) {
6461

6562
Assert.notNull(method, "CouchbaseQueryMethod must not be null!");
6663
Assert.notNull(operations, "ReactiveCouchbaseOperations must not be null!");
67-
Assert.notNull(expressionParser, "SpelExpressionParser must not be null!");
68-
Assert.notNull(evaluationContextProvider, "QueryMethodEvaluationContextProvider must not be null!");
64+
Assert.notNull(valueExpressionDelegate, "ValueExpressionDelegate must not be null!");
6965

7066
this.method = method;
7167
this.operations = operations;
7268
this.instantiators = new EntityInstantiators();
73-
this.expressionParser = expressionParser;
74-
this.evaluationContextProvider = evaluationContextProvider;
69+
this.valueExpressionDelegate = valueExpressionDelegate;
7570

7671
EntityMetadata<?> metadata = method.getEntityInformation();
7772
Class<?> type = metadata.getJavaType();

src/main/java/org/springframework/data/couchbase/repository/query/AbstractReactiveCouchbaseQuery.java

+4-8
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,9 @@
2626
import org.springframework.data.repository.core.EntityMetadata;
2727
import org.springframework.data.repository.query.ParameterAccessor;
2828
import org.springframework.data.repository.query.ParametersParameterAccessor;
29-
import org.springframework.data.repository.query.QueryMethodEvaluationContextProvider;
3029
import org.springframework.data.repository.query.RepositoryQuery;
3130
import org.springframework.data.repository.query.ResultProcessor;
32-
import org.springframework.expression.spel.standard.SpelExpressionParser;
31+
import org.springframework.data.repository.query.ValueExpressionDelegate;
3332
import org.springframework.lang.Nullable;
3433
import org.springframework.util.Assert;
3534

@@ -51,16 +50,13 @@ public abstract class AbstractReactiveCouchbaseQuery extends AbstractCouchbaseQu
5150
*
5251
* @param method must not be {@literal null}.
5352
* @param operations must not be {@literal null}.
54-
* @param expressionParser must not be {@literal null}.
55-
* @param evaluationContextProvider must not be {@literal null}.
53+
* @param valueExpressionDelegate must not be {@literal null}.
5654
*/
5755
public AbstractReactiveCouchbaseQuery(ReactiveCouchbaseQueryMethod method, ReactiveCouchbaseOperations operations,
58-
SpelExpressionParser expressionParser, QueryMethodEvaluationContextProvider evaluationContextProvider) {
59-
super(method, operations, expressionParser, evaluationContextProvider);
56+
ValueExpressionDelegate valueExpressionDelegate) {
57+
super(method, operations, valueExpressionDelegate);
6058
Assert.notNull(method, "CouchbaseQueryMethod must not be null!");
6159
Assert.notNull(operations, "ReactiveCouchbaseOperations must not be null!");
62-
Assert.notNull(expressionParser, "SpelExpressionParser must not be null!");
63-
Assert.notNull(evaluationContextProvider, "QueryMethodEvaluationContextProvider must not be null!");
6460

6561
EntityMetadata<?> metadata = method.getEntityInformation();
6662
Class<?> type = metadata.getJavaType();

0 commit comments

Comments
 (0)