jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mreut...@apache.org
Subject svn commit: r292675 - in /incubator/jackrabbit/trunk/src/java: META-INF/services/ org/apache/jackrabbit/core/query/ org/apache/jackrabbit/core/query/lucene/ org/apache/jackrabbit/core/query/sql/ org/apache/jackrabbit/core/query/xpath/
Date Fri, 30 Sep 2005 08:22:58 GMT
Author: mreutegg
Date: Fri Sep 30 01:22:45 2005
New Revision: 292675

URL: http://svn.apache.org/viewcvs?rev=292675&view=rev
Log:
JCR-229: Decouple packages in core.query
- TextPlainTextFilter moved to sub package o.a.j.c.query.lucene
- Introduced interface QueryTreeBuilder that allows to implement arbitrary syntax that can
be represented with a QueryNode tree specified in package o.a.j.c.query. XPath and SQL syntax
are now implemented via this interface.

Added:
    incubator/jackrabbit/trunk/src/java/META-INF/services/org.apache.jackrabbit.core.query.QueryTreeBuilder
    incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/query/QueryTreeBuilder.java
  (with props)
    incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/query/QueryTreeBuilderRegistry.java
  (with props)
    incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/query/lucene/TextPlainTextFilter.java
  (with props)
    incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/query/sql/QueryBuilder.java
  (with props)
    incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/query/xpath/QueryBuilder.java
  (with props)
Removed:
    incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/query/TextPlainTextFilter.java
Modified:
    incubator/jackrabbit/trunk/src/java/META-INF/services/org.apache.jackrabbit.core.query.TextFilterService
    incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/query/QueryParser.java
    incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/query/TextFilterService.java

Added: incubator/jackrabbit/trunk/src/java/META-INF/services/org.apache.jackrabbit.core.query.QueryTreeBuilder
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/java/META-INF/services/org.apache.jackrabbit.core.query.QueryTreeBuilder?rev=292675&view=auto
==============================================================================
--- incubator/jackrabbit/trunk/src/java/META-INF/services/org.apache.jackrabbit.core.query.QueryTreeBuilder
(added)
+++ incubator/jackrabbit/trunk/src/java/META-INF/services/org.apache.jackrabbit.core.query.QueryTreeBuilder
Fri Sep 30 01:22:45 2005
@@ -0,0 +1,22 @@
+# Copyright 2004-2005 The Apache Software Foundation or its licensors,
+#                     as applicable.
+#
+# Licensed 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.
+#
+
+org.apache.jackrabbit.core.query.xpath.QueryBuilder
+org.apache.jackrabbit.core.query.sql.QueryBuilder

Modified: incubator/jackrabbit/trunk/src/java/META-INF/services/org.apache.jackrabbit.core.query.TextFilterService
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/java/META-INF/services/org.apache.jackrabbit.core.query.TextFilterService?rev=292675&r1=292674&r2=292675&view=diff
==============================================================================
--- incubator/jackrabbit/trunk/src/java/META-INF/services/org.apache.jackrabbit.core.query.TextFilterService
(original)
+++ incubator/jackrabbit/trunk/src/java/META-INF/services/org.apache.jackrabbit.core.query.TextFilterService
Fri Sep 30 01:22:45 2005
@@ -18,4 +18,4 @@
 # with Jackrabbit.
 #
 
-org.apache.jackrabbit.core.query.TextPlainTextFilter
+org.apache.jackrabbit.core.query.lucene.TextPlainTextFilter

Modified: incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/query/QueryParser.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/query/QueryParser.java?rev=292675&r1=292674&r2=292675&view=diff
==============================================================================
--- incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/query/QueryParser.java
(original)
+++ incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/query/QueryParser.java
Fri Sep 30 01:22:45 2005
@@ -16,12 +16,9 @@
  */
 package org.apache.jackrabbit.core.query;
 
-import org.apache.jackrabbit.core.query.sql.JCRSQLQueryBuilder;
-import org.apache.jackrabbit.core.query.xpath.XPathQueryBuilder;
 import org.apache.jackrabbit.name.NamespaceResolver;
 
 import javax.jcr.query.InvalidQueryException;
-import javax.jcr.query.Query;
 
 /**
  * This class acts as the central entry point for parsing query statements from
@@ -53,13 +50,8 @@
                                       NamespaceResolver resolver)
             throws InvalidQueryException {
 
-        if (Query.XPATH.equals(language)) {
-            return XPathQueryBuilder.createQuery(statement, resolver);
-        } else if (Query.SQL.equals(language)) {
-            return JCRSQLQueryBuilder.createQuery(statement, resolver);
-        } else {
-            throw new InvalidQueryException("Unsupported language: " + language);
-        }
+        QueryTreeBuilder builder = QueryTreeBuilderRegistry.getQueryTreeBuilder(language);
+        return builder.createQueryTree(statement, resolver);
     }
 
     /**
@@ -86,13 +78,8 @@
                                   NamespaceResolver resolver)
             throws InvalidQueryException {
 
-        if (Query.XPATH.equals(language)) {
-            return XPathQueryBuilder.toString(root, resolver);
-        } else if (Query.SQL.equals(language)) {
-            return JCRSQLQueryBuilder.toString(root, resolver);
-        } else {
-            throw new InvalidQueryException("Unsupported language: " + language);
-        }
+        QueryTreeBuilder builder = QueryTreeBuilderRegistry.getQueryTreeBuilder(language);
+        return builder.toString(root, resolver);
     }
 
 }

Added: incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/query/QueryTreeBuilder.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/query/QueryTreeBuilder.java?rev=292675&view=auto
==============================================================================
--- incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/query/QueryTreeBuilder.java
(added)
+++ incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/query/QueryTreeBuilder.java
Fri Sep 30 01:22:45 2005
@@ -0,0 +1,63 @@
+/*
+ * Copyright 2004-2005 The Apache Software Foundation or its licensors,
+ *                     as applicable.
+ *
+ * Licensed 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 org.apache.jackrabbit.name.NamespaceResolver;
+
+import javax.jcr.query.InvalidQueryException;
+
+/**
+ * Specifies an interface for a query tree builder.
+ */
+public interface QueryTreeBuilder {
+
+    /**
+     * Creates a <code>QueryNode</code> tree from a statement.
+     *
+     * @param statement the statement.
+     * @param resolver  the namespace resolver to use.
+     * @return the <code>QueryNode</code> tree for the statement.
+     * @throws javax.jcr.query.InvalidQueryException
+     *          if the statement is malformed.
+     */
+    public QueryRootNode createQueryTree(String statement, NamespaceResolver resolver)
+            throws InvalidQueryException;
+
+    /**
+     * Returns <code>true</code> if this query tree builder can handle a
+     * statement in <code>language</code>.
+     *
+     * @param language the language of a query statement to build a query tree.
+     * @return <code>true</code> if this builder can handle <code>language</code>;
+     *         <code>false</code> otherwise.
+     */
+    public boolean canHandle(String language);
+
+    /**
+     * Creates a String representation of the query node tree in the syntax this
+     * <code>QueryTreeBuilder</code> can handle.
+     *
+     * @param root     the root of the query node tree.
+     * @param resolver to resolve QNames.
+     * @return a String representation of the query node tree.
+     * @throws InvalidQueryException if the query node tree cannot be converted
+     *                               into a String representation due to
+     *                               restrictions in this syntax.
+     */
+    public String toString(QueryRootNode root, NamespaceResolver resolver)
+            throws InvalidQueryException;
+}

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

Added: incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/query/QueryTreeBuilderRegistry.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/query/QueryTreeBuilderRegistry.java?rev=292675&view=auto
==============================================================================
--- incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/query/QueryTreeBuilderRegistry.java
(added)
+++ incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/query/QueryTreeBuilderRegistry.java
Fri Sep 30 01:22:45 2005
@@ -0,0 +1,71 @@
+/*
+ * Copyright 2004-2005 The Apache Software Foundation or its licensors,
+ *                     as applicable.
+ *
+ * Licensed 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 org.apache.log4j.Logger;
+
+import javax.imageio.spi.ServiceRegistry;
+import javax.jcr.query.InvalidQueryException;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Iterator;
+
+/**
+ * Implements a central access to QueryTreeBuilder instances.
+ */
+public class QueryTreeBuilderRegistry {
+
+    /**
+     * Logger instance for this class.
+     */
+    private static final Logger log = Logger.getLogger(QueryTreeBuilderRegistry.class);
+
+    /**
+     * List of <code>QueryTreeBuilder</code> instances known to the classloader.
+     */
+    private static final List BUILDERS = new ArrayList();
+
+    static {
+        try {
+            Iterator it = ServiceRegistry.lookupProviders(QueryTreeBuilder.class);
+            while (it.hasNext()) {
+                BUILDERS.add(it.next());
+            }
+        } catch (Error e) {
+            log.warn("Unable to load providers for QueryTreeBuilder: " + e);
+        }
+    }
+
+    /**
+     * Returns the <code>QueryTreeBuilder</code> for <code>language</code>.
+     *
+     * @param language the language of the query statement.
+     * @return the <code>QueryTreeBuilder</code> for <code>language</code>.
+     * @throws InvalidQueryException if there is no query tree builder for
+     *                               <code>language</code>.
+     */
+    public static QueryTreeBuilder getQueryTreeBuilder(String language)
+            throws InvalidQueryException {
+        for (int i = 0; i < BUILDERS.size(); i++) {
+            QueryTreeBuilder builder = (QueryTreeBuilder) BUILDERS.get(i);
+            if (builder.canHandle(language)) {
+                return builder;
+            }
+        }
+        throw new InvalidQueryException("Unsupported language: " + language);
+    }
+}

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

Modified: incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/query/TextFilterService.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/query/TextFilterService.java?rev=292675&r1=292674&r2=292675&view=diff
==============================================================================
--- incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/query/TextFilterService.java
(original)
+++ incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/query/TextFilterService.java
Fri Sep 30 01:22:45 2005
@@ -32,7 +32,7 @@
  * are registered in a jar file as providers for
  * <code>META-INF/services/org.apache.jackrabbit.core.query.TextFilterService</code>
  * E.g. the jackrabbit jar file contains entries for some {@link TextFilter}
- * implementations such as {@link TextPlainTextFilter}. Custom
+ * implementations such as {@link org.apache.jackrabbit.core.query.lucene.TextPlainTextFilter}.
Custom
  * {@link TextFilter} implementations may be added to Jackrabbit by packaging
  * them into a jar file together with a
  * <code>META-INF/services/org.apache.jackrabbit.core.query.TextFilterService</code>

Added: incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/query/lucene/TextPlainTextFilter.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/query/lucene/TextPlainTextFilter.java?rev=292675&view=auto
==============================================================================
--- incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/query/lucene/TextPlainTextFilter.java
(added)
+++ incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/query/lucene/TextPlainTextFilter.java
Fri Sep 30 01:22:45 2005
@@ -0,0 +1,80 @@
+/*
+ * Copyright 2004-2005 The Apache Software Foundation or its licensors,
+ *                     as applicable.
+ *
+ * Licensed 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.jackrabbit.core.query.TextFilter;
+import org.apache.jackrabbit.core.state.PropertyState;
+import org.apache.jackrabbit.core.value.BLOBFileValue;
+import org.apache.jackrabbit.core.value.InternalValue;
+
+import javax.jcr.RepositoryException;
+import java.io.InputStreamReader;
+import java.io.Reader;
+import java.io.UnsupportedEncodingException;
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * Implements a {@link org.apache.jackrabbit.core.query.TextFilter} that handles binary properties
of mime-type
+ * text/plain.
+ */
+public class TextPlainTextFilter implements TextFilter {
+
+    /**
+     * Returns <code>true</code> for <code>text/plain</code>; <code>false</code>
+     * in all other cases.
+     * @param mimeType the mime-type.
+     * @return <code>true</code> for <code>text/plain</code>; <code>false</code>
+     * in all other cases.
+     */
+    public boolean canFilter(String mimeType) {
+        return "text/plain".equalsIgnoreCase(mimeType);
+    }
+
+    /**
+     * Returns a map with a single entry for field {@link FieldNames#FULLTEXT}.
+     * @param data the data property.
+     * @param encoding the encoding
+     * @return a map with a single Reader value for field
+     *  {@link FieldNames#FULLTEXT}.
+     * @throws RepositoryException if encoding is not supported or data is a
+     *  multi-value property.
+     */
+    public Map doFilter(PropertyState data, String encoding) throws RepositoryException {
+        InternalValue[] values = data.getValues();
+        if (values.length == 1) {
+            BLOBFileValue blob = (BLOBFileValue) values[0].internalValue();
+            try {
+                Reader reader;
+                if (encoding == null) {
+                    // use platform default
+                    reader = new InputStreamReader(blob.getStream());
+                } else {
+                    reader = new InputStreamReader(blob.getStream(), encoding);
+                }
+                Map result = new HashMap();
+                result.put(FieldNames.FULLTEXT, reader);
+                return result;
+            } catch (UnsupportedEncodingException e) {
+                throw new RepositoryException(e);
+            }
+        } else {
+            // multi value not supported
+            throw new RepositoryException("Multi-valued binary properties not supported.");
+        }
+    }
+}

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

Added: incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/query/sql/QueryBuilder.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/query/sql/QueryBuilder.java?rev=292675&view=auto
==============================================================================
--- incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/query/sql/QueryBuilder.java
(added)
+++ incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/query/sql/QueryBuilder.java
Fri Sep 30 01:22:45 2005
@@ -0,0 +1,54 @@
+/*
+ * Copyright 2004-2005 The Apache Software Foundation or its licensors,
+ *                     as applicable.
+ *
+ * Licensed 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.sql;
+
+import org.apache.jackrabbit.core.query.QueryTreeBuilder;
+import org.apache.jackrabbit.core.query.QueryRootNode;
+import org.apache.jackrabbit.name.NamespaceResolver;
+
+import javax.jcr.query.InvalidQueryException;
+import javax.jcr.query.Query;
+
+/**
+ * Implements the JCR SQL query tree builder.
+ */
+public class QueryBuilder implements QueryTreeBuilder {
+
+    /**
+     * @inheritDoc
+     */
+    public QueryRootNode createQueryTree(String statement,
+                                         NamespaceResolver resolver)
+            throws InvalidQueryException {
+        return JCRSQLQueryBuilder.createQuery(statement, resolver);
+    }
+
+    /**
+     * @inheritDoc
+     */
+    public boolean canHandle(String language) {
+        return Query.SQL.equals(language);
+    }
+
+    /**
+     * @inheritDoc
+     */
+    public String toString(QueryRootNode root, NamespaceResolver resolver)
+            throws InvalidQueryException {
+        return JCRSQLQueryBuilder.toString(root, resolver);
+    }
+}

Propchange: incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/query/sql/QueryBuilder.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/query/xpath/QueryBuilder.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/query/xpath/QueryBuilder.java?rev=292675&view=auto
==============================================================================
--- incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/query/xpath/QueryBuilder.java
(added)
+++ incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/query/xpath/QueryBuilder.java
Fri Sep 30 01:22:45 2005
@@ -0,0 +1,54 @@
+/*
+ * Copyright 2004-2005 The Apache Software Foundation or its licensors,
+ *                     as applicable.
+ *
+ * Licensed 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.xpath;
+
+import org.apache.jackrabbit.core.query.QueryTreeBuilder;
+import org.apache.jackrabbit.core.query.QueryRootNode;
+import org.apache.jackrabbit.name.NamespaceResolver;
+
+import javax.jcr.query.InvalidQueryException;
+import javax.jcr.query.Query;
+
+/**
+ * Implements the XPath query tree builder.
+ */
+public class QueryBuilder implements QueryTreeBuilder {
+
+    /**
+     * @inheritDoc
+     */
+    public QueryRootNode createQueryTree(String statement,
+                                         NamespaceResolver resolver)
+            throws InvalidQueryException {
+        return XPathQueryBuilder.createQuery(statement, resolver);
+    }
+
+    /**
+     * @inheritDoc
+     */
+    public boolean canHandle(String language) {
+        return Query.XPATH.equals(language);
+    }
+
+    /**
+     * @inheritDoc
+     */
+    public String toString(QueryRootNode root, NamespaceResolver resolver)
+            throws InvalidQueryException {
+        return XPathQueryBuilder.toString(root, resolver);
+    }
+}

Propchange: incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/query/xpath/QueryBuilder.java
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message