jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ang...@apache.org
Subject svn commit: r1430206 - in /jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/user/query: Condition.java XPathQueryBuilder.java XPathQueryEvaluator.java
Date Tue, 08 Jan 2013 10:56:01 GMT
Author: angela
Date: Tue Jan  8 10:56:01 2013
New Revision: 1430206

URL: http://svn.apache.org/viewvc?rev=1430206&view=rev
Log:
OAK-480 : Authorizable Query  (minor improvement)

Modified:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/user/query/Condition.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/user/query/XPathQueryBuilder.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/user/query/XPathQueryEvaluator.java

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/user/query/Condition.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/user/query/Condition.java?rev=1430206&r1=1430205&r2=1430206&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/user/query/Condition.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/user/query/Condition.java
Tue Jan  8 10:56:01 2013
@@ -27,9 +27,10 @@ interface Condition {
 
     void accept(ConditionVisitor visitor) throws RepositoryException;
 
-    //------------------------------------------< Condition implementations >---
+    //-----------------------------------------------------< Node Condition >---
 
     static class Node implements Condition {
+
         private final String pattern;
 
         public Node(String pattern) {
@@ -45,7 +46,10 @@ interface Condition {
         }
     }
 
+    //-------------------------------------------------< Property Condition >---
+
     static class Property implements Condition {
+
         private final String relPath;
         private final RelationOp op;
         private final Value value;
@@ -93,7 +97,10 @@ interface Condition {
         }
     }
 
+    //-------------------------------------------------< Contains Condition >---
+
     static class Contains implements Condition {
+
         private final String relPath;
         private final String searchExpr;
 
@@ -115,7 +122,10 @@ interface Condition {
         }
     }
 
+    //--------------------------------------------< Impersonation Condition >---
+
     static class Impersonation implements Condition {
+
         private final String name;
 
         public Impersonation(String name) {
@@ -131,7 +141,10 @@ interface Condition {
         }
     }
 
+    //------------------------------------------------------< Not Condition >---
+
     static class Not implements Condition {
+
         private final Condition condition;
 
         public Not(Condition condition) {
@@ -147,28 +160,26 @@ interface Condition {
         }
     }
 
+    //-------------------------------------------------< Compound Condition >---
+
     abstract static class Compound implements Condition, Iterable<Condition> {
-        private final List<Condition> conditions = new ArrayList<Condition>();
 
-        public Compound() {
-            super();
-        }
+        private final List<Condition> conditions = new ArrayList<Condition>();
 
         public Compound(Condition condition1, Condition condition2) {
             conditions.add(condition1);
             conditions.add(condition2);
         }
 
-        public void addCondition(Condition condition) {
-            conditions.add(condition);
-        }
-
         public Iterator<Condition> iterator() {
             return conditions.iterator();
         }
     }
 
+    //------------------------------------------------------< And Condition >---
+
     static class And extends Compound {
+
         public And(Condition condition1, Condition condition2) {
             super(condition1, condition2);
         }
@@ -178,7 +189,10 @@ interface Condition {
         }
     }
 
+    //-------------------------------------------------------< Or Condition >---
+
     static class Or extends Compound {
+
         public Or(Condition condition1, Condition condition2) {
             super(condition1, condition2);
         }

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/user/query/XPathQueryBuilder.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/user/query/XPathQueryBuilder.java?rev=1430206&r1=1430205&r2=1430206&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/user/query/XPathQueryBuilder.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/user/query/XPathQueryBuilder.java
Tue Jan  8 10:56:01 2013
@@ -65,14 +65,16 @@ public class XPathQueryBuilder implement
 
     @Override
     public void setLimit(Value bound, long maxCount) {
-        offset = 0;   // Unset any previously set offset
+        // reset the offset before setting bound value/maxCount
+        offset = 0;
         this.bound = bound;
         this.maxCount = maxCount;
     }
 
     @Override
     public void setLimit(long offset, long maxCount) {
-        bound = null; // Unset any previously set bound
+        // reset the bound value before setting offset/maxCount
+        bound = null;
         this.offset = offset;
         this.maxCount = maxCount;
     }

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/user/query/XPathQueryEvaluator.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/user/query/XPathQueryEvaluator.java?rev=1430206&r1=1430205&r2=1430206&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/user/query/XPathQueryEvaluator.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/user/query/XPathQueryEvaluator.java
Tue Jan  8 10:56:01 2013
@@ -41,8 +41,7 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 /**
- * This evaluator for {@link org.apache.jackrabbit.api.security.user.Query}s use XPath
- * and some minimal client side filtering.
+ * XPATH based evaluation of {@link org.apache.jackrabbit.api.security.user.Query}s.
  */
 public class XPathQueryEvaluator implements ConditionVisitor {
 
@@ -64,7 +63,6 @@ public class XPathQueryEvaluator impleme
     }
 
     public Iterator<Authorizable> eval() throws RepositoryException {
-        // shortcut
         if (builder.getMaxCount() == 0) {
             return Iterators.emptyIterator();
         }
@@ -74,7 +72,6 @@ public class XPathQueryEvaluator impleme
                 .append(')');
 
         Value bound = builder.getBound();
-
         Condition condition = builder.getCondition();
         String sortCol = builder.getSortProperty();
         QueryBuilder.Direction sortDir = builder.getSortDirection();
@@ -83,9 +80,11 @@ public class XPathQueryEvaluator impleme
                 log.warn("Ignoring bound {} since no sort order is specified");
             } else {
                 Condition boundCondition = builder.property(sortCol, getCollation(sortDir),
bound);
-                condition = condition == null
-                        ? boundCondition
-                        : builder.and(condition, boundCondition);
+                if (condition == null) {
+                    condition = boundCondition;
+                } else {
+                    condition = builder.and(condition, boundCondition);
+                }
             }
         }
 
@@ -113,7 +112,7 @@ public class XPathQueryEvaluator impleme
                 }
                 return findAuthorizables(builder.getMaxCount(), offset);
             } else {
-                // filtering by group name not included in query -> enforce offset
+                // filtering by group name included in query -> enforce offset
                 // and limit on the result set.
                 Iterator<Authorizable> result = findAuthorizables(Long.MAX_VALUE, 0);
                 Iterator<Authorizable> filtered = filter(result, builder.getGroupName(),
builder.isDeclaredMembersOnly());
@@ -122,10 +121,6 @@ public class XPathQueryEvaluator impleme
         } catch (ParseException e) {
             throw new RepositoryException(e);
         }
-
-        // If we are scoped to a group and have a limit, we have to apply the limit
-        // here (inefficient!) otherwise we can apply the limit in the query
-
     }
 
     //---------------------------------------------------< ConditionVisitor >---
@@ -225,7 +220,7 @@ public class XPathQueryEvaluator impleme
         int k = 0;
         int j;
         do {
-            j = string.indexOf('%', k); // split on %
+            j = string.indexOf('%', k);
             if (j < 0) {
                 // jcr escape trail
                 result.append(Text.escapeIllegalJcrChars(string.substring(k)));
@@ -271,8 +266,7 @@ public class XPathQueryEvaluator impleme
                 return "xs:dateTime('" + value.getString() + "')";
 
             default:
-                throw new RepositoryException("Property of type " + PropertyType.nameFromValue(value.getType())
+
-                        " not supported");
+                throw new RepositoryException("Property of type " + PropertyType.nameFromValue(value.getType())
+ " not supported");
         }
     }
 
@@ -291,8 +285,8 @@ public class XPathQueryEvaluator impleme
     @Nonnull
     private Iterator<Authorizable> findAuthorizables(long limit, long offset) throws
ParseException {
         Iterable<? extends ResultRow> resultRows = root.getQueryEngine().executeQuery(xPath.toString(),
Query.XPATH, limit, offset, null, namePathMapper).getRows();
-        Iterator<Authorizable> authorizbles = Iterators.transform(resultRows.iterator(),
new ResultRowToAuthorizable(userManager));
-        return Iterators.filter(authorizbles, Predicates.<Object>notNull());
+        Iterator<Authorizable> authorizables = Iterators.transform(resultRows.iterator(),
new ResultRowToAuthorizable(userManager));
+        return Iterators.filter(authorizables, Predicates.<Object>notNull());
     }
 
     @Nonnull



Mime
View raw message