jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ju...@apache.org
Subject svn commit: r778680 - in /jackrabbit/branches/1.x: ./ jackrabbit-core/src/main/java/org/apache/jackrabbit/core/version/ jackrabbit-core/src/test/java/org/apache/jackrabbit/core/version/
Date Tue, 26 May 2009 12:47:18 GMT
Author: jukka
Date: Tue May 26 12:47:17 2009
New Revision: 778680

URL: http://svn.apache.org/viewvc?rev=778680&view=rev
Log:
1.x: Merged revision 778645 (JCR-134)

Added:
    jackrabbit/branches/1.x/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/version/RemoveOrphanVersionHistoryTest.java
      - copied unchanged from r778645, jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/version/RemoveOrphanVersionHistoryTest.java
Modified:
    jackrabbit/branches/1.x/   (props changed)
    jackrabbit/branches/1.x/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/version/AbstractVersionManager.java
    jackrabbit/branches/1.x/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/version/InternalVersionHistoryImpl.java
    jackrabbit/branches/1.x/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/version/VersionManagerImpl.java
    jackrabbit/branches/1.x/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/version/XAVersionManager.java

Propchange: jackrabbit/branches/1.x/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Tue May 26 12:47:17 2009
@@ -1 +1 @@
-/jackrabbit/trunk:770143-773197,773483,773525-773554,773584,773588,773828,773835-775756,775833,775836,775840,775868,775981,775986,776036,776256,776310,776313,776321-776322,776332,776356-776357,776362,776373,776650-776693,776737,776757,776776-776777,777024,777029,777034,777478,777509,777541,777548,777936
+/jackrabbit/trunk:770143-773197,773483,773525-773554,773584,773588,773828,773835-775756,775833,775836,775840,775868,775981,775986,776036,776256,776310,776313,776321-776322,776332,776356-776357,776362,776373,776650-776693,776737,776757,776776-776777,777024,777029,777034,777478,777509,777541,777548,777936,778645

Modified: jackrabbit/branches/1.x/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/version/AbstractVersionManager.java
URL: http://svn.apache.org/viewvc/jackrabbit/branches/1.x/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/version/AbstractVersionManager.java?rev=778680&r1=778679&r2=778680&view=diff
==============================================================================
--- jackrabbit/branches/1.x/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/version/AbstractVersionManager.java
(original)
+++ jackrabbit/branches/1.x/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/version/AbstractVersionManager.java
Tue May 26 12:47:17 2009
@@ -40,8 +40,8 @@
 /**
  * Base implementation of the {@link VersionManager} interface.
  * <p/>
- * All read operations must aquire the read lock before reading, all write
- * operations must aquire the write lock.
+ * All read operations must acquire the read lock before reading, all write
+ * operations must acquire the write lock.
  */
 abstract class AbstractVersionManager implements VersionManager {
 
@@ -291,7 +291,7 @@
     /**
      * Returns the item with the given persistent id. Subclass responsibility.
      * <p/>
-     * Please note, that the overridden method must aquire the readlock before
+     * Please note, that the overridden method must acquire the readlock before
      * reading the state manager.
      *
      * @param id the id of the item
@@ -312,18 +312,31 @@
 
     /**
      * Checks if there are item references (from outside the version storage)
-     * that reference the given version item. Subclass responsiblity.
+     * that reference the given node. Subclass responsibility.
      * <p/>
-     * Please note, that the overridden method must aquire the readlock before
+     * Please note, that the overridden method must acquire the readlock before
      * reading the state manager.
      *
-     * @param item version item
+     * @param id the id of the node
      * @return <code>true</code> if there are item references from outside the
      *         version storage; <code>false</code> otherwise.
      * @throws RepositoryException if an error occurs while reading from the
      *                             repository.
      */
-    protected abstract boolean hasItemReferences(InternalVersionItem item)
+    protected abstract boolean hasItemReferences(NodeId id)
+            throws RepositoryException;
+
+    /**
+     * Returns the node with the given persistent id. Subclass responsibility.
+     * <p/>
+     * Please note, that the overridden method must acquire the readlock before
+     * reading the state manager.
+     *
+     * @param id the id of the node
+     * @throws RepositoryException if an error occurs while reading from the
+     *                             repository.
+     */
+    protected abstract NodeStateEx getNodeStateEx(NodeId id)
             throws RepositoryException;
 
     /**

Modified: jackrabbit/branches/1.x/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/version/InternalVersionHistoryImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/branches/1.x/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/version/InternalVersionHistoryImpl.java?rev=778680&r1=778679&r2=778680&view=diff
==============================================================================
--- jackrabbit/branches/1.x/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/version/InternalVersionHistoryImpl.java
(original)
+++ jackrabbit/branches/1.x/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/version/InternalVersionHistoryImpl.java
Tue May 26 12:47:17 2009
@@ -375,7 +375,7 @@
             throw new VersionException(msg);
         }
         // check if any references (from outside the version storage) exist on this version
-        if (vMgr.hasItemReferences(v)) {
+        if (vMgr.hasItemReferences(v.getId())) {
             throw new ReferentialIntegrityException("Unable to remove version. At least once
referenced.");
         }
 
@@ -396,8 +396,25 @@
         nameCache.remove(versionName);
         vMgr.versionDestroyed(v);
 
-        // store changes
-        node.store();
+        // Check if this was the last version in addition to the root version
+        if (!vMgr.hasItemReferences(node.getNodeId())) {
+            log.debug("Current version history has no references");
+            NodeStateEx[] childNodes = node.getChildNodes();
+
+            // Check if there is only root version and version labels nodes
+            if (childNodes.length == 2) {
+                log.debug("Removing orphan version history as it contains only two children");
+                NodeStateEx parentNode = vMgr.getNodeStateEx(node.getParentId());
+                // Remove version history node
+                parentNode.removeNode(node.getName());
+                // store changes for this node and his children
+                parentNode.store();
+            }
+        } else {
+            log.debug("Current version history has at least one reference");
+            // store changes
+            node.store();
+        }
 
         // now also remove from labelCache
         for (int i = 0; i < labels.length; i++) {

Modified: jackrabbit/branches/1.x/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/version/VersionManagerImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/branches/1.x/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/version/VersionManagerImpl.java?rev=778680&r1=778679&r2=778680&view=diff
==============================================================================
--- jackrabbit/branches/1.x/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/version/VersionManagerImpl.java
(original)
+++ jackrabbit/branches/1.x/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/version/VersionManagerImpl.java
Tue May 26 12:47:17 2009
@@ -411,14 +411,19 @@
     /**
      * {@inheritDoc}
      */
-    protected boolean hasItemReferences(InternalVersionItem item)
+    protected boolean hasItemReferences(NodeId id)
+            throws RepositoryException {
+        return stateMgr.hasNodeReferences(new NodeReferencesId(id));
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    protected NodeStateEx getNodeStateEx(NodeId parentNodeId)
             throws RepositoryException {
         try {
-            NodeReferences refs = stateMgr.getNodeReferences(
-                    new NodeReferencesId(item.getId()));
-            return refs.hasReferences();
-        } catch (NoSuchItemStateException e) {
-            return false;
+            NodeState state = (NodeState) stateMgr.getItemState(parentNodeId);
+            return new NodeStateEx(stateMgr, ntReg, state, null);
         } catch (ItemStateException e) {
             throw new RepositoryException(e);
         }

Modified: jackrabbit/branches/1.x/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/version/XAVersionManager.java
URL: http://svn.apache.org/viewvc/jackrabbit/branches/1.x/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/version/XAVersionManager.java?rev=778680&r1=778679&r2=778680&view=diff
==============================================================================
--- jackrabbit/branches/1.x/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/version/XAVersionManager.java
(original)
+++ jackrabbit/branches/1.x/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/version/XAVersionManager.java
Tue May 26 12:47:17 2009
@@ -370,9 +370,22 @@
     /**
      * {@inheritDoc}
      */
-    protected boolean hasItemReferences(InternalVersionItem item)
+    protected boolean hasItemReferences(NodeId id)
             throws RepositoryException {
-        return session.getNodeById(item.getId()).getReferences().hasNext();
+        return session.getNodeById(id).getReferences().hasNext();
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    protected NodeStateEx getNodeStateEx(NodeId parentNodeId)
+            throws RepositoryException {
+        try {
+            NodeState state = (NodeState) stateMgr.getItemState(parentNodeId);
+            return new NodeStateEx(stateMgr, ntReg, state, null);
+        } catch (ItemStateException e) {
+            throw new RepositoryException(e);
+        }
     }
 
     /**



Mime
View raw message