jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mreut...@apache.org
Subject svn commit: r786565 - in /jackrabbit/trunk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/query: QueryImpl.java QueryManagerImpl.java QueryObjectModelImpl.java
Date Fri, 19 Jun 2009 15:59:24 GMT
Author: mreutegg
Date: Fri Jun 19 15:59:24 2009
New Revision: 786565

URL: http://svn.apache.org/viewvc?rev=786565&view=rev
Log:
JCR-2076: JSR 283: QOM and SQL2
- jcr2spi implementation

Added:
    jackrabbit/trunk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/query/QueryObjectModelImpl.java
  (with props)
Modified:
    jackrabbit/trunk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/query/QueryImpl.java
    jackrabbit/trunk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/query/QueryManagerImpl.java

Modified: jackrabbit/trunk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/query/QueryImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/query/QueryImpl.java?rev=786565&r1=786564&r2=786565&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/query/QueryImpl.java
(original)
+++ jackrabbit/trunk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/query/QueryImpl.java
Fri Jun 19 15:59:24 2009
@@ -101,23 +101,29 @@
     /**
      * The name/value pairs collected upon calls to {@link #bindValue(String, Value)}.
      */
-    private final Map<String, QValue> boundValues = new HashMap();
+    private final Map<String, QValue> boundValues = new HashMap<String, QValue>();
 
     /**
      * Creates a new query.
      *
-     * @param session          the session that created this query.
+     * @param session     the session that created this query.
      * @param mgrProvider the manager provider.
-     * @param itemMgr          the item manager of that session.
-     * @param wspManager       the workspace manager that belongs to the
-     *                         session.
-     * @param statement        the query statement.
-     * @param language         the language of the query statement.
+     * @param itemMgr     the item manager of that session.
+     * @param wspManager  the workspace manager that belongs to the session.
+     * @param statement   the query statement.
+     * @param language    the language of the query statement.
+     * @param node        the node from where the query was read or
+     *                    <code>null</code> if this query is not a stored
+     *                    query.
      * @throws InvalidQueryException if the query is invalid.
      */
-    public QueryImpl(Session session, ManagerProvider mgrProvider,
-                     ItemManager itemMgr, WorkspaceManager wspManager,
-                     String statement, String language)
+    public QueryImpl(Session session,
+                     ManagerProvider mgrProvider,
+                     ItemManager itemMgr,
+                     WorkspaceManager wspManager,
+                     String statement,
+                     String language,
+                     Node node)
             throws InvalidQueryException, RepositoryException {
         this.session = session;
         this.mgrProvider = mgrProvider;
@@ -125,44 +131,8 @@
         this.statement = statement;
         this.language = language;
         this.wspManager = wspManager;
-        this.wspManager.checkQueryStatement(
-                statement, language, getNamespaceMappings());
-    }
-
-    /**
-     * Creates a query from a node.
-     *
-     * @param session    the session that created this query.
-     * @param mgrProvider the manager provider.
-     * @param itemMgr    the item manager of that session.
-     * @param wspManager the workspace manager that belongs to the session.
-     * @param node       the node from where to read the query.
-     * @throws InvalidQueryException if the query is invalid.
-     * @throws RepositoryException   if another error occurs while reading from
-     *                               the node.
-     */
-    public QueryImpl(Session session, ManagerProvider mgrProvider,
-                     ItemManager itemMgr, WorkspaceManager wspManager,
-                     Node node)
-        throws InvalidQueryException, RepositoryException {
-
-        this.session = session;
-        this.mgrProvider = mgrProvider;
-        this.itemManager = itemMgr;
+        this.wspManager.checkQueryStatement(statement, language, getNamespaceMappings());
         this.node = node;
-        this.wspManager = wspManager;
-
-        NamePathResolver resolver = mgrProvider.getNamePathResolver();
-        if (!node.isNodeType(resolver.getJCRName(NameConstants.NT_QUERY))) {
-            throw new InvalidQueryException("Node is not of type nt:query");
-        }
-        if (node.getSession() != session) {
-            throw new InvalidQueryException("Node belongs to a different session.");
-        }
-        statement = node.getProperty(resolver.getJCRName(NameConstants.JCR_STATEMENT)).getString();
-        language = node.getProperty(resolver.getJCRName(NameConstants.JCR_LANGUAGE)).getString();
-        this.wspManager.checkQueryStatement(
-                statement, language, getNamespaceMappings());
     }
 
     /**

Modified: jackrabbit/trunk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/query/QueryManagerImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/query/QueryManagerImpl.java?rev=786565&r1=786564&r2=786565&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/query/QueryManagerImpl.java
(original)
+++ jackrabbit/trunk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/query/QueryManagerImpl.java
Fri Jun 19 15:59:24 2009
@@ -21,10 +21,15 @@
 import org.apache.jackrabbit.jcr2spi.ManagerProvider;
 import org.apache.jackrabbit.spi.commons.query.qom.QueryObjectModelFactoryImpl;
 import org.apache.jackrabbit.spi.commons.query.qom.QueryObjectModelTree;
+import org.apache.jackrabbit.spi.commons.query.QueryObjectModelBuilderRegistry;
+import org.apache.jackrabbit.spi.commons.query.QueryObjectModelBuilder;
+import org.apache.jackrabbit.spi.commons.conversion.NamePathResolver;
+import org.apache.jackrabbit.spi.commons.name.NameConstants;
 
 import javax.jcr.Node;
 import javax.jcr.RepositoryException;
 import javax.jcr.Session;
+import javax.jcr.ValueFactory;
 import javax.jcr.query.InvalidQueryException;
 import javax.jcr.query.Query;
 import javax.jcr.query.QueryManager;
@@ -42,6 +47,11 @@
     private final Session session;
 
     /**
+     * The value factory.
+     */
+    private final ValueFactory valueFactory;
+
+    /**
      * Provides various managers.
      */
     private final ManagerProvider mgrProvider;
@@ -57,36 +67,25 @@
     private final WorkspaceManager wspManager;
 
     /**
-     * The query object model factory.
-     */
-    private final QueryObjectModelFactory qomFactory;
-
-    /**
      * Creates a new <code>QueryManagerImpl</code> for the passed
      * <code>Session</code>.
      *
-     * @param session the current session.
+     * @param session     the current session.
      * @param mgrProvider the manager provider.
-     * @param itemMgr the item manager of the current session.
-     * @param wspManager the workspace manager.
+     * @param itemMgr     the item manager of the current session.
+     * @param wspManager  the workspace manager.
+     * @throws RepositoryException if an error occurs while initializing this
+     *                             query manager.
      */
     public QueryManagerImpl(Session session,
                             ManagerProvider mgrProvider,
                             ItemManager itemMgr,
                             WorkspaceManager wspManager) throws RepositoryException {
         this.session = session;
+        this.valueFactory = mgrProvider.getJcrValueFactory();
         this.mgrProvider = mgrProvider;
         this.itemMgr = itemMgr;
         this.wspManager = wspManager;
-        this.qomFactory = new QueryObjectModelFactoryImpl(
-                mgrProvider.getNamePathResolver(), mgrProvider.getJcrValueFactory()) {
-            
-            protected QueryObjectModel createQuery(QueryObjectModelTree qomTree)
-                    throws InvalidQueryException, RepositoryException {
-                // TODO implementation missing
-                throw new UnsupportedOperationException("Implementation missing: JCR-2107");
-            }
-        };
     }
 
     /**
@@ -95,7 +94,8 @@
     public Query createQuery(String statement, String language)
             throws InvalidQueryException, RepositoryException {
         checkIsAlive();
-        return new QueryImpl(session, mgrProvider, itemMgr, wspManager, statement, language);
+        return new QueryImpl(session, mgrProvider, itemMgr, wspManager,
+                statement, language, null);
     }
 
     /**
@@ -104,7 +104,26 @@
     public Query getQuery(Node node)
             throws InvalidQueryException, RepositoryException {
         checkIsAlive();
-        return new QueryImpl(session, mgrProvider, itemMgr, wspManager, node);
+
+        NamePathResolver resolver = mgrProvider.getNamePathResolver();
+        if (!node.isNodeType(resolver.getJCRName(NameConstants.NT_QUERY))) {
+            throw new InvalidQueryException("Node is not of type nt:query");
+        }
+        if (node.getSession() != session) {
+            throw new InvalidQueryException("Node belongs to a different session.");
+        }
+        String statement = node.getProperty(resolver.getJCRName(NameConstants.JCR_STATEMENT)).getString();
+        String language = node.getProperty(resolver.getJCRName(NameConstants.JCR_LANGUAGE)).getString();
+
+        if (Query.JCR_JQOM.equals(language)) {
+            QueryObjectModelFactory qomFactory = new QOMFactory(
+                    node, resolver, valueFactory);
+            QueryObjectModelBuilder builder = QueryObjectModelBuilderRegistry.getQueryObjectModelBuilder(language);
+            return builder.createQueryObjectModel(statement, qomFactory, valueFactory);
+        } else {
+            return new QueryImpl(session, mgrProvider, itemMgr, wspManager,
+                    statement, language, node);
+        }
     }
 
     /**
@@ -118,7 +137,7 @@
      * @see QueryManager#getQOMFactory()
      */
     public QueryObjectModelFactory getQOMFactory() {
-        return qomFactory;        
+        return new QOMFactory(null, mgrProvider.getNamePathResolver(), valueFactory);
     }
 
     //------------------------------------------------------------< private >---
@@ -135,4 +154,21 @@
         }
     }
 
+    private class QOMFactory extends QueryObjectModelFactoryImpl {
+
+        private final Node node;
+
+        public QOMFactory(Node node,
+                          NamePathResolver resolver,
+                          ValueFactory factory) {
+            super(resolver, factory);
+            this.node = node;
+        }
+
+        protected QueryObjectModel createQuery(QueryObjectModelTree qomTree)
+                throws InvalidQueryException, RepositoryException {
+            return new QueryObjectModelImpl(session, mgrProvider, itemMgr,
+                    wspManager, qomTree, node);
+        }
+    }
 }

Added: jackrabbit/trunk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/query/QueryObjectModelImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/query/QueryObjectModelImpl.java?rev=786565&view=auto
==============================================================================
--- jackrabbit/trunk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/query/QueryObjectModelImpl.java
(added)
+++ jackrabbit/trunk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/query/QueryObjectModelImpl.java
Fri Jun 19 15:59:24 2009
@@ -0,0 +1,184 @@
+/*
+ * 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.jcr2spi.query;
+
+import javax.jcr.query.qom.QueryObjectModel;
+import javax.jcr.query.qom.Source;
+import javax.jcr.query.qom.Constraint;
+import javax.jcr.query.qom.Ordering;
+import javax.jcr.query.qom.Column;
+import javax.jcr.query.InvalidQueryException;
+import javax.jcr.query.Query;
+import javax.jcr.query.QueryResult;
+import javax.jcr.Session;
+import javax.jcr.RepositoryException;
+import javax.jcr.Node;
+import javax.jcr.ItemNotFoundException;
+import javax.jcr.ItemExistsException;
+import javax.jcr.PathNotFoundException;
+import javax.jcr.UnsupportedRepositoryOperationException;
+import javax.jcr.Value;
+import javax.jcr.lock.LockException;
+import javax.jcr.nodetype.ConstraintViolationException;
+import javax.jcr.version.VersionException;
+
+import org.apache.jackrabbit.jcr2spi.ManagerProvider;
+import org.apache.jackrabbit.jcr2spi.ItemManager;
+import org.apache.jackrabbit.jcr2spi.WorkspaceManager;
+import org.apache.jackrabbit.spi.commons.query.qom.QueryObjectModelTree;
+import org.apache.jackrabbit.spi.commons.query.QueryObjectModelBuilderRegistry;
+
+/**
+ * <code>QueryObjectModelImpl</code> implements the jcr2spi query object model.
+ */
+public class QueryObjectModelImpl extends QueryImpl implements QueryObjectModel {
+
+    /**
+     * The query object model tree.
+     */
+    private final QueryObjectModelTree qomTree;
+
+    public QueryObjectModelImpl(Session session,
+                                ManagerProvider mgrProvider,
+                                ItemManager itemMgr,
+                                WorkspaceManager wspManager,
+                                QueryObjectModelTree qomTree,
+                                Node node)
+            throws InvalidQueryException, RepositoryException {
+        super(session, mgrProvider, itemMgr, wspManager,
+                getSQL2ForQOM(qomTree), Query.JCR_SQL2, node);
+        this.qomTree = qomTree;
+    }
+
+    /**
+     * @return always {@link Query#JCR_JQOM}.
+     */
+    public String getLanguage() {
+        return Query.JCR_JQOM;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public Source getSource() {
+        return qomTree.getSource();
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public Constraint getConstraint() {
+        return qomTree.getConstraint();
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public Ordering[] getOrderings() {
+        return qomTree.getOrderings();
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public Column[] getColumns() {
+        return qomTree.getColumns();
+    }
+
+    private static String getSQL2ForQOM(QueryObjectModelTree qomTree)
+            throws InvalidQueryException {
+        return QueryObjectModelBuilderRegistry.getQueryObjectModelBuilder(Query.JCR_JQOM).toString(new
DummyQOM(qomTree));
+    }
+
+    private static class DummyQOM implements QueryObjectModel {
+
+        /**
+         * The query object model tree.
+         */
+        private final QueryObjectModelTree qomTree;
+
+        public DummyQOM(QueryObjectModelTree qomTree) {
+            this.qomTree = qomTree;
+        }
+
+        /**
+         * {@inheritDoc}
+         */
+        public Source getSource() {
+            return qomTree.getSource();
+        }
+
+        /**
+         * {@inheritDoc}
+         */
+        public Constraint getConstraint() {
+            return qomTree.getConstraint();
+        }
+
+        /**
+         * {@inheritDoc}
+         */
+        public Ordering[] getOrderings() {
+            return qomTree.getOrderings();
+        }
+
+        /**
+         * {@inheritDoc}
+         */
+        public Column[] getColumns() {
+            return qomTree.getColumns();
+        }
+
+        public QueryResult execute()
+                throws InvalidQueryException, RepositoryException {
+            throw new UnsupportedOperationException();
+        }
+
+        public void setLimit(long limit) {
+            throw new UnsupportedOperationException();
+        }
+
+        public void setOffset(long offset) {
+            throw new UnsupportedOperationException();
+        }
+
+        public String getStatement() {
+            throw new UnsupportedOperationException();
+        }
+
+        public String getLanguage() {
+            throw new UnsupportedOperationException();
+        }
+
+        public String getStoredQueryPath()
+                throws ItemNotFoundException, RepositoryException {
+            throw new UnsupportedOperationException();
+        }
+
+        public Node storeAsNode(String absPath) throws ItemExistsException,
+                PathNotFoundException, VersionException,
+                ConstraintViolationException, LockException,
+                UnsupportedRepositoryOperationException, RepositoryException {
+            throw new UnsupportedOperationException();
+        }
+
+        public void bindValue(String varName, Value value)
+                throws IllegalArgumentException, RepositoryException {
+            throw new UnsupportedOperationException();
+        }
+    }
+}

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



Mime
View raw message