You are viewing a plain text version of this content. The canonical link for it is here.
Posted to oak-commits@jackrabbit.apache.org by th...@apache.org on 2012/03/20 14:49:49 UTC

svn commit: r1302895 [1/2] - in /jackrabbit/oak/trunk/oak-jcr/src: main/java/org/apache/jackrabbit/oak/jcr/query/ main/java/org/apache/jackrabbit/oak/jcr/query/qom/ test/java/org/apache/jackrabbit/oak/jcr/query/ test/java/org/apache/jackrabbit/oak/jcr/...

Author: thomasm
Date: Tue Mar 20 13:49:47 2012
New Revision: 1302895

URL: http://svn.apache.org/viewvc?rev=1302895&view=rev
Log:
OAK-28 Query implementation

Added:
    jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/query/
    jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/query/qom/
    jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/query/qom/AndImpl.java
    jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/query/qom/BindVariableValueImpl.java
    jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/query/qom/ChildNodeImpl.java
    jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/query/qom/ChildNodeJoinConditionImpl.java
    jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/query/qom/ColumnImpl.java
    jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/query/qom/ComparisonImpl.java
    jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/query/qom/ConstraintImpl.java
    jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/query/qom/DescendantNodeImpl.java
    jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/query/qom/DescendantNodeJoinConditionImpl.java
    jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/query/qom/DynamicOperandImpl.java
    jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/query/qom/EquiJoinConditionImpl.java
    jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/query/qom/FullTextSearchImpl.java
    jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/query/qom/FullTextSearchScoreImpl.java
    jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/query/qom/JoinConditionImpl.java
    jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/query/qom/JoinImpl.java
    jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/query/qom/JoinType.java
    jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/query/qom/LengthImpl.java
    jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/query/qom/LiteralImpl.java
    jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/query/qom/LowerCaseImpl.java
    jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/query/qom/NodeLocalNameImpl.java
    jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/query/qom/NodeNameImpl.java
    jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/query/qom/NotImpl.java
    jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/query/qom/Operator.java
    jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/query/qom/OrImpl.java
    jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/query/qom/Order.java
    jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/query/qom/OrderingImpl.java
    jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/query/qom/PropertyExistenceImpl.java
    jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/query/qom/PropertyValueImpl.java
    jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/query/qom/QOMNode.java
    jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/query/qom/QOMVisitor.java
    jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/query/qom/QueryObjectModelFactoryImpl.java
    jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/query/qom/QueryObjectModelImpl.java
    jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/query/qom/SameNodeImpl.java
    jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/query/qom/SameNodeJoinConditionImpl.java
    jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/query/qom/SelectorImpl.java
    jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/query/qom/SourceImpl.java
    jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/query/qom/StaticOperandImpl.java
    jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/query/qom/UpperCaseImpl.java
    jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/query/
    jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/query/qom/
    jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/query/qom/QomTest.java

Added: jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/query/qom/AndImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/query/qom/AndImpl.java?rev=1302895&view=auto
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/query/qom/AndImpl.java (added)
+++ jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/query/qom/AndImpl.java Tue Mar 20 13:49:47 2012
@@ -0,0 +1,57 @@
+/*
+ * 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.jackrabbit.oak.jcr.query.qom;
+
+import javax.jcr.query.qom.And;
+
+/**
+ * The implementation of the corresponding JCR interface.
+ */
+public class AndImpl extends ConstraintImpl implements And {
+
+    private final ConstraintImpl constraint1, constraint2;
+
+    public AndImpl(ConstraintImpl constraint1, ConstraintImpl constraint2) {
+        this.constraint1 = constraint1;
+        this.constraint2 = constraint2;
+    }
+
+    @Override
+    public ConstraintImpl getConstraint1() {
+        return constraint1;
+    }
+
+    @Override
+    public ConstraintImpl getConstraint2() {
+        return constraint2;
+    }
+
+    @Override
+    public String toString() {
+        return protect(constraint1) + " AND " + protect(constraint2);
+    }
+
+    @Override
+    public void bindVariables(QueryObjectModelImpl qom) {
+        constraint1.bindVariables(qom);
+        constraint2.bindVariables(qom);
+    }
+
+}
+

Added: jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/query/qom/BindVariableValueImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/query/qom/BindVariableValueImpl.java?rev=1302895&view=auto
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/query/qom/BindVariableValueImpl.java (added)
+++ jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/query/qom/BindVariableValueImpl.java Tue Mar 20 13:49:47 2012
@@ -0,0 +1,49 @@
+/*
+ * 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.jackrabbit.oak.jcr.query.qom;
+
+import javax.jcr.query.qom.BindVariableValue;
+
+/**
+ * The implementation of the corresponding JCR interface.
+ */
+public class BindVariableValueImpl extends StaticOperandImpl implements BindVariableValue {
+
+    private final String bindVariableName;
+
+    public BindVariableValueImpl(String bindVariableName) {
+        this.bindVariableName = bindVariableName;
+    }
+
+    @Override
+    public String getBindVariableName() {
+        return bindVariableName;
+    }
+
+    @Override
+    public String toString() {
+        return '$' + bindVariableName;
+    }
+
+    @Override
+    public void bindVariables(QueryObjectModelImpl qom) {
+        qom.addBindVariable(this);
+    }
+
+}

Added: jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/query/qom/ChildNodeImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/query/qom/ChildNodeImpl.java?rev=1302895&view=auto
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/query/qom/ChildNodeImpl.java (added)
+++ jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/query/qom/ChildNodeImpl.java Tue Mar 20 13:49:47 2012
@@ -0,0 +1,56 @@
+/*
+ * 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.jackrabbit.oak.jcr.query.qom;
+
+import javax.jcr.query.qom.ChildNode;
+
+/**
+ * The implementation of the corresponding JCR interface.
+ */
+public class ChildNodeImpl extends ConstraintImpl implements ChildNode {
+
+    private final String selectorName;
+    private final String parentPath;
+
+    public ChildNodeImpl(String selectorName, String parentPath) {
+        this.selectorName = selectorName;
+        this.parentPath = parentPath;
+    }
+
+    @Override
+    public String getSelectorName() {
+        return selectorName;
+    }
+
+    @Override
+    public String getParentPath() {
+        return parentPath;
+    }
+
+    @Override
+    public String toString() {
+        return "ISCHILDNODE(" + selectorName + ", " + quotePath(parentPath) + ')';
+    }
+
+    @Override
+    public void bindVariables(QueryObjectModelImpl qom) {
+        // ignore
+    }
+
+}
\ No newline at end of file

Added: jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/query/qom/ChildNodeJoinConditionImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/query/qom/ChildNodeJoinConditionImpl.java?rev=1302895&view=auto
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/query/qom/ChildNodeJoinConditionImpl.java (added)
+++ jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/query/qom/ChildNodeJoinConditionImpl.java Tue Mar 20 13:49:47 2012
@@ -0,0 +1,53 @@
+/*
+ * 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.jackrabbit.oak.jcr.query.qom;
+
+import javax.jcr.query.qom.ChildNodeJoinCondition;
+
+/**
+ * The implementation of the corresponding JCR interface.
+ */
+public class ChildNodeJoinConditionImpl extends JoinConditionImpl implements ChildNodeJoinCondition {
+
+    private final String childSelectorName;
+    private final String parentSelectorName;
+
+    public ChildNodeJoinConditionImpl(String childSelectorName, String parentSelectorName) {
+        this.childSelectorName = childSelectorName;
+        this.parentSelectorName = parentSelectorName;
+    }
+
+    @Override
+    public String getChildSelectorName() {
+        return childSelectorName;
+    }
+
+    @Override
+    public String getParentSelectorName() {
+        return parentSelectorName;
+    }
+
+    @Override
+    public String toString() {
+        String child = getChildSelectorName();
+        String parent = getParentSelectorName();
+        return "ISCHILDNODE(" + child + ", " + parent + ')';
+    }
+
+}
\ No newline at end of file

Added: jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/query/qom/ColumnImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/query/qom/ColumnImpl.java?rev=1302895&view=auto
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/query/qom/ColumnImpl.java (added)
+++ jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/query/qom/ColumnImpl.java Tue Mar 20 13:49:47 2012
@@ -0,0 +1,58 @@
+/*
+ * 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.jackrabbit.oak.jcr.query.qom;
+
+import javax.jcr.query.qom.Column;
+
+/**
+ * The implementation of the corresponding JCR interface.
+ */
+public class ColumnImpl extends QOMNode implements Column {
+
+    private final String selectorName, propertyName, columnName;
+
+    public ColumnImpl(String selectorName, String propertyName, String columnName) {
+        this.selectorName = selectorName;
+        this.propertyName = propertyName;
+        this.columnName = columnName;
+    }
+
+    public String getColumnName() {
+        return columnName;
+    }
+
+    public String getPropertyName() {
+        return propertyName;
+    }
+
+    public String getSelectorName() {
+        return selectorName;
+    }
+
+    @Override
+    public String toString() {
+        if (propertyName != null) {
+            return getSelectorName() + '.' + getPropertyName()
+                    + " AS " + getColumnName();
+        } else {
+            return getSelectorName() + ".*";
+        }
+    }
+
+}

Added: jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/query/qom/ComparisonImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/query/qom/ComparisonImpl.java?rev=1302895&view=auto
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/query/qom/ComparisonImpl.java (added)
+++ jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/query/qom/ComparisonImpl.java Tue Mar 20 13:49:47 2012
@@ -0,0 +1,63 @@
+/*
+ * 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.jackrabbit.oak.jcr.query.qom;
+
+import javax.jcr.query.qom.Comparison;
+
+/**
+ * The implementation of the corresponding JCR interface.
+ */
+public class ComparisonImpl extends ConstraintImpl implements Comparison {
+
+    private final DynamicOperandImpl operand1;
+    private final Operator operator;
+    private final StaticOperandImpl operand2;
+
+    public ComparisonImpl(DynamicOperandImpl operand1, Operator operator, StaticOperandImpl operand2) {
+        this.operand1 = operand1;
+        this.operator = operator;
+        this.operand2 = operand2;
+    }
+
+    @Override
+    public DynamicOperandImpl getOperand1() {
+        return operand1;
+    }
+
+    @Override
+    public String getOperator() {
+        return operator.toString();
+    }
+
+    @Override
+    public StaticOperandImpl getOperand2() {
+        return operand2;
+    }
+
+    @Override
+    public String toString() {
+        return operator.formatSql(operand1.toString(), operand2.toString());
+    }
+
+    @Override
+    public void bindVariables(QueryObjectModelImpl qom) {
+        operand2.bindVariables(qom);
+    }
+
+}

Added: jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/query/qom/ConstraintImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/query/qom/ConstraintImpl.java?rev=1302895&view=auto
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/query/qom/ConstraintImpl.java (added)
+++ jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/query/qom/ConstraintImpl.java Tue Mar 20 13:49:47 2012
@@ -0,0 +1,28 @@
+/*
+ * 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.jackrabbit.oak.jcr.query.qom;
+
+import javax.jcr.query.qom.Constraint;
+
+/**
+ * The implementation of the corresponding JCR interface.
+ */
+public abstract class ConstraintImpl extends QOMNode implements Constraint {
+
+    public abstract void bindVariables(QueryObjectModelImpl qom);
+
+}

Added: jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/query/qom/DescendantNodeImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/query/qom/DescendantNodeImpl.java?rev=1302895&view=auto
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/query/qom/DescendantNodeImpl.java (added)
+++ jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/query/qom/DescendantNodeImpl.java Tue Mar 20 13:49:47 2012
@@ -0,0 +1,56 @@
+/*
+ * 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.jackrabbit.oak.jcr.query.qom;
+
+import javax.jcr.query.qom.DescendantNode;
+
+/**
+ * The implementation of the corresponding JCR interface.
+ */
+public class DescendantNodeImpl extends ConstraintImpl implements DescendantNode {
+
+    private final String selectorName;
+    private final String ancestorPath;
+
+    public DescendantNodeImpl(String selectorName, String ancestorPath) {
+        this.selectorName = selectorName;
+        this.ancestorPath = ancestorPath;
+    }
+
+    @Override
+    public String getSelectorName() {
+        return selectorName;
+    }
+
+    @Override
+    public String getAncestorPath() {
+        return ancestorPath;
+    }
+
+    @Override
+    public String toString() {
+        return "ISDESCENDANTNODE(" + getSelectorName() + ", " + quotePath(ancestorPath) + ')';
+    }
+
+    @Override
+    public void bindVariables(QueryObjectModelImpl qom) {
+        // ignore
+    }
+
+}

Added: jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/query/qom/DescendantNodeJoinConditionImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/query/qom/DescendantNodeJoinConditionImpl.java?rev=1302895&view=auto
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/query/qom/DescendantNodeJoinConditionImpl.java (added)
+++ jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/query/qom/DescendantNodeJoinConditionImpl.java Tue Mar 20 13:49:47 2012
@@ -0,0 +1,55 @@
+/*
+ * 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.jackrabbit.oak.jcr.query.qom;
+
+import javax.jcr.query.qom.DescendantNodeJoinCondition;
+
+/**
+ * The implementation of the corresponding JCR interface.
+ */
+public class DescendantNodeJoinConditionImpl extends JoinConditionImpl implements
+        DescendantNodeJoinCondition {
+
+    private final String descendantSelectorName;
+    private final String ancestorSelectorName;
+
+    public DescendantNodeJoinConditionImpl(String descendantSelectorName,
+            String ancestorSelectorName) {
+        this.descendantSelectorName = descendantSelectorName;
+        this.ancestorSelectorName = ancestorSelectorName;
+    }
+
+    @Override
+    public String getDescendantSelectorName() {
+        return descendantSelectorName;
+    }
+
+    @Override
+    public String getAncestorSelectorName() {
+        return ancestorSelectorName;
+    }
+
+    @Override
+    public String toString() {
+        String descendant = getDescendantSelectorName();
+        String ancestor = getAncestorSelectorName();
+        return "ISDESCENDANTNODE(" + descendant + ", " + ancestor + ')';
+    }
+
+}

Added: jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/query/qom/DynamicOperandImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/query/qom/DynamicOperandImpl.java?rev=1302895&view=auto
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/query/qom/DynamicOperandImpl.java (added)
+++ jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/query/qom/DynamicOperandImpl.java Tue Mar 20 13:49:47 2012
@@ -0,0 +1,25 @@
+/*
+ * 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.jackrabbit.oak.jcr.query.qom;
+
+import javax.jcr.query.qom.DynamicOperand;
+
+public abstract class DynamicOperandImpl extends QOMNode implements DynamicOperand {
+
+    // base class without methods
+
+}

Added: jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/query/qom/EquiJoinConditionImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/query/qom/EquiJoinConditionImpl.java?rev=1302895&view=auto
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/query/qom/EquiJoinConditionImpl.java (added)
+++ jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/query/qom/EquiJoinConditionImpl.java Tue Mar 20 13:49:47 2012
@@ -0,0 +1,68 @@
+/*
+ * 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.jackrabbit.oak.jcr.query.qom;
+
+import javax.jcr.query.qom.EquiJoinCondition;
+
+/**
+ * The implementation of the corresponding JCR interface.
+ */
+public class EquiJoinConditionImpl extends JoinConditionImpl implements EquiJoinCondition {
+
+    private final String property1Name;
+    private final String property2Name;
+    private final String selector1Name;
+    private final String selector2Name;
+
+    public EquiJoinConditionImpl(String selector1Name, String property1Name, String selector2Name,
+            String property2Name) {
+        this.selector1Name = selector1Name;
+        this.property1Name = property1Name;
+        this.selector2Name = selector2Name;
+        this.property2Name = property2Name;
+    }
+
+    @Override
+    public String getSelector1Name() {
+        return selector1Name;
+    }
+
+    @Override
+    public String getProperty1Name() {
+        return property1Name;
+    }
+
+    @Override
+    public String getSelector2Name() {
+        return selector2Name;
+    }
+
+    @Override
+    public String getProperty2Name() {
+        return property2Name;
+    }
+
+    @Override
+    public String toString() {
+        // TODO quote property names?
+        return getSelector1Name() + '.' + getProperty1Name()
+                + " = " + getSelector2Name() + '.' + getProperty2Name();
+    }
+
+}

Added: jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/query/qom/FullTextSearchImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/query/qom/FullTextSearchImpl.java?rev=1302895&view=auto
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/query/qom/FullTextSearchImpl.java (added)
+++ jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/query/qom/FullTextSearchImpl.java Tue Mar 20 13:49:47 2012
@@ -0,0 +1,77 @@
+/*
+ * 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.jackrabbit.oak.jcr.query.qom;
+
+import javax.jcr.query.qom.FullTextSearch;
+
+/**
+ * The implementation of the corresponding JCR interface.
+ */
+public class FullTextSearchImpl extends ConstraintImpl implements FullTextSearch {
+
+    private final String selectorName;
+    private final String propertyName;
+    private final StaticOperandImpl fullTextSearchExpression;
+
+    public FullTextSearchImpl(String selectorName, String propertyName,
+            StaticOperandImpl fullTextSearchExpression) {
+        this.selectorName = selectorName;
+        this.propertyName = propertyName;
+        this.fullTextSearchExpression = fullTextSearchExpression;
+    }
+
+    @Override
+    public StaticOperandImpl getFullTextSearchExpression() {
+        return fullTextSearchExpression;
+    }
+
+    @Override
+    public String getPropertyName() {
+        return propertyName;
+    }
+
+    @Override
+    public String getSelectorName() {
+        return selectorName;
+    }
+
+    @Override
+    public String toString() {
+        // TODO quote property names?
+        StringBuilder builder = new StringBuilder();
+        builder.append("CONTAINS(");
+        builder.append(getSelectorName());
+        if (propertyName != null) {
+            builder.append('.');
+            builder.append(propertyName);
+            builder.append(", ");
+        } else {
+            builder.append(".*, ");
+        }
+        builder.append(getFullTextSearchExpression());
+        builder.append(')');
+        return builder.toString();
+    }
+
+    @Override
+    public void bindVariables(QueryObjectModelImpl qom) {
+        this.fullTextSearchExpression.bindVariables(qom);
+    }
+
+}

Added: jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/query/qom/FullTextSearchScoreImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/query/qom/FullTextSearchScoreImpl.java?rev=1302895&view=auto
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/query/qom/FullTextSearchScoreImpl.java (added)
+++ jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/query/qom/FullTextSearchScoreImpl.java Tue Mar 20 13:49:47 2012
@@ -0,0 +1,44 @@
+/*
+ * 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.jackrabbit.oak.jcr.query.qom;
+
+import javax.jcr.query.qom.FullTextSearchScore;
+
+/**
+ * The implementation of the corresponding JCR interface.
+ */
+public class FullTextSearchScoreImpl extends DynamicOperandImpl implements FullTextSearchScore {
+
+    private final String selectorName;
+
+    public FullTextSearchScoreImpl(String selectorName) {
+        this.selectorName = selectorName;
+    }
+
+    @Override
+    public String getSelectorName() {
+        return selectorName;
+    }
+
+    @Override
+    public String toString() {
+        return "SCORE(" + getSelectorName() + ')';
+    }
+
+}

Added: jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/query/qom/JoinConditionImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/query/qom/JoinConditionImpl.java?rev=1302895&view=auto
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/query/qom/JoinConditionImpl.java (added)
+++ jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/query/qom/JoinConditionImpl.java Tue Mar 20 13:49:47 2012
@@ -0,0 +1,22 @@
+/*
+ * 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.jackrabbit.oak.jcr.query.qom;
+
+import javax.jcr.query.qom.JoinCondition;
+
+public abstract class JoinConditionImpl extends QOMNode implements JoinCondition {
+
+    // base class without methods
+
+}

Added: jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/query/qom/JoinImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/query/qom/JoinImpl.java?rev=1302895&view=auto
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/query/qom/JoinImpl.java (added)
+++ jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/query/qom/JoinImpl.java Tue Mar 20 13:49:47 2012
@@ -0,0 +1,61 @@
+/*
+ * 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.jackrabbit.oak.jcr.query.qom;
+
+import javax.jcr.query.qom.Join;
+
+/**
+ * The implementation of the corresponding JCR interface.
+ */
+public class JoinImpl extends SourceImpl implements Join {
+
+    private final JoinConditionImpl joinCondition;
+    private JoinType joinType;
+    private SourceImpl left;
+    private SourceImpl right;
+
+    public JoinImpl(SourceImpl left, SourceImpl right, JoinType joinType,
+            JoinConditionImpl joinCondition) {
+        this.left = left;
+        this.right = right;
+        this.joinType = joinType;
+        this.joinCondition = joinCondition;
+    }
+
+    @Override
+    public JoinConditionImpl getJoinCondition() {
+        return joinCondition;
+    }
+
+    @Override
+    public String getJoinType() {
+        return joinType.toString();
+    }
+
+    @Override
+    public SourceImpl getLeft() {
+        return left;
+    }
+
+    @Override
+    public SourceImpl getRight() {
+        return right;
+    }
+
+    @Override
+    public String toString() {
+        return joinType.formatSql(left, right, joinCondition);
+    }
+
+}

Added: jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/query/qom/JoinType.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/query/qom/JoinType.java?rev=1302895&view=auto
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/query/qom/JoinType.java (added)
+++ jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/query/qom/JoinType.java Tue Mar 20 13:49:47 2012
@@ -0,0 +1,108 @@
+/*
+ * 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.jackrabbit.oak.jcr.query.qom;
+
+import javax.jcr.RepositoryException;
+import javax.jcr.query.qom.Join;
+import javax.jcr.query.qom.JoinCondition;
+import javax.jcr.query.qom.QueryObjectModelConstants;
+import javax.jcr.query.qom.QueryObjectModelFactory;
+import javax.jcr.query.qom.Source;
+
+/**
+ * Enumeration of the JCR 2.0 join types.
+ *
+ * @since Apache Jackrabbit 2.0
+ */
+public enum JoinType {
+
+    INNER(QueryObjectModelConstants.JCR_JOIN_TYPE_INNER, "INNER JOIN"),
+
+    LEFT(QueryObjectModelConstants.JCR_JOIN_TYPE_LEFT_OUTER, "LEFT OUTER JOIN"),
+
+    RIGHT(QueryObjectModelConstants.JCR_JOIN_TYPE_RIGHT_OUTER, "RIGHT OUTER JOIN");
+
+    /**
+     * JCR name of this join type.
+     */
+    private final String name;
+
+    private final String sql;
+
+    JoinType(String name, String sql) {
+        this.name = name;
+        this.sql = sql;
+    }
+
+    /**
+     * Returns the join of the given sources.
+     *
+     * @param factory factory for creating the join
+     * @param left left join source
+     * @param right right join source
+     * @param condition join condition
+     * @return join
+     * @throws RepositoryException if the join can not be created
+     */
+    public Join join(
+            QueryObjectModelFactory factory,
+            Source left, Source right, JoinCondition condition)
+            throws RepositoryException {
+        return factory.join(left, right, name, condition);
+    }
+
+    /**
+     * Formats an SQL join with this join type and the given sources and
+     * join condition. The sources and condition are simply used as-is,
+     * without any quoting or escaping.
+     *
+     * @param left left source
+     * @param right right source
+     * @param condition join condition
+     * @return SQL join, {@code left join right}
+     */
+    public String formatSql(Object left, Object right, Object condition) {
+        return left + " " + sql + ' ' + right + " ON " + condition;
+    }
+
+    /**
+     * Returns the JCR 2.0 name of this join type.
+     *
+     * @see QueryObjectModelConstants
+     * @return JCR name of this join type
+     */
+    @Override
+    public String toString() {
+        return name;
+    }
+
+    /**
+     * Returns the join type with the given JCR name.
+     *
+     * @param name JCR name of a join type
+     * @return join type with the given name
+     */
+    public static JoinType getJoinTypeByName(String name)  {
+        for (JoinType type : JoinType.values()) {
+            if (type.name.equals(name)) {
+                return type;
+            }
+        }
+        throw new IllegalArgumentException("Unknown join type name: " + name);
+    }
+
+}

Added: jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/query/qom/LengthImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/query/qom/LengthImpl.java?rev=1302895&view=auto
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/query/qom/LengthImpl.java (added)
+++ jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/query/qom/LengthImpl.java Tue Mar 20 13:49:47 2012
@@ -0,0 +1,44 @@
+/*
+ * 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.jackrabbit.oak.jcr.query.qom;
+
+import javax.jcr.query.qom.Length;
+
+/**
+ * The implementation of the corresponding JCR interface.
+ */
+public class LengthImpl extends DynamicOperandImpl implements Length {
+
+    private final PropertyValueImpl propertyValue;
+
+    public LengthImpl(PropertyValueImpl propertyValue) {
+        this.propertyValue = propertyValue;
+    }
+
+    @Override
+    public PropertyValueImpl getPropertyValue() {
+        return propertyValue;
+    }
+
+    @Override
+    public String toString() {
+        return "LENGTH(" + getPropertyValue() + ')';
+    }
+
+}

Added: jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/query/qom/LiteralImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/query/qom/LiteralImpl.java?rev=1302895&view=auto
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/query/qom/LiteralImpl.java (added)
+++ jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/query/qom/LiteralImpl.java Tue Mar 20 13:49:47 2012
@@ -0,0 +1,90 @@
+/*
+ * 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.jackrabbit.oak.jcr.query.qom;
+
+import javax.jcr.PropertyType;
+import javax.jcr.RepositoryException;
+import javax.jcr.Value;
+import javax.jcr.query.qom.Literal;
+
+/**
+ * The implementation of the corresponding JCR interface.
+ */
+public class LiteralImpl extends StaticOperandImpl implements Literal {
+
+    private final Value value;
+
+    public LiteralImpl(Value value) {
+        this.value = value;
+    }
+
+    @Override
+    public Value getLiteralValue() {
+        return value;
+    }
+
+    @Override
+    public String toString() {
+        try {
+            switch (value.getType()) {
+            case PropertyType.BINARY:
+                return cast("BINARY");
+            case PropertyType.BOOLEAN:
+                return cast("BOOLEAN");
+            case PropertyType.DATE:
+                return cast("DATE");
+            case PropertyType.DECIMAL:
+                return cast("DECIMAL");
+            case PropertyType.DOUBLE:
+            case PropertyType.LONG:
+                return value.getString();
+            case PropertyType.NAME:
+                return cast("NAME");
+            case PropertyType.PATH:
+                return cast("PATH");
+            case PropertyType.REFERENCE:
+                return cast("REFERENCE");
+            case PropertyType.STRING:
+                return escape(value.getString());
+            case PropertyType.URI:
+                return cast("URI");
+            case PropertyType.WEAKREFERENCE:
+                return cast("WEAKREFERENCE");
+            default:
+                return escape(value.getString());
+            }
+        } catch (RepositoryException e) {
+            return value.toString();
+        }
+    }
+
+    private String cast(String type) throws RepositoryException {
+        return "CAST(" + escape(value.getString()) + " AS " + type + ')';
+    }
+
+    public static final String escape(String v){
+        return '\'' + v.replace("'", "''") + '\'';
+    }
+
+    @Override
+    public void bindVariables(QueryObjectModelImpl qom) {
+        // ignore
+    }
+
+}

Added: jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/query/qom/LowerCaseImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/query/qom/LowerCaseImpl.java?rev=1302895&view=auto
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/query/qom/LowerCaseImpl.java (added)
+++ jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/query/qom/LowerCaseImpl.java Tue Mar 20 13:49:47 2012
@@ -0,0 +1,44 @@
+/*
+ * 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.jackrabbit.oak.jcr.query.qom;
+
+import javax.jcr.query.qom.LowerCase;
+
+/**
+ * The implementation of the corresponding JCR interface.
+ */
+public class LowerCaseImpl extends DynamicOperandImpl implements LowerCase {
+
+    private final DynamicOperandImpl operand;
+
+    public LowerCaseImpl(DynamicOperandImpl operand) {
+        this.operand = operand;
+    }
+
+    @Override
+    public DynamicOperandImpl getOperand() {
+        return operand;
+    }
+
+    @Override
+    public String toString() {
+        return "LOWER(" + operand + ')';
+    }
+
+}

Added: jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/query/qom/NodeLocalNameImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/query/qom/NodeLocalNameImpl.java?rev=1302895&view=auto
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/query/qom/NodeLocalNameImpl.java (added)
+++ jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/query/qom/NodeLocalNameImpl.java Tue Mar 20 13:49:47 2012
@@ -0,0 +1,44 @@
+/*
+ * 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.jackrabbit.oak.jcr.query.qom;
+
+import javax.jcr.query.qom.NodeLocalName;
+
+/**
+ * The implementation of the corresponding JCR interface.
+ */
+public class NodeLocalNameImpl extends DynamicOperandImpl implements NodeLocalName {
+
+    private final String selectorName;
+
+    public NodeLocalNameImpl(String selectorName) {
+        this.selectorName = selectorName;
+    }
+
+    @Override
+    public String getSelectorName() {
+        return selectorName;
+    }
+
+    @Override
+    public String toString() {
+        return "LOCALNAME(" + getSelectorName() + ')';
+    }
+
+}

Added: jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/query/qom/NodeNameImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/query/qom/NodeNameImpl.java?rev=1302895&view=auto
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/query/qom/NodeNameImpl.java (added)
+++ jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/query/qom/NodeNameImpl.java Tue Mar 20 13:49:47 2012
@@ -0,0 +1,44 @@
+/*
+ * 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.jackrabbit.oak.jcr.query.qom;
+
+import javax.jcr.query.qom.NodeName;
+
+/**
+ * The implementation of the corresponding JCR interface.
+ */
+public class NodeNameImpl extends DynamicOperandImpl implements NodeName {
+
+    private final String selectorName;
+
+    public NodeNameImpl(String selectorName) {
+        this.selectorName = selectorName;
+    }
+
+    @Override
+    public String getSelectorName() {
+        return selectorName;
+    }
+
+    @Override
+    public String toString() {
+        return "NAME(" + getSelectorName() + ')';
+    }
+
+}

Added: jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/query/qom/NotImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/query/qom/NotImpl.java?rev=1302895&view=auto
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/query/qom/NotImpl.java (added)
+++ jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/query/qom/NotImpl.java Tue Mar 20 13:49:47 2012
@@ -0,0 +1,49 @@
+/*
+ * 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.jackrabbit.oak.jcr.query.qom;
+
+import javax.jcr.query.qom.Not;
+
+/**
+ * The implementation of the corresponding JCR interface.
+ */
+public class NotImpl extends ConstraintImpl implements Not {
+
+    private final ConstraintImpl constraint;
+
+    public NotImpl(ConstraintImpl constraint) {
+        this.constraint = constraint;
+    }
+
+    @Override
+    public ConstraintImpl getConstraint() {
+        return constraint;
+    }
+
+    @Override
+    public String toString() {
+        return "NOT " + protect(constraint);
+    }
+
+    @Override
+    public void bindVariables(QueryObjectModelImpl qom) {
+        constraint.bindVariables(qom);
+    }
+
+}

Added: jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/query/qom/Operator.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/query/qom/Operator.java?rev=1302895&view=auto
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/query/qom/Operator.java (added)
+++ jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/query/qom/Operator.java Tue Mar 20 13:49:47 2012
@@ -0,0 +1,160 @@
+/*
+ * 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.jackrabbit.oak.jcr.query.qom;
+
+import javax.jcr.RepositoryException;
+import javax.jcr.query.qom.Comparison;
+import javax.jcr.query.qom.DynamicOperand;
+import javax.jcr.query.qom.QueryObjectModelConstants;
+import javax.jcr.query.qom.QueryObjectModelFactory;
+import javax.jcr.query.qom.StaticOperand;
+
+/**
+ * Enumeration of the JCR 2.0 query operators.
+ *
+ * @since Apache Jackrabbit 2.0
+ */
+public enum Operator {
+
+    EQ(QueryObjectModelConstants.JCR_OPERATOR_EQUAL_TO, "="),
+
+    NE(QueryObjectModelConstants.JCR_OPERATOR_NOT_EQUAL_TO, "!=", "<>"),
+
+    GT(QueryObjectModelConstants.JCR_OPERATOR_GREATER_THAN, ">"),
+
+    GE(QueryObjectModelConstants.JCR_OPERATOR_GREATER_THAN_OR_EQUAL_TO, ">="),
+
+    LT(QueryObjectModelConstants.JCR_OPERATOR_LESS_THAN, "<"),
+
+    LE(QueryObjectModelConstants.JCR_OPERATOR_LESS_THAN_OR_EQUAL_TO, "<="),
+
+    LIKE(QueryObjectModelConstants.JCR_OPERATOR_LIKE, null, "like");
+
+    /**
+     * JCR name of this operator.
+     */
+    private final String name;
+
+    /**
+     * This operator in XPath syntax.
+     */
+    private final String xpath;
+
+    /**
+     * This operator in SQL syntax.
+     */
+    private final String sql;
+
+    Operator(String name, String op) {
+        this(name, op, op);
+    }
+
+    Operator(String name, String xpath, String sql) {
+        this.name = name;
+        this.xpath = xpath;
+        this.sql = sql;
+    }
+
+    /**
+     * Returns a comparison between the given operands using this operator.
+     *
+     * @param factory factory for creating the comparison
+     * @param left operand on the left hand side
+     * @param right operand on the right hand side
+     * @return comparison
+     * @throws RepositoryException if the comparison can not be created
+     */
+    public Comparison comparison(
+            QueryObjectModelFactory factory,
+            DynamicOperand left, StaticOperand right)
+            throws RepositoryException {
+        return factory.comparison(left, name, right);
+    }
+
+    /**
+     * Formats an XPath constraint with this operator and the given operands.
+     * The operands are simply used as-is, without any quoting or escaping.
+     *
+     * @param a first operand
+     * @param b second operand
+     * @return XPath constraint, {@code a op b} or
+     *         {@code jcr:like(a, b)} for {@link #LIKE}
+     */
+    public String formatXpath(String a, String b) {
+        if (this == LIKE) {
+            return "jcr:like(" + a + ", " + b + ')';
+        } else {
+            return a + ' ' + xpath + ' ' + b;
+        }
+    }
+
+    /**
+     * Formats an SQL constraint with this operator and the given operands.
+     * The operands are simply used as-is, without any quoting or escaping.
+     *
+     * @param a first operand
+     * @param b second operand
+     * @return SQL constraint, {@code a op b}
+     */
+    public String formatSql(String a, String b) {
+        return a + ' ' + sql + ' ' + b;
+    }
+
+    /**
+     * Returns the JCR 2.0 name of this query operator.
+     *
+     * @see QueryObjectModelConstants
+     * @return JCR name of this operator
+     */
+    @Override
+    public String toString() {
+        return name;
+    }
+
+    /**
+     * Returns an array of the names of all the JCR 2.0 query operators.
+     *
+     * @return names of all query operators
+     */
+    public static String[] getAllQueryOperators() {
+        return new String[] {
+                EQ.toString(),
+                NE.toString(),
+                GT.toString(),
+                GE.toString(),
+                LT.toString(),
+                LE.toString(),
+                LIKE.toString()
+        };
+    }
+
+    /**
+     * Returns the operator with the given JCR name.
+     *
+     * @param name JCR name of an operator
+     * @return operator with the given name
+     */
+    public static Operator getOperatorByName(String name) {
+        for (Operator operator : Operator.values()) {
+            if (operator.name.equals(name)) {
+                return operator;
+            }
+        }
+        throw new IllegalArgumentException("Unknown operator name: " + name);
+    }
+
+}

Added: jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/query/qom/OrImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/query/qom/OrImpl.java?rev=1302895&view=auto
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/query/qom/OrImpl.java (added)
+++ jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/query/qom/OrImpl.java Tue Mar 20 13:49:47 2012
@@ -0,0 +1,57 @@
+/*
+ * 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.jackrabbit.oak.jcr.query.qom;
+
+import javax.jcr.query.qom.Or;
+
+/**
+ * The implementation of the corresponding JCR interface.
+ */
+public class OrImpl extends ConstraintImpl implements Or {
+
+    private final ConstraintImpl constraint1;
+    private final ConstraintImpl constraint2;
+
+    public OrImpl(ConstraintImpl constraint1, ConstraintImpl constraint2) {
+        this.constraint1 = constraint1;
+        this.constraint2 = constraint2;
+    }
+
+    @Override
+    public ConstraintImpl getConstraint1() {
+        return constraint1;
+    }
+
+    @Override
+    public ConstraintImpl getConstraint2() {
+        return constraint2;
+    }
+
+    @Override
+    public String toString() {
+        return protect(constraint1) + " OR " + protect(constraint2);
+    }
+
+    @Override
+    public void bindVariables(QueryObjectModelImpl qom) {
+        constraint1.bindVariables(qom);
+        constraint2.bindVariables(qom);
+    }
+
+}

Added: jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/query/qom/Order.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/query/qom/Order.java?rev=1302895&view=auto
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/query/qom/Order.java (added)
+++ jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/query/qom/Order.java Tue Mar 20 13:49:47 2012
@@ -0,0 +1,64 @@
+/*
+ * 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.jackrabbit.oak.jcr.query.qom;
+
+import javax.jcr.query.qom.QueryObjectModelConstants;
+
+/**
+ * Enumeration of the JCR 2.0 query order.
+ *
+ * @since Apache Jackrabbit 2.0
+ */
+public enum Order {
+
+    ASCENDING(QueryObjectModelConstants.JCR_ORDER_ASCENDING),
+
+    DESCENDING(QueryObjectModelConstants.JCR_ORDER_DESCENDING);
+
+    /**
+     * JCR name of this order.
+     */
+    private final String name;
+
+    Order(String name) {
+        this.name = name;
+    }
+
+    /**
+     * @return the JCR name of this order.
+     */
+    public String getName() {
+        return name;
+    }
+
+    /**
+     * Return the order with the given JCR name.
+     *
+     * @param name the JCR name of an order.
+     * @return the order with the given name.
+     * @throws IllegalArgumentException if {@code name} is not a known JCR
+     *                                  order name.
+     */
+    public static Order getOrderByName(String name) {
+        for (Order order : Order.values()) {
+            if (order.name.equals(name)) {
+                return order;
+            }
+        }
+        throw new IllegalArgumentException("Unknown order name: " + name);
+    }
+}

Added: jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/query/qom/OrderingImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/query/qom/OrderingImpl.java?rev=1302895&view=auto
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/query/qom/OrderingImpl.java (added)
+++ jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/query/qom/OrderingImpl.java Tue Mar 20 13:49:47 2012
@@ -0,0 +1,55 @@
+/*
+ * 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.jackrabbit.oak.jcr.query.qom;
+
+import javax.jcr.query.qom.Ordering;
+
+/**
+ * The implementation of the corresponding JCR interface.
+ */
+public class OrderingImpl extends QOMNode implements Ordering {
+
+    private final DynamicOperandImpl operand;
+    private final Order order;
+
+    public OrderingImpl(DynamicOperandImpl operand, Order order) {
+        this.operand = operand;
+        this.order = order;
+    }
+
+    @Override
+    public DynamicOperandImpl getOperand() {
+        return operand;
+    }
+
+    @Override
+    public String getOrder() {
+        return order.getName();
+    }
+
+    @Override
+    public String toString() {
+        if (order == Order.ASCENDING) {
+            return operand + " ASC";
+        } else {
+            return operand + " DESC";
+        }
+    }
+
+}

Added: jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/query/qom/PropertyExistenceImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/query/qom/PropertyExistenceImpl.java?rev=1302895&view=auto
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/query/qom/PropertyExistenceImpl.java (added)
+++ jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/query/qom/PropertyExistenceImpl.java Tue Mar 20 13:49:47 2012
@@ -0,0 +1,57 @@
+/*
+ * 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.jackrabbit.oak.jcr.query.qom;
+
+import javax.jcr.query.qom.PropertyExistence;
+
+/**
+ * The implementation of the corresponding JCR interface.
+ */
+public class PropertyExistenceImpl extends ConstraintImpl implements PropertyExistence {
+
+    private final String selectorName;
+    private final String propertyName;
+
+    public PropertyExistenceImpl(String selectorName, String propertyName) {
+        this.selectorName = selectorName;
+        this.propertyName = propertyName;
+    }
+
+    @Override
+    public String getPropertyName() {
+        return propertyName;
+    }
+
+    @Override
+    public String getSelectorName() {
+        return selectorName;
+    }
+
+    @Override
+    public String toString() {
+        // TODO quote property names?
+        return getSelectorName() + '.' + propertyName + " IS NOT NULL";
+    }
+
+    @Override
+    public void bindVariables(QueryObjectModelImpl qom) {
+        // ignore
+    }
+
+}

Added: jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/query/qom/PropertyValueImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/query/qom/PropertyValueImpl.java?rev=1302895&view=auto
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/query/qom/PropertyValueImpl.java (added)
+++ jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/query/qom/PropertyValueImpl.java Tue Mar 20 13:49:47 2012
@@ -0,0 +1,52 @@
+/*
+ * 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.jackrabbit.oak.jcr.query.qom;
+
+import javax.jcr.query.qom.PropertyValue;
+
+/**
+ * The implementation of the corresponding JCR interface.
+ */
+public class PropertyValueImpl extends DynamicOperandImpl implements PropertyValue {
+
+    private final String selectorName;
+    private final String propertyName;
+
+    public PropertyValueImpl(String selectorName, String propertyName) {
+        this.selectorName = selectorName;
+        this.propertyName = propertyName;
+    }
+
+    @Override
+    public String getSelectorName() {
+        return selectorName;
+    }
+
+    @Override
+    public String getPropertyName() {
+        return propertyName;
+    }
+
+    @Override
+    public String toString() {
+        // TODO quote property names?
+        return getSelectorName() + '.' + propertyName;
+    }
+
+}

Added: jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/query/qom/QOMNode.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/query/qom/QOMNode.java?rev=1302895&view=auto
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/query/qom/QOMNode.java (added)
+++ jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/query/qom/QOMNode.java Tue Mar 20 13:49:47 2012
@@ -0,0 +1,37 @@
+/*
+ * 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.jackrabbit.oak.jcr.query.qom;
+
+abstract class QOMNode {
+
+    protected String protect(Object expression) {
+        String str = expression.toString();
+        if (str.indexOf(' ') >= 0) {
+            return '(' + str + ')';
+        } else {
+            return str;
+        }
+    }
+
+    protected String quotePath(String path) {
+        return '[' + path + ']';
+    }
+
+}
+

Added: jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/query/qom/QOMVisitor.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/query/qom/QOMVisitor.java?rev=1302895&view=auto
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/query/qom/QOMVisitor.java (added)
+++ jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/query/qom/QOMVisitor.java Tue Mar 20 13:49:47 2012
@@ -0,0 +1,75 @@
+/*
+ * 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.jackrabbit.oak.jcr.query.qom;
+
+public interface QOMVisitor {
+
+    boolean visit(AndImpl node);
+
+    boolean visit(BindVariableValueImpl node);
+
+    boolean visit(ChildNodeImpl node);
+
+    boolean visit(ChildNodeJoinConditionImpl node);
+
+    boolean visit(ColumnImpl node);
+
+    boolean visit(ComparisonImpl node);
+
+    boolean visit(DescendantNodeImpl node);
+
+    boolean visit(DescendantNodeJoinConditionImpl node);
+
+    boolean visit(EquiJoinConditionImpl node);
+
+    boolean visit(FullTextSearchImpl node);
+
+    boolean visit(FullTextSearchScoreImpl node);
+
+    boolean visit(JoinImpl node);
+
+    boolean visit(LengthImpl node);
+
+    boolean visit(LiteralImpl node);
+
+    boolean visit(LowerCaseImpl node);
+
+    boolean visit(NodeLocalNameImpl node);
+
+    boolean visit(NodeNameImpl node);
+
+    boolean visit(NotImpl node);
+
+    boolean visit(OrderingImpl node);
+
+    boolean visit(OrImpl node);
+
+    boolean visit(PropertyExistenceImpl node);
+
+    boolean visit(PropertyValueImpl node);
+
+    boolean visit(SameNodeImpl node);
+
+    boolean visit(SameNodeJoinConditionImpl node);
+
+    boolean visit(SelectorImpl node);
+
+    boolean visit(UpperCaseImpl node);
+
+}
\ No newline at end of file

Added: jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/query/qom/QueryObjectModelFactoryImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/query/qom/QueryObjectModelFactoryImpl.java?rev=1302895&view=auto
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/query/qom/QueryObjectModelFactoryImpl.java (added)
+++ jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/query/qom/QueryObjectModelFactoryImpl.java Tue Mar 20 13:49:47 2012
@@ -0,0 +1,179 @@
+/*
+ * 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.jackrabbit.oak.jcr.query.qom;
+
+import javax.jcr.Value;
+import javax.jcr.query.qom.ChildNode;
+import javax.jcr.query.qom.ChildNodeJoinCondition;
+import javax.jcr.query.qom.Column;
+import javax.jcr.query.qom.Comparison;
+import javax.jcr.query.qom.Constraint;
+import javax.jcr.query.qom.DescendantNode;
+import javax.jcr.query.qom.DescendantNodeJoinCondition;
+import javax.jcr.query.qom.DynamicOperand;
+import javax.jcr.query.qom.EquiJoinCondition;
+import javax.jcr.query.qom.FullTextSearch;
+import javax.jcr.query.qom.FullTextSearchScore;
+import javax.jcr.query.qom.Join;
+import javax.jcr.query.qom.JoinCondition;
+import javax.jcr.query.qom.Length;
+import javax.jcr.query.qom.Literal;
+import javax.jcr.query.qom.LowerCase;
+import javax.jcr.query.qom.NodeLocalName;
+import javax.jcr.query.qom.NodeName;
+import javax.jcr.query.qom.Not;
+import javax.jcr.query.qom.Or;
+import javax.jcr.query.qom.Ordering;
+import javax.jcr.query.qom.PropertyExistence;
+import javax.jcr.query.qom.PropertyValue;
+import javax.jcr.query.qom.QueryObjectModel;
+import javax.jcr.query.qom.QueryObjectModelFactory;
+import javax.jcr.query.qom.SameNode;
+import javax.jcr.query.qom.SameNodeJoinCondition;
+import javax.jcr.query.qom.Selector;
+import javax.jcr.query.qom.Source;
+import javax.jcr.query.qom.StaticOperand;
+import javax.jcr.query.qom.UpperCase;
+
+/**
+ * The implementation of the corresponding JCR interface.
+ */
+public class QueryObjectModelFactoryImpl implements QueryObjectModelFactory {
+
+    public AndImpl and(Constraint constraint1, Constraint constraint2) {
+        return new AndImpl((ConstraintImpl) constraint1, (ConstraintImpl) constraint2);
+    }
+
+    public OrderingImpl ascending(DynamicOperand operand) {
+        return new OrderingImpl((DynamicOperandImpl) operand, Order.ASCENDING);
+    }
+
+    public BindVariableValueImpl bindVariable(String bindVariableName) {
+        return new BindVariableValueImpl(bindVariableName);
+    }
+
+    public ChildNode childNode(String selectorName, String path) {
+        return new ChildNodeImpl(selectorName, path);
+    }
+
+    public ChildNodeJoinCondition childNodeJoinCondition(String childSelectorName, String parentSelectorName)
+            {
+        return new ChildNodeJoinConditionImpl(childSelectorName, parentSelectorName);
+    }
+
+    public Column column(String selectorName, String propertyName, String columnName) {
+        return new ColumnImpl(selectorName, propertyName, columnName);
+    }
+
+    public Comparison comparison(DynamicOperand operand1, String operator, StaticOperand operand2)
+            {
+        return new ComparisonImpl((DynamicOperandImpl) operand1, Operator.getOperatorByName(operator), (StaticOperandImpl) operand2);
+    }
+
+    public DescendantNode descendantNode(String selectorName, String path) {
+        return new DescendantNodeImpl(selectorName, path);
+    }
+
+    public DescendantNodeJoinCondition descendantNodeJoinCondition(String descendantSelectorName,
+            String ancestorSelectorName) {
+        return new DescendantNodeJoinConditionImpl(descendantSelectorName, ancestorSelectorName);
+    }
+
+    public Ordering descending(DynamicOperand operand) {
+        return new OrderingImpl((DynamicOperandImpl) operand, Order.DESCENDING);
+    }
+
+    public EquiJoinCondition equiJoinCondition(String selector1Name, String property1Name, String selector2Name,
+            String property2Name) {
+        return new EquiJoinConditionImpl(selector1Name, property1Name, selector2Name, property2Name);
+    }
+
+    public FullTextSearch fullTextSearch(String selectorName, String propertyName,
+            StaticOperand fullTextSearchExpression) {
+        return new FullTextSearchImpl(selectorName, propertyName, (StaticOperandImpl) fullTextSearchExpression);
+    }
+
+    public FullTextSearchScore fullTextSearchScore(String selectorName) {
+        return new FullTextSearchScoreImpl(selectorName);
+    }
+
+    public Join join(Source left, Source right, String joinType, JoinCondition joinCondition) {
+        return new JoinImpl((SourceImpl) left, (SourceImpl) right, JoinType.getJoinTypeByName(joinType), (JoinConditionImpl) joinCondition);
+    }
+
+    public Length length(PropertyValue propertyValue) {
+        return new LengthImpl((PropertyValueImpl) propertyValue);
+    }
+
+    public Literal literal(Value literalValue) {
+        return new LiteralImpl(literalValue);
+    }
+
+    public LowerCase lowerCase(DynamicOperand operand) {
+        return new LowerCaseImpl((DynamicOperandImpl) operand);
+    }
+
+    public NodeLocalName nodeLocalName(String selectorName) {
+        return new NodeLocalNameImpl(selectorName);
+    }
+
+    public NodeName nodeName(String selectorName) {
+        return new NodeNameImpl(selectorName);
+    }
+
+    public Not not(Constraint constraint) {
+        return new NotImpl((ConstraintImpl) constraint);
+    }
+
+    public Or or(Constraint constraint1, Constraint constraint2) {
+        return new OrImpl((ConstraintImpl) constraint1, (ConstraintImpl) constraint2);
+    }
+
+    public PropertyExistence propertyExistence(String selectorName, String propertyName) {
+        return new PropertyExistenceImpl(selectorName, propertyName);
+    }
+
+    @Override
+    public PropertyValue propertyValue(String selectorName, String propertyName) {
+        return new PropertyValueImpl(selectorName, propertyName);
+    }
+
+    @Override
+    public SameNode sameNode(String selectorName, String path) {
+        return new SameNodeImpl(selectorName, path);
+    }
+
+    @Override
+    public SameNodeJoinCondition sameNodeJoinCondition(String selector1Name, String selector2Name, String selector2Path) {
+        return new SameNodeJoinConditionImpl(selector1Name, selector2Name, selector2Path);
+    }
+
+    @Override
+    public Selector selector(String nodeTypeName, String selectorName) {
+        return new SelectorImpl(nodeTypeName, selectorName);
+    }
+
+    @Override
+    public UpperCase upperCase(DynamicOperand operand) {
+        return new UpperCaseImpl((DynamicOperandImpl) operand);
+    }
+
+    @Override
+    public QueryObjectModel createQuery(Source source, Constraint constraint, Ordering[] orderings, Column[] columns) {
+        QueryObjectModelImpl qom = new QueryObjectModelImpl(source, constraint, orderings, columns);
+        qom.bindVariables();
+        return qom;
+    }
+
+}