@@ -161,7 +161,8 @@ protected boolean isDeleteQuery() {
161
161
* @param bindings
162
162
* @return
163
163
*/
164
- private String replacePlaceholders (String input , ConvertingParameterAccessor accessor , List <ParameterBinding > bindings ) {
164
+ private String replacePlaceholders (String input , ConvertingParameterAccessor accessor ,
165
+ List <ParameterBinding > bindings ) {
165
166
166
167
if (bindings .isEmpty ()) {
167
168
return input ;
@@ -187,11 +188,11 @@ private String replacePlaceholders(String input, ConvertingParameterAccessor acc
187
188
int end = idx + parameter .length ();
188
189
189
190
if (shouldPotentiallyRemoveQuotes ) {
190
-
191
+
191
192
// is the insertion point actually surrounded by quotes?
192
193
char beforeStart = result .charAt (start - 1 );
193
194
char afterEnd = result .charAt (end );
194
-
195
+
195
196
if ((beforeStart == '\'' || beforeStart == '"' ) && (afterEnd == '\'' || afterEnd == '"' )) {
196
197
197
198
// skip preceeding and following quote
@@ -235,9 +236,10 @@ private String getParameterValueForBinding(ConvertingParameterAccessor accessor,
235
236
*/
236
237
private Object evaluateExpression (String expressionString , Object [] parameterValues ) {
237
238
238
- EvaluationContext evaluationContext = evaluationContextProvider . getEvaluationContext ( getQueryMethod ()
239
- .getParameters (), parameterValues );
239
+ EvaluationContext evaluationContext = evaluationContextProvider
240
+ .getEvaluationContext ( getQueryMethod (). getParameters (), parameterValues );
240
241
Expression expression = expressionParser .parseExpression (expressionString );
242
+
241
243
return expression .getValue (evaluationContext , Object .class );
242
244
}
243
245
@@ -287,7 +289,7 @@ public String parseAndCollectParameterBindingsFromQueryIntoBindings(String input
287
289
return transformedInput ;
288
290
}
289
291
290
- private String transformQueryAndCollectExpressionParametersIntoBindings (String input ,
292
+ private static String transformQueryAndCollectExpressionParametersIntoBindings (String input ,
291
293
List <ParameterBinding > bindings ) {
292
294
293
295
StringBuilder result = new StringBuilder ();
@@ -297,14 +299,11 @@ private String transformQueryAndCollectExpressionParametersIntoBindings(String i
297
299
int exprIndex = 0 ;
298
300
299
301
while (currentPos < input .length ()) {
300
- int indexOfExpressionParameter = input .indexOf (INDEX_BASED_EXPRESSION_PARAM_START , currentPos );
301
302
302
- if (indexOfExpressionParameter < 0 ) {
303
- indexOfExpressionParameter = input .indexOf (NAME_BASED_EXPRESSION_PARAM_START , currentPos );
304
- }
303
+ int indexOfExpressionParameter = getIndexOfExpressionParameter (input , currentPos );
305
304
305
+ // no expression parameter found
306
306
if (indexOfExpressionParameter < 0 ) {
307
- // no expression parameter found
308
307
break ;
309
308
}
310
309
@@ -313,44 +312,41 @@ private String transformQueryAndCollectExpressionParametersIntoBindings(String i
313
312
314
313
// eat parameter expression
315
314
int curlyBraceOpenCnt = 1 ;
315
+
316
316
while (curlyBraceOpenCnt > 0 ) {
317
- char c = input .charAt (currentPos ++);
318
- switch (c ) {
317
+ switch (input .charAt (currentPos ++)) {
319
318
case CURRLY_BRACE_OPEN :
320
319
curlyBraceOpenCnt ++;
321
320
break ;
322
321
case CURRLY_BRACE_CLOSE :
323
322
curlyBraceOpenCnt --;
324
323
break ;
325
324
default :
326
- ;
327
325
}
328
326
}
329
327
330
328
result .append (input .subSequence (startIndex , indexOfExpressionParameter ));
331
- result .append (EXPRESSION_PARAM_QUOTE ).append (EXPRESSION_PARAM_PREFIX ).append (exprIndex )
332
- .append (EXPRESSION_PARAM_QUOTE );
329
+ result .append (EXPRESSION_PARAM_QUOTE ).append (EXPRESSION_PARAM_PREFIX );
330
+ result .append (exprIndex );
331
+ result .append (EXPRESSION_PARAM_QUOTE );
332
+
333
333
bindings .add (new ParameterBinding (exprIndex , true , input .substring (exprStart , currentPos - 1 )));
334
334
335
335
startIndex = currentPos ;
336
336
337
337
exprIndex ++;
338
338
}
339
339
340
- result .append (input .subSequence (currentPos , input .length ()));
341
-
342
- return result .toString ();
340
+ return result .append (input .subSequence (currentPos , input .length ())).toString ();
343
341
}
344
342
345
- private String makeParameterReferencesParseable (String input ) {
343
+ private static String makeParameterReferencesParseable (String input ) {
346
344
347
345
Matcher matcher = PARAMETER_BINDING_PATTERN .matcher (input );
348
- String parseableInput = matcher .replaceAll (PARSEABLE_PARAMETER );
349
-
350
- return parseableInput ;
346
+ return matcher .replaceAll (PARSEABLE_PARAMETER );
351
347
}
352
348
353
- private void collectParameterReferencesIntoBindings (List <ParameterBinding > bindings , Object value ) {
349
+ private static void collectParameterReferencesIntoBindings (List <ParameterBinding > bindings , Object value ) {
354
350
355
351
if (value instanceof String ) {
356
352
@@ -393,7 +389,7 @@ private void collectParameterReferencesIntoBindings(List<ParameterBinding> bindi
393
389
}
394
390
}
395
391
396
- private void potentiallyAddBinding (String source , List <ParameterBinding > bindings ) {
392
+ private static void potentiallyAddBinding (String source , List <ParameterBinding > bindings ) {
397
393
398
394
Matcher valueMatcher = PARSEABLE_BINDING_PATTERN .matcher (source );
399
395
@@ -406,6 +402,14 @@ private void potentiallyAddBinding(String source, List<ParameterBinding> binding
406
402
bindings .add (new ParameterBinding (paramIndex , quoted ));
407
403
}
408
404
}
405
+
406
+ private static int getIndexOfExpressionParameter (String input , int position ) {
407
+
408
+ int indexOfExpressionParameter = input .indexOf (INDEX_BASED_EXPRESSION_PARAM_START , position );
409
+
410
+ return indexOfExpressionParameter < 0 ? input .indexOf (NAME_BASED_EXPRESSION_PARAM_START , position )
411
+ : indexOfExpressionParameter ;
412
+ }
409
413
}
410
414
411
415
/**
0 commit comments