DATAJPA-1140 - Polishing.
Removed dead code, including those only used in tests. Javadoc. Formatting. Original pull request: #206.
This commit is contained in:
committed by
Oliver Gierke
parent
f97928ef47
commit
d15139f962
@@ -60,7 +60,6 @@ class StoredProcedureJpaQuery extends AbstractJpaQuery {
|
||||
* Determine whether to used named parameters for the given query method.
|
||||
*
|
||||
* @param method must not be {@literal null}.
|
||||
* @return
|
||||
*/
|
||||
private static boolean useNamedParameters(QueryMethod method) {
|
||||
|
||||
@@ -104,7 +103,6 @@ class StoredProcedureJpaQuery extends AbstractJpaQuery {
|
||||
* Extracts the output value from the given {@link StoredProcedureQuery}.
|
||||
*
|
||||
* @param storedProcedureQuery must not be {@literal null}.
|
||||
* @return
|
||||
*/
|
||||
Object extractOutputValue(StoredProcedureQuery storedProcedureQuery) {
|
||||
|
||||
@@ -124,8 +122,6 @@ class StoredProcedureJpaQuery extends AbstractJpaQuery {
|
||||
|
||||
/**
|
||||
* Creates a new JPA 2.1 {@link StoredProcedureQuery} from this {@link StoredProcedureJpaQuery}.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
private StoredProcedureQuery createStoredProcedure() {
|
||||
return procedureAttributes.isNamedStoredProcedure() ? newNamedStoredProcedureQuery()
|
||||
@@ -134,8 +130,6 @@ class StoredProcedureJpaQuery extends AbstractJpaQuery {
|
||||
|
||||
/**
|
||||
* Creates a new named {@link StoredProcedureQuery} defined via an {@link NamedStoredProcedureQuery} on an entity.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
private StoredProcedureQuery newNamedStoredProcedureQuery() {
|
||||
return getEntityManager().createNamedStoredProcedureQuery(procedureAttributes.getProcedureName());
|
||||
@@ -143,8 +137,6 @@ class StoredProcedureJpaQuery extends AbstractJpaQuery {
|
||||
|
||||
/**
|
||||
* Creates a new ad-hoc {@link StoredProcedureQuery} from the given {@link StoredProcedureAttributes}.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
private StoredProcedureQuery newAdhocStoredProcedureQuery() {
|
||||
|
||||
|
||||
@@ -68,17 +68,13 @@ class StringQuery {
|
||||
|
||||
/**
|
||||
* Returns whether we have found some like bindings.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public boolean hasParameterBindings() {
|
||||
boolean hasParameterBindings() {
|
||||
return !bindings.isEmpty();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the {@link ParameterBinding}s registered.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
List<ParameterBinding> getParameterBindings() {
|
||||
return bindings;
|
||||
@@ -86,8 +82,6 @@ class StringQuery {
|
||||
|
||||
/**
|
||||
* Returns the query string.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public String getQueryString() {
|
||||
return query;
|
||||
@@ -98,62 +92,23 @@ class StringQuery {
|
||||
*
|
||||
* @return the alias
|
||||
*/
|
||||
public String getAlias() {
|
||||
String getAlias() {
|
||||
return alias;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the {@link ParameterBinding} for the given name.
|
||||
*
|
||||
* @param name must not be {@literal null} or empty.
|
||||
* @return
|
||||
*/
|
||||
public ParameterBinding getBindingFor(String name) {
|
||||
|
||||
Assert.hasText(name, PARAMETER_NAME_MISSING);
|
||||
|
||||
for (ParameterBinding binding : bindings) {
|
||||
if (binding.hasName(name)) {
|
||||
return binding;
|
||||
}
|
||||
}
|
||||
|
||||
throw new IllegalArgumentException(String.format("No parameter binding found for name %s!", name));
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the {@link ParameterBinding} for the given position.
|
||||
*
|
||||
* @param position
|
||||
* @return
|
||||
*/
|
||||
public ParameterBinding getBindingFor(int position) {
|
||||
|
||||
for (ParameterBinding binding : bindings) {
|
||||
if (binding.hasPosition(position)) {
|
||||
return binding;
|
||||
}
|
||||
}
|
||||
|
||||
throw new IllegalArgumentException(String.format("No parameter binding found for position %s!", position));
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether the query is using a constructor expression.
|
||||
*
|
||||
* @return
|
||||
* @since 1.10
|
||||
*/
|
||||
public boolean hasConstructorExpression() {
|
||||
boolean hasConstructorExpression() {
|
||||
return hasConstructorExpression;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether the query uses the default projection, i.e. returns the main alias defined for the query.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public boolean isDefaultProjection() {
|
||||
boolean isDefaultProjection() {
|
||||
return QueryUtils.getProjection(query).equals(alias);
|
||||
}
|
||||
|
||||
@@ -174,7 +129,7 @@ class StringQuery {
|
||||
|
||||
static {
|
||||
|
||||
List<String> keywords = new ArrayList<String>();
|
||||
List<String> keywords = new ArrayList<>();
|
||||
|
||||
for (ParameterBindingType type : ParameterBindingType.values()) {
|
||||
if (type.getKeyword() != null) {
|
||||
@@ -203,11 +158,8 @@ class StringQuery {
|
||||
/**
|
||||
* Parses {@link ParameterBinding} instances from the given query and adds them to the registered bindings. Returns
|
||||
* the cleaned up query.
|
||||
*
|
||||
* @param query
|
||||
* @return
|
||||
*/
|
||||
private final String parseParameterBindingsOfQueryIntoBindingsAndReturnCleanedQuery(String query,
|
||||
private String parseParameterBindingsOfQueryIntoBindingsAndReturnCleanedQuery(String query,
|
||||
List<ParameterBinding> bindings) {
|
||||
|
||||
String result = query;
|
||||
@@ -329,7 +281,7 @@ class StringQuery {
|
||||
* @author Thomas Darimont
|
||||
* @author Oliver Gierke
|
||||
*/
|
||||
private static enum ParameterBindingType {
|
||||
private enum ParameterBindingType {
|
||||
|
||||
// Trailing whitespace is intentional to reflect that the keywords must be used with at least one whitespace
|
||||
// character, while = does not.
|
||||
@@ -337,7 +289,7 @@ class StringQuery {
|
||||
|
||||
private final String keyword;
|
||||
|
||||
private ParameterBindingType(String keyword) {
|
||||
ParameterBindingType(String keyword) {
|
||||
this.keyword = keyword;
|
||||
}
|
||||
|
||||
@@ -352,11 +304,8 @@ class StringQuery {
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the appropriate {@link ParameterBindingType} for the given {@link String}. Returns {@keyword #AS_IS} in
|
||||
* Return the appropriate {@link ParameterBindingType} for the given {@link String}. Returns {@literal #AS_IS} in
|
||||
* case no other {@link ParameterBindingType} could be found.
|
||||
*
|
||||
* @param typeSource
|
||||
* @return
|
||||
*/
|
||||
static ParameterBindingType of(String typeSource) {
|
||||
|
||||
@@ -386,31 +335,22 @@ class StringQuery {
|
||||
private final String expression;
|
||||
private final Integer position;
|
||||
|
||||
/**
|
||||
* Creates a new {@link ParameterBinding} for the parameter with the given name.
|
||||
*
|
||||
* @param name must not be {@literal null}.
|
||||
*/
|
||||
public ParameterBinding(String name) {
|
||||
this(name, null, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new {@link ParameterBinding} for the parameter with the given position.
|
||||
*
|
||||
* @param position must not be {@literal null}.
|
||||
*/
|
||||
public ParameterBinding(Integer position) {
|
||||
ParameterBinding(Integer position) {
|
||||
this(null, position, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new {@link ParameterBinding} for the parameter with the given name, position and expression
|
||||
* information.
|
||||
* information. Either {@literal name} or {@literal position} must be not {@literal null}.
|
||||
*
|
||||
* @param name
|
||||
* @param position
|
||||
* @param expression
|
||||
* @param name of the parameter may be {@literal null}.
|
||||
* @param position of the parameter may be {@literal null}.
|
||||
* @param expression the expression to apply to any value for this parameter.
|
||||
*/
|
||||
ParameterBinding(String name, Integer position, String expression) {
|
||||
|
||||
@@ -430,22 +370,16 @@ class StringQuery {
|
||||
/**
|
||||
* Returns whether the binding has the given name. Will always be {@literal false} in case the
|
||||
* {@link ParameterBinding} has been set up from a position.
|
||||
*
|
||||
* @param name
|
||||
* @return
|
||||
*/
|
||||
public boolean hasName(String name) {
|
||||
boolean hasName(String name) {
|
||||
return this.position == null && this.name != null && this.name.equals(name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether the binding has the given position. Will always be {@literal false} in case the
|
||||
* {@link ParameterBinding} has been set up from a name.
|
||||
*
|
||||
* @param position
|
||||
* @return
|
||||
*/
|
||||
public boolean hasPosition(Integer position) {
|
||||
boolean hasPosition(Integer position) {
|
||||
return position != null && this.name == null && position.equals(this.position);
|
||||
}
|
||||
|
||||
@@ -459,7 +393,7 @@ class StringQuery {
|
||||
/**
|
||||
* @return the position
|
||||
*/
|
||||
public Integer getPosition() {
|
||||
Integer getPosition() {
|
||||
return position;
|
||||
}
|
||||
|
||||
@@ -514,8 +448,7 @@ class StringQuery {
|
||||
}
|
||||
|
||||
/**
|
||||
* @param valueToBind
|
||||
* @return
|
||||
* @param valueToBind value to prepare
|
||||
*/
|
||||
public Object prepare(Object valueToBind) {
|
||||
return valueToBind;
|
||||
@@ -536,21 +469,15 @@ class StringQuery {
|
||||
|
||||
/**
|
||||
* Creates a new {@link InParameterBinding} for the parameter with the given name.
|
||||
*
|
||||
* @param name
|
||||
* @param expression
|
||||
*/
|
||||
public InParameterBinding(String name, String expression) {
|
||||
InParameterBinding(String name, String expression) {
|
||||
super(name, null, expression);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new {@link InParameterBinding} for the parameter with the given position.
|
||||
*
|
||||
* @param position
|
||||
* @param expression
|
||||
*/
|
||||
public InParameterBinding(int position, String expression) {
|
||||
InParameterBinding(int position, String expression) {
|
||||
super(null, position, expression);
|
||||
}
|
||||
|
||||
@@ -566,7 +493,7 @@ class StringQuery {
|
||||
}
|
||||
|
||||
int length = Array.getLength(value);
|
||||
Collection<Object> result = new ArrayList<Object>(length);
|
||||
Collection<Object> result = new ArrayList<>(length);
|
||||
|
||||
for (int i = 0; i < length; i++) {
|
||||
result.add(Array.get(value, i));
|
||||
@@ -596,7 +523,7 @@ class StringQuery {
|
||||
* @param name must not be {@literal null} or empty.
|
||||
* @param type must not be {@literal null}.
|
||||
*/
|
||||
public LikeParameterBinding(String name, Type type) {
|
||||
LikeParameterBinding(String name, Type type) {
|
||||
this(name, type, null);
|
||||
}
|
||||
|
||||
@@ -608,7 +535,7 @@ class StringQuery {
|
||||
* @param type must not be {@literal null}.
|
||||
* @param expression may be {@literal null}.
|
||||
*/
|
||||
public LikeParameterBinding(String name, Type type, String expression) {
|
||||
LikeParameterBinding(String name, Type type, String expression) {
|
||||
|
||||
super(name, null, expression);
|
||||
|
||||
@@ -623,22 +550,22 @@ class StringQuery {
|
||||
|
||||
/**
|
||||
* Creates a new {@link LikeParameterBinding} for the parameter with the given position and {@link Type}.
|
||||
*
|
||||
* @param position
|
||||
*
|
||||
* @param position position of the parameter in the query.
|
||||
* @param type must not be {@literal null}.
|
||||
*/
|
||||
public LikeParameterBinding(int position, Type type) {
|
||||
LikeParameterBinding(int position, Type type) {
|
||||
this(position, type, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new {@link LikeParameterBinding} for the parameter with the given position and {@link Type}.
|
||||
*
|
||||
* @param position
|
||||
*
|
||||
* @param position position of the parameter in the query.
|
||||
* @param type must not be {@literal null}.
|
||||
* @param expression may be {@literal null}.
|
||||
*/
|
||||
public LikeParameterBinding(int position, Type type, String expression) {
|
||||
LikeParameterBinding(int position, Type type, String expression) {
|
||||
|
||||
super(null, position, expression);
|
||||
|
||||
@@ -669,7 +596,7 @@ class StringQuery {
|
||||
public Object prepare(Object value) {
|
||||
|
||||
if (value == null) {
|
||||
return value;
|
||||
return null;
|
||||
}
|
||||
|
||||
switch (type) {
|
||||
@@ -728,7 +655,6 @@ class StringQuery {
|
||||
* Extracts the like {@link Type} from the given JPA like expression.
|
||||
*
|
||||
* @param expression must not be {@literal null} or empty.
|
||||
* @return
|
||||
*/
|
||||
private static Type getLikeTypeFrom(String expression) {
|
||||
|
||||
|
||||
@@ -298,8 +298,6 @@ public class UserRepositoryTests {
|
||||
|
||||
/**
|
||||
* Tests, that searching by the email address of the reference user returns exactly that instance.
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
@Test
|
||||
public void testFindByEmailAddress() throws Exception {
|
||||
@@ -323,8 +321,6 @@ public class UserRepositoryTests {
|
||||
|
||||
/**
|
||||
* Tests that all users get deleted by triggering {@link UserRepository#deleteAll()}.
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
@Test
|
||||
public void deleteAll() throws Exception {
|
||||
@@ -1545,8 +1541,9 @@ public class UserRepositoryTests {
|
||||
public void shouldFindUsersByUserFirstnameAsSpELExpressionAndLastnameAsStringInStringBasedQuery() {
|
||||
|
||||
flushTestUsers();
|
||||
|
||||
List<User> users = repository.findUsersByUserFirstnameAsSpELExpressionAndLastnameAsString(firstUser, firstUser.getLastname());
|
||||
|
||||
List<User> users = repository.findUsersByUserFirstnameAsSpELExpressionAndLastnameAsString(firstUser,
|
||||
firstUser.getLastname());
|
||||
|
||||
assertThat(users).containsOnly(firstUser);
|
||||
}
|
||||
@@ -1555,19 +1552,20 @@ public class UserRepositoryTests {
|
||||
public void shouldFindUsersByFirstnameAsStringAndUserLastnameAsSpELExpressionInStringBasedQuery() {
|
||||
|
||||
flushTestUsers();
|
||||
|
||||
List<User> users = repository.findUsersByFirstnameAsStringAndUserLastnameAsSpELExpression(firstUser.getFirstname(), firstUser);
|
||||
|
||||
List<User> users = repository.findUsersByFirstnameAsStringAndUserLastnameAsSpELExpression(firstUser.getFirstname(),
|
||||
firstUser);
|
||||
|
||||
assertThat(users).containsOnly(firstUser);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Test // DATAJPA-1140
|
||||
public void shouldFindUsersByUserFirstnameAsSpELExpressionAndLastnameAsFakeSpELExpressionInStringBasedQuery() {
|
||||
|
||||
flushTestUsers();
|
||||
|
||||
List<User> users = repository.findUsersByUserFirstnameAsSpELExpressionAndLastnameAsFakeSpELExpression(firstUser, firstUser.getLastname());
|
||||
|
||||
List<User> users = repository.findUsersByUserFirstnameAsSpELExpressionAndLastnameAsFakeSpELExpression(firstUser,
|
||||
firstUser.getLastname());
|
||||
|
||||
assertThat(users).containsOnly(firstUser);
|
||||
}
|
||||
@@ -1576,8 +1574,10 @@ public class UserRepositoryTests {
|
||||
public void shouldFindUsersByFirstnameAsFakeSpELExpressionAndUserLastnameAsSpELExpressionInStringBasedQuery() {
|
||||
|
||||
flushTestUsers();
|
||||
|
||||
List<User> users = repository.findUsersByFirstnameAsFakeSpELExpressionAndUserLastnameAsSpELExpression(firstUser.getFirstname(), firstUser);
|
||||
|
||||
List<User> users = repository
|
||||
.findUsersByFirstnameAsFakeSpELExpressionAndUserLastnameAsSpELExpression(firstUser.getFirstname(), firstUser);
|
||||
|
||||
assertThat(users).containsOnly(firstUser);
|
||||
}
|
||||
|
||||
|
||||
@@ -205,17 +205,6 @@ public class StringQueryUnitTests {
|
||||
assertNamedBinding(InParameterBinding.class, "statuses", bindings.get(0));
|
||||
}
|
||||
|
||||
@Test // DATAJPA-513
|
||||
public void rejectsNullParameterNameHintingTowardsAtParamForNullParameterName() {
|
||||
|
||||
StringQuery query = new StringQuery("select x from X");
|
||||
|
||||
exception.expect(IllegalArgumentException.class);
|
||||
exception.expectMessage(Param.class.getSimpleName());
|
||||
|
||||
query.getBindingFor(null);
|
||||
}
|
||||
|
||||
@Test // DATAJPA-545
|
||||
public void detectsInBindingWithSpecialFrenchCharactersInParentheses() {
|
||||
|
||||
|
||||
Reference in New Issue
Block a user