cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aadamc...@apache.org
Subject [1/2] cayenne git commit: CAY-2037 EJBQL: COUNT(DISTINCT .. ) doesn't properly translate paths ending with relationship
Date Mon, 16 Nov 2015 19:42:33 GMT
Repository: cayenne
Updated Branches:
  refs/heads/master bdd8d903a -> 80de06e8f


CAY-2037 EJBQL: COUNT(DISTINCT .. ) doesn't properly translate paths ending with relationship

* unit tests; commented test fails


Project: http://git-wip-us.apache.org/repos/asf/cayenne/repo
Commit: http://git-wip-us.apache.org/repos/asf/cayenne/commit/e0caeacb
Tree: http://git-wip-us.apache.org/repos/asf/cayenne/tree/e0caeacb
Diff: http://git-wip-us.apache.org/repos/asf/cayenne/diff/e0caeacb

Branch: refs/heads/master
Commit: e0caeacb1db20ead138ff7bad08cc48b40417ee6
Parents: bdd8d90
Author: aadamchik <aadamchik@apache.org>
Authored: Mon Nov 9 10:34:14 2015 +0100
Committer: aadamchik <aadamchik@apache.org>
Committed: Mon Nov 16 14:37:25 2015 -0500

----------------------------------------------------------------------
 .../apache/cayenne/query/EJBQLQueryCountIT.java | 103 +++++++++++++++++++
 .../org/apache/cayenne/query/EJBQLQueryIT.java  |  26 ++---
 2 files changed, 116 insertions(+), 13 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cayenne/blob/e0caeacb/cayenne-server/src/test/java/org/apache/cayenne/query/EJBQLQueryCountIT.java
----------------------------------------------------------------------
diff --git a/cayenne-server/src/test/java/org/apache/cayenne/query/EJBQLQueryCountIT.java
b/cayenne-server/src/test/java/org/apache/cayenne/query/EJBQLQueryCountIT.java
new file mode 100644
index 0000000..9dd7ace
--- /dev/null
+++ b/cayenne-server/src/test/java/org/apache/cayenne/query/EJBQLQueryCountIT.java
@@ -0,0 +1,103 @@
+/*****************************************************************
+ *   Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ ****************************************************************/
+package org.apache.cayenne.query;
+
+import static org.junit.Assert.assertEquals;
+
+import java.util.Collections;
+
+import org.apache.cayenne.ObjectContext;
+import org.apache.cayenne.di.Inject;
+import org.apache.cayenne.test.jdbc.DBHelper;
+import org.apache.cayenne.test.jdbc.TableHelper;
+import org.apache.cayenne.unit.di.server.CayenneProjects;
+import org.apache.cayenne.unit.di.server.ServerCase;
+import org.apache.cayenne.unit.di.server.UseServerRuntime;
+import org.junit.Before;
+import org.junit.Test;
+
+@UseServerRuntime(CayenneProjects.TESTMAP_PROJECT)
+public class EJBQLQueryCountIT extends ServerCase {
+
+	@Inject
+	private ObjectContext context;
+
+	@Inject
+	protected DBHelper dbHelper;
+
+	protected TableHelper tArtist;
+	protected TableHelper tPainting;
+	protected TableHelper tGallery;
+
+	@Before
+	public void before() throws Exception {
+		tArtist = new TableHelper(dbHelper, "ARTIST");
+		tArtist.setColumns("ARTIST_ID", "ARTIST_NAME");
+
+		tPainting = new TableHelper(dbHelper, "PAINTING");
+		tPainting.setColumns("PAINTING_ID", "ARTIST_ID", "PAINTING_TITLE");
+	}
+
+	@Test
+	public void test_ToOne() throws Exception {
+		tArtist.insert(1, "A1");
+		tArtist.insert(2, "A2");
+		tArtist.insert(3, "A3");
+
+		tPainting.insert(1, 1, "P1");
+		tPainting.insert(2, 1, "P2");
+		tPainting.insert(4, 2, "P1");
+
+		EJBQLQuery query = new EJBQLQuery("SELECT COUNT(p.toArtist) FROM Painting p");
+
+		// this should be simply a count of painting/artist joins
+		assertEquals(Collections.singletonList(3l), context.performQuery(query));
+	}
+
+//	@Test
+//	public void test_DistinctToOne() throws Exception {
+//		tArtist.insert(1, "A1");
+//		tArtist.insert(2, "A2");
+//		tArtist.insert(3, "A3");
+//
+//		tPainting.insert(1, 1, "P1");
+//		tPainting.insert(2, 1, "P2");
+//		tPainting.insert(4, 2, "P1");
+//
+//		EJBQLQuery query = new EJBQLQuery("SELECT COUNT(DISTINCT p.toArtist) FROM Painting p");
+//		// this should be a count of artists that have paintings
+//		assertEquals(Collections.singletonList(2l), context.performQuery(query));
+//	}
+	
+	@Test
+	public void test_DistinctToOneAttribute() throws Exception {
+		tArtist.insert(1, "A1");
+		tArtist.insert(2, "A1");
+		tArtist.insert(3, "A1");
+
+		tPainting.insert(1, 1, "P1");
+		tPainting.insert(2, 1, "P2");
+		tPainting.insert(4, 2, "P1");
+
+		EJBQLQuery query = new EJBQLQuery("SELECT COUNT(DISTINCT p.toArtist.artistName) FROM Painting
p");
+		// this should be a count of artists that have paintings
+		assertEquals(Collections.singletonList(1l), context.performQuery(query));
+	}
+	
+}

http://git-wip-us.apache.org/repos/asf/cayenne/blob/e0caeacb/cayenne-server/src/test/java/org/apache/cayenne/query/EJBQLQueryIT.java
----------------------------------------------------------------------
diff --git a/cayenne-server/src/test/java/org/apache/cayenne/query/EJBQLQueryIT.java b/cayenne-server/src/test/java/org/apache/cayenne/query/EJBQLQueryIT.java
index 56b2054..45e156a 100644
--- a/cayenne-server/src/test/java/org/apache/cayenne/query/EJBQLQueryIT.java
+++ b/cayenne-server/src/test/java/org/apache/cayenne/query/EJBQLQueryIT.java
@@ -18,6 +18,19 @@
  ****************************************************************/
 package org.apache.cayenne.query;
 
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertSame;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+import java.io.PrintWriter;
+import java.io.StringWriter;
+import java.util.List;
+import java.util.Map;
+
 import org.apache.cayenne.DataRow;
 import org.apache.cayenne.access.DataContext;
 import org.apache.cayenne.configuration.server.ServerRuntime;
@@ -40,19 +53,6 @@ import org.apache.cayenne.util.XMLEncoder;
 import org.junit.Before;
 import org.junit.Test;
 
-import java.io.PrintWriter;
-import java.io.StringWriter;
-import java.util.List;
-import java.util.Map;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertSame;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
-
 @UseServerRuntime(CayenneProjects.TESTMAP_PROJECT)
 public class EJBQLQueryIT extends ServerCase {
 


Mime
View raw message