cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aadamc...@apache.org
Subject svn commit: r725004 - in /cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src: main/java/org/apache/cayenne/access/jdbc/ test/java/org/apache/cayenne/access/ test/java/org/apache/cayenne/unit/ test/resources/dml/
Date Wed, 10 Dec 2008 05:55:44 GMT
Author: aadamchik
Date: Tue Dec  9 21:55:44 2008
New Revision: 725004

URL: http://svn.apache.org/viewvc?rev=725004&view=rev
Log:
CAY-1144 EJBQL mixed GROUP BY clause is generated incorrectly

adding comma between GROUP BY components

Modified:
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/jdbc/EJBQLGroupByTranslator.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/DataContextEJBQLGroupByHavingTest.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/BasicCase.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/resources/dml/access.DataContextEJBQLGroupByHavingTest.xml

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/jdbc/EJBQLGroupByTranslator.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/jdbc/EJBQLGroupByTranslator.java?rev=725004&r1=725003&r2=725004&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/jdbc/EJBQLGroupByTranslator.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/jdbc/EJBQLGroupByTranslator.java
Tue Dec  9 21:55:44 2008
@@ -37,7 +37,12 @@
 
     @Override
     public boolean visitIdentifier(EJBQLExpression expression) {
-        expression.visit(context.getTranslatorFactory().getIdentifierColumnsTranslator(context));
+        if (itemCount++ > 0) {
+            context.append(',');
+        }
+        
+        expression.visit(context.getTranslatorFactory().getIdentifierColumnsTranslator(
+                context));
         return false;
     }
 

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/DataContextEJBQLGroupByHavingTest.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/DataContextEJBQLGroupByHavingTest.java?rev=725004&r1=725003&r2=725004&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/DataContextEJBQLGroupByHavingTest.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/DataContextEJBQLGroupByHavingTest.java
Tue Dec  9 21:55:44 2008
@@ -21,6 +21,7 @@
 import java.math.BigDecimal;
 import java.util.List;
 
+import org.apache.art.Artist;
 import org.apache.cayenne.query.EJBQLQuery;
 import org.apache.cayenne.unit.CayenneCase;
 
@@ -80,6 +81,26 @@
         assertEquals(new Long(2), row2[2]);
     }
 
+    public void testGroupByRelatedEntity() throws Exception {
+
+        createTestData("testGroupByRelatedEntity");
+
+        String ejbql = "SELECT COUNT(p), a, a.artistName "
+                + "FROM Painting p INNER JOIN p.toArtist a GROUP BY a, a.artistName "
+                + "ORDER BY a.artistName";
+        EJBQLQuery query = new EJBQLQuery(ejbql);
+
+        List data = createDataContext().performQuery(query);
+        assertEquals(2, data.size());
+
+        assertTrue(data.get(0) instanceof Object[]);
+        Object[] row0 = (Object[]) data.get(0);
+        assertEquals(3, row0.length);
+        assertEquals(new Long(1), row0[0]);
+        assertEquals("AA1", row0[2]);
+        assertTrue(row0[1] instanceof Artist);
+    }
+
     public void testGroupByIdVariable() throws Exception {
         createTestData("prepare");
 

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/BasicCase.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/BasicCase.java?rev=725004&r1=725003&r2=725004&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/BasicCase.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/BasicCase.java
Tue Dec  9 21:55:44 2008
@@ -32,7 +32,8 @@
 public abstract class BasicCase extends TestCase {
 
     public static void assertEquals(BigDecimal d1, Object d2, double delta) {
-        assertTrue(d2 instanceof BigDecimal);
+        assertNotNull(d2);
+        assertTrue("d2: " + d2.getClass().getName(), d2 instanceof BigDecimal);
         BigDecimal d3 = d1.subtract((BigDecimal) d2);
         assertTrue(Math.abs(d3.doubleValue()) < delta);
     }

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/resources/dml/access.DataContextEJBQLGroupByHavingTest.xml
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/resources/dml/access.DataContextEJBQLGroupByHavingTest.xml?rev=725004&r1=725003&r2=725004&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/resources/dml/access.DataContextEJBQLGroupByHavingTest.xml
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/resources/dml/access.DataContextEJBQLGroupByHavingTest.xml
Tue Dec  9 21:55:44 2008
@@ -40,6 +40,48 @@
 		INSERT INTO PAINTING (PAINTING_ID, PAINTING_TITLE, ESTIMATED_PRICE) VALUES (33005, 'PZ',
1)
 		</value></constructor-arg>
 	</bean>
+	
+	<bean id="A1" class="org.apache.cayenne.unit.util.UpdatingSQLTemplate">
+		<constructor-arg type="java.lang.Class"><value>org.apache.art.Artist</value></constructor-arg>
+		<constructor-arg><value>
+		insert into ARTIST (ARTIST_ID, ARTIST_NAME) values (33001, 'AA1')
+		</value></constructor-arg>
+	</bean>
+	
+	<bean id="A2" class="org.apache.cayenne.unit.util.UpdatingSQLTemplate">
+		<constructor-arg type="java.lang.Class"><value>org.apache.art.Artist</value></constructor-arg>
+		<constructor-arg><value>
+		insert into ARTIST (ARTIST_ID, ARTIST_NAME) values (33002, 'AA2')
+		</value></constructor-arg>
+	</bean>
+	
+	<bean id="A3" class="org.apache.cayenne.unit.util.UpdatingSQLTemplate">
+		<constructor-arg type="java.lang.Class"><value>org.apache.art.Artist</value></constructor-arg>
+		<constructor-arg><value>
+		insert into ARTIST (ARTIST_ID, ARTIST_NAME) values (33003, 'BB1')
+		</value></constructor-arg>
+	</bean>
+	
+	<bean id="A4" class="org.apache.cayenne.unit.util.UpdatingSQLTemplate">
+		<constructor-arg type="java.lang.Class"><value>org.apache.art.Artist</value></constructor-arg>
+		<constructor-arg><value>
+		insert into ARTIST (ARTIST_ID, ARTIST_NAME) values (33004, 'BB2')
+		</value></constructor-arg>
+	</bean>
+	
+	<bean id="P11" class="org.apache.cayenne.unit.util.UpdatingSQLTemplate">
+		<constructor-arg type="java.lang.Class"><value>org.apache.art.Painting</value></constructor-arg>
+		<constructor-arg><value>
+		INSERT INTO PAINTING (PAINTING_ID, PAINTING_TITLE, ARTIST_ID, ESTIMATED_PRICE) VALUES (33007,
'P1', 33001, 3000)
+		</value></constructor-arg>
+	</bean>
+	
+	<bean id="P12" class="org.apache.cayenne.unit.util.UpdatingSQLTemplate">
+		<constructor-arg type="java.lang.Class"><value>org.apache.art.Painting</value></constructor-arg>
+		<constructor-arg><value>
+		INSERT INTO PAINTING (PAINTING_ID, PAINTING_TITLE, ARTIST_ID, ESTIMATED_PRICE) VALUES (33008,
'P2', 33002, 5000)
+		</value></constructor-arg>
+	</bean>
 
 	<!-- ======================================= -->
 	<!-- Data Sets -->
@@ -56,4 +98,17 @@
 			</list>
 		</constructor-arg>
 	</bean>
+	
+	<bean id="testGroupByRelatedEntity" class="java.util.ArrayList">
+		<constructor-arg>
+			<list>
+				<ref bean="A1"/>
+				<ref bean="A2"/>
+				<ref bean="A3"/>
+				<ref bean="A4"/>
+				<ref bean="P11"/>
+				<ref bean="P12"/>
+			</list>
+		</constructor-arg>
+	</bean>
 </beans>
\ No newline at end of file



Mime
View raw message