jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mreut...@apache.org
Subject svn commit: r1423368 - in /jackrabbit/oak/trunk: oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/version/ oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/ oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/query/ oak-jcr/src/main/java/org...
Date Tue, 18 Dec 2012 09:29:06 GMT
Author: mreutegg
Date: Tue Dec 18 09:29:02 2012
New Revision: 1423368

URL: http://svn.apache.org/viewvc?rev=1423368&view=rev
Log:
OAK-168: Basic JCR VersionManager support (WIP)
- implementation of methods that read from the version store

Modified:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/version/VersionHook.java
    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/query/QueryImpl.java
    jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/version/VersionDelegate.java
    jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/version/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/VersionManagerDelegate.java

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/version/VersionHook.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/version/VersionHook.java?rev=1423368&r1=1423367&r2=1423368&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/version/VersionHook.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/version/VersionHook.java
Tue Dec 18 09:29:02 2012
@@ -24,6 +24,7 @@ import javax.jcr.RepositoryException;
 import javax.jcr.nodetype.ConstraintViolationException;
 import javax.jcr.version.VersionException;
 
+import org.apache.jackrabbit.JcrConstants;
 import org.apache.jackrabbit.oak.api.CommitFailedException;
 import org.apache.jackrabbit.oak.api.PropertyState;
 import org.apache.jackrabbit.oak.api.Tree;
@@ -86,8 +87,14 @@ public class VersionHook implements Comm
             if (!isVersionable()) {
                 return;
             }
+            // JCR allows to put a lock on a checked in node.
+            if (after.getName().equals(JcrConstants.JCR_LOCKOWNER)
+                    || after.getName().equals(JcrConstants.JCR_LOCKISDEEP)) {
+                return;
+            }
             if (wasCheckedIn()) {
-                throwCheckedIn("Cannot add property on checked in node");
+                throwCheckedIn("Cannot add property " + after.getName() +
+                        " on checked in node");
             }
         }
 
@@ -95,7 +102,8 @@ public class VersionHook implements Comm
         public void propertyChanged(PropertyState before, PropertyState after) {
             if (!isVersionable()) {
                 if (!isVersionProperty(after) && wasCheckedIn()) {
-                    throwProtected("Cannot change property on checked in node");
+                    throwCheckedIn("Cannot change property " + after.getName() +
+                            " on checked in node");
                 }
                 return;
             }
@@ -111,7 +119,8 @@ public class VersionHook implements Comm
             } else if (isVersionProperty(after)) {
                 throwProtected(after.getName());
             } else if (wasCheckedIn()) {
-                throwCheckedIn("Cannot change property on checked in node");
+                throwCheckedIn("Cannot change property " + after.getName() +
+                        " on checked in node");
             }
         }
 

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=1423368&r1=1423367&r2=1423368&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 Dec 18 09:29:02 2012
@@ -53,6 +53,7 @@ import javax.jcr.nodetype.NodeType;
 import javax.jcr.nodetype.NodeTypeManager;
 import javax.jcr.nodetype.PropertyDefinition;
 import javax.jcr.version.Version;
+import javax.jcr.version.VersionException;
 import javax.jcr.version.VersionHistory;
 import javax.jcr.version.VersionManager;
 
@@ -870,6 +871,10 @@ public class NodeImpl<T extends NodeDele
     public void setPrimaryType(final String nodeTypeName) throws RepositoryException {
         checkStatus();
         checkProtected();
+        if (!isCheckedOut()) {
+            throw new VersionException("Cannot set primary type. Node is " +
+                    "checked in.");
+        }
 
         internalSetPrimaryType(nodeTypeName);
     }
@@ -940,9 +945,7 @@ public class NodeImpl<T extends NodeDele
                 ntm.getNodeType(mixinName); // throws on not found
                 // TODO: END
 
-                VersionManager vMgr = sessionDelegate.getVersionManager();
-                String path = toJcrPath(dlg.getPath());
-                return isSupportedMixinName(mixinName) && vMgr.isCheckedOut(path);
+                return isSupportedMixinName(mixinName) && isCheckedOut();
             }
         });
     }

Modified: jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/query/QueryImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/query/QueryImpl.java?rev=1423368&r1=1423367&r2=1423368&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/query/QueryImpl.java
(original)
+++ jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/query/QueryImpl.java
Tue Dec 18 09:29:02 2012
@@ -29,6 +29,8 @@ import javax.jcr.ValueFactory;
 import javax.jcr.query.InvalidQueryException;
 import javax.jcr.query.Query;
 import javax.jcr.query.QueryResult;
+import javax.jcr.version.VersionException;
+
 import org.apache.jackrabbit.JcrConstants;
 import org.apache.jackrabbit.oak.commons.PathUtils;
 import org.apache.jackrabbit.oak.jcr.NodeDelegate;
@@ -131,6 +133,10 @@ public class QueryImpl implements Query 
             throw new PathNotFoundException("The specified path does not exist: " + parent);
         }
         Node parentNode = new NodeImpl<NodeDelegate>(parentDelegate);
+        if (!parentNode.isCheckedOut()) {
+            throw new VersionException("Cannot store query. Node at " +
+                    absPath + " is checked in.");
+        }
         String nodeName = PathUtils.getName(oakPath);
         ValueFactory vf = sessionDelegate.getValueFactory();
         Node n = parentNode.addNode(nodeName, JcrConstants.NT_QUERY);

Modified: jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/version/VersionDelegate.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/version/VersionDelegate.java?rev=1423368&r1=1423367&r2=1423368&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/version/VersionDelegate.java
(original)
+++ jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/version/VersionDelegate.java
Tue Dec 18 09:29:02 2012
@@ -16,20 +16,25 @@
  */
 package org.apache.jackrabbit.oak.jcr.version;
 
+import javax.annotation.Nonnull;
+
 import org.apache.jackrabbit.oak.api.Tree;
 import org.apache.jackrabbit.oak.jcr.NodeDelegate;
 import org.apache.jackrabbit.oak.jcr.SessionDelegate;
 
+import static com.google.common.base.Preconditions.checkNotNull;
+
 /**
  * <code>VersionDelegate</code>...
  */
 public class VersionDelegate extends NodeDelegate {
 
     private VersionDelegate(SessionDelegate sessionDelegate, Tree tree) {
-        super(sessionDelegate, tree);
+        super(checkNotNull(sessionDelegate), checkNotNull(tree));
     }
 
-    static VersionDelegate create(SessionDelegate sessionDelegate, Tree tree) {
+    static VersionDelegate create(@Nonnull SessionDelegate sessionDelegate,
+                                  @Nonnull Tree tree) {
         return new VersionDelegate(sessionDelegate, tree);
     }
 }

Modified: jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/version/VersionHistoryDelegate.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/version/VersionHistoryDelegate.java?rev=1423368&r1=1423367&r2=1423368&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/version/VersionHistoryDelegate.java
(original)
+++ jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/version/VersionHistoryDelegate.java
Tue Dec 18 09:29:02 2012
@@ -16,14 +16,31 @@
  */
 package org.apache.jackrabbit.oak.jcr.version;
 
+import java.util.ArrayList;
+import java.util.Calendar;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.SortedMap;
+import java.util.TreeMap;
+
 import javax.annotation.Nonnull;
+import javax.annotation.Nullable;
 import javax.jcr.InvalidItemStateException;
+import javax.jcr.RepositoryException;
+import javax.jcr.version.VersionException;
 
 import org.apache.jackrabbit.JcrConstants;
+import org.apache.jackrabbit.oak.api.PropertyState;
 import org.apache.jackrabbit.oak.api.Tree;
 import org.apache.jackrabbit.oak.api.Type;
 import org.apache.jackrabbit.oak.jcr.NodeDelegate;
+import org.apache.jackrabbit.oak.jcr.PropertyDelegate;
 import org.apache.jackrabbit.oak.jcr.SessionDelegate;
+import org.apache.jackrabbit.oak.version.VersionConstants;
+
+import com.google.common.base.Function;
+import com.google.common.collect.Iterators;
 
 import static com.google.common.base.Preconditions.checkNotNull;
 
@@ -40,4 +57,110 @@ public class VersionHistoryDelegate exte
     public String getVersionableIdentifier() throws InvalidItemStateException {
         return getTree().getProperty(JcrConstants.JCR_VERSIONABLEUUID).getValue(Type.STRING);
     }
+
+    @Nonnull
+    public VersionDelegate getRootVersion() throws RepositoryException {
+        Tree rootVersion = getTree().getChild(VersionConstants.JCR_ROOTVERSION);
+        if (rootVersion == null) {
+            throw new RepositoryException("Inconsistent version storage. " +
+                    "VersionHistory does not have a root version");
+        }
+        return VersionDelegate.create(sessionDelegate, rootVersion);
+    }
+
+    @Nonnull
+    public VersionDelegate getVersion(@Nonnull String versionName)
+            throws VersionException, RepositoryException {
+        checkNotNull(versionName);
+        Tree version = getTree().getChild(versionName);
+        if (version == null) {
+            throw new VersionException("No such Version: " + versionName);
+        }
+        return VersionDelegate.create(sessionDelegate, version);
+    }
+
+    @Nonnull
+    public VersionDelegate getVersionByLabel(@Nonnull String label)
+            throws VersionException, RepositoryException {
+        checkNotNull(label);
+        Tree versionLabels = getVersionLabelsTree();
+        PropertyState p = versionLabels.getProperty(label);
+        if (p == null) {
+            throw new VersionException("Unknown label: " + label);
+        }
+        String id = p.getValue(Type.REFERENCE);
+        Tree version = sessionDelegate.getIdManager().getTree(id);
+        if (version == null) {
+            throw new VersionException("Invalid label: " + label + "(" + id + ")");
+        }
+        return VersionDelegate.create(sessionDelegate, version);
+    }
+
+    @Nonnull
+    public Iterable<String> getVersionLabels() throws RepositoryException {
+        Tree versionLabels = getVersionLabelsTree();
+        List<String> labels = new ArrayList<String>();
+        for (PropertyState p : versionLabels.getProperties()) {
+            if (p.getType() == Type.REFERENCE) {
+                labels.add(p.getName());
+            }
+        }
+        return labels;
+    }
+
+    @Nonnull
+    public Iterable<String> getVersionLabels(@Nonnull String identifier)
+            throws RepositoryException {
+        checkNotNull(identifier);
+        Tree versionLabels = getVersionLabelsTree();
+        List<String> labels = new ArrayList<String>();
+        for (PropertyState p : versionLabels.getProperties()) {
+            if (p.getType() == Type.REFERENCE
+                    && identifier.equals(p.getValue(Type.REFERENCE))) {
+                labels.add(p.getName());
+            }
+        }
+        return labels;
+    }
+
+    @Nonnull
+    public Iterator<VersionDelegate> getAllVersions()
+            throws RepositoryException {
+        SortedMap<Calendar, String> versions = new TreeMap<Calendar, String>();
+        for (Iterator<NodeDelegate> it = getChildren(); it.hasNext(); ) {
+            NodeDelegate n = it.next();
+            String primaryType = n.getProperty(JcrConstants.JCR_PRIMARYTYPE).getValue().getString();
+            if (primaryType.equals(VersionConstants.NT_VERSION)) {
+                PropertyDelegate created = n.getProperty(JcrConstants.JCR_CREATED);
+                if (created != null) {
+                    versions.put(created.getValue().getDate(), n.getName());
+                }
+            }
+        }
+        final Tree thisTree = getTree();
+        return Iterators.transform(versions.values().iterator(), new Function<String,
VersionDelegate>() {
+            @Override
+            public VersionDelegate apply(String name) {
+                return VersionDelegate.create(sessionDelegate, thisTree.getChild(name));
+            }
+        });
+    }
+
+    //-----------------------------< internal >---------------------------------
+
+    /**
+     * @return the jcr:versionLabels tree or throws a <code>RepositoryException</code>
+     *         if it doesn't exist.
+     * @throws RepositoryException if the jcr:versionLabels child does not
+     *                             exist.
+     */
+    @Nonnull
+    private Tree getVersionLabelsTree() throws RepositoryException {
+        Tree versionLabels = getTree().getChild(VersionConstants.JCR_VERSIONLABELS);
+        if (versionLabels == null) {
+            throw new RepositoryException("Inconsistent version storage. " +
+                    "VersionHistory does not have jcr:versionLabels child node");
+        }
+        return versionLabels;
+    }
 }

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=1423368&r1=1423367&r2=1423368&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 Dec 18 09:29:02 2012
@@ -16,6 +16,10 @@
  */
 package org.apache.jackrabbit.oak.jcr.version;
 
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
 import javax.jcr.AccessDeniedException;
 import javax.jcr.NodeIterator;
 import javax.jcr.ReferentialIntegrityException;
@@ -28,9 +32,14 @@ import javax.jcr.version.VersionHistory;
 import javax.jcr.version.VersionIterator;
 
 import org.apache.jackrabbit.commons.iterator.FrozenNodeIteratorAdapter;
+import org.apache.jackrabbit.commons.iterator.VersionIteratorAdapter;
 import org.apache.jackrabbit.oak.jcr.NodeImpl;
+import org.apache.jackrabbit.oak.namepath.NamePathMapper;
 import org.apache.jackrabbit.oak.util.TODO;
 
+import com.google.common.base.Function;
+import com.google.common.collect.Iterators;
+
 /**
  * <code>VersionHistoryImpl</code>...
  */
@@ -53,7 +62,7 @@ public class VersionHistoryImpl extends 
 
     @Override
     public Version getRootVersion() throws RepositoryException {
-        return TODO.unimplemented().returnValue(null);
+        return new VersionImpl(dlg.getRootVersion());
     }
 
     @Override
@@ -63,7 +72,13 @@ public class VersionHistoryImpl extends 
 
     @Override
     public VersionIterator getAllVersions() throws RepositoryException {
-        return TODO.unimplemented().returnValue(null);
+        return new VersionIteratorAdapter(Iterators.transform(
+                dlg.getAllVersions(), new Function<VersionDelegate, Version>() {
+            @Override
+            public Version apply(VersionDelegate input) {
+                return new VersionImpl(input);
+            }
+        }));
     }
 
     @Override
@@ -79,13 +94,14 @@ public class VersionHistoryImpl extends 
     @Override
     public Version getVersion(String versionName)
             throws VersionException, RepositoryException {
-        return TODO.unimplemented().returnValue(null);
+        return new VersionImpl(dlg.getVersion(versionName));
     }
 
     @Override
     public Version getVersionByLabel(String label)
             throws VersionException, RepositoryException {
-        return TODO.unimplemented().returnValue(null);
+        String oakLabel = sessionDelegate.getOakNameOrThrow(label);
+        return new VersionImpl(dlg.getVersionByLabel(oakLabel));
     }
 
     @Override
@@ -94,35 +110,49 @@ public class VersionHistoryImpl extends 
                                 boolean moveLabel)
             throws LabelExistsVersionException, VersionException,
             RepositoryException {
-        TODO.unimplemented();
+        TODO.unimplemented().doNothing();
     }
 
     @Override
     public void removeVersionLabel(String label)
             throws VersionException, RepositoryException {
-        TODO.unimplemented();
+        TODO.unimplemented().doNothing();
     }
 
     @Override
     public boolean hasVersionLabel(String label) throws RepositoryException {
-        return TODO.unimplemented().returnValue(Boolean.FALSE);
+        return Arrays.asList(getVersionLabels()).contains(label);
     }
 
     @Override
     public boolean hasVersionLabel(Version version, String label)
             throws VersionException, RepositoryException {
-        return TODO.unimplemented().returnValue(Boolean.FALSE);
+        return Arrays.asList(getVersionLabels(version)).contains(label);
     }
 
     @Override
     public String[] getVersionLabels() throws RepositoryException {
-        return TODO.unimplemented().returnValue(new String[0]);
+        NamePathMapper mapper = sessionDelegate.getNamePathMapper();
+        List<String> labels = new ArrayList<String>();
+        for (String label : dlg.getVersionLabels()) {
+            labels.add(mapper.getJcrName(label));
+        }
+        return labels.toArray(new String[labels.size()]);
     }
 
     @Override
     public String[] getVersionLabels(Version version)
             throws VersionException, RepositoryException {
-        return TODO.unimplemented().returnValue(new String[0]);
+        if (!version.getContainingHistory().getPath().equals(getPath())) {
+            throw new VersionException("Version is not contained in this " +
+                    "VersionHistory");
+        }
+        NamePathMapper mapper = sessionDelegate.getNamePathMapper();
+        List<String> labels = new ArrayList<String>();
+        for (String label : dlg.getVersionLabels(version.getIdentifier())) {
+            labels.add(mapper.getJcrName(label));
+        }
+        return labels.toArray(new String[labels.size()]);
     }
 
     @Override
@@ -130,6 +160,6 @@ public class VersionHistoryImpl extends 
             throws ReferentialIntegrityException, AccessDeniedException,
             UnsupportedRepositoryOperationException, VersionException,
             RepositoryException {
-        TODO.unimplemented();
+        TODO.unimplemented().doNothing();
     }
 }

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=1423368&r1=1423367&r2=1423368&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 Dec 18 09:29:02 2012
@@ -16,17 +16,26 @@
  */
 package org.apache.jackrabbit.oak.jcr.version;
 
+import java.util.ArrayList;
 import java.util.Calendar;
+import java.util.List;
 
+import javax.annotation.Nonnull;
 import javax.jcr.Node;
 import javax.jcr.RepositoryException;
+import javax.jcr.Value;
 import javax.jcr.version.Version;
 import javax.jcr.version.VersionHistory;
 
 import org.apache.jackrabbit.JcrConstants;
 import org.apache.jackrabbit.oak.jcr.NodeDelegate;
 import org.apache.jackrabbit.oak.jcr.NodeImpl;
+import org.apache.jackrabbit.oak.jcr.PropertyDelegate;
+import org.apache.jackrabbit.oak.jcr.SessionDelegate;
 import org.apache.jackrabbit.oak.util.TODO;
+import org.apache.jackrabbit.oak.version.VersionConstants;
+
+import static com.google.common.base.Preconditions.checkNotNull;
 
 class VersionImpl extends NodeImpl<VersionDelegate> implements Version {
 
@@ -36,12 +45,13 @@ class VersionImpl extends NodeImpl<Versi
 
     @Override
     public VersionHistory getContainingHistory() throws RepositoryException {
-        return TODO.unimplemented().returnValue(null);
+        return new VersionHistoryImpl(
+                getVersionManagerDelegate().getVersionHistory(dlg.getParent()));
     }
 
     @Override
     public Calendar getCreated() throws RepositoryException {
-        return TODO.unimplemented().returnValue(Calendar.getInstance());
+        return getPropertyOrThrow(JcrConstants.JCR_CREATED).getValue().getDate();
     }
 
     @Override
@@ -56,17 +66,49 @@ class VersionImpl extends NodeImpl<Versi
 
     @Override
     public Version[] getPredecessors() throws RepositoryException {
-        return TODO.unimplemented().returnValue(new Version[0]);
+        PropertyDelegate p = getPropertyOrThrow(VersionConstants.JCR_PREDECESSORS);
+        List<Version> predecessors = new ArrayList<Version>();
+        VersionManagerDelegate vMgr = getVersionManagerDelegate();
+        for (Value v : p.getValues()) {
+            String id = v.getString();
+            predecessors.add(new VersionImpl(vMgr.getVersionByIdentifier(id)));
+        }
+        return predecessors.toArray(new Version[predecessors.size()]);
     }
 
     @Override
     public Version[] getSuccessors() throws RepositoryException {
-        return TODO.unimplemented().returnValue(new Version[0]);
+        PropertyDelegate p = getPropertyOrThrow(VersionConstants.JCR_SUCCESSORS);
+        List<Version> successors = new ArrayList<Version>();
+        VersionManagerDelegate vMgr = getVersionManagerDelegate();
+        for (Value v : p.getValues()) {
+            String id = v.getString();
+            successors.add(new VersionImpl(vMgr.getVersionByIdentifier(id)));
+        }
+        return successors.toArray(new Version[successors.size()]);
     }
 
     @Override
     public Node getFrozenNode() throws RepositoryException {
-        return TODO.unimplemented().returnValue(null);
+        return new NodeImpl<NodeDelegate>(
+                dlg.getChild(VersionConstants.JCR_FROZENNODE));
     }
 
+    //------------------------------< internal >--------------------------------
+
+    @Nonnull
+    private VersionManagerDelegate getVersionManagerDelegate() {
+        return VersionManagerDelegate.create(dlg.getSessionDelegate());
+    }
+
+    @Nonnull
+    private PropertyDelegate getPropertyOrThrow(@Nonnull String name)
+            throws RepositoryException {
+        PropertyDelegate p = dlg.getProperty(checkNotNull(name));
+        if (p == null) {
+            throw new RepositoryException("Inconsistent version storage. " +
+                    "Version does not have a " + name + " property.");
+        }
+        return p;
+    }
 }

Modified: jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/version/VersionManagerDelegate.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/version/VersionManagerDelegate.java?rev=1423368&r1=1423367&r2=1423368&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/version/VersionManagerDelegate.java
(original)
+++ jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/version/VersionManagerDelegate.java
Tue Dec 18 09:29:02 2012
@@ -105,6 +105,17 @@ public class VersionManagerDelegate {
         return VersionDelegate.create(sessionDelegate, v);
     }
 
+    @Nonnull
+    public VersionDelegate getVersionByIdentifier(@Nonnull String identifier)
+            throws RepositoryException {
+        Tree t = sessionDelegate.getIdManager().getTree(identifier);
+        if (t == null) {
+            throw new RepositoryException("No such Version with identifier: " +
+                    identifier);
+        }
+        return VersionDelegate.create(sessionDelegate, t);
+    }
+
     //----------------------------< internal >----------------------------------
 
     /**



Mime
View raw message