You are viewing a plain text version of this content. The canonical link for it is here.
Posted to oak-commits@jackrabbit.apache.org by ju...@apache.org on 2012/06/22 16:27:07 UTC

svn commit: r1352901 - in /jackrabbit/oak/trunk: oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/name/NamespaceRegistryImpl.java oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/WorkspaceImpl.java

Author: jukka
Date: Fri Jun 22 14:27:06 2012
New Revision: 1352901

URL: http://svn.apache.org/viewvc?rev=1352901&view=rev
Log:
OAK-149: Automatic session refresh after namespace registry changes

Refresh the associated session after all namespace registry accesses, read as well as write.

Modified:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/name/NamespaceRegistryImpl.java
    jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/WorkspaceImpl.java

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/name/NamespaceRegistryImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/name/NamespaceRegistryImpl.java?rev=1352901&r1=1352900&r2=1352901&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/name/NamespaceRegistryImpl.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/name/NamespaceRegistryImpl.java Fri Jun 22 14:27:06 2012
@@ -41,6 +41,17 @@ public class NamespaceRegistryImpl imple
         this.session = session;
     }
 
+    /**
+     * Called by the {@link NamespaceRegistry} implementation methods to
+     * refresh the state of the session associated with this instance.
+     * That way the session is kept in sync with the latest global state
+     * seen by the namespace registry.
+     *
+     * @throws RepositoryException if the session could not be refreshed
+     */
+    protected void refresh() throws RepositoryException {
+    }
+
     //--------------------------------------------------< NamespaceRegistry >---
 
     @Override
@@ -52,6 +63,7 @@ public class NamespaceRegistryImpl imple
             namespaces.setProperty(
                     prefix, session.getCoreValueFactory().createValue(uri));
             root.commit(DefaultConflictHandler.OURS);
+            refresh();
         } catch (NamespaceValidatorException e) {
             throw e.getNamespaceException();
         } catch (CommitFailedException e) {
@@ -74,6 +86,7 @@ public class NamespaceRegistryImpl imple
                         + getURI(prefix) + " can not be unregistered");
             }
             root.commit(DefaultConflictHandler.OURS);
+            refresh();
         } catch (NamespaceValidatorException e) {
             throw e.getNamespaceException();
         } catch (CommitFailedException e) {
@@ -104,6 +117,7 @@ public class NamespaceRegistryImpl imple
             Map<String, String> map = Namespaces.getNamespaceMap(root);
             String[] prefixes = map.keySet().toArray(new String[map.size()]);
             Arrays.sort(prefixes);
+            refresh();
             return prefixes;
         } catch (RuntimeException e) {
             throw new RepositoryException(
@@ -119,6 +133,7 @@ public class NamespaceRegistryImpl imple
             Map<String, String> map = Namespaces.getNamespaceMap(root);
             String[] uris = map.values().toArray(new String[map.size()]);
             Arrays.sort(uris);
+            refresh();
             return uris;
         } catch (RuntimeException e) {
             throw new RepositoryException(
@@ -137,6 +152,7 @@ public class NamespaceRegistryImpl imple
                 throw new NamespaceException(
                         "No namespace registered for prefix " + prefix);
             }
+            refresh();
             return uri;
         } catch (RuntimeException e) {
             throw new RepositoryException(
@@ -153,6 +169,7 @@ public class NamespaceRegistryImpl imple
             Map<String, String> map = Namespaces.getNamespaceMap(root);
             for (Map.Entry<String, String> entry : map.entrySet()) {
                 if (entry.getValue().equals(uri)) {
+                    refresh();
                     return entry.getKey();
                 }
             }

Modified: jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/WorkspaceImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/WorkspaceImpl.java?rev=1352901&r1=1352900&r2=1352901&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/WorkspaceImpl.java (original)
+++ jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/WorkspaceImpl.java Fri Jun 22 14:27:06 2012
@@ -148,7 +148,12 @@ public class WorkspaceImpl implements Ja
 
     @Override
     public NamespaceRegistry getNamespaceRegistry() {
-        return new NamespaceRegistryImpl(sessionDelegate.getContentSession());
+        return new NamespaceRegistryImpl(sessionDelegate.getContentSession()) {
+            @Override
+            protected void refresh() throws RepositoryException {
+                getSession().refresh(true);
+            }
+        };
     }
 
     @Override