mirror of https://github.com/apache/openjpa.git
OPENJPA-1039: treat AND OR operators as non-associative
git-svn-id: https://svn.apache.org/repos/asf/openjpa/trunk@765085 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
affdc073d0
commit
21b41a50fe
|
@ -28,6 +28,7 @@ import org.apache.openjpa.persistence.OpenJPAEntityManagerFactory;
|
||||||
import org.apache.openjpa.persistence.query.DomainObject;
|
import org.apache.openjpa.persistence.query.DomainObject;
|
||||||
import org.apache.openjpa.persistence.query.Expression;
|
import org.apache.openjpa.persistence.query.Expression;
|
||||||
import org.apache.openjpa.persistence.query.OpenJPAQueryBuilder;
|
import org.apache.openjpa.persistence.query.OpenJPAQueryBuilder;
|
||||||
|
import org.apache.openjpa.persistence.query.Predicate;
|
||||||
import org.apache.openjpa.persistence.query.QueryBuilderImpl;
|
import org.apache.openjpa.persistence.query.QueryBuilderImpl;
|
||||||
import org.apache.openjpa.persistence.query.QueryDefinition;
|
import org.apache.openjpa.persistence.query.QueryDefinition;
|
||||||
import org.apache.openjpa.persistence.query.SelectItem;
|
import org.apache.openjpa.persistence.query.SelectItem;
|
||||||
|
@ -90,6 +91,25 @@ public class TestCriteria extends SingleEMFTestCase {
|
||||||
// do nothing as we may not have a database connection
|
// do nothing as we may not have a database connection
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void testLogicalPredicateAssociativity() {
|
||||||
|
DomainObject e = qb.createQueryDefinition(Employee.class);
|
||||||
|
Predicate p1 = e.get("salary").greaterThan(100);
|
||||||
|
Predicate p2 = e.get("rating").equal(5);
|
||||||
|
Predicate p3 = e.get("name").like("John");
|
||||||
|
Predicate w1 = p1.and(p2.or(p3));
|
||||||
|
Predicate w2 = (p1.and(p2)).or(p3);
|
||||||
|
QueryDefinition q1 = e.select(e).where(w1);
|
||||||
|
String jpql1 = qb.toJPQL(q1);
|
||||||
|
emf.createEntityManager().createDynamicQuery(q1).getResultList();
|
||||||
|
|
||||||
|
QueryDefinition q2 = e.select(e).where(w2);
|
||||||
|
String jpql2 = qb.toJPQL(q2);
|
||||||
|
System.err.println(jpql1);
|
||||||
|
System.err.println(jpql2);
|
||||||
|
assertNotEquals(jpql1, jpql2);
|
||||||
|
emf.createEntityManager().createDynamicQuery(q2).getResultList();
|
||||||
|
}
|
||||||
|
|
||||||
public void testMultipleDomainOfSameClass() {
|
public void testMultipleDomainOfSameClass() {
|
||||||
DomainObject o1 = qb.createQueryDefinition(Order.class);
|
DomainObject o1 = qb.createQueryDefinition(Order.class);
|
||||||
DomainObject o2 = o1.addRoot(Order.class);
|
DomainObject o2 = o1.addRoot(Order.class);
|
||||||
|
|
|
@ -52,7 +52,7 @@ public class LogicalPredicate extends AbstractVisitable
|
||||||
}
|
}
|
||||||
|
|
||||||
public String asExpression(AliasContext ctx) {
|
public String asExpression(AliasContext ctx) {
|
||||||
return ((Visitable)_p1).asExpression(ctx) + " " + _op + " "
|
return OPEN_BRACE + ((Visitable)_p1).asExpression(ctx) + SPACE + _op +
|
||||||
+ ((Visitable)_p2).asExpression(ctx);
|
SPACE + ((Visitable)_p2).asExpression(ctx) + CLOSE_BRACE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue