jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mreut...@apache.org
Subject svn commit: r785594 - in /jackrabbit/trunk: jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/ jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/join/ jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/qu...
Date Wed, 17 Jun 2009 13:33:25 GMT
Author: mreutegg
Date: Wed Jun 17 13:33:24 2009
New Revision: 785594

URL: http://svn.apache.org/viewvc?rev=785594&view=rev
Log:
JCR-2076: JSR 283: QOM and SQL2
- QueryObjectModelBuilder for SQL2 parser
- support for SQL2 in jackrabbit-core

Added:
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/AQTQueryFactory.java
  (with props)
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/CompoundQueryFactory.java
  (with props)
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/QOMQueryFactory.java
  (with props)
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/QueryFactory.java
  (with props)
    jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/query/QueryObjectModelBuilder.java
  (with props)
    jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/query/QueryObjectModelBuilderRegistry.java
  (with props)
    jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/query/sql2/SQL2QOMBuilder.java
  (with props)
    jackrabbit/trunk/jackrabbit-spi-commons/src/main/resources/META-INF/services/org.apache.jackrabbit.spi.commons.query.QueryObjectModelBuilder
Modified:
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/QueryManagerImpl.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/join/Join.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/join/SameNodeJoin.java
    jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/query/AbstractQueryTest.java
    jackrabbit/trunk/jackrabbit-spi-commons/src/main/resources/META-INF/services/org.apache.jackrabbit.spi.commons.query.QueryTreeBuilder

Added: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/AQTQueryFactory.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/AQTQueryFactory.java?rev=785594&view=auto
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/AQTQueryFactory.java
(added)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/AQTQueryFactory.java
Wed Jun 17 13:33:24 2009
@@ -0,0 +1,36 @@
+/*
+ * 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 java.util.List;
+import java.util.Arrays;
+
+import org.apache.jackrabbit.spi.commons.query.QueryTreeBuilderRegistry;
+
+/**
+ * <code>AQTQueryFactory</code> implements a query factory that creates AQT
+ * (Abstract Query Tree) based queries.
+ */
+public abstract class AQTQueryFactory implements QueryFactory {
+
+    /**
+     * {@inheritDoc}
+     */
+    public List<String> getSupportedLanguages() {
+        return Arrays.asList(QueryTreeBuilderRegistry.getSupportedLanguages());
+    }
+}

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

Added: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/CompoundQueryFactory.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/CompoundQueryFactory.java?rev=785594&view=auto
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/CompoundQueryFactory.java
(added)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/CompoundQueryFactory.java
Wed Jun 17 13:33:24 2009
@@ -0,0 +1,72 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jackrabbit.core.query;
+
+import java.util.List;
+import java.util.ArrayList;
+
+import javax.jcr.query.Query;
+import javax.jcr.query.InvalidQueryException;
+import javax.jcr.RepositoryException;
+
+/**
+ * <code>CompoundQueryFactory</code> implements a query factory that consists
of
+ * multiple other query factories.
+ */
+public class CompoundQueryFactory implements QueryFactory {
+
+    /**
+     * The query factories.
+     */
+    private List<QueryFactory> factories = new ArrayList<QueryFactory>();
+
+    /**
+     * Creates a compound query factory that consists of multiple other query
+     * factories.
+     *
+     * @param factories the query factories.
+     */
+    public CompoundQueryFactory(List<QueryFactory> factories) {
+        this.factories.addAll(factories);
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public List<String> getSupportedLanguages() {
+        List<String> languages = new ArrayList<String>();
+        for (QueryFactory factory : factories) {
+            for (String lang : factory.getSupportedLanguages()) {
+                languages.add(lang);
+            }
+        }
+        return languages;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public Query createQuery(String statement, String language)
+            throws InvalidQueryException, RepositoryException {
+        for (QueryFactory factory : factories) {
+            if (factory.getSupportedLanguages().contains(language)) {
+                return factory.createQuery(statement, language);
+            }
+        }
+        throw new InvalidQueryException("Unsupported language: " + language);
+    }
+}

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

Added: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/QOMQueryFactory.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/QOMQueryFactory.java?rev=785594&view=auto
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/QOMQueryFactory.java
(added)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/QOMQueryFactory.java
Wed Jun 17 13:33:24 2009
@@ -0,0 +1,72 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jackrabbit.core.query;
+
+import java.util.List;
+import java.util.Arrays;
+
+import javax.jcr.query.Query;
+import javax.jcr.query.InvalidQueryException;
+import javax.jcr.query.qom.QueryObjectModelFactory;
+import javax.jcr.RepositoryException;
+import javax.jcr.ValueFactory;
+
+import org.apache.jackrabbit.spi.commons.query.QueryObjectModelBuilderRegistry;
+
+/**
+ * <code>QOMQueryFactory</code> implements a query factory that creates QOM
+ * based queries.
+ */
+public class QOMQueryFactory implements QueryFactory {
+
+    /**
+     * The query object model factory.
+     */
+    private final QueryObjectModelFactory qf;
+
+    /**
+     * The value factory.
+     */
+    private final ValueFactory vf;
+
+    /**
+     * Creates a new QOM base query factory.
+     *
+     * @param qf the QOM factory.
+     * @param vf the value factory.
+     */
+    public QOMQueryFactory(QueryObjectModelFactory qf, ValueFactory vf) {
+        this.qf = qf;
+        this.vf = vf;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public List<String> getSupportedLanguages() {
+        return Arrays.asList(QueryObjectModelBuilderRegistry.getSupportedLanguages());
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public Query createQuery(String statement, String language)
+            throws InvalidQueryException, RepositoryException {
+        return QueryObjectModelBuilderRegistry.getQueryObjectModelBuilder(
+                language).createQueryObjectModel(statement, qf, vf);
+    }
+}

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

Added: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/QueryFactory.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/QueryFactory.java?rev=785594&view=auto
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/QueryFactory.java
(added)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/QueryFactory.java
Wed Jun 17 13:33:24 2009
@@ -0,0 +1,49 @@
+/*
+ * 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 java.util.List;
+
+import javax.jcr.query.Query;
+import javax.jcr.query.InvalidQueryException;
+import javax.jcr.RepositoryException;
+
+/**
+ * <code>QueryFactory</code> defines a simple interface for turning a statement
+ * in a given language into a JCR Query instance.
+ */
+public interface QueryFactory {
+
+    /**
+     * @return supported query languages by this factory.
+     */
+    public List<String> getSupportedLanguages();
+
+    /**
+     * Creates a JCR query instance from the given <code>statement</code> in
the
+     * given <code>language</code>.
+     *
+     * @param statement the query statement.
+     * @param language  the language of the query statement.
+     * @return the JCR query instance representing the query.
+     * @throws InvalidQueryException if the statement is malformed or the
+     *                               language is not supported.
+     * @throws RepositoryException   if another error occurs.
+     */
+    public Query createQuery(String statement, String language)
+            throws InvalidQueryException, RepositoryException;
+}

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

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/QueryManagerImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/QueryManagerImpl.java?rev=785594&r1=785593&r2=785594&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/QueryManagerImpl.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/QueryManagerImpl.java
Wed Jun 17 13:33:24 2009
@@ -17,7 +17,6 @@
 package org.apache.jackrabbit.core.query;
 
 import java.util.Arrays;
-import java.util.Collections;
 import java.util.List;
 
 import javax.jcr.Node;
@@ -31,7 +30,6 @@
 import org.apache.jackrabbit.core.ItemManager;
 import org.apache.jackrabbit.core.SearchManager;
 import org.apache.jackrabbit.core.SessionImpl;
-import org.apache.jackrabbit.spi.commons.query.QueryTreeBuilderRegistry;
 import org.apache.jackrabbit.spi.commons.query.qom.QueryObjectModelFactoryImpl;
 import org.apache.jackrabbit.spi.commons.query.qom.QueryObjectModelTree;
 
@@ -41,17 +39,6 @@
 public class QueryManagerImpl implements QueryManager {
 
     /**
-     * Defines all supported query languages
-     */
-    private static final String[] SUPPORTED_QUERIES = QueryTreeBuilderRegistry.getSupportedLanguages();
-
-    /**
-     * List of all supported query languages
-     */
-    private static final List SUPPORTED_QUERIES_LIST
-            = Collections.unmodifiableList(Arrays.asList(SUPPORTED_QUERIES));
-
-    /**
      * The <code>Session</code> for this QueryManager.
      */
     private final SessionImpl session;
@@ -72,17 +59,24 @@
     private final QueryObjectModelFactoryImpl qomFactory;
 
     /**
+     * The query factory which is responsible to create query instances base
+     * on the passed query language.
+     */
+    private final QueryFactory queryFactory;
+
+    /**
      * Creates a new <code>QueryManagerImpl</code> for the passed
      * <code>session</code>
      *
-     * @param session
-     * @param itemMgr
-     * @param searchMgr
-     */
-    public QueryManagerImpl(
-            final SessionImpl session,
-            final ItemManager itemMgr,
-            final SearchManager searchMgr)
+     * @param session   the session for this query manager.
+     * @param itemMgr   the item manager of the session.
+     * @param searchMgr the search manager of this workspace.
+     * @throws RepositoryException if an error occurs while initializing the
+     *                             query manager.
+     */
+    public QueryManagerImpl(final SessionImpl session,
+                            final ItemManager itemMgr,
+                            final SearchManager searchMgr)
             throws RepositoryException {
         this.session = session;
         this.itemMgr = itemMgr;
@@ -95,6 +89,14 @@
                         session, qomTree, Query.JCR_SQL2);
             }
         };
+        this.queryFactory = new CompoundQueryFactory(Arrays.asList(
+                new QOMQueryFactory(qomFactory, session.getValueFactory()),
+                new AQTQueryFactory() {
+                    public Query createQuery(String statement, String language)
+                            throws InvalidQueryException, RepositoryException {
+                        return searchMgr.createQuery(session, itemMgr, statement, language);
+                    }
+                }));
     }
 
     /**
@@ -103,7 +105,7 @@
     public Query createQuery(String statement, String language)
             throws InvalidQueryException, RepositoryException {
         sanityCheck();
-        return searchMgr.createQuery(session, itemMgr, statement, language);
+        return queryFactory.createQuery(statement, language);
     }
 
     /**
@@ -112,6 +114,7 @@
     public Query getQuery(Node node)
             throws InvalidQueryException, RepositoryException {
         sanityCheck();
+        // TODO: support SQL2 and QOM
         return searchMgr.createQuery(session, itemMgr, node);
     }
 
@@ -119,7 +122,8 @@
      * {@inheritDoc}
      */
     public String[] getSupportedQueryLanguages() throws RepositoryException {
-        return (String[]) SUPPORTED_QUERIES_LIST.toArray(new String[SUPPORTED_QUERIES.length]);
+        List<String> languages = queryFactory.getSupportedLanguages();
+        return languages.toArray(new String[languages.size()]);
     }
 
     //---------------------------< JSR 283 >------------------------------------

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/join/Join.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/join/Join.java?rev=785594&r1=785593&r2=785594&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/join/Join.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/join/Join.java
Wed Jun 17 13:33:24 2009
@@ -26,6 +26,7 @@
 import org.apache.jackrabbit.core.query.lucene.MultiColumnQueryHits;
 import org.apache.jackrabbit.core.query.lucene.ScoreNode;
 import org.apache.jackrabbit.spi.Name;
+import org.apache.jackrabbit.spi.Path;
 import org.apache.jackrabbit.spi.commons.query.qom.ChildNodeJoinConditionImpl;
 import org.apache.jackrabbit.spi.commons.query.qom.DefaultQOMTreeVisitor;
 import org.apache.jackrabbit.spi.commons.query.qom.DescendantNodeJoinConditionImpl;
@@ -74,7 +75,7 @@
     /**
      * A buffer for joined score node rows.
      */
-    protected final List buffer = new LinkedList();
+    protected final List<ScoreNode[]> buffer = new LinkedList<ScoreNode[]>();
 
     /**
      * Creates a new join.
@@ -218,20 +219,22 @@
                             || src1 == right && JoinType.RIGHT == joinType) {
                         outer = src1;
                         outerIdx = getIndex(outer, node.getSelector1QName());
-                        if (node.getSelector2QPath() != null) {
+                        Path selector2Path = node.getSelector2QPath();
+                        if (selector2Path == null || (selector2Path.getLength() == 1 &&
selector2Path.getNameElement().denotesCurrent())) {
+                            c = new SameNodeJoin(src2, node.getSelector2QName(), reader);
+                        } else {
                             c = new DescendantPathNodeJoin(src2, node.getSelector2QName(),
                                     node.getSelector2QPath(), hmgr);
-                        } else {
-                            c = new SameNodeJoin(src2, node.getSelector2QName(), reader);
                         }
                     } else {
                         outer = src2;
                         outerIdx = getIndex(outer, node.getSelector2QName());
-                        if (node.getSelector2QPath() != null) {
+                        Path selector2Path = node.getSelector2QPath();
+                        if (selector2Path == null || (selector2Path.getLength() == 1 &&
selector2Path.getNameElement().denotesCurrent())) {
+                            c = new SameNodeJoin(src1, node.getSelector1QName(), reader);
+                        } else {
                             c = new AncestorPathNodeJoin(src1, node.getSelector1QName(),
                                     node.getSelector2QPath(), hmgr);
-                        } else {
-                            c = new SameNodeJoin(src1, node.getSelector1QName(), reader);
                         }
                     }
                     return new Join(outer, outerIdx, isInner, c);
@@ -251,7 +254,7 @@
      */
     public ScoreNode[] nextScoreNodes() throws IOException {
         if (!buffer.isEmpty()) {
-            return (ScoreNode[]) buffer.remove(0);
+            return buffer.remove(0);
         }
         do {
             // refill buffer
@@ -261,8 +264,7 @@
             }
             ScoreNode[][] nodes = condition.getMatchingScoreNodes(sn[outerScoreNodeIndex]);
             if (nodes != null) {
-                for (int i = 0; i < nodes.length; i++) {
-                    ScoreNode[] node = nodes[i];
+                for (ScoreNode[] node : nodes) {
                     // create array with both outer and inner
                     ScoreNode[] tmp = new ScoreNode[sn.length + node.length];
                     System.arraycopy(sn, 0, tmp, 0, sn.length);
@@ -278,7 +280,7 @@
             }
         } while (buffer.isEmpty());
 
-        return (ScoreNode[]) buffer.remove(0);
+        return buffer.remove(0);
     }
 
     /**

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/join/SameNodeJoin.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/join/SameNodeJoin.java?rev=785594&r1=785593&r2=785594&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/join/SameNodeJoin.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/join/SameNodeJoin.java
Wed Jun 17 13:33:24 2009
@@ -55,8 +55,7 @@
         int idx = getIndex(inner, innerSelectorName);
         ScoreNode[] nodes;
         while ((nodes = inner.nextScoreNodes()) != null) {
-            Integer docNum = new Integer(nodes[idx].getDoc(reader));
-            innerIndex.addScoreNodes(docNum, nodes);
+            innerIndex.addScoreNodes(nodes[idx].getDoc(reader), nodes);
         }
     }
 
@@ -65,6 +64,6 @@
      */
     public ScoreNode[][] getMatchingScoreNodes(ScoreNode outer)
             throws IOException {
-        return innerIndex.getScoreNodes(new Integer(outer.getDoc(reader)));
+        return innerIndex.getScoreNodes(outer.getDoc(reader));
     }
 }

Modified: jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/query/AbstractQueryTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/query/AbstractQueryTest.java?rev=785594&r1=785593&r2=785594&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/query/AbstractQueryTest.java
(original)
+++ jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/query/AbstractQueryTest.java
Wed Jun 17 13:33:24 2009
@@ -71,6 +71,11 @@
     protected QueryObjectModelFactory qf;
 
     /**
+     * The query manager for {@link #superuser}
+     */
+    protected QueryManager qm;
+
+    /**
      * Set-up the configuration values used for the test. Per default retrieves
      * a session, configures testRoot, and nodetype and checks if the query
      * language for the current language is available.<br>
@@ -82,10 +87,16 @@
         jcrRoot = superuser.getNamespacePrefix(NS_JCR_URI) + ":root";
         jcrContains = superuser.getNamespacePrefix(NS_JCR_URI) + ":contains";
         jcrDeref = superuser.getNamespacePrefix(NS_JCR_URI) + ":deref";
-        QueryManager qm = superuser.getWorkspace().getQueryManager();
+        qm = superuser.getWorkspace().getQueryManager();
         qf = qm.getQOMFactory();
     }
 
+    protected void tearDown() throws Exception {
+        qm = null;
+        qf = null;
+        super.tearDown();
+    }
+
     /**
      * Create a {@link Query} for a given {@link Statement}.
      *

Added: jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/query/QueryObjectModelBuilder.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/query/QueryObjectModelBuilder.java?rev=785594&view=auto
==============================================================================
--- jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/query/QueryObjectModelBuilder.java
(added)
+++ jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/query/QueryObjectModelBuilder.java
Wed Jun 17 13:33:24 2009
@@ -0,0 +1,79 @@
+/*
+ * 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.spi.commons.query;
+
+import javax.jcr.query.qom.QueryObjectModel;
+import javax.jcr.query.qom.QueryObjectModelFactory;
+import javax.jcr.query.InvalidQueryException;
+import javax.jcr.ValueFactory;
+import javax.jcr.RepositoryException;
+
+import org.apache.jackrabbit.spi.commons.conversion.NameResolver;
+
+/**
+ * <code>QueryObjectModelBuilder</code> defines an interface for building a
+ * query object model from a string based query statement and vice versa.
+ */
+public interface QueryObjectModelBuilder {
+
+    /**
+     * Creates a new query object model from the given <code>statement</code>
+     * using the passed QOM and value factory.
+     *
+     * @param statement the query statement.
+     * @param qf        the query object model factory.
+     * @param vf        the value factory.
+     * @return the query object model for the given statement.
+     * @throws InvalidQueryException if the statement is invalid.
+     * @throws RepositoryException   if another error occurs.
+     */
+    public QueryObjectModel createQueryObjectModel(String statement,
+                                                   QueryObjectModelFactory qf,
+                                                   ValueFactory vf)
+            throws InvalidQueryException, RepositoryException;
+
+    /**
+     * Returns <code>true</code> if this QOM builder can handle a statement in
+     * <code>language</code>.
+     *
+     * @param language the language of a query statement to build a QOM.
+     * @return <code>true</code> if this builder can handle
+     *         <code>language</code>; <code>false</code> otherwise.
+     */
+    boolean canHandle(String language);
+
+    /**
+     * Returns the set of query languages supported by this builder.
+     *
+     * @return String array containing the names of the supported languages.
+     */
+    String[] getSupportedLanguages();
+
+    /**
+     * Creates a String representation of the query object model in the syntax
+     * this <code>QueryObjectModelBuilder</code> can handle.
+     *
+     * @param qom      the query object model.
+     * @param resolver to resolve Names.
+     * @return a String representation of the QOM.
+     * @throws InvalidQueryException if the query object model cannot be
+     *                               converted into a String representation due
+     *                               to restrictions in this syntax.
+     */
+    String toString(QueryObjectModel qom, NameResolver resolver)
+            throws InvalidQueryException;
+}

Propchange: jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/query/QueryObjectModelBuilder.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/query/QueryObjectModelBuilderRegistry.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/query/QueryObjectModelBuilderRegistry.java?rev=785594&view=auto
==============================================================================
--- jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/query/QueryObjectModelBuilderRegistry.java
(added)
+++ jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/query/QueryObjectModelBuilderRegistry.java
Wed Jun 17 13:33:24 2009
@@ -0,0 +1,98 @@
+/*
+ * 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.spi.commons.query;
+
+import java.util.List;
+import java.util.ArrayList;
+import java.util.Set;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.Arrays;
+import java.util.Collections;
+
+import javax.imageio.spi.ServiceRegistry;
+import javax.jcr.query.InvalidQueryException;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Implements a central access to QueryObjectModelBuilder instances.
+ */
+public class QueryObjectModelBuilderRegistry {
+
+    /**
+     * Logger instance for this class.
+     */
+    private static final Logger log = LoggerFactory.getLogger(QueryObjectModelBuilderRegistry.class);
+
+    /**
+     * List of <code>QueryObjectModelBuilder</code> instances known to the classloader.
+     */
+    private static final List<QueryObjectModelBuilder> BUILDERS = new ArrayList<QueryObjectModelBuilder>();
+
+    /**
+     * Set of languages known to the registered builders.
+     */
+    private static final Set<String> LANGUAGES;
+
+    static {
+        Set<String> languages = new HashSet<String>();
+        try {
+            Iterator<QueryObjectModelBuilder> it = ServiceRegistry.lookupProviders(QueryObjectModelBuilder.class,
+                    QueryObjectModelBuilder.class.getClassLoader());
+            while (it.hasNext()) {
+                QueryObjectModelBuilder builder = it.next();
+                BUILDERS.add(builder);
+                languages.addAll(Arrays.asList(builder.getSupportedLanguages()));
+            }
+        } catch (Error e) {
+            log.warn("Unable to load providers for QueryObjectModelBuilder: " + e);
+        }
+        LANGUAGES = Collections.unmodifiableSet(languages);
+    }
+
+    /**
+     * Returns the <code>QueryObjectModelBuilder</code> for
+     * <code>language</code>.
+     *
+     * @param language the language of the query statement.
+     * @return the <code>QueryObjectModelBuilder</code> for
+     *         <code>language</code>.
+     * @throws InvalidQueryException if there is no query object model builder
+     *                               for <code>language</code>.
+     */
+    public static QueryObjectModelBuilder getQueryObjectModelBuilder(String language)
+            throws InvalidQueryException {
+        for (QueryObjectModelBuilder builder : BUILDERS) {
+            if (builder.canHandle(language)) {
+                return builder;
+            }
+        }
+        throw new InvalidQueryException("Unsupported language: " + language);
+    }
+
+    /**
+     * Returns the set of query languages supported by all registered
+     * {@link QueryObjectModelBuilder} implementations.
+     *
+     * @return String array containing the names of the supported languages.
+     */
+    public static String[] getSupportedLanguages() {
+        return LANGUAGES.toArray(new String[LANGUAGES.size()]);
+    }
+}

Propchange: jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/query/QueryObjectModelBuilderRegistry.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/query/sql2/SQL2QOMBuilder.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/query/sql2/SQL2QOMBuilder.java?rev=785594&view=auto
==============================================================================
--- jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/query/sql2/SQL2QOMBuilder.java
(added)
+++ jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/query/sql2/SQL2QOMBuilder.java
Wed Jun 17 13:33:24 2009
@@ -0,0 +1,64 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jackrabbit.spi.commons.query.sql2;
+
+import javax.jcr.query.qom.QueryObjectModel;
+import javax.jcr.query.qom.QueryObjectModelFactory;
+import javax.jcr.query.InvalidQueryException;
+import javax.jcr.query.Query;
+import javax.jcr.ValueFactory;
+import javax.jcr.RepositoryException;
+
+import org.apache.jackrabbit.spi.commons.query.QueryObjectModelBuilder;
+import org.apache.jackrabbit.spi.commons.conversion.NameResolver;
+
+/**
+ * <code>SQL2QOMBuilder</code> implements QOM builder that understands
+ * {@link Query#JCR_SQL2}.
+ */
+public class SQL2QOMBuilder implements QueryObjectModelBuilder {
+
+    /**
+     * {@inheritDoc}
+     */
+    public QueryObjectModel createQueryObjectModel(String statement,
+                                                   QueryObjectModelFactory qf,
+                                                   ValueFactory vf)
+            throws InvalidQueryException, RepositoryException {
+        return new Parser(qf, vf).createQueryObjectModel(statement);
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public boolean canHandle(String language) {
+        return Query.JCR_SQL2.equals(language);
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public String[] getSupportedLanguages() {
+        return new String[]{Query.JCR_SQL2};
+    }
+
+    public String toString(QueryObjectModel qom, NameResolver resolver)
+            throws InvalidQueryException {
+        // TODO
+        return null;
+    }
+}

Propchange: jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/query/sql2/SQL2QOMBuilder.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: jackrabbit/trunk/jackrabbit-spi-commons/src/main/resources/META-INF/services/org.apache.jackrabbit.spi.commons.query.QueryObjectModelBuilder
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-spi-commons/src/main/resources/META-INF/services/org.apache.jackrabbit.spi.commons.query.QueryObjectModelBuilder?rev=785594&view=auto
==============================================================================
--- jackrabbit/trunk/jackrabbit-spi-commons/src/main/resources/META-INF/services/org.apache.jackrabbit.spi.commons.query.QueryObjectModelBuilder
(added)
+++ jackrabbit/trunk/jackrabbit-spi-commons/src/main/resources/META-INF/services/org.apache.jackrabbit.spi.commons.query.QueryObjectModelBuilder
Wed Jun 17 13:33:24 2009
@@ -0,0 +1,21 @@
+#  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.
+
+#
+# This file lists all available query language implementations that are shipped
+# with Jackrabbit and are based on the JCR 2.0 QueryObjectModel.
+#
+
+org.apache.jackrabbit.spi.commons.query.sql2.SQL2QOMBuilder

Modified: jackrabbit/trunk/jackrabbit-spi-commons/src/main/resources/META-INF/services/org.apache.jackrabbit.spi.commons.query.QueryTreeBuilder
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-spi-commons/src/main/resources/META-INF/services/org.apache.jackrabbit.spi.commons.query.QueryTreeBuilder?rev=785594&r1=785593&r2=785594&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-spi-commons/src/main/resources/META-INF/services/org.apache.jackrabbit.spi.commons.query.QueryTreeBuilder
(original)
+++ jackrabbit/trunk/jackrabbit-spi-commons/src/main/resources/META-INF/services/org.apache.jackrabbit.spi.commons.query.QueryTreeBuilder
Wed Jun 17 13:33:24 2009
@@ -15,7 +15,7 @@
 
 #
 # This file lists all available query language implementations that are shipped
-# with Jackrabbit.
+# with Jackrabbit and are based on the proprietary QueryTree.
 #
 
 org.apache.jackrabbit.spi.commons.query.xpath.QueryBuilder



Mime
View raw message