DATAJPA-564 - Allow SpEL expressions to be the only consumer of query method parameters.
Since eclipselink doesn't reliably report whether a given query contains parameter we try to set query-parameters via brute force in SESQPB.
This commit is contained in:
committed by
Oliver Gierke
parent
0602084c0e
commit
26cda66de8
@@ -63,7 +63,8 @@ class SpelExpressionStringQueryParameterBinder extends StringQueryParameterBinde
|
|||||||
*/
|
*/
|
||||||
private <T extends Query> T potentiallyBindExpressionParameters(T jpaQuery) {
|
private <T extends Query> T potentiallyBindExpressionParameters(T jpaQuery) {
|
||||||
|
|
||||||
if (jpaQuery.getParameters().isEmpty()) {
|
if (isJpaParameterInformationReliable(jpaQuery) && jpaQuery.getParameters().isEmpty()) {
|
||||||
|
// We can rely on the fact there are no parameters in the given query.
|
||||||
return jpaQuery;
|
return jpaQuery;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -75,14 +76,28 @@ class SpelExpressionStringQueryParameterBinder extends StringQueryParameterBinde
|
|||||||
|
|
||||||
Object value = evaluateExpression(expr);
|
Object value = evaluateExpression(expr);
|
||||||
|
|
||||||
if (binding.getName() != null) {
|
try {
|
||||||
jpaQuery.setParameter(binding.getName(), binding.prepare(value));
|
if (binding.getName() != null) {
|
||||||
} else {
|
jpaQuery.setParameter(binding.getName(), binding.prepare(value));
|
||||||
jpaQuery.setParameter(binding.getPosition(), binding.prepare(value));
|
} else {
|
||||||
|
jpaQuery.setParameter(binding.getPosition(), binding.prepare(value));
|
||||||
|
}
|
||||||
|
} catch (IllegalArgumentException iae) {
|
||||||
|
/*
|
||||||
|
* Since Eclipse doesn't reliably report whether a query has parameters
|
||||||
|
* we simply try to set the parameters and ignore possible failures.
|
||||||
|
*
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return jpaQuery;
|
return jpaQuery;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private <T extends Query> boolean isJpaParameterInformationReliable(T jpaQuery) {
|
||||||
|
|
||||||
|
String className = jpaQuery.getClass().getName();
|
||||||
|
return className.startsWith("org.apache.openjpa") || className.startsWith("org.hibernate");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -74,10 +74,4 @@ public class EclipseLinkNamespaceUserRepositoryTests extends NamespaceUserReposi
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void findByElementCollectionAttribute() {}
|
public void findByElementCollectionAttribute() {}
|
||||||
|
|
||||||
/**
|
|
||||||
* Temporarily ignored until issue with native queries and pagination is resolved.
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public void shouldFindUsersInNativeQueryWithPagination() {}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -89,7 +89,7 @@ public class OpenJpaNamespaceUserRepositoryTests extends NamespaceUserRepository
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Temporarily ignored until issue with native queries and pagination is resolved.
|
* Temporarily ignored until openjpa works with hsqldb 2.x.
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void shouldFindUsersInNativeQueryWithPagination() {}
|
public void shouldFindUsersInNativeQueryWithPagination() {}
|
||||||
|
|||||||
Reference in New Issue
Block a user