jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mreut...@apache.org
Subject svn commit: r647798 - in /jackrabbit/trunk/jackrabbit-core/src: main/java/org/apache/jackrabbit/core/query/lucene/ test/java/org/apache/jackrabbit/core/query/qom/
Date Mon, 14 Apr 2008 13:54:23 GMT
Author: mreutegg
Date: Mon Apr 14 06:54:14 2008
New Revision: 647798

URL: http://svn.apache.org/viewvc?rev=647798&view=rev
Log:
JCR-1104: JSR 283 support (work in progress)
- NodeLocalName

Added:
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/LocalNameQuery.java   (with props)
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/LocalNameRangeQuery.java   (with props)
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/NameQuery.java   (with props)
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/NameRangeQuery.java   (with props)
    jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/query/qom/NodeLocalNameTest.java   (with props)
Modified:
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/AbstractIndex.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/ChildAxisQuery.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/ChildNodesQueryHits.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/DerefQuery.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/DescendantSelfAxisQuery.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/FieldNames.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/IndexFormatVersion.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/IndexingQueueStore.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/JQOM2LuceneQueryBuilder.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/LuceneQueryBuilder.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/MatchAllDocsQuery.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/MultiIndex.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/NodeIndexer.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/ParentAxisQuery.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/PropertiesSynonymProvider.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/SearchIndex.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/SimilarityQuery.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/Util.java
    jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/query/qom/NodeNameTest.java
    jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/query/qom/TestAll.java

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/AbstractIndex.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/AbstractIndex.java?rev=647798&r1=647797&r2=647798&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/AbstractIndex.java (original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/AbstractIndex.java Mon Apr 14 06:54:14 2008
@@ -183,9 +183,7 @@
                     if (cause instanceof IOException) {
                         ex = (IOException) cause;
                     } else {
-                        IOException e = new IOException();
-                        e.initCause(cause);
-                        ex = e;
+                        throw Util.createIOException(cause);
                     }
                 } else {
                     // all others are logged

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/ChildAxisQuery.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/ChildAxisQuery.java?rev=647798&r1=647797&r2=647798&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/ChildAxisQuery.java (original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/ChildAxisQuery.java Mon Apr 14 06:54:14 2008
@@ -37,7 +37,6 @@
 import org.apache.lucene.search.Scorer;
 import org.apache.lucene.search.Searcher;
 import org.apache.lucene.search.Similarity;
-import org.apache.lucene.search.TermQuery;
 import org.apache.lucene.search.Weight;
 import org.apache.lucene.search.Sort;
 
@@ -68,7 +67,7 @@
      * The nameTest to apply on the child axis, or <code>null</code> if all
      * child nodes should be selected.
      */
-    private final String nameTest;
+    private final Name nameTest;
 
     /**
      * The context position for the selected child node, or
@@ -77,6 +76,16 @@
     private final int position;
 
     /**
+     * The index format version.
+     */ 
+    private final IndexFormatVersion version;
+
+    /**
+     * The internal namespace mappings.
+     */
+    private final NamespaceMappings nsMappings;
+
+    /**
      * The scorer of the context query
      */
     private Scorer contextScorer;
@@ -94,9 +103,15 @@
      * @param context the context for this query.
      * @param nameTest a name test or <code>null</code> if any child node is
      * selected.
+     * @param version the index format version.
+     * @param nsMappings the internal namespace mappings.
      */
-    ChildAxisQuery(ItemStateManager itemMgr, Query context, String nameTest) {
-        this(itemMgr, context, nameTest, LocationStepQueryNode.NONE);
+    ChildAxisQuery(ItemStateManager itemMgr,
+                   Query context,
+                   Name nameTest,
+                   IndexFormatVersion version,
+                   NamespaceMappings nsMappings) {
+        this(itemMgr, context, nameTest, LocationStepQueryNode.NONE, version, nsMappings);
     }
 
     /**
@@ -110,12 +125,21 @@
      * @param position the context position of the child node to select. If
      * <code>position</code> is {@link LocationStepQueryNode#NONE}, the context
      * position of the child node is not checked.
+     * @param version the index format version.
+     * @param nsMapping the internal namespace mappings.
      */
-    ChildAxisQuery(ItemStateManager itemMgr, Query context, String nameTest, int position) {
+    ChildAxisQuery(ItemStateManager itemMgr,
+                   Query context,
+                   Name nameTest,
+                   int position,
+                   IndexFormatVersion version,
+                   NamespaceMappings nsMapping) {
         this.itemMgr = itemMgr;
         this.contextQuery = context;
         this.nameTest = nameTest;
         this.position = position;
+        this.version = version;
+        this.nsMappings = nsMapping;
     }
 
     /**
@@ -136,7 +160,7 @@
     /**
      * @return the name test or <code>null</code> if none was specified.
      */
-    String getNameTest() {
+    Name getNameTest() {
         return nameTest;
     }
 
@@ -179,7 +203,7 @@
                     if (nameTest == null) {
                         sub = new MatchAllDocsQuery();
                     } else {
-                        sub = new TermQuery(new Term(FieldNames.LABEL, nameTest));
+                        sub = new NameQuery(nameTest, version, nsMappings);
                     }
                     return new DescendantSelfAxisQuery(dsaq.getContextQuery(),
                             sub, dsaq.getMinLevels() + 1).rewrite(reader);
@@ -191,7 +215,8 @@
         if (cQuery == contextQuery) {
             return this;
         } else {
-            return new ChildAxisQuery(itemMgr, cQuery, nameTest, position);
+            return new ChildAxisQuery(itemMgr, cQuery, nameTest,
+                    position, version, nsMappings);
         }
     }
 
@@ -283,7 +308,7 @@
         public Scorer scorer(IndexReader reader) throws IOException {
             contextScorer = contextQuery.weight(searcher).scorer(reader);
             if (nameTest != null) {
-                nameTestScorer = new TermQuery(new Term(FieldNames.LABEL, nameTest)).weight(searcher).scorer(reader);
+                nameTestScorer = new NameQuery(nameTest, version, nsMappings).weight(searcher).scorer(reader);
             }
             return new ChildAxisScorer(searcher.getSimilarity(),
                     reader, (HierarchyResolver) reader);

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/ChildNodesQueryHits.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/ChildNodesQueryHits.java?rev=647798&r1=647797&r2=647798&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/ChildNodesQueryHits.java (original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/ChildNodesQueryHits.java Mon Apr 14 06:54:14 2008
@@ -99,9 +99,7 @@
                 Node parent = session.getNodeById(nextParent.getNodeId());
                 childHits = new NodeTraversingQueryHits(parent, false, 1);
             } catch (RepositoryException e) {
-                IOException ex = new IOException(e.getMessage());
-                ex.initCause(e);
-                throw ex;
+                throw Util.createIOException(e);
             }
         } else {
             childHits = null;

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/DerefQuery.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/DerefQuery.java?rev=647798&r1=647797&r2=647798&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/DerefQuery.java (original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/DerefQuery.java Mon Apr 14 06:54:14 2008
@@ -25,8 +25,8 @@
 import org.apache.lucene.search.Scorer;
 import org.apache.lucene.search.Searcher;
 import org.apache.lucene.search.Similarity;
-import org.apache.lucene.search.TermQuery;
 import org.apache.lucene.search.Weight;
+import org.apache.jackrabbit.spi.Name;
 
 import java.io.IOException;
 import java.util.ArrayList;
@@ -55,7 +55,17 @@
      * The nameTest to apply on target node, or <code>null</code> if all
      * target nodes should be selected.
      */
-    private final String nameTest;
+    private final Name nameTest;
+
+    /**
+     * The index format version.
+     */
+    private final IndexFormatVersion version;
+
+    /**
+     * The internal namespace mappings.
+     */
+    private final NamespaceMappings nsMappings;
 
     /**
      * The scorer of the context query
@@ -75,11 +85,16 @@
      * @param refProperty the name of the reference property.
      * @param nameTest a name test or <code>null</code> if any node is
      *  selected.
+     * @param version the index format version.
+     * @param nsMappings the namespace mappings.
      */
-    DerefQuery(Query context, String refProperty, String nameTest) {
+    DerefQuery(Query context, String refProperty, Name nameTest,
+               IndexFormatVersion version, NamespaceMappings nsMappings) {
         this.contextQuery = context;
         this.refProperty = refProperty;
         this.nameTest = nameTest;
+        this.version = version;
+        this.nsMappings = nsMappings;
     }
 
     /**
@@ -117,7 +132,7 @@
         if (cQuery == contextQuery) {
             return this;
         } else {
-            return new DerefQuery(cQuery, refProperty, nameTest);
+            return new DerefQuery(cQuery, refProperty, nameTest, version, nsMappings);
         }
     }
 
@@ -182,7 +197,7 @@
         public Scorer scorer(IndexReader reader) throws IOException {
             contextScorer = contextQuery.weight(searcher).scorer(reader);
             if (nameTest != null) {
-                nameTestScorer = new TermQuery(new Term(FieldNames.LABEL, nameTest)).weight(searcher).scorer(reader);
+                nameTestScorer = new NameQuery(nameTest, version, nsMappings).weight(searcher).scorer(reader);
             }
             return new DerefScorer(searcher.getSimilarity(), reader);
         }

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/DescendantSelfAxisQuery.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/DescendantSelfAxisQuery.java?rev=647798&r1=647797&r2=647798&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/DescendantSelfAxisQuery.java (original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/DescendantSelfAxisQuery.java Mon Apr 14 06:54:14 2008
@@ -233,9 +233,7 @@
                         startingPoints.put(node.getPath(), sn);
                     }
                 } catch (RepositoryException e) {
-                    IOException ex = new IOException(e.getMessage());
-                    ex.initCause(e);
-                    throw ex;
+                    throw Util.createIOException(e);
                 }
             } finally {
                 result.close();
@@ -293,9 +291,7 @@
                             currentTraversal = new NodeTraversingQueryHits(node,
                                     getMinLevels() == 0);
                         } catch (RepositoryException e) {
-                            IOException ex = new IOException(e.getMessage());
-                            ex.initCause(e);
-                            throw ex;
+                            throw Util.createIOException(e);
                         }
                     } else {
                         currentTraversal = null;

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/FieldNames.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/FieldNames.java?rev=647798&r1=647797&r2=647798&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/FieldNames.java (original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/FieldNames.java Mon Apr 14 06:54:14 2008
@@ -58,6 +58,18 @@
     public static final String LABEL = "_:LABEL".intern();
 
     /**
+     * Name of the field that contains the local name of the node. Terms are not
+     * tokenized.
+     */
+    public static final String LOCAL_NAME = "_:LOCAL_NAME".intern();
+
+    /**
+     * Name of the field that contains the namespace URI of the node name. Terms
+     * are not tokenized.
+     */
+    public static final String NAMESPACE_URI = "_:NAMESPACE_URI".intern();
+
+    /**
      * Name of the field that contains the names of multi-valued properties that
      * hold more than one value. Terms are not tokenized and not stored, only
      * indexed.

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/IndexFormatVersion.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/IndexFormatVersion.java?rev=647798&r1=647797&r2=647798&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/IndexFormatVersion.java (original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/IndexFormatVersion.java Mon Apr 14 06:54:14 2008
@@ -17,12 +17,8 @@
 package org.apache.jackrabbit.core.query.lucene;
 
 import java.util.Collection;
-import java.io.IOException;
 
 import org.apache.lucene.index.IndexReader;
-import org.apache.lucene.index.TermPositions;
-import org.apache.lucene.index.Term;
-import org.apache.lucene.index.TermEnum;
 
 /**
  * This class indicates the lucene index format that is used.
@@ -34,8 +30,9 @@
  * adds a <code>PROPERTIES_SET</code> field which contains all property names of
  * a node. This speeds up queries that check the existence of a property.</li>
  * <li><b>Version 3</b> is the index format introduced with Jackrabbit 1.5.x. It
- * adds support for length queries using the newly added
- * <code>PROPERTY_LENGTHS</code> field. Furthermore a Payload is added to
+ * adds support for length and local name queries using the newly added
+ * fields <code>PROPERTY_LENGTHS</code>, <code>LOCAL_NAME</code> and
+ * <code>NAMESPACE_URI</code>. Furthermore a Payload is added to
  * <code>PROPERTIES</code> fields to indicate the property type.</li>
  * </ul>
  * Please note that existing indexes are not automatically upgraded to a newer
@@ -92,44 +89,15 @@
      * @return the index format version of the index used by the given
      * index reader.
      */
-    public static IndexFormatVersion getVersion(IndexReader indexReader)
-            throws IOException {
+    public static IndexFormatVersion getVersion(IndexReader indexReader) {
         Collection fields = indexReader.getFieldNames(
                 IndexReader.FieldOption.ALL);
-        if (hasPayloads(indexReader) || indexReader.numDocs() == 0) {
+        if (fields.contains(FieldNames.LOCAL_NAME) || indexReader.numDocs() == 0) {
             return IndexFormatVersion.V3;
         } else if (fields.contains(FieldNames.PROPERTIES_SET)) {
             return IndexFormatVersion.V2;
         } else {
             return IndexFormatVersion.V1;
         }
-    }
-
-    /**
-     * @param reader the index reader.
-     * @return <code>true</code> if the {@link FieldNames#PROPERTIES} fields
-     *         contain payloads; <code>false</code> otherwise.
-     * @throws IOException if an error occurs while reading from the index.
-     */
-    public static boolean hasPayloads(IndexReader reader) throws IOException {
-        TermPositions tp = reader.termPositions();
-        try {
-            TermEnum terms = reader.terms(
-                    new Term(FieldNames.PROPERTIES, ""));
-            try {
-                do {
-                    tp.seek(terms);
-                    if (tp.next()) {
-                        tp.nextPosition();
-                        return tp.isPayloadAvailable();
-                    }
-                } while (terms.next() && terms.term().field() == FieldNames.PROPERTIES);
-            } finally {
-                terms.close();
-            }
-        } finally {
-            tp.close();
-        }
-        return false;
     }
 }

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/IndexingQueueStore.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/IndexingQueueStore.java?rev=647798&r1=647797&r2=647798&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/IndexingQueueStore.java (original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/IndexingQueueStore.java Mon Apr 14 06:54:14 2008
@@ -239,9 +239,7 @@
                     out.close();
                     out = null;
                 }
-                IOException ex = new IOException(e.getMessage());
-                ex.initCause(e);
-                throw ex;
+                throw Util.createIOException(e);
             }
         }
         return out;

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/JQOM2LuceneQueryBuilder.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/JQOM2LuceneQueryBuilder.java?rev=647798&r1=647797&r2=647798&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/JQOM2LuceneQueryBuilder.java (original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/JQOM2LuceneQueryBuilder.java Mon Apr 14 06:54:14 2008
@@ -467,9 +467,50 @@
         return transformCase(obj, data, false);
     }
 
-    public Object visit(NodeLocalNameImpl node, Object data) {
-        // TODO: implement
-        throw new UnsupportedOperationException("not yet implemented");
+    public Object visit(NodeLocalNameImpl node, Object data) throws Exception {
+        if (version.getVersion() < IndexFormatVersion.V3.getVersion()) {
+            throw new InvalidQueryException("NodeLocalName operand is only " +
+                    "available with index version >= 3. Please re-index " +
+                    "repository and execute query again.");
+        }
+        if (data instanceof ComparisonImpl) {
+            ComparisonImpl comp = ((ComparisonImpl) data);
+            int operator = comp.getOperator();
+            Value v = (Value) ((StaticOperandImpl) comp.getOperand2()).accept(this, data);
+            String value = v.getString();
+
+            switch (operator) {
+                case OPERATOR_EQUAL_TO:
+                    return new TermQuery(new Term(FieldNames.LOCAL_NAME, value));
+                case OPERATOR_GREATER_THAN:
+                    return new LocalNameRangeQuery(value, null, false);
+                case OPERATOR_GREATER_THAN_OR_EQUAL_TO:
+                    return new LocalNameRangeQuery(value, null, true);
+                case OPERATOR_LESS_THAN:
+                    return new LocalNameRangeQuery(null, value, false);
+                case OPERATOR_LESS_THAN_OR_EQUAL_TO:
+                    return new LocalNameRangeQuery(null, value, true);
+                case OPERATOR_LIKE:
+                    if (value.equals("%")) {
+                        return new MatchAllDocsQuery();
+                    } else {
+                        return new WildcardQuery(FieldNames.LOCAL_NAME, null, value);
+                    }
+                case OPERATOR_NOT_EQUAL_TO:
+                    MatchAllDocsQuery all = new MatchAllDocsQuery();
+                    BooleanQuery b = new BooleanQuery();
+                    b.add(all, BooleanClause.Occur.SHOULD);
+                    b.add(new TermQuery(new Term(FieldNames.LOCAL_NAME, value)),
+                            BooleanClause.Occur.MUST_NOT);
+                    return b;
+                default:
+                    throw new InvalidQueryException(
+                            "Unknown operator " + operator);
+            }
+        } else {
+            // TODO
+            throw new InvalidQueryException("not yet implemented");
+        }
     }
 
     public Object visit(NodeNameImpl node, Object data) throws Exception {
@@ -497,43 +538,25 @@
                 throw new InvalidQueryException(v.getString() +
                         " cannot be converted into a NAME value");
             }
-            String stringValue = npResolver.getJCRName(value);
-            // the prefix including colon
-            String prefix = stringValue.substring(0, stringValue.indexOf(':') + 1);
 
             switch (operator) {
                 case OPERATOR_EQUAL_TO:
-                    return new TermQuery(new Term(FieldNames.LABEL, stringValue));
+                    return new NameQuery(value, version, nsMappings);
                 case OPERATOR_GREATER_THAN:
-                    Term lower = new Term(FieldNames.LABEL, stringValue);
-                    Term upper = new Term(FieldNames.LABEL,
-                            prefix + "\uFFFF");
-                    return new RangeQuery(lower, upper, false);
+                    return new NameRangeQuery(value, null, false, version, nsMappings);
                 case OPERATOR_GREATER_THAN_OR_EQUAL_TO:
-                    lower = new Term(FieldNames.LABEL, stringValue);
-                    upper = new Term(FieldNames.LABEL,
-                            prefix + "\uFFFF");
-                    return new RangeQuery(lower, upper, true);
+                    return new NameRangeQuery(value, null, true, version, nsMappings);
                 case OPERATOR_LESS_THAN:
-                    lower = new Term(FieldNames.LABEL, prefix);
-                    upper = new Term(FieldNames.LABEL, stringValue);
-                    return new RangeQuery(lower, upper, false);
+                    return new NameRangeQuery(null, value, false, version, nsMappings);
                 case OPERATOR_LESS_THAN_OR_EQUAL_TO:
-                    lower = new Term(FieldNames.LABEL, prefix);
-                    upper = new Term(FieldNames.LABEL, stringValue);
-                    return new RangeQuery(lower, upper, true);
+                    return new NameRangeQuery(null, value, true, version, nsMappings);
                 case OPERATOR_LIKE:
-                    if (stringValue.equals("%")) {
-                        return new MatchAllDocsQuery();
-                    } else {
-                        return new WildcardQuery(FieldNames.LABEL,
-                                null, stringValue);
-                    }
+                    throw new InvalidQueryException("Operator LIKE is not supported with NAME operands");
                 case OPERATOR_NOT_EQUAL_TO:
                     MatchAllDocsQuery all = new MatchAllDocsQuery();
                     BooleanQuery b = new BooleanQuery();
                     b.add(all, BooleanClause.Occur.SHOULD);
-                    b.add(new TermQuery(new Term(FieldNames.LABEL, stringValue)),
+                    b.add(new NameQuery(value, version, nsMappings),
                             BooleanClause.Occur.MUST_NOT);
                     return b;
                 default:

Added: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/LocalNameQuery.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/LocalNameQuery.java?rev=647798&view=auto
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/LocalNameQuery.java (added)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/LocalNameQuery.java Mon Apr 14 06:54:14 2008
@@ -0,0 +1,77 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jackrabbit.core.query.lucene;
+
+import org.apache.lucene.search.Query;
+import org.apache.lucene.search.TermQuery;
+import org.apache.lucene.index.IndexReader;
+import org.apache.lucene.index.Term;
+
+import java.io.IOException;
+import java.util.Set;
+
+/**
+ * <code>LocalNameQuery</code> implements a query for the local name of a node.
+ */
+public class LocalNameQuery extends Query {
+
+    /**
+     * The local name of a node.
+     */
+    private final String localName;
+
+    /**
+     * The index format version.
+     */
+    private final IndexFormatVersion version;
+
+    /**
+     * Creates a new <code>LocalNameQuery</code> for the given
+     * <code>localName</code>.
+     *
+     * @param localName the local name of a node.
+     * @param version   the version of the index.
+     */
+    public LocalNameQuery(String localName, IndexFormatVersion version) {
+        this.localName = localName;
+        this.version = version;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public Query rewrite(IndexReader reader) throws IOException {
+        if (version.getVersion() >= IndexFormatVersion.V3.getVersion()) {
+            return new TermQuery(new Term(FieldNames.LOCAL_NAME, localName));
+        } else {
+            throw new IOException("LocalNameQuery requires IndexFormatVersion V3");
+        }
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public void extractTerms(Set terms) {
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public String toString(String field) {
+        return "local-name() = " + localName;
+    }
+}

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

Added: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/LocalNameRangeQuery.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/LocalNameRangeQuery.java?rev=647798&view=auto
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/LocalNameRangeQuery.java (added)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/LocalNameRangeQuery.java Mon Apr 14 06:54:14 2008
@@ -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;
+
+import org.apache.lucene.index.Term;
+
+/**
+ * <code>LocalNameRangeQuery</code> implements a range query on the local name
+ * of nodes.
+ */
+public class LocalNameRangeQuery extends RangeQuery {
+
+    /**
+     * Creates a new <code>LocalNameRangeQuery</code>. The lower or the upper
+     * bound may be null, but not both!
+     *
+     * @param lowerName the lower bound or <code>null</code>.
+     * @param upperName the upper bound or <code>null</code>.
+     * @param inclusive if bounds are inclusive.
+     */
+    public LocalNameRangeQuery(String lowerName,
+                               String upperName,
+                               boolean inclusive) {
+        super(getLowerTerm(lowerName), getUpperTerm(upperName), inclusive);
+    }
+
+    /**
+     * Creates a {@link Term} for the lower bound local name.
+     *
+     * @param lowerName the lower bound local name.
+     * @return a {@link Term} for the lower bound local name.
+     */
+    private static Term getLowerTerm(String lowerName) {
+        String text;
+        if (lowerName == null) {
+            text = "";
+        } else {
+            text = lowerName;
+        }
+        return new Term(FieldNames.LOCAL_NAME, text);
+    }
+
+    /**
+     * Creates a {@link Term} for the upper bound local name.
+     *
+     * @param upperName the upper bound local name.
+     * @return a {@link Term} for the upper bound local name.
+     */
+    private static Term getUpperTerm(String upperName) {
+        String text;
+        if (upperName == null) {
+            text = "\uFFFF";
+        } else {
+            text = upperName;
+        }
+        return new Term(FieldNames.LOCAL_NAME, text);
+    }
+}

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

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/LuceneQueryBuilder.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/LuceneQueryBuilder.java?rev=647798&r1=647797&r2=647798&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/LuceneQueryBuilder.java (original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/LuceneQueryBuilder.java Mon Apr 14 06:54:14 2008
@@ -416,9 +416,9 @@
                 // text search on some child axis
                 Path.Element[] elements = relPath.getElements();
                 for (int i = elements.length - 1; i >= 0; i--) {
-                    String name = null;
+                    Name name = null;
                     if (!elements[i].getName().equals(RelationQueryNode.STAR_NAME_TEST)) {
-                        name = resolver.getJCRName(elements[i].getName());
+                        name = elements[i].getName();
                     }
                     // join text search with name test
                     // if path references property that's elements.length - 2
@@ -426,7 +426,7 @@
                     if (name != null
                             && ((node.getReferencesProperty() && i == elements.length - 2)
                                 || (!node.getReferencesProperty() && i == elements.length - 1))) {
-                        Query q = new TermQuery(new Term(FieldNames.LABEL, name));
+                        Query q = new NameQuery(name, indexFormatVersion, nsMappings);
                         BooleanQuery and = new BooleanQuery();
                         and.add(q, Occur.MUST);
                         and.add(context, Occur.MUST);
@@ -434,11 +434,13 @@
                     } else if ((node.getReferencesProperty() && i < elements.length - 2)
                             || (!node.getReferencesProperty() && i < elements.length - 1)) {
                         // otherwise do a parent axis step
-                        context = new ParentAxisQuery(context, name);
+                        context = new ParentAxisQuery(context, name,
+                                indexFormatVersion, nsMappings);
                     }
                 }
                 // finally select parent
-                context = new ParentAxisQuery(context, null);
+                context = new ParentAxisQuery(context, null,
+                        indexFormatVersion, nsMappings);
             }
             return context;
         } catch (NamespaceException e) {
@@ -465,15 +467,9 @@
                 } else {
                     // then this is a node != the root node
                     // will never match anything!
-                    String name = "";
-                    try {
-                        name = resolver.getJCRName(nameTest);
-                    } catch (NamespaceException e) {
-                        exceptions.add(e);
-                    }
                     BooleanQuery and = new BooleanQuery();
                     and.add(new TermQuery(new Term(FieldNames.PARENT, "")), Occur.MUST);
-                    and.add(new TermQuery(new Term(FieldNames.LABEL, name)), Occur.MUST);
+                    and.add(new NameQuery(nameTest, indexFormatVersion, nsMappings), Occur.MUST);
                     context = and;
                 }
                 LocationStepQueryNode[] tmp = new LocationStepQueryNode[steps.length - 1];
@@ -526,15 +522,9 @@
             }
         }
 
-        TermQuery nameTest = null;
+        NameQuery nameTest = null;
         if (node.getNameTest() != null) {
-            try {
-                String internalName = resolver.getJCRName(node.getNameTest());
-                nameTest = new TermQuery(new Term(FieldNames.LABEL, internalName));
-            } catch (NamespaceException e) {
-                // should never happen
-                exceptions.add(e);
-            }
+            nameTest = new NameQuery(node.getNameTest(), indexFormatVersion, nsMappings);
         }
 
         if (node.getIncludeDescendants()) {
@@ -564,7 +554,9 @@
                             andQuery.add(context, Occur.MUST);
                         } else {
                             context = new DescendantSelfAxisQuery(context, true);
-                            andQuery.add(new ChildAxisQuery(sharedItemMgr, context, null, node.getIndex()), Occur.MUST);
+                            andQuery.add(new ChildAxisQuery(sharedItemMgr,
+                                    context, null, node.getIndex(),
+                                    indexFormatVersion, nsMappings), Occur.MUST);
                         }
                     } else {
                         andQuery.add(new MatchAllDocsQuery(), Occur.MUST);
@@ -574,10 +566,14 @@
         } else {
             // name test
             if (nameTest != null) {
-                andQuery.add(new ChildAxisQuery(sharedItemMgr, context, nameTest.getTerm().text(), node.getIndex()), Occur.MUST);
+                andQuery.add(new ChildAxisQuery(sharedItemMgr, context,
+                        nameTest.getName(), node.getIndex(), indexFormatVersion,
+                        nsMappings), Occur.MUST);
             } else {
                 // select child nodes
-                andQuery.add(new ChildAxisQuery(sharedItemMgr, context, null, node.getIndex()), Occur.MUST);
+                andQuery.add(new ChildAxisQuery(sharedItemMgr, context, null,
+                        node.getIndex(), indexFormatVersion, nsMappings),
+                        Occur.MUST);
             }
         }
 
@@ -592,17 +588,14 @@
 
         try {
             String refProperty = resolver.getJCRName(node.getRefProperty());
-            String nameTest = null;
-            if (node.getNameTest() != null) {
-                nameTest = resolver.getJCRName(node.getNameTest());
-            }
 
             if (node.getIncludeDescendants()) {
                 Query refPropQuery = Util.createMatchAllQuery(refProperty, indexFormatVersion);
                 context = new DescendantSelfAxisQuery(context, refPropQuery, false);
             }
 
-            context = new DerefQuery(context, refProperty, nameTest);
+            context = new DerefQuery(context, refProperty, node.getNameTest(),
+                    indexFormatVersion, nsMappings);
 
             // attach predicates
             Object[] predicates = node.acceptOperands(this, data);
@@ -726,9 +719,7 @@
                 // parse string literal as JCR Name
                 try {
                     Name n = session.getQName(ISO9075.decode(node.getStringValue()));
-                    String translatedQName = nsMappings.translatePropertyName(n);
-                    Term t = new Term(FieldNames.LABEL, translatedQName);
-                    query = new TermQuery(t);
+                    query = new NameQuery(n, indexFormatVersion, nsMappings);
                 } catch (NameException e) {
                     exceptions.add(e);
                     return data;
@@ -738,7 +729,7 @@
                 }
             } else {
                 // will never match -> create dummy query
-                query = new TermQuery(new Term(FieldNames.UUID, "x"));
+                query = new BooleanQuery();
             }
         } else {
             switch (node.getOperation()) {
@@ -879,16 +870,17 @@
                     query = new NotQuery(Util.createMatchAllQuery(field, indexFormatVersion));
                     break;
                 case QueryConstants.OPERATION_SIMILAR:
-                    String uuid = "x";
                     try {
                         NodeId id = hmgr.resolveNodePath(session.getQPath(node.getStringValue()));
                         if (id != null) {
-                            uuid = id.getUUID().toString();
+                            query = new SimilarityQuery(id.getUUID().toString(), analyzer);
+                        } else {
+                            query = new BooleanQuery();
                         }
                     } catch (Exception e) {
                         exceptions.add(e);
+                        query = new BooleanQuery();
                     }
-                    query = new SimilarityQuery(uuid, analyzer);
                     break;
                 case QueryConstants.OPERATION_NOT_NULL:
                     query = Util.createMatchAllQuery(field, indexFormatVersion);
@@ -903,37 +895,35 @@
         }
 
         if (relPath.getLength() > 1) {
-            try {
-                // child axis in relation
-                Path.Element[] elements = relPath.getElements();
-                // elements.length - 1 = property name
-                // elements.length - 2 = last child axis name test
-                for (int i = elements.length - 2; i >= 0; i--) {
-                    String name = null;
-                    if (!elements[i].getName().equals(RelationQueryNode.STAR_NAME_TEST)) {
-                        name = resolver.getJCRName(elements[i].getName());
-                    }
-                    if (i == elements.length - 2) {
-                        // join name test with property query if there is one
-                        if (name != null) {
-                            Query nameTest = new TermQuery(new Term(FieldNames.LABEL, name));
-                            BooleanQuery and = new BooleanQuery();
-                            and.add(query, Occur.MUST);
-                            and.add(nameTest, Occur.MUST);
-                            query = and;
-                        } else {
-                            // otherwise the query can be used as is
-                        }
+            // child axis in relation
+            Path.Element[] elements = relPath.getElements();
+            // elements.length - 1 = property name
+            // elements.length - 2 = last child axis name test
+            for (int i = elements.length - 2; i >= 0; i--) {
+                Name name = null;
+                if (!elements[i].getName().equals(RelationQueryNode.STAR_NAME_TEST)) {
+                    name = elements[i].getName();
+                }
+                if (i == elements.length - 2) {
+                    // join name test with property query if there is one
+                    if (name != null) {
+                        Query nameTest = new NameQuery(name,
+                                indexFormatVersion, nsMappings);
+                        BooleanQuery and = new BooleanQuery();
+                        and.add(query, Occur.MUST);
+                        and.add(nameTest, Occur.MUST);
+                        query = and;
                     } else {
-                        query = new ParentAxisQuery(query, name);
+                        // otherwise the query can be used as is
                     }
+                } else {
+                    query = new ParentAxisQuery(query, name,
+                            indexFormatVersion, nsMappings);
                 }
-            } catch (NamespaceException e) {
-                // should never happen
-                exceptions.add(e);
             }
             // finally select the parent of the selected nodes
-            query = new ParentAxisQuery(query, null);
+            query = new ParentAxisQuery(query, null,
+                    indexFormatVersion, nsMappings);
         }
 
         return query;

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/MatchAllDocsQuery.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/MatchAllDocsQuery.java?rev=647798&r1=647797&r2=647798&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/MatchAllDocsQuery.java (original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/MatchAllDocsQuery.java Mon Apr 14 06:54:14 2008
@@ -41,9 +41,7 @@
                 return new NodeTraversingQueryHits(
                         session.getRootNode(), true);
             } catch (RepositoryException e) {
-                IOException ex = new IOException(e.getMessage());
-                ex.initCause(e);
-                throw ex;
+                throw Util.createIOException(e);
             }
         } else {
             return null;

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/MultiIndex.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/MultiIndex.java?rev=647798&r1=647797&r2=647798&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/MultiIndex.java (original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/MultiIndex.java Mon Apr 14 06:54:14 2008
@@ -265,9 +265,7 @@
             fs.init();
             store = new IndexingQueueStore(fs, INDEXING_QUEUE_FILE);
         } catch (FileSystemException e) {
-            IOException ex = new IOException();
-            ex.initCause(e);
-            throw ex;
+            throw Util.createIOException(e);
         }
 
         // initialize indexing queue

Added: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/NameQuery.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/NameQuery.java?rev=647798&view=auto
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/NameQuery.java (added)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/NameQuery.java Mon Apr 14 06:54:14 2008
@@ -0,0 +1,111 @@
+/*
+ * 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;
+
+import org.apache.lucene.search.Query;
+import org.apache.lucene.search.BooleanQuery;
+import org.apache.lucene.search.TermQuery;
+import org.apache.lucene.search.BooleanClause;
+import org.apache.lucene.index.IndexReader;
+import org.apache.lucene.index.Term;
+import org.apache.jackrabbit.spi.Name;
+import org.apache.jackrabbit.spi.commons.namespace.NamespaceResolver;
+import org.apache.jackrabbit.spi.commons.conversion.IllegalNameException;
+
+import javax.jcr.NamespaceException;
+import java.io.IOException;
+import java.util.Set;
+
+/**
+ * <code>NameQuery</code> implements a query for the name of a node.
+ */
+public class NameQuery extends Query {
+
+    /**
+     * The node name.
+     */
+    private final Name nodeName;
+
+    /**
+     * The index format version.
+     */
+    private final IndexFormatVersion version;
+
+    /**
+     * The internal namespace mappings of the index.
+     */
+    private final NamespaceMappings nsMappings;
+
+    /**
+     * Creates a new <code>NameQuery</code>.
+     *
+     * @param nodeName   the name of the nodes to return.
+     * @param version    the version of the index.
+     * @param nsMappings the namespace mappings of the index.
+     */
+    public NameQuery(Name nodeName,
+                     IndexFormatVersion version,
+                     NamespaceMappings nsMappings) {
+        this.nodeName = nodeName;
+        this.version = version;
+        this.nsMappings = nsMappings;
+    }
+
+    /**
+     * @return the name of the nodes to return.
+     */
+    public Name getName() {
+        return nodeName;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public Query rewrite(IndexReader reader) throws IOException {
+        if (version.getVersion() >= IndexFormatVersion.V3.getVersion()) {
+            // use LOCAL_NAME and NAMESPACE_URI field
+            BooleanQuery name = new BooleanQuery();
+            name.add(new TermQuery(new Term(FieldNames.NAMESPACE_URI, nodeName.getNamespaceURI())),
+                    BooleanClause.Occur.MUST);
+            name.add(new TermQuery(new Term(FieldNames.LOCAL_NAME,
+                    nodeName.getLocalName())),
+                    BooleanClause.Occur.MUST);
+            return name;
+        } else {
+            // use LABEL field
+            try {
+                return new TermQuery(new Term(FieldNames.LABEL,
+                        nsMappings.translatePropertyName(nodeName)));
+            } catch (IllegalNameException e) {
+                throw Util.createIOException(e);
+            }
+        }
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public void extractTerms(Set terms) {
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public String toString(String field) {
+        return "name() = " + nodeName.toString();
+    }
+}

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

Added: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/NameRangeQuery.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/NameRangeQuery.java?rev=647798&view=auto
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/NameRangeQuery.java (added)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/NameRangeQuery.java Mon Apr 14 06:54:14 2008
@@ -0,0 +1,193 @@
+/*
+ * 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;
+
+import org.apache.lucene.search.Query;
+import org.apache.lucene.search.BooleanQuery;
+import org.apache.lucene.search.TermQuery;
+import org.apache.lucene.search.BooleanClause;
+import org.apache.lucene.index.Term;
+import org.apache.lucene.index.IndexReader;
+import org.apache.lucene.util.ToStringUtils;
+import org.apache.jackrabbit.spi.Name;
+
+import javax.jcr.NamespaceException;
+import javax.jcr.RepositoryException;
+import java.io.IOException;
+
+/**
+ * <code>NameRangeQuery</code>...
+ */
+public class NameRangeQuery extends Query {
+
+    /**
+     * The lower name. May be <code>null</code> if <code>upperName</code> is not
+     * <code>null</code>.
+     */
+    private final Name lowerName;
+
+    /**
+     * The upper name. May be <code>null</code> if <code>lowerName</code> is not
+     * <code>null</code>.
+     */
+    private final Name upperName;
+
+    /**
+     * If <code>true</code> the range interval is inclusive.
+     */
+    private final boolean inclusive;
+
+    /**
+     * The index format version.
+     */
+    private final IndexFormatVersion version;
+
+    /**
+     * The internal namespace mappings.
+     */
+    private final NamespaceMappings nsMappings;
+
+    /**
+     * Creates a new NameRangeQuery. The lower or the upper name may be
+     * <code>null</code>, but not both!
+     *
+     * @param lowerName the lower name of the interval, or <code>null</code>
+     * @param upperName the upper name of the interval, or <code>null</code>.
+     * @param inclusive if <code>true</code> the interval is inclusive.
+     * @param version the index format version.
+     * @param nsMappings the internal namespace mappings.
+     */
+    public NameRangeQuery(Name lowerName,
+                          Name upperName,
+                          boolean inclusive,
+                          IndexFormatVersion version,
+                          NamespaceMappings nsMappings) {
+        if (lowerName == null && upperName == null) {
+            throw new IllegalArgumentException("At least one term must be non-null");
+        }
+        if (lowerName != null && upperName != null &&
+                !lowerName.getNamespaceURI().equals(upperName.getNamespaceURI())) {
+            throw new IllegalArgumentException("Both names must have the same namespace URI");
+        }
+        this.lowerName = lowerName;
+        this.upperName = upperName;
+        this.inclusive = inclusive;
+        this.version = version;
+        this.nsMappings = nsMappings;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public Query rewrite(IndexReader reader) throws IOException {
+        if (version.getVersion() >= IndexFormatVersion.V3.getVersion()) {
+            RangeQuery localNames = new RangeQuery(getLowerLocalNameTerm(),
+                    getUpperLocalNameTerm(), inclusive);
+            BooleanQuery query = new BooleanQuery();
+            query.add(new TermQuery(new Term(FieldNames.NAMESPACE_URI,
+                    getNamespaceURI())), BooleanClause.Occur.MUST);
+            query.add(localNames, BooleanClause.Occur.MUST);
+            return query.rewrite(reader);
+        } else {
+            return new RangeQuery(getLowerTerm(), getUpperTerm(), inclusive).rewrite(reader);
+        }
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public String toString(String field) {
+        StringBuffer buffer = new StringBuffer();
+        buffer.append("name():");
+        buffer.append(inclusive ? "[" : "{");
+        buffer.append(lowerName != null ? lowerName.toString() : "null");
+        buffer.append(" TO ");
+        buffer.append(upperName != null ? upperName.toString() : "null");
+        buffer.append(inclusive ? "]" : "}");
+        buffer.append(ToStringUtils.boost(getBoost()));
+        return buffer.toString();
+    }
+
+    //----------------------------< internal >----------------------------------
+
+    /**
+     * @return the namespace URI of this name query.
+     */
+    private String getNamespaceURI() {
+        return lowerName != null ? lowerName.getNamespaceURI() : upperName.getNamespaceURI();
+    }
+
+    /**
+     * @return the local name term of the lower name or <code>null</code> if no
+     *         lower name is set.
+     */
+    private Term getLowerLocalNameTerm() {
+        if (lowerName == null) {
+            return null;
+        } else {
+            return new Term(FieldNames.LOCAL_NAME, lowerName.getLocalName());
+        }
+    }
+
+    /**
+     * @return the local name term of the upper name or <code>null</code> if no
+     *         upper name is set.
+     */
+    private Term getUpperLocalNameTerm() {
+        if (upperName == null) {
+            return null;
+        } else {
+            return new Term(FieldNames.LOCAL_NAME, upperName.getLocalName());
+        }
+    }
+
+    /**
+     * @return the lower term. Must only be used for IndexFormatVersion &lt; 3.
+     * @throws IOException if a name cannot be translated.
+     */
+    private Term getLowerTerm() throws IOException {
+        try {
+            String text;
+            if (lowerName == null) {
+                text = nsMappings.getPrefix(upperName.getNamespaceURI()) + ":";
+            } else {
+                text = nsMappings.translatePropertyName(lowerName);
+            }
+            return new Term(FieldNames.LABEL, text);
+        } catch (RepositoryException e) {
+            throw Util.createIOException(e);
+        }
+    }
+
+    /**
+     * @return the upper term. Must only be used for IndexFormatVersion &lt; 3.
+     * @throws IOException if a name cannot be translated.
+     */
+    private Term getUpperTerm() throws IOException {
+        try {
+            String text;
+            if (upperName == null) {
+                text = nsMappings.getPrefix(lowerName.getNamespaceURI()) + ":\uFFFF";
+            } else {
+                text = nsMappings.translatePropertyName(upperName);
+            }
+            return new Term(FieldNames.LABEL, text);
+        } catch (RepositoryException e) {
+            throw Util.createIOException(e);
+        }
+    }
+}

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

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/NodeIndexer.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/NodeIndexer.java?rev=647798&r1=647797&r2=647798&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/NodeIndexer.java (original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/NodeIndexer.java Mon Apr 14 06:54:14 2008
@@ -182,7 +182,7 @@
             if (node.getParentId() == null) {
                 // root node
                 doc.add(new Field(FieldNames.PARENT, "", Field.Store.YES, Field.Index.NO_NORMS, Field.TermVector.NO));
-                doc.add(new Field(FieldNames.LABEL, "", Field.Store.NO, Field.Index.NO_NORMS, Field.TermVector.NO));
+                addNodeName(doc, "", "");
             } else {
                 doc.add(new Field(
                         FieldNames.PARENT, node.getParentId().toString(),
@@ -196,8 +196,8 @@
                             "Missing child node entry for node with id: "
                             + node.getNodeId());
                 }
-                String name = resolver.getJCRName(child.getName());
-                doc.add(new Field(FieldNames.LABEL, name, Field.Store.NO, Field.Index.NO_NORMS, Field.TermVector.NO));
+                Name name = child.getName();
+                addNodeName(doc, name.getNamespaceURI(), name.getLocalName());
             }
         } catch (NoSuchItemStateException e) {
             throwRepositoryException(e);
@@ -798,5 +798,25 @@
         doc.add(new Field(FieldNames.PROPERTY_LENGTHS,
                 FieldNames.createNamedLength(propertyName, length),
                 Field.Store.NO, Field.Index.NO_NORMS));
+    }
+
+    /**
+     * Depending on the index format version adds one or two fields to the
+     * document for the node name.
+     *
+     * @param doc the lucene document.
+     * @param namespaceURI the namespace URI of the node name.
+     * @param localName the local name of the node.
+     */
+    protected void addNodeName(Document doc,
+                               String namespaceURI,
+                               String localName) throws NamespaceException {
+        String name = mappings.getPrefix(namespaceURI) + ":" + localName;
+        doc.add(new Field(FieldNames.LABEL, name, Field.Store.NO, Field.Index.NO_NORMS));
+        // as of version 3, also index combination of namespace URI and local name
+        if (indexFormatVersion.getVersion() >= IndexFormatVersion.V3.getVersion()) {
+            doc.add(new Field(FieldNames.NAMESPACE_URI, namespaceURI, Field.Store.NO, Field.Index.NO_NORMS));
+            doc.add(new Field(FieldNames.LOCAL_NAME, localName, Field.Store.NO, Field.Index.NO_NORMS));
+        }
     }
 }

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/ParentAxisQuery.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/ParentAxisQuery.java?rev=647798&r1=647797&r2=647798&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/ParentAxisQuery.java (original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/ParentAxisQuery.java Mon Apr 14 06:54:14 2008
@@ -24,8 +24,9 @@
 import org.apache.lucene.search.Similarity;
 import org.apache.lucene.search.HitCollector;
 import org.apache.lucene.index.IndexReader;
-import org.apache.lucene.index.Term;
-import org.apache.lucene.index.TermDocs;
+import org.apache.jackrabbit.spi.Name;
+import org.apache.jackrabbit.core.query.lucene.hits.ScorerHits;
+import org.apache.jackrabbit.core.query.lucene.hits.Hits;
 
 import java.io.IOException;
 import java.util.BitSet;
@@ -52,7 +53,17 @@
      * The nameTest to apply on the parent axis, or <code>null</code> if any
      * parent node should be selected.
      */
-    private final String nameTest;
+    private final Name nameTest;
+
+    /**
+     * The index format version.
+     */
+    private final IndexFormatVersion version;
+
+    /**
+     * The internal namespace mappings.
+     */
+    private final NamespaceMappings nsMappings;
 
     /**
      * The scorer of the context query
@@ -66,10 +77,15 @@
      * @param context  the context for this query.
      * @param nameTest a name test or <code>null</code> if any parent node is
      *                 selected.
+     * @param version the index format version.
+     * @param nsMappings the internal namespace mappings.
      */
-    ParentAxisQuery(Query context, String nameTest) {
+    ParentAxisQuery(Query context, Name nameTest,
+                   IndexFormatVersion version, NamespaceMappings nsMappings) {
         this.contextQuery = context;
         this.nameTest = nameTest;
+        this.version = version;
+        this.nsMappings = nsMappings;
     }
 
     /**
@@ -97,7 +113,7 @@
         if (cQuery == contextQuery) {
             return this;
         } else {
-            return new ParentAxisQuery(cQuery, nameTest);
+            return new ParentAxisQuery(cQuery, nameTest, version, nsMappings);
         }
     }
 
@@ -172,7 +188,8 @@
         public Scorer scorer(IndexReader reader) throws IOException {
             contextScorer = contextQuery.weight(searcher).scorer(reader);
             HierarchyResolver resolver = (HierarchyResolver) reader;
-            return new ParentAxisScorer(searcher.getSimilarity(), reader, resolver);
+            return new ParentAxisScorer(searcher.getSimilarity(),
+                    reader, searcher, resolver);
         }
 
         /**
@@ -201,6 +218,11 @@
         private final HierarchyResolver hResolver;
 
         /**
+         * The searcher instance.
+         */
+        private final Searcher searcher;
+
+        /**
          * BitSet storing the id's of selected documents
          */
         private BitSet hits;
@@ -225,10 +247,16 @@
          *
          * @param similarity the <code>Similarity</code> instance to use.
          * @param reader     for index access.
+         * @param searcher   the index searcher.
+         * @param resolver   the hierarchy resolver.
          */
-        protected ParentAxisScorer(Similarity similarity, IndexReader reader, HierarchyResolver resolver) {
+        protected ParentAxisScorer(Similarity similarity,
+                                   IndexReader reader,
+                                   Searcher searcher,
+                                   HierarchyResolver resolver) {
             super(similarity);
             this.reader = reader;
+            this.searcher = searcher;
             this.hResolver = resolver;
         }
 
@@ -305,24 +333,21 @@
 
                 // filter out documents that do not match the name test
                 if (nameTest != null) {
-                    TermDocs tDocs = reader.termDocs(new Term(FieldNames.LABEL, nameTest));
-                    try {
-                        for (int i = hits.nextSetBit(0); i >= 0; i = hits.nextSetBit(i + 1)) {
-                            if (!tDocs.skipTo(i)) {
-                                // no more name tests, clear remaining
-                                hits.clear(i, hits.length());
-                            } else {
-                                // assert doc >= i
-                                int doc = tDocs.doc();
-                                if (doc > i) {
-                                    // clear hits
-                                    hits.clear(i, doc);
-                                    i = doc;
-                                }
+                    Query nameQuery = new NameQuery(nameTest, version, nsMappings);
+                    Hits nameHits = new ScorerHits(nameQuery.weight(searcher).scorer(reader));
+                    for (int i = hits.nextSetBit(0); i >= 0; i = hits.nextSetBit(i + 1)) {
+                        int doc = nameHits.skipTo(i);
+                        if (doc == -1) {
+                            // no more name tests, clear remaining
+                            hits.clear(i, hits.length());
+                        } else {
+                            // assert doc >= i
+                            if (doc > i) {
+                                // clear hits
+                                hits.clear(i, doc);
+                                i = doc;
                             }
                         }
-                    } finally {
-                        tDocs.close();
                     }
                 }
             }

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/PropertiesSynonymProvider.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/PropertiesSynonymProvider.java?rev=647798&r1=647797&r2=647798&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/PropertiesSynonymProvider.java (original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/PropertiesSynonymProvider.java Mon Apr 14 06:54:14 2008
@@ -89,9 +89,7 @@
             configLastModified = config.lastModified();
             lastCheck = System.currentTimeMillis();
         } catch (FileSystemException e) {
-            IOException ex = new IOException();
-            ex.initCause(e);
-            throw ex;
+            throw Util.createIOException(e);
         }
     }
 
@@ -161,9 +159,7 @@
             }
             return synonyms;
         } catch (FileSystemException e) {
-            IOException ex = new IOException();
-            ex.initCause(e);
-            throw ex;
+            throw Util.createIOException(e);
         }
     }
 

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/SearchIndex.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/SearchIndex.java?rev=647798&r1=647797&r2=647798&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/SearchIndex.java (original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/SearchIndex.java Mon Apr 14 06:54:14 2008
@@ -490,6 +490,11 @@
 
         log.info("Index initialized: {} Version: {}",
                 new Object[]{path, index.getIndexFormatVersion()});
+        if (!index.getIndexFormatVersion().equals(getIndexFormatVersion())) {
+            log.warn("Using Version {} for reading. Please re-index version " +
+                    "storage for optimal performance.",
+                    new Integer(getIndexFormatVersion().getVersion()));
+        }
     }
 
     /**
@@ -719,9 +724,7 @@
         try {
             ep = (ExcerptProvider) excerptProviderClass.newInstance();
         } catch (Exception e) {
-            IOException ex = new IOException();
-            ex.initCause(e);
-            throw ex;
+            throw Util.createIOException(e);
         }
         ep.init(query, this);
         return ep;

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/SimilarityQuery.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/SimilarityQuery.java?rev=647798&r1=647797&r2=647798&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/SimilarityQuery.java (original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/SimilarityQuery.java Mon Apr 14 06:54:14 2008
@@ -17,7 +17,7 @@
 package org.apache.jackrabbit.core.query.lucene;
 
 import org.apache.lucene.search.Query;
-import org.apache.lucene.search.TermQuery;
+import org.apache.lucene.search.BooleanQuery;
 import org.apache.lucene.index.IndexReader;
 import org.apache.lucene.index.Term;
 import org.apache.lucene.index.TermDocs;
@@ -67,7 +67,7 @@
             return similarityQuery.rewrite(reader);
         } else {
             // return dummy query that never matches
-            return new TermQuery(new Term(FieldNames.UUID, "x"));
+            return new BooleanQuery();
         }
     }
 

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=647798&r1=647797&r2=647798&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 14 06:54:14 2008
@@ -96,4 +96,15 @@
             return new MatchAllQuery(name);
         }
     }
+
+    /**
+     * Creates an {@link IOException} with <code>t</code> as its cause.
+     *
+     * @param t the cause.
+     */
+    public static IOException createIOException(Throwable t) {
+        IOException ex = new IOException(t.getMessage());
+        ex.initCause(t);
+        return ex;
+    }
 }

Added: jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/query/qom/NodeLocalNameTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/query/qom/NodeLocalNameTest.java?rev=647798&view=auto
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/query/qom/NodeLocalNameTest.java (added)
+++ jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/query/qom/NodeLocalNameTest.java Mon Apr 14 06:54:14 2008
@@ -0,0 +1,216 @@
+/*
+ * 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.qom;
+
+import javax.jcr.RepositoryException;
+import javax.jcr.Value;
+import javax.jcr.Node;
+import javax.jcr.PropertyType;
+import javax.jcr.query.Query;
+import java.util.Calendar;
+
+/**
+ * <code>NodeLocalNameTest</code> checks if conversion of literals is correctly
+ * performed and operators work as specified.
+ * TODO: assumes https://jsr-283.dev.java.net/issues/show_bug.cgi?id=483 gets resolved as initially proposed
+ */
+public class NodeLocalNameTest extends AbstractQOMTest {
+
+    private Node node1;
+
+    private String nodeLocalName;
+
+    protected void setUp() throws Exception {
+        super.setUp();
+        node1 = testRootNode.addNode(nodeName1, testNodeType);
+        testRootNode.save();
+        int colon = nodeName1.indexOf(':');
+        if (colon != -1) {
+            nodeLocalName = nodeName1.substring(colon + 1);
+        } else {
+            nodeLocalName = nodeName1;
+        }
+    }
+
+    protected void tearDown() throws Exception {
+        node1 = null;
+        super.tearDown();
+    }
+
+    public void testStringLiteral() throws RepositoryException {
+        Value literal = superuser.getValueFactory().createValue(nodeLocalName);
+        Query q = createQuery(OPERATOR_EQUAL_TO, literal);
+        checkResult(q.execute(), new Node[]{node1});
+    }
+
+    public void testStringLiteralInvalidName() throws RepositoryException {
+        Value literal = superuser.getValueFactory().createValue("[" + nodeLocalName);
+        Query q = createQuery(OPERATOR_EQUAL_TO, literal);
+        checkResult(q.execute(), new Node[]{});
+    }
+
+    public void testBinaryLiteral() throws RepositoryException {
+        Value literal = superuser.getValueFactory().createValue(
+                nodeLocalName, PropertyType.BINARY);
+        Query q = createQuery(OPERATOR_EQUAL_TO, literal);
+        checkResult(q.execute(), new Node[]{node1});
+    }
+
+    public void testDateLiteral() throws RepositoryException {
+        Value literal = superuser.getValueFactory().createValue(Calendar.getInstance());
+        Query q = createQuery(OPERATOR_EQUAL_TO, literal);
+        checkResult(q.execute(), new Node[]{});
+    }
+
+    public void testDoubleLiteral() throws RepositoryException {
+        Value literal = superuser.getValueFactory().createValue(Math.PI);
+        Query q = createQuery(OPERATOR_EQUAL_TO, literal);
+        checkResult(q.execute(), new Node[]{});
+    }
+
+    public void testDecimalLiteral() throws RepositoryException {
+        // TODO must not match node
+    }
+
+    public void testLongLiteral() throws RepositoryException {
+        Value literal = superuser.getValueFactory().createValue(283);
+        Query q = createQuery(OPERATOR_EQUAL_TO, literal);
+        checkResult(q.execute(), new Node[]{});
+    }
+
+    public void testBooleanLiteral() throws RepositoryException {
+        Value literal = superuser.getValueFactory().createValue(true);
+        Query q = createQuery(OPERATOR_EQUAL_TO, literal);
+        checkResult(q.execute(), new Node[]{});
+    }
+
+    public void testNameLiteral() throws RepositoryException {
+        Value literal = superuser.getValueFactory().createValue(
+                nodeLocalName, PropertyType.NAME);
+        Query q = createQuery(OPERATOR_EQUAL_TO, literal);
+        checkResult(q.execute(), new Node[]{node1});
+    }
+
+    public void testPathLiteral() throws RepositoryException {
+        Value literal = superuser.getValueFactory().createValue(
+                nodeLocalName, PropertyType.PATH);
+        Query q = createQuery(OPERATOR_EQUAL_TO, literal);
+        checkResult(q.execute(), new Node[]{node1});
+
+        literal = superuser.getValueFactory().createValue(
+                node1.getPath(), PropertyType.PATH);
+        q = createQuery(OPERATOR_EQUAL_TO, literal);
+        checkResult(q.execute(), new Node[]{});
+
+        literal = superuser.getValueFactory().createValue(
+                nodeName1 + "/" + nodeName1, PropertyType.PATH);
+        q = createQuery(OPERATOR_EQUAL_TO, literal);
+        checkResult(q.execute(), new Node[]{});
+    }
+
+    public void testReferenceLiteral() throws RepositoryException {
+        if (!node1.isNodeType(mixReferenceable)) {
+            node1.addMixin(mixReferenceable);
+        }
+        node1.save();
+        Value literal = superuser.getValueFactory().createValue(node1);
+        Query q = createQuery(OPERATOR_EQUAL_TO, literal);
+        checkResult(q.execute(), new Node[]{});
+    }
+
+    public void testWeakReferenceLiteral() throws RepositoryException {
+        // TODO must not match node
+    }
+
+    public void testURILiteral() throws RepositoryException {
+        // TODO must not match node
+    }
+
+    public void testEqualTo() throws RepositoryException {
+        checkOperator(OPERATOR_EQUAL_TO, false, true, false);
+    }
+
+    public void testGreaterThan() throws RepositoryException {
+        checkOperator(OPERATOR_GREATER_THAN, true, false, false);
+    }
+
+    public void testGreaterThanOrEqualTo() throws RepositoryException {
+        checkOperator(OPERATOR_GREATER_THAN_OR_EQUAL_TO, true, true, false);
+    }
+
+    public void testLessThan() throws RepositoryException {
+        checkOperator(OPERATOR_LESS_THAN, false, false, true);
+    }
+
+    public void testLessThanOrEqualTo() throws RepositoryException {
+        checkOperator(OPERATOR_LESS_THAN_OR_EQUAL_TO, false, true, true);
+    }
+
+    public void testLike() throws RepositoryException {
+        checkOperator(OPERATOR_LIKE, false, true, false);
+    }
+
+    public void testNotEqualTo() throws RepositoryException {
+        checkOperator(OPERATOR_NOT_EQUAL_TO, true, false, true);
+    }
+
+    //------------------------------< helper >----------------------------------
+
+    private void checkOperator(int operator,
+                               boolean matchesLesser,
+                               boolean matchesEqual,
+                               boolean matchesGreater)
+            throws RepositoryException {
+        checkOperatorSingleLiteral(createLexicographicallyLesser(nodeLocalName), operator, matchesLesser);
+        checkOperatorSingleLiteral(nodeLocalName, operator, matchesEqual);
+        checkOperatorSingleLiteral(createLexicographicallyGreater(nodeLocalName), operator, matchesGreater);
+    }
+
+    private void checkOperatorSingleLiteral(String literal,
+                                            int operator,
+                                            boolean matches)
+            throws RepositoryException {
+        Value value = superuser.getValueFactory().createValue(literal);
+        Query q = createQuery(operator, value);
+        checkResult(q.execute(), matches ? new Node[]{node1} : new Node[0]);
+    }
+
+    private String createLexicographicallyGreater(String name) {
+        StringBuffer tmp = new StringBuffer(name);
+        tmp.setCharAt(tmp.length() - 1, (char) (tmp.charAt(tmp.length() - 1) + 1));
+        return tmp.toString();
+    }
+
+    private String createLexicographicallyLesser(String name) {
+        StringBuffer tmp = new StringBuffer(name);
+        tmp.setCharAt(tmp.length() - 1, (char) (tmp.charAt(tmp.length() - 1) - 1));
+        return tmp.toString();
+    }
+
+    private Query createQuery(int operator, Value literal) throws RepositoryException {
+        return qomFactory.createQuery(
+                qomFactory.selector(testNodeType, "s"),
+                qomFactory.and(
+                        qomFactory.childNode("s", testRoot),
+                        qomFactory.comparison(
+                                qomFactory.nodeLocalName("s"),
+                                operator,
+                                qomFactory.literal(literal)
+                        )
+                ), null, null);
+    }
+}

Propchange: jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/query/qom/NodeLocalNameTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/query/qom/NodeNameTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/query/qom/NodeNameTest.java?rev=647798&r1=647797&r2=647798&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/query/qom/NodeNameTest.java (original)
+++ jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/query/qom/NodeNameTest.java Mon Apr 14 06:54:14 2008
@@ -177,26 +177,6 @@
         checkOperator(OPERATOR_EQUAL_TO, false, true, false);
     }
 
-    public void testGreaterThan() throws RepositoryException {
-        checkOperator(OPERATOR_GREATER_THAN, true, false, false);
-    }
-
-    public void testGreaterThanOrEqualTo() throws RepositoryException {
-        checkOperator(OPERATOR_GREATER_THAN_OR_EQUAL_TO, true, true, false);
-    }
-
-    public void testLessThan() throws RepositoryException {
-        checkOperator(OPERATOR_LESS_THAN, false, false, true);
-    }
-
-    public void testLessThanOrEqualTo() throws RepositoryException {
-        checkOperator(OPERATOR_LESS_THAN_OR_EQUAL_TO, false, true, true);
-    }
-
-    public void testLike() throws RepositoryException {
-        checkOperator(OPERATOR_LIKE, false, true, false);
-    }
-
     public void testNotEqualTo() throws RepositoryException {
         checkOperator(OPERATOR_NOT_EQUAL_TO, true, false, true);
     }

Modified: jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/query/qom/TestAll.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/query/qom/TestAll.java?rev=647798&r1=647797&r2=647798&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/query/qom/TestAll.java (original)
+++ jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/query/qom/TestAll.java Mon Apr 14 06:54:14 2008
@@ -33,6 +33,7 @@
         suite.addTestSuite(ChildNodeTest.class);
         suite.addTestSuite(DescendantNodeTest.class);
         suite.addTestSuite(LengthTest.class);
+        suite.addTestSuite(NodeLocalNameTest.class);
         suite.addTestSuite(NodeNameTest.class);
         suite.addTestSuite(PropertyExistenceTest.class);
         suite.addTestSuite(QueryObjectModelFactoryTest.class);



Mime
View raw message