jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ju...@apache.org
Subject svn commit: r702425 - in /jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core: ./ version/ xml/
Date Tue, 07 Oct 2008 10:16:45 GMT
Author: jukka
Date: Tue Oct  7 03:16:43 2008
New Revision: 702425

URL: http://svn.apache.org/viewvc?rev=702425&view=rev
Log:
JCR-1775: Transaction-safe versioning

All calls to VersionManager's getVersionHistory and createVersionHistory followed this pattern:

    VersionHistory vh = manager.getVersionHistory(...);
    if (vh == null) {
        vh = manager.createVersionHistory(...);
    }

Simplified things by making getVersionHistory() automatically create the version history if
it doesn't already exist. This simplifies the client code to:

    VersionHistory vh = manager.getVersionHistory(...);

Modified:
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/BatchedItemOperations.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/ItemImpl.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/version/AbstractVersionManager.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/version/VersionManager.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/version/VersionManagerImpl.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/version/XAVersionManager.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/xml/WorkspaceImporter.java

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/BatchedItemOperations.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/BatchedItemOperations.java?rev=702425&r1=702424&r2=702425&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/BatchedItemOperations.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/BatchedItemOperations.java
Tue Oct  7 03:16:43 2008
@@ -2003,13 +2003,7 @@
      */
     private VersionHistory getOrCreateVersionHistory(NodeState node)
             throws RepositoryException {
-        VersionManager vMgr = session.getVersionManager();
-        VersionHistory vh = vMgr.getVersionHistory(session, node);
-        if (vh == null) {
-            // create a new version history
-            vh = vMgr.createVersionHistory(session, node);
-        }
-        return vh;
+        return session.getVersionManager().getVersionHistory(session, node);
     }
 
     /**

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/ItemImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/ItemImpl.java?rev=702425&r1=702424&r2=702425&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/ItemImpl.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/ItemImpl.java
Tue Oct  7 03:16:43 2008
@@ -726,10 +726,8 @@
                          * IMPORT_UUID_COLLISION_REPLACE_EXISTING;
                          * otherwise create a new version history
                          */
-                        VersionHistory vh = vMgr.getVersionHistory(session, nodeState);
-                        if (vh == null) {
-                            vh = vMgr.createVersionHistory(session, nodeState);
-                        }
+                        VersionHistory vh =
+                            vMgr.getVersionHistory(session, nodeState);
                         node.internalSetProperty(NameConstants.JCR_VERSIONHISTORY, InternalValue.create(new
UUID(vh.getUUID())));
                         node.internalSetProperty(NameConstants.JCR_BASEVERSION, InternalValue.create(new
UUID(vh.getRootVersion().getUUID())));
                         node.internalSetProperty(NameConstants.JCR_ISCHECKEDOUT, InternalValue.create(true));

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/version/AbstractVersionManager.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/version/AbstractVersionManager.java?rev=702425&r1=702424&r2=702425&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/version/AbstractVersionManager.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/version/AbstractVersionManager.java
Tue Oct  7 03:16:43 2008
@@ -228,16 +228,12 @@
     }
 
     /**
-     * Returns the version history associated with the given node.
-     *
-     * @param session 
-     * @param node the node whose version history's id is to be returned.
-     * @return the version history associated with the given node
-     *         or <code>null</code> if that node doesn't have a version history.
-     * @throws RepositoryException if an error occurs
+     * {@inheritDoc}
      */
     public VersionHistory getVersionHistory(Session session, NodeState node)
             throws RepositoryException {
+        NodeId id = null;
+
         acquireReadLock();
         try {
             String uuid = node.getNodeId().getUUID().toString();
@@ -245,17 +241,33 @@
 
             NodeStateEx parent = getParentNode(uuid, false);
             if (parent != null && parent.hasNode(name)) {
-                NodeId id =
-                    parent.getState().getChildNodeEntry(name, 1).getId();
-                return (VersionHistory) ((SessionImpl) session).getNodeById(id);
-            } else {
-                return null;
+                id = parent.getState().getChildNodeEntry(name, 1).getId();
             }
         } finally {
             releaseReadLock();
         }
+
+        if (id == null) {
+            id = createVersionHistory(session, node);
+        }
+
+        return (VersionHistory) ((SessionImpl) session).getNodeById(id);
     }
 
+
+    /**
+     * Creates a new version history. This action is needed either when creating
+     * a new 'mix:versionable' node or when adding the 'mix:versionable' mixin
+     * to a node.
+     *
+     * @param node
+     * @return identifier of the new version history node
+     * @throws RepositoryException
+     * @see #getVersionHistory(Session, NodeState)
+     */
+    protected abstract NodeId createVersionHistory(
+            Session session, NodeState node) throws RepositoryException;
+
     /**
      * Returns the item with the given persistent id. Subclass responsibility.
      * <p/>

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/version/VersionManager.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/version/VersionManager.java?rev=702425&r1=702424&r2=702425&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/version/VersionManager.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/version/VersionManager.java
Tue Oct  7 03:16:43 2008
@@ -42,30 +42,15 @@
     VirtualItemStateProvider getVirtualItemStateProvider();
 
     /**
-     * Creates a new version history. This action is needed either when creating
-     * a new 'mix:versionable' node or when adding the 'mix:versionable' mixin
-     * to a node.
-     *
-     * @param node
-     * @return
-     * @throws RepositoryException
-     * @see #getVersionHistory(Session, NodeState)
-     */
-    VersionHistory createVersionHistory(Session session, NodeState node)
-            throws RepositoryException;
-
-    /**
-     * Returns the version history of the specified <code>node</code> or
-     * <code>null</code> if the given node doesn't (yet) have an associated
-     * version history.
+     * Returns the version history of the specified node. If the given node
+     * does not already have an associated version history, then an empty
+     * history is automatically created. This method should only be called
+     * by code that already knows that the specified node is versionable.
      *
      * @param session
      * @param node node whose version history should be returned
-     * @return the version history of the specified <code>node</code> or
-     *         <code>null</code> if the given node doesn't (yet) have an
-     *        associated version history.
+     * @return the version history of the specified node
      * @throws RepositoryException if an error occurs
-     * @see #createVersionHistory(Session, NodeState)
      */
     VersionHistory getVersionHistory(Session session, NodeState node)
             throws RepositoryException;

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/version/VersionManagerImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/version/VersionManagerImpl.java?rev=702425&r1=702424&r2=702425&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/version/VersionManagerImpl.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/version/VersionManagerImpl.java
Tue Oct  7 03:16:43 2008
@@ -211,7 +211,7 @@
      * This method must not be synchronized since it could cause deadlocks with
      * item-reading listeners in the observation thread.
      */
-    public VersionHistory createVersionHistory(Session session, final NodeState node)
+    protected NodeId createVersionHistory(Session session, final NodeState node)
             throws RepositoryException {
         InternalVersionHistory history = (InternalVersionHistory)
                 escFactory.doSourced((SessionImpl) session, new SourcedTarget() {
@@ -223,7 +223,7 @@
         if (history == null) {
             throw new VersionException("History already exists for node " + node.getNodeId());
         }
-        return (VersionHistory) ((SessionImpl) session).getNodeById(history.getId());
+        return history.getId();
     }
 
     /**

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/version/XAVersionManager.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/version/XAVersionManager.java?rev=702425&r1=702424&r2=702425&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/version/XAVersionManager.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/version/XAVersionManager.java
Tue Oct  7 03:16:43 2008
@@ -131,13 +131,13 @@
     /**
      * {@inheritDoc}
      */
-    public VersionHistory createVersionHistory(Session session, NodeState node)
+    protected NodeId createVersionHistory(Session session, NodeState node)
             throws RepositoryException {
 
         if (isInXA()) {
             InternalVersionHistory history = createVersionHistory(node);
             xaItems.put(history.getId(), history);
-            return (VersionHistory) ((SessionImpl) session).getNodeById(history.getId());
+            return history.getId();
         }
         return vMgr.createVersionHistory(session, node);
     }

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/xml/WorkspaceImporter.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/xml/WorkspaceImporter.java?rev=702425&r1=702424&r2=702425&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/xml/WorkspaceImporter.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/xml/WorkspaceImporter.java
Tue Oct  7 03:16:43 2008
@@ -308,10 +308,8 @@
              * IMPORT_UUID_COLLISION_REPLACE_EXISTING;
              * otherwise create a new version history
              */
-            VersionHistory history = versionManager.getVersionHistory(session, node);
-            if (history == null) {
-                history = versionManager.createVersionHistory(session, node);
-            }
+            VersionHistory history =
+                versionManager.getVersionHistory(session, node);
             Version rootVersion = history.getRootVersion();
 
             // jcr:versionHistory



Mime
View raw message