jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tri...@apache.org
Subject svn commit: rev 56758 - in incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core: . version
Date Sat, 06 Nov 2004 12:40:33 GMT
Author: tripod
Date: Sat Nov  6 04:40:33 2004
New Revision: 56758

Modified:
   incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/RepositoryImpl.java
   incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/SessionImpl.java
   incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/version/PersistentVersionManager.java
   incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/version/VersionManager.java
Log:
- enhancing versioning to work with all workspaces

Modified: incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/RepositoryImpl.java
==============================================================================
--- incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/RepositoryImpl.java	(original)
+++ incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/RepositoryImpl.java	Sat
Nov  6 04:40:33 2004
@@ -274,11 +274,15 @@
          */
 
         // check system root node of system workspace
-        SessionImpl sysSession = getSystemSession(repConfig.getDefaultWorkspaceName());
-        NodeImpl rootNode = (NodeImpl) sysSession.getRootNode();
-        if (!rootNode.hasNode(SYSTEM_ROOT_NAME)) {
-            rootNode.addNode(SYSTEM_ROOT_NAME, NodeTypeRegistry.NT_UNSTRUCTURED);
-            rootNode.save();
+        // (by now, we just create a system root node in all workspaces)
+        Iterator wspNames = wspConfigs.keySet().iterator();
+        while (wspNames.hasNext()) {
+            String wspName = (String) wspNames.next();
+            NodeImpl rootNode = (NodeImpl) getSystemSession(wspName).getRootNode();
+            if (!rootNode.hasNode(SYSTEM_ROOT_NAME)) {
+                rootNode.addNode(SYSTEM_ROOT_NAME, NodeTypeRegistry.NT_UNSTRUCTURED);
+                rootNode.save();
+            }
         }
 
         // init version manager

Modified: incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/SessionImpl.java
==============================================================================
--- incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/SessionImpl.java	(original)
+++ incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/SessionImpl.java	Sat Nov
 6 04:40:33 2004
@@ -147,12 +147,12 @@
         hierMgr = itemStateMgr.getHierarchyMgr();
         itemMgr = createItemManager(itemStateMgr, hierMgr);
         accessMgr = createAccessManager(credentials, hierMgr);
-        versionMgr = rep.getPersistentVersionManager()==null?null:rep.getPersistentVersionManager().getVersionManager();
+        versionMgr = rep.getPersistentVersionManager()==null?null:rep.getPersistentVersionManager().getVersionManager(wsp);
 
         // add virtual item managers only for normal sessions
         if (!(this instanceof SystemSession)) {
             try {
-                itemStateMgr.addVirtualItemStateProvider(versionMgr.getVirtualItemStateProvider(itemStateMgr));
+                itemStateMgr.addVirtualItemStateProvider(versionMgr.getVirtualItemStateProvider(this,
itemStateMgr));
             } catch (Exception e) {
                 log.error("Unable to add vmgr: " + e.toString(), e);
             }
@@ -178,12 +178,12 @@
         itemStateMgr = new SessionItemStateManager(rep.getRootNodeUUID(), wsp.getPersistentStateManager(),
getNamespaceResolver());
         hierMgr = itemStateMgr.getHierarchyMgr();
         itemMgr = createItemManager(itemStateMgr, hierMgr);
-        versionMgr = rep.getPersistentVersionManager()==null?null:rep.getPersistentVersionManager().getVersionManager();
+        versionMgr = rep.getPersistentVersionManager()==null?null:rep.getPersistentVersionManager().getVersionManager(wsp);
 
         // add virtual item managers only for normal sessions
         if (!(this instanceof SystemSession)) {
             try {
-                itemStateMgr.addVirtualItemStateProvider(versionMgr.getVirtualItemStateProvider(itemStateMgr));
+                itemStateMgr.addVirtualItemStateProvider(versionMgr.getVirtualItemStateProvider(this,
itemStateMgr));
             } catch (Exception e) {
                 log.error("Unable to add vmgr: " + e.toString(), e);
             }

Modified: incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/version/PersistentVersionManager.java
==============================================================================
--- incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/version/PersistentVersionManager.java
(original)
+++ incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/version/PersistentVersionManager.java
Sat Nov  6 04:40:33 2004
@@ -27,6 +27,7 @@
 import javax.jcr.Node;
 import javax.jcr.RepositoryException;
 import javax.jcr.Value;
+import javax.jcr.Workspace;
 import java.util.Iterator;
 import java.util.ArrayList;
 import java.util.HashMap;
@@ -77,16 +78,6 @@
     private final PersistentNode historyRoot;
 
     /**
-     * the virtual root node of the version histories
-     */
-    private final String virtHistoryRootId;
-
-    /**
-     * the system root id
-     */
-    private final String systemRootId;
-
-    /**
      * the state manager for the version storage
      */
     private PersistentItemStateProvider stateMgr;
@@ -97,9 +88,9 @@
     private NodeTypeManagerImpl ntMgr;
 
     /**
-     * The representation version manager
+     * The representation version managers (per workspace)
      */
-    private VersionManager versionManager;
+    private HashMap versionManagers = new HashMap();
 
     /**
      * the version histories
@@ -118,17 +109,11 @@
 
         // check for versionhistory root
         NodeImpl systemRoot = ((RepositoryImpl) session.getRepository()).getSystemRootNode(session);
-        systemRootId = systemRoot.internalGetUUID();
         if (!systemRoot.hasNode(VERSION_HISTORY_ROOT_NAME)) {
             // if not exist, create
             systemRoot.addNode(VERSION_HISTORY_ROOT_NAME, NodeTypeRegistry.NT_UNSTRUCTURED);
         }
-        if (!systemRoot.hasNode(VersionManager.VERSION_HISTORY_ROOT_NAME)) {
-            // if not exist, create
-            systemRoot.addNode(VersionManager.VERSION_HISTORY_ROOT_NAME, NodeTypeRegistry.NT_UNSTRUCTURED);
-        }
         systemRoot.save();
-        virtHistoryRootId = systemRoot.getNode(VersionManager.VERSION_HISTORY_ROOT_NAME).internalGetUUID();
 
         try {
             PersistentNodeState nodeState = (PersistentNodeState) stateMgr.getItemState(new
NodeId(systemRoot.getNode(VERSION_HISTORY_ROOT_NAME).internalGetUUID()));
@@ -159,6 +144,9 @@
         // create new history node in the persistent state
         InternalVersionHistory hist = InternalVersionHistory.create(this, historyRoot, uuid,
historyNodeName, node);
         histories.put(hist.getId(), hist);
+
+        // notify version managers
+        onVersionHistoryModified(hist);
         return hist;
     }
 
@@ -216,8 +204,21 @@
      */
     protected void onVersionModified(InternalVersion version)  throws RepositoryException
{
         // check if version manager already generated item states
-        if (versionManager!=null) {
-            versionManager.onVersionModified(version);
+        Iterator iter = versionManagers.values().iterator();
+        while (iter.hasNext()) {
+            ((VersionManager) iter.next()).onVersionModified(version);
+        }
+    }
+
+    /**
+     * is informed by the versions if they were modified
+     * @param vh
+     */
+    protected void onVersionHistoryModified(InternalVersionHistory vh)  throws RepositoryException
{
+        // check if version manager already generated item states
+        Iterator iter = versionManagers.values().iterator();
+        while (iter.hasNext()) {
+            ((VersionManager) iter.next()).onVersionHistoryModified(vh);
         }
     }
 
@@ -279,11 +280,13 @@
      * returns the version manager
      * @return
      */
-    public synchronized VersionManager getVersionManager() {
-        if (versionManager==null) {
-            versionManager = new VersionManager(this, virtHistoryRootId);
+    public synchronized VersionManager getVersionManager(Workspace wsp) {
+        VersionManager vm = (VersionManager) versionManagers.get(wsp.getName());
+        if (vm==null) {
+            vm = new VersionManager(this);
+            versionManagers.put(wsp.getName(), vm);
         }
-        return versionManager;
+        return vm;
     }
 
     /**

Modified: incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/version/VersionManager.java
==============================================================================
--- incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/version/VersionManager.java
(original)
+++ incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/version/VersionManager.java
Sat Nov  6 04:40:33 2004
@@ -25,6 +25,7 @@
 
 import javax.jcr.RepositoryException;
 import javax.jcr.PropertyType;
+import javax.jcr.Workspace;
 import javax.jcr.nodetype.NodeDef;
 import javax.jcr.version.VersionHistory;
 import javax.jcr.version.Version;
@@ -100,11 +101,6 @@
     private final PersistentVersionManager vMgr;
 
     /**
-     * the uuid of the system root node
-     */
-    private final String rootId;
-
-    /**
      * The virtual item manager that exposes the versions to the content
      */
     private DefaultItemStateProvider virtProvider;
@@ -117,11 +113,9 @@
 
     /**
      * @param vMgr
-     * @param rootId the uuid of the version history root
      */
-    protected VersionManager(PersistentVersionManager vMgr, String rootId) {
+    protected VersionManager(PersistentVersionManager vMgr) {
         this.vMgr = vMgr;
-        this.rootId = rootId;
     }
 
     /**
@@ -130,9 +124,18 @@
      * @param base
      * @return
      */
-    public VirtualItemStateProvider getVirtualItemStateProvider(ItemStateProvider base) {
+    public VirtualItemStateProvider getVirtualItemStateProvider(SessionImpl session, ItemStateProvider
base) {
         if (virtProvider==null) {
             try {
+                // check, if workspace of session has history root
+                NodeImpl systemRoot = ((RepositoryImpl) session.getRepository()).getSystemRootNode(session);
+                if (!systemRoot.hasNode(VersionManager.VERSION_HISTORY_ROOT_NAME)) {
+                    // if not exist, create
+                    systemRoot.addNode(VersionManager.VERSION_HISTORY_ROOT_NAME, NodeTypeRegistry.NT_UNSTRUCTURED);
+                }
+                systemRoot.save();
+                String rootId = systemRoot.getNode(VersionManager.VERSION_HISTORY_ROOT_NAME).internalGetUUID();
+
                 virtProvider = new DefaultItemStateProvider(vMgr.getNodeTypeManager());
                 // create a duplicate of the version history root name
                 NodeState virtRootState = (NodeState) base.getItemState(new NodeId(rootId));
@@ -162,7 +165,6 @@
      */
     public VersionHistory createVersionHistory(NodeImpl node) throws RepositoryException
{
         InternalVersionHistory history = vMgr.createVersionHistory(node);
-        mapVersionHistory(history);
         return (VersionHistory) node.getSession().getNodeByUUID(history.getId());
     }
 
@@ -256,8 +258,10 @@
     public Version checkin(NodeImpl node) throws RepositoryException {
         try {
             InternalVersion version = vMgr.checkin(node);
+            vMgr.onVersionHistoryModified(version.getVersionHistory());
+
             VirtualNodeState vhNode = (VirtualNodeState) virtProvider.getItemState(new NodeId(version.getVersionHistory().getId()));
-            mapVersion(vhNode, version);
+
             // invalidate predecessors 'sucessors' properties
             InternalVersion[] pred = version.getPredecessors();
             for (int i=0; i<pred.length; i++) {
@@ -285,6 +289,16 @@
     }
 
     /**
+     * Called when a internal version history has changed its internal structure,
+     * and the structure has to be remapped to the content.
+     * @param vh
+     * @throws RepositoryException
+     */
+    protected void onVersionHistoryModified(InternalVersionHistory vh) throws RepositoryException
{
+        mapVersionHistory(vh);
+    }
+
+    /**
      * Maps the version history and it's versions to the content representation.
      * @param vh
      * @throws RepositoryException
@@ -308,7 +322,12 @@
             }
 
             historyNodeName = new QName(NamespaceRegistryImpl.NS_DEFAULT_URI, uuid.substring(4));
-            VirtualNodeState vhNode = virtProvider.addNode(parent, historyNodeName, vh.getId(),
NodeTypeRegistry.NT_VERSION_HISTORY, null);
+            VirtualNodeState vhNode;
+            if (parent.hasChildNodeEntry(historyNodeName)) {
+                vhNode = virtProvider.getNode(parent, historyNodeName, 1);
+            } else {
+                vhNode = virtProvider.addNode(parent, historyNodeName, vh.getId(), NodeTypeRegistry.NT_VERSION_HISTORY,
null);
+            }
 
             // add the versions
             Iterator iter = vh.getVersions();
@@ -331,24 +350,27 @@
     private void mapVersion(VirtualNodeState vhNode, InternalVersion version)
             throws RepositoryException {
         try {
-            VirtualNodeState vNode = virtProvider.addNode(vhNode, version.getName(), version.getId(),
NodeTypeRegistry.NT_VERSION, null);
-
-            // initialize the version
-            virtProvider.setPropertyValue(vNode, VersionManager.PROPNAME_CREATED, InternalValue.create(version.getCreated()));
-
-            // initialize the primary properties
-            InternalFrozenNode fNode = version.getFrozenNode();
-            virtProvider.setPropertyValue(vNode, VersionManager.PROPNAME_FROZEN_UUID, InternalValue.create(fNode.getFrozenUUID()));
-            virtProvider.setPropertyValue(vNode, VersionManager.PROPNAME_FROZEN_PRIMARY_TYPE,
InternalValue.create(fNode.getFrozenPrimaryType()));
-            virtProvider.setPropertyValues(vNode, VersionManager.PROPNAME_FROZEN_MIXIN_TYPES,
PropertyType.NAME, InternalValue.create(fNode.getFrozenMixinTypes()));
+            VirtualNodeState vNode;
+            if (vhNode.hasChildNodeEntry(version.getName())) {
+                vNode = virtProvider.getNode(vhNode, version.getName(), 1);
+            } else {
+                vNode = virtProvider.addNode(vhNode, version.getName(), version.getId(),
NodeTypeRegistry.NT_VERSION, null);
+                // initialize the version
+                virtProvider.setPropertyValue(vNode, VersionManager.PROPNAME_CREATED, InternalValue.create(version.getCreated()));
+
+                // initialize the primary properties
+                InternalFrozenNode fNode = version.getFrozenNode();
+                virtProvider.setPropertyValue(vNode, VersionManager.PROPNAME_FROZEN_UUID,
InternalValue.create(fNode.getFrozenUUID()));
+                virtProvider.setPropertyValue(vNode, VersionManager.PROPNAME_FROZEN_PRIMARY_TYPE,
InternalValue.create(fNode.getFrozenPrimaryType()));
+                virtProvider.setPropertyValues(vNode, VersionManager.PROPNAME_FROZEN_MIXIN_TYPES,
PropertyType.NAME, InternalValue.create(fNode.getFrozenMixinTypes()));
+                if (!version.isRootVersion()) {
+                    // don't map for root verion
+                    mapFrozenNode(vNode, PersistentVersionManager.NODENAME_FROZEN, fNode);
+                }
+            }
 
             // map dynamic ones
             mapDynamicProperties(vNode, version);
-
-            if (!version.isRootVersion()) {
-                // don't map for root verion
-                mapFrozenNode(vNode, PersistentVersionManager.NODENAME_FROZEN, fNode);
-            }
 
         } catch (ItemStateException e) {
             throw new RepositoryException(e);

Mime
View raw message