jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From thom...@apache.org
Subject svn commit: r1295186 - in /jackrabbit/sandbox/jackrabbit-microkernel/src: main/java/org/apache/jackrabbit/query/qom/ main/java/org/apache/jackrabbit/query/qom/tree/ test/resources/
Date Wed, 29 Feb 2012 16:53:00 GMT
Author: thomasm
Date: Wed Feb 29 16:52:59 2012
New Revision: 1295186

URL: http://svn.apache.org/viewvc?rev=1295186&view=rev
Log:
Query implementation (WIP)

Modified:
    jackrabbit/sandbox/jackrabbit-microkernel/src/main/java/org/apache/jackrabbit/query/qom/QueryObjectModelImpl.java
    jackrabbit/sandbox/jackrabbit-microkernel/src/main/java/org/apache/jackrabbit/query/qom/tree/BindVariableValueImpl.java
    jackrabbit/sandbox/jackrabbit-microkernel/src/main/java/org/apache/jackrabbit/query/qom/tree/ChildNodeJoinConditionImpl.java
    jackrabbit/sandbox/jackrabbit-microkernel/src/main/java/org/apache/jackrabbit/query/qom/tree/DescendantNodeJoinConditionImpl.java
    jackrabbit/sandbox/jackrabbit-microkernel/src/main/java/org/apache/jackrabbit/query/qom/tree/EquiJoinConditionImpl.java
    jackrabbit/sandbox/jackrabbit-microkernel/src/main/java/org/apache/jackrabbit/query/qom/tree/JoinConditionImpl.java
    jackrabbit/sandbox/jackrabbit-microkernel/src/main/java/org/apache/jackrabbit/query/qom/tree/JoinImpl.java
    jackrabbit/sandbox/jackrabbit-microkernel/src/main/java/org/apache/jackrabbit/query/qom/tree/SameNodeJoinConditionImpl.java
    jackrabbit/sandbox/jackrabbit-microkernel/src/test/resources/queryTest.txt

Modified: jackrabbit/sandbox/jackrabbit-microkernel/src/main/java/org/apache/jackrabbit/query/qom/QueryObjectModelImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/jackrabbit-microkernel/src/main/java/org/apache/jackrabbit/query/qom/QueryObjectModelImpl.java?rev=1295186&r1=1295185&r2=1295186&view=diff
==============================================================================
--- jackrabbit/sandbox/jackrabbit-microkernel/src/main/java/org/apache/jackrabbit/query/qom/QueryObjectModelImpl.java
(original)
+++ jackrabbit/sandbox/jackrabbit-microkernel/src/main/java/org/apache/jackrabbit/query/qom/QueryObjectModelImpl.java
Wed Feb 29 16:52:59 2012
@@ -96,6 +96,7 @@ public class QueryObjectModelImpl implem
             @Override
             public boolean visit(ChildNodeJoinConditionImpl node) {
                 node.setQuery(query);
+                node.bindSelector(source);
                 return true;
             }
 
@@ -115,12 +116,14 @@ public class QueryObjectModelImpl implem
             @Override
             public boolean visit(DescendantNodeJoinConditionImpl node) {
                 node.setQuery(query);
+                node.bindSelector(source);
                 return true;
             }
 
             @Override
             public boolean visit(EquiJoinConditionImpl node) {
                 node.setQuery(query);
+                node.bindSelector(source);
                 return true;
             }
 
@@ -172,6 +175,7 @@ public class QueryObjectModelImpl implem
             @Override
             public boolean visit(SameNodeJoinConditionImpl node) {
                 node.setQuery(query);
+                node.bindSelector(source);
                 return true;
             }
 

Modified: jackrabbit/sandbox/jackrabbit-microkernel/src/main/java/org/apache/jackrabbit/query/qom/tree/BindVariableValueImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/jackrabbit-microkernel/src/main/java/org/apache/jackrabbit/query/qom/tree/BindVariableValueImpl.java?rev=1295186&r1=1295185&r2=1295186&view=diff
==============================================================================
--- jackrabbit/sandbox/jackrabbit-microkernel/src/main/java/org/apache/jackrabbit/query/qom/tree/BindVariableValueImpl.java
(original)
+++ jackrabbit/sandbox/jackrabbit-microkernel/src/main/java/org/apache/jackrabbit/query/qom/tree/BindVariableValueImpl.java
Wed Feb 29 16:52:59 2012
@@ -20,7 +20,6 @@ package org.apache.jackrabbit.query.qom.
 
 import javax.jcr.Value;
 import javax.jcr.query.qom.BindVariableValue;
-import org.apache.jackrabbit.query.qom.QueryObjectModelImpl;
 
 /**
  * The implementation of the corresponding JCR interface.

Modified: jackrabbit/sandbox/jackrabbit-microkernel/src/main/java/org/apache/jackrabbit/query/qom/tree/ChildNodeJoinConditionImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/jackrabbit-microkernel/src/main/java/org/apache/jackrabbit/query/qom/tree/ChildNodeJoinConditionImpl.java?rev=1295186&r1=1295185&r2=1295186&view=diff
==============================================================================
--- jackrabbit/sandbox/jackrabbit-microkernel/src/main/java/org/apache/jackrabbit/query/qom/tree/ChildNodeJoinConditionImpl.java
(original)
+++ jackrabbit/sandbox/jackrabbit-microkernel/src/main/java/org/apache/jackrabbit/query/qom/tree/ChildNodeJoinConditionImpl.java
Wed Feb 29 16:52:59 2012
@@ -27,6 +27,8 @@ public class ChildNodeJoinConditionImpl 
 
     private final String childSelectorName;
     private final String parentSelectorName;
+    private SelectorImpl childSelector;
+    private SelectorImpl parentSelector;
 
     public ChildNodeJoinConditionImpl(String childSelectorName, String parentSelectorName)
{
         this.childSelectorName = childSelectorName;
@@ -52,4 +54,20 @@ public class ChildNodeJoinConditionImpl 
         return "ISCHILDNODE(" + child + ", " + parent + ')';
     }
 
+    public void bindSelector(SourceImpl source) {
+        parentSelector = source.getSelector(parentSelectorName);
+        if (parentSelector == null) {
+            throw new RuntimeException("Unknown selector: " + parentSelector);
+        }
+        childSelector = source.getSelector(childSelectorName);
+        if (childSelector == null) {
+            throw new RuntimeException("Unknown selector: " + childSelectorName);
+        }
+    }
+
+    @Override
+    public boolean evaluate() {
+        return parentSelector.currentPath().equals(childSelector.currentPath());
+    }
+
 }
\ No newline at end of file

Modified: jackrabbit/sandbox/jackrabbit-microkernel/src/main/java/org/apache/jackrabbit/query/qom/tree/DescendantNodeJoinConditionImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/jackrabbit-microkernel/src/main/java/org/apache/jackrabbit/query/qom/tree/DescendantNodeJoinConditionImpl.java?rev=1295186&r1=1295185&r2=1295186&view=diff
==============================================================================
--- jackrabbit/sandbox/jackrabbit-microkernel/src/main/java/org/apache/jackrabbit/query/qom/tree/DescendantNodeJoinConditionImpl.java
(original)
+++ jackrabbit/sandbox/jackrabbit-microkernel/src/main/java/org/apache/jackrabbit/query/qom/tree/DescendantNodeJoinConditionImpl.java
Wed Feb 29 16:52:59 2012
@@ -19,6 +19,7 @@
 package org.apache.jackrabbit.query.qom.tree;
 
 import javax.jcr.query.qom.DescendantNodeJoinCondition;
+import org.apache.jackrabbit.mk.util.PathUtils;
 
 /**
  * The implementation of the corresponding JCR interface.
@@ -28,6 +29,8 @@ public class DescendantNodeJoinCondition
 
     private final String descendantSelectorName;
     private final String ancestorSelectorName;
+    private SelectorImpl descendantSelector;
+    private SelectorImpl ancestorSelector;
 
     public DescendantNodeJoinConditionImpl(String descendantSelectorName,
             String ancestorSelectorName) {
@@ -54,4 +57,22 @@ public class DescendantNodeJoinCondition
         return "ISDESCENDANTNODE(" + descendant + ", " + ancestor + ')';
     }
 
+    public void bindSelector(SourceImpl source) {
+        descendantSelector = source.getSelector(descendantSelectorName);
+        if (descendantSelector == null) {
+            throw new RuntimeException("Unknown selector: " + descendantSelectorName);
+        }
+        ancestorSelector = source.getSelector(ancestorSelectorName);
+        if (ancestorSelector == null) {
+            throw new RuntimeException("Unknown selector: " + ancestorSelectorName);
+        }
+    }
+
+    @Override
+    public boolean evaluate() {
+        String a = ancestorSelector.currentPath();
+        String d = descendantSelector.currentPath();
+        return PathUtils.isAncestor(a, d);
+    }
+
 }

Modified: jackrabbit/sandbox/jackrabbit-microkernel/src/main/java/org/apache/jackrabbit/query/qom/tree/EquiJoinConditionImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/jackrabbit-microkernel/src/main/java/org/apache/jackrabbit/query/qom/tree/EquiJoinConditionImpl.java?rev=1295186&r1=1295185&r2=1295186&view=diff
==============================================================================
--- jackrabbit/sandbox/jackrabbit-microkernel/src/main/java/org/apache/jackrabbit/query/qom/tree/EquiJoinConditionImpl.java
(original)
+++ jackrabbit/sandbox/jackrabbit-microkernel/src/main/java/org/apache/jackrabbit/query/qom/tree/EquiJoinConditionImpl.java
Wed Feb 29 16:52:59 2012
@@ -19,6 +19,7 @@
 package org.apache.jackrabbit.query.qom.tree;
 
 import javax.jcr.query.qom.EquiJoinCondition;
+import org.apache.jackrabbit.mk.simple.NodeImpl;
 
 /**
  * The implementation of the corresponding JCR interface.
@@ -29,6 +30,8 @@ public class EquiJoinConditionImpl exten
     private final String property2Name;
     private final String selector1Name;
     private final String selector2Name;
+    private SelectorImpl selector1;
+    private SelectorImpl selector2;
 
     public EquiJoinConditionImpl(String selector1Name, String property1Name, String selector2Name,
             String property2Name) {
@@ -65,4 +68,31 @@ public class EquiJoinConditionImpl exten
                 + " = " + getSelector2Name() + '.' + getProperty2Name();
     }
 
+    public void bindSelector(SourceImpl source) {
+        selector1 = source.getSelector(selector1Name);
+        if (selector1 == null) {
+            throw new RuntimeException("Unknown selector: " + selector1Name);
+        }
+        selector2 = source.getSelector(selector2Name);
+        if (selector2 == null) {
+            throw new RuntimeException("Unknown selector: " + selector2Name);
+        }
+    }
+
+    @Override
+    public boolean evaluate() {
+        NodeImpl n1 = selector1.currentNode();
+        String v1 = n1.getProperty(property1Name);
+        if (v1 == null) {
+            return false;
+        }
+        // TODO data type mapping
+        NodeImpl n2 = selector2.currentNode();
+        String v2 = n2.getProperty(property1Name);
+        if (v2 == null) {
+            return false;
+        }
+        return v1.equals(v2);
+    }
+
 }

Modified: jackrabbit/sandbox/jackrabbit-microkernel/src/main/java/org/apache/jackrabbit/query/qom/tree/JoinConditionImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/jackrabbit-microkernel/src/main/java/org/apache/jackrabbit/query/qom/tree/JoinConditionImpl.java?rev=1295186&r1=1295185&r2=1295186&view=diff
==============================================================================
--- jackrabbit/sandbox/jackrabbit-microkernel/src/main/java/org/apache/jackrabbit/query/qom/tree/JoinConditionImpl.java
(original)
+++ jackrabbit/sandbox/jackrabbit-microkernel/src/main/java/org/apache/jackrabbit/query/qom/tree/JoinConditionImpl.java
Wed Feb 29 16:52:59 2012
@@ -17,6 +17,6 @@ import javax.jcr.query.qom.JoinCondition
 
 public abstract class JoinConditionImpl extends QOMNode implements JoinCondition {
 
-    // marker class
+    public abstract boolean evaluate();
 
 }

Modified: jackrabbit/sandbox/jackrabbit-microkernel/src/main/java/org/apache/jackrabbit/query/qom/tree/JoinImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/jackrabbit-microkernel/src/main/java/org/apache/jackrabbit/query/qom/tree/JoinImpl.java?rev=1295186&r1=1295185&r2=1295186&view=diff
==============================================================================
--- jackrabbit/sandbox/jackrabbit-microkernel/src/main/java/org/apache/jackrabbit/query/qom/tree/JoinImpl.java
(original)
+++ jackrabbit/sandbox/jackrabbit-microkernel/src/main/java/org/apache/jackrabbit/query/qom/tree/JoinImpl.java
Wed Feb 29 16:52:59 2012
@@ -14,6 +14,8 @@
 package org.apache.jackrabbit.query.qom.tree;
 
 import javax.jcr.query.qom.Join;
+import org.apache.jackrabbit.mk.api.MicroKernel;
+import org.apache.jackrabbit.mk.simple.NodeImpl;
 import org.apache.jackrabbit.query.qom.QueryObjectModelImpl;
 
 /**
@@ -25,6 +27,10 @@ public class JoinImpl extends SourceImpl
     private final SourceImpl right;
     private final JoinType joinType;
     private final JoinConditionImpl joinCondition;
+    private boolean leftNeedExecute, rightNeedExecute;
+    private boolean leftNeedNext;
+    private boolean end;
+    private String revisionId;
 
     public JoinImpl(SourceImpl left, SourceImpl right, JoinType joinType,
             JoinConditionImpl joinCondition) {
@@ -89,6 +95,12 @@ public class JoinImpl extends SourceImpl
     }
 
     @Override
+    public void prepare(MicroKernel mk) {
+        left.prepare(mk);
+        right.prepare(mk);
+    }
+
+    @Override
     public SelectorImpl getSelector(String selectorName) {
         SelectorImpl s = left.getSelector(selectorName);
         if (s == null) {
@@ -97,4 +109,53 @@ public class JoinImpl extends SourceImpl
         return s;
     }
 
+    @Override
+    public void execute(String revisionId) {
+        this.revisionId = revisionId;
+        leftNeedExecute = true;
+        end = false;
+    }
+
+    public boolean next() {
+        // TODO implement outer joins
+        if (end) {
+            return false;
+        }
+        if (leftNeedExecute) {
+            left.execute(revisionId);
+            leftNeedExecute = false;
+            leftNeedNext = true;
+        }
+        while (true) {
+            if (leftNeedNext) {
+                if (!left.next()) {
+                    end = true;
+                    return false;
+                }
+                leftNeedNext = false;
+                rightNeedExecute = true;
+            }
+            if (rightNeedExecute) {
+                right.execute(revisionId);
+                rightNeedExecute = false;
+            }
+            if (!right.next()) {
+                leftNeedNext = true;
+            } else {
+                if (joinCondition.evaluate()) {
+                    return true;
+                }
+            }
+        }
+    }
+
+    public String currentPath() {
+        // TODO
+        return left.currentPath();
+    }
+
+    public NodeImpl currentNode() {
+        return null;
+    }
+
 }

Modified: jackrabbit/sandbox/jackrabbit-microkernel/src/main/java/org/apache/jackrabbit/query/qom/tree/SameNodeJoinConditionImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/jackrabbit-microkernel/src/main/java/org/apache/jackrabbit/query/qom/tree/SameNodeJoinConditionImpl.java?rev=1295186&r1=1295185&r2=1295186&view=diff
==============================================================================
--- jackrabbit/sandbox/jackrabbit-microkernel/src/main/java/org/apache/jackrabbit/query/qom/tree/SameNodeJoinConditionImpl.java
(original)
+++ jackrabbit/sandbox/jackrabbit-microkernel/src/main/java/org/apache/jackrabbit/query/qom/tree/SameNodeJoinConditionImpl.java
Wed Feb 29 16:52:59 2012
@@ -28,6 +28,8 @@ public class SameNodeJoinConditionImpl e
     private final String selector1Name;
     private final String selector2Name;
     private final String selector2Path;
+    private SelectorImpl selector1;
+    private SelectorImpl selector2;
 
     public SameNodeJoinConditionImpl(String selector1Name, String selector2Name,
             String selector2Path) {
@@ -67,4 +69,21 @@ public class SameNodeJoinConditionImpl e
         return builder.toString();
     }
 
+    public void bindSelector(SourceImpl source) {
+        selector1 = source.getSelector(selector1Name);
+        if (selector1 == null) {
+            throw new RuntimeException("Unknown selector: " + selector1Name);
+        }
+        selector2 = source.getSelector(selector2Name);
+        if (selector2 == null) {
+            throw new RuntimeException("Unknown selector: " + selector2Name);
+        }
+    }
+
+    @Override
+    public boolean evaluate() {
+        // TODO Auto-generated method stub
+        return false;
+    }
+
 }

Modified: jackrabbit/sandbox/jackrabbit-microkernel/src/test/resources/queryTest.txt
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/jackrabbit-microkernel/src/test/resources/queryTest.txt?rev=1295186&r1=1295185&r2=1295186&view=diff
==============================================================================
--- jackrabbit/sandbox/jackrabbit-microkernel/src/test/resources/queryTest.txt (original)
+++ jackrabbit/sandbox/jackrabbit-microkernel/src/test/resources/queryTest.txt Wed Feb 29
16:52:59 2012
@@ -5,6 +5,17 @@
 # * new tests are typically be added on top, after the syntax docs
 # * use ascii character only
 
++ "parents": { "p0": {"id": "0"}, "p1": {"id": "1"}, "p2": {"id": "2"}}
++ "children": { "c1": {"p": "1"}, "c2": {"p": "1"}, "c3": {"p": "2"}, "c4": {"p": "3"}}
+
+select * from [nt:base] as p inner join [nt:base] as c on p.id = c.id
+/parents/p0
+/parents/p1
+/parents/p2
+
+- "parents"
+- "children"
+
 + "test": { "hello": { "x": "1" }, "world": { "x": "2" } }
 + "test2": { "id":"1", "x": "2" }
 



Mime
View raw message