Skip to content

Commit 45456f8

Browse files
committed
DATAMONGO-1603 - Polishing.
Remove code that became unused. Reformat code. Extend years in copyright header. Original pull request: #441.
1 parent a19e67e commit 45456f8

File tree

3 files changed

+40
-44
lines changed

3 files changed

+40
-44
lines changed

spring-data-mongodb/src/main/java/org/springframework/data/mongodb/repository/query/ExpressionEvaluatingParameterBinder.java

Lines changed: 24 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
/**
4646
* {@link ExpressionEvaluatingParameterBinder} allows to evaluate, convert and bind parameters to placeholders within a
4747
* {@link String}.
48-
*
48+
*
4949
* @author Christoph Strobl
5050
* @author Thomas Darimont
5151
* @author Oliver Gierke
@@ -59,7 +59,7 @@ class ExpressionEvaluatingParameterBinder {
5959

6060
/**
6161
* Creates new {@link ExpressionEvaluatingParameterBinder}
62-
*
62+
*
6363
* @param expressionParser must not be {@literal null}.
6464
* @param evaluationContextProvider must not be {@literal null}.
6565
*/
@@ -76,7 +76,7 @@ public ExpressionEvaluatingParameterBinder(SpelExpressionParser expressionParser
7676
/**
7777
* Bind values provided by {@link MongoParameterAccessor} to placeholders in {@literal raw} while considering
7878
* potential conversions and parameter types.
79-
*
79+
*
8080
* @param raw can be {@literal null} or empty.
8181
* @param accessor must not be {@literal null}.
8282
* @param bindingContext must not be {@literal null}.
@@ -93,7 +93,7 @@ public String bind(String raw, MongoParameterAccessor accessor, BindingContext b
9393

9494
/**
9595
* Replaced the parameter placeholders with the actual parameter values from the given {@link ParameterBinding}s.
96-
*
96+
*
9797
* @param input must not be {@literal null} or empty.
9898
* @param accessor must not be {@literal null}.
9999
* @param bindingContext must not be {@literal null}.
@@ -264,38 +264,34 @@ private Pattern createReplacementPattern(List<ParameterBinding> bindings) {
264264
*/
265265
private Placeholder extractPlaceholder(int parameterIndex, Matcher matcher) {
266266

267-
if (matcher.groupCount() > 1) {
268-
269-
String rawPlaceholder = matcher.group(parameterIndex * 3 + 1);
270-
String suffix = matcher.group(parameterIndex * 3 + 2);
267+
String rawPlaceholder = matcher.group(parameterIndex * 3 + 1);
268+
String suffix = matcher.group(parameterIndex * 3 + 2);
271269

272-
if (!StringUtils.hasText(rawPlaceholder)) {
270+
if (!StringUtils.hasText(rawPlaceholder)) {
273271

274-
rawPlaceholder = matcher.group();
275-
if(rawPlaceholder.matches(".*\\d$")) {
276-
suffix = "";
277-
} else {
278-
int index = rawPlaceholder.replaceAll("[^\\?0-9]*$", "").length() - 1;
279-
if (index > 0 && rawPlaceholder.length() > index) {
280-
suffix = rawPlaceholder.substring(index+1);
281-
}
282-
}
283-
if (QuotedString.endsWithQuote(rawPlaceholder)) {
284-
rawPlaceholder = rawPlaceholder.substring(0, rawPlaceholder.length() - (StringUtils.hasText(suffix) ? suffix.length() : 1));
272+
rawPlaceholder = matcher.group();
273+
if (rawPlaceholder.matches(".*\\d$")) {
274+
suffix = "";
275+
} else {
276+
int index = rawPlaceholder.replaceAll("[^\\?0-9]*$", "").length() - 1;
277+
if (index > 0 && rawPlaceholder.length() > index) {
278+
suffix = rawPlaceholder.substring(index + 1);
285279
}
286280
}
281+
if (QuotedString.endsWithQuote(rawPlaceholder)) {
282+
rawPlaceholder = rawPlaceholder.substring(0,
283+
rawPlaceholder.length() - (StringUtils.hasText(suffix) ? suffix.length() : 1));
284+
}
285+
}
287286

288-
if (StringUtils.hasText(suffix)) {
287+
if (StringUtils.hasText(suffix)) {
289288

290-
boolean quoted = QuotedString.endsWithQuote(suffix);
289+
boolean quoted = QuotedString.endsWithQuote(suffix);
291290

292-
return Placeholder.of(parameterIndex, rawPlaceholder, quoted,
293-
quoted ? QuotedString.unquoteSuffix(suffix) : suffix);
294-
}
295-
return Placeholder.of(parameterIndex, rawPlaceholder, false, null);
291+
return Placeholder.of(parameterIndex, rawPlaceholder, quoted,
292+
quoted ? QuotedString.unquoteSuffix(suffix) : suffix);
296293
}
297-
298-
return Placeholder.of(parameterIndex, matcher.group(), false, null);
294+
return Placeholder.of(parameterIndex, rawPlaceholder, false, null);
299295
}
300296

301297
/**

spring-data-mongodb/src/main/java/org/springframework/data/mongodb/repository/query/StringBasedMongoQuery.java

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2011-2016 the original author or authors.
2+
* Copyright 2011-2017 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -38,7 +38,7 @@
3838

3939
/**
4040
* Query to use a plain JSON String to create the {@link Query} to actually execute.
41-
*
41+
*
4242
* @author Oliver Gierke
4343
* @author Christoph Strobl
4444
* @author Thomas Darimont
@@ -61,7 +61,7 @@ public class StringBasedMongoQuery extends AbstractMongoQuery {
6161

6262
/**
6363
* Creates a new {@link StringBasedMongoQuery} for the given {@link MongoQueryMethod} and {@link MongoOperations}.
64-
*
64+
*
6565
* @param method must not be {@literal null}.
6666
* @param mongoOperations must not be {@literal null}.
6767
* @param expressionParser must not be {@literal null}.
@@ -99,7 +99,6 @@ public StringBasedMongoQuery(String query, MongoQueryMethod method, MongoOperati
9999

100100
this.parameterBinder = new ExpressionEvaluatingParameterBinder(expressionParser, evaluationContextProvider);
101101

102-
103102
if (method.hasAnnotatedQuery()) {
104103

105104
org.springframework.data.mongodb.repository.Query queryAnnotation = method.getQueryAnnotation();
@@ -127,10 +126,10 @@ public StringBasedMongoQuery(String query, MongoQueryMethod method, MongoOperati
127126
@Override
128127
protected Query createQuery(ConvertingParameterAccessor accessor) {
129128

130-
String queryString = parameterBinder.bind(this.query, accessor, new BindingContext(getQueryMethod()
131-
.getParameters(), queryParameterBindings));
132-
String fieldsString = parameterBinder.bind(this.fieldSpec, accessor, new BindingContext(getQueryMethod()
133-
.getParameters(), fieldSpecParameterBindings));
129+
String queryString = parameterBinder.bind(this.query, accessor,
130+
new BindingContext(getQueryMethod().getParameters(), queryParameterBindings));
131+
String fieldsString = parameterBinder.bind(this.fieldSpec, accessor,
132+
new BindingContext(getQueryMethod().getParameters(), fieldSpecParameterBindings));
134133

135134
Query query = new BasicQuery(queryString, fieldsString).with(accessor.getSort());
136135

@@ -141,7 +140,7 @@ protected Query createQuery(ConvertingParameterAccessor accessor) {
141140
return query;
142141
}
143142

144-
/*
143+
/*
145144
* (non-Javadoc)
146145
* @see org.springframework.data.mongodb.repository.query.AbstractMongoQuery#isCountQuery()
147146
*/
@@ -168,7 +167,8 @@ protected boolean isDeleteQuery() {
168167
return this.isDeleteQuery;
169168
}
170169

171-
private static boolean hasAmbiguousProjectionFlags(boolean isCountQuery, boolean isExistsQuery, boolean isDeleteQuery) {
170+
private static boolean hasAmbiguousProjectionFlags(boolean isCountQuery, boolean isExistsQuery,
171+
boolean isDeleteQuery) {
172172
return countBooleanValues(isCountQuery, isExistsQuery, isDeleteQuery) > 1;
173173
}
174174

@@ -188,7 +188,7 @@ private static int countBooleanValues(boolean... values) {
188188

189189
/**
190190
* A parser that extracts the parameter bindings from a given query string.
191-
*
191+
*
192192
* @author Thomas Darimont
193193
*/
194194
private enum ParameterBindingParser {
@@ -211,7 +211,7 @@ private enum ParameterBindingParser {
211211
/**
212212
* Returns a list of {@link ParameterBinding}s found in the given {@code input} or an
213213
* {@link Collections#emptyList()}.
214-
*
214+
*
215215
* @param input can be {@literal null} or empty.
216216
* @param bindings must not be {@literal null}.
217217
* @return
@@ -306,7 +306,7 @@ private static void collectParameterReferencesIntoBindings(List<ParameterBinding
306306
int paramIndex = Integer.parseInt(valueMatcher.group(PARAMETER_INDEX_GROUP));
307307

308308
/*
309-
* The pattern is used as a direct parameter replacement, e.g. 'field': ?1,
309+
* The pattern is used as a direct parameter replacement, e.g. 'field': ?1,
310310
* therefore we treat it as not quoted to remain backwards compatible.
311311
*/
312312
boolean quoted = !string.equals(PARAMETER_PREFIX + paramIndex);
@@ -356,7 +356,7 @@ private static int getIndexOfExpressionParameter(String input, int position) {
356356

357357
/**
358358
* A generic parameter binding with name or position information.
359-
*
359+
*
360360
* @author Thomas Darimont
361361
*/
362362
static class ParameterBinding {
@@ -367,7 +367,7 @@ static class ParameterBinding {
367367

368368
/**
369369
* Creates a new {@link ParameterBinding} with the given {@code parameterIndex} and {@code quoted} information.
370-
*
370+
*
371371
* @param parameterIndex
372372
* @param quoted whether or not the parameter is already quoted.
373373
*/

spring-data-mongodb/src/test/java/org/springframework/data/mongodb/repository/query/StringBasedMongoQueryUnitTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@
6060

6161
/**
6262
* Unit tests for {@link StringBasedMongoQuery}.
63-
*
63+
*
6464
* @author Oliver Gierke
6565
* @author Christoph Strobl
6666
* @author Thomas Darimont

0 commit comments

Comments
 (0)