jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ju...@apache.org
Subject svn commit: r1387053 - in /jackrabbit/oak/trunk: oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/name/ oak-core/src/main/java/org/apache/jackrabbit/oak/security/privilege/ oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/name/ oak-jcr/...
Date Tue, 18 Sep 2012 08:45:20 GMT
Author: jukka
Date: Tue Sep 18 08:45:20 2012
New Revision: 1387053

URL: http://svn.apache.org/viewvc?rev=1387053&view=rev
Log:
OAK-306: Limit session refresh on namespace registry use

Modified:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/name/NamespaceRegistryImpl.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/privilege/PrivilegeMigrator.java
    jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/name/NamespaceRegistryImplTest.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=1387053&r1=1387052&r2=1387053&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
Tue Sep 18 08:45:20 2012
@@ -26,7 +26,7 @@ import javax.jcr.RepositoryException;
 
 import org.apache.jackrabbit.JcrConstants;
 import org.apache.jackrabbit.oak.api.CommitFailedException;
-import org.apache.jackrabbit.oak.api.ContentSession;
+import org.apache.jackrabbit.oak.plugins.memory.StringValue;
 import org.apache.jackrabbit.oak.api.Root;
 import org.apache.jackrabbit.oak.api.Tree;
 import org.apache.jackrabbit.oak.core.DefaultConflictHandler;
@@ -34,13 +34,12 @@ import org.apache.jackrabbit.oak.core.De
 /**
  * Implementation of {@link NamespaceRegistry}.
  */
-public class NamespaceRegistryImpl implements NamespaceRegistry, NamespaceConstants {
+public abstract class NamespaceRegistryImpl
+        implements NamespaceRegistry, NamespaceConstants {
 
-    private final ContentSession session;
+    abstract protected Root getReadRoot();
 
-    public NamespaceRegistryImpl(ContentSession session) {
-        this.session = session;
-    }
+    abstract protected Root getWriteRoot();
 
     /**
      * Called by the {@link NamespaceRegistry} implementation methods to
@@ -59,10 +58,9 @@ public class NamespaceRegistryImpl imple
     public void registerNamespace(String prefix, String uri)
             throws RepositoryException {
         try {
-            Root root = session.getLatestRoot();
+            Root root = getWriteRoot();
             Tree namespaces = getOrCreate(root, JcrConstants.JCR_SYSTEM, REP_NAMESPACES);
-            namespaces.setProperty(
-                    prefix, session.getCoreValueFactory().createValue(uri));
+            namespaces.setProperty(prefix, new StringValue(uri));
             root.commit(DefaultConflictHandler.OURS);
             refresh();
         } catch (NamespaceValidatorException e) {
@@ -76,7 +74,7 @@ public class NamespaceRegistryImpl imple
 
     @Override
     public void unregisterNamespace(String prefix) throws RepositoryException {
-        Root root = session.getLatestRoot();
+        Root root = getWriteRoot();
         Tree namespaces = root.getTree(NAMESPACES_PATH);
         if (namespaces == null || !namespaces.hasProperty(prefix)) {
             throw new NamespaceException(
@@ -114,11 +112,10 @@ public class NamespaceRegistryImpl imple
     @Nonnull
     public String[] getPrefixes() throws RepositoryException {
         try {
-            Tree root = session.getLatestRoot().getTree("/");
+            Tree root = getReadRoot().getTree("/");
             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(
@@ -130,11 +127,10 @@ public class NamespaceRegistryImpl imple
     @Nonnull
     public String[] getURIs() throws RepositoryException {
         try {
-            Tree root = session.getLatestRoot().getTree("/");
+            Tree root = getReadRoot().getTree("/");
             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(
@@ -146,14 +142,13 @@ public class NamespaceRegistryImpl imple
     @Nonnull
     public String getURI(String prefix) throws RepositoryException {
         try {
-            Tree root = session.getLatestRoot().getTree("/");
+            Tree root = getReadRoot().getTree("/");
             Map<String, String> map = Namespaces.getNamespaceMap(root);
             String uri = map.get(prefix);
             if (uri == null) {
                 throw new NamespaceException(
                         "No namespace registered for prefix " + prefix);
             }
-            refresh();
             return uri;
         } catch (RuntimeException e) {
             throw new RepositoryException(
@@ -166,11 +161,10 @@ public class NamespaceRegistryImpl imple
     @Nonnull
     public String getPrefix(String uri) throws RepositoryException {
         try {
-            Tree root = session.getLatestRoot().getTree("/");
+            Tree root = getReadRoot().getTree("/");
             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-core/src/main/java/org/apache/jackrabbit/oak/security/privilege/PrivilegeMigrator.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/privilege/PrivilegeMigrator.java?rev=1387053&r1=1387052&r2=1387053&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/privilege/PrivilegeMigrator.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/privilege/PrivilegeMigrator.java
Tue Sep 18 08:45:20 2012
@@ -22,8 +22,8 @@ import javax.jcr.NamespaceRegistry;
 import javax.jcr.RepositoryException;
 
 import org.apache.jackrabbit.oak.api.ContentSession;
-import org.apache.jackrabbit.oak.plugins.name.NamespaceRegistryImpl;
 import org.apache.jackrabbit.oak.spi.security.privilege.PrivilegeDefinition;
+import org.apache.jackrabbit.oak.util.TODO;
 
 /**
  * PrivilegeMigrator is a utility to migrate custom privilege definitions from
@@ -50,7 +50,9 @@ public class PrivilegeMigrator {
         // new FileSystemResource(fs, "/privileges/custom_privileges.xml").getInputStream()
         if (stream != null) {
             try {
-                NamespaceRegistry nsRegistry = new NamespaceRegistryImpl(contentSession);
+                // TODO: should get a proper namespace registry from somewhere
+                NamespaceRegistry nsRegistry =
+                        TODO.dummyImplementation().returnValue(null);
                 PrivilegeDefinition[] custom = PrivilegeDefinitionReader.readCustomDefinitons(stream,
nsRegistry);
 
                 for (PrivilegeDefinition def : custom) {

Modified: jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/name/NamespaceRegistryImplTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/name/NamespaceRegistryImplTest.java?rev=1387053&r1=1387052&r2=1387053&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/name/NamespaceRegistryImplTest.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/name/NamespaceRegistryImplTest.java
Tue Sep 18 08:45:20 2012
@@ -21,6 +21,7 @@ import javax.jcr.NamespaceRegistry;
 import org.apache.jackrabbit.oak.AbstractOakTest;
 import org.apache.jackrabbit.oak.api.ContentRepository;
 import org.apache.jackrabbit.oak.api.ContentSession;
+import org.apache.jackrabbit.oak.api.Root;
 import org.junit.Test;
 
 import static org.junit.Assert.assertEquals;
@@ -34,8 +35,17 @@ public class NamespaceRegistryImplTest e
 
     @Test
     public void testMappings() throws Exception {
-        ContentSession session = createAdminSession();
-        NamespaceRegistry r = new NamespaceRegistryImpl(session);
+        final ContentSession session = createAdminSession();
+        NamespaceRegistry r = new NamespaceRegistryImpl() {
+            @Override
+            protected Root getReadRoot() {
+                return session.getLatestRoot();
+            }
+            @Override
+            protected Root getWriteRoot() {
+                return session.getLatestRoot();
+            }
+        };
 
         assertEquals("", r.getURI(""));
         assertEquals("http://www.jcp.org/jcr/1.0", r.getURI("jcr"));

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=1387053&r1=1387052&r2=1387053&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
Tue Sep 18 08:45:20 2012
@@ -32,6 +32,7 @@ import javax.jcr.version.VersionManager;
 
 import org.apache.jackrabbit.api.JackrabbitWorkspace;
 import org.apache.jackrabbit.api.security.authorization.PrivilegeManager;
+import org.apache.jackrabbit.oak.api.Root;
 import org.apache.jackrabbit.oak.commons.PathUtils;
 import org.apache.jackrabbit.oak.jcr.lock.LockManagerImpl;
 import org.apache.jackrabbit.oak.jcr.query.QueryManagerImpl;
@@ -145,11 +146,19 @@ public class WorkspaceImpl implements Ja
 
     @Override
     public NamespaceRegistry getNamespaceRegistry() {
-        return new NamespaceRegistryImpl(sessionDelegate.getContentSession()) {
+        return new NamespaceRegistryImpl() {
             @Override
             protected void refresh() throws RepositoryException {
                 getSession().refresh(true);
             }
+            @Override
+            protected Root getReadRoot() {
+                return sessionDelegate.getRoot();
+            }
+            @Override
+            protected Root getWriteRoot() {
+                return sessionDelegate.getContentSession().getLatestRoot();
+            }
         };
     }
 



Mime
View raw message