jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ju...@apache.org
Subject svn commit: r1080235 - in /jackrabbit/trunk: jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/ jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/join/ jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/c...
Date Thu, 10 Mar 2011 14:39:38 GMT
Author: jukka
Date: Thu Mar 10 14:39:37 2011
New Revision: 1080235

URL: http://svn.apache.org/viewvc?rev=1080235&view=rev
Log:
JCR-2853: QOM utility classes in jcr-commons

Move OperandEvaluator to jcr-commons.

Add a simple value factory class to simplify testing.

Added:
    jackrabbit/trunk/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/SimpleValueFactory.java
    jackrabbit/trunk/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/query/qom/OperandEvaluator.java
      - copied, changed from r1080186, jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/join/OperandEvaluator.java
Removed:
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/join/OperandEvaluator.java
Modified:
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/LuceneQueryFactory.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/join/AbstractRow.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/join/ChildNodeJoinMerger.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/join/DescendantNodeJoinMerger.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/join/EquiJoinMerger.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/join/JoinMerger.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/join/JoinRow.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/join/QueryEngine.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/join/SameNodeJoinMerger.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/join/SelectorRow.java

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/LuceneQueryFactory.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/LuceneQueryFactory.java?rev=1080235&r1=1080234&r2=1080235&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/LuceneQueryFactory.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/LuceneQueryFactory.java
Thu Mar 10 14:39:37 2011
@@ -90,10 +90,10 @@ import javax.jcr.query.qom.UpperCase;
 import org.apache.jackrabbit.commons.predicate.Predicate;
 import org.apache.jackrabbit.commons.predicate.Predicates;
 import org.apache.jackrabbit.commons.predicate.RowPredicate;
+import org.apache.jackrabbit.commons.query.qom.OperandEvaluator;
 import org.apache.jackrabbit.core.NodeImpl;
 import org.apache.jackrabbit.core.SessionImpl;
 import org.apache.jackrabbit.core.id.NodeId;
-import org.apache.jackrabbit.core.query.lucene.join.OperandEvaluator;
 import org.apache.jackrabbit.core.query.lucene.join.SelectorRow;
 import org.apache.jackrabbit.core.query.lucene.join.ValueComparator;
 import org.apache.jackrabbit.spi.Name;

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/join/AbstractRow.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/join/AbstractRow.java?rev=1080235&r1=1080234&r2=1080235&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/join/AbstractRow.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/join/AbstractRow.java
Thu Mar 10 14:39:37 2011
@@ -26,6 +26,8 @@ import javax.jcr.query.Row;
 import javax.jcr.query.qom.Operand;
 import javax.jcr.query.qom.PropertyValue;
 
+import org.apache.jackrabbit.commons.query.qom.OperandEvaluator;
+
 abstract class AbstractRow implements Row {
 
     private final Map<String, PropertyValue> columns;

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/join/ChildNodeJoinMerger.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/join/ChildNodeJoinMerger.java?rev=1080235&r1=1080234&r2=1080235&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/join/ChildNodeJoinMerger.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/join/ChildNodeJoinMerger.java
Thu Mar 10 14:39:37 2011
@@ -33,6 +33,8 @@ import javax.jcr.query.qom.Join;
 import javax.jcr.query.qom.PropertyValue;
 import javax.jcr.query.qom.QueryObjectModelFactory;
 
+import org.apache.jackrabbit.commons.query.qom.OperandEvaluator;
+
 class ChildNodeJoinMerger extends JoinMerger {
 
     private final String childSelector;

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/join/DescendantNodeJoinMerger.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/join/DescendantNodeJoinMerger.java?rev=1080235&r1=1080234&r2=1080235&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/join/DescendantNodeJoinMerger.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/join/DescendantNodeJoinMerger.java
Thu Mar 10 14:39:37 2011
@@ -33,6 +33,8 @@ import javax.jcr.query.qom.Join;
 import javax.jcr.query.qom.PropertyValue;
 import javax.jcr.query.qom.QueryObjectModelFactory;
 
+import org.apache.jackrabbit.commons.query.qom.OperandEvaluator;
+
 class DescendantNodeJoinMerger extends JoinMerger {
 
     private final String descendantSelector;

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/join/EquiJoinMerger.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/join/EquiJoinMerger.java?rev=1080235&r1=1080234&r2=1080235&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/join/EquiJoinMerger.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/join/EquiJoinMerger.java
Thu Mar 10 14:39:37 2011
@@ -36,6 +36,8 @@ import javax.jcr.query.qom.Literal;
 import javax.jcr.query.qom.PropertyValue;
 import javax.jcr.query.qom.QueryObjectModelFactory;
 
+import org.apache.jackrabbit.commons.query.qom.OperandEvaluator;
+
 class EquiJoinMerger extends JoinMerger {
 
     private final PropertyValue leftProperty;

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/join/JoinMerger.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/join/JoinMerger.java?rev=1080235&r1=1080234&r2=1080235&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/join/JoinMerger.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/join/JoinMerger.java
Thu Mar 10 14:39:37 2011
@@ -46,6 +46,7 @@ import javax.jcr.query.qom.Source;
 
 import org.apache.jackrabbit.commons.iterator.RowIterable;
 import org.apache.jackrabbit.commons.iterator.RowIteratorAdapter;
+import org.apache.jackrabbit.commons.query.qom.OperandEvaluator;
 
 /**
  * A join merger is used by the {@link QueryEngine} class to efficiently

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/join/JoinRow.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/join/JoinRow.java?rev=1080235&r1=1080234&r2=1080235&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/join/JoinRow.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/join/JoinRow.java
Thu Mar 10 14:39:37 2011
@@ -24,6 +24,8 @@ import javax.jcr.RepositoryException;
 import javax.jcr.query.Row;
 import javax.jcr.query.qom.PropertyValue;
 
+import org.apache.jackrabbit.commons.query.qom.OperandEvaluator;
+
 public class JoinRow extends AbstractRow {
 
     private final Row leftRow;

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/join/QueryEngine.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/join/QueryEngine.java?rev=1080235&r1=1080234&r2=1080235&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/join/QueryEngine.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/join/QueryEngine.java
Thu Mar 10 14:39:37 2011
@@ -57,6 +57,7 @@ import javax.jcr.query.qom.Source;
 
 import org.apache.jackrabbit.commons.JcrUtils;
 import org.apache.jackrabbit.commons.iterator.RowIteratorAdapter;
+import org.apache.jackrabbit.commons.query.qom.OperandEvaluator;
 import org.apache.jackrabbit.core.query.lucene.LuceneQueryFactory;
 
 public class QueryEngine {

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/join/SameNodeJoinMerger.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/join/SameNodeJoinMerger.java?rev=1080235&r1=1080234&r2=1080235&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/join/SameNodeJoinMerger.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/join/SameNodeJoinMerger.java
Thu Mar 10 14:39:37 2011
@@ -34,6 +34,8 @@ import javax.jcr.query.qom.PropertyValue
 import javax.jcr.query.qom.QueryObjectModelFactory;
 import javax.jcr.query.qom.SameNodeJoinCondition;
 
+import org.apache.jackrabbit.commons.query.qom.OperandEvaluator;
+
 class SameNodeJoinMerger extends JoinMerger {
 
     private final String selector1;

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/join/SelectorRow.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/join/SelectorRow.java?rev=1080235&r1=1080234&r2=1080235&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/join/SelectorRow.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/join/SelectorRow.java
Thu Mar 10 14:39:37 2011
@@ -22,6 +22,8 @@ import javax.jcr.Node;
 import javax.jcr.RepositoryException;
 import javax.jcr.query.qom.PropertyValue;
 
+import org.apache.jackrabbit.commons.query.qom.OperandEvaluator;
+
 /**
  * A row implementation for a query with just a single selector.
  */

Added: jackrabbit/trunk/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/SimpleValueFactory.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/SimpleValueFactory.java?rev=1080235&view=auto
==============================================================================
--- jackrabbit/trunk/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/SimpleValueFactory.java
(added)
+++ jackrabbit/trunk/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/SimpleValueFactory.java
Thu Mar 10 14:39:37 2011
@@ -0,0 +1,43 @@
+/*
+ * 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.commons;
+
+import javax.jcr.ValueFormatException;
+
+import org.apache.jackrabbit.value.AbstractValueFactory;
+
+/**
+ * Simple value factory implementation for use mainly in testing.
+ * Complex value types such as names, paths and references are kept
+ * just as strings, and no format checks nor any namespace prefix
+ * updates are made.
+ *
+ * @since Apache Jackrabbit 2.3
+ */
+public class SimpleValueFactory extends AbstractValueFactory {
+
+    @Override
+    protected void checkPathFormat(String pathValue)
+            throws ValueFormatException {
+    }
+
+    @Override
+    protected void checkNameFormat(String nameValue)
+            throws ValueFormatException {
+    }
+
+}

Copied: jackrabbit/trunk/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/query/qom/OperandEvaluator.java
(from r1080186, jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/join/OperandEvaluator.java)
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/query/qom/OperandEvaluator.java?p2=jackrabbit/trunk/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/query/qom/OperandEvaluator.java&p1=jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/join/OperandEvaluator.java&r1=1080186&r2=1080235&rev=1080235&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/join/OperandEvaluator.java
(original)
+++ jackrabbit/trunk/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/query/qom/OperandEvaluator.java
Thu Mar 10 14:39:37 2011
@@ -14,11 +14,9 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-package org.apache.jackrabbit.core.query.lucene.join;
-
-import static java.util.Locale.ENGLISH;
-import static javax.jcr.PropertyType.NAME;
+package org.apache.jackrabbit.commons.query.qom;
 
+import java.util.Locale;
 import java.util.Map;
 
 import javax.jcr.Node;
@@ -55,20 +53,53 @@ public class OperandEvaluator {
     /** Bind variables */
     private final Map<String, Value> variables;
 
+    /** The locale to use in upper- and lower-case conversion. */
+    private final Locale locale;
+
     /**
      * Creates an operand evaluator for the given value factory and set of
-     * bind variables.
+     * bind variables. Upper- and lower-case conversions are performed using
+     * the given locale.
      *
      * @param factory value factory
      * @param variables bind variables
+     * @param locale locale to use in upper- and lower-case conversions
      */
     public OperandEvaluator(
-            ValueFactory factory, Map<String, Value> variables) {
+            ValueFactory factory, Map<String, Value> variables, Locale locale) {
         this.factory = factory;
         this.variables = variables;
+        this.locale = locale;
     }
 
-    public Value getValue(StaticOperand operand, int type) throws RepositoryException {
+    /**
+     * Creates an operand evaluator for the given value factory and set of
+     * bind variables. Upper- and lower-case conversions are performed using
+     * the {@link Locale#ENGLISH}.
+     *
+     * @param factory value factory
+     * @param variables bind variables
+     * @param locale locale to use in upper- and lower-case conversions
+     */
+    public OperandEvaluator(
+            ValueFactory factory, Map<String, Value> variables) {
+        this(factory, variables, Locale.ENGLISH);
+    }
+
+    /**
+     * Returns the value of the given static operand
+     * ({@link Literal literal} or {@link BindVariableValue bind variable})
+     * casted to the given type.
+     *
+     * @param operand static operand to be evaluated
+     * @param type expected value type
+     * @return evaluated value, casted to the given type
+     * @throws RepositoryException if a named bind variable is not found,
+     *                             if the operand type is unknown, or
+     *                             if the type conversion fails
+     */
+    public Value getValue(StaticOperand operand, int type)
+            throws RepositoryException {
         Value value = getValue(operand);
         if (type == PropertyType.UNDEFINED || type == value.getType()) {
             return value;
@@ -120,7 +151,7 @@ public class OperandEvaluator {
      * @param operand operand to be evaluated
      * @param row query result row
      * @return evaluated value
-     * @throws RepositoryException
+     * @throws RepositoryException if the operand can't be evaluated
      */
     public Value getValue(Operand operand, Row row) throws RepositoryException {
         Value[] values = getValues(operand, row);
@@ -157,8 +188,10 @@ public class OperandEvaluator {
             return new Value[] { factory.createValue(score) };
         } else if (operand instanceof NodeName) {
             NodeName nn = (NodeName) operand;
-            Node node = row.getNode(nn.getSelectorName());
-            return new Value[] { factory.createValue(node.getName(), NAME) };
+            Value value = factory.createValue(
+                    row.getNode(nn.getSelectorName()).getName(),
+                    PropertyType.NAME);
+            return new Value[] { value };
         } else if (operand instanceof Length) {
             return getLengthValues((Length) operand, row);
         } else if (operand instanceof LowerCase) {
@@ -215,7 +248,7 @@ public class OperandEvaluator {
         Value[] values = getValues(operand.getOperand(), row);
         for (int i = 0; i < values.length; i++) {
             String value = values[i].getString();
-            String lower = value.toLowerCase(ENGLISH);
+            String lower = value.toLowerCase(locale);
             if (!value.equals(lower)) {
                 values[i] = factory.createValue(lower);
             }
@@ -236,7 +269,7 @@ public class OperandEvaluator {
         Value[] values = getValues(operand.getOperand(), row);
         for (int i = 0; i < values.length; i++) {
             String value = values[i].getString();
-            String upper = value.toUpperCase(ENGLISH);
+            String upper = value.toUpperCase(locale);
             if (!value.equals(upper)) {
                 values[i] = factory.createValue(upper);
             }
@@ -259,7 +292,7 @@ public class OperandEvaluator {
         if (colon != -1) {
             name = name.substring(colon + 1);
         }
-        return new Value[] { factory.createValue(name, NAME) };
+        return new Value[] { factory.createValue(name, PropertyType.NAME) };
     }
 
     /**



Mime
View raw message