cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aadamc...@apache.org
Subject svn commit: r667165 - in /cayenne/main/trunk: docs/doc/src/main/resources/ framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/trans/ framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/
Date Thu, 12 Jun 2008 17:11:34 GMT
Author: aadamchik
Date: Thu Jun 12 10:11:34 2008
New Revision: 667165

URL: http://svn.apache.org/viewvc?rev=667165&view=rev
Log:
CAY-1074 Derby: Wrong SQL Generated for select items -- DESC follows column name

Modified:
    cayenne/main/trunk/docs/doc/src/main/resources/RELEASE-NOTES.txt
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/trans/OrderingTranslator.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/DataContextOrderingTest.java

Modified: cayenne/main/trunk/docs/doc/src/main/resources/RELEASE-NOTES.txt
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/docs/doc/src/main/resources/RELEASE-NOTES.txt?rev=667165&r1=667164&r2=667165&view=diff
==============================================================================
--- cayenne/main/trunk/docs/doc/src/main/resources/RELEASE-NOTES.txt (original)
+++ cayenne/main/trunk/docs/doc/src/main/resources/RELEASE-NOTES.txt Thu Jun 12 10:11:34 2008
@@ -28,6 +28,7 @@
 CAY-1063 Derby adapter is not able to remove NOT NULL relationship
 CAY-1072 EJBQLQuery non-serializable exception when run via ROP
 CAY-1073 Bug in Expression.toEJBQL with inExp/notInExp
+CAY-1074 Derby: Wrong SQL Generated for select items -- DESC follows column name
 
 ----------------------------------
 Release: 3.0M4

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/trans/OrderingTranslator.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/trans/OrderingTranslator.java?rev=667165&r1=667164&r2=667165&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/trans/OrderingTranslator.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/trans/OrderingTranslator.java
Thu Jun 12 10:11:34 2008
@@ -61,42 +61,54 @@
 
         Iterator<Ordering> it = ((SelectQuery) q).getOrderings().iterator();
 
-        while (it.hasNext()) {
-            Ordering ord = it.next();
+        Appendable mainBuffer = this.out;
 
-            if (ord.isCaseInsensitive()) {
-                out.append("UPPER(");
-            }
-
-            Expression exp = ord.getSortSpec();
-
-            if (exp.getType() == Expression.OBJ_PATH) {
-                appendObjPath(exp);
-            }
-            else if (exp.getType() == Expression.DB_PATH) {
-                appendDbPath(exp);
-            }
-            else {
-                throw new CayenneRuntimeException("Unsupported ordering expression: "
-                        + exp);
-            }
-
-            // Close UPPER() modifier
-            if (ord.isCaseInsensitive()) {
-                out.append(")");
-            }
-
-            orderByColumnList.add(out.toString());
-
-            // "ASC" is a noop, omit it from the query
-            if (!ord.isAscending()) {
-                out.append(" DESC");
-            }
-
-            if (it.hasNext()) {
-                out.append(", ");
+        try {
+            while (it.hasNext()) {
+                Ordering ord = it.next();
+
+                // reset buffer to collect SQL for the single column, that we'll be reusing

+                this.out = new StringBuilder();
+
+                if (ord.isCaseInsensitive()) {
+                    out.append("UPPER(");
+                }
+
+                Expression exp = ord.getSortSpec();
+
+                if (exp.getType() == Expression.OBJ_PATH) {
+                    appendObjPath(exp);
+                }
+                else if (exp.getType() == Expression.DB_PATH) {
+                    appendDbPath(exp);
+                }
+                else {
+                    throw new CayenneRuntimeException("Unsupported ordering expression: "
+                            + exp);
+                }
+
+                // Close UPPER() modifier
+                if (ord.isCaseInsensitive()) {
+                    out.append(")");
+                }
+
+                String columnSQL = out.toString();
+                mainBuffer.append(columnSQL);
+                orderByColumnList.add(columnSQL);
+
+                // "ASC" is a noop, omit it from the query
+                if (!ord.isAscending()) {
+                    mainBuffer.append(" DESC");
+                }
+
+                if (it.hasNext()) {
+                    mainBuffer.append(", ");
+                }
             }
         }
+        finally {
+            this.out = mainBuffer;
+        }
     }
 
     /**

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/DataContextOrderingTest.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/DataContextOrderingTest.java?rev=667165&r1=667164&r2=667165&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/DataContextOrderingTest.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/DataContextOrderingTest.java
Thu Jun 12 10:11:34 2008
@@ -18,10 +18,13 @@
  ****************************************************************/
 package org.apache.cayenne.access;
 
+import java.math.BigDecimal;
 import java.util.Calendar;
 import java.util.List;
 
 import org.apache.art.Artist;
+import org.apache.art.Painting;
+import org.apache.cayenne.exp.ExpressionFactory;
 import org.apache.cayenne.query.Ordering;
 import org.apache.cayenne.query.SelectQuery;
 import org.apache.cayenne.unit.CayenneCase;
@@ -37,32 +40,76 @@
     public void testMultipleOrdering() throws Exception {
 
         Calendar c = Calendar.getInstance();
-        
+
         DataContext context = createDataContext();
         Artist a1 = context.newObject(Artist.class);
         a1.setArtistName("2");
         a1.setDateOfBirth(c.getTime());
-        
+
         c.add(Calendar.DAY_OF_MONTH, -1);
         Artist a2 = context.newObject(Artist.class);
         a2.setArtistName("3");
         a2.setDateOfBirth(c.getTime());
-        
+
         c.add(Calendar.DAY_OF_MONTH, -1);
         Artist a3 = context.newObject(Artist.class);
         a3.setArtistName("3");
         a3.setDateOfBirth(c.getTime());
-        
+
         context.commitChanges();
-        
+
         SelectQuery query = new SelectQuery(Artist.class);
         query.addOrdering(Artist.ARTIST_NAME_PROPERTY, Ordering.DESC);
         query.addOrdering(Artist.DATE_OF_BIRTH_PROPERTY, Ordering.DESC);
-        
+
         List<Artist> list = context.performQuery(query);
         assertEquals(3, list.size());
         assertSame(a2, list.get(0));
         assertSame(a3, list.get(1));
         assertSame(a1, list.get(2));
     }
+
+    public void testMultipleOrderingInSelectClauseCAY_1074() throws Exception {
+
+        Calendar c = Calendar.getInstance();
+
+        DataContext context = createDataContext();
+        Artist a1 = context.newObject(Artist.class);
+        a1.setArtistName("2");
+        a1.setDateOfBirth(c.getTime());
+
+        c.add(Calendar.DAY_OF_MONTH, -1);
+        Artist a2 = context.newObject(Artist.class);
+        a2.setArtistName("3");
+        a2.setDateOfBirth(c.getTime());
+
+        c.add(Calendar.DAY_OF_MONTH, -1);
+        Artist a3 = context.newObject(Artist.class);
+        a3.setArtistName("3");
+        a3.setDateOfBirth(c.getTime());
+
+        Painting p1 = context.newObject(Painting.class);
+        p1.setEstimatedPrice(new BigDecimal(1));
+        p1.setPaintingTitle("Y");
+        a1.addToPaintingArray(p1);
+
+        Painting p2 = context.newObject(Painting.class);
+        p2.setEstimatedPrice(new BigDecimal(2));
+        p2.setPaintingTitle("X");
+        a2.addToPaintingArray(p2);
+
+        context.commitChanges();
+
+        SelectQuery query1 = new SelectQuery(Artist.class);
+
+        // per CAY-1074, adding a to-many join to expression messes up the ordering
+        query1.andQualifier(ExpressionFactory.noMatchExp(
+                Artist.PAINTING_ARRAY_PROPERTY,
+                null));
+        query1.addOrdering(Artist.ARTIST_NAME_PROPERTY, Ordering.DESC);
+        query1.addOrdering(Artist.DATE_OF_BIRTH_PROPERTY, Ordering.DESC);
+
+        List<Artist> list1 = context.performQuery(query1);
+        assertEquals(2, list1.size());
+    }
 }



Mime
View raw message