jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ju...@apache.org
Subject svn commit: r705937 - in /jackrabbit/trunk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi: NamespaceRegistryImpl.java NamespaceStorage.java WorkspaceManager.java
Date Sat, 18 Oct 2008 23:38:38 GMT
Author: jukka
Date: Sat Oct 18 16:38:38 2008
New Revision: 705937

URL: http://svn.apache.org/viewvc?rev=705937&view=rev
Log:
JCR-1612: Reintroduce NamespaceStorage and namespace-caching

Hmm, the namespace cache I restored actually wasn't repository-level but per-session, which
caused a test failure.

In fact, with the current SPI RepositoryService design it's impossible to do a proper repository-level
namespace cache without making extra assumptions about the repository as all the namespace
methods in RepositoryService take a SessionInfo argument.

Modified:
    jackrabbit/trunk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/NamespaceRegistryImpl.java
    jackrabbit/trunk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/NamespaceStorage.java
    jackrabbit/trunk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/WorkspaceManager.java

Modified: jackrabbit/trunk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/NamespaceRegistryImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/NamespaceRegistryImpl.java?rev=705937&r1=705936&r2=705937&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/NamespaceRegistryImpl.java
(original)
+++ jackrabbit/trunk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/NamespaceRegistryImpl.java
Sat Oct 18 16:38:38 2008
@@ -16,12 +16,14 @@
  */
 package org.apache.jackrabbit.jcr2spi;
 
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.Map;
+import java.util.Collection;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
-import javax.jcr.NamespaceException;
 import javax.jcr.NamespaceRegistry;
+import javax.jcr.NamespaceException;
+import javax.jcr.UnsupportedRepositoryOperationException;
 import javax.jcr.RepositoryException;
 
 /**
@@ -30,14 +32,9 @@
  */
 public class NamespaceRegistryImpl implements NamespaceRegistry {
 
-    /**
-     * The namespace storage.
-     */
-    private final NamespaceStorage storage;
-
-    private final Map prefixToUri = new HashMap();
+    private static Logger log = LoggerFactory.getLogger(NamespaceRegistryImpl.class);
 
-    private final Map uriToPrefix = new HashMap();
+    private final NamespaceStorage storage;
 
     /**
      * Create a new <code>NamespaceRegistryImpl</code>.
@@ -53,93 +50,58 @@
     /**
      * @see NamespaceRegistry#registerNamespace(String, String)
      */
-    public synchronized void registerNamespace(String prefix, String uri)
-            throws RepositoryException {
+    public void registerNamespace(String prefix, String uri) throws NamespaceException, UnsupportedRepositoryOperationException,
RepositoryException {
         storage.registerNamespace(prefix, uri);
-        reloadNamespaces();
     }
 
     /**
      * @see NamespaceRegistry#unregisterNamespace(String)
      */
-    public synchronized void unregisterNamespace(String prefix)
-            throws RepositoryException {
+    public void unregisterNamespace(String prefix) throws NamespaceException, UnsupportedRepositoryOperationException,
RepositoryException {
         storage.unregisterNamespace(prefix);
-        reloadNamespaces();
     }
 
     /**
      * @see javax.jcr.NamespaceRegistry#getPrefixes()
      */
-    public synchronized String[] getPrefixes() throws RepositoryException {
-        reloadNamespaces();
-        return (String[]) prefixToUri.keySet().toArray(new String[prefixToUri.size()]);
+    public String[] getPrefixes() throws RepositoryException {
+        Collection prefixes = storage.getRegisteredNamespaces().keySet();
+        return (String[]) prefixes.toArray(new String[prefixes.size()]);
     }
 
     /**
      * @see javax.jcr.NamespaceRegistry#getURIs()
      */
-    public synchronized String[] getURIs() throws RepositoryException {
-        reloadNamespaces();
-        return (String[]) uriToPrefix.keySet().toArray(new String[uriToPrefix.size()]);
+    public String[] getURIs() throws RepositoryException {
+        Collection uris = storage.getRegisteredNamespaces().values();
+        return (String[]) uris.toArray(new String[uris.size()]);
     }
 
     /**
      * @see javax.jcr.NamespaceRegistry#getURI(String)
      * @see org.apache.jackrabbit.spi.commons.namespace.NamespaceResolver#getURI(String)
      */
-    public synchronized String getURI(String prefix)
-            throws RepositoryException {
-        String uri = (String) prefixToUri.get(prefix);
-        if (uri == null) {
-            // Not found, try loading latest state from storage
-            reloadNamespaces();
-            uri = (String) prefixToUri.get(prefix);
+    public String getURI(String prefix) throws NamespaceException {
+        // try to load the uri
+        try {
+            return storage.getURI(prefix);
+        } catch (RepositoryException ex) {
+            log.debug("Internal error while loading registered namespaces.");
+            throw new NamespaceException(prefix + ": is not a registered namespace prefix.");
         }
-        if (uri == null) {
-            // Still not found, it's not a known prefix
-            throw new NamespaceException("Namespace not found: " + prefix);
-        }
-        return uri;
     }
 
     /**
      * @see javax.jcr.NamespaceRegistry#getPrefix(String)
      * @see org.apache.jackrabbit.spi.commons.namespace.NamespaceResolver#getPrefix(String)
      */
-    public synchronized String getPrefix(String uri) throws RepositoryException {
-        String prefix = (String) uriToPrefix.get(uri);
-        if (prefix == null) {
-            // Not found, try loading latest state from storage
-            reloadNamespaces();
-            prefix = (String) uriToPrefix.get(uri);
-        }
-        if (prefix == null) {
-            // Still not found, it's not a known URI
-            throw new NamespaceException("Namespace not found: " + uri);
-        }
-        return prefix;
-    }
-
-    //-------------------------------------------------------------< private >
-
-    /**
-     * Clears the current namespace cache and loads new mappings from
-     * the underlying namespace storage.
-     *
-     * @throws RepositoryException if new mappings could not be loaded
-     */
-    private synchronized void reloadNamespaces() throws RepositoryException {
-        Map namespaces = storage.getRegisteredNamespaces();
-
-        prefixToUri.clear();
-        uriToPrefix.clear();
-
-        Iterator iterator = namespaces.entrySet().iterator();
-        while (iterator.hasNext()) {
-            Map.Entry entry = (Map.Entry) iterator.next();
-            prefixToUri.put(entry.getKey(), entry.getValue());
-            uriToPrefix.put(entry.getValue(), entry.getKey());
+    public String getPrefix(String uri) throws NamespaceException {
+        // try to load the prefix
+        try {
+            return storage.getPrefix(uri);
+        } catch (RepositoryException ex) {
+            log.debug("Internal error while loading registered namespaces.");
+            throw new NamespaceException(uri + ": is not a registered namespace uri.");
         }
     }
 

Modified: jackrabbit/trunk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/NamespaceStorage.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/NamespaceStorage.java?rev=705937&r1=705936&r2=705937&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/NamespaceStorage.java
(original)
+++ jackrabbit/trunk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/NamespaceStorage.java
Sat Oct 18 16:38:38 2008
@@ -18,6 +18,9 @@
 
 import java.util.Map;
 
+import javax.jcr.NamespaceException;
+import javax.jcr.UnsupportedRepositoryOperationException;
+import javax.jcr.AccessDeniedException;
 import javax.jcr.RepositoryException;
 
 /**
@@ -25,10 +28,14 @@
  */
 public interface NamespaceStorage {
 
-    Map getRegisteredNamespaces() throws RepositoryException;
+    public Map getRegisteredNamespaces() throws RepositoryException;
 
-    void registerNamespace(String prefix, String uri) throws RepositoryException;
+    public String getPrefix(String uri) throws NamespaceException, RepositoryException;
 
-    void unregisterNamespace(String uri) throws RepositoryException;
+    public String getURI(String prefix) throws NamespaceException, RepositoryException;
+
+    public void registerNamespace(String prefix, String uri) throws NamespaceException, UnsupportedRepositoryOperationException,
AccessDeniedException, RepositoryException;
+
+    public void unregisterNamespace(String uri) throws NamespaceException, UnsupportedRepositoryOperationException,
AccessDeniedException, RepositoryException;
 
 }

Modified: jackrabbit/trunk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/WorkspaceManager.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/WorkspaceManager.java?rev=705937&r1=705936&r2=705937&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/WorkspaceManager.java
(original)
+++ jackrabbit/trunk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/WorkspaceManager.java
Sat Oct 18 16:38:38 2008
@@ -16,102 +16,103 @@
  */
 package org.apache.jackrabbit.jcr2spi;
 
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-
-import javax.jcr.AccessDeniedException;
-import javax.jcr.InvalidItemStateException;
-import javax.jcr.ItemExistsException;
-import javax.jcr.ItemNotFoundException;
-import javax.jcr.MergeException;
-import javax.jcr.NamespaceRegistry;
-import javax.jcr.NoSuchWorkspaceException;
-import javax.jcr.PathNotFoundException;
-import javax.jcr.ReferentialIntegrityException;
-import javax.jcr.RepositoryException;
-import javax.jcr.Session;
-import javax.jcr.UnsupportedRepositoryOperationException;
-import javax.jcr.lock.LockException;
-import javax.jcr.nodetype.ConstraintViolationException;
-import javax.jcr.nodetype.NoSuchNodeTypeException;
-import javax.jcr.query.InvalidQueryException;
-import javax.jcr.version.VersionException;
-
-import org.apache.jackrabbit.jcr2spi.config.CacheBehaviour;
-import org.apache.jackrabbit.jcr2spi.hierarchy.HierarchyEventListener;
-import org.apache.jackrabbit.jcr2spi.hierarchy.HierarchyManager;
-import org.apache.jackrabbit.jcr2spi.hierarchy.HierarchyManagerImpl;
-import org.apache.jackrabbit.jcr2spi.nodetype.EffectiveNodeTypeProvider;
+import org.apache.jackrabbit.jcr2spi.nodetype.NodeTypeRegistryImpl;
+import org.apache.jackrabbit.jcr2spi.nodetype.NodeTypeRegistry;
+import org.apache.jackrabbit.jcr2spi.nodetype.NodeTypeStorage;
 import org.apache.jackrabbit.jcr2spi.nodetype.ItemDefinitionProvider;
 import org.apache.jackrabbit.jcr2spi.nodetype.ItemDefinitionProviderImpl;
+import org.apache.jackrabbit.jcr2spi.nodetype.EffectiveNodeTypeProvider;
 import org.apache.jackrabbit.jcr2spi.nodetype.NodeTypeCache;
-import org.apache.jackrabbit.jcr2spi.nodetype.NodeTypeRegistry;
-import org.apache.jackrabbit.jcr2spi.nodetype.NodeTypeRegistryImpl;
-import org.apache.jackrabbit.jcr2spi.nodetype.NodeTypeStorage;
-import org.apache.jackrabbit.jcr2spi.observation.InternalEventListener;
-import org.apache.jackrabbit.jcr2spi.operation.AddLabel;
+import org.apache.jackrabbit.jcr2spi.state.ItemState;
+import org.apache.jackrabbit.jcr2spi.state.ChangeLog;
+import org.apache.jackrabbit.jcr2spi.state.UpdatableItemStateManager;
+import org.apache.jackrabbit.jcr2spi.state.ItemStateFactory;
+import org.apache.jackrabbit.jcr2spi.state.WorkspaceItemStateFactory;
+import org.apache.jackrabbit.jcr2spi.state.NodeState;
+import org.apache.jackrabbit.jcr2spi.state.TransientItemStateFactory;
+import org.apache.jackrabbit.jcr2spi.state.TransientISFactory;
+import org.apache.jackrabbit.jcr2spi.state.Status;
+import org.apache.jackrabbit.jcr2spi.operation.OperationVisitor;
 import org.apache.jackrabbit.jcr2spi.operation.AddNode;
 import org.apache.jackrabbit.jcr2spi.operation.AddProperty;
-import org.apache.jackrabbit.jcr2spi.operation.Checkin;
-import org.apache.jackrabbit.jcr2spi.operation.Checkout;
 import org.apache.jackrabbit.jcr2spi.operation.Clone;
 import org.apache.jackrabbit.jcr2spi.operation.Copy;
-import org.apache.jackrabbit.jcr2spi.operation.LockOperation;
-import org.apache.jackrabbit.jcr2spi.operation.LockRefresh;
-import org.apache.jackrabbit.jcr2spi.operation.LockRelease;
-import org.apache.jackrabbit.jcr2spi.operation.Merge;
 import org.apache.jackrabbit.jcr2spi.operation.Move;
-import org.apache.jackrabbit.jcr2spi.operation.Operation;
-import org.apache.jackrabbit.jcr2spi.operation.OperationVisitor;
 import org.apache.jackrabbit.jcr2spi.operation.Remove;
-import org.apache.jackrabbit.jcr2spi.operation.RemoveLabel;
-import org.apache.jackrabbit.jcr2spi.operation.RemoveVersion;
-import org.apache.jackrabbit.jcr2spi.operation.ReorderNodes;
-import org.apache.jackrabbit.jcr2spi.operation.ResolveMergeConflict;
-import org.apache.jackrabbit.jcr2spi.operation.Restore;
 import org.apache.jackrabbit.jcr2spi.operation.SetMixin;
 import org.apache.jackrabbit.jcr2spi.operation.SetPropertyValue;
+import org.apache.jackrabbit.jcr2spi.operation.ReorderNodes;
+import org.apache.jackrabbit.jcr2spi.operation.Operation;
+import org.apache.jackrabbit.jcr2spi.operation.Checkout;
+import org.apache.jackrabbit.jcr2spi.operation.Checkin;
 import org.apache.jackrabbit.jcr2spi.operation.Update;
+import org.apache.jackrabbit.jcr2spi.operation.Restore;
+import org.apache.jackrabbit.jcr2spi.operation.ResolveMergeConflict;
+import org.apache.jackrabbit.jcr2spi.operation.Merge;
+import org.apache.jackrabbit.jcr2spi.operation.LockOperation;
+import org.apache.jackrabbit.jcr2spi.operation.LockRefresh;
+import org.apache.jackrabbit.jcr2spi.operation.LockRelease;
+import org.apache.jackrabbit.jcr2spi.operation.AddLabel;
+import org.apache.jackrabbit.jcr2spi.operation.RemoveLabel;
+import org.apache.jackrabbit.jcr2spi.operation.RemoveVersion;
 import org.apache.jackrabbit.jcr2spi.operation.WorkspaceImport;
 import org.apache.jackrabbit.jcr2spi.security.AccessManager;
-import org.apache.jackrabbit.jcr2spi.state.ChangeLog;
-import org.apache.jackrabbit.jcr2spi.state.ItemState;
-import org.apache.jackrabbit.jcr2spi.state.ItemStateFactory;
-import org.apache.jackrabbit.jcr2spi.state.NodeState;
-import org.apache.jackrabbit.jcr2spi.state.Status;
-import org.apache.jackrabbit.jcr2spi.state.TransientISFactory;
-import org.apache.jackrabbit.jcr2spi.state.TransientItemStateFactory;
-import org.apache.jackrabbit.jcr2spi.state.UpdatableItemStateManager;
-import org.apache.jackrabbit.jcr2spi.state.WorkspaceItemStateFactory;
-import org.apache.jackrabbit.spi.Batch;
-import org.apache.jackrabbit.spi.Event;
-import org.apache.jackrabbit.spi.EventBundle;
-import org.apache.jackrabbit.spi.EventFilter;
-import org.apache.jackrabbit.spi.IdFactory;
-import org.apache.jackrabbit.spi.ItemId;
-import org.apache.jackrabbit.spi.LockInfo;
+import org.apache.jackrabbit.jcr2spi.observation.InternalEventListener;
+import org.apache.jackrabbit.jcr2spi.config.CacheBehaviour;
+import org.apache.jackrabbit.jcr2spi.hierarchy.HierarchyEventListener;
+import org.apache.jackrabbit.jcr2spi.hierarchy.HierarchyManager;
+import org.apache.jackrabbit.jcr2spi.hierarchy.HierarchyManagerImpl;
+import org.apache.jackrabbit.spi.Path;
 import org.apache.jackrabbit.spi.Name;
-import org.apache.jackrabbit.spi.NameFactory;
+import org.apache.jackrabbit.spi.RepositoryService;
+import org.apache.jackrabbit.spi.SessionInfo;
 import org.apache.jackrabbit.spi.NodeId;
-import org.apache.jackrabbit.spi.Path;
-import org.apache.jackrabbit.spi.PathFactory;
+import org.apache.jackrabbit.spi.IdFactory;
+import org.apache.jackrabbit.spi.LockInfo;
+import org.apache.jackrabbit.spi.QueryInfo;
+import org.apache.jackrabbit.spi.ItemId;
 import org.apache.jackrabbit.spi.PropertyId;
+import org.apache.jackrabbit.spi.Batch;
+import org.apache.jackrabbit.spi.EventBundle;
+import org.apache.jackrabbit.spi.EventFilter;
 import org.apache.jackrabbit.spi.QNodeTypeDefinition;
 import org.apache.jackrabbit.spi.QValue;
-import org.apache.jackrabbit.spi.QueryInfo;
-import org.apache.jackrabbit.spi.RepositoryService;
-import org.apache.jackrabbit.spi.SessionInfo;
+import org.apache.jackrabbit.spi.Event;
+import org.apache.jackrabbit.spi.NameFactory;
+import org.apache.jackrabbit.spi.PathFactory;
 import org.apache.jackrabbit.spi.Subscription;
-import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
+import org.slf4j.Logger;
+
+import javax.jcr.RepositoryException;
+import javax.jcr.NamespaceRegistry;
+import javax.jcr.UnsupportedRepositoryOperationException;
+import javax.jcr.AccessDeniedException;
+import javax.jcr.PathNotFoundException;
+import javax.jcr.ItemNotFoundException;
+import javax.jcr.NamespaceException;
+import javax.jcr.NoSuchWorkspaceException;
+import javax.jcr.ItemExistsException;
+import javax.jcr.InvalidItemStateException;
+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;
+import javax.jcr.nodetype.ConstraintViolationException;
+
+import java.util.List;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.Set;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Collection;
 
-import EDU.oswego.cs.dl.util.concurrent.Mutex;
 import EDU.oswego.cs.dl.util.concurrent.Sync;
+import EDU.oswego.cs.dl.util.concurrent.Mutex;
 
 /**
  * <code>WorkspaceManager</code>...
@@ -630,16 +631,28 @@
     /**
      * @inheritDoc
      */
-    public void registerNamespace(String prefix, String uri)
-            throws RepositoryException {
+    public String getPrefix(String uri) throws NamespaceException, RepositoryException {
+        return service.getNamespacePrefix(sessionInfo, uri);
+    }
+
+    /**
+     * @inheritDoc
+     */
+    public String getURI(String prefix) throws NamespaceException, RepositoryException {
+        return service.getNamespaceURI(sessionInfo, prefix);
+    }
+
+    /**
+     * @inheritDoc
+     */
+    public void registerNamespace(String prefix, String uri) throws NamespaceException, UnsupportedRepositoryOperationException,
AccessDeniedException, RepositoryException {
         service.registerNamespace(sessionInfo, prefix, uri);
     }
 
     /**
      * @inheritDoc
      */
-    public void unregisterNamespace(String uri)
-            throws RepositoryException {
+    public void unregisterNamespace(String uri) throws NamespaceException, UnsupportedRepositoryOperationException,
AccessDeniedException, RepositoryException {
         service.unregisterNamespace(sessionInfo, uri);
     }
 



Mime
View raw message