jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mreut...@apache.org
Subject svn commit: r638303 - in /jackrabbit/trunk/jackrabbit-core/src: main/java/org/apache/jackrabbit/core/version/ test/java/org/apache/jackrabbit/core/version/
Date Tue, 18 Mar 2008 10:17:32 GMT
Author: mreutegg
Date: Tue Mar 18 03:17:26 2008
New Revision: 638303

URL: http://svn.apache.org/viewvc?rev=638303&view=rev
Log:
JCR-1476: Restore to base version throws NullPointerException

Added:
    jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/version/TestAll.java
  (with props)
Modified:
    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/InternalVersion.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/version/InternalVersionImpl.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/test/java/org/apache/jackrabbit/core/version/RestoreTest.java
    jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/version/VersionIteratorImplTest.java

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=638303&r1=638302&r2=638303&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 Mar 18 03:17:26 2008
@@ -21,6 +21,7 @@
 import org.apache.jackrabbit.core.NodeId;
 import org.apache.jackrabbit.core.NodeImpl;
 import org.apache.jackrabbit.core.SessionImpl;
+import org.apache.jackrabbit.core.nodetype.NodeTypeRegistry;
 import org.apache.jackrabbit.core.state.ItemStateException;
 import org.apache.jackrabbit.core.state.LocalItemStateManager;
 import org.apache.jackrabbit.core.state.NodeState;
@@ -59,6 +60,11 @@
     protected LocalItemStateManager stateMgr;
 
     /**
+     * Node type registry.
+     */
+    protected final NodeTypeRegistry ntReg;
+
+    /**
      * Persistent root node of the version histories.
      */
     protected NodeStateEx historyRoot;
@@ -78,6 +84,10 @@
                 }
             };
 
+    public AbstractVersionManager(NodeTypeRegistry ntReg) {
+        this.ntReg = ntReg;
+    }
+
     //-------------------------------------------------------< VersionManager >
 
     /**
@@ -528,5 +538,43 @@
      * @param item
      */
     protected void itemDiscarded(InternalVersionItem item) {
+    }
+
+    /**
+     * Creates an {@link InternalVersionItem} based on the {@link NodeState}
+     * identified by <code>id</code>.
+     *
+     * @param id    the node id of the version item.
+     * @return the version item or <code>null</code> if there is no node state
+     *         with the given <code>id</code>.
+     * @throws RepositoryException if an error occurs while reading from the
+     *                             version storage.
+     */
+    protected InternalVersionItem createInternalVersionItem(NodeId id)
+            throws RepositoryException {
+        try {
+            if (stateMgr.hasItemState(id)) {
+                NodeState state = (NodeState) stateMgr.getItemState(id);
+                NodeStateEx pNode = new NodeStateEx(stateMgr, ntReg, state, null);
+                NodeId parentId = pNode.getParentId();
+                InternalVersionItem parent = getItem(parentId);
+                Name ntName = state.getNodeTypeName();
+                if (ntName.equals(NameConstants.NT_FROZENNODE)) {
+                    return new InternalFrozenNodeImpl(this, pNode, parent);
+                } else if (ntName.equals(NameConstants.NT_VERSIONEDCHILD)) {
+                    return new InternalFrozenVHImpl(this, pNode, parent);
+                } else if (ntName.equals(NameConstants.NT_VERSION)) {
+                    return ((InternalVersionHistory) parent).getVersion(id);
+                } else if (ntName.equals(NameConstants.NT_VERSIONHISTORY)) {
+                    return new InternalVersionHistoryImpl(this, pNode);
+                } else {
+                    return null;
+                }
+            } else {
+                return null;
+            }
+        } catch (ItemStateException e) {
+            throw new RepositoryException(e);
+        }
     }
 }

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/version/InternalVersion.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/version/InternalVersion.java?rev=638303&r1=638302&r2=638303&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/version/InternalVersion.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/version/InternalVersion.java
Tue Mar 18 03:17:26 2008
@@ -17,6 +17,7 @@
 package org.apache.jackrabbit.core.version;
 
 import org.apache.jackrabbit.spi.Name;
+import org.apache.jackrabbit.core.NodeId;
 
 import java.util.Calendar;
 
@@ -39,6 +40,13 @@
      * @return the frozen node.
      */
     InternalFrozenNode getFrozenNode();
+
+    /**
+     * Returns the node id of the frozen node.
+     *
+     * @return the node id of the frozen node;
+     */
+    NodeId getFrozenNodeId();
 
     /**
      * Equivalent to {@link Version#getCreated()}

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/version/InternalVersionImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/version/InternalVersionImpl.java?rev=638303&r1=638302&r2=638303&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/version/InternalVersionImpl.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/version/InternalVersionImpl.java
Tue Mar 18 03:17:26 2008
@@ -108,14 +108,21 @@
     public InternalFrozenNode getFrozenNode() {
         // get frozen node
         try {
-            NodeState.ChildNodeEntry entry = node.getState().getChildNodeEntry(NameConstants.JCR_FROZENNODE,
1);
-            if (entry == null) {
-                throw new InternalError("version has no frozen node: " + getId());
-            }
-            return (InternalFrozenNode) vMgr.getItem(entry.getId());
+            return (InternalFrozenNode) vMgr.getItem(getFrozenNodeId());
         } catch (RepositoryException e) {
             throw new IllegalStateException("unable to retrieve frozen node: " + e);
         }
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public NodeId getFrozenNodeId() {
+        NodeState.ChildNodeEntry entry = node.getState().getChildNodeEntry(NameConstants.JCR_FROZENNODE,
1);
+        if (entry == null) {
+            throw new InternalError("version has no frozen node: " + getId());
+        }
+        return entry.getId();
     }
 
     /**

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=638303&r1=638302&r2=638303&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 Mar 18 03:17:26 2008
@@ -112,11 +112,6 @@
     private final VersionItemStateProvider versProvider;
 
     /**
-     * the node type manager
-     */
-    private NodeTypeRegistry ntReg;
-
-    /**
      * the dynamic event state collection factory
      */
     private final DynamicESCFactory escFactory;
@@ -136,10 +131,10 @@
                               NodeId rootParentId,
                               ItemStateCacheFactory cacheFactory,
                               ISMLocking ismLocking) throws RepositoryException {
+        super(ntReg);
         try {
             this.pMgr = pMgr;
             this.fs = fs;
-            this.ntReg = ntReg;
             this.escFactory = new DynamicESCFactory(obsMgr);
 
             // need to store the version storage root directly into the persistence manager
@@ -257,37 +252,20 @@
             synchronized (versionItems) {
                 InternalVersionItem item = (InternalVersionItem) versionItems.get(id);
                 if (item == null) {
-                    if (stateMgr.hasItemState(id)) {
-                        NodeState state = (NodeState) stateMgr.getItemState(id);
-                        NodeStateEx pNode = new NodeStateEx(stateMgr, ntReg, state, null);
-                        NodeId parentId = pNode.getParentId();
-                        InternalVersionItem parent = getItem(parentId);
-                        Name ntName = state.getNodeTypeName();
-                        if (ntName.equals(NameConstants.NT_FROZENNODE)) {
-                            item = new InternalFrozenNodeImpl(this, pNode, parent);
-                        } else if (ntName.equals(NameConstants.NT_VERSIONEDCHILD)) {
-                            item = new InternalFrozenVHImpl(this, pNode, parent);
-                        } else if (ntName.equals(NameConstants.NT_VERSION)) {
-                            item = ((InternalVersionHistory) parent).getVersion(id);
-                        } else if (ntName.equals(NameConstants.NT_VERSIONHISTORY)) {
-                            item = new InternalVersionHistoryImpl(this, pNode);
-                        } else {
-                            return null;
-                        }
+                    item = createInternalVersionItem(id);
+                    if (item != null) {
+                        versionItems.put(id, item);
                     } else {
                         return null;
                     }
-                    versionItems.put(id, item);
                 }
                 return item;
             }
-        } catch (ItemStateException e) {
-            throw new RepositoryException(e);
         } finally {
             releaseReadLock();
         }
     }
-
+    
     /**
      * {@inheritDoc}
      * <p/>

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=638303&r1=638302&r2=638303&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 Mar 18 03:17:26 2008
@@ -75,11 +75,6 @@
     private final VersionManagerImpl vMgr;
 
     /**
-     * Node type registry.
-     */
-    private NodeTypeRegistry ntReg;
-
-    /**
      * The session that uses this version manager.
      */
     private SessionImpl session;
@@ -100,9 +95,8 @@
     public XAVersionManager(VersionManagerImpl vMgr, NodeTypeRegistry ntReg,
                             SessionImpl session, ItemStateCacheFactory cacheFactory)
             throws RepositoryException {
-
+        super(ntReg);
         this.vMgr = vMgr;
-        this.ntReg = ntReg;
         this.session = session;
         this.stateMgr = new XAItemStateManager(vMgr.getSharedStateMgr(),
                 this, CHANGE_LOG_ATTRIBUTE_NAME, cacheFactory);
@@ -366,7 +360,13 @@
             history = makeLocalCopy(history);
             xaItems.put(history.getId(), history);
         }
-        return super.checkin(history, node);
+        InternalVersion version = super.checkin(history, node);
+        NodeId frozenNodeId = version.getFrozenNodeId();
+        InternalVersionItem frozenNode = createInternalVersionItem(frozenNodeId);
+        if (frozenNode != null) {
+            xaItems.put(frozenNodeId, frozenNode);
+        }
+        return version;
     }
 
     /**

Modified: jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/version/RestoreTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/version/RestoreTest.java?rev=638303&r1=638302&r2=638303&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/version/RestoreTest.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/version/RestoreTest.java
Tue Mar 18 03:17:26 2008
@@ -34,7 +34,9 @@
         UserTransactionImpl tx = new UserTransactionImpl(superuser);
         tx.begin();
         Version v10 = n.checkin();
+        String versionName = v10.getName();
         n.restore(v10, true);
+        assertEquals("Wrong version restored", versionName, n.getBaseVersion().getName());
         tx.commit();
     }
 }

Added: jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/version/TestAll.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/version/TestAll.java?rev=638303&view=auto
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/version/TestAll.java
(added)
+++ jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/version/TestAll.java
Tue Mar 18 03:17:26 2008
@@ -0,0 +1,42 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jackrabbit.core.version;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+/**
+ * Test suite that includes all jackrabbit core version tests.
+ */
+public class TestAll extends TestCase {
+
+    /**
+     * Returns a test suite that executes all tests inside this package.
+     *
+     * @return a test suite that executes all tests inside this package
+     */
+    public static Test suite() {
+        TestSuite suite = new TestSuite("Version tests");
+        // disabled because JCR-1481 is not yet fixed
+        //suite.addTestSuite(CheckinRemoveVersionTest.class);
+        suite.addTestSuite(RemoveVersionLabelTest.class);
+        suite.addTestSuite(RestoreTest.class);
+        suite.addTestSuite(VersionIteratorImplTest.class);
+        return suite;
+    }
+}

Propchange: jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/version/TestAll.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/version/VersionIteratorImplTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/version/VersionIteratorImplTest.java?rev=638303&r1=638302&r2=638303&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/version/VersionIteratorImplTest.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/version/VersionIteratorImplTest.java
Tue Mar 18 03:17:26 2008
@@ -48,6 +48,7 @@
 
         public Calendar getCreated() {return null;}
         public InternalFrozenNode getFrozenNode() {return null;}
+        public NodeId getFrozenNodeId() {return null;}
         public Name[] getLabels() {return null;}
         public Name getName() {return null;}
         public InternalVersion[] getPredecessors() {return null;}



Mime
View raw message