jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mdue...@apache.org
Subject svn commit: r1051949 - in /jackrabbit/trunk: jackrabbit-api/src/main/java/org/apache/jackrabbit/api/security/user/ jackrabbit-core/src/main/java/org/apache/jackrabbit/core/security/user/ jackrabbit-core/src/test/java/org/apache/jackrabbit/api/security/...
Date Wed, 22 Dec 2010 15:24:14 GMT
Author: mduerig
Date: Wed Dec 22 15:24:14 2010
New Revision: 1051949

URL: http://svn.apache.org/viewvc?rev=1051949&view=rev
Log:
JCR-2854: Add option to make sorting in user/group query case insensitive

Modified:
    jackrabbit/trunk/jackrabbit-api/src/main/java/org/apache/jackrabbit/api/security/user/QueryBuilder.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/security/user/XPathQueryBuilder.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/security/user/XPathQueryEvaluator.java
    jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/api/security/user/UserManagerSearchTest.java

Modified: jackrabbit/trunk/jackrabbit-api/src/main/java/org/apache/jackrabbit/api/security/user/QueryBuilder.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-api/src/main/java/org/apache/jackrabbit/api/security/user/QueryBuilder.java?rev=1051949&r1=1051948&r2=1051949&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-api/src/main/java/org/apache/jackrabbit/api/security/user/QueryBuilder.java
(original)
+++ jackrabbit/trunk/jackrabbit-api/src/main/java/org/apache/jackrabbit/api/security/user/QueryBuilder.java
Wed Dec 22 15:24:14 2010
@@ -73,8 +73,22 @@ public interface QueryBuilder<T> {
      *
      * @param propertyName  The name of the property to sort on
      * @param direction  Direction to sort. Either {@link Direction#ASCENDING} or {@link
Direction#DESCENDING}
+     * @param ignoreCase  Ignore character case in sort iff <code>true</code>.
Note: For <code>false</code>
+     * sorting is done lexicographically even for non string properties.
      */
-    void setSortOrder(String propertyName, Direction direction);
+    void setSortOrder(String propertyName, Direction direction, boolean ignoreCase);
+
+    /**
+     * Set the sort order of the {@link Authorizable}s returned by the query.
+     * The format of the <code>propertyName</code> is the same as in XPath:
+     * <code>@propertyName</code> sorts on a property of the current node.
+     * <code>relative/path/@propertyName</code> sorts on a property of a
+     * descendant node. Character case is taken into account for the sort order.
+     *
+     * @param propertyName  The name of the property to sort on
+     * @param direction  Direction to sort. Either {@link Direction#ASCENDING} or {@link
Direction#DESCENDING}
+     */
+    void setSortOrder(String propertyName, Direction direction); 
 
     /**
      * Set limits for the query. The limits consists of a bound and a maximal

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/security/user/XPathQueryBuilder.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/security/user/XPathQueryBuilder.java?rev=1051949&r1=1051948&r2=1051949&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/security/user/XPathQueryBuilder.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/security/user/XPathQueryBuilder.java
Wed Dec 22 15:24:14 2010
@@ -80,6 +80,7 @@ public class XPathQueryBuilder implement
     private Condition condition;
     private String sortProperty;
     private Direction sortDirection = Direction.ASCENDING;
+    private boolean sortIgnoreCase; 
     private Value bound;
     private long offset;
     private long maxCount = -1;
@@ -108,6 +109,10 @@ public class XPathQueryBuilder implement
         return sortDirection;
     }
 
+    boolean getSortIgnoreCase() {
+        return sortIgnoreCase;
+    }
+
     Value getBound() {
         return bound;
     }
@@ -135,9 +140,14 @@ public class XPathQueryBuilder implement
         this.condition = condition;
     }
 
-    public void setSortOrder(String propertyName, Direction direction) {
+    public void setSortOrder(String propertyName, Direction direction, boolean ignoreCase)
{
         sortProperty = propertyName;
         sortDirection = direction;
+        sortIgnoreCase = ignoreCase;
+    }
+
+    public void setSortOrder(String propertyName, Direction direction) {
+        setSortOrder(propertyName, direction, false);
     }
 
     public void setLimit(Value bound, long maxCount) {

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/security/user/XPathQueryEvaluator.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/security/user/XPathQueryEvaluator.java?rev=1051949&r1=1051948&r2=1051949&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/security/user/XPathQueryEvaluator.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/security/user/XPathQueryEvaluator.java
Wed Dec 22 15:24:14 2010
@@ -93,9 +93,11 @@ public class XPathQueryEvaluator impleme
         }
 
         if (sortCol != null) {
-            xPath.append(" order by ")
+            boolean ignoreCase = builder.getSortIgnoreCase();
+            xPath.append(" order by ") 
+                    .append(ignoreCase ? "" : "fn:lower-case(")
                     .append(sortCol)
-                    .append(' ')
+                    .append(ignoreCase ? " " : ") ")
                     .append(sortDir.getDirection());
         }
 

Modified: jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/api/security/user/UserManagerSearchTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/api/security/user/UserManagerSearchTest.java?rev=1051949&r1=1051948&r2=1051949&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/api/security/user/UserManagerSearchTest.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/api/security/user/UserManagerSearchTest.java
Wed Dec 22 15:24:14 2010
@@ -154,7 +154,7 @@ public class UserManagerSearchTest exten
                 jackrabbit, deer, opposum, kangaroo, elephant, lemur, gibbon, crocodile,
turtle, lizard,
                 salamander, goldenToad, poisonDartFrog);
         setProperty("color", vf.createValue("black"), blackWidow, gardenSpider, ant, fly,
lizard, salamander);
-        setProperty("color", vf.createValue("white"), opposum, goose, pelican, dove);
+        setProperty("color", vf.createValue("WHITE"), opposum, goose, pelican, dove);
         setProperty("color", vf.createValue("gold"), goldenToad);
         setProperty("numberOfLegs", vf.createValue(2), kangaroo, gibbon, kestrel, goose,
dove);
         setProperty("numberOfLegs", vf.createValue(4), jackrabbit, deer, opposum, elephant,
lemur, crocodile,
@@ -595,7 +595,7 @@ public class UserManagerSearchTest exten
             Value[] color = authorizable.getProperty("color");
             assertNotNull(color);
             assertEquals(1, color.length);
-            assertTrue(prev == null || prev.compareTo(color[0].getString()) >= 0);
+            assertTrue(prev == null || prev.compareToIgnoreCase(color[0].getString()) >=
0);
             prev = color[0].getString();
         }
     }
@@ -605,7 +605,7 @@ public class UserManagerSearchTest exten
             public <T> void build(QueryBuilder<T> builder) {
                 builder.setCondition(builder.
                         exists("profile/@weight"));
-                builder.setSortOrder("profile/@weight", Direction.ASCENDING);
+                builder.setSortOrder("profile/@weight", Direction.ASCENDING, true);
             }
         });
 
@@ -677,7 +677,7 @@ public class UserManagerSearchTest exten
                 public <T> void build(QueryBuilder<T> builder) {
                     builder.setCondition(builder.
                             eq("profile/@cute", vf.createValue(true)));
-                    builder.setSortOrder("profile/@weight", Direction.ASCENDING);
+                    builder.setSortOrder("profile/@weight", Direction.ASCENDING, true);
                     builder.setLimit(vf.createValue(1000.0), count);
                 }
             });



Mime
View raw message