jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mreut...@apache.org
Subject svn commit: r1513387 - in /jackrabbit/oak/trunk/oak-jcr: ./ src/main/java/org/apache/jackrabbit/oak/jcr/ src/main/java/org/apache/jackrabbit/oak/jcr/delegate/ src/main/java/org/apache/jackrabbit/oak/jcr/version/
Date Tue, 13 Aug 2013 08:19:11 GMT
Author: mreutegg
Date: Tue Aug 13 08:19:11 2013
New Revision: 1513387

URL: http://svn.apache.org/r1513387
Log:
OAK-168: Basic JCR VersionManager support
- Successor/predecessor implementation
- Verify node is lockable in Node.lock/unlock()
- Enable more tests

Modified:
    jackrabbit/oak/trunk/oak-jcr/pom.xml
    jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/NodeImpl.java
    jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/delegate/VersionDelegate.java
    jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/delegate/VersionHistoryDelegate.java
    jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/version/VersionHistoryImpl.java
    jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/version/VersionImpl.java
    jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/version/VersionManagerImpl.java

Modified: jackrabbit/oak/trunk/oak-jcr/pom.xml
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/pom.xml?rev=1513387&r1=1513386&r2=1513387&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/pom.xml (original)
+++ jackrabbit/oak/trunk/oak-jcr/pom.xml Tue Aug 13 08:19:11 2013
@@ -199,38 +199,21 @@
       org.apache.jackrabbit.test.api.observation.LockingTest#testRemoveLockFromNode
 
       <!-- Versioning -->
-      org.apache.jackrabbit.test.api.version.VersionTest#testRestore
-      org.apache.jackrabbit.test.api.version.VersionTest#testUnlock
-      org.apache.jackrabbit.test.api.version.VersionTest#testUnlockJcr2
       org.apache.jackrabbit.test.api.version.VersionTest#testUpdate
       org.apache.jackrabbit.test.api.version.VersionTest#testGetCorrespondingNodePath
       org.apache.jackrabbit.test.api.version.VersionTest#testGetLock
       org.apache.jackrabbit.test.api.version.VersionTest#testGetLockJcr2
-      org.apache.jackrabbit.test.api.version.VersionTest#testLock
-      org.apache.jackrabbit.test.api.version.VersionTest#testLockJcr2
       org.apache.jackrabbit.test.api.version.VersionTest#testMerge
-      org.apache.jackrabbit.test.api.version.VersionHistoryTest#testRestore
-      org.apache.jackrabbit.test.api.version.VersionHistoryTest#testUnlock
-      org.apache.jackrabbit.test.api.version.VersionHistoryTest#testUnlockJcr2
       org.apache.jackrabbit.test.api.version.VersionHistoryTest#testUpdate
       org.apache.jackrabbit.test.api.version.VersionHistoryTest#testGetCorrespondingNodePath
       org.apache.jackrabbit.test.api.version.VersionHistoryTest#testGetLock
       org.apache.jackrabbit.test.api.version.VersionHistoryTest#testGetLockJcr2
-      org.apache.jackrabbit.test.api.version.VersionHistoryTest#testLock
-      org.apache.jackrabbit.test.api.version.VersionHistoryTest#testLockJcr2
       org.apache.jackrabbit.test.api.version.VersionHistoryTest#testMerge
-      org.apache.jackrabbit.test.api.version.VersionHistoryTest#testInitialNumberOfLinearVersions
-      org.apache.jackrabbit.test.api.version.VersionHistoryTest#testInitiallyGetAllLinearVersionsContainsTheRootAndTheBaseVersion
       org.apache.jackrabbit.test.api.version.CopyTest
       org.apache.jackrabbit.test.api.version.RestoreTest#testRestoreWithUUIDConflict
-      org.apache.jackrabbit.test.api.version.RestoreTest#testRestoreOrderJcr2
-      org.apache.jackrabbit.test.api.version.RestoreTest#testRestoreOrderJcr2_2
-      org.apache.jackrabbit.test.api.version.RestoreTest#testRestoreOrderJcr2_3
-      org.apache.jackrabbit.test.api.version.RestoreTest#testRestoreOrderJcr2_4
       org.apache.jackrabbit.test.api.version.RestoreTest#testRestoreLabel
       org.apache.jackrabbit.test.api.version.RestoreTest#testRestoreLabelJcr2
       org.apache.jackrabbit.test.api.version.WorkspaceRestoreTest
-      org.apache.jackrabbit.test.api.version.GetPredecessorsTest
       org.apache.jackrabbit.test.api.version.GetReferencesNodeTest#testGetReferencesNeverFromVersions
<!-- Node.getReferences must not return references from version storage -->
       org.apache.jackrabbit.test.api.version.MergeCancelMergeTest
       org.apache.jackrabbit.test.api.version.MergeCheckedoutSubNodeTest

Modified: jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/NodeImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/NodeImpl.java?rev=1513387&r1=1513386&r2=1513387&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/NodeImpl.java
(original)
+++ jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/NodeImpl.java
Tue Aug 13 08:19:11 2013
@@ -41,6 +41,7 @@ import javax.jcr.RepositoryException;
 import javax.jcr.UnsupportedRepositoryOperationException;
 import javax.jcr.Value;
 import javax.jcr.lock.Lock;
+import javax.jcr.lock.LockException;
 import javax.jcr.nodetype.ConstraintViolationException;
 import javax.jcr.nodetype.NodeDefinition;
 import javax.jcr.nodetype.NodeType;
@@ -91,6 +92,7 @@ import static javax.jcr.Property.JCR_LOC
 import static javax.jcr.Property.JCR_LOCK_OWNER;
 import static org.apache.jackrabbit.JcrConstants.JCR_MIXINTYPES;
 import static org.apache.jackrabbit.JcrConstants.JCR_PRIMARYTYPE;
+import static org.apache.jackrabbit.JcrConstants.MIX_LOCKABLE;
 import static org.apache.jackrabbit.oak.api.Type.NAME;
 import static org.apache.jackrabbit.oak.api.Type.NAMES;
 
@@ -1161,6 +1163,7 @@ public class NodeImpl<T extends NodeDele
     @Nonnull
     public Lock lock(final boolean isDeep, boolean isSessionScoped)
             throws RepositoryException {
+        checkLockable();
         // TODO: use perform()
         ContentSession session = sessionDelegate.getContentSession();
         final String userID = session.getAuthInfo().getUserID();
@@ -1195,6 +1198,7 @@ public class NodeImpl<T extends NodeDele
      */
     @Override
     public void unlock() throws RepositoryException {
+        checkLockable();
         // TODO: use perform
         String lockOwner = getOakPathOrThrow(JCR_LOCK_OWNER);
         String lockIsDeep = getOakPathOrThrow(JCR_LOCK_IS_DEEP);
@@ -1259,6 +1263,24 @@ public class NodeImpl<T extends NodeDele
 
     //------------------------------------------------------------< internal >---
 
+    /**
+     * Checks if this node is lockable; otherwise throws a LockException.
+     * @throws LockException if the node is not lockable.
+     */
+    private void checkLockable() throws RepositoryException {
+        perform(new NodeOperation<Void>(dlg) {
+            @Override
+            public Void perform() throws RepositoryException {
+                if (!getNodeTypeManager().isNodeType(node.getTree(), MIX_LOCKABLE)) {
+                    String msg = "Unable to perform a locking operation on a non-lockable
node: " + getPath();
+                    log.debug(msg);
+                    throw new LockException(msg);
+                }
+                return null;
+            }
+        });
+    }
+
     private EffectiveNodeType getEffectiveNodeType() throws RepositoryException {
         return getNodeTypeManager().getEffectiveNodeType(dlg.getTree());
     }

Modified: jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/delegate/VersionDelegate.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/delegate/VersionDelegate.java?rev=1513387&r1=1513386&r2=1513387&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/delegate/VersionDelegate.java
(original)
+++ jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/delegate/VersionDelegate.java
Tue Aug 13 08:19:11 2013
@@ -16,13 +16,20 @@
  */
 package org.apache.jackrabbit.oak.jcr.delegate;
 
+import java.util.List;
+
 import static com.google.common.base.Preconditions.checkNotNull;
+import static org.apache.jackrabbit.JcrConstants.JCR_PREDECESSORS;
 
+import javax.annotation.CheckForNull;
 import javax.annotation.Nonnull;
 import javax.jcr.RepositoryException;
 
 import org.apache.jackrabbit.JcrConstants;
 import org.apache.jackrabbit.oak.api.Tree;
+import org.apache.jackrabbit.oak.api.Type;
+
+import com.google.common.collect.Lists;
 
 /**
  * {@code VersionDelegate}...
@@ -47,4 +54,30 @@ public class VersionDelegate extends Nod
         }
         return frozenNode;
     }
+
+    @Nonnull
+    public Iterable<VersionDelegate> getPredecessors()
+            throws RepositoryException {
+        PropertyDelegate p = getPropertyOrNull(JCR_PREDECESSORS);
+        if (p == null) {
+            throw new RepositoryException("Inconsistent version storage. " +
+                    "Version does not have a " + JCR_PREDECESSORS + " property.");
+        }
+        List<VersionDelegate> predecessors = Lists.newArrayList();
+        VersionManagerDelegate vMgr = VersionManagerDelegate.create(sessionDelegate);
+        for (String id : p.getMultiState().getValue(Type.REFERENCES)) {
+            predecessors.add(vMgr.getVersionByIdentifier(id));
+        }
+        return predecessors;
+    }
+
+    @CheckForNull
+    public VersionDelegate getLinearPredecessor() throws RepositoryException {
+        Iterable<VersionDelegate> predecessors = getPredecessors();
+        if (predecessors.iterator().hasNext()) {
+            // return first predecessor (same behavior as Jackrabbit)
+            return predecessors.iterator().next();
+        }
+        return null;
+    }
 }

Modified: jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/delegate/VersionHistoryDelegate.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/delegate/VersionHistoryDelegate.java?rev=1513387&r1=1513386&r2=1513387&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/delegate/VersionHistoryDelegate.java
(original)
+++ jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/delegate/VersionHistoryDelegate.java
Tue Aug 13 08:19:11 2013
@@ -17,9 +17,13 @@
 package org.apache.jackrabbit.oak.jcr.delegate;
 
 import static com.google.common.base.Preconditions.checkNotNull;
+import static org.apache.jackrabbit.JcrConstants.JCR_BASEVERSION;
 
+import java.util.ArrayDeque;
 import java.util.ArrayList;
 import java.util.Calendar;
+import java.util.Collections;
+import java.util.Deque;
 import java.util.Iterator;
 import java.util.List;
 import java.util.SortedMap;
@@ -33,6 +37,8 @@ import javax.jcr.version.VersionExceptio
 
 import com.google.common.base.Function;
 import com.google.common.collect.Iterators;
+import com.google.common.collect.Lists;
+
 import org.apache.jackrabbit.JcrConstants;
 import org.apache.jackrabbit.oak.api.PropertyState;
 import org.apache.jackrabbit.oak.api.Tree;
@@ -151,6 +157,26 @@ public class VersionHistoryDelegate exte
         });
     }
 
+    @Nonnull
+    public Iterator<VersionDelegate> getAllLinearVersions()
+            throws RepositoryException {
+        String id = getVersionableIdentifier();
+        NodeDelegate versionable = sessionDelegate.getNodeByIdentifier(id);
+        if (versionable == null
+                || versionable.getPropertyOrNull(JCR_BASEVERSION) == null) {
+            return Iterators.emptyIterator();
+        }
+        Deque<VersionDelegate> linearVersions = new ArrayDeque<VersionDelegate>();
+        VersionManagerDelegate vMgr = VersionManagerDelegate.create(sessionDelegate);
+        VersionDelegate version = vMgr.getVersionByIdentifier(
+                versionable.getProperty(JCR_BASEVERSION).getString());
+        while (version != null) {
+            linearVersions.add(version);
+            version = version.getLinearPredecessor();
+        }
+        return linearVersions.descendingIterator();
+    }
+
     public void addVersionLabel(@Nonnull VersionDelegate version,
                                 @Nonnull String oakVersionLabel,
                                 boolean moveLabel)

Modified: jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/version/VersionHistoryImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/version/VersionHistoryImpl.java?rev=1513387&r1=1513386&r2=1513387&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/version/VersionHistoryImpl.java
(original)
+++ jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/version/VersionHistoryImpl.java
Tue Aug 13 08:19:11 2013
@@ -80,7 +80,18 @@ public class VersionHistoryImpl extends 
 
     @Override
     public VersionIterator getAllLinearVersions() throws RepositoryException {
-        return TODO.unimplemented().returnValue(null);
+        return perform(new SessionOperation<VersionIterator>() {
+            @Override
+            public VersionIterator perform() throws RepositoryException {
+                return new VersionIteratorAdapter(Iterators.transform(
+                        dlg.getAllLinearVersions(), new Function<VersionDelegate, Version>()
{
+                    @Override
+                    public Version apply(VersionDelegate input) {
+                        return new VersionImpl(input, sessionContext);
+                    }
+                }));
+            }
+        });
     }
 
     @Override

Modified: jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/version/VersionImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/version/VersionImpl.java?rev=1513387&r1=1513386&r2=1513387&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/version/VersionImpl.java
(original)
+++ jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/version/VersionImpl.java
Tue Aug 13 08:19:11 2013
@@ -20,6 +20,7 @@ import static com.google.common.base.Pre
 
 import java.util.ArrayList;
 import java.util.Calendar;
+import java.util.Iterator;
 import java.util.List;
 
 import javax.annotation.Nonnull;
@@ -36,11 +37,11 @@ import org.apache.jackrabbit.oak.jcr.Nod
 import org.apache.jackrabbit.oak.jcr.SessionContext;
 import org.apache.jackrabbit.oak.jcr.delegate.PropertyDelegate;
 import org.apache.jackrabbit.oak.jcr.delegate.VersionDelegate;
+import org.apache.jackrabbit.oak.jcr.delegate.VersionHistoryDelegate;
 import org.apache.jackrabbit.oak.jcr.delegate.VersionManagerDelegate;
 import org.apache.jackrabbit.oak.jcr.operation.SessionOperation;
 import org.apache.jackrabbit.oak.plugins.value.ValueFactoryImpl;
 import org.apache.jackrabbit.oak.plugins.version.VersionConstants;
-import org.apache.jackrabbit.oak.util.TODO;
 
 public class VersionImpl extends NodeImpl<VersionDelegate> implements Version {
 
@@ -73,12 +74,40 @@ public class VersionImpl extends NodeImp
 
     @Override
     public Version getLinearPredecessor() throws RepositoryException {
-        return TODO.unimplemented().returnValue(null);
+        return perform(new SessionOperation<Version>() {
+            @Override
+            public Version perform() throws RepositoryException {
+                VersionDelegate predecessor = dlg.getLinearPredecessor();
+                if (predecessor == null) {
+                    return null;
+                } else {
+                    return new VersionImpl(predecessor, sessionContext);
+                }
+            }
+        });
     }
 
     @Override
     public Version getLinearSuccessor() throws RepositoryException {
-        return TODO.unimplemented().returnValue(null);
+        return perform(new SessionOperation<Version>() {
+            @Override
+            public Version perform() throws RepositoryException {
+                VersionHistoryDelegate vHistory = getVersionManagerDelegate()
+                        .createVersionHistory(dlg.getParent());
+                Iterator<VersionDelegate> it = vHistory.getAllLinearVersions();
+                // search for this version ...
+                while (it.hasNext()) {
+                    VersionDelegate vDlg = it.next();
+                    if (vDlg.getIdentifier().equals(dlg.getIdentifier())
+                            && it.hasNext()) {
+                        // ... and return next
+                        return new VersionImpl(it.next(), sessionContext);
+                    }
+                }
+                // none found
+                return null;
+            }
+        });
     }
 
     private List<Value> getValues(PropertyDelegate p) throws InvalidItemStateException,
ValueFormatException {
@@ -90,12 +119,9 @@ public class VersionImpl extends NodeImp
         return perform(new SessionOperation<Version[]>() {
             @Override
             public Version[] perform() throws RepositoryException {
-                PropertyDelegate p = getPropertyOrThrow(VersionConstants.JCR_PREDECESSORS);
                 List<Version> predecessors = new ArrayList<Version>();
-                VersionManagerDelegate vMgr = getVersionManagerDelegate();
-                for (Value v : getValues(p)) {
-                    String id = v.getString();
-                    predecessors.add(new VersionImpl(vMgr.getVersionByIdentifier(id), sessionContext));
+                for (VersionDelegate vDelegate : dlg.getPredecessors()) {
+                    predecessors.add(new VersionImpl(vDelegate, sessionContext));
                 }
                 return predecessors.toArray(new Version[predecessors.size()]);
             }

Modified: jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/version/VersionManagerImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/version/VersionManagerImpl.java?rev=1513387&r1=1513386&r2=1513387&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/version/VersionManagerImpl.java
(original)
+++ jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/version/VersionManagerImpl.java
Tue Aug 13 08:19:11 2013
@@ -124,7 +124,7 @@ public class VersionManagerImpl implemen
                     sessionDelegate.getRoot().commit();
                     success = true;
                 } catch (CommitFailedException e) {
-                    throw new RepositoryException(e);
+                    throw e.asRepositoryException();
                 } finally {
                     if (!success) {
                         // refresh if one of the modifying operations fail



Mime
View raw message