jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mreut...@apache.org
Subject svn commit: r469480 - in /jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core: NodeImpl.java RepositoryImpl.java state/SharedItemStateManager.java
Date Tue, 31 Oct 2006 13:48:23 GMT
Author: mreutegg
Date: Tue Oct 31 05:48:22 2006
New Revision: 469480

URL: http://svn.apache.org/viewvc?view=rev&rev=469480
Log:
JCR-605: Error when registering node types on virgin repository
- centralized workspace initialization code in SharedItemStateManager. The jcr:system node
is now created within the same method as the root node of the workspace: SharedItemStateManager.createRootNodeState()

Modified:
    jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/NodeImpl.java
    jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/RepositoryImpl.java
    jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/state/SharedItemStateManager.java

Modified: jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/NodeImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/NodeImpl.java?view=diff&rev=469480&r1=469479&r2=469480
==============================================================================
--- jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/NodeImpl.java (original)
+++ jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/NodeImpl.java Tue
Oct 31 05:48:22 2006
@@ -809,94 +809,6 @@
         return createChildNode(nodeName, def, nodeType, id);
     }
 
-    /**
-     * Adds a child node entry for a virtual node state to this node. E.g. the
-     * node <code>/jcr:system/jcr:versionStorage</code>.
-     *
-     * @param nodeName the name of the virtual child node.
-     * @param nodeType the node type of the virtual child node.
-     * @param id       the id of the virtual node state.
-     * @return the <code>NodeImpl</code> for the virtual node state with
-     *         <code>id</code>.
-     * @throws ItemExistsException          if there already exists a child node
-     *                                      entry with the given <code>nodeName</code>.
-     * @throws ConstraintViolationException if this node does not allow a child
-     *                                      node with the specified <code>nodeType</code>
-     *                                      and <code>nodeName</code>.
-     * @throws RepositoryException          if there is no virtual node state
-     *                                      with <code>id</code>.
-     */
-    protected NodeImpl internalAddVirtualChildNode(QName nodeName,
-                                                   NodeTypeImpl nodeType,
-                                                   NodeId id)
-            throws ItemExistsException, ConstraintViolationException, RepositoryException
{
-        Path nodePath;
-        try {
-            nodePath = Path.create(getPrimaryPath(), nodeName, true);
-        } catch (MalformedPathException e) {
-            // should never happen
-            String msg = "internal error: invalid path " + safeGetJCRPath();
-            log.debug(msg);
-            throw new RepositoryException(msg, e);
-        }
-
-        NodeDefinitionImpl def;
-        try {
-            QName nodeTypeName = null;
-            if (nodeType != null) {
-                nodeTypeName = nodeType.getQName();
-            }
-            def = getApplicableChildNodeDefinition(nodeName, nodeTypeName);
-        } catch (RepositoryException re) {
-            String msg = "no definition found in parent node's node type for new node";
-            log.debug(msg);
-            throw new ConstraintViolationException(msg, re);
-        }
-
-        // check for name collisions
-        NodeState thisState = (NodeState) state;
-        if (thisState.hasPropertyName(nodeName)) {
-            // there's already a property with that name
-            throw new ItemExistsException(itemMgr.safeGetJCRPath(nodePath));
-        }
-        NodeState.ChildNodeEntry cne = thisState.getChildNodeEntry(nodeName, 1);
-        if (cne != null) {
-            // there's already a child node entry with that name;
-            // check same-name sibling setting of new node
-            if (!def.allowsSameNameSiblings()) {
-                throw new ItemExistsException(itemMgr.safeGetJCRPath(nodePath));
-            }
-            // check same-name sibling setting of existing node
-            NodeId newId = cne.getId();
-            if (!((NodeImpl) itemMgr.getItem(newId)).getDefinition().allowsSameNameSiblings())
{
-                throw new ItemExistsException(itemMgr.safeGetJCRPath(nodePath));
-            }
-        }
-
-        // get virtual node state
-        NodeState nodeState;
-        try {
-            nodeState = (NodeState) stateMgr.getItemState(id);
-        } catch (ItemStateException e) {
-            String msg = "failed to get virtual child node " + nodeName + " of "
-                    + safeGetJCRPath();
-            log.debug(msg);
-            throw new RepositoryException(msg, e);
-        }
-
-        // create Node instance wrapping virtual state
-        NodeImpl node = itemMgr.createNodeInstance(nodeState, def);
-
-        // touch the virtual node, otherwise save will complain that the
-        // virtual node needs to be saved as well.
-        node.getOrCreateTransientItemState();
-
-        // add new child node entry
-        thisState.addChildNodeEntry(nodeName, id);
-
-        return node;
-    }
-
     private void setMixinTypesProperty(Set mixinNames) throws RepositoryException {
         NodeState thisState = (NodeState) state;
         // get or create jcr:mixinTypes property

Modified: jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/RepositoryImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/RepositoryImpl.java?view=diff&rev=469480&r1=469479&r2=469480
==============================================================================
--- jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/RepositoryImpl.java
(original)
+++ jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/RepositoryImpl.java
Tue Oct 31 05:48:22 2006
@@ -35,7 +35,6 @@
 import org.apache.jackrabbit.core.fs.FileSystemResource;
 import org.apache.jackrabbit.core.lock.LockManager;
 import org.apache.jackrabbit.core.lock.LockManagerImpl;
-import org.apache.jackrabbit.core.nodetype.NodeTypeImpl;
 import org.apache.jackrabbit.core.nodetype.NodeTypeRegistry;
 import org.apache.jackrabbit.core.nodetype.virtual.VirtualNodeTypeStateManager;
 import org.apache.jackrabbit.core.observation.DelegatingObservationDispatcher;
@@ -533,20 +532,9 @@
          * - all other workspaces should be dynamic workspaces based on
          *   this 'read-only' system workspace
          *
-         * for now, we just create a /jcr:system node in every workspace
+         * for now, the jcr:system node is created in
+         * {@link org.apache.jackrabbit.core.state.SharedItemStateManager#createRootNodeState}
          */
-        NodeImpl rootNode = (NodeImpl) sysSession.getRootNode();
-        if (!rootNode.hasNode(QName.JCR_SYSTEM)) {
-            NodeTypeImpl nt = sysSession.getNodeTypeManager().getNodeType(QName.REP_SYSTEM);
-            NodeImpl sysRoot = rootNode.internalAddChildNode(QName.JCR_SYSTEM, nt, SYSTEM_ROOT_NODE_ID);
-            // add version storage
-            nt = sysSession.getNodeTypeManager().getNodeType(QName.REP_VERSIONSTORAGE);
-            sysRoot.internalAddVirtualChildNode(QName.JCR_VERSIONSTORAGE, nt, VERSION_STORAGE_NODE_ID);
-            // add node types
-            nt = sysSession.getNodeTypeManager().getNodeType(QName.REP_NODETYPES);
-            sysRoot.internalAddVirtualChildNode(QName.JCR_NODETYPES, nt, NODETYPES_NODE_ID);
-            rootNode.save();
-        }
 
         // register the repository as event listener for keeping repository statistics
         wsp.getObservationManager().addEventListener(this,

Modified: jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/state/SharedItemStateManager.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/state/SharedItemStateManager.java?view=diff&rev=469480&r1=469479&r2=469480
==============================================================================
--- jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/state/SharedItemStateManager.java
(original)
+++ jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/state/SharedItemStateManager.java
Tue Oct 31 05:48:22 2006
@@ -21,6 +21,7 @@
 import org.apache.jackrabbit.core.ItemId;
 import org.apache.jackrabbit.core.NodeId;
 import org.apache.jackrabbit.core.PropertyId;
+import org.apache.jackrabbit.core.RepositoryImpl;
 import org.apache.jackrabbit.core.persistence.PersistenceManager;
 import org.apache.jackrabbit.core.version.XAVersionManager;
 import org.apache.jackrabbit.core.nodetype.EffectiveNodeType;
@@ -799,6 +800,7 @@
             throws ItemStateException {
 
         NodeState rootState = createInstance(rootNodeId, QName.REP_ROOT, null);
+        NodeState jcrSystemState = createInstance(RepositoryImpl.SYSTEM_ROOT_NODE_ID, QName.REP_SYSTEM,
rootNodeId);
 
         // FIXME need to manually setup root node by creating mandatory jcr:primaryType property
         // @todo delegate setup of root node to NodeTypeInstanceHandler
@@ -807,11 +809,14 @@
         NodeDefId nodeDefId;
         // definition of jcr:primaryType property
         PropDef propDef;
+        // id of the jcr:system node's definition
+        NodeDefId jcrSystemDefId;
         try {
             nodeDefId = ntReg.getRootNodeDef().getId();
             EffectiveNodeType ent = ntReg.getEffectiveNodeType(QName.REP_ROOT);
             propDef = ent.getApplicablePropertyDef(QName.JCR_PRIMARYTYPE,
                     PropertyType.NAME, false);
+            jcrSystemDefId = ent.getApplicableChildNodeDef(QName.JCR_SYSTEM, QName.REP_SYSTEM,
ntReg).getId();
         } catch (NoSuchNodeTypeException nsnte) {
             String msg = "internal error: failed to create root node";
             log.error(msg, nsnte);
@@ -822,8 +827,9 @@
             throw new ItemStateException(msg, cve);
         }
         rootState.setDefinitionId(nodeDefId);
+        jcrSystemState.setDefinitionId(jcrSystemDefId);
 
-        // create jcr:primaryType property
+        // create jcr:primaryType property on root node state
         rootState.addPropertyName(propDef.getName());
 
         PropertyState prop = createInstance(propDef.getName(), rootNodeId);
@@ -832,9 +838,30 @@
         prop.setMultiValued(propDef.isMultiple());
         prop.setDefinitionId(propDef.getId());
 
+        // create jcr:primaryType property on jcr:system node state
+        jcrSystemState.addPropertyName(propDef.getName());
+
+        PropertyState primaryTypeProp = createInstance(propDef.getName(), jcrSystemState.getNodeId());
+        primaryTypeProp.setValues(new InternalValue[]{InternalValue.create(QName.REP_SYSTEM)});
+        primaryTypeProp.setType(propDef.getRequiredType());
+        primaryTypeProp.setMultiValued(propDef.isMultiple());
+        primaryTypeProp.setDefinitionId(propDef.getId());
+
+        // add child node entry for jcr:system node
+        rootState.addChildNodeEntry(QName.JCR_SYSTEM, RepositoryImpl.SYSTEM_ROOT_NODE_ID);
+
+        // add child node entry for virtual jcr:versionStorage
+        jcrSystemState.addChildNodeEntry(QName.JCR_VERSIONSTORAGE, RepositoryImpl.VERSION_STORAGE_NODE_ID);
+
+        // add child node entry for virtual jcr:nodeTypes
+        jcrSystemState.addChildNodeEntry(QName.JCR_NODETYPES, RepositoryImpl.NODETYPES_NODE_ID);
+
+
         ChangeLog changeLog = new ChangeLog();
         changeLog.added(rootState);
         changeLog.added(prop);
+        changeLog.added(jcrSystemState);
+        changeLog.added(primaryTypeProp);
 
         persistMgr.store(changeLog);
         changeLog.persisted();



Mime
View raw message