You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jackrabbit.apache.org by mr...@apache.org on 2009/04/27 14:43:31 UTC

svn commit: r768954 [2/4] - in /jackrabbit/trunk: jackrabbit-api/src/main/java/org/apache/jackrabbit/api/jsr283/query/ jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/ jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query...

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/Util.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/Util.java?rev=768954&r1=768953&r2=768954&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/Util.java (original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/Util.java Mon Apr 27 12:43:28 2009
@@ -21,12 +21,19 @@
 import org.apache.lucene.search.Query;
 import org.apache.lucene.index.Term;
 import org.apache.lucene.index.IndexReader;
+import org.apache.jackrabbit.core.value.InternalValue;
 import org.slf4j.LoggerFactory;
 import org.slf4j.Logger;
 
 import java.util.Iterator;
+import java.util.regex.Pattern;
 import java.io.IOException;
 
+import javax.jcr.PropertyType;
+import javax.jcr.Value;
+import javax.jcr.ValueFormatException;
+import javax.jcr.RepositoryException;
+
 /**
  * <code>Util</code> provides various static utility methods.
  */
@@ -125,4 +132,217 @@
             reader.close();
         }
     }
+
+    /**
+     * Returns a comparable for the internal <code>value</code>.
+     *
+     * @param value an internal value.
+     * @return a comparable for the given <code>value</code>.
+     */
+    public static Comparable getComparable(InternalValue value) {
+        switch (value.getType()) {
+            case PropertyType.BINARY:
+                return null;
+            case PropertyType.BOOLEAN:
+                return ComparableBoolean.valueOf(value.getBoolean());
+            case PropertyType.DATE:
+                return new Long(value.getDate().getTimeInMillis());
+            case PropertyType.DOUBLE:
+                return new Double(value.getDouble());
+            case PropertyType.LONG:
+                return new Long(value.getLong());
+            case PropertyType.NAME:
+                return value.getQName().toString();
+            case PropertyType.PATH:
+                return value.getPath().toString();
+            case PropertyType.REFERENCE:
+            case PropertyType.STRING:
+                return value.getString();
+            // TODO: JSR 283 now node types
+            default:
+                return null;
+        }
+    }
+
+    /**
+     * Returns a comparable for the internal <code>value</code>.
+     *
+     * @param value an internal value.
+     * @return a comparable for the given <code>value</code>.
+     * @throws ValueFormatException if the given <code>value</code> cannot be
+     *                              converted into a comparable (i.e.
+     *                              unsupported type).
+     * @throws RepositoryException  if an error occurs while converting the
+     *                              value.
+     */
+    public static Comparable getComparable(Value value)
+            throws ValueFormatException, RepositoryException {
+        switch (value.getType()) {
+            case PropertyType.BOOLEAN:
+                return ComparableBoolean.valueOf(value.getBoolean());
+            case PropertyType.DATE:
+                return new Long(value.getDate().getTimeInMillis());
+            case PropertyType.DOUBLE:
+                return new Double(value.getDouble());
+            case PropertyType.LONG:
+                return new Long(value.getLong());
+            case PropertyType.NAME:
+            case PropertyType.PATH:
+            case PropertyType.REFERENCE:
+            case PropertyType.STRING:
+                return value.getString();
+                // TODO: JSR 283 now node types
+            default:
+                throw new RepositoryException("Unsupported type: "
+                        + PropertyType.nameFromValue(value.getType()));
+        }
+    }
+
+    /**
+     * Compares values <code>c1</code> and <code>c2</code>. If the
+     * values have differing types, then the order is defined on
+     * the type itself by calling <code>compareTo()</code> on the respective
+     * type class names.
+     *
+     * @param c1 the first value.
+     * @param c2 the second value.
+     * @return a negative integer if <code>c1</code> should come before
+     *         <code>c2</code><br> a positive integer if <code>c1</code>
+     *         should come after <code>c2</code><br> <code>0</code> if they
+     *         are equal.
+     */
+    public static int compare(Comparable c1, Comparable c2) {
+        if (c1 == c2) {
+            return 0;
+        } else if (c1 == null) {
+            return -1;
+        } else if (c2 == null) {
+            return 1;
+        } else if (c1.getClass() == c2.getClass()) {
+            return c1.compareTo(c2);
+        } else {
+            // differing types -> compare class names
+            String name1 = c1.getClass().getName();
+            String name2 = c2.getClass().getName();
+            return name1.compareTo(name2);
+        }
+    }
+
+    /**
+     * Compares the two values. If the values have differing types, then an
+     * attempt is made to convert the second value into the type of the first
+     * value.
+     * <p/>
+     * Comparison of binary values is not supported.
+     *
+     * @param v1 the first value.
+     * @param v2 the second value.
+     * @return result of the comparison as specified in
+     *         {@link Comparable#compareTo(Object)}.
+     * @throws ValueFormatException if the given <code>value</code> cannot be
+     *                              converted into a comparable (i.e.
+     *                              unsupported type).
+     * @throws RepositoryException  if an error occurs while converting the
+     *                              value.
+     */
+    public static int compare(Value v1, Value v2)
+            throws ValueFormatException, RepositoryException {
+        Comparable c1 = getComparable(v1);
+        Comparable c2;
+        switch (v1.getType()) {
+            case PropertyType.BOOLEAN:
+                c2 = ComparableBoolean.valueOf(v2.getBoolean());
+                break;
+            case PropertyType.DATE:
+                c2 = new Long(v2.getDate().getTimeInMillis());
+                break;
+            case PropertyType.DOUBLE:
+                c2 = new Double(v2.getDouble());
+                break;
+            case PropertyType.LONG:
+                c2 = new Long(v2.getLong());
+                break;
+            case PropertyType.NAME:
+            case PropertyType.PATH:
+            case PropertyType.REFERENCE:
+            case PropertyType.STRING:
+                c2 = v2.getString();
+                break;
+                // TODO: JSR 283 now node types
+            default:
+                throw new RepositoryException("Unsupported type: "
+                        + PropertyType.nameFromValue(v2.getType()));
+        }
+        return compare(c1, c2);
+    }
+
+    /**
+     * Creates a regexp from <code>likePattern</code>.
+     *
+     * @param likePattern the pattern.
+     * @return the regular expression <code>Pattern</code>.
+     */
+    public static Pattern createRegexp(String likePattern) {
+        // - escape all non alphabetic characters
+        // - escape constructs like \<alphabetic char> into \\<alphabetic char>
+        // - replace non escaped _ % into . and .*
+        StringBuffer regexp = new StringBuffer();
+        boolean escaped = false;
+        for (int i = 0; i < likePattern.length(); i++) {
+            if (likePattern.charAt(i) == '\\') {
+                if (escaped) {
+                    regexp.append("\\\\");
+                    escaped = false;
+                } else {
+                    escaped = true;
+                }
+            } else {
+                if (Character.isLetterOrDigit(likePattern.charAt(i))) {
+                    if (escaped) {
+                        regexp.append("\\\\").append(likePattern.charAt(i));
+                        escaped = false;
+                    } else {
+                        regexp.append(likePattern.charAt(i));
+                    }
+                } else {
+                    if (escaped) {
+                        regexp.append('\\').append(likePattern.charAt(i));
+                        escaped = false;
+                    } else {
+                        switch (likePattern.charAt(i)) {
+                            case '_':
+                                regexp.append('.');
+                                break;
+                            case '%':
+                                regexp.append(".*");
+                                break;
+                            default:
+                                regexp.append('\\').append(likePattern.charAt(i));
+                        }
+                    }
+                }
+            }
+        }
+        return Pattern.compile(regexp.toString(), Pattern.DOTALL);
+    }
+
+    /**
+     * Returns length of the internal value.
+     *
+     * @param value a value.
+     * @return the length of the internal value or <code>-1</code> if the length
+     *         cannot be determined.
+     */
+    public static long getLength(InternalValue value) {
+        // TODO: support new JSR 283 property types
+        if (value.getType() == PropertyType.BINARY) {
+            return value.getBLOBFileValue().getLength();
+        } else
+        if (value.getType() == PropertyType.NAME
+                || value.getType() == PropertyType.PATH) {
+            return -1;
+        } else {
+            return value.toString().length();
+        }
+    }
 }

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/WildcardTermEnum.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/WildcardTermEnum.java?rev=768954&r1=768953&r2=768954&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/WildcardTermEnum.java (original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/WildcardTermEnum.java Mon Apr 27 12:43:28 2009
@@ -22,7 +22,6 @@
 import org.apache.lucene.search.FilteredTermEnum;
 
 import java.io.IOException;
-import java.util.regex.Pattern;
 import java.util.regex.Matcher;
 import java.util.Map;
 import java.util.LinkedHashMap;
@@ -113,7 +112,7 @@
 
         // initialize with prefix as dummy value
         input = new OffsetCharSequence(prefix.length(), prefix, transform);
-        this.pattern = createRegexp(pattern.substring(idx)).matcher(input);
+        this.pattern = Util.createRegexp(pattern.substring(idx)).matcher(input);
 
         if (transform == TRANSFORM_NONE) {
             setEnum(reader.terms(new Term(field, prefix)));
@@ -156,56 +155,6 @@
     //--------------------------< internal >------------------------------------
 
     /**
-     * Creates a regexp from <code>likePattern</code>.
-     *
-     * @param likePattern the pattern.
-     * @return the regular expression <code>Pattern</code>.
-     */
-    private Pattern createRegexp(String likePattern) {
-        // - escape all non alphabetic characters
-        // - escape constructs like \<alphabetic char> into \\<alphabetic char>
-        // - replace non escaped _ % into . and .*
-        StringBuffer regexp = new StringBuffer();
-        boolean escaped = false;
-        for (int i = 0; i < likePattern.length(); i++) {
-            if (likePattern.charAt(i) == '\\') {
-                if (escaped) {
-                    regexp.append("\\\\");
-                    escaped = false;
-                } else {
-                    escaped = true;
-                }
-            } else {
-                if (Character.isLetterOrDigit(likePattern.charAt(i))) {
-                    if (escaped) {
-                        regexp.append("\\\\").append(likePattern.charAt(i));
-                        escaped = false;
-                    } else {
-                        regexp.append(likePattern.charAt(i));
-                    }
-                } else {
-                    if (escaped) {
-                        regexp.append('\\').append(likePattern.charAt(i));
-                        escaped = false;
-                    } else {
-                        switch (likePattern.charAt(i)) {
-                            case '_':
-                                regexp.append('.');
-                                break;
-                            case '%':
-                                regexp.append(".*");
-                                break;
-                            default:
-                                regexp.append('\\').append(likePattern.charAt(i));
-                        }
-                    }
-                }
-            }
-        }
-        return Pattern.compile(regexp.toString(), Pattern.DOTALL);
-    }
-
-    /**
      * Implements a term enum which respects the transformation flag and
      * matches a pattern on the enumerated terms.
      */

Added: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/constraint/AndConstraint.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/constraint/AndConstraint.java?rev=768954&view=auto
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/constraint/AndConstraint.java (added)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/constraint/AndConstraint.java Mon Apr 27 12:43:28 2009
@@ -0,0 +1,60 @@
+/*
+ * 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.core.query.lucene.constraint;
+
+import java.io.IOException;
+
+import org.apache.jackrabbit.core.query.lucene.ScoreNode;
+import org.apache.jackrabbit.spi.Name;
+
+/**
+ * <code>AndConstraint</code> implements an AND constraint.
+ */
+public class AndConstraint implements Constraint {
+
+    /**
+     * The left operand.
+     */
+    private final Constraint left;
+
+    /**
+     * The right operand.
+     */
+    private final Constraint right;
+
+    /**
+     * Creates a new AND constraint.
+     *
+     * @param left the left operand.
+     * @param right the right operand.
+     */
+    public AndConstraint(Constraint left, Constraint right) {
+        this.left = left;
+        this.right = right;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public boolean evaluate(ScoreNode[] row,
+                            Name[] selectorNames,
+                            EvaluationContext context)
+            throws IOException {
+        return left.evaluate(row, selectorNames, context)
+                && right.evaluate(row, selectorNames, context);
+    }
+}

Propchange: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/constraint/AndConstraint.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/constraint/ChildNodeConstraint.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/constraint/ChildNodeConstraint.java?rev=768954&view=auto
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/constraint/ChildNodeConstraint.java (added)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/constraint/ChildNodeConstraint.java Mon Apr 27 12:43:28 2009
@@ -0,0 +1,67 @@
+/*
+ * 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.core.query.lucene.constraint;
+
+import java.io.IOException;
+
+import javax.jcr.RepositoryException;
+
+import org.apache.jackrabbit.spi.commons.query.qom.ChildNodeImpl;
+import org.apache.jackrabbit.spi.commons.query.qom.SelectorImpl;
+import org.apache.jackrabbit.spi.Name;
+import org.apache.jackrabbit.core.query.lucene.ScoreNode;
+import org.apache.jackrabbit.core.SessionImpl;
+import org.apache.jackrabbit.core.NodeImpl;
+
+/**
+ * <code>ChildNodeConstraint</code> implements a child node constraint.
+ */
+public class ChildNodeConstraint extends HierarchyConstraint {
+
+    /**
+     * Creates a child node constraint from the given QOM
+     * <code>constraint</code> on the given <code>selector</code>.
+     *
+     * @param constraint the QOM child node constraint.
+     * @param selector   the selector.
+     */
+    public ChildNodeConstraint(ChildNodeImpl constraint,
+                               SelectorImpl selector) {
+        super(constraint.getPath(), selector);
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public boolean evaluate(ScoreNode[] row,
+                            Name[] selectorNames,
+                            EvaluationContext context)
+            throws IOException {
+        ScoreNode sn = row[getSelectorIndex(selectorNames)];
+        if (sn == null) {
+            return false;
+        }
+        SessionImpl session = context.getSession();
+        NodeImpl parent;
+        try {
+            parent = (NodeImpl) session.getNodeById(sn.getNodeId()).getParent();
+        } catch (RepositoryException e) {
+            return false;
+        }
+        return parent.getId().equals(getBaseNodeId(context));
+    }
+}

Propchange: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/constraint/ChildNodeConstraint.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/constraint/ComparisonConstraint.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/constraint/ComparisonConstraint.java?rev=768954&view=auto
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/constraint/ComparisonConstraint.java (added)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/constraint/ComparisonConstraint.java Mon Apr 27 12:43:28 2009
@@ -0,0 +1,121 @@
+/*
+ * 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.core.query.lucene.constraint;
+
+import java.io.IOException;
+
+import javax.jcr.Value;
+import javax.jcr.RepositoryException;
+
+import org.apache.jackrabbit.spi.commons.query.jsr283.qom.QueryObjectModelConstants;
+import org.apache.jackrabbit.spi.commons.query.qom.SelectorImpl;
+import org.apache.jackrabbit.spi.Name;
+import org.apache.jackrabbit.core.query.lucene.ScoreNode;
+import org.apache.jackrabbit.core.query.lucene.Util;
+
+/**
+ * <code>ComparisonConstraint</code> implements a comparison constraint.
+ */
+public class ComparisonConstraint extends SelectorBasedConstraint
+        implements QueryObjectModelConstants {
+
+    /**
+     * The dynamic operand.
+     */
+    private final DynamicOperand operand1;
+
+    /**
+     * The operator.
+     */
+    private final int operator;
+
+    /**
+     * The static operand.
+     */
+    private final Value operand2;
+
+    /**
+     * Creates a new comparision constraint.
+     *
+     * @param operand1 the dynamic operand.
+     * @param operator the operator.
+     * @param operand2 the static operand.
+     * @param selector the selector for this constraint.
+     */
+    public ComparisonConstraint(DynamicOperand operand1,
+                                int operator,
+                                Value operand2,
+                                SelectorImpl selector) {
+        super(selector);
+        this.operand1 = operand1;
+        this.operator = operator;
+        this.operand2 = operand2;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public boolean evaluate(ScoreNode[] row,
+                            Name[] selectorNames,
+                            EvaluationContext context)
+            throws IOException {
+        ScoreNode sn = row[getSelectorIndex(selectorNames)];
+        if (sn == null) {
+            return false;
+        }
+        Value[] values = operand1.getValues(sn, context);
+        try {
+            for (int i = 0; i < values.length; i++) {
+                if (evaluate(values[i])) {
+                    return true;
+                }
+            }
+        } catch (RepositoryException e) {
+            throw Util.createIOException(e);
+        }
+        return false;
+    }
+
+    /**
+     * Evaluates this constraint for the given dynamic operand value
+     * <code>op1</code>.
+     *
+     * @param op1 the current value of the dynamic operand.
+     * @return <code>true</code> if the given value satisfies the constraint.
+     * @throws RepositoryException if an error occurs while converting the
+     *                             values.
+     */
+    protected boolean evaluate(Value op1) throws RepositoryException {
+        int c = Util.compare(op1, operand2);
+        switch (operator) {
+            case OPERATOR_EQUAL_TO:
+                return c == 0;
+            case OPERATOR_GREATER_THAN:
+                return c > 0;
+            case OPERATOR_GREATER_THAN_OR_EQUAL_TO:
+                return c >= 0;
+            case OPERATOR_LESS_THAN:
+                return c < 0;
+            case OPERATOR_LESS_THAN_OR_EQUAL_TO:
+                return c <= 0;
+            case OPERATOR_NOT_EQUAL_TO:
+                return c != 0;
+            default:
+                throw new IllegalStateException("unsupported operation: " + operator);
+        }
+    }
+}

Propchange: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/constraint/ComparisonConstraint.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/constraint/Constraint.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/constraint/Constraint.java?rev=768954&view=auto
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/constraint/Constraint.java (added)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/constraint/Constraint.java Mon Apr 27 12:43:28 2009
@@ -0,0 +1,42 @@
+/*
+ * 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.core.query.lucene.constraint;
+
+import java.io.IOException;
+
+import org.apache.jackrabbit.core.query.lucene.ScoreNode;
+import org.apache.jackrabbit.spi.Name;
+
+/**
+ * <code>Constraint</code> defines an interface for a QOM constraint.
+ */
+public interface Constraint {
+
+    /**
+     * Evaluates this constraint for the given row.
+     *
+     * @param row           the current row of score nodes.
+     * @param selectorNames the selector names associated with <code>row</code>.
+     * @param context       the evaluation context.
+     * @return <code>true</code> if the row satisfies the constraint,
+     *         <code>false</code> otherwise.
+     * @throws IOException if an error occurs while evaluating the constraint.
+     */
+    public boolean evaluate(ScoreNode[] row,
+                            Name[] selectorNames,
+                            EvaluationContext context) throws IOException;
+}

Propchange: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/constraint/Constraint.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/constraint/ConstraintBuilder.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/constraint/ConstraintBuilder.java?rev=768954&view=auto
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/constraint/ConstraintBuilder.java (added)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/constraint/ConstraintBuilder.java Mon Apr 27 12:43:28 2009
@@ -0,0 +1,342 @@
+/*
+ * 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.core.query.lucene.constraint;
+
+import java.util.Map;
+
+import javax.jcr.RepositoryException;
+import javax.jcr.Value;
+import javax.jcr.PropertyType;
+import javax.jcr.ValueFormatException;
+import javax.jcr.ValueFactory;
+import javax.jcr.query.InvalidQueryException;
+
+import org.apache.jackrabbit.spi.commons.query.qom.ConstraintImpl;
+import org.apache.jackrabbit.spi.commons.query.qom.QOMTreeVisitor;
+import org.apache.jackrabbit.spi.commons.query.qom.AndImpl;
+import org.apache.jackrabbit.spi.commons.query.qom.BindVariableValueImpl;
+import org.apache.jackrabbit.spi.commons.query.qom.ChildNodeImpl;
+import org.apache.jackrabbit.spi.commons.query.qom.ChildNodeJoinConditionImpl;
+import org.apache.jackrabbit.spi.commons.query.qom.ColumnImpl;
+import org.apache.jackrabbit.spi.commons.query.qom.ComparisonImpl;
+import org.apache.jackrabbit.spi.commons.query.qom.DescendantNodeImpl;
+import org.apache.jackrabbit.spi.commons.query.qom.DescendantNodeJoinConditionImpl;
+import org.apache.jackrabbit.spi.commons.query.qom.EquiJoinConditionImpl;
+import org.apache.jackrabbit.spi.commons.query.qom.FullTextSearchImpl;
+import org.apache.jackrabbit.spi.commons.query.qom.FullTextSearchScoreImpl;
+import org.apache.jackrabbit.spi.commons.query.qom.JoinImpl;
+import org.apache.jackrabbit.spi.commons.query.qom.LengthImpl;
+import org.apache.jackrabbit.spi.commons.query.qom.LiteralImpl;
+import org.apache.jackrabbit.spi.commons.query.qom.LowerCaseImpl;
+import org.apache.jackrabbit.spi.commons.query.qom.NodeLocalNameImpl;
+import org.apache.jackrabbit.spi.commons.query.qom.NodeNameImpl;
+import org.apache.jackrabbit.spi.commons.query.qom.NotImpl;
+import org.apache.jackrabbit.spi.commons.query.qom.OrderingImpl;
+import org.apache.jackrabbit.spi.commons.query.qom.OrImpl;
+import org.apache.jackrabbit.spi.commons.query.qom.PropertyExistenceImpl;
+import org.apache.jackrabbit.spi.commons.query.qom.PropertyValueImpl;
+import org.apache.jackrabbit.spi.commons.query.qom.QueryObjectModelTree;
+import org.apache.jackrabbit.spi.commons.query.qom.SameNodeImpl;
+import org.apache.jackrabbit.spi.commons.query.qom.SameNodeJoinConditionImpl;
+import org.apache.jackrabbit.spi.commons.query.qom.SelectorImpl;
+import org.apache.jackrabbit.spi.commons.query.qom.DynamicOperandImpl;
+import org.apache.jackrabbit.spi.commons.query.qom.StaticOperandImpl;
+import org.apache.jackrabbit.spi.commons.query.qom.UpperCaseImpl;
+import org.apache.jackrabbit.spi.commons.query.jsr283.qom.QueryObjectModelConstants;
+import org.apache.jackrabbit.spi.Name;
+import org.apache.jackrabbit.core.query.lucene.LuceneQueryFactory;
+
+/**
+ * <code>ConstraintBuilder</code> builds a {@link Constraint} from a tree of
+ * QOM constraints.
+ */
+public class ConstraintBuilder {
+
+    /**
+     * Creates a {@link Constraint} from a QOM <code>constraint</code>.
+     *
+     * @param constraint         the QOM constraint.
+     * @param bindVariableValues the map of bind variables and their respective
+     *                           value.
+     * @param selectors          the selectors of the current query.
+     * @param factory            the lucene query factory.
+     * @param vf                 the value factory of the current session.
+     * @return a {@link Constraint}.
+     * @throws RepositoryException if an error occurs while building the
+     *                             constraint.
+     */
+    public static Constraint create(ConstraintImpl constraint,
+                                    Map bindVariableValues,
+                                    SelectorImpl[] selectors,
+                                    LuceneQueryFactory factory,
+                                    ValueFactory vf)
+            throws RepositoryException {
+        try {
+            return (Constraint) constraint.accept(new Visitor(
+                    bindVariableValues, selectors, factory, vf), null);
+        } catch (RepositoryException e) {
+            throw e;
+        } catch (Exception e) {
+            throw new RepositoryException(e);
+        }
+    }
+
+    /**
+     * A QOM tree visitor that translates the contraints.
+     */
+    private static final class Visitor implements QOMTreeVisitor {
+
+        /**
+         * The bind variables and their values.
+         */
+        private final Map bindVariableValues;
+
+        /**
+         * The selectors of the query.
+         */
+        private final SelectorImpl[] selectors;
+
+        /**
+         * The lucene query builder.
+         */
+        private final LuceneQueryFactory factory;
+
+        /**
+         * The value factory of the current session.
+         */
+        private final ValueFactory vf;
+
+        /**
+         * Creates a new visitor.
+         *
+         * @param bindVariableValues the bound values.
+         * @param selectors          the selectors of the current query.
+         * @param factory            the lucene query factory.
+         * @param vf                 the value factory of the current session.
+         */
+        Visitor(Map bindVariableValues,
+                SelectorImpl[] selectors,
+                LuceneQueryFactory factory,
+                ValueFactory vf) {
+            this.bindVariableValues = bindVariableValues;
+            this.selectors = selectors;
+            this.factory = factory;
+            this.vf = vf;
+        }
+
+        public Object visit(AndImpl node, Object data) throws Exception {
+            ConstraintImpl left = (ConstraintImpl) node.getConstraint1();
+            ConstraintImpl right = (ConstraintImpl) node.getConstraint2();
+            return new AndConstraint((Constraint) left.accept(this, null),
+                    (Constraint) right.accept(this, null));
+        }
+
+        public Object visit(BindVariableValueImpl node, Object data)
+                throws Exception {
+            return bindVariableValues.get(node.getBindVariableQName());
+        }
+
+        public Object visit(ChildNodeImpl node, Object data) throws Exception {
+            return new ChildNodeConstraint(node,
+                    getSelector(node.getSelectorQName()));
+        }
+
+        public Object visit(ChildNodeJoinConditionImpl node, Object data)
+                throws Exception {
+            // not used
+            return null;
+        }
+
+        public Object visit(ColumnImpl node, Object data) throws Exception {
+            // not used
+            return null;
+        }
+
+        public Object visit(ComparisonImpl node, Object data) throws Exception {
+            DynamicOperandImpl op1 = (DynamicOperandImpl) node.getOperand1();
+            StaticOperandImpl op2 = ((StaticOperandImpl) node.getOperand2());
+            Value staticValue = (Value) op2.accept(this, null);
+
+            DynamicOperand dynOp = (DynamicOperand) op1.accept(this, staticValue);
+            SelectorImpl selector = getSelector(op1.getSelectorQName());
+            if (node.getOperator() == QueryObjectModelConstants.OPERATOR_LIKE) {
+                return new LikeConstraint(dynOp, staticValue, selector);
+            } else {
+                return new ComparisonConstraint(dynOp, node.getOperator(),
+                        staticValue, selector);
+            }
+        }
+
+        public Object visit(DescendantNodeImpl node, Object data)
+                throws Exception {
+            return new DescendantNodeConstraint(node,
+                    getSelector(node.getSelectorQName()));
+        }
+
+        public Object visit(DescendantNodeJoinConditionImpl node, Object data)
+                throws Exception {
+            // not used
+            return null;
+        }
+
+        public Object visit(EquiJoinConditionImpl node, Object data)
+                throws Exception {
+            // not used
+            return null;
+        }
+
+        public Object visit(FullTextSearchImpl node, Object data)
+                throws Exception {
+            return new FullTextConstraint(node,
+                    getSelector(node.getSelectorQName()), factory);
+        }
+
+        public Object visit(FullTextSearchScoreImpl node, Object data)
+                throws Exception {
+            // TODO
+            return null;
+        }
+
+        public Object visit(JoinImpl node, Object data) throws Exception {
+            // not used
+            return null;
+        }
+
+        public Object visit(LengthImpl node, Object data) throws Exception {
+            Value staticValue = (Value) data;
+            // make sure it can be converted to Long
+            try {
+                staticValue.getLong();
+            } catch (ValueFormatException e) {
+                throw new InvalidQueryException("Static value " +
+                        staticValue.toString() + " cannot be converted to a Long");
+            }
+            PropertyValueImpl propValue = (PropertyValueImpl) node.getPropertyValue();
+            return new LengthOperand((PropertyValueOperand) propValue.accept(this, null));
+        }
+
+        public Object visit(LiteralImpl node, Object data) throws Exception {
+            return node.getValue();
+        }
+
+        public Object visit(LowerCaseImpl node, Object data) throws Exception {
+            DynamicOperandImpl operand = (DynamicOperandImpl) node.getOperand();
+            return new LowerCaseOperand((DynamicOperand) operand.accept(this, null));
+        }
+
+        public Object visit(NodeLocalNameImpl node, Object data) throws Exception {
+            return new NodeLocalNameOperand();
+        }
+
+        public Object visit(NodeNameImpl node, Object data) throws Exception {
+            Value staticValue = (Value) data;
+            switch (staticValue.getType()) {
+                case PropertyType.STRING:
+                case PropertyType.PATH:
+                    // make sure static value is valid NAME
+                    try {
+                            vf.createValue(staticValue.getString(), PropertyType.NAME);
+                    } catch (ValueFormatException e) {
+                            throw new InvalidQueryException("Value " +
+                                staticValue.getString() +
+                                " cannot be converted into STRING");
+                    }
+                    break;
+                case PropertyType.DATE:
+                case PropertyType.DOUBLE:
+                    // TODO case PropertyType.DECIMAL:
+                case PropertyType.LONG:
+                case PropertyType.BOOLEAN:
+                case PropertyType.REFERENCE:
+                // TODO case PropertyType.WEAKREFERENCE:
+                // TODO case PropertyType.URI
+                    throw new InvalidQueryException(staticValue.getString() +
+                            " cannot be converted into a NAME value");
+            }
+
+            return new NodeNameOperand();
+        }
+
+        public Object visit(NotImpl node, Object data) throws Exception {
+            ConstraintImpl c = (ConstraintImpl) node.getConstraint();
+            return new NotConstraint((Constraint) c.accept(this, null));
+        }
+
+        public Object visit(OrderingImpl node, Object data) throws Exception {
+            // not used
+            return null;
+        }
+
+        public Object visit(OrImpl node, Object data) throws Exception {
+            ConstraintImpl left = (ConstraintImpl) node.getConstraint1();
+            ConstraintImpl right = (ConstraintImpl) node.getConstraint2();
+            return new OrConstraint((Constraint) left.accept(this, null),
+                    (Constraint) right.accept(this, null));
+        }
+
+        public Object visit(PropertyExistenceImpl node, Object data)
+                throws Exception {
+            return new PropertyExistenceConstraint(node,
+                    getSelector(node.getSelectorQName()), factory);
+        }
+
+        public Object visit(PropertyValueImpl node, Object data) throws Exception {
+            return new PropertyValueOperand(node);
+        }
+
+        public Object visit(QueryObjectModelTree node, Object data)
+                throws Exception {
+            // not used
+            return null;
+        }
+
+        public Object visit(SameNodeImpl node, Object data) throws Exception {
+            return new SameNodeConstraint(node,
+                    getSelector(node.getSelectorQName()));
+        }
+
+        public Object visit(SameNodeJoinConditionImpl node, Object data)
+                throws Exception {
+            // not used
+            return null;
+        }
+
+        public Object visit(SelectorImpl node, Object data) throws Exception {
+            // not used
+            return null;
+        }
+
+        public Object visit(UpperCaseImpl node, Object data) throws Exception {
+            DynamicOperandImpl operand = (DynamicOperandImpl) node.getOperand();
+            return new UpperCaseOperand((DynamicOperand) operand.accept(this, null));
+        }
+
+        private SelectorImpl getSelector(Name name) {
+            if (name == null) {
+                // assume default selector
+                return selectors[0];
+            }
+            for (int i = 0; i < selectors.length; i++) {
+                if (selectors[i].getSelectorQName().equals(name)) {
+                    return selectors[i];
+                }
+            }
+            return null;
+        }
+
+    }
+}

Propchange: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/constraint/ConstraintBuilder.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/constraint/DescendantNodeConstraint.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/constraint/DescendantNodeConstraint.java?rev=768954&view=auto
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/constraint/DescendantNodeConstraint.java (added)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/constraint/DescendantNodeConstraint.java Mon Apr 27 12:43:28 2009
@@ -0,0 +1,78 @@
+/*
+ * 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.core.query.lucene.constraint;
+
+import java.io.IOException;
+
+import javax.jcr.RepositoryException;
+
+import org.apache.jackrabbit.spi.commons.query.qom.DescendantNodeImpl;
+import org.apache.jackrabbit.spi.commons.query.qom.SelectorImpl;
+import org.apache.jackrabbit.spi.Name;
+import org.apache.jackrabbit.core.query.lucene.ScoreNode;
+import org.apache.jackrabbit.core.NodeImpl;
+import org.apache.jackrabbit.core.SessionImpl;
+import org.apache.jackrabbit.core.NodeId;
+
+/**
+ * <code>DescendantNodeConstraint</code> implements a descendant node
+ * constraint.
+ */
+public class DescendantNodeConstraint extends HierarchyConstraint {
+
+    /**
+     * Creates a new descendant node constraint from the given QOM constraint.
+     *
+     * @param constraint the QOM descendant node constraint.
+     * @param selector   the selector.
+     */
+    public DescendantNodeConstraint(DescendantNodeImpl constraint,
+                                    SelectorImpl selector) {
+        super(constraint.getPath(), selector);
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public boolean evaluate(ScoreNode[] row,
+                            Name[] selectorNames,
+                            EvaluationContext context)
+            throws IOException {
+        NodeId baseId = getBaseNodeId(context);
+        if (baseId == null) {
+            return false;
+        }
+        ScoreNode sn = row[getSelectorIndex(selectorNames)];
+        if (sn == null) {
+            return false;
+        }
+        NodeId id = sn.getNodeId();
+        SessionImpl session = context.getSession();
+        try {
+            NodeImpl parent = session.getNodeById(id);
+            for (;;) {
+                // throws exception if there is no parent
+                parent = (NodeImpl) parent.getParent();
+                if (parent.getId().equals(baseId)) {
+                    return true;
+                }
+            }
+        } catch (RepositoryException e) {
+            return false;
+        }
+    }
+}

Propchange: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/constraint/DescendantNodeConstraint.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/constraint/DynamicOperand.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/constraint/DynamicOperand.java?rev=768954&view=auto
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/constraint/DynamicOperand.java (added)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/constraint/DynamicOperand.java Mon Apr 27 12:43:28 2009
@@ -0,0 +1,47 @@
+/*
+ * 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.core.query.lucene.constraint;
+
+import java.io.IOException;
+
+import javax.jcr.Value;
+
+import org.apache.jackrabbit.core.query.lucene.ScoreNode;
+
+/**
+ * <code>DynamicOperand</code> is a base class for dynamic operands.
+ */
+public abstract class DynamicOperand {
+
+    /**
+     * An empty {@link Value} array.
+     */
+    protected static final Value[] EMPTY = new Value[0];
+
+    /**
+     * Returns the values for the given score node <code>sn</code> of this
+     * dynamic operand. If there are no values for the given score node, then
+     * an empty array is returned.
+     *
+     * @param sn      the current score node.
+     * @param context the evaluation context.
+     * @return the values for the given score node.
+     * @throws IOException if an error occurs while retrieving the value.
+     */
+    public abstract Value[] getValues(ScoreNode sn, EvaluationContext context)
+            throws IOException;
+}

Propchange: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/constraint/DynamicOperand.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/constraint/EvaluationContext.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/constraint/EvaluationContext.java?rev=768954&view=auto
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/constraint/EvaluationContext.java (added)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/constraint/EvaluationContext.java Mon Apr 27 12:43:28 2009
@@ -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.core.query.lucene.constraint;
+
+import java.io.IOException;
+
+import org.apache.jackrabbit.core.query.lucene.QueryHits;
+import org.apache.jackrabbit.core.SessionImpl;
+import org.apache.jackrabbit.core.state.ItemStateManager;
+import org.apache.lucene.search.Query;
+import org.apache.lucene.index.IndexReader;
+
+/**
+ * <code>EvaluationContext</code> defines a context with various resources that
+ * are needed for constraint evaluation.
+ */
+public interface EvaluationContext {
+
+    /**
+     * Evaluates the given lucene <code>query</code> and returns the query
+     * hits.
+     *
+     * @param query the lucene query to evaluate.
+     * @return the query hits for the given <code>query</code>.
+     * @throws IOException if an error occurs while reading from the index.
+     */
+    public QueryHits evaluate(Query query) throws IOException;
+
+    /**
+     * @return the index reader.
+     */
+    public IndexReader getIndexReader();
+
+    /**
+     * @return the session that executes the query.
+     */
+    public SessionImpl getSession();
+
+    /**
+     * @return the shared item state manager of the current workspace.
+     */
+    public ItemStateManager getItemStateManager();
+}

Propchange: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/constraint/EvaluationContext.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/constraint/FullTextConstraint.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/constraint/FullTextConstraint.java?rev=768954&view=auto
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/constraint/FullTextConstraint.java (added)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/constraint/FullTextConstraint.java Mon Apr 27 12:43:28 2009
@@ -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.core.query.lucene.constraint;
+
+import javax.jcr.RepositoryException;
+
+import org.apache.jackrabbit.spi.commons.query.qom.FullTextSearchImpl;
+import org.apache.jackrabbit.spi.commons.query.qom.SelectorImpl;
+import org.apache.jackrabbit.core.query.lucene.LuceneQueryFactory;
+
+/**
+ * <code>FullTextConstraint</code> implements a full text search constraint.
+ */
+public class FullTextConstraint extends QueryConstraint {
+
+    /**
+     * Creates a new full text search constraint.
+     *
+     * @param fts      the QOM constraint.
+     * @param selector the selector for this constraint.
+     * @param factory  the lucene query factory.
+     * @throws RepositoryException if an error occurs while building the query.
+     */
+    public FullTextConstraint(FullTextSearchImpl fts,
+                              SelectorImpl selector,
+                              LuceneQueryFactory factory)
+            throws RepositoryException {
+        super(factory.create(fts), selector, factory);
+    }
+}

Propchange: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/constraint/FullTextConstraint.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/constraint/HierarchyConstraint.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/constraint/HierarchyConstraint.java?rev=768954&view=auto
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/constraint/HierarchyConstraint.java (added)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/constraint/HierarchyConstraint.java Mon Apr 27 12:43:28 2009
@@ -0,0 +1,71 @@
+/*
+ * 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.core.query.lucene.constraint;
+
+import javax.jcr.RepositoryException;
+
+import org.apache.jackrabbit.spi.commons.query.qom.SelectorImpl;
+import org.apache.jackrabbit.core.NodeId;
+import org.apache.jackrabbit.core.NodeImpl;
+
+/**
+ * <code>HierarchyConstraint</code> is a base class for hierarchy related
+ * constraints.
+ */
+public abstract class HierarchyConstraint extends SelectorBasedConstraint {
+
+    /**
+     * A base path.
+     */
+    private final String path;
+
+    /**
+     * The id of the node at {@link #path}.
+     */
+    private NodeId id;
+
+    /**
+     * Creates a new hierarchy constraint with the given base
+     * <code>path</code>.
+     *
+     * @param path     the base path.
+     * @param selector the selector this constraint is placed on.
+     */
+    public HierarchyConstraint(String path, SelectorImpl selector) {
+        super(selector);
+        this.path = path;
+    }
+
+    /**
+     * Returns the id of the base node or <code>null</code> if there is no node
+     * at the base path.
+     *
+     * @param context the evaluation context.
+     * @return the id or <code>null</code> if it doesn't exist.
+     */
+    protected final NodeId getBaseNodeId(EvaluationContext context) {
+        if (id == null) {
+            try {
+                NodeImpl node = (NodeImpl) context.getSession().getNode(path);
+                id = (NodeId) node.getId();
+            } catch (RepositoryException e) {
+                return null;
+            }
+        }
+        return id;
+    }
+}

Propchange: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/constraint/HierarchyConstraint.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/constraint/LengthOperand.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/constraint/LengthOperand.java?rev=768954&view=auto
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/constraint/LengthOperand.java (added)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/constraint/LengthOperand.java Mon Apr 27 12:43:28 2009
@@ -0,0 +1,72 @@
+/*
+ * 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.core.query.lucene.constraint;
+
+import java.io.IOException;
+
+import javax.jcr.Value;
+import javax.jcr.ValueFactory;
+import javax.jcr.RepositoryException;
+
+import org.apache.jackrabbit.core.query.lucene.ScoreNode;
+import org.apache.jackrabbit.core.query.lucene.Util;
+import org.apache.jackrabbit.core.state.PropertyState;
+import org.apache.jackrabbit.core.value.InternalValue;
+
+/**
+ * <code>LengthOperand</code> implements a length operand.
+ */
+public class LengthOperand extends DynamicOperand {
+
+    /**
+     * The property value operand for which to return the length.
+     */
+    private final PropertyValueOperand property;
+
+    /**
+     * Creates a new length operand.
+     *
+     * @param property the operand for which to return the length.
+     */
+    public LengthOperand(PropertyValueOperand property) {
+        super();
+        this.property = property;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public Value[] getValues(ScoreNode sn, EvaluationContext context)
+            throws IOException {
+        PropertyState ps = property.getPropertyState(sn, context);
+        if (ps == null) {
+            return EMPTY;
+        } else {
+            try {
+                ValueFactory vf = context.getSession().getValueFactory();
+                InternalValue[] values = ps.getValues();
+                Value[] lengths = new Value[values.length];
+                for (int i = 0; i < lengths.length; i++) {
+                    lengths[i] = vf.createValue(Util.getLength(values[i]));
+                }
+                return lengths;
+            } catch (RepositoryException e) {
+                throw Util.createIOException(e);
+            }
+        }
+    }
+}

Propchange: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/constraint/LengthOperand.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/constraint/LikeConstraint.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/constraint/LikeConstraint.java?rev=768954&view=auto
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/constraint/LikeConstraint.java (added)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/constraint/LikeConstraint.java Mon Apr 27 12:43:28 2009
@@ -0,0 +1,59 @@
+/*
+ * 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.core.query.lucene.constraint;
+
+import java.util.regex.Matcher;
+
+import javax.jcr.Value;
+import javax.jcr.RepositoryException;
+
+import org.apache.jackrabbit.spi.commons.query.qom.SelectorImpl;
+import org.apache.jackrabbit.core.query.lucene.Util;
+
+/**
+ * <code>LikeConstraint</code> implements a like constraint.
+ */
+public class LikeConstraint extends ComparisonConstraint {
+
+    /**
+     * A regular expression matcher for the like constraint.
+     */
+    private final Matcher matcher;
+
+    /**
+     * Creates a new like constraint.
+     *
+     * @param operand1 the dynamic operand.
+     * @param operand2 the static operand.
+     * @param selector the selector for the dynamic operand.
+     * @throws RepositoryException if an error occurs reading the string value
+     *                             from the static operand.
+     */
+    public LikeConstraint(DynamicOperand operand1,
+                          Value operand2,
+                          SelectorImpl selector) throws RepositoryException {
+        super(operand1, OPERATOR_LIKE, operand2, selector);
+        this.matcher = Util.createRegexp(operand2.getString()).matcher("");
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    protected boolean evaluate(Value op1) throws RepositoryException {
+        return matcher.reset(op1.getString()).matches();
+    }
+}

Propchange: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/constraint/LikeConstraint.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/constraint/LowerCaseOperand.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/constraint/LowerCaseOperand.java?rev=768954&view=auto
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/constraint/LowerCaseOperand.java (added)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/constraint/LowerCaseOperand.java Mon Apr 27 12:43:28 2009
@@ -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.core.query.lucene.constraint;
+
+import java.io.IOException;
+
+import javax.jcr.Value;
+import javax.jcr.ValueFactory;
+import javax.jcr.RepositoryException;
+
+import org.apache.jackrabbit.core.query.lucene.ScoreNode;
+import org.apache.jackrabbit.core.query.lucene.Util;
+
+/**
+ * <code>LowerCaseOperand</code> implements a lower case operand.
+ */
+public class LowerCaseOperand extends DynamicOperand {
+
+    /**
+     * The dynamic operand for which to lower case the value.
+     */
+    private final DynamicOperand operand;
+
+    /**
+     * Creates a new lower case operand.
+     *
+     * @param operand the operand to lower case the value.
+     */
+    public LowerCaseOperand(DynamicOperand operand) {
+        super();
+        this.operand = operand;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public Value[] getValues(ScoreNode sn, EvaluationContext context)
+            throws IOException {
+        try {
+            ValueFactory vf = context.getSession().getValueFactory();
+            Value[] values = operand.getValues(sn, context);
+            for (int i = 0; i < values.length; i++) {
+                values[i] = vf.createValue(values[i].getString().toLowerCase());
+            }
+            return values;
+        } catch (RepositoryException e) {
+            throw Util.createIOException(e);
+        }
+    }
+}

Propchange: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/constraint/LowerCaseOperand.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/constraint/NodeLocalNameOperand.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/constraint/NodeLocalNameOperand.java?rev=768954&view=auto
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/constraint/NodeLocalNameOperand.java (added)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/constraint/NodeLocalNameOperand.java Mon Apr 27 12:43:28 2009
@@ -0,0 +1,54 @@
+/*
+ * 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.core.query.lucene.constraint;
+
+import java.io.IOException;
+
+import javax.jcr.RepositoryException;
+import javax.jcr.Value;
+
+import org.apache.jackrabbit.core.query.lucene.ScoreNode;
+import org.apache.jackrabbit.core.query.lucene.Util;
+import org.apache.jackrabbit.core.SessionImpl;
+import org.apache.jackrabbit.util.Text;
+
+/**
+ * <code>NodeLocalNameOperand</code> implements a node local name operand.
+ */
+public class NodeLocalNameOperand extends DynamicOperand {
+
+    /**
+     * Returns the local name of the node denoted by the given score node
+     * <code>sn</code>.
+     *
+     * @param sn      the score node.
+     * @param context the evaluation context.
+     * @return the local node name.
+     * @throws IOException if an error occurs while reading the local name.
+     */
+    public Value[] getValues(ScoreNode sn, EvaluationContext context)
+            throws IOException {
+        try {
+            SessionImpl session = context.getSession();
+            String name = session.getNodeById(sn.getNodeId()).getName();
+            return new Value[]{session.getValueFactory().createValue(
+                    Text.getLocalName(name))};
+        } catch (RepositoryException e) {
+            throw Util.createIOException(e);
+        }
+    }
+}

Propchange: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/constraint/NodeLocalNameOperand.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/constraint/NodeNameOperand.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/constraint/NodeNameOperand.java?rev=768954&view=auto
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/constraint/NodeNameOperand.java (added)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/constraint/NodeNameOperand.java Mon Apr 27 12:43:28 2009
@@ -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.core.query.lucene.constraint;
+
+import java.io.IOException;
+
+import javax.jcr.RepositoryException;
+import javax.jcr.Value;
+
+import org.apache.jackrabbit.core.query.lucene.ScoreNode;
+import org.apache.jackrabbit.core.query.lucene.Util;
+import org.apache.jackrabbit.core.SessionImpl;
+
+/**
+ * <code>NodeNameOperand</code> implements a node name operand.
+ */
+public class NodeNameOperand extends DynamicOperand {
+
+    /**
+     * Returns the name of the node denoted by the given score node
+     * <code>sn</code>.
+     *
+     * @param sn      the score node.
+     * @param context the evaluation context.
+     * @return the node name.
+     * @throws IOException if an error occurs while reading the name.
+     */
+    public Value[] getValues(ScoreNode sn, EvaluationContext context)
+            throws IOException {
+        try {
+            SessionImpl session = context.getSession();
+            String name = session.getNodeById(sn.getNodeId()).getName();
+            return new Value[]{session.getValueFactory().createValue(name)};
+        } catch (RepositoryException e) {
+            throw Util.createIOException(e);
+        }
+    }
+}

Propchange: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/constraint/NodeNameOperand.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/constraint/NotConstraint.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/constraint/NotConstraint.java?rev=768954&view=auto
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/constraint/NotConstraint.java (added)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/constraint/NotConstraint.java Mon Apr 27 12:43:28 2009
@@ -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.core.query.lucene.constraint;
+
+import java.io.IOException;
+
+import org.apache.jackrabbit.core.query.lucene.ScoreNode;
+import org.apache.jackrabbit.spi.Name;
+
+/**
+ * <code>NotConstraint</code> implements a NOT constraint.
+ */
+public class NotConstraint implements Constraint {
+
+    /**
+     * The single operand.
+     */
+    private final Constraint constraint;
+
+    /**
+     * Creates a new NOT constraint with the given <code>constraint</code> as
+     * its operand.
+     *
+     * @param constraint the operand.
+     */
+    public NotConstraint(Constraint constraint) {
+        this.constraint = constraint;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public boolean evaluate(ScoreNode[] row,
+                            Name[] selectorNames,
+                            EvaluationContext context)
+            throws IOException {
+        return !constraint.evaluate(row, selectorNames, context);
+    }
+}

Propchange: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/constraint/NotConstraint.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/constraint/OrConstraint.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/constraint/OrConstraint.java?rev=768954&view=auto
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/constraint/OrConstraint.java (added)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/constraint/OrConstraint.java Mon Apr 27 12:43:28 2009
@@ -0,0 +1,60 @@
+/*
+ * 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.core.query.lucene.constraint;
+
+import java.io.IOException;
+
+import org.apache.jackrabbit.core.query.lucene.ScoreNode;
+import org.apache.jackrabbit.spi.Name;
+
+/**
+ * <code>OrConstraint</code> implements an OR constraint.
+ */
+public class OrConstraint implements Constraint {
+
+    /**
+     * The left operand.
+     */
+    private final Constraint left;
+
+    /**
+     * The right operand.
+     */
+    private final Constraint right;
+
+    /**
+     * Creates a new OR constraint.
+     *
+     * @param left the left operand.
+     * @param right the right operand.
+     */
+    public OrConstraint(Constraint left, Constraint right) {
+        this.left = left;
+        this.right = right;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public boolean evaluate(ScoreNode[] row,
+                            Name[] selectorNames,
+                            EvaluationContext context)
+            throws IOException {
+        return left.evaluate(row, selectorNames, context)
+                || right.evaluate(row, selectorNames, context);
+    }
+}

Propchange: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/constraint/OrConstraint.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/constraint/PropertyExistenceConstraint.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/constraint/PropertyExistenceConstraint.java?rev=768954&view=auto
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/constraint/PropertyExistenceConstraint.java (added)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/constraint/PropertyExistenceConstraint.java Mon Apr 27 12:43:28 2009
@@ -0,0 +1,46 @@
+/*
+ * 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.core.query.lucene.constraint;
+
+import javax.jcr.RepositoryException;
+
+import org.apache.jackrabbit.spi.commons.query.qom.PropertyExistenceImpl;
+import org.apache.jackrabbit.spi.commons.query.qom.SelectorImpl;
+import org.apache.jackrabbit.core.query.lucene.LuceneQueryFactory;
+
+/**
+ * <code>PropertyExistenceConstraint</code> implements a property existence
+ * constraint.
+ */
+public class PropertyExistenceConstraint extends QueryConstraint {
+
+    /**
+     * Creates a new property existence constraint.
+     *
+     * @param prop     the QOM property existence constraint.
+     * @param selector the selector for this constraint.
+     * @param factory  the lucene query factory.
+     * @throws RepositoryException if an error occurs while creating a lucene
+     *                             query for this constraint.
+     */
+    public PropertyExistenceConstraint(PropertyExistenceImpl prop,
+                                       SelectorImpl selector,
+                                       LuceneQueryFactory factory)
+            throws RepositoryException {
+        super(factory.create(prop), selector, factory);
+    }
+}

Propchange: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/constraint/PropertyExistenceConstraint.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/constraint/PropertyValueOperand.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/constraint/PropertyValueOperand.java?rev=768954&view=auto
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/constraint/PropertyValueOperand.java (added)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/constraint/PropertyValueOperand.java Mon Apr 27 12:43:28 2009
@@ -0,0 +1,123 @@
+/*
+ * 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.core.query.lucene.constraint;
+
+import java.io.IOException;
+
+import javax.jcr.Value;
+import javax.jcr.Property;
+import javax.jcr.Node;
+import javax.jcr.PathNotFoundException;
+import javax.jcr.RepositoryException;
+
+import org.apache.jackrabbit.spi.commons.query.qom.PropertyValueImpl;
+import org.apache.jackrabbit.core.query.lucene.ScoreNode;
+import org.apache.jackrabbit.core.query.lucene.Util;
+import org.apache.jackrabbit.core.state.ItemStateManager;
+import org.apache.jackrabbit.core.state.PropertyState;
+import org.apache.jackrabbit.core.state.ItemStateException;
+import org.apache.jackrabbit.core.state.NoSuchItemStateException;
+import org.apache.jackrabbit.core.PropertyId;
+import org.apache.jackrabbit.core.SessionImpl;
+
+/**
+ * <code>PropertyValueOperand</code> implements a property value operand.
+ */
+public class PropertyValueOperand extends DynamicOperand {
+
+    /**
+     * The QOM operand.
+     */
+    private final PropertyValueImpl operand;
+
+    /**
+     * Creates a new property value operand.
+     *
+     * @param operand the QOM operand.
+     */
+    public PropertyValueOperand(PropertyValueImpl operand) {
+        super();
+        this.operand = operand;
+    }
+
+    /**
+     * Returns the property state for the given score node or <code>null</code>
+     * if none exists.
+     *
+     * @param sn the current score node.
+     * @param context the evaluation context.
+     * @return the property state or <code>null</code>.
+     * @throws IOException if an error occurs while reading.
+     */
+    public final PropertyState getPropertyState(ScoreNode sn,
+                                          EvaluationContext context)
+            throws IOException {
+        ItemStateManager ism = context.getItemStateManager();
+        PropertyId propId = new PropertyId(sn.getNodeId(), operand.getPropertyQName());
+        try {
+            return (PropertyState) ism.getItemState(propId);
+        } catch (NoSuchItemStateException e) {
+            return null;
+        } catch (ItemStateException e) {
+            throw Util.createIOException(e);
+        }
+    }
+
+    /**
+     * Returns the property for the given score node or <code>null</code> if
+     * none exists.
+     *
+     * @param sn the current score node.
+     * @param context the evaluation context.
+     * @return the property or <code>null</code>.
+     * @throws IOException if an error occurs while reading.
+     */
+    public final Property getProperty(ScoreNode sn,
+                                      EvaluationContext context)
+            throws IOException {
+        SessionImpl session = context.getSession();
+        try {
+            Node n = session.getNodeById(sn.getNodeId());
+            return n.getProperty(operand.getPropertyName());
+        } catch (PathNotFoundException e) {
+            return null;
+        } catch (RepositoryException e) {
+            throw Util.createIOException(e);
+        }
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public Value[] getValues(ScoreNode sn, EvaluationContext context)
+            throws IOException {
+        Property prop = getProperty(sn, context);
+        if (prop == null) {
+            return EMPTY;
+        } else {
+            try {
+                if (prop.getDefinition().isMultiple()) {
+                    return prop.getValues();
+                } else {
+                    return new Value[]{prop.getValue()};
+                }
+            } catch (RepositoryException e) {
+                throw Util.createIOException(e);
+            }
+        }
+    }
+}

Propchange: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/constraint/PropertyValueOperand.java
------------------------------------------------------------------------------
    svn:eol-style = native