15
15
*/
16
16
package org .springframework .data .repository .query ;
17
17
18
- import org .springframework .data .domain .Range ;
19
- import org .springframework .data .domain .Range .Bound ;
20
- import org .springframework .lang .Nullable ;
21
- import org .springframework .util .Assert ;
22
-
23
18
import java .util .ArrayList ;
24
19
import java .util .Arrays ;
25
20
import java .util .Collection ;
33
28
import java .util .regex .Pattern ;
34
29
import java .util .stream .Stream ;
35
30
31
+ import org .springframework .data .domain .Range ;
32
+ import org .springframework .data .domain .Range .Bound ;
33
+ import org .springframework .lang .Nullable ;
34
+ import org .springframework .util .Assert ;
35
+
36
36
/**
37
- * A {@literal SpelQueryContext} is able to find SpEL expressions in a query string and to replace them with bind variables.
37
+ * A {@literal SpelQueryContext} is able to find SpEL expressions in a query string and to replace them with bind
38
+ * variables.
38
39
* <p>
39
- * Result o the parse process is a {@link SpelExtractor} which offers the transformed query string.
40
- * Alternatively and preferred one may provide a {@link QueryMethodEvaluationContextProvider} via
40
+ * Result o the parse process is a {@link SpelExtractor} which offers the transformed query string. Alternatively and
41
+ * preferred one may provide a {@link QueryMethodEvaluationContextProvider} via
41
42
* {@link #withEvaluationContextProvider(QueryMethodEvaluationContextProvider)} which will yield the more powerful
42
43
* {@link EvaluatingSpelQueryContext}.
43
44
* <p>
44
45
* Typical usage looks like
45
- * <pre><code>
46
+ *
47
+ * <pre>
48
+ * <code>
46
49
SpelQueryContext.EvaluatingSpelQueryContext queryContext = SpelQueryContext
47
50
.of((counter, expression) -> String.format("__$synthetic$__%d", counter), String::concat)
48
51
.withEvaluationContextProvider(evaluationContextProvider);
49
52
50
53
SpelEvaluator spelEvaluator = queryContext.parse(query, queryMethod.getParameters());
51
54
52
55
spelEvaluator.evaluate(objects).forEach(parameterMap::addValue);
53
- * </code></pre>
56
+ * </code>
57
+ * </pre>
54
58
*
55
59
* @author Jens Schauder
56
60
* @author Gerrit Meier
@@ -79,7 +83,7 @@ public class SpelQueryContext {
79
83
private final BiFunction <String , String , String > replacementSource ;
80
84
81
85
private SpelQueryContext (BiFunction <Integer , String , String > parameterNameSource ,
82
- BiFunction <String , String , String > replacementSource ) {
86
+ BiFunction <String , String , String > replacementSource ) {
83
87
84
88
Assert .notNull (parameterNameSource , "Parameter name source must not be null" );
85
89
Assert .notNull (replacementSource , "Replacement source must not be null" );
@@ -89,7 +93,7 @@ private SpelQueryContext(BiFunction<Integer, String, String> parameterNameSource
89
93
}
90
94
91
95
public static SpelQueryContext of (BiFunction <Integer , String , String > parameterNameSource ,
92
- BiFunction <String , String , String > replacementSource ) {
96
+ BiFunction <String , String , String > replacementSource ) {
93
97
return new SpelQueryContext (parameterNameSource , replacementSource );
94
98
}
95
99
@@ -105,7 +109,7 @@ public static SpelQueryContext of(BiFunction<Integer, String, String> parameterN
105
109
*
106
110
* @param query a query containing SpEL expressions in the format described above. Must not be {@literal null}.
107
111
* @return A {@link SpelExtractor} which makes the query with SpEL expressions replaced by bind parameters and a map
108
- * from bind parameter to SpEL expression available. Guaranteed to be not {@literal null}.
112
+ * from bind parameter to SpEL expression available. Guaranteed to be not {@literal null}.
109
113
*/
110
114
public SpelExtractor parse (String query ) {
111
115
return new SpelExtractor (query );
@@ -141,11 +145,11 @@ public static class EvaluatingSpelQueryContext extends SpelQueryContext {
141
145
* parameter name source and replacement source.
142
146
*
143
147
* @param evaluationContextProvider must not be {@literal null}.
144
- * @param parameterNameSource must not be {@literal null}.
145
- * @param replacementSource must not be {@literal null}.
148
+ * @param parameterNameSource must not be {@literal null}.
149
+ * @param replacementSource must not be {@literal null}.
146
150
*/
147
151
private EvaluatingSpelQueryContext (QueryMethodEvaluationContextProvider evaluationContextProvider ,
148
- BiFunction <Integer , String , String > parameterNameSource , BiFunction <String , String , String > replacementSource ) {
152
+ BiFunction <Integer , String , String > parameterNameSource , BiFunction <String , String , String > replacementSource ) {
149
153
150
154
super (parameterNameSource , replacementSource );
151
155
@@ -162,7 +166,7 @@ private EvaluatingSpelQueryContext(QueryMethodEvaluationContextProvider evaluati
162
166
* with prefix being the character ':' or '?'. Parsing honors quoted {@literal String}s enclosed in single or double
163
167
* quotation marks.
164
168
*
165
- * @param query a query containing SpEL expressions in the format described above. Must not be {@literal null}.
169
+ * @param query a query containing SpEL expressions in the format described above. Must not be {@literal null}.
166
170
* @param parameters a {@link Parameters} instance describing query method parameters
167
171
* @return A {@link SpelEvaluator} which allows to evaluate the SpEL expressions. Will never be {@literal null}.
168
172
*/
@@ -180,6 +184,7 @@ public SpelEvaluator parse(String query, Parameters<?, ?> parameters) {
180
184
*
181
185
* @author Jens Schauder
182
186
* @author Oliver Gierke
187
+ * @author Mark Paluch
183
188
* @since 2.1
184
189
*/
185
190
public class SpelExtractor {
@@ -264,6 +269,16 @@ public String getParameter(String name) {
264
269
return expressions .get (name );
265
270
}
266
271
272
+ /**
273
+ * Returns the number of expressions in this extractor.
274
+ *
275
+ * @return the number of expressions in this extractor.
276
+ * @since 3.1.3
277
+ */
278
+ public int size () {
279
+ return expressions .size ();
280
+ }
281
+
267
282
/**
268
283
* A {@literal Map} from parameter name to SpEL expression.
269
284
*
0 commit comments