jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mreut...@apache.org
Subject svn commit: r1387537 - in /jackrabbit/oak/trunk: oak-core/src/main/java/org/apache/jackrabbit/oak/core/ oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/type/ oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/
Date Wed, 19 Sep 2012 12:05:37 GMT
Author: mreutegg
Date: Wed Sep 19 12:05:37 2012
New Revision: 1387537

URL: http://svn.apache.org/viewvc?rev=1387537&view=rev
Log:
OAK-312: Use stable root from session in NodeTypeManagerImpl

Modified:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/ContentSessionImpl.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/type/AbstractNodeTypeManager.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/type/NodeTypeManagerImpl.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/core/ContentSessionImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/ContentSessionImpl.java?rev=1387537&r1=1387536&r2=1387537&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/ContentSessionImpl.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/ContentSessionImpl.java
Wed Sep 19 12:05:37 2012
@@ -78,7 +78,7 @@ class ContentSessionImpl implements Cont
         synchronized (this) {
             if (!initialised) {
                 initialised = true;
-                NodeTypeManagerImpl.registerBuiltInNodeTypes(this);
+                NodeTypeManagerImpl.registerBuiltInNodeTypes(getLatestRoot());
             }
         }
 

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/type/AbstractNodeTypeManager.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/type/AbstractNodeTypeManager.java?rev=1387537&r1=1387536&r2=1387537&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/type/AbstractNodeTypeManager.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/type/AbstractNodeTypeManager.java
Wed Sep 19 12:05:37 2012
@@ -35,12 +35,19 @@ import javax.jcr.nodetype.PropertyDefini
 import com.google.common.collect.Lists;
 import org.apache.jackrabbit.commons.iterator.NodeTypeIteratorAdapter;
 import org.apache.jackrabbit.oak.api.CoreValueFactory;
+import org.apache.jackrabbit.oak.api.Root;
 import org.apache.jackrabbit.oak.api.Tree;
 import org.apache.jackrabbit.oak.namepath.NameMapper;
 import org.apache.jackrabbit.oak.namepath.NamePathMapperImpl;
 import org.apache.jackrabbit.oak.plugins.memory.MemoryValueFactory;
 import org.apache.jackrabbit.oak.util.NodeUtil;
 
+/**
+ * Base implementation of a {@link NodeTypeManager} with support for reading
+ * node types from the {@link Tree} returned by {@link #getTypes()}. Methods
+ * related to node type modifications throw
+ * {@link UnsupportedRepositoryOperationException}.
+ */
 public abstract class AbstractNodeTypeManager implements NodeTypeManager {
 
     /**
@@ -88,11 +95,27 @@ public abstract class AbstractNodeTypeMa
         return null;
     }
 
+    /**
+     * Returns a {@link CoreValueFactory} to be used by this node type manager.
+     * This implementation returns a {@link MemoryValueFactory#INSTANCE}. A
+     * subclass may override this method and provide a different
+     * implementation.
+     *
+     * @return {@link CoreValueFactory} instance.
+     */
     @Nonnull
     protected CoreValueFactory getCoreValueFactory() {
         return MemoryValueFactory.INSTANCE;
     }
 
+    /**
+     * Returns a {@link NameMapper} to be used by this node type manager. This
+     * implementation returns the {@link NamePathMapperImpl#DEFAULT} instance. A
+     * subclass may override this method and provide a different
+     * implementation.
+     *
+     * @return {@link NameMapper} instance.
+     */
     @Nonnull
     protected NameMapper getNameMapper() {
         return NamePathMapperImpl.DEFAULT;
@@ -179,21 +202,33 @@ public abstract class AbstractNodeTypeMa
         return new PropertyDefinitionTemplateImpl(getNameMapper());
     }
 
+    /**
+     * This implementation always throws a {@link UnsupportedRepositoryOperationException}.
+     */
     @Override
     public NodeType registerNodeType(NodeTypeDefinition ntd, boolean allowUpdate) throws
RepositoryException {
         throw new UnsupportedRepositoryOperationException();
     }
 
+    /**
+     * This implementation always throws a {@link UnsupportedRepositoryOperationException}.
+     */
     @Override
     public NodeTypeIterator registerNodeTypes(NodeTypeDefinition[] ntds, boolean allowUpdate)
throws RepositoryException {
         throw new UnsupportedRepositoryOperationException();
     }
 
+    /**
+     * This implementation always throws a {@link UnsupportedRepositoryOperationException}.
+     */
     @Override
     public void unregisterNodeType(String name) throws RepositoryException {
         throw new UnsupportedRepositoryOperationException();
     }
 
+    /**
+     * This implementation always throws a {@link UnsupportedRepositoryOperationException}.
+     */
     @Override
     public void unregisterNodeTypes(String[] names) throws RepositoryException {
         throw new UnsupportedRepositoryOperationException();

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/type/NodeTypeManagerImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/type/NodeTypeManagerImpl.java?rev=1387537&r1=1387536&r2=1387537&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/type/NodeTypeManagerImpl.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/type/NodeTypeManagerImpl.java
Wed Sep 19 12:05:37 2012
@@ -22,10 +22,10 @@ import java.security.PrivilegedAction;
 import java.util.List;
 import java.util.Map;
 
+import javax.annotation.Nonnull;
 import javax.jcr.PropertyType;
 import javax.jcr.RepositoryException;
 import javax.jcr.Value;
-import javax.jcr.ValueFactory;
 import javax.jcr.nodetype.ItemDefinition;
 import javax.jcr.nodetype.NoSuchNodeTypeException;
 import javax.jcr.nodetype.NodeDefinition;
@@ -44,14 +44,9 @@ import org.apache.jackrabbit.commons.cnd
 import org.apache.jackrabbit.commons.cnd.ParseException;
 import org.apache.jackrabbit.commons.iterator.NodeTypeIteratorAdapter;
 import org.apache.jackrabbit.oak.api.CommitFailedException;
-import org.apache.jackrabbit.oak.api.ContentSession;
-import org.apache.jackrabbit.oak.api.CoreValueFactory;
 import org.apache.jackrabbit.oak.api.Root;
 import org.apache.jackrabbit.oak.api.Tree;
 import org.apache.jackrabbit.oak.core.DefaultConflictHandler;
-import org.apache.jackrabbit.oak.namepath.NameMapper;
-import org.apache.jackrabbit.oak.namepath.NamePathMapper;
-import org.apache.jackrabbit.oak.namepath.NamePathMapperImpl;
 import org.apache.jackrabbit.oak.spi.security.principal.AdminPrincipal;
 import org.apache.jackrabbit.oak.util.NodeUtil;
 
@@ -88,22 +83,68 @@ import static org.apache.jackrabbit.oak.
 import static org.apache.jackrabbit.oak.plugins.type.NodeTypeConstants.JCR_NODE_TYPES;
 import static org.apache.jackrabbit.oak.plugins.type.NodeTypeConstants.NODE_TYPES_PATH;
 
-public class NodeTypeManagerImpl extends AbstractNodeTypeManager {
+/**
+ * <code>NodeTypeManagerImpl</code> extends the {@link AbstractNodeTypeManager}
+ * and add support for operations that modify node types:
+ * <ul>
+ *     <li>{@link #registerNodeType(NodeTypeDefinition, boolean)}</li>
+ *     <li>{@link #registerNodeTypes(NodeTypeDefinition[], boolean)}</li>
+ *     <li>{@link #unregisterNodeType(String)}</li>
+ *     <li>{@link #unregisterNodeTypes(String[])}</li>
+ * </ul>
+ * Calling any of the above methods will result in a {@link #refresh()} callback
+ * to e.g. inform an associated session that it should refresh to make the
+ * changes visible.
+ * </p>
+ * Subclass responsibility is to provide an implementation of
+ * {@link #getTypes()} for read only access to the tree where node types are
+ * stored in content and {@link #getWriteRoot()} for write access to the
+ * repository in order to modify node types stored in content. A subclass may
+ * also want to override the default implementation of
+ * {@link AbstractNodeTypeManager} for the following methods:
+ * <ul>
+ *     <li>{@link #getValueFactory()}</li>
+ *     <li>{@link #getCoreValueFactory()}</li>
+ *     <li>{@link #getNameMapper()}</li>
+ * </ul>
+ */
+public abstract class NodeTypeManagerImpl extends AbstractNodeTypeManager {
 
-    private final ContentSession session;
-
-    private final NamePathMapper mapper;
-
-    private final ValueFactory factory;
-
-    public NodeTypeManagerImpl(ContentSession session, NamePathMapper mapper, ValueFactory
factory) {
-        this.session = session;
-        this.mapper = mapper;
-        this.factory = factory;
+    /**
+     * Called by the methods {@link #registerNodeType(NodeTypeDefinition,boolean)},
+     * {@link #registerNodeTypes(NodeTypeDefinition[], boolean)},
+     * {@link #unregisterNodeType(String)} and {@link #unregisterNodeTypes(String[])}
+     * to acquire a fresh {@link Root} instance that can be used to persist the
+     * requested node type changes (and nothing else).
+     * <p/>
+     * This default implementation throws an {@link UnsupportedOperationException}.
+     *
+     * @return fresh {@link Root} instance.
+     */
+    @Nonnull
+    protected Root getWriteRoot() {
+        throw new UnsupportedOperationException();
     }
 
-    public static void registerBuiltInNodeTypes(ContentSession session) {
-        new NodeTypeManagerImpl(session, NamePathMapperImpl.DEFAULT, null).registerBuiltinNodeTypes();
+    /**
+     * Registers built in node types using the given {@link Root}.
+     *
+     * @param root the {@link Root} instance.
+     */
+    public static void registerBuiltInNodeTypes(final Root root) {
+        NodeTypeManagerImpl ntMgr = new NodeTypeManagerImpl() {
+            @Override
+            protected Tree getTypes() {
+                return root.getTree(NODE_TYPES_PATH);
+            }
+
+            @Nonnull
+            @Override
+            protected Root getWriteRoot() {
+                return root;
+            }
+        };
+        ntMgr.registerBuiltinNodeTypes();
     }
 
     private void registerBuiltinNodeTypes() {
@@ -144,7 +185,7 @@ public class NodeTypeManagerImpl extends
     public void registerNodeTypes(InputStreamReader cnd) throws ParseException, RepositoryException
{
         CompactNodeTypeDefReader<NodeTypeTemplate, Map<String, String>> reader
=
                 new CompactNodeTypeDefReader<NodeTypeTemplate, Map<String, String>>(
-                        cnd, null, new DefBuilderFactory(mapper));
+                        cnd, null, new DefBuilderFactory(getNameMapper()));
         Map<String, NodeTypeTemplate> templates = Maps.newHashMap();
         for (NodeTypeTemplate template : reader.getNodeTypeDefinitions()) {
             templates.put(template.getName(), template);
@@ -181,36 +222,17 @@ public class NodeTypeManagerImpl extends
         registerNodeTypes(templates.values().toArray(new NodeTypeTemplate[templates.size()]),
true);
     }
 
-    @Override
-    protected Tree getTypes() {
-        return session.getLatestRoot().getTree(NODE_TYPES_PATH);
-    }
-
-    @Override
-    protected ValueFactory getValueFactory() {
-        return factory;
-    }
-
-    @Override
-    protected CoreValueFactory getCoreValueFactory() {
-        return session.getCoreValueFactory();
-    }
-
-    @Override
-    protected NameMapper getNameMapper() {
-        return mapper;
-    }
-
     //----------------------------------------------------< NodeTypeManager >---
 
     @Override
     public NodeType registerNodeType(NodeTypeDefinition ntd, boolean allowUpdate) throws
RepositoryException {
         // TODO proper node type registration... (OAK-66)
-        Root root = session.getLatestRoot();
+        Root root = getWriteRoot();
         Tree types = getOrCreateNodeTypes(root);
         try {
             NodeType type = internalRegister(types, ntd, allowUpdate);
             root.commit(DefaultConflictHandler.OURS);
+            refresh();
             return type;
         } catch (CommitFailedException e) {
             throw new RepositoryException(e);
@@ -221,7 +243,7 @@ public class NodeTypeManagerImpl extends
     public final NodeTypeIterator registerNodeTypes(NodeTypeDefinition[] ntds, boolean allowUpdate)
             throws RepositoryException {
         // TODO handle inter-type dependencies (OAK-66)
-        Root root = session.getLatestRoot();
+        Root root = getWriteRoot();
         Tree types = getOrCreateNodeTypes(root);
         try {
             List<NodeType> list = Lists.newArrayList();
@@ -229,6 +251,7 @@ public class NodeTypeManagerImpl extends
                 list.add(internalRegister(types, ntd, allowUpdate));
             }
             root.commit(DefaultConflictHandler.OURS);
+            refresh();
             return new NodeTypeIteratorAdapter(list);
         } catch (CommitFailedException e) {
             throw new RepositoryException(e);
@@ -252,7 +275,7 @@ public class NodeTypeManagerImpl extends
         }
         type = types.addChild(oakName);
 
-        NodeUtil node = new NodeUtil(type, getCoreValueFactory(), mapper);
+        NodeUtil node = new NodeUtil(type, getCoreValueFactory(), getNameMapper());
         node.setName(JCR_PRIMARYTYPE, NT_NODETYPE);
         node.setName(JCR_NODETYPENAME, jcrName);
         node.setNames(JCR_SUPERTYPES, ntd.getDeclaredSupertypeNames());
@@ -288,7 +311,7 @@ public class NodeTypeManagerImpl extends
             }
         }
 
-        return new NodeTypeImpl(this, this.factory, node);
+        return new NodeTypeImpl(this, getValueFactory(), node);
     }
 
     private static void internalRegisterItemDefinition(
@@ -356,15 +379,14 @@ public class NodeTypeManagerImpl extends
     }
 
     private boolean nodeTypesInContent() {
-        Root currentRoot = session.getLatestRoot();
-        Tree types = currentRoot.getTree(NODE_TYPES_PATH);
+        Tree types = getTypes();
         return types != null && types.getChildrenCount() > 0;
     }
 
     @Override
     public void unregisterNodeType(String name) throws RepositoryException {
         Tree type = null;
-        Root root = session.getLatestRoot();
+        Root root = getWriteRoot();
         Tree types = root.getTree(NODE_TYPES_PATH);
         if (types != null) {
             type = types.getChild(getOakName(name));
@@ -384,7 +406,7 @@ public class NodeTypeManagerImpl extends
 
     @Override
     public void unregisterNodeTypes(String[] names) throws RepositoryException {
-        Root root = session.getLatestRoot();
+        Root root = getWriteRoot();
         Tree types = root.getTree(NODE_TYPES_PATH);
         if (types == null) {
             throw new NoSuchNodeTypeException("Node types can not be unregistered.");

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=1387537&r1=1387536&r2=1387537&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
Wed Sep 19 12:05:37 2012
@@ -19,10 +19,12 @@ package org.apache.jackrabbit.oak.jcr;
 import java.io.IOException;
 import java.io.InputStream;
 
+import javax.annotation.Nonnull;
 import javax.jcr.NamespaceRegistry;
 import javax.jcr.RepositoryException;
 import javax.jcr.Session;
 import javax.jcr.UnsupportedRepositoryOperationException;
+import javax.jcr.ValueFactory;
 import javax.jcr.lock.LockManager;
 import javax.jcr.nodetype.NodeTypeManager;
 import javax.jcr.observation.ObservationManager;
@@ -32,6 +34,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.CoreValueFactory;
 import org.apache.jackrabbit.oak.api.Root;
 import org.apache.jackrabbit.oak.api.Tree;
 import org.apache.jackrabbit.oak.commons.PathUtils;
@@ -39,6 +42,7 @@ import org.apache.jackrabbit.oak.jcr.loc
 import org.apache.jackrabbit.oak.jcr.query.QueryManagerImpl;
 import org.apache.jackrabbit.oak.jcr.security.privilege.PrivilegeManagerImpl;
 import org.apache.jackrabbit.oak.jcr.version.VersionManagerImpl;
+import org.apache.jackrabbit.oak.namepath.NameMapper;
 import org.apache.jackrabbit.oak.plugins.name.NamespaceRegistryImpl;
 import org.apache.jackrabbit.oak.plugins.type.NodeTypeManagerImpl;
 import org.slf4j.Logger;
@@ -46,6 +50,8 @@ import org.slf4j.LoggerFactory;
 import org.xml.sax.ContentHandler;
 import org.xml.sax.InputSource;
 
+import static org.apache.jackrabbit.oak.plugins.type.NodeTypeConstants.NODE_TYPES_PATH;
+
 /**
  * {@code WorkspaceImpl}...
  */
@@ -165,14 +171,39 @@ public class WorkspaceImpl implements Ja
 
     @Override
     public NodeTypeManager getNodeTypeManager() {
-        return new NodeTypeManagerImpl(
-                sessionDelegate.getContentSession(),
-                sessionDelegate.getNamePathMapper(),
-                sessionDelegate.getValueFactory()) {
+        return new NodeTypeManagerImpl() {
             @Override
             protected void refresh() throws RepositoryException {
                 getSession().refresh(true);
             }
+
+            @Override
+            protected Tree getTypes() {
+                return sessionDelegate.getRoot().getTree(NODE_TYPES_PATH);
+            }
+
+            @Nonnull
+            @Override
+            protected Root getWriteRoot() {
+                return sessionDelegate.getContentSession().getLatestRoot();
+            }
+
+            @Nonnull
+            @Override
+            protected CoreValueFactory getCoreValueFactory() {
+                return sessionDelegate.getContentSession().getCoreValueFactory();
+            }
+
+            @Override
+            protected ValueFactory getValueFactory() {
+                return sessionDelegate.getValueFactory();
+            }
+
+            @Nonnull
+            @Override
+            protected NameMapper getNameMapper() {
+                return sessionDelegate.getNamePathMapper();
+            }
         };
     }
 



Mime
View raw message