Skip to content

Commit e2d6f18

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

File tree

3 files changed

+30
-39
lines changed

3 files changed

+30
-39
lines changed

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

Lines changed: 22 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -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);
271-
272-
if (!StringUtils.hasText(rawPlaceholder)) {
273-
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));
267+
String rawPlaceholder = matcher.group(parameterIndex * 3 + 1);
268+
String suffix = matcher.group(parameterIndex * 3 + 2);
269+
270+
if (!StringUtils.hasText(rawPlaceholder)) {
271+
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: 1 addition & 1 deletion
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.

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

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,9 @@
2424
import java.util.Collections;
2525
import java.util.List;
2626
import java.util.Map;
27-
import java.util.regex.Pattern;
2827

2928
import javax.xml.bind.DatatypeConverter;
3029

31-
import com.mongodb.BasicDBObject;
32-
import com.mongodb.DBObject;
33-
import com.mongodb.util.JSON;
3430
import org.bson.BSON;
3531
import org.bson.BsonRegularExpression;
3632
import org.bson.Document;
@@ -446,8 +442,8 @@ public void shouldAllowReuseOfPlaceholderWithinQuery() throws Exception {
446442
ConvertingParameterAccessor accessor = StubParameterAccessor.getAccessor(converter, "calamity", "regalia");
447443

448444
org.springframework.data.mongodb.core.query.Query query = mongoQuery.createQuery(accessor);
449-
assertThat(query.getQueryObject(), is(new Document().append("arg0", "calamity")
450-
.append("arg1", "regalia").append("arg2", "calamity")));
445+
assertThat(query.getQueryObject(),
446+
is(new Document().append("arg0", "calamity").append("arg1", "regalia").append("arg2", "calamity")));
451447
}
452448

453449
@Test // DATAMONGO-1603
@@ -458,8 +454,8 @@ public void shouldAllowReuseOfQuotedPlaceholderWithinQuery() throws Exception {
458454
ConvertingParameterAccessor accessor = StubParameterAccessor.getAccessor(converter, "calamity", "regalia");
459455

460456
org.springframework.data.mongodb.core.query.Query query = mongoQuery.createQuery(accessor);
461-
assertThat(query.getQueryObject(), is(new Document().append("arg0", "calamity")
462-
.append("arg1", "regalia").append("arg2", "calamity")));
457+
assertThat(query.getQueryObject(),
458+
is(new Document().append("arg0", "calamity").append("arg1", "regalia").append("arg2", "calamity")));
463459
}
464460

465461
@Test // DATAMONGO-1603
@@ -470,8 +466,8 @@ public void shouldAllowReuseOfQuotedPlaceholderWithinQueryAndIncludeSuffixCorrec
470466
ConvertingParameterAccessor accessor = StubParameterAccessor.getAccessor(converter, "calamity", "regalia");
471467

472468
org.springframework.data.mongodb.core.query.Query query = mongoQuery.createQuery(accessor);
473-
assertThat(query.getQueryObject(), is(new Document().append("arg0", "calamity")
474-
.append("arg1", "regalia").append("arg2", "calamitys")));
469+
assertThat(query.getQueryObject(),
470+
is(new Document().append("arg0", "calamity").append("arg1", "regalia").append("arg2", "calamitys")));
475471
}
476472

477473
@Test // DATAMONGO-1603
@@ -482,8 +478,7 @@ public void shouldAllowQuotedParameterWithSuffixAppended() throws Exception {
482478
ConvertingParameterAccessor accessor = StubParameterAccessor.getAccessor(converter, "calamity", "regalia");
483479

484480
org.springframework.data.mongodb.core.query.Query query = mongoQuery.createQuery(accessor);
485-
assertThat(query.getQueryObject(),
486-
is(new Document().append("arg0", "calamity").append("arg1", "regalias")));
481+
assertThat(query.getQueryObject(), is(new Document().append("arg0", "calamity").append("arg1", "regalias")));
487482
}
488483

489484
@Test // DATAMONGO-1603

0 commit comments

Comments
 (0)