DATAMONGO-1603 - Polishing.

Remove code that became unused. Reformat code. Extend years in copyright header.

Original pull request: #441.
This commit is contained in:
Mark Paluch
2017-03-01 08:17:57 +01:00
parent 8068e36679
commit e2d6f187c2
3 changed files with 29 additions and 38 deletions

View File

@@ -264,38 +264,34 @@ class ExpressionEvaluatingParameterBinder {
*/
private Placeholder extractPlaceholder(int parameterIndex, Matcher matcher) {
if (matcher.groupCount() > 1) {
String rawPlaceholder = matcher.group(parameterIndex * 3 + 1);
String suffix = matcher.group(parameterIndex * 3 + 2);
String rawPlaceholder = matcher.group(parameterIndex * 3 + 1);
String suffix = matcher.group(parameterIndex * 3 + 2);
if (!StringUtils.hasText(rawPlaceholder)) {
if (!StringUtils.hasText(rawPlaceholder)) {
rawPlaceholder = matcher.group();
if(rawPlaceholder.matches(".*\\d$")) {
suffix = "";
} else {
int index = rawPlaceholder.replaceAll("[^\\?0-9]*$", "").length() - 1;
if (index > 0 && rawPlaceholder.length() > index) {
suffix = rawPlaceholder.substring(index+1);
}
}
if (QuotedString.endsWithQuote(rawPlaceholder)) {
rawPlaceholder = rawPlaceholder.substring(0, rawPlaceholder.length() - (StringUtils.hasText(suffix) ? suffix.length() : 1));
rawPlaceholder = matcher.group();
if (rawPlaceholder.matches(".*\\d$")) {
suffix = "";
} else {
int index = rawPlaceholder.replaceAll("[^\\?0-9]*$", "").length() - 1;
if (index > 0 && rawPlaceholder.length() > index) {
suffix = rawPlaceholder.substring(index + 1);
}
}
if (StringUtils.hasText(suffix)) {
boolean quoted = QuotedString.endsWithQuote(suffix);
return Placeholder.of(parameterIndex, rawPlaceholder, quoted,
quoted ? QuotedString.unquoteSuffix(suffix) : suffix);
if (QuotedString.endsWithQuote(rawPlaceholder)) {
rawPlaceholder = rawPlaceholder.substring(0,
rawPlaceholder.length() - (StringUtils.hasText(suffix) ? suffix.length() : 1));
}
return Placeholder.of(parameterIndex, rawPlaceholder, false, null);
}
return Placeholder.of(parameterIndex, matcher.group(), false, null);
if (StringUtils.hasText(suffix)) {
boolean quoted = QuotedString.endsWithQuote(suffix);
return Placeholder.of(parameterIndex, rawPlaceholder, quoted,
quoted ? QuotedString.unquoteSuffix(suffix) : suffix);
}
return Placeholder.of(parameterIndex, rawPlaceholder, false, null);
}
/**

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2011-2016 the original author or authors.
* Copyright 2011-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.

View File

@@ -24,13 +24,9 @@ import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.regex.Pattern;
import javax.xml.bind.DatatypeConverter;
import com.mongodb.BasicDBObject;
import com.mongodb.DBObject;
import com.mongodb.util.JSON;
import org.bson.BSON;
import org.bson.BsonRegularExpression;
import org.bson.Document;
@@ -446,8 +442,8 @@ public class StringBasedMongoQueryUnitTests {
ConvertingParameterAccessor accessor = StubParameterAccessor.getAccessor(converter, "calamity", "regalia");
org.springframework.data.mongodb.core.query.Query query = mongoQuery.createQuery(accessor);
assertThat(query.getQueryObject(), is(new Document().append("arg0", "calamity")
.append("arg1", "regalia").append("arg2", "calamity")));
assertThat(query.getQueryObject(),
is(new Document().append("arg0", "calamity").append("arg1", "regalia").append("arg2", "calamity")));
}
@Test // DATAMONGO-1603
@@ -458,8 +454,8 @@ public class StringBasedMongoQueryUnitTests {
ConvertingParameterAccessor accessor = StubParameterAccessor.getAccessor(converter, "calamity", "regalia");
org.springframework.data.mongodb.core.query.Query query = mongoQuery.createQuery(accessor);
assertThat(query.getQueryObject(), is(new Document().append("arg0", "calamity")
.append("arg1", "regalia").append("arg2", "calamity")));
assertThat(query.getQueryObject(),
is(new Document().append("arg0", "calamity").append("arg1", "regalia").append("arg2", "calamity")));
}
@Test // DATAMONGO-1603
@@ -470,8 +466,8 @@ public class StringBasedMongoQueryUnitTests {
ConvertingParameterAccessor accessor = StubParameterAccessor.getAccessor(converter, "calamity", "regalia");
org.springframework.data.mongodb.core.query.Query query = mongoQuery.createQuery(accessor);
assertThat(query.getQueryObject(), is(new Document().append("arg0", "calamity")
.append("arg1", "regalia").append("arg2", "calamitys")));
assertThat(query.getQueryObject(),
is(new Document().append("arg0", "calamity").append("arg1", "regalia").append("arg2", "calamitys")));
}
@Test // DATAMONGO-1603
@@ -482,8 +478,7 @@ public class StringBasedMongoQueryUnitTests {
ConvertingParameterAccessor accessor = StubParameterAccessor.getAccessor(converter, "calamity", "regalia");
org.springframework.data.mongodb.core.query.Query query = mongoQuery.createQuery(accessor);
assertThat(query.getQueryObject(),
is(new Document().append("arg0", "calamity").append("arg1", "regalias")));
assertThat(query.getQueryObject(), is(new Document().append("arg0", "calamity").append("arg1", "regalias")));
}
@Test // DATAMONGO-1603