You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cayenne.apache.org by nt...@apache.org on 2017/01/19 07:45:50 UTC

cayenne git commit: CAY-2137 When generating SQL from EJBQL, use "AND" to separate multiple join conditions

Repository: cayenne
Updated Branches:
  refs/heads/master ed0604a2c -> 666c96de1


CAY-2137
When generating SQL from EJBQL, use "AND" to separate multiple join conditions


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

Branch: refs/heads/master
Commit: 666c96de112d07a688aa10cf5fa7d285ebc9db26
Parents: ed0604a
Author: Nikita Timofeev <st...@gmail.com>
Authored: Thu Jan 19 10:45:07 2017 +0300
Committer: Nikita Timofeev <st...@gmail.com>
Committed: Thu Jan 19 10:45:07 2017 +0300

----------------------------------------------------------------------
 .../translator/ejbql/EJBQLJoinAppender.java     |  2 +-
 .../cayenne/query/QueryWithCompoundJoinIT.java  | 97 ++++++++++++++++++++
 docs/doc/src/main/resources/RELEASE-NOTES.txt   |  1 +
 3 files changed, 99 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cayenne/blob/666c96de/cayenne-server/src/main/java/org/apache/cayenne/access/translator/ejbql/EJBQLJoinAppender.java
----------------------------------------------------------------------
diff --git a/cayenne-server/src/main/java/org/apache/cayenne/access/translator/ejbql/EJBQLJoinAppender.java b/cayenne-server/src/main/java/org/apache/cayenne/access/translator/ejbql/EJBQLJoinAppender.java
index b09aac9..c98a1ce 100644
--- a/cayenne-server/src/main/java/org/apache/cayenne/access/translator/ejbql/EJBQLJoinAppender.java
+++ b/cayenne-server/src/main/java/org/apache/cayenne/access/translator/ejbql/EJBQLJoinAppender.java
@@ -213,7 +213,7 @@ public class EJBQLJoinAppender {
         }
 
         while (it.hasNext()) {
-            context.append(", ");
+            context.append(" AND ");
             DbJoin dbJoin = it.next();
             context
                     .append(sourceAlias)

http://git-wip-us.apache.org/repos/asf/cayenne/blob/666c96de/cayenne-server/src/test/java/org/apache/cayenne/query/QueryWithCompoundJoinIT.java
----------------------------------------------------------------------
diff --git a/cayenne-server/src/test/java/org/apache/cayenne/query/QueryWithCompoundJoinIT.java b/cayenne-server/src/test/java/org/apache/cayenne/query/QueryWithCompoundJoinIT.java
new file mode 100644
index 0000000..8758318
--- /dev/null
+++ b/cayenne-server/src/test/java/org/apache/cayenne/query/QueryWithCompoundJoinIT.java
@@ -0,0 +1,97 @@
+/*****************************************************************
+ *   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 java.util.List;
+
+import org.apache.cayenne.access.DataContext;
+import org.apache.cayenne.configuration.server.ServerRuntime;
+import org.apache.cayenne.di.Inject;
+import org.apache.cayenne.test.jdbc.DBHelper;
+import org.apache.cayenne.test.jdbc.TableHelper;
+import org.apache.cayenne.testdo.compound.CompoundFkTestEntity;
+import org.apache.cayenne.testdo.compound.CompoundPkTestEntity;
+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;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+/**
+ * Test join on compound primary key
+ * @see <a href="https://issues.apache.org/jira/browse/CAY-2137">CAY-2137</a>
+ * @since 4.0
+ */
+@UseServerRuntime(CayenneProjects.COMPOUND_PROJECT)
+public class QueryWithCompoundJoinIT extends ServerCase {
+
+    @Inject
+    private DataContext context;
+
+    @Inject
+    private ServerRuntime runtime;
+
+    @Inject
+    private DBHelper dbHelper;
+
+    private TableHelper tCompoundPk;
+    private TableHelper tCompoundFk;
+
+    @Before
+    public void setUp() throws Exception {
+        tCompoundPk = new TableHelper(dbHelper, "COMPOUND_PK_TEST");
+        tCompoundPk.setColumns("KEY1", "KEY2", "NAME");
+
+        tCompoundFk = new TableHelper(dbHelper, "COMPOUND_FK_TEST");
+        tCompoundFk.setColumns("F_KEY1", "F_KEY2", "NAME", "PKEY");
+
+        createDataSet();
+    }
+
+    private void createDataSet() throws Exception {
+        tCompoundPk.insert("a", "b", "abc");
+        tCompoundPk.insert("c", "d", "cde");
+
+        tCompoundFk.insert("a", "b", "test", 1);
+        tCompoundFk.insert("c", "d", "nottest", 2);
+    }
+
+    @Test
+    public void testEJBQLCompoundJoin() throws Exception {
+        EJBQLQuery query = new EJBQLQuery(
+                "select f from CompoundFkTestEntity f inner join f.toCompoundPk p where p.name like 'a%'");
+        List res = context.performQuery(query);
+        assertEquals(1, res.size());
+        assertTrue(res.get(0) instanceof CompoundFkTestEntity);
+        assertEquals("test", ((CompoundFkTestEntity)res.get(0)).getName());
+    }
+
+    @Test
+    public void testObjectSelectCompoundJoin() throws Exception {
+        List<CompoundFkTestEntity> res = ObjectSelect.query(CompoundFkTestEntity.class)
+                .where(CompoundFkTestEntity.TO_COMPOUND_PK.dot(CompoundPkTestEntity.NAME).like("a%"))
+                .select(context);
+        assertEquals(1, res.size());
+        assertEquals("test", res.get(0).getName());
+    }
+}

http://git-wip-us.apache.org/repos/asf/cayenne/blob/666c96de/docs/doc/src/main/resources/RELEASE-NOTES.txt
----------------------------------------------------------------------
diff --git a/docs/doc/src/main/resources/RELEASE-NOTES.txt b/docs/doc/src/main/resources/RELEASE-NOTES.txt
index f673f32..713c286 100644
--- a/docs/doc/src/main/resources/RELEASE-NOTES.txt
+++ b/docs/doc/src/main/resources/RELEASE-NOTES.txt
@@ -28,6 +28,7 @@ CAY-2197 Update sqlite version and enable in-memory default config
 
 Bug Fixes:
 
+CAY-2137 When generating SQL from EJBQL, use "AND" to separate multiple join conditions
 CAY-2174 Change FK attribute name cause ObjAttribute appear after Reverse Engineering
 CAY-2175 AliasName used in EJBQLQuery is not working if it contains mixed case