jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mreut...@apache.org
Subject svn commit: r483370 - in /jackrabbit/trunk/contrib/spi: client/src/test/java/org/apache/jackrabbit/jcr2spi/query/ jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/ jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/name/ jcr2spi/src/main/java/org/a...
Date Thu, 07 Dec 2006 08:22:53 GMT
Author: mreutegg
Date: Thu Dec  7 00:22:51 2006
New Revision: 483370

URL: http://svn.apache.org/viewvc?view=rev&rev=483370
Log:
Work in progress
- Add checkQueryStatement() to RepositoryService
- Add Map of locally remapped namespaces to RepositoryService.executeQuery()
- Added test case for query statement with locally remapped namespace prefix

TODO: implement query statement check in spi2dav

Modified:
    jackrabbit/trunk/contrib/spi/client/src/test/java/org/apache/jackrabbit/jcr2spi/query/QueryTest.java
    jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/SessionImpl.java
    jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/WorkspaceImpl.java
    jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/WorkspaceManager.java
    jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/name/LocalNamespaceMappings.java
    jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/query/QueryImpl.java
    jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/query/QueryManagerImpl.java
    jackrabbit/trunk/contrib/spi/spi/src/main/java/org/apache/jackrabbit/spi/RepositoryService.java
    jackrabbit/trunk/contrib/spi/spi2dav/src/main/java/org/apache/jackrabbit/spi2dav/RepositoryServiceImpl.java

Modified: jackrabbit/trunk/contrib/spi/client/src/test/java/org/apache/jackrabbit/jcr2spi/query/QueryTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/spi/client/src/test/java/org/apache/jackrabbit/jcr2spi/query/QueryTest.java?view=diff&rev=483370&r1=483369&r2=483370
==============================================================================
--- jackrabbit/trunk/contrib/spi/client/src/test/java/org/apache/jackrabbit/jcr2spi/query/QueryTest.java
(original)
+++ jackrabbit/trunk/contrib/spi/client/src/test/java/org/apache/jackrabbit/jcr2spi/query/QueryTest.java
Thu Dec  7 00:22:51 2006
@@ -20,6 +20,7 @@
 import javax.jcr.RepositoryException;
 import javax.jcr.NodeIterator;
 import javax.jcr.Node;
+import javax.jcr.NamespaceRegistry;
 import java.util.List;
 import java.util.ArrayList;
 
@@ -38,5 +39,30 @@
         }
         Node[] children = (Node[]) nodes.toArray(new Node[nodes.size()]);
         executeXPathQuery(superuser, "/jcr:root/*", children);
+    }
+
+    public void testRemappedNamespace() throws RepositoryException {
+        String namespaceURI = "http://jackrabbit.apache.org/spi/test";
+        String defaultPrefix = "spiTest";
+
+        NamespaceRegistry nsReg = superuser.getWorkspace().getNamespaceRegistry();
+        try {
+            nsReg.getPrefix(namespaceURI);
+        } catch (RepositoryException e) {
+            nsReg.registerNamespace(defaultPrefix, namespaceURI);
+        }
+
+        Node n = testRootNode.addNode("spiTest:node");
+        testRootNode.save();
+
+        long time = System.currentTimeMillis();
+        for (int i = 0; i < 10; i++) {
+            String prefix = defaultPrefix + i;
+            superuser.setNamespacePrefix(prefix, namespaceURI);
+            executeXPathQuery(superuser, testPath + "/" + prefix + ":node", new Node[]{n});
+        }
+        time = System.currentTimeMillis() - time;
+        System.out.println("Executed 10 queries in " + time + " ms");
+        System.out.println("Time per query: " + (time / 10) + " ms");
     }
 }

Modified: jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/SessionImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/SessionImpl.java?view=diff&rev=483370&r1=483369&r2=483370
==============================================================================
--- jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/SessionImpl.java
(original)
+++ jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/SessionImpl.java
Thu Dec  7 00:22:51 2006
@@ -725,6 +725,11 @@
     }
 
     //--------------------------------------------------------------------------
+
+    LocalNamespaceMappings getLocalNamespaceMappings() {
+        return nsMappings;
+    }
+
     ItemManager getItemManager() {
         return itemManager;
     }

Modified: jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/WorkspaceImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/WorkspaceImpl.java?view=diff&rev=483370&r1=483369&r2=483370
==============================================================================
--- jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/WorkspaceImpl.java
(original)
+++ jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/WorkspaceImpl.java
Thu Dec  7 00:22:51 2006
@@ -260,7 +260,7 @@
     public QueryManager getQueryManager() throws RepositoryException {
         session.checkIsAlive();
         if (qManager == null) {
-            qManager = new QueryManagerImpl(session, session.getNamespaceResolver(),
+            qManager = new QueryManagerImpl(session, session.getLocalNamespaceMappings(),
                 session.getItemManager(), session.getItemStateManager(), wspManager);
         }
         return qManager;

Modified: jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/WorkspaceManager.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/WorkspaceManager.java?view=diff&rev=483370&r1=483369&r2=483370
==============================================================================
--- jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/WorkspaceManager.java
(original)
+++ jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/WorkspaceManager.java
Thu Dec  7 00:22:51 2006
@@ -95,6 +95,7 @@
 import javax.jcr.MergeException;
 import javax.jcr.Session;
 import javax.jcr.ReferentialIntegrityException;
+import javax.jcr.query.InvalidQueryException;
 import javax.jcr.version.VersionException;
 import javax.jcr.lock.LockException;
 import javax.jcr.nodetype.NoSuchNodeTypeException;
@@ -246,15 +247,34 @@
     }
 
     /**
+     * Checks if the query statement is valid.
      *
-     * @param statement
-     * @param language
+     * @param statement  the query statement.
+     * @param language   the query language.
+     * @param namespaces the locally remapped namespaces which might be used in
+     *                   the query statement.
+     * @throws InvalidQueryException if the query statement is invalid.
+     * @throws RepositoryException   if an error occurs while checking the query
+     *                               statement.
+     */
+    public void checkQueryStatement(String statement,
+                                    String language,
+                                    Map namespaces)
+            throws InvalidQueryException, RepositoryException {
+        service.checkQueryStatement(sessionInfo, statement, language, namespaces);
+    }
+
+    /**
+     * @param statement  the query statement.
+     * @param language   the query language.
+     * @param namespaces the locally remapped namespaces which might be used in
+     *                   the query statement.
      * @return
      * @throws RepositoryException
      */
-    public QueryInfo executeQuery(String statement, String language)
+    public QueryInfo executeQuery(String statement, String language, Map namespaces)
             throws RepositoryException {
-        return service.executeQuery(sessionInfo, statement, language);
+        return service.executeQuery(sessionInfo, statement, language, namespaces);
     }
 
     /**
@@ -450,7 +470,10 @@
                 eventSignal = getEventPollingRequest();
             }
             try {
-                eventSignal.acquire();
+                // wait at most 10 seconds
+                if (!eventSignal.attempt(10 * 1000)) {
+                    log.warn("No events received for batch");
+                }
             } catch (InterruptedException e) {
                 Thread.interrupted();
                 log.warn("Interrupted while waiting for events from RepositoryService");
@@ -991,13 +1014,16 @@
                         EventFilter[] filtArr = (EventFilter[]) filters.toArray(new EventFilter[filters.size()]);
 
                         EventBundle[] bundles = service.getEvents(sessionInfo, timeout, filtArr);
-                        if (bundles.length > 0) {
-                            onEventReceived(bundles);
-                        }
-                        if (signal != null) {
-                            log.debug("About to signal that events have been delivered");
-                            signal.release();
-                            log.debug("Event delivery signaled");
+                        try {
+                            if (bundles.length > 0) {
+                                onEventReceived(bundles);
+                            }
+                        } finally {
+                            if (signal != null) {
+                                log.debug("About to signal that events have been delivered");
+                                signal.release();
+                                log.debug("Event delivery signaled");
+                            }
                         }
                     }
                 } catch (UnsupportedRepositoryOperationException e) {
@@ -1010,6 +1036,9 @@
                 } catch (InterruptedException e) {
                     // terminate
                     break;
+                } catch (Exception e) {
+                    log.warn("Exception in event polling thread: " + e);
+                    log.debug("Dump:", e);
                 }
             }
         }

Modified: jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/name/LocalNamespaceMappings.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/name/LocalNamespaceMappings.java?view=diff&rev=483370&r1=483369&r2=483370
==============================================================================
--- jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/name/LocalNamespaceMappings.java
(original)
+++ jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/name/LocalNamespaceMappings.java
Thu Dec  7 00:22:51 2006
@@ -29,6 +29,7 @@
 import java.util.HashMap;
 import java.util.HashSet;
 import java.util.Arrays;
+import java.util.Map;
 
 /**
  * Manager for local session namespace mappings. This class is
@@ -156,6 +157,13 @@
      */
     public void dispose() {
         nsReg.removeListener(this);
+    }
+
+    /**
+     * @return the namespace mappings that are locally re-mapped.
+     */
+    public Map getLocalNamespaceMappings() {
+        return new HashMap(prefixToURI);
     }
 
     //--------------------------------------------------< NamespaceResolver >---

Modified: jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/query/QueryImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/query/QueryImpl.java?view=diff&rev=483370&r1=483369&r2=483370
==============================================================================
--- jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/query/QueryImpl.java
(original)
+++ jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/query/QueryImpl.java
Thu Dec  7 00:22:51 2006
@@ -18,9 +18,9 @@
 
 import org.apache.jackrabbit.jcr2spi.ItemManager;
 import org.apache.jackrabbit.jcr2spi.WorkspaceManager;
+import org.apache.jackrabbit.jcr2spi.name.LocalNamespaceMappings;
 import org.apache.jackrabbit.jcr2spi.state.ItemStateManager;
 import org.apache.jackrabbit.name.MalformedPathException;
-import org.apache.jackrabbit.name.NamespaceResolver;
 import org.apache.jackrabbit.name.NoPrefixDeclaredException;
 import org.apache.jackrabbit.name.Path;
 import org.apache.jackrabbit.name.PathFormat;
@@ -53,9 +53,9 @@
     private final Session session;
 
     /**
-     * The namespace nsResolver of the session that executes this query.
+     * The namespace mappings of the session that executes this query.
      */
-    private final NamespaceResolver nsResolver;
+    private final LocalNamespaceMappings nsResolver;
 
     /**
      * The item manager of the session that executes this query.
@@ -91,19 +91,21 @@
     /**
      * Creates a new query.
      *
-     * @param session    the session that created this query.
-     * @param nsResolver the namespace resolver to be used.
-     * @param itemMgr    the item manager of that session.
+     * @param session          the session that created this query.
+     * @param nsResolver       the namespace resolver to be used.
+     * @param itemMgr          the item manager of that session.
      * @param itemStateManager the item state 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 wspManager       the workspace manager that belongs to the
+     *                         session.
+     * @param statement        the query statement.
+     * @param language         the language of the query statement.
      * @throws InvalidQueryException if the query is invalid.
      */
-    public QueryImpl(Session session, NamespaceResolver nsResolver,
+    public QueryImpl(Session session, LocalNamespaceMappings nsResolver,
                      ItemManager itemMgr, ItemStateManager itemStateManager,
                      WorkspaceManager wspManager,
-                     String statement, String language) throws InvalidQueryException {
+                     String statement, String language)
+            throws InvalidQueryException, RepositoryException {
         this.session = session;
         this.nsResolver = nsResolver;
         this.itemManager = itemMgr;
@@ -111,8 +113,7 @@
         this.statement = statement;
         this.language = language;
         this.wspManager = wspManager;
-        // TODO: validate statement
-        //this.query = handler.createExecutableQuery(session, itemMgr, statement, language);
+        this.wspManager.checkQueryStatement(statement, language, nsResolver.getLocalNamespaceMappings());
     }
 
     /**
@@ -127,7 +128,7 @@
      * @throws RepositoryException   if another error occurs while reading from
      *                               the node.
      */
-    public QueryImpl(Session session, NamespaceResolver nsResolver,
+    public QueryImpl(Session session, LocalNamespaceMappings nsResolver,
                      ItemManager itemMgr, ItemStateManager itemStateManager,
                      WorkspaceManager wspManager, Node node)
         throws InvalidQueryException, RepositoryException {
@@ -145,8 +146,8 @@
             }
             statement = node.getProperty(NameFormat.format(QName.JCR_STATEMENT, nsResolver)).getString();
             language = node.getProperty(NameFormat.format(QName.JCR_LANGUAGE, nsResolver)).getString();
-            // TODO: validate statement
-            //query = handler.createExecutableQuery(session, itemMgr, statement, language);
+            this.wspManager.checkQueryStatement(statement, language,
+                    nsResolver.getLocalNamespaceMappings());
         } catch (NoPrefixDeclaredException e) {
             throw new RepositoryException(e.getMessage(), e);
         }
@@ -156,7 +157,8 @@
      * @see Query#execute() 
      */
     public QueryResult execute() throws RepositoryException {
-        QueryInfo qI = wspManager.executeQuery(statement, language);
+        QueryInfo qI = wspManager.executeQuery(statement, language,
+                nsResolver.getLocalNamespaceMappings());
         return new QueryResultImpl(itemManager, itemStateManager, qI, nsResolver);
     }
 

Modified: jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/query/QueryManagerImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/query/QueryManagerImpl.java?view=diff&rev=483370&r1=483369&r2=483370
==============================================================================
--- jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/query/QueryManagerImpl.java
(original)
+++ jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/query/QueryManagerImpl.java
Thu Dec  7 00:22:51 2006
@@ -18,8 +18,8 @@
 
 import org.apache.jackrabbit.jcr2spi.ItemManager;
 import org.apache.jackrabbit.jcr2spi.WorkspaceManager;
+import org.apache.jackrabbit.jcr2spi.name.LocalNamespaceMappings;
 import org.apache.jackrabbit.jcr2spi.state.ItemStateManager;
-import org.apache.jackrabbit.name.NamespaceResolver;
 
 import javax.jcr.Node;
 import javax.jcr.RepositoryException;
@@ -39,9 +39,9 @@
     private final Session session;
 
     /**
-     * The namespace nsResolver for this query manager.
+     * The local namespace mappings for this query manager.
      */
-    private final NamespaceResolver nsResolver;
+    private final LocalNamespaceMappings nsResolver;
 
     /**
      * The <code>ItemManager</code> of for item retrieval in search results
@@ -69,7 +69,7 @@
      * @param wspManager
      */
     public QueryManagerImpl(Session session,
-                            NamespaceResolver nsResolver,
+                            LocalNamespaceMappings nsResolver,
                             ItemManager itemMgr,
                             ItemStateManager itemStateManager,
                             WorkspaceManager wspManager) {

Modified: jackrabbit/trunk/contrib/spi/spi/src/main/java/org/apache/jackrabbit/spi/RepositoryService.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/spi/spi/src/main/java/org/apache/jackrabbit/spi/RepositoryService.java?view=diff&rev=483370&r1=483369&r2=483370
==============================================================================
--- jackrabbit/trunk/contrib/spi/spi/src/main/java/org/apache/jackrabbit/spi/RepositoryService.java
(original)
+++ jackrabbit/trunk/contrib/spi/spi/src/main/java/org/apache/jackrabbit/spi/RepositoryService.java
Thu Dec  7 00:22:51 2006
@@ -39,6 +39,7 @@
 import javax.jcr.Node;
 import javax.jcr.LoginException;
 import javax.jcr.ReferentialIntegrityException;
+import javax.jcr.query.InvalidQueryException;
 import java.util.Map;
 import java.util.Collection;
 import java.io.InputStream;
@@ -522,14 +523,33 @@
     public String[] getSupportedQueryLanguages(SessionInfo sessionInfo) throws RepositoryException;
 
     /**
+     * Checks if the query <code>statement</code> is valid according to the
+     * specified query <code>language</code>.
+     *
+     * @param sessionInfo the session info.
+     * @param statement   the query statement to check.
+     * @param language    the query language.
+     * @param namespaces  the locally re-mapped namespace which may be used in
+     *                    the query <code>statement</code>.
+     * @throws InvalidQueryException if the query statement is invalid or the
+     *                               language is not supported.
+     * @throws RepositoryException   if an error occurs while checking the
+     *                               statement.
+     * @see javax.jcr.query.QueryManager#createQuery(String, String)
+     */
+    public void checkQueryStatement(SessionInfo sessionInfo, String statement, String language,
Map namespaces) throws InvalidQueryException, RepositoryException;
+
+    /**
      * @param sessionInfo
      * @param statement
      * @param language
+     * @param namespaces  the locally re-mapped namespace which may be used in
+     *                    the query <code>statement</code>.
      * @return
      * @throws javax.jcr.RepositoryException
      * @see javax.jcr.query.Query#execute()
      */
-    public QueryInfo executeQuery(SessionInfo sessionInfo, String statement, String language)
throws RepositoryException;
+    public QueryInfo executeQuery(SessionInfo sessionInfo, String statement, String language,
Map namespaces) throws RepositoryException;
 
     //--------------------------------------------------------< Observation >---
 

Modified: jackrabbit/trunk/contrib/spi/spi2dav/src/main/java/org/apache/jackrabbit/spi2dav/RepositoryServiceImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/spi/spi2dav/src/main/java/org/apache/jackrabbit/spi2dav/RepositoryServiceImpl.java?view=diff&rev=483370&r1=483369&r2=483370
==============================================================================
--- jackrabbit/trunk/contrib/spi/spi2dav/src/main/java/org/apache/jackrabbit/spi2dav/RepositoryServiceImpl.java
(original)
+++ jackrabbit/trunk/contrib/spi/spi2dav/src/main/java/org/apache/jackrabbit/spi2dav/RepositoryServiceImpl.java
Thu Dec  7 00:22:51 2006
@@ -85,6 +85,7 @@
 import org.apache.jackrabbit.webdav.header.CodedUrlHeader;
 import org.apache.jackrabbit.webdav.header.IfHeader;
 import org.apache.jackrabbit.webdav.search.SearchConstants;
+import org.apache.jackrabbit.webdav.search.SearchInfo;
 import org.apache.jackrabbit.webdav.jcr.version.report.RepositoryDescriptorsReport;
 import org.apache.jackrabbit.webdav.jcr.version.report.RegisteredNamespacesReport;
 import org.apache.jackrabbit.webdav.jcr.version.report.NodeTypesReport;
@@ -146,6 +147,7 @@
 import javax.jcr.ValueFactory;
 import javax.jcr.LoginException;
 import javax.jcr.ReferentialIntegrityException;
+import javax.jcr.query.InvalidQueryException;
 import javax.jcr.lock.LockException;
 import javax.jcr.nodetype.ConstraintViolationException;
 import javax.jcr.nodetype.NoSuchNodeTypeException;
@@ -1190,14 +1192,24 @@
         }
     }
 
+    public void checkQueryStatement(SessionInfo sessionInfo,
+                                    String statement,
+                                    String language,
+                                    Map namespaces)
+            throws InvalidQueryException, RepositoryException {
+        // TODO implement
+    }
+
     /**
-     * @see RepositoryService#executeQuery(SessionInfo, String, String)
+     * @see RepositoryService#executeQuery(SessionInfo, String, String, Map)
      */
-    public QueryInfo executeQuery(SessionInfo sessionInfo, String statement, String language)
throws RepositoryException {
+    public QueryInfo executeQuery(SessionInfo sessionInfo, String statement, String language,
Map namespaces) throws RepositoryException {
         SearchMethod method = null;
         try {
             String uri = uriResolver.getWorkspaceUri(sessionInfo.getWorkspaceName());
-            method = new SearchMethod(uri, statement, language);
+            SearchInfo sInfo = new SearchInfo(language,
+                    Namespace.EMPTY_NAMESPACE, statement, namespaces);
+            method = new SearchMethod(uri, sInfo);
             getClient(sessionInfo).executeMethod(method);
             method.checkSuccess();
 



Mime
View raw message