Skip to content

Commit 3629ff8

Browse files
mp911demarcingrzejszczak
authored andcommitted
Hacking.
1 parent ce7b205 commit 3629ff8

File tree

2 files changed

+64
-1
lines changed

2 files changed

+64
-1
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/*
2+
* Copyright 2024 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package org.springframework.data.repository.query;
17+
18+
import org.springframework.data.expression.ValueExpression;
19+
import org.springframework.data.expression.ValueExpressionParser;
20+
import org.springframework.expression.ParseException;
21+
import org.springframework.util.ConcurrentLruCache;
22+
23+
/**
24+
* Caching variant of {@link ValueExpressionSupportHolder}.
25+
*
26+
* @author Mark Paluch
27+
*/
28+
public class CachingValueExpressionSupportHolder extends ValueExpressionSupportHolder {
29+
30+
private final ConcurrentLruCache<String, ValueExpression> expressionCache;
31+
32+
public CachingValueExpressionSupportHolder(ValueExpressionSupportHolder supportHolder) {
33+
super(supportHolder);
34+
this.expressionCache = new ConcurrentLruCache<>(256, supportHolder.getValueExpressionParser()::parse);
35+
}
36+
37+
public CachingValueExpressionSupportHolder(QueryMethodValueEvaluationContextProviderFactory providerFactory,
38+
ValueExpressionParser valueExpressionParser) {
39+
super(providerFactory, valueExpressionParser);
40+
this.expressionCache = new ConcurrentLruCache<>(256, valueExpressionParser::parse);
41+
}
42+
43+
@Override
44+
public ValueExpressionParser getValueExpressionParser() {
45+
return this;
46+
}
47+
48+
@Override
49+
public ValueExpression parse(String expressionString) throws ParseException {
50+
return expressionCache.get(expressionString);
51+
}
52+
}

src/main/java/org/springframework/data/repository/query/ValueExpressionSupportHolder.java

+12-1
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,23 @@
1515
*/
1616
package org.springframework.data.repository.query;
1717

18+
import org.springframework.data.expression.ValueExpression;
1819
import org.springframework.data.expression.ValueExpressionParser;
20+
import org.springframework.expression.ParseException;
1921

2022
/**
2123
* @author Mark Paluch
2224
*/
23-
public final class ValueExpressionSupportHolder {
25+
public class ValueExpressionSupportHolder implements ValueExpressionParser {
2426

2527
private final QueryMethodValueEvaluationContextProviderFactory providerFactory;
2628
private final ValueExpressionParser valueExpressionParser;
2729

30+
ValueExpressionSupportHolder(ValueExpressionSupportHolder original) {
31+
this.providerFactory = original.providerFactory;
32+
this.valueExpressionParser = original.valueExpressionParser;
33+
}
34+
2835
public ValueExpressionSupportHolder(QueryMethodValueEvaluationContextProviderFactory providerFactory,
2936
ValueExpressionParser valueExpressionParser) {
3037
this.providerFactory = providerFactory;
@@ -39,4 +46,8 @@ public ValueExpressionParser getValueExpressionParser() {
3946
return valueExpressionParser;
4047
}
4148

49+
@Override
50+
public ValueExpression parse(String expressionString) throws ParseException {
51+
return valueExpressionParser.parse(expressionString);
52+
}
4253
}

0 commit comments

Comments
 (0)