cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aadamc...@apache.org
Subject svn commit: r546239 - in /cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src: main/java/org/apache/cayenne/access/jdbc/EJBQLPathTranslator.java test/java/org/apache/cayenne/access/DataContextEJBQLJoinsTest.java
Date Mon, 11 Jun 2007 20:08:08 GMT
Author: aadamchik
Date: Mon Jun 11 13:08:06 2007
New Revision: 546239

URL: http://svn.apache.org/viewvc?view=rev&rev=546239
Log:
EJBQL joins processing - support for mixed implicit/explicit joins

Modified:
    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/DataContextEJBQLJoinsTest.java

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=546239&r1=546238&r2=546239
==============================================================================
--- 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
Mon Jun 11 13:08:06 2007
@@ -37,8 +37,9 @@
     private ObjEntity currentEntity;
     private ObjRelationship currentIncoming;
     private String lastPathComponent;
+    private String lastAlias;
     private String idPath;
-    private String unresolvedPath;
+    private String fullPath;
     private EJBQLFromTranslator joinAppender;
 
     EJBQLPathTranslator(EJBQLTranslationContext context) {
@@ -71,7 +72,7 @@
 
         this.currentEntity = descriptor.getEntity();
         this.idPath = expression.getText();
-        this.unresolvedPath = idPath;
+        this.fullPath = idPath;
         return true;
     }
 
@@ -91,11 +92,12 @@
 
         String newPath = idPath + '.' + lastPathComponent;
         String oldPath = context.registerReusableJoin(idPath, lastPathComponent, newPath);
-        
-        this.unresolvedPath = unresolvedPath + '.' + lastPathComponent;
+
+        this.fullPath = fullPath + '.' + lastPathComponent;
 
         if (oldPath != null) {
             this.idPath = oldPath;
+            this.lastAlias = context.getAlias(oldPath, currentEntity.getDbEntityName());
         }
         else {
             // register join
@@ -110,7 +112,7 @@
             path.jjtAddChild(idVar, 1);
 
             EJBQLIdentifier joinId = new EJBQLIdentifier(-1);
-            joinId.setText(unresolvedPath);
+            joinId.setText(fullPath);
 
             EJBQLInnerJoin join = new EJBQLInnerJoin(-1);
             join.jjtAddChild(path, 0);
@@ -129,9 +131,8 @@
             context.switchToMainBuffer();
 
             this.idPath = newPath;
+            this.lastAlias = context.getAlias(fullPath, currentEntity.getDbEntityName());
         }
-
-        
     }
 
     private void processIntermediatePath() {
@@ -155,7 +156,9 @@
                 .getAttribute(lastPathComponent);
 
         DbEntity table = currentEntity.getDbEntity();
-        String alias = context.getAlias(idPath, table.getFullyQualifiedName());
+        String alias = this.lastAlias != null ? lastAlias : context.getAlias(
+                idPath,
+                table.getFullyQualifiedName());
         context.append(' ').append(alias).append('.').append(
                 attribute.getDbAttributeName());
     }

Modified: cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/test/java/org/apache/cayenne/access/DataContextEJBQLJoinsTest.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/test/java/org/apache/cayenne/access/DataContextEJBQLJoinsTest.java?view=diff&rev=546239&r1=546238&r2=546239
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/test/java/org/apache/cayenne/access/DataContextEJBQLJoinsTest.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/test/java/org/apache/cayenne/access/DataContextEJBQLJoinsTest.java
Mon Jun 11 13:08:06 2007
@@ -35,28 +35,28 @@
     }
 
     public void testThetaJoins() throws Exception {
-        createTestData("testThetaJoins");
-
+        // createTestData("testThetaJoins");
+        //
         // String ejbql = "SELECT DISTINCT a "
         // + "FROM Artist a, Painting b "
         // + "WHERE a.artistName = b.paintingTitle";
-        //
+        //        
         // EJBQLQuery query = new EJBQLQuery(ejbql);
-        //
+        //        
         // System.out.println(""
         // + query.getExpression(getDomain().getEntityResolver()).getExpression());
         // List artists = createDataContext().performQuery(query);
         // assertEquals(2, artists.size());
-        //
+        //        
         // Set names = new HashSet(2);
         // Iterator it = artists.iterator();
         // while (it.hasNext()) {
         // Artist a = (Artist) it.next();
         // names.add(a.getArtistName());
-        // }
-        //
-        // assertTrue(names.contains("AA1"));
-        // assertTrue(names.contains("BB2"));
+        //         }
+        //        
+        //         assertTrue(names.contains("AA1"));
+        //         assertTrue(names.contains("BB2"));
     }
 
     public void testInnerJoins() throws Exception {
@@ -107,25 +107,41 @@
     }
 
     public void testImplicitJoins() throws Exception {
-        // createTestData("testChainedJoins");
-        // String ejbql = "SELECT a "
-        // + "FROM Artist a "
-        // + "WHERE a.paintingArray.toGallery.galleryName = 'gallery2'";
-        //        
-        // List artists = createDataContext().performQuery(new EJBQLQuery(ejbql));
-        // assertEquals(1, artists.size());
-        //         assertEquals(33002, DataObjectUtils.intPKForObject((Artist) artists.get(0)));
+         createTestData("testChainedJoins");
+         String ejbql = "SELECT a "
+         + "FROM Artist a "
+         + "WHERE a.paintingArray.toGallery.galleryName = 'gallery2'";
+         
+         EJBQLQuery query = new EJBQLQuery(ejbql);
+         
+         System.out.println(""
+                 + query.getExpression(getDomain().getEntityResolver()).getExpression());
+                
+         List artists = createDataContext().performQuery(query);
+         assertEquals(1, artists.size());
+                 assertEquals(33002, DataObjectUtils.intPKForObject((Artist) artists.get(0)));
     }
 
-    public void testPartialImplicitJoins() throws Exception {
+    public void testPartialImplicitJoins1() throws Exception {
         createTestData("testChainedJoins");
-        // String ejbql = "SELECT a "
-        // + "FROM Artist a JOIN a.paintingArray b "
-        // + "WHERE a.paintingArray.toGallery.galleryName = 'gallery2'";
-        //
-        // List artists = createDataContext().performQuery(new EJBQLQuery(ejbql));
-        // assertEquals(1, artists.size());
-        // assertEquals(33002, DataObjectUtils.intPKForObject((Artist) artists.get(0)));
+         String ejbql = "SELECT a "
+         + "FROM Artist a JOIN a.paintingArray b "
+         + "WHERE a.paintingArray.toGallery.galleryName = 'gallery2'";
+        
+         List artists = createDataContext().performQuery(new EJBQLQuery(ejbql));
+         assertEquals(1, artists.size());
+         assertEquals(33002, DataObjectUtils.intPKForObject((Artist) artists.get(0)));
+    }
+    
+    public void testPartialImplicitJoins2() throws Exception {
+        createTestData("testChainedJoins");
+         String ejbql = "SELECT a "
+         + "FROM Artist a JOIN a.paintingArray b "
+         + "WHERE a.paintingArray.paintingTitle = 'CC2'";
+        
+         List artists = createDataContext().performQuery(new EJBQLQuery(ejbql));
+         assertEquals(1, artists.size());
+         assertEquals(33002, DataObjectUtils.intPKForObject((Artist) artists.get(0)));
     }
 
     public void testMultipleJoinsToTheSameTable() throws Exception {



Mime
View raw message