jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mreut...@apache.org
Subject svn commit: r907659 - in /jackrabbit/trunk/jackrabbit-core/src: main/java/org/apache/jackrabbit/core/query/lucene/ test/java/org/apache/jackrabbit/core/query/
Date Mon, 08 Feb 2010 14:04:03 GMT
Author: mreutegg
Date: Mon Feb  8 14:04:02 2010
New Revision: 907659

URL: http://svn.apache.org/viewvc?rev=907659&view=rev
Log:
JCR-2417: RepositoryException when using BindVariables in JCR-SQL2 CONTAINS

Added:
    jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/query/FulltextSQL2QueryTest.java
  (with props)
Modified:
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/LuceneQueryFactoryImpl.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/TestAll.java

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/LuceneQueryFactoryImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/LuceneQueryFactoryImpl.java?rev=907659&r1=907658&r2=907659&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/LuceneQueryFactoryImpl.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/LuceneQueryFactoryImpl.java
Mon Feb  8 14:04:02 2010
@@ -16,37 +16,41 @@
  */
 package org.apache.jackrabbit.core.query.lucene;
 
-import java.util.List;
 import java.util.ArrayList;
 import java.util.Arrays;
+import java.util.List;
+import java.util.Map;
 
-import javax.jcr.nodetype.NodeTypeManager;
+import javax.jcr.RepositoryException;
+import javax.jcr.Value;
 import javax.jcr.nodetype.NodeType;
 import javax.jcr.nodetype.NodeTypeIterator;
+import javax.jcr.nodetype.NodeTypeManager;
+import javax.jcr.query.InvalidQueryException;
 import javax.jcr.query.qom.Literal;
 import javax.jcr.query.qom.StaticOperand;
-import javax.jcr.RepositoryException;
 
-import org.apache.lucene.search.Query;
-import org.apache.lucene.search.BooleanQuery;
-import org.apache.lucene.search.BooleanClause;
-import org.apache.lucene.search.SortComparatorSource;
-import org.apache.lucene.index.Term;
-import org.apache.lucene.queryParser.QueryParser;
-import org.apache.lucene.queryParser.ParseException;
-import org.apache.lucene.analysis.Analyzer;
-import org.apache.jackrabbit.spi.commons.query.qom.SelectorImpl;
+import org.apache.jackrabbit.core.HierarchyManager;
+import org.apache.jackrabbit.core.SessionImpl;
+import org.apache.jackrabbit.spi.Name;
+import org.apache.jackrabbit.spi.commons.conversion.NamePathResolver;
+import org.apache.jackrabbit.spi.commons.name.NameConstants;
+import org.apache.jackrabbit.spi.commons.query.qom.BindVariableValueImpl;
+import org.apache.jackrabbit.spi.commons.query.qom.DefaultQOMTreeVisitor;
 import org.apache.jackrabbit.spi.commons.query.qom.FullTextSearchImpl;
+import org.apache.jackrabbit.spi.commons.query.qom.JoinConditionImpl;
+import org.apache.jackrabbit.spi.commons.query.qom.JoinImpl;
 import org.apache.jackrabbit.spi.commons.query.qom.PropertyExistenceImpl;
+import org.apache.jackrabbit.spi.commons.query.qom.SelectorImpl;
 import org.apache.jackrabbit.spi.commons.query.qom.SourceImpl;
-import org.apache.jackrabbit.spi.commons.query.qom.JoinImpl;
-import org.apache.jackrabbit.spi.commons.query.qom.DefaultQOMTreeVisitor;
-import org.apache.jackrabbit.spi.commons.query.qom.JoinConditionImpl;
-import org.apache.jackrabbit.spi.commons.name.NameConstants;
-import org.apache.jackrabbit.spi.commons.conversion.NamePathResolver;
-import org.apache.jackrabbit.spi.Name;
-import org.apache.jackrabbit.core.SessionImpl;
-import org.apache.jackrabbit.core.HierarchyManager;
+import org.apache.lucene.analysis.Analyzer;
+import org.apache.lucene.index.Term;
+import org.apache.lucene.queryParser.ParseException;
+import org.apache.lucene.queryParser.QueryParser;
+import org.apache.lucene.search.BooleanClause;
+import org.apache.lucene.search.BooleanQuery;
+import org.apache.lucene.search.Query;
+import org.apache.lucene.search.SortComparatorSource;
 
 /**
  * <code>LuceneQueryFactoryImpl</code> implements a lucene query factory.
@@ -94,6 +98,11 @@
     private final IndexFormatVersion version;
 
     /**
+     * The Bind Variable values.
+     */
+    private final Map<Name, Value> bindVariables;
+
+    /**
      * Creates a new lucene query factory.
      *
      * @param session         the session that executes the query.
@@ -103,6 +112,7 @@
      * @param analyzer        the analyzer of the index.
      * @param synonymProvider the synonym provider of the index.
      * @param version         the version of the index format.
+     * @param bindVariables   the bind variable values of the query
      */
     public LuceneQueryFactoryImpl(SessionImpl session,
                                   SortComparatorSource scs,
@@ -110,7 +120,8 @@
                                   NamespaceMappings nsMappings,
                                   Analyzer analyzer,
                                   SynonymProvider synonymProvider,
-                                  IndexFormatVersion version) {
+                                  IndexFormatVersion version,
+                                  Map<Name, Value> bindVariables) {
         this.session = session;
         this.scs = scs;
         this.hmgr = hmgr;
@@ -119,6 +130,7 @@
         this.synonymProvider = synonymProvider;
         this.version = version;
         this.npResolver = NamePathResolverImpl.create(nsMappings);
+        this.bindVariables = bindVariables;
     }
 
     /**
@@ -211,6 +223,13 @@
             if (expr instanceof Literal) {
                 return parser.parse(
                         ((Literal) expr).getLiteralValue().getString());
+            } else if (expr instanceof BindVariableValueImpl) {
+                Value value = this.bindVariables.get(
+                        ((BindVariableValueImpl) expr).getBindVariableQName());
+                if (value == null) {
+                    throw new InvalidQueryException("Bind variable not bound");
+                }
+                return parser.parse(value.getString());
             } else {
                 throw new RepositoryException(
                         "Unknown static operand type: " + expr);

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=907659&r1=907658&r2=907659&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
Mon Feb  8 14:04:02 2010
@@ -101,7 +101,8 @@
                 index.getSortComparatorSource(),
                 index.getContext().getHierarchyManager(),
                 index.getNamespaceMappings(), index.getTextAnalyzer(),
-                index.getSynonymProvider(), index.getIndexFormatVersion());
+                index.getSynonymProvider(), index.getIndexFormatVersion(),
+                getBindVariableValues());
 
         MultiColumnQuery query = factory.create(qomTree.getSource());
 

Added: jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/query/FulltextSQL2QueryTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/query/FulltextSQL2QueryTest.java?rev=907659&view=auto
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/query/FulltextSQL2QueryTest.java
(added)
+++ jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/query/FulltextSQL2QueryTest.java
Mon Feb  8 14:04:02 2010
@@ -0,0 +1,60 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jackrabbit.core.query;
+
+import javax.jcr.Node;
+import javax.jcr.query.Query;
+import javax.jcr.query.QueryResult;
+
+/**
+ * Performs tests with the <code>CONTAINS</code> function in JCR_SQL2 queries.
+ */
+public class FulltextSQL2QueryTest extends AbstractQueryTest {
+
+    public void testFulltextSimpleSQL() throws Exception {
+        Node foo = testRootNode.addNode("foo");
+        foo.setProperty("mytext", new String[]{"the quick brown fox jumps over the lazy dog."});
+
+        testRootNode.save();
+
+        String sql = "SELECT * FROM [nt:unstructured]"
+                + " WHERE ISCHILDNODE([" + testRoot + "])"
+                + " AND CONTAINS(mytext, 'fox')";
+        Query q = superuser.getWorkspace().getQueryManager().createQuery(sql, Query.JCR_SQL2);
+        QueryResult result = q.execute();
+        checkResult(result, 1);
+    }
+
+    public void testFulltextBindVariableSQL() throws Exception {
+        Node foo = testRootNode.addNode("foo");
+        foo.setProperty("mytext", new String[]{"the quick brown fox jumps over the lazy dog."});
+        
+        testRootNode.save();
+        
+        String sql = "SELECT * FROM [nt:unstructured]"
+            + " WHERE ISCHILDNODE([" + testRoot + "])"
+            + " AND CONTAINS(mytext, $searchExpression)";
+        Query q = superuser.getWorkspace().getQueryManager().createQuery(sql, Query.JCR_SQL2);
+        assertEquals("Expected exactly 1 bind variable", 1, q.getBindVariableNames().length);
+        assertEquals("searchExpression", q.getBindVariableNames()[0]);
+
+        q.bindValue("searchExpression", superuser.getValueFactory().createValue("fox"));
+        QueryResult result = q.execute();
+        checkResult(result, 1);
+    }
+
+}

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

Modified: jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/query/TestAll.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/query/TestAll.java?rev=907659&r1=907658&r2=907659&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/query/TestAll.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/query/TestAll.java
Mon Feb  8 14:04:02 2010
@@ -62,6 +62,7 @@
         suite.addTestSuite(ShareableNodeTest.class);
         suite.addTestSuite(ParentNodeTest.class);
         suite.addTestSuite(SimilarQueryTest.class);
+        suite.addTestSuite(FulltextSQL2QueryTest.class);
 
         return suite;
     }



Mime
View raw message