jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mreut...@apache.org
Subject svn commit: r643404 - in /jackrabbit/trunk/jackrabbit-core/src: main/java/org/apache/jackrabbit/core/query/lucene/ test/java/org/apache/jackrabbit/core/query/qom/
Date Tue, 01 Apr 2008 13:59:36 GMT
Author: mreutegg
Date: Tue Apr  1 06:59:27 2008
New Revision: 643404

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

Added:
    jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/query/qom/PropertyExistenceTest.java
  (with props)
Modified:
    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/QueryObjectModelImpl.java
    jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/query/qom/TestAll.java
    jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/query/qom/UpperLowerCaseTest.java

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=643404&r1=643403&r2=643404&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
Tue Apr  1 06:59:27 2008
@@ -155,6 +155,11 @@
     private final Map selectors = new HashMap();
 
     /**
+     * The index format version.
+     */
+    private final IndexFormatVersion version;
+
+    /**
      * Creates a new <code>LuceneQueryBuilder</code> instance.
      *
      * @param qomTree            the root of the query object model.
@@ -168,6 +173,7 @@
      * @param synonymProvider    the synonym provider or <code>null</code> if
      *                           node is configured.
      * @param bindVariableValues the bind variable values.
+     * @param version            the index format version.
      */
     private JQOM2LuceneQueryBuilder(QueryObjectModelTree qomTree,
                                     SessionImpl session,
@@ -177,7 +183,8 @@
                                     Analyzer analyzer,
                                     PropertyTypeRegistry propReg,
                                     SynonymProvider synonymProvider,
-                                    Map bindVariableValues) {
+                                    Map bindVariableValues,
+                                    IndexFormatVersion version) {
         this.qomTree = qomTree;
         this.session = session;
         this.ism = ism;
@@ -188,6 +195,7 @@
         this.propRegistry = propReg;
         this.synonymProvider = synonymProvider;
         this.bindVariableValues = bindVariableValues;
+        this.version = version;
     }
 
     /**
@@ -206,6 +214,7 @@
      * @param synonymProvider    the synonym provider or <code>null</code> if
      *                           node is configured.
      * @param bindVariableValues the bind variable values.
+     * @param version            the index format version.
      * @return the lucene query tree.
      * @throws RepositoryException if an error occurs during the translation.
      */
@@ -216,15 +225,16 @@
                                     Analyzer analyzer,
                                     PropertyTypeRegistry propReg,
                                     SynonymProvider synonymProvider,
-                                    Map bindVariableValues)
+                                    Map bindVariableValues,
+                                    IndexFormatVersion version)
             throws RepositoryException {
 
         NodeId id = ((NodeImpl) session.getRootNode()).getNodeId();
         HierarchyManager hmgr = new HierarchyManagerImpl(
                 id, sharedItemMgr, session);
         JQOM2LuceneQueryBuilder builder = new JQOM2LuceneQueryBuilder(
-                qomTree, session, sharedItemMgr, hmgr, nsMappings,
-                analyzer, propReg, synonymProvider, bindVariableValues);
+                qomTree, session, sharedItemMgr, hmgr, nsMappings, analyzer,
+                propReg, synonymProvider, bindVariableValues, version);
 
         return builder.createLuceneQuery();
     }
@@ -507,8 +517,7 @@
 
     public Object visit(PropertyExistenceImpl node, Object data) throws Exception {
         String propName = npResolver.getJCRName(node.getPropertyQName());
-        // TODO respect index version
-        return new MatchAllQuery(propName);
+        return createMatchAllQuery(propName);
     }
 
     public Object visit(PropertyValueImpl node, Object data) throws Exception {
@@ -765,6 +774,22 @@
             throw new InvalidQueryException(
                     "lower/upper-case not supported on operand "
                     + operand.getClass().getName());
+        }
+    }
+
+    /**
+     * Depending on the index format this method returns
+     * a query that matches all nodes that have a property named 'field'
+     *
+     * @param field
+     * @return Query that matches all nodes that have a property named 'field'
+     */
+    private Query createMatchAllQuery(String field) {
+        if (version.getVersion() >= IndexFormatVersion.V2.getVersion()) {
+            // new index format style
+            return new TermQuery(new Term(FieldNames.PROPERTIES_SET, field));
+        } else {
+            return new MatchAllQuery(field);
         }
     }
 }

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/QueryObjectModelImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/QueryObjectModelImpl.java?rev=643404&r1=643403&r2=643404&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/QueryObjectModelImpl.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/QueryObjectModelImpl.java
Tue Apr  1 06:59:27 2008
@@ -100,7 +100,8 @@
         Query query = JQOM2LuceneQueryBuilder.createQuery(qomTree, session,
                 index.getContext().getItemStateManager(),
                 index.getNamespaceMappings(), index.getTextAnalyzer(),
-                propReg, index.getSynonymProvider(), getBindVariableValues());
+                propReg, index.getSynonymProvider(), getBindVariableValues(),
+                index.getIndexFormatVersion());
 
         ColumnImpl[] columns = qomTree.getColumns();
         Name[] selectProps = new Name[columns.length];

Added: jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/query/qom/PropertyExistenceTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/query/qom/PropertyExistenceTest.java?rev=643404&view=auto
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/query/qom/PropertyExistenceTest.java
(added)
+++ jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/query/qom/PropertyExistenceTest.java
Tue Apr  1 06:59:27 2008
@@ -0,0 +1,52 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jackrabbit.core.query.qom;
+
+import javax.jcr.RepositoryException;
+import javax.jcr.Node;
+import javax.jcr.query.QueryResult;
+
+/**
+ * <code>PropertyExistenceTest</code> performs a test with
+ * <code>PropertyExistence</code>.
+ */
+public class PropertyExistenceTest extends AbstractQOMTest {
+
+    public void testPropertyExistence() throws RepositoryException {
+        Node n1 = testRootNode.addNode(nodeName1, testNodeType);
+        n1.setProperty(propertyName1, "abc");
+        Node n2 = testRootNode.addNode(nodeName2, testNodeType);
+        n2.setProperty(propertyName2, "abc");
+        testRootNode.save();
+
+        QueryResult result = qomFactory.createQuery(
+                qomFactory.selector(testNodeType, "s"),
+                qomFactory.and(
+                        qomFactory.childNode("s", testRoot),
+                        qomFactory.propertyExistence("s", propertyName1)
+                ), null, null).execute();
+        checkResult(result, new Node[]{n1});
+
+        result = qomFactory.createQuery(
+                qomFactory.selector(testNodeType, "s"),
+                qomFactory.and(
+                        qomFactory.childNode("s", testRoot),
+                        qomFactory.propertyExistence("s", propertyName2)
+                ), null, null).execute();
+        checkResult(result, new Node[]{n2});
+    }
+}

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

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=643404&r1=643403&r2=643404&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
Tue Apr  1 06:59:27 2008
@@ -33,9 +33,11 @@
         suite.addTestSuite(ChildNodeTest.class);
         suite.addTestSuite(DescendantNodeTest.class);
         suite.addTestSuite(NodeNameTest.class);
+        suite.addTestSuite(PropertyExistenceTest.class);
         suite.addTestSuite(QueryObjectModelFactoryTest.class);
         suite.addTestSuite(SameNodeTest.class);
         suite.addTestSuite(SelectorTest.class);
+        suite.addTestSuite(UpperLowerCaseTest.class);
 
         return suite;
     }

Modified: jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/query/qom/UpperLowerCaseTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/query/qom/UpperLowerCaseTest.java?rev=643404&r1=643403&r2=643404&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/query/qom/UpperLowerCaseTest.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/query/qom/UpperLowerCaseTest.java
Tue Apr  1 06:59:27 2008
@@ -38,7 +38,7 @@
     protected void setUp() throws Exception {
         super.setUp();
         vf = superuser.getValueFactory();
-        node = testRootNode.addNode(nodeName1);
+        node = testRootNode.addNode(nodeName1, testNodeType);
         node.setProperty(propertyName1, "abc");
         node.setProperty(propertyName2, "ABC");
         testRootNode.save();



Mime
View raw message