openjpa-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ppod...@apache.org
Subject svn commit: r765085 - in /openjpa/trunk: openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/TestCriteria.java openjpa-persistence/src/main/java/org/apache/openjpa/persistence/query/LogicalPredicate.java
Date Wed, 15 Apr 2009 08:34:46 GMT
Author: ppoddar
Date: Wed Apr 15 08:34:45 2009
New Revision: 765085

URL: http://svn.apache.org/viewvc?rev=765085&view=rev
Log:
OPENJPA-1039: treat AND OR operators as non-associative

Modified:
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/TestCriteria.java
    openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/query/LogicalPredicate.java

Modified: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/TestCriteria.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/TestCriteria.java?rev=765085&r1=765084&r2=765085&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/TestCriteria.java
(original)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/TestCriteria.java
Wed Apr 15 08:34:45 2009
@@ -28,6 +28,7 @@
 import org.apache.openjpa.persistence.query.DomainObject;
 import org.apache.openjpa.persistence.query.Expression;
 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.QueryDefinition;
 import org.apache.openjpa.persistence.query.SelectItem;
@@ -90,6 +91,25 @@
 		// 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() {
 		DomainObject o1 = qb.createQueryDefinition(Order.class);
 		DomainObject o2 = o1.addRoot(Order.class);

Modified: openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/query/LogicalPredicate.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/query/LogicalPredicate.java?rev=765085&r1=765084&r2=765085&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/query/LogicalPredicate.java
(original)
+++ openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/query/LogicalPredicate.java
Wed Apr 15 08:34:45 2009
@@ -52,7 +52,7 @@
 	}
 
 	public String asExpression(AliasContext ctx) {
-		return ((Visitable)_p1).asExpression(ctx) + " " + _op + " " 
-		     + ((Visitable)_p2).asExpression(ctx);
+		return OPEN_BRACE + ((Visitable)_p1).asExpression(ctx) + SPACE + _op + 
+			   SPACE + ((Visitable)_p2).asExpression(ctx) + CLOSE_BRACE;
 	}
 }



Mime
View raw message