jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mreut...@apache.org
Subject svn commit: r152659 - in incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/search: ExecutableQuery.java QueryImpl.java
Date Tue, 08 Feb 2005 10:45:07 GMT
Author: mreutegg
Date: Tue Feb  8 02:45:04 2005
New Revision: 152659

URL: http://svn.apache.org/viewcvs?view=rev&rev=152659
Log:
New classes were missing with the last commit. sorry about that....

Added:
    incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/search/ExecutableQuery.java
  (with props)
    incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/search/QueryImpl.java 
 (with props)

Added: incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/search/ExecutableQuery.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/search/ExecutableQuery.java?view=auto&rev=152659
==============================================================================
--- incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/search/ExecutableQuery.java
(added)
+++ incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/search/ExecutableQuery.java
Tue Feb  8 02:45:04 2005
@@ -0,0 +1,36 @@
+/*
+ * 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.search;
+
+import javax.jcr.query.QueryResult;
+import javax.jcr.RepositoryException;
+
+/**
+ * Specifies an interface for a query object implementation that can just be
+ * executed.
+ * @see QueryImpl
+ */
+public interface ExecutableQuery {
+
+    /**
+     * Executes this query and returns a <code>{@link QueryResult}</code>.
+     *
+     * @return a <code>QueryResult</code>
+     * @throws RepositoryException if an error occurs
+     */
+    public QueryResult execute() throws RepositoryException;
+}

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

Added: incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/search/QueryImpl.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/search/QueryImpl.java?view=auto&rev=152659
==============================================================================
--- incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/search/QueryImpl.java (added)
+++ incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/search/QueryImpl.java Tue
Feb  8 02:45:04 2005
@@ -0,0 +1,188 @@
+/*
+ * 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.search;
+
+import org.apache.jackrabbit.core.nodetype.NodeTypeRegistry;
+import org.apache.jackrabbit.core.SessionImpl;
+import org.apache.jackrabbit.core.ItemManager;
+import org.apache.jackrabbit.core.Path;
+import org.apache.jackrabbit.core.MalformedPathException;
+import org.apache.jackrabbit.core.NoPrefixDeclaredException;
+import org.apache.jackrabbit.core.NamespaceResolver;
+import org.apache.log4j.Logger;
+
+import javax.jcr.nodetype.ConstraintViolationException;
+import javax.jcr.query.InvalidQueryException;
+import javax.jcr.query.QueryResult;
+import javax.jcr.query.Query;
+import javax.jcr.lock.LockException;
+import javax.jcr.version.VersionException;
+import javax.jcr.Node;
+import javax.jcr.RepositoryException;
+import javax.jcr.ItemNotFoundException;
+import javax.jcr.ItemExistsException;
+import javax.jcr.PathNotFoundException;
+import javax.jcr.UnsupportedRepositoryOperationException;
+
+/**
+ * Implements the {@link Query} interface.
+ */
+public class QueryImpl implements Query {
+
+    /** The session of the user executing this query */
+    private final SessionImpl session;
+
+    /** The query statement */
+    private final String statement;
+
+    /** The syntax of the query statement */
+    private final String language;
+
+    /** The actual query implementation that can be executed */
+    private final ExecutableQuery query;
+
+    /**
+     * The node where this query is persisted. Only set when this is a persisted
+     * query.
+     */
+    private Node node;
+
+    /**
+     * Creates a new query instance from a query string.
+     * @param session the session of the user executing this query.
+     * @param itemMgr the item manager of the session executing this query.
+     * @param handler the query handler of the search index.
+     * @param statement the query statement.
+     * @param language the syntax of the query statement.
+     * @throws InvalidQueryException if the query statement is invalid according
+     * to the specified <code>language</code>.
+     */
+    public QueryImpl(SessionImpl session,
+                     ItemManager itemMgr,
+                     QueryHandler handler,
+                     String statement,
+                     String language) throws InvalidQueryException {
+        this.session = session;
+        this.statement = statement;
+        this.language = language;
+        this.query = handler.createExecutableQuery(session, itemMgr, statement, language);
+    }
+
+    /**
+     * Create a new query instance from a nt:query node.
+     * @param session the session of the user executing this query.
+     * @param itemMgr the item manager of the session executing this query.
+     * @param handler the query handler of the search index.
+     * @param node a node of type <code>nt:query</code>.
+     * @throws InvalidQueryException If <code>node</code> is not a valid persisted
query
+     *   (that is, a node of type <code>nt:query</code>).
+     * @throws RepositoryException if another error occurs
+     */
+    public QueryImpl(SessionImpl session,
+                     ItemManager itemMgr,
+                     QueryHandler handler,
+                     Node node)
+            throws InvalidQueryException, RepositoryException {
+
+        this.session = session;
+        this.node = node;
+
+        try {
+            if (!node.isNodeType(NodeTypeRegistry.NT_QUERY.toJCRName(session.getNamespaceResolver())))
{
+                throw new InvalidQueryException("node is not of type nt:query");
+            }
+            statement = node.getProperty(Constants.JCR_STATEMENT.toJCRName(session.getNamespaceResolver())).getString();
+            language = node.getProperty(Constants.JCR_LANGUAGE.toJCRName(session.getNamespaceResolver())).getString();
+            query = handler.createExecutableQuery(session, itemMgr, statement, language);
+        } catch (NoPrefixDeclaredException e) {
+            throw new RepositoryException(e.getMessage(), e);
+        }
+    }
+
+    /**
+     * This method simply forwards the <code>execute</code> call to the
+     * {@link ExecutableQuery} object returned by
+     * {@link QueryHandler#createExecutableQuery}.
+     * @see Query#execute()
+     */
+    public QueryResult execute() throws RepositoryException {
+        return query.execute();
+    }
+
+    /**
+     * @see Query#getStatement()
+     */
+    public String getStatement() {
+        return statement;
+    }
+
+    /**
+     * @see Query#getLanguage()
+     */
+    public String getLanguage() {
+        return language;
+    }
+
+    /**
+     * @see Query#getPersistentQueryPath()
+     */
+    public String getPersistentQueryPath() throws ItemNotFoundException, RepositoryException
{
+        if (node == null) {
+            throw new ItemNotFoundException("not a persistent query");
+        }
+        return node.getPath();
+    }
+
+    /**
+     * @see Query#save(String)
+     */
+    public void save(String absPath)
+            throws ItemExistsException,
+            PathNotFoundException,
+            VersionException,
+            ConstraintViolationException,
+            LockException,
+            UnsupportedRepositoryOperationException,
+            RepositoryException {
+        try {
+            NamespaceResolver resolver = session.getNamespaceResolver();
+            Path p = Path.create(absPath, resolver, true);
+            if (!p.isAbsolute()) {
+                throw new RepositoryException(absPath + " is not an absolut path");
+            }
+            if (!session.getRootNode().hasNode(p.getAncestor(1).toJCRPath(resolver).substring(1)))
{
+                throw new PathNotFoundException(p.getAncestor(1).toJCRPath(resolver));
+            }
+            String relPath = p.toJCRPath(resolver).substring(1);
+            if (session.getRootNode().hasNode(relPath)) {
+                throw new ItemExistsException(p.toJCRPath(resolver));
+            }
+            Node queryNode = session.getRootNode().addNode(relPath,
+                    NodeTypeRegistry.NT_QUERY.toJCRName(resolver));
+            // set properties
+            queryNode.setProperty(Constants.JCR_LANGUAGE.toJCRName(resolver), language);
+            queryNode.setProperty(Constants.JCR_STATEMENT.toJCRName(resolver), statement);
+            // todo this should be changed in the spec some time!
+            queryNode.getParent().save();
+        } catch (MalformedPathException e) {
+            throw new RepositoryException(e.getMessage(), e);
+        } catch (NoPrefixDeclaredException e) {
+            throw new RepositoryException(e.getMessage(), e);
+        }
+    }
+}
+

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



Mime
View raw message