openjpa-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mik...@apache.org
Subject svn commit: r1003197 - in /openjpa/branches/1.3.x: openjpa-kernel/src/main/java/org/apache/openjpa/kernel/ExpressionStoreQuery.java openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/query/TestMultipleEntityProjection.java
Date Thu, 30 Sep 2010 18:27:41 GMT
Author: mikedd
Date: Thu Sep 30 18:27:41 2010
New Revision: 1003197

URL: http://svn.apache.org/viewvc?rev=1003197&view=rev
Log:
OPENJPA-1814: JPQL fails with Group By and Having aggregate_expression IN (subquery)

Modified:
    openjpa/branches/1.3.x/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/ExpressionStoreQuery.java
    openjpa/branches/1.3.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/query/TestMultipleEntityProjection.java

Modified: openjpa/branches/1.3.x/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/ExpressionStoreQuery.java
URL: http://svn.apache.org/viewvc/openjpa/branches/1.3.x/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/ExpressionStoreQuery.java?rev=1003197&r1=1003196&r2=1003197&view=diff
==============================================================================
--- openjpa/branches/1.3.x/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/ExpressionStoreQuery.java
(original)
+++ openjpa/branches/1.3.x/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/ExpressionStoreQuery.java
Thu Sep 30 18:27:41 2010
@@ -19,6 +19,8 @@
 package org.apache.openjpa.kernel;
 
 import java.io.Serializable;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.HashSet;
@@ -29,6 +31,7 @@ import java.util.Set;
 
 import org.apache.commons.collections.map.LinkedMap;
 import org.apache.openjpa.conf.OpenJPAConfiguration;
+import org.apache.openjpa.kernel.exps.Subquery;
 import org.apache.openjpa.kernel.exps.AbstractExpressionVisitor;
 import org.apache.openjpa.kernel.exps.AggregateListener;
 import org.apache.openjpa.kernel.exps.Constant;
@@ -436,8 +439,28 @@ public class ExpressionStoreQuery
                 for (int i = 0; i < exps.grouping.length; i++)
                     exps.grouping[i].acceptVisit(visitor);
                 visitor._grouping = false;
-                if (exps.having != null)
-                    exps.having.acceptVisit(visitor);
+                if (exps.having != null) {
+                    Class cls = exps.having.getClass();
+                    if (cls.getName().endsWith("Expression"))
+                        cls = cls.getSuperclass();
+                    Object value2 = null;
+                    Method getValue2 = null;
+                    try {
+                        getValue2 = cls.getMethod("getValue2");
+                        getValue2.setAccessible(true);
+                        value2 = getValue2.invoke(exps.having, (Object[]) null);
+                    } catch (NoSuchMethodException name) {
+                        // skip
+                    } catch (IllegalAccessException iae) {
+                        // skip
+                    } catch (InvocationTargetException ite) {
+                        // skip
+                    } 
+                    if (value2 != null && value2 instanceof Subquery)
+                        ;  // complex having with subquery, validation is performed by DBMS
+                    else
+                        exps.having.acceptVisit(visitor);
+                }
                 for (int i = 0; i < exps.projections.length; i++)
                     exps.projections[i].acceptVisit(visitor);
             }

Modified: openjpa/branches/1.3.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/query/TestMultipleEntityProjection.java
URL: http://svn.apache.org/viewvc/openjpa/branches/1.3.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/query/TestMultipleEntityProjection.java?rev=1003197&r1=1003196&r2=1003197&view=diff
==============================================================================
--- openjpa/branches/1.3.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/query/TestMultipleEntityProjection.java
(original)
+++ openjpa/branches/1.3.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/query/TestMultipleEntityProjection.java
Thu Sep 30 18:27:41 2010
@@ -164,6 +164,26 @@ public class TestMultipleEntityProjectio
 		query = em.createQuery(jpql);
 		result = query.getResultList();
 		assertTrue(result.isEmpty());
+
+//      The following JPQL results in syntax error,
+//      see comments in OPENJPA-1814              
+//		jpql = "select m.publisher, max(m.datePublished) " + 
+//		    "from Magazine m group by m.publisher " + 
+//		    "having max(m.tsPublished) IN " + 
+//		    "(select max(m.tsPublished) from Magazine m " +
+//		    "where m.datePublished = CURRENT_TIMESTAMP)";
+//		query = em.createQuery(jpql);
+//		result = query.getResultList();
+//		assertTrue(result.isEmpty());
+
+		jpql = "select m.publisher, max(m.datePublished) " + 
+		    "from Magazine m group by m.publisher " + 
+		    "having max(m.tsPublished) = " + 
+		    "(select max(m.tsPublished) from Magazine m " + 
+		    "where m.datePublished = CURRENT_TIMESTAMP)";
+		query = em.createQuery(jpql);
+		result = query.getResultList();
+		assertTrue(result.isEmpty());
 	}
 	
 	/**



Mime
View raw message