cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aadamc...@apache.org
Subject svn commit: r562970 - in /cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src: main/java/org/apache/cayenne/access/jdbc/ test/java/org/apache/cayenne/access/
Date Sun, 05 Aug 2007 21:38:43 GMT
Author: aadamchik
Date: Sun Aug  5 14:38:42 2007
New Revision: 562970

URL: http://svn.apache.org/viewvc?view=rev&rev=562970
Log:
CAY-842 EJBQL Collections condition support
(MEMBER OF)

Modified:
    cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/access/jdbc/EJBQLConditionTranslator.java
    cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/access/jdbc/EJBQLPathTranslator.java
    cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/test/java/org/apache/cayenne/access/DataContextEJBQLConditionsTest.java

Modified: cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/access/jdbc/EJBQLConditionTranslator.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/access/jdbc/EJBQLConditionTranslator.java?view=diff&rev=562970&r1=562969&r2=562970
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/access/jdbc/EJBQLConditionTranslator.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/access/jdbc/EJBQLConditionTranslator.java
Sun Aug  5 14:38:42 2007
@@ -104,6 +104,32 @@
         return false;
     }
 
+    public boolean visitMemberOf(EJBQLExpression expression) {
+        // handle as "? =|<> path" (an alt. way would've been a correlated subquery
+        // on the target entity)...
+
+        if (expression.isNegated()) {
+            context.switchToMarker(EJBQLSelectTranslator.makeDistinctMarker(), true);
+            context.append(" DISTINCT");
+            context.switchToMainBuffer();
+
+            visitNotEquals(expression, -1);
+            for (int i = 0; i < expression.getChildrenCount(); i++) {
+                expression.getChild(i).visit(this);
+                visitNotEquals(expression, i);
+            }
+        }
+        else {
+            visitEquals(expression, -1);
+            for (int i = 0; i < expression.getChildrenCount(); i++) {
+                expression.getChild(i).visit(this);
+                visitEquals(expression, i);
+            }
+        }
+
+        return false;
+    }
+
     public boolean visitAll(EJBQLExpression expression) {
         context.append(" ALL");
         return true;

Modified: cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/access/jdbc/EJBQLPathTranslator.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/access/jdbc/EJBQLPathTranslator.java?view=diff&rev=562970&r1=562969&r2=562970
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/access/jdbc/EJBQLPathTranslator.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/access/jdbc/EJBQLPathTranslator.java
Sun Aug  5 14:38:42 2007
@@ -32,6 +32,7 @@
 import org.apache.cayenne.ejbql.parser.EJBQLJoin;
 import org.apache.cayenne.ejbql.parser.EJBQLOuterJoin;
 import org.apache.cayenne.ejbql.parser.EJBQLPath;
+import org.apache.cayenne.map.DbAttribute;
 import org.apache.cayenne.map.DbEntity;
 import org.apache.cayenne.map.DbJoin;
 import org.apache.cayenne.map.DbRelationship;
@@ -234,19 +235,19 @@
                     idPath,
                     table.getFullyQualifiedName());
 
-            List joins = dbRelationship.getJoins();
+            List pks = table.getPrimaryKey();
 
-            if (joins.size() == 1) {
-                DbJoin join = (DbJoin) joins.get(0);
+            if (pks.size() == 1) {
+                DbAttribute pk = (DbAttribute) pks.get(0);
                 context
                         .append(' ')
                         .append(alias)
                         .append('.')
-                        .append(join.getTargetName());
+                        .append(pk.getName());
             }
             else {
                 throw new EJBQLException(
-                        "Multi-column to-many matches are not yet supported.");
+                        "Multi-column PK to-many matches are not yet supported.");
             }
         }
         else {

Modified: cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/test/java/org/apache/cayenne/access/DataContextEJBQLConditionsTest.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/test/java/org/apache/cayenne/access/DataContextEJBQLConditionsTest.java?view=diff&rev=562970&r1=562969&r2=562970
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/test/java/org/apache/cayenne/access/DataContextEJBQLConditionsTest.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/test/java/org/apache/cayenne/access/DataContextEJBQLConditionsTest.java
Sun Aug  5 14:38:42 2007
@@ -23,7 +23,9 @@
 import java.util.List;
 import java.util.Set;
 
+import org.apache.art.Painting;
 import org.apache.cayenne.DataObjectUtils;
+import org.apache.cayenne.ObjectContext;
 import org.apache.cayenne.Persistent;
 import org.apache.cayenne.query.EJBQLQuery;
 import org.apache.cayenne.unit.CayenneCase;
@@ -231,4 +233,76 @@
         assertTrue(ids.contains(new Integer(33001)));
         assertTrue(ids.contains(new Integer(33002)));
     }
+
+    public void testCollectionMemberOfParameter() throws Exception {
+        createTestData("prepareCollection");
+
+        String ejbql = "SELECT a FROM Artist a " + "WHERE :x MEMBER OF a.paintingArray";
+
+        ObjectContext context = createDataContext();
+
+        EJBQLQuery query = new EJBQLQuery(ejbql);
+        query.setParameter("x", DataObjectUtils.objectForPK(
+                context,
+                Painting.class,
+                33010));
+        List objects = context.performQuery(query);
+        assertEquals(1, objects.size());
+
+        Set ids = new HashSet();
+        Iterator it = objects.iterator();
+        while (it.hasNext()) {
+            Object id = DataObjectUtils.pkForObject((Persistent) it.next());
+            ids.add(id);
+        }
+
+        assertTrue(ids.contains(new Integer(33001)));
+    }
+    
+//    public void testCollectionNotMemberOfParameter() throws Exception {
+//        createTestData("prepareCollection");
+//
+//        String ejbql = "SELECT a FROM Artist a " + "WHERE :x NOT MEMBER a.paintingArray";
+//
+//        ObjectContext context = createDataContext();
+//
+//        EJBQLQuery query = new EJBQLQuery(ejbql);
+//        query.setParameter("x", DataObjectUtils.objectForPK(
+//                context,
+//                Painting.class,
+//                33010));
+//        List objects = context.performQuery(query);
+//        assertEquals(2, objects.size());
+//
+//        Set ids = new HashSet();
+//        Iterator it = objects.iterator();
+//        while (it.hasNext()) {
+//            Object id = DataObjectUtils.pkForObject((Persistent) it.next());
+//            ids.add(id);
+//        }
+//        
+//        assertTrue(ids.contains(new Integer(33002)));
+//        assertTrue(ids.contains(new Integer(33003)));
+//    }
+
+//    public void testCollectionMemberOfThetaJoin() throws Exception {
+//        createTestData("prepareCollection");
+//
+//        String ejbql = "SELECT p FROM Painting p, Artist a "
+//                + "WHERE p MEMBER OF a.paintingArray AND a.artistName = 'B'";
+//
+//        EJBQLQuery query = new EJBQLQuery(ejbql);
+//        List objects = createDataContext().performQuery(query);
+//        assertEquals(2, objects.size());
+//
+//        Set ids = new HashSet();
+//        Iterator it = objects.iterator();
+//        while (it.hasNext()) {
+//            Object id = DataObjectUtils.pkForObject((Persistent) it.next());
+//            ids.add(id);
+//        }
+//
+//        assertTrue(ids.contains(new Integer(33009)));
+//        assertTrue(ids.contains(new Integer(33010)));
+//    }
 }



Mime
View raw message