cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aadamc...@apache.org
Subject svn commit: r721113 - in /cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src: main/java/org/apache/cayenne/access/ main/java/org/apache/cayenne/access/trans/ main/java/org/apache/cayenne/dba/frontbase/ main/java/org/apache/cayenne/dba/hsqldb/ ...
Date Thu, 27 Nov 2008 08:22:47 GMT
Author: aadamchik
Date: Thu Nov 27 00:22:46 2008
New Revision: 721113

URL: http://svn.apache.org/viewvc?rev=721113&view=rev
Log:
refactoring to cache query metadata in the translator

Modified:
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/DataDomainLegacyQueryAction.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/trans/DeleteTranslator.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/trans/QueryAssembler.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/trans/SelectTranslator.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/trans/UpdateTranslator.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/frontbase/FrontBaseSelectTranslator.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/hsqldb/HSQLSelectTranslator.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/mysql/MySQLSelectTranslator.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/openbase/OpenBaseSelectTranslator.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/oracle/OracleSelectTranslator.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/postgres/PostgresSelectTranslator.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/trans/OrderingTranslatorTest.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/trans/QualifierTranslatorTest.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/trans/TstQueryAssembler.java

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/DataDomainLegacyQueryAction.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/DataDomainLegacyQueryAction.java?rev=721113&r1=721112&r2=721113&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/DataDomainLegacyQueryAction.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/DataDomainLegacyQueryAction.java
Thu Nov 27 00:22:46 2008
@@ -22,7 +22,6 @@
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.HashMap;
-import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
 

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/trans/DeleteTranslator.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/trans/DeleteTranslator.java?rev=721113&r1=721112&r2=721113&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/trans/DeleteTranslator.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/trans/DeleteTranslator.java
Thu Nov 27 00:22:46 2008
@@ -22,7 +22,6 @@
 import org.apache.cayenne.map.DbEntity;
 import org.apache.cayenne.map.DbRelationship;
 import org.apache.cayenne.map.JoinType;
-import org.apache.cayenne.map.ObjEntity;
 import org.apache.cayenne.query.DeleteQuery;
 
 /**
@@ -32,16 +31,6 @@
  * @deprecated since 3.0 since {@link DeleteQuery} is deprecated.
  */
 public class DeleteTranslator extends QueryAssembler {
-    
-    @Override
-    public DbEntity getRootDbEntity() {
-        return query.getMetaData(entityResolver).getDbEntity();
-    }
-    
-    @Override
-    public ObjEntity getRootEntity() {
-        return query.getMetaData(entityResolver).getObjEntity();
-    }
 
     @Override
     public void dbRelationshipAdded(

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/trans/QueryAssembler.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/trans/QueryAssembler.java?rev=721113&r1=721112&r2=721113&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/trans/QueryAssembler.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/trans/QueryAssembler.java
Thu Nov 27 00:22:46 2008
@@ -35,6 +35,7 @@
 import org.apache.cayenne.map.JoinType;
 import org.apache.cayenne.map.ObjEntity;
 import org.apache.cayenne.query.Query;
+import org.apache.cayenne.query.QueryMetadata;
 
 /**
  * Abstract superclass of Query translators.
@@ -42,6 +43,7 @@
 public abstract class QueryAssembler {
 
     protected Query query;
+    protected QueryMetadata queryMetadata;
     protected Connection connection;
     protected DbAdapter adapter;
     protected EntityResolver entityResolver;
@@ -89,8 +91,13 @@
         return query;
     }
 
+    public QueryMetadata getQueryMetadata() {
+        return queryMetadata;
+    }
+
     public void setQuery(Query query) {
         this.query = query;
+        refreshMetadata();
     }
 
     public void setConnection(Connection connection) {
@@ -103,11 +110,25 @@
 
     public void setEntityResolver(EntityResolver entityResolver) {
         this.entityResolver = entityResolver;
+        refreshMetadata();
+    }
+
+    private void refreshMetadata() {
+        if (query != null && entityResolver != null) {
+            queryMetadata = query.getMetaData(entityResolver);
+        }
+        else {
+            queryMetadata = null;
+        }
     }
 
-    public abstract ObjEntity getRootEntity();
+    public DbEntity getRootDbEntity() {
+        return queryMetadata.getDbEntity();
+    }
 
-    public abstract DbEntity getRootDbEntity();
+    public ObjEntity getRootEntity() {
+        return queryMetadata.getObjEntity();
+    }
 
     /**
      * A callback invoked by a child qualifier or ordering processor allowing query

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/trans/SelectTranslator.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/trans/SelectTranslator.java?rev=721113&r1=721112&r2=721113&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/trans/SelectTranslator.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/trans/SelectTranslator.java
Thu Nov 27 00:22:46 2008
@@ -88,16 +88,6 @@
      */
     boolean forcingDistinct;
 
-    @Override
-    public DbEntity getRootDbEntity() {
-        return query.getMetaData(entityResolver).getDbEntity();
-    }
-
-    @Override
-    public ObjEntity getRootEntity() {
-        return query.getMetaData(entityResolver).getObjEntity();
-    }
-
     protected JoinStack createJoinStack() {
         return new JoinStack();
     }
@@ -291,9 +281,7 @@
         // * GROUP BY
         // * joined prefetch PK
 
-        ClassDescriptor descriptor = query
-                .getMetaData(entityResolver)
-                .getClassDescriptor();
+        ClassDescriptor descriptor = queryMetadata.getClassDescriptor();
         ObjEntity oe = descriptor.getEntity();
 
         PropertyVisitor visitor = new PropertyVisitor() {

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/trans/UpdateTranslator.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/trans/UpdateTranslator.java?rev=721113&r1=721112&r2=721113&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/trans/UpdateTranslator.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/trans/UpdateTranslator.java
Thu Nov 27 00:22:46 2008
@@ -27,7 +27,6 @@
 import org.apache.cayenne.map.DbEntity;
 import org.apache.cayenne.map.DbRelationship;
 import org.apache.cayenne.map.JoinType;
-import org.apache.cayenne.map.ObjEntity;
 import org.apache.cayenne.query.UpdateQuery;
 
 /**
@@ -45,16 +44,6 @@
             String joinSplitAlias) {
         throw new UnsupportedOperationException("db relationships not supported");
     }
-    
-    @Override
-    public DbEntity getRootDbEntity() {
-        return query.getMetaData(entityResolver).getDbEntity();
-    }
-    
-    @Override
-    public ObjEntity getRootEntity() {
-        return query.getMetaData(entityResolver).getObjEntity();
-    }
 
     @Override
     public String getCurrentAlias() {

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/frontbase/FrontBaseSelectTranslator.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/frontbase/FrontBaseSelectTranslator.java?rev=721113&r1=721112&r2=721113&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/frontbase/FrontBaseSelectTranslator.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/frontbase/FrontBaseSelectTranslator.java
Thu Nov 27 00:22:46 2008
@@ -31,7 +31,7 @@
     @Override
     protected void appendLimitAndOffsetClauses(StringBuilder buffer) {
 
-        int limit = getQuery().getMetaData(getEntityResolver()).getFetchLimit();
+        int limit = queryMetadata.getFetchLimit();
         if (limit > 0 && buffer.length() > SELECT_PREFIX.length()) {
 
             if (SELECT_PREFIX.equals(buffer.substring(0, SELECT_PREFIX.length()))) {

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/hsqldb/HSQLSelectTranslator.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/hsqldb/HSQLSelectTranslator.java?rev=721113&r1=721112&r2=721113&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/hsqldb/HSQLSelectTranslator.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/hsqldb/HSQLSelectTranslator.java
Thu Nov 27 00:22:46 2008
@@ -29,9 +29,8 @@
 
     @Override
     protected void appendLimitAndOffsetClauses(StringBuilder buffer) {
-        QueryMetadata metadata = getQuery().getMetaData(getEntityResolver());
-        int offset = metadata.getFetchOffset();
-        int limit = metadata.getFetchLimit();
+        int offset = queryMetadata.getFetchOffset();
+        int limit = queryMetadata.getFetchLimit();
 
         if (offset > 0 || limit > 0) {
             buffer.append(" LIMIT ");

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/mysql/MySQLSelectTranslator.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/mysql/MySQLSelectTranslator.java?rev=721113&r1=721112&r2=721113&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/mysql/MySQLSelectTranslator.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/mysql/MySQLSelectTranslator.java
Thu Nov 27 00:22:46 2008
@@ -20,7 +20,6 @@
 package org.apache.cayenne.dba.mysql;
 
 import org.apache.cayenne.access.trans.SelectTranslator;
-import org.apache.cayenne.query.QueryMetadata;
 
 /**
  * @since 1.2
@@ -29,9 +28,8 @@
 
     @Override
     protected void appendLimitAndOffsetClauses(StringBuilder buffer) {
-        QueryMetadata metadata = getQuery().getMetaData(getEntityResolver());
-        int offset = metadata.getFetchOffset();
-        int limit = metadata.getFetchLimit();
+        int offset = queryMetadata.getFetchOffset();
+        int limit = queryMetadata.getFetchLimit();
 
         if (offset > 0 || limit > 0) {
             buffer.append(" LIMIT ");

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/openbase/OpenBaseSelectTranslator.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/openbase/OpenBaseSelectTranslator.java?rev=721113&r1=721112&r2=721113&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/openbase/OpenBaseSelectTranslator.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/openbase/OpenBaseSelectTranslator.java
Thu Nov 27 00:22:46 2008
@@ -34,7 +34,7 @@
 
     @Override
     protected void appendLimitAndOffsetClauses(StringBuilder buffer) {
-        int limit = getQuery().getMetaData(getEntityResolver()).getFetchLimit();
+        int limit = queryMetadata.getFetchLimit();
         if (limit > 0) {
             buffer.append(" RETURN RESULTS ").append(limit);
         }

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/oracle/OracleSelectTranslator.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/oracle/OracleSelectTranslator.java?rev=721113&r1=721112&r2=721113&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/oracle/OracleSelectTranslator.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/oracle/OracleSelectTranslator.java
Thu Nov 27 00:22:46 2008
@@ -33,9 +33,8 @@
 
     @Override
     protected void appendLimitAndOffsetClauses(StringBuilder buffer) {
-        QueryMetadata metadata = getQuery().getMetaData(getEntityResolver());
-        int offset = metadata.getFetchOffset();
-        int limit = metadata.getFetchLimit();
+        int offset = queryMetadata.getFetchOffset();
+        int limit = queryMetadata.getFetchLimit();
 
         if (limit > 0 || offset > 0) {
             int max = (limit <= 0) ? Integer.MAX_VALUE : limit + offset;

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/postgres/PostgresSelectTranslator.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/postgres/PostgresSelectTranslator.java?rev=721113&r1=721112&r2=721113&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/postgres/PostgresSelectTranslator.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/postgres/PostgresSelectTranslator.java
Thu Nov 27 00:22:46 2008
@@ -20,7 +20,6 @@
 package org.apache.cayenne.dba.postgres;
 
 import org.apache.cayenne.access.trans.SelectTranslator;
-import org.apache.cayenne.query.QueryMetadata;
 
 /**
  * @since 1.2
@@ -29,11 +28,10 @@
 
     @Override
     protected void appendLimitAndOffsetClauses(StringBuilder buffer) {
-        QueryMetadata metadata = getQuery().getMetaData(getEntityResolver());
 
         // limit results
-        int offset = metadata.getFetchOffset();
-        int limit = metadata.getFetchLimit();
+        int offset = queryMetadata.getFetchOffset();
+        int limit = queryMetadata.getFetchLimit();
 
         if (limit > 0) {
             buffer.append(" LIMIT ").append(limit);

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/trans/OrderingTranslatorTest.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/trans/OrderingTranslatorTest.java?rev=721113&r1=721112&r2=721113&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/trans/OrderingTranslatorTest.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/trans/OrderingTranslatorTest.java
Thu Nov 27 00:22:46 2008
@@ -27,26 +27,20 @@
 
 public class OrderingTranslatorTest extends CayenneCase {
 
-    protected TstQueryAssembler qa;
-    protected SelectQuery q;
-
-    @Override
-    protected void setUp() throws Exception {
-        qa = new TstQueryAssembler(getNode(), new SelectQuery());
-        q = (SelectQuery) qa.getQuery();
-    }
-
     /**
      * Tests ascending ordering on string attribute.
      */
     public void testDoTranslation1() throws Exception {
+        SelectQuery q = new SelectQuery(Artist.class);
+        q.addOrdering("artistName", Ordering.ASC);
+
+        TstQueryAssembler qa = new TstQueryAssembler(getNode(), q);
+
         try {
             TranslationCase tstCase = new TranslationCase(
                     "Artist",
                     null,
                     "ta.ARTIST_NAME");
-            q.setRoot(Artist.class);
-            q.addOrdering("artistName", Ordering.ASC);
 
             StringBuilder out = new StringBuilder();
             new OrderingTranslator(qa).appendPart(out);
@@ -63,13 +57,16 @@
      * Tests descending ordering on string attribute.
      */
     public void testDoTranslation2() throws Exception {
+        SelectQuery q = new SelectQuery(Artist.class);
+        q.addOrdering("artistName", Ordering.DESC);
+
+        TstQueryAssembler qa = new TstQueryAssembler(getNode(), q);
+
         try {
             TranslationCase tstCase = new TranslationCase(
                     "Artist",
                     null,
                     "ta.ARTIST_NAME DESC");
-            q.setRoot(Artist.class);
-            q.addOrdering("artistName", Ordering.DESC);
 
             StringBuilder out = new StringBuilder();
             new OrderingTranslator(qa).appendPart(out);
@@ -86,13 +83,17 @@
      * Tests ascending caese-insensitive ordering on string attribute.
      */
     public void testDoTranslation4() throws Exception {
+        SelectQuery q = new SelectQuery(Artist.class);
+        q.addOrdering("artistName", Ordering.ASC, true);
+
+        TstQueryAssembler qa = new TstQueryAssembler(getNode(), q);
+
         try {
             TranslationCase tstCase = new TranslationCase(
                     "Artist",
                     null,
                     "UPPER(ta.ARTIST_NAME)");
-            q.setRoot(Artist.class);
-            q.addOrdering("artistName", Ordering.ASC, true);
+
             StringBuilder out = new StringBuilder();
             new OrderingTranslator(qa).appendPart(out);
 
@@ -107,14 +108,18 @@
     }
 
     public void testDoTranslation5() throws Exception {
+        SelectQuery q = new SelectQuery(Artist.class);
+        q.addOrdering("artistName", Ordering.DESC, true);
+        q.addOrdering("paintingArray.estimatedPrice", Ordering.ASC);
+
+        TstQueryAssembler qa = new TstQueryAssembler(getNode(), q);
+
         try {
             TranslationCase tstCase = new TranslationCase(
                     "Artist",
                     null,
                     "UPPER(ta.ARTIST_NAME) DESC, ta.ESTIMATED_PRICE");
-            q.setRoot(Artist.class);
-            q.addOrdering("artistName", Ordering.DESC, true);
-            q.addOrdering("paintingArray.estimatedPrice", Ordering.ASC);
+
             StringBuilder out = new StringBuilder();
             new OrderingTranslator(qa).appendPart(out);
 
@@ -135,20 +140,24 @@
     }
 
     public void testDoTranslation6() throws Exception {
+        SelectQuery q = new SelectQuery(Artist.class);
+        q.addOrdering("artistName", Ordering.ASC, true);
+        q.addOrdering("paintingArray.estimatedPrice", Ordering.ASC, true);
+
+        TstQueryAssembler qa = new TstQueryAssembler(getNode(), q);
+
         try {
             TranslationCase tstCase = new TranslationCase(
                     "Artist",
                     null,
                     "UPPER(ta.ARTIST_NAME), UPPER(ta.ESTIMATED_PRICE)");
-            q.setRoot(Artist.class);
-            q.addOrdering("artistName", Ordering.ASC, true);
-            q.addOrdering("paintingArray.estimatedPrice", Ordering.ASC, true);
+
             StringBuilder out = new StringBuilder();
             new OrderingTranslator(qa).appendPart(out);
 
             assertTrue(out.length() > 0);
             String orderBySql = out.toString();
-            
+
             // Check there is at least one UPPER modifier
             int indexOfUpper = orderBySql.indexOf("UPPER(");
             assertTrue(indexOfUpper != -1);
@@ -164,14 +173,19 @@
     }
 
     public void testDoTranslation3() throws Exception {
+        SelectQuery q = new SelectQuery(Artist.class);
+
+        q.addOrdering("artistName", Ordering.DESC);
+        q.addOrdering("paintingArray.estimatedPrice", Ordering.ASC);
+
+        TstQueryAssembler qa = new TstQueryAssembler(getNode(), q);
+
         try {
             TranslationCase tstCase = new TranslationCase(
                     "Artist",
                     null,
                     "ta.ARTIST_NAME DESC, ta.ESTIMATED_PRICE");
-            q.setRoot(Artist.class);
-            q.addOrdering("artistName", Ordering.DESC);
-            q.addOrdering("paintingArray.estimatedPrice", Ordering.ASC);
+
             StringBuilder out = new StringBuilder();
             new OrderingTranslator(qa).appendPart(out);
 

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/trans/QualifierTranslatorTest.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/trans/QualifierTranslatorTest.java?rev=721113&r1=721112&r2=721113&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/trans/QualifierTranslatorTest.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/trans/QualifierTranslatorTest.java
Thu Nov 27 00:22:46 2008
@@ -31,22 +31,13 @@
 import org.apache.cayenne.exp.TstUnaryExpSuite;
 import org.apache.cayenne.map.ObjEntity;
 import org.apache.cayenne.query.MockQuery;
-import org.apache.cayenne.query.QualifiedQuery;
 import org.apache.cayenne.query.SelectQuery;
 import org.apache.cayenne.unit.CayenneCase;
 
 public class QualifierTranslatorTest extends CayenneCase {
 
-    protected TstQueryAssembler qa;
-
-    @Override
-    protected void setUp() throws java.lang.Exception {
-        qa = new TstQueryAssembler(getNode(), new SelectQuery());
-    }
-
     public void testNonQualifiedQuery() throws Exception {
-        qa.dispose();
-        qa = new TstQueryAssembler(getNode(), new MockQuery());
+        TstQueryAssembler qa = new TstQueryAssembler(getNode(), new MockQuery());
 
         try {
             new QualifierTranslator(qa).appendPart(new StringBuilder());
@@ -61,6 +52,8 @@
     }
 
     public void testNullQualifier() throws Exception {
+        TstQueryAssembler qa = new TstQueryAssembler(getNode(), new SelectQuery());
+
         StringBuilder out = new StringBuilder();
         try {
             new QualifierTranslator(qa).appendPart(out);
@@ -110,17 +103,21 @@
 
     private void doExpressionTest(TstExpressionSuite suite) throws Exception {
 
+        TstQueryAssembler qa = new TstQueryAssembler(getNode(), new MockQuery());
+
         try {
             TstExpressionCase[] cases = suite.cases();
 
             int len = cases.length;
             for (int i = 0; i < len; i++) {
                 try {
-                    QualifiedQuery q = (QualifiedQuery) qa.getQuery();
+
+                    ObjEntity entity = getObjEntity(cases[i].getRootEntity());
+                    assertNotNull(entity);
+                    SelectQuery q = new SelectQuery(entity);
                     q.setQualifier(cases[i].getCayenneExp());
-                    ObjEntity ent = getObjEntity(cases[i].getRootEntity());
-                    assertNotNull(ent);
-                    q.setRoot(ent);
+                    qa.setQuery(q);
+                    
                     StringBuilder out = new StringBuilder();
                     new QualifierTranslator(qa).appendPart(out);
                     cases[i].assertTranslatedWell(out.toString());

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/trans/TstQueryAssembler.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/trans/TstQueryAssembler.java?rev=721113&r1=721112&r2=721113&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/trans/TstQueryAssembler.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/trans/TstQueryAssembler.java
Thu Nov 27 00:22:46 2008
@@ -25,10 +25,8 @@
 
 import org.apache.cayenne.CayenneRuntimeException;
 import org.apache.cayenne.access.DataNode;
-import org.apache.cayenne.map.DbEntity;
 import org.apache.cayenne.map.DbRelationship;
 import org.apache.cayenne.map.JoinType;
-import org.apache.cayenne.map.ObjEntity;
 import org.apache.cayenne.query.Query;
 
 public class TstQueryAssembler extends QueryAssembler {
@@ -48,16 +46,6 @@
         super.setEntityResolver(node.getEntityResolver());
         super.setQuery(q);
     }
-    
-    @Override
-    public DbEntity getRootDbEntity() {
-        return query.getMetaData(entityResolver).getDbEntity();
-    }
-    
-    @Override
-    public ObjEntity getRootEntity() {
-        return query.getMetaData(entityResolver).getObjEntity();
-    }
 
     public void dispose() throws SQLException {
         connection.close();



Mime
View raw message