cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mgen...@apache.org
Subject svn commit: r820640 - in /cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/query: Ordering.java SortOrder.java
Date Thu, 01 Oct 2009 13:11:59 GMT
Author: mgentry
Date: Thu Oct  1 13:11:58 2009
New Revision: 820640

URL: http://svn.apache.org/viewvc?rev=820640&view=rev
Log:
Updates for CAY-1283 -- adding enums for Ordering.

Added:
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/query/SortOrder.java
Modified:
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/query/Ordering.java

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/query/Ordering.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/query/Ordering.java?rev=820640&r1=820639&r2=820640&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/query/Ordering.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/query/Ordering.java
Thu Oct  1 13:11:58 2009
@@ -39,24 +39,29 @@
  * as a specification for building <em>ORDER BY</em> clause of a SelectQuery
query. Note
  * that in case of in-memory sorting, Ordering can be used with any JavaBeans, not just
  * DataObjects.
- * 
  */
 public class Ordering implements Comparator<Object>, Serializable, XMLSerializable
{
-
     /**
      * Symbolic representation of ascending ordering criterion.
+     * 
+     * @deprecated Use SortOrder.ASCENDING instead.
      */
+    @Deprecated
     public static final boolean ASC = true;
 
     /**
      * Symbolic representation of descending ordering criterion.
+     * 
+     * @deprecated Use SortOrder.DESCENDING instead.
      */
+    @Deprecated
     public static final boolean DESC = false;
 
     protected String sortSpecString;
     protected transient Expression sortSpec;
-    protected boolean ascending;
-    protected boolean caseInsensitive;
+    protected SortOrder sortOrder;
+//    protected boolean ascending;
+//    protected boolean caseInsensitive;
     protected boolean pathExceptionSuppressed = false;
     protected boolean nullSortedFirst = true;
 
@@ -73,24 +78,40 @@
     public Ordering() {
     }
 
+    @Deprecated
     public Ordering(String sortPathSpec, boolean ascending) {
         this(sortPathSpec, ascending, false);
     }
 
+    /**
+     * @since 3.0
+     */
+    public Ordering(String sortPathSpec, SortOrder sortOrder) {
+        setSortSpecString(sortPathSpec);
+        setSortOrder(sortOrder);
+    }
+
+    @Deprecated
     public Ordering(String sortPathSpec, boolean ascending, boolean caseInsensitive) {
         setSortSpecString(sortPathSpec);
-        this.ascending = ascending;
-        this.caseInsensitive = caseInsensitive;
+        setAscending(ascending);
+        setCaseInsensitive(caseInsensitive);
+//        this.ascending = ascending;
+//        this.caseInsensitive = caseInsensitive;
     }
 
+    @Deprecated
     public Ordering(Expression sortExpression, boolean ascending) {
         this(sortExpression, ascending, false);
     }
 
+    @Deprecated
     public Ordering(Expression sortExpression, boolean ascending, boolean caseInsensitive)
{
         setSortSpec(sortExpression);
-        this.ascending = ascending;
-        this.caseInsensitive = caseInsensitive;
+        setAscending(ascending);
+        setCaseInsensitive(caseInsensitive);
+//        this.ascending = ascending;
+//        this.caseInsensitive = caseInsensitive;
     }
 
     /**
@@ -154,24 +175,119 @@
         return sortSpecString;
     }
 
+    /**
+     * Sets the sort order for this ordering.
+     * 
+     * @since 3.0
+     */
+    public void setSortOrder(SortOrder order) {
+        this.sortOrder = order;
+    }
+
     /** Returns true if sorting is done in ascending order. */
     public boolean isAscending() {
-        return ascending;
+        return sortOrder == null || sortOrder == SortOrder.ASCENDING || sortOrder == SortOrder.ASCENDING_INSENSITIVE;
     }
 
-    /** Sets <code>ascending</code> property of this Ordering. */
+    /**
+     * Returns true if the sorting is done in descending order.
+     * 
+     * @since 3.0
+     */
+    public boolean isDescending() {
+        return !isAscending();
+    }
+
+    /**
+     * Sets <code>ascending</code> property of this Ordering.
+     * 
+     * @deprecated Use setSortOrder() or setAscending() or setDescending().
+     */
+    @Deprecated
     public void setAscending(boolean ascending) {
-        this.ascending = ascending;
+        if (ascending)
+            setAscending();
+        else
+            setDescending();
+    }
+
+    /**
+     * If the sort order is DESCENDING or DESCENDING_INSENSITIVE, sets
+     * the sort order to ASCENDING or ASCENDING_INSENSITIVE, respectively.
+     * 
+     * @since 3.0
+     */
+    public void setAscending() {
+        if (sortOrder == null || sortOrder == SortOrder.DESCENDING)
+            setSortOrder(SortOrder.ASCENDING);
+        else if (sortOrder == SortOrder.DESCENDING_INSENSITIVE)
+            setSortOrder(SortOrder.ASCENDING_INSENSITIVE);
+    }
+
+    /**
+     * If the sort order is ASCENDING or ASCENDING_INSENSITIVE, sets
+     * the sort order to DESCENDING or DESCENDING_INSENSITIVE, respectively.
+     * 
+     * @since 3.0
+     */
+    public void setDescending() {
+        if (sortOrder == null || sortOrder == SortOrder.ASCENDING)
+            setSortOrder(SortOrder.DESCENDING);
+        else if (sortOrder == SortOrder.ASCENDING_INSENSITIVE)
+            setSortOrder(SortOrder.DESCENDING_INSENSITIVE);
     }
 
     /** Returns true if the sorting is case insensitive */
     public boolean isCaseInsensitive() {
-        return caseInsensitive;
+        return !isCaseSensitive();
     }
 
-    /** Sets <code>caseInsensitive</code> property of this Ordering. */
+    /**
+     * Returns true if the sorting is case sensitive.
+     * 
+     * @since 3.0
+     */
+    public boolean isCaseSensitive() {
+        return sortOrder == null || sortOrder == SortOrder.ASCENDING || sortOrder == SortOrder.DESCENDING;
+    }
+
+    /**
+     * Sets <code>caseInsensitive</code> property of this Ordering.
+     * 
+     * @deprecated Use setSortOrder() or setCaseInsensitive() or setCaseSensitive().
+     */
+    @Deprecated
     public void setCaseInsensitive(boolean caseInsensitive) {
-        this.caseInsensitive = caseInsensitive;
+        if (caseInsensitive)
+            setCaseInsensitive();
+        else
+            setCaseSensitive();
+    }
+
+    /**
+     * If the sort order is ASCENDING or DESCENDING, sets the sort order to
+     * ASCENDING_INSENSITIVE or DESCENDING_INSENSITIVE, respectively.
+     * 
+     * @since 3.0
+     */
+    public void setCaseInsensitive() {
+        if (sortOrder == null || sortOrder == SortOrder.ASCENDING)
+            setSortOrder(SortOrder.ASCENDING_INSENSITIVE);
+        else if (sortOrder == SortOrder.DESCENDING)
+            setSortOrder(SortOrder.DESCENDING_INSENSITIVE);
+    }
+
+    /**
+     * If the sort order is ASCENDING_INSENSITIVE or DESCENDING_INSENSITIVE,
+     * sets the sort order to ASCENDING or DESCENDING, respectively.
+     * 
+     * @since 3.0
+     */
+    public void setCaseSensitive() {
+        if (sortOrder == null || sortOrder == SortOrder.ASCENDING_INSENSITIVE)
+            setSortOrder(SortOrder.ASCENDING);
+        else if (sortOrder == SortOrder.DESCENDING_INSENSITIVE)
+            setSortOrder(SortOrder.DESCENDING);
     }
 
     /**
@@ -222,7 +338,7 @@
 			if (pathExceptionSuppressed && e.getCause() instanceof org.apache.cayenne.reflect.UnresolvablePathException)
{
 				//do nothing, we expect this 
 			} else {
-				//rethrow
+				//re-throw
 				throw e;
 			}
 		}
@@ -246,7 +362,7 @@
             return nullSortedFirst? 1:-1;
         }
 
-        if (this.caseInsensitive) {
+        if (isCaseInsensitive()) {
             // TODO: to upper case should probably be defined as a separate expression
             // type
             value1 = ConversionUtil.toUpperCase(value1);
@@ -255,7 +371,7 @@
 
         int compareResult = ConversionUtil.toComparable(value1).compareTo(
                 ConversionUtil.toComparable(value2));
-        return (ascending) ? compareResult : -compareResult;
+        return (isAscending()) ? compareResult : -compareResult;
     }
 
     /**
@@ -266,11 +382,11 @@
     public void encodeAsXML(XMLEncoder encoder) {
         encoder.print("<ordering");
 
-        if (!ascending) {
+        if (isDescending()) {
             encoder.print(" descending=\"true\"");
         }
 
-        if (caseInsensitive) {
+        if (isCaseInsensitive()) {
             encoder.print(" ignore-case=\"true\"");
         }
 

Added: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/query/SortOrder.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/query/SortOrder.java?rev=820640&view=auto
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/query/SortOrder.java
(added)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/query/SortOrder.java
Thu Oct  1 13:11:58 2009
@@ -0,0 +1,36 @@
+/*****************************************************************
+ *   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;
+
+/**
+ * Constants to order query results (the ORDER BY clause).
+ * 
+ * @since 3.0
+ */
+public enum SortOrder {
+    /**
+     * ASCENDING = Ascending order, case sensitive.<br/>
+     * ASCENDING_INSENSITIVE = Ascending order, case insensitive<br/>
+     * DESCENDING = Descending order, case sensitive.<br>
+     * DESCENDING_INSENSITIVE = Descending order, case insensitive.<br>
+     */
+    ASCENDING,  ASCENDING_INSENSITIVE,
+    DESCENDING, DESCENDING_INSENSITIVE
+}



Mime
View raw message