You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jackrabbit.apache.org by tr...@apache.org on 2009/07/23 17:05:45 UTC
svn commit: r797094 - in /jackrabbit/trunk:
jackrabbit-core/src/main/java/org/apache/jackrabbit/core/
jackrabbit-core/src/main/java/org/apache/jackrabbit/core/version/
jackrabbit-core/src/main/resources/org/apache/jackrabbit/core/nodetype/
jackrabbit-s...
Author: tripod
Date: Thu Jul 23 15:05:44 2009
New Revision: 797094
URL: http://svn.apache.org/viewvc?rev=797094&view=rev
Log:
JCR-2140: Baselines & Configurations
Modified:
jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/VersionManagerImpl.java
jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/version/InternalBaseline.java
jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/version/InternalBaselineImpl.java
jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/version/InternalVersionHistoryImpl.java
jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/version/InternalVersionManager.java
jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/version/InternalVersionManagerBase.java
jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/version/InternalVersionManagerImpl.java
jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/version/InternalXAVersionManager.java
jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/version/VersionManagerImplBase.java
jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/version/VersionManagerImplConfig.java
jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/version/VersionManagerImplRestore.java
jackrabbit/trunk/jackrabbit-core/src/main/resources/org/apache/jackrabbit/core/nodetype/builtin_nodetypes.cnd
jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/name/NameConstants.java
Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/VersionManagerImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/VersionManagerImpl.java?rev=797094&r1=797093&r2=797094&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/VersionManagerImpl.java (original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/VersionManagerImpl.java Thu Jul 23 15:05:44 2009
@@ -155,7 +155,7 @@
// check for pending changes
if (session.hasPendingChanges()) {
String msg = "Unable to restore version. Session has pending changes.";
- log.debug(msg);
+ log.error(msg);
throw new InvalidItemStateException(msg);
}
// add all versions to map of versions to restore
@@ -165,7 +165,9 @@
// check for collision
NodeId historyId = v.getVersionHistory().getId();
if (toRestore.containsKey(historyId)) {
- throw new VersionException("Unable to restore. Two or more versions have same version history.");
+ String msg = "Unable to restore. Two or more versions have same version history.";
+ log.error(msg);
+ throw new VersionException(msg);
}
toRestore.put(historyId, v);
}
@@ -285,7 +287,9 @@
if (!srcWorkspaceName.equals(session.getWorkspace().getName())) {
// check authorization for specified workspace
if (!session.getAccessManager().canAccess(srcWorkspaceName)) {
- throw new AccessDeniedException("not authorized to access " + srcWorkspaceName);
+ String msg = "not authorized to access " + srcWorkspaceName;
+ log.error(msg);
+ throw new AccessDeniedException(msg);
}
// get root node of src workspace
SessionImpl srcSession = null;
@@ -342,8 +346,9 @@
if (session.nodeExists(absPath)) {
// refuse to create a configuration if a baseline is specified.
if (baseline != null) {
- throw new UnsupportedRepositoryOperationException(
- "Create configuration to existing nodes only allowed without specifying a basline: " + absPath);
+ String msg = "Create configuration to existing nodes only allowed without specifying a basline: " + absPath;
+ log.error(msg);
+ throw new UnsupportedRepositoryOperationException(msg);
}
NodeStateEx state = getNodeState(absPath,
ItemValidator.CHECK_LOCK | ItemValidator.CHECK_PENDING_CHANGES_ON_NODE | ItemValidator.CHECK_HOLD,
@@ -353,7 +358,9 @@
throw new UnsupportedRepositoryOperationException("Node not full versionable: " + absPath);
}
if (state.getPropertyValue(NameConstants.JCR_CONFIGURATION) != null) {
- throw new UnsupportedRepositoryOperationException("Node is already a configuration root: " + absPath);
+ String msg = "Node is already a configuration root: " + absPath;
+ log.error(msg);
+ throw new UnsupportedRepositoryOperationException(msg);
}
NodeId configId = createConfiguration(state);
@@ -361,14 +368,16 @@
} else {
// check if supplied baseline is valid
if (baseline == null) {
- throw new UnsupportedRepositoryOperationException(
- "CreateConfiguration on non-existing path must supply a baseline: " + absPath);
+ String msg = "CreateConfiguration on non-existing path must supply a baseline: " + absPath;
+ log.error(msg);
+ throw new UnsupportedRepositoryOperationException(msg);
}
VersionImpl v = (VersionImpl) baseline;
InternalBaseline bl = vMgr.getBaseline(v.getNodeId());
if (bl == null) {
- throw new UnsupportedRepositoryOperationException(
- "Supplied version is not a baseline: " + v.safeGetJCRPath());
+ String msg = "Supplied version is not a baseline: " + v.safeGetJCRPath();
+ log.error(msg);
+ throw new UnsupportedRepositoryOperationException(msg);
}
// parent has to exist
@@ -395,7 +404,9 @@
} else {
NodeImpl actNode = (NodeImpl) activity;
if (!actNode.isNodeType(NameConstants.NT_ACTIVITY)) {
- throw new UnsupportedRepositoryOperationException("Given node is not an activity.");
+ String msg = "Given node is not an activity: " + actNode.safeGetJCRPath();
+ log.error(msg);
+ throw new UnsupportedRepositoryOperationException(msg);
}
currentActivity = actNode.getNodeId();
}
@@ -427,7 +438,9 @@
public void removeActivity(Node node) throws RepositoryException {
NodeImpl actNode = (NodeImpl) node;
if (!actNode.isNodeType(NameConstants.NT_ACTIVITY)) {
- throw new UnsupportedRepositoryOperationException("Given node is not an activity.");
+ String msg = "Given node is not an activity: " + actNode.safeGetJCRPath();
+ log.error(msg);
+ throw new UnsupportedRepositoryOperationException(msg);
}
NodeId actId = actNode.getNodeId();
vMgr.removeActivity(session, actId);
@@ -442,11 +455,15 @@
public NodeIterator merge(Node activityNode) throws RepositoryException {
NodeImpl actNode = (NodeImpl) activityNode;
if (!actNode.isNodeType(NameConstants.NT_ACTIVITY)) {
- throw new UnsupportedRepositoryOperationException("Given node is not an activity.");
+ String msg = "Given node is not an activity: " + actNode.safeGetJCRPath();
+ log.error(msg);
+ throw new UnsupportedRepositoryOperationException(msg);
}
InternalActivity activity = vMgr.getActivity(actNode.getNodeId());
if (activity == null) {
- throw new UnsupportedRepositoryOperationException("Given activity not found.");
+ String msg = "Given activity not found in version storage.";
+ log.error(msg);
+ throw new UnsupportedRepositoryOperationException(msg);
}
List<ItemId> failedIds = new ArrayList<ItemId>();
merge(activity, failedIds);
Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/version/InternalBaseline.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/version/InternalBaseline.java?rev=797094&r1=797093&r2=797094&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/version/InternalBaseline.java (original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/version/InternalBaseline.java Thu Jul 23 15:05:44 2009
@@ -18,6 +18,8 @@
import javax.jcr.RepositoryException;
+import org.apache.jackrabbit.core.id.NodeId;
+
/**
* This interface defines the internal baseline.
* <p/>
@@ -40,4 +42,19 @@
*/
VersionSet getBaseVersions() throws RepositoryException;
+ /**
+ * Returns the id of the nt:configuration node. this is basically the
+ * versionable id of the history.
+ *
+ * @return the configuration node id
+ */
+ NodeId getConfigurationId();
+
+ /**
+ * Returns the id of the root node of a workspace configuration. this is
+ * basically the jcr:root property of the frozen configuration.
+ *
+ * @return the configuration root node id
+ */
+ NodeId getConfigurationRootId();
}
\ No newline at end of file
Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/version/InternalBaselineImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/version/InternalBaselineImpl.java?rev=797094&r1=797093&r2=797094&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/version/InternalBaselineImpl.java (original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/version/InternalBaselineImpl.java Thu Jul 23 15:05:44 2009
@@ -16,10 +16,15 @@
*/
package org.apache.jackrabbit.core.version;
+import java.util.HashMap;
+import java.util.Map;
+
import javax.jcr.RepositoryException;
-import javax.jcr.UnsupportedRepositoryOperationException;
+import org.apache.jackrabbit.core.id.NodeId;
+import org.apache.jackrabbit.core.value.InternalValue;
import org.apache.jackrabbit.spi.Name;
+import org.apache.jackrabbit.spi.commons.name.NameConstants;
/**
* Implements a internal representation of a baseline node.
@@ -44,7 +49,32 @@
* {@inheritDoc}
*/
public VersionSet getBaseVersions() throws RepositoryException {
- throw new UnsupportedRepositoryOperationException("InternalBaseline.getBaseversions()");
+ InternalValue[] vs = ((InternalFrozenNodeImpl) getFrozenNode()).node.
+ getPropertyValues(NameConstants.REP_VERSIONS);
+ Map<NodeId, InternalVersion> versions = new HashMap<NodeId, InternalVersion>();
+ if (vs != null) {
+ for (InternalValue v: vs) {
+ InternalVersion iv = vMgr.getVersion(v.getNodeId());
+ if (iv != null) {
+ versions.put(iv.getVersionHistory().getId(), iv);
+ }
+ }
+ }
+ return new VersionSet(versions);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public NodeId getConfigurationId() {
+ return getVersionHistory().getVersionableId();
}
+ /**
+ * {@inheritDoc}
+ */
+ public NodeId getConfigurationRootId() {
+ return ((InternalFrozenNodeImpl) getFrozenNode()).node.getPropertyValue
+ (NameConstants.JCR_ROOT).getNodeId();
+ }
}
\ No newline at end of file
Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/version/InternalVersionHistoryImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/version/InternalVersionHistoryImpl.java?rev=797094&r1=797093&r2=797094&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/version/InternalVersionHistoryImpl.java (original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/version/InternalVersionHistoryImpl.java Thu Jul 23 15:05:44 2009
@@ -22,8 +22,6 @@
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Set;
-import java.util.Arrays;
-import java.util.HashSet;
import javax.jcr.PropertyType;
import javax.jcr.ReferentialIntegrityException;
@@ -229,10 +227,16 @@
v.clear();
} else {
// check if baseline
- if (child.getState().getMixinTypeNames().contains(NameConstants.REP_BASELINE)) {
- v = new InternalBaselineImpl(this, child, child.getName());
- } else {
- v = new InternalVersionImpl(this, child, child.getName());
+ try {
+ NodeStateEx frozen = child.getNode(NameConstants.JCR_FROZENNODE, 1);
+ Name frozenType = frozen.getPropertyValue(NameConstants.JCR_FROZENPRIMARYTYPE).getName();
+ if (NameConstants.NT_CONFIGURATION.equals(frozenType)) {
+ v = new InternalBaselineImpl(this, child, child.getName());
+ } else {
+ v = new InternalVersionImpl(this, child, child.getName());
+ }
+ } catch (RepositoryException e) {
+ throw new InternalError("Version does not have a jcr:frozenNode: " + child.getNodeId());
}
}
return v;
@@ -492,11 +496,10 @@
*
* @param name new version name
* @param src source node to version
- * @param configuration the set of versions in case a configuration is checked in
* @return the newly created version
* @throws RepositoryException if an error occurs
*/
- InternalVersionImpl checkin(Name name, NodeStateEx src, Set<NodeId> configuration)
+ InternalVersionImpl checkin(Name name, NodeStateEx src)
throws RepositoryException {
// copy predecessors from src node
@@ -535,16 +538,6 @@
InternalValue act = src.getPropertyValue(NameConstants.JCR_ACTIVITY);
vNode.setPropertyValue(NameConstants.JCR_ACTIVITY, act);
}
- // check configuration
- if (configuration != null) {
- vNode.setMixins(new HashSet<Name>(Arrays.asList(NameConstants.REP_BASELINE)));
- InternalValue[] values = new InternalValue[configuration.size()];
- int i=0;
- for (NodeId id: configuration) {
- values[i++] = InternalValue.create(id);
- }
- vNode.setPropertyValues(NameConstants.REP_BASEVERSIONS, PropertyType.REFERENCE, values, true);
- }
// initialize 'created', 'predecessors' and 'successors'
vNode.setPropertyValue(NameConstants.JCR_CREATED, InternalValue.create(getCurrentTime()));
@@ -555,9 +548,10 @@
InternalFrozenNodeImpl.checkin(vNode, NameConstants.JCR_FROZENNODE, src);
// update version graph
- InternalVersionImpl version = configuration == null
- ? new InternalVersionImpl(this, vNode, name)
- : new InternalBaselineImpl(this, vNode, name);
+ boolean isConfiguration = src.getEffectiveNodeType().includesNodeType(NameConstants.NT_CONFIGURATION);
+ InternalVersionImpl version = isConfiguration
+ ? new InternalBaselineImpl(this, vNode, name)
+ : new InternalVersionImpl(this, vNode, name);
version.internalAttach();
// and store
@@ -607,10 +601,6 @@
// create root version
NodeId versionId = new NodeId();
NodeStateEx vNode = pNode.addNode(NameConstants.JCR_ROOTVERSION, NameConstants.NT_VERSION, versionId, true);
- if (nodeState.getNodeTypeName().equals(NameConstants.NT_CONFIGURATION)) {
- // add baseline mixin for configurations
- vNode.setMixins(new HashSet<Name>(Arrays.asList(NameConstants.REP_BASELINE)));
- }
// initialize 'created' and 'predecessors'
vNode.setPropertyValue(NameConstants.JCR_CREATED, InternalValue.create(getCurrentTime()));
Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/version/InternalVersionManager.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/version/InternalVersionManager.java?rev=797094&r1=797093&r2=797094&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/version/InternalVersionManager.java (original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/version/InternalVersionManager.java Thu Jul 23 15:05:44 2009
@@ -16,8 +16,6 @@
*/
package org.apache.jackrabbit.core.version;
-import java.util.Set;
-
import javax.jcr.RepositoryException;
import javax.jcr.Session;
@@ -63,12 +61,10 @@
*
* @param session session that invokes the checkin
* @param node node to checkin
- * @param baseVersions set of base versions to record in the baseline if the
- * given node is a nt:configuration
* @return the newly created version
* @throws RepositoryException if an error occurs
*/
- InternalVersion checkin(Session session, NodeStateEx node, Set<NodeId> baseVersions)
+ InternalVersion checkin(Session session, NodeStateEx node)
throws RepositoryException;
/**
Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/version/InternalVersionManagerBase.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/version/InternalVersionManagerBase.java?rev=797094&r1=797093&r2=797094&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/version/InternalVersionManagerBase.java (original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/version/InternalVersionManagerBase.java Thu Jul 23 15:05:44 2009
@@ -16,8 +16,6 @@
*/
package org.apache.jackrabbit.core.version;
-import java.util.Set;
-
import javax.jcr.ItemNotFoundException;
import javax.jcr.ReferentialIntegrityException;
import javax.jcr.RepositoryException;
@@ -543,20 +541,18 @@
* @param history the version history
* @param node node to checkin
* @param simple flag indicates simple versioning
- * @param baseVersions in case the node is a nt:configuration
* @return internal version
* @throws javax.jcr.RepositoryException if an error occurs
* @see javax.jcr.Node#checkin()
*/
protected InternalVersion internalCheckin(InternalVersionHistoryImpl history,
- NodeStateEx node, boolean simple,
- final Set<NodeId> baseVersions)
+ NodeStateEx node, boolean simple)
throws RepositoryException {
WriteOperation operation = startWriteOperation();
try {
String versionName = calculateCheckinVersionName(history, node, simple);
InternalVersionImpl v = history.checkin(
- NameFactoryImpl.getInstance().create("", versionName), node, baseVersions);
+ NameFactoryImpl.getInstance().create("", versionName), node);
// check for jcr:activity
if (node.hasProperty(NameConstants.JCR_ACTIVITY)) {
Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/version/InternalVersionManagerImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/version/InternalVersionManagerImpl.java?rev=797094&r1=797093&r2=797094&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/version/InternalVersionManagerImpl.java (original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/version/InternalVersionManagerImpl.java Thu Jul 23 15:05:44 2009
@@ -19,7 +19,6 @@
import java.util.Collection;
import java.util.List;
import java.util.Map;
-import java.util.Set;
import javax.jcr.PropertyType;
import javax.jcr.RepositoryException;
@@ -418,8 +417,7 @@
* This method must not be synchronized since it could cause deadlocks with
* item-reading listeners in the observation thread.
*/
- public InternalVersion checkin(final Session session, final NodeStateEx node,
- final Set<NodeId> baseVersions)
+ public InternalVersion checkin(final Session session, final NodeStateEx node)
throws RepositoryException {
return (InternalVersion)
escFactory.doSourced((SessionImpl) session, new SourcedTarget() {
@@ -430,11 +428,11 @@
// the property
NodeId histId = node.getPropertyValue(NameConstants.JCR_VERSIONHISTORY).getNodeId();
vh = getVersionHistory(histId);
- return internalCheckin((InternalVersionHistoryImpl) vh, node, false, baseVersions);
+ return internalCheckin((InternalVersionHistoryImpl) vh, node, false);
} else {
// in simple versioning the history id needs to be calculated
vh = getVersionHistoryOfNode(node.getNodeId());
- return internalCheckin((InternalVersionHistoryImpl) vh, node, true, baseVersions);
+ return internalCheckin((InternalVersionHistoryImpl) vh, node, true);
}
}
});
Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/version/InternalXAVersionManager.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/version/InternalXAVersionManager.java?rev=797094&r1=797093&r2=797094&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/version/InternalXAVersionManager.java (original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/version/InternalXAVersionManager.java Thu Jul 23 15:05:44 2009
@@ -18,7 +18,6 @@
import java.util.HashMap;
import java.util.Map;
-import java.util.Set;
import javax.jcr.RepositoryException;
import javax.jcr.Session;
@@ -213,7 +212,7 @@
/**
* {@inheritDoc}
*/
- public InternalVersion checkin(Session session, NodeStateEx node, Set<NodeId> baseVersions)
+ public InternalVersion checkin(Session session, NodeStateEx node)
throws RepositoryException {
if (isInXA()) {
InternalVersionHistory vh;
@@ -223,15 +222,15 @@
// the property
NodeId histId = node.getPropertyValue(NameConstants.JCR_VERSIONHISTORY).getNodeId();
vh = getVersionHistory(histId);
- version = internalCheckin((InternalVersionHistoryImpl) vh, node, false, baseVersions);
+ version = internalCheckin((InternalVersionHistoryImpl) vh, node, false);
} else {
// in simple versioning the history id needs to be calculated
vh = getVersionHistoryOfNode(node.getNodeId());
- version = internalCheckin((InternalVersionHistoryImpl) vh, node, true, baseVersions);
+ version = internalCheckin((InternalVersionHistoryImpl) vh, node, true);
}
return version;
} else {
- return vMgr.checkin(session, node, baseVersions);
+ return vMgr.checkin(session, node);
}
}
@@ -444,15 +443,14 @@
* Before modifying version history given, make a local copy of it.
*/
protected InternalVersion internalCheckin(InternalVersionHistoryImpl history,
- NodeStateEx node, boolean simple,
- Set<NodeId> baseVersions)
+ NodeStateEx node, boolean simple)
throws RepositoryException {
if (history.getVersionManager() != this) {
history = makeLocalCopy(history);
xaItems.put(history.getId(), history);
}
- InternalVersion version = super.internalCheckin(history, node, simple, baseVersions);
+ InternalVersion version = super.internalCheckin(history, node, simple);
NodeId frozenNodeId = version.getFrozenNodeId();
InternalVersionItem frozenNode = createInternalVersionItem(frozenNodeId);
if (frozenNode != null) {
Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/version/VersionManagerImplBase.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/version/VersionManagerImplBase.java?rev=797094&r1=797093&r2=797094&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/version/VersionManagerImplBase.java (original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/version/VersionManagerImplBase.java Thu Jul 23 15:05:44 2009
@@ -163,11 +163,18 @@
// the 2 cases could be consolidated but is clearer this way
if (checkin) {
// check for configuration
- Set<NodeId> baseVersions = null;
if (state.getEffectiveNodeType().includesNodeType(NameConstants.NT_CONFIGURATION)) {
- baseVersions = collectBaseVersions(state);
+ // collect the base versions and the the rep:versions property of the configuration
+ Set<NodeId> baseVersions = collectBaseVersions(state);
+ InternalValue[] vs = new InternalValue[baseVersions.size()];
+ int i=0;
+ for (NodeId id: baseVersions) {
+ vs[i++] = InternalValue.create(id);
+ }
+ state.setPropertyValues(NameConstants.REP_VERSIONS, PropertyType.REFERENCE, vs);
+ state.store();
}
- InternalVersion v = vMgr.checkin(session, state, baseVersions);
+ InternalVersion v = vMgr.checkin(session, state);
baseId = v.getId();
if (isFull) {
state.setPropertyValue(
@@ -214,10 +221,11 @@
NodeId rootId = config.getPropertyValue(NameConstants.JCR_ROOT).getNodeId();
NodeStateEx root = getNodeStateEx(rootId);
if (root == null) {
- throw new ItemNotFoundException("Configuration root node for " + safeGetJCRPath(config) + " not found.");
+ String msg = "Configuration root node for " + safeGetJCRPath(config) + " not found.";
+ log.error(msg);
+ throw new ItemNotFoundException(msg);
}
Set<NodeId> baseVersions = new HashSet<NodeId>();
- baseVersions.add(root.getPropertyValue(NameConstants.JCR_BASEVERSION).getNodeId());
collectBaseVersions(root, baseVersions);
return baseVersions;
}
@@ -230,15 +238,24 @@
*/
private void collectBaseVersions(NodeStateEx root, Set<NodeId> baseVersions)
throws RepositoryException {
- for (NodeStateEx child: root.getChildNodes()) {
- if (child.getEffectiveNodeType().includesNodeType(NameConstants.MIX_VERSIONABLE)) {
- if (child.hasProperty(NameConstants.JCR_CONFIGURATION)) {
- // don't traverse into child nodes that have a jcr:configuration
- // property as they belong to a different configuration.
- continue;
- }
- baseVersions.add(child.getPropertyValue(NameConstants.JCR_BASEVERSION).getNodeId());
+ if (!baseVersions.isEmpty()) {
+ // base version of configuration root already recorded
+ if (root.hasProperty(NameConstants.JCR_CONFIGURATION)
+ && root.getEffectiveNodeType().includesNodeType(NameConstants.MIX_VERSIONABLE)) {
+ // don't traverse into child nodes that have a jcr:configuration
+ // property as they belong to a different configuration.
+ return;
}
+ }
+ InternalVersion baseVersion = getBaseVersion(root);
+ if (baseVersion.isRootVersion()) {
+ String msg = "Unable to checkin configuration as it has unversioned child node: " + safeGetJCRPath(root);
+ log.error(msg);
+ throw new UnsupportedRepositoryOperationException(msg);
+ }
+ baseVersions.add(baseVersion.getId());
+
+ for (NodeStateEx child: root.getChildNodes()) {
collectBaseVersions(child, baseVersions);
}
}
@@ -260,7 +277,7 @@
} else {
String msg = "Unable to perform a versioning operation on a " +
"non versionable node: " + safeGetJCRPath(state);
- log.debug(msg);
+ log.error(msg);
throw new UnsupportedRepositoryOperationException(msg);
}
}
@@ -518,7 +535,8 @@
success = true;
return new WriteOperation(lock);
} catch (IllegalStateException e) {
- throw new RepositoryException("Unable to start edit operation.", e);
+ String msg = "Unable to start edit operation.";
+ throw new RepositoryException(msg, e);
} finally {
if (!success) {
lock.release();
Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/version/VersionManagerImplConfig.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/version/VersionManagerImplConfig.java?rev=797094&r1=797093&r2=797094&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/version/VersionManagerImplConfig.java (original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/version/VersionManagerImplConfig.java Thu Jul 23 15:05:44 2009
@@ -16,6 +16,9 @@
*/
package org.apache.jackrabbit.core.version;
+import java.util.Set;
+import java.util.HashSet;
+
import javax.jcr.PropertyType;
import javax.jcr.RepositoryException;
import javax.jcr.UnsupportedRepositoryOperationException;
@@ -29,6 +32,8 @@
import org.apache.jackrabbit.core.value.InternalValue;
import org.apache.jackrabbit.spi.Name;
import org.apache.jackrabbit.spi.commons.name.NameConstants;
+import org.slf4j.LoggerFactory;
+import org.slf4j.Logger;
/**
* The JCR Version Manager impementation is split in several classes in order to
@@ -42,6 +47,11 @@
abstract public class VersionManagerImplConfig extends VersionManagerImplMerge {
/**
+ * default logger
+ */
+ private static final Logger log = LoggerFactory.getLogger(VersionManagerImplConfig.class);
+
+ /**
* Creates a new version manager for the given session
* @param session workspace sesion
* @param stateMgr the underlying state manager
@@ -64,12 +74,14 @@
*/
protected NodeId restore(NodeStateEx parent, Name name, InternalBaseline baseline)
throws RepositoryException {
- NodeStateEx config = parent.getNode(baseline.getVersionHistory().getVersionableId());
- NodeId rootId = config.getPropertyValue(NameConstants.JCR_ROOT).getNodeId();
+ // check if nt:configuration exists
+ NodeId configId = baseline.getConfigurationId();
+ NodeId rootId = baseline.getConfigurationRootId();
if (stateMgr.hasItemState(rootId)) {
NodeStateEx existing = parent.getNode(rootId);
- throw new UnsupportedRepositoryOperationException(
- "Configuration for the given baseline already exists at: " + safeGetJCRPath(existing));
+ String msg = "Configuration for the given baseline already exists at: " + safeGetJCRPath(existing);
+ log.error(msg);
+ throw new UnsupportedRepositoryOperationException(msg);
}
// find version for configuration root
@@ -82,20 +94,32 @@
}
}
if (rootVersion == null) {
- throw new RepositoryException("Internal error: supplied baseline has no version for its configuration root.");
+ String msg = "Internal error: supplied baseline has no version for its configuration root.";
+ log.error(msg);
+ throw new RepositoryException(msg);
}
// create new node below parent
WriteOperation ops = startWriteOperation();
try {
+ // check if nt:configuration node exists
+ NodeStateEx config = null;
+ if (stateMgr.hasItemState(configId)) {
+ config = parent.getNode(configId);
+ } else {
+ internalCreateConfiguration(rootId, configId, baseline.getId());
+ }
+ // create the root node so that the restore works
InternalFrozenNode fn = rootVersion.getFrozenNode();
NodeStateEx state = parent.addNode(name, fn.getFrozenPrimaryType(), fn.getFrozenId());
state.setMixins(fn.getFrozenMixinTypes());
parent.store();
- // now just restore all versions
- internalRestore(versions, true);
+
+ // and finally restore the config and root
+ internalRestore(config, baseline, null, false);
+
ops.save();
- return config.getNodeId();
+ return configId;
} catch (ItemStateException e) {
throw new RepositoryException(e);
} finally {
@@ -104,42 +128,6 @@
}
/**
- * Performs a configuration restore
- * @param config config to restore
- * @param name name of the baseline version
- * @param removeExisting remove existing flag
- * @throws RepositoryException if an error occurs
- */
-// protected void restore(InternalConfiguration config, Name name, boolean removeExisting)
-// throws RepositoryException {
-// throw new UnsupportedRepositoryOperationException("not implemented, yet");
-// }
-
- /**
- * Performs a configuration restore
- * @param config config to restore
- * @param name label of the baseline version
- * @param removeExisting remove existing flag
- * @throws RepositoryException if an error occurs
- */
-// protected void restoreByLabel(InternalConfiguration config, Name name, boolean removeExisting)
-// throws RepositoryException {
-// throw new UnsupportedRepositoryOperationException("not implemented, yet");
-// }
-
- /**
- * Performs a configuration restore
- * @param config config to restore
- * @param version baseline version to restore
- * @param removeExisting remove existing flag
- * @throws RepositoryException if an error occurs
- */
-// protected void restore(InternalConfiguration config, Version version, boolean removeExisting)
-// throws RepositoryException {
-// throw new UnsupportedRepositoryOperationException("not implemented, yet");
-// }
-
- /**
* Creates a new configuration node.
* <p/>
* The nt:confguration is stored within the nt:configurations storage using
@@ -154,37 +142,12 @@
WriteOperation ops = startWriteOperation();
try {
- NodeId rootId = state.getNodeId();
- NodeStateEx configRoot = internalGetConfigRoot();
- NodeStateEx configParent = InternalVersionManagerBase.getParentNode(
- configRoot,
- rootId.toString(),
- NameConstants.REP_CONFIGURATIONS);
- Name name = InternalVersionManagerBase.getName(rootId.toString());
-
- NodeId configId = new NodeId();
- NodeStateEx config = configParent.addNode(name, NameConstants.NT_CONFIGURATION, configId, true);
- config.setPropertyValue(NameConstants.JCR_ROOT, InternalValue.create(rootId));
-
- // init mix:versionable flags
- VersionHistoryInfo vh = vMgr.getVersionHistory(session, config.getState(), null);
-
- // and set the base version and history to the config
- InternalValue historyId = InternalValue.create(vh.getVersionHistoryId());
- InternalValue versionId = InternalValue.create(vh.getRootVersionId());
-
- config.setPropertyValue(NameConstants.JCR_BASEVERSION, versionId);
- config.setPropertyValue(NameConstants.JCR_VERSIONHISTORY, historyId);
- config.setPropertyValue(NameConstants.JCR_ISCHECKEDOUT, InternalValue.create(true));
- config.setPropertyValues(NameConstants.JCR_PREDECESSORS, PropertyType.REFERENCE, new InternalValue[]{versionId});
- configParent.store();
+ NodeId configId = internalCreateConfiguration(state.getNodeId(), null, null);
// set configuration reference in state
state.setPropertyValue(NameConstants.JCR_CONFIGURATION, InternalValue.create(configId));
state.store();
-
ops.save();
-
return configId;
} catch (ItemStateException e) {
throw new RepositoryException(e);
@@ -194,6 +157,55 @@
}
/**
+ * Creates a new configuration node.
+ * <p/>
+ * The nt:confguration is stored within the nt:configurations storage using
+ * the nodeid of the configuration root (rootId) as path.
+ *
+ * @param rootId the id of the configuration root node
+ * @param configId the id of the configuration node
+ * @param baseLine id of the baseline version or <code>null</code>
+ * @return the node id of the created configuration
+ * @throws RepositoryException if an error occurs
+ */
+ private NodeId internalCreateConfiguration(NodeId rootId,
+ NodeId configId, NodeId baseLine)
+ throws RepositoryException {
+
+ NodeStateEx configRoot = internalGetConfigRoot();
+ NodeStateEx configParent = InternalVersionManagerBase.getParentNode(
+ configRoot,
+ rootId.toString(),
+ NameConstants.REP_CONFIGURATIONS);
+ Name name = InternalVersionManagerBase.getName(rootId.toString());
+
+ if (configId == null) {
+ configId = new NodeId();
+ }
+ NodeStateEx config = configParent.addNode(name, NameConstants.NT_CONFIGURATION, configId, true);
+ Set<Name> mix = new HashSet<Name>();
+ mix.add(NameConstants.REP_VERSION_REFERENCE);
+ config.setMixins(mix);
+ config.setPropertyValue(NameConstants.JCR_ROOT, InternalValue.create(rootId));
+
+ // init mix:versionable flags
+ VersionHistoryInfo vh = vMgr.getVersionHistory(session, config.getState(), null);
+
+ // and set the base version and history to the config
+ InternalValue historyId = InternalValue.create(vh.getVersionHistoryId());
+ InternalValue versionId = InternalValue.create(
+ baseLine == null ? vh.getRootVersionId() : baseLine);
+
+ config.setPropertyValue(NameConstants.JCR_BASEVERSION, versionId);
+ config.setPropertyValue(NameConstants.JCR_VERSIONHISTORY, historyId);
+ config.setPropertyValue(NameConstants.JCR_ISCHECKEDOUT, InternalValue.create(true));
+ config.setPropertyValues(NameConstants.JCR_PREDECESSORS, PropertyType.REFERENCE, new InternalValue[]{versionId});
+ configParent.store();
+
+ return configId;
+ }
+
+ /**
* Returns the root node of the configurations storage located at
* "/jcr:system/jcr:configurations"
*
Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/version/VersionManagerImplRestore.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/version/VersionManagerImplRestore.java?rev=797094&r1=797093&r2=797094&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/version/VersionManagerImplRestore.java (original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/version/VersionManagerImplRestore.java Thu Jul 23 15:05:44 2009
@@ -90,7 +90,9 @@
InternalVersion v = getVersion(version);
// check if 'own' version
if (!v.getVersionHistory().equals(getVersionHistory(state))) {
- throw new VersionException("Unable to restore version. Not same version history.");
+ String msg = "Unable to restore version. Not same version history.";
+ log.error(msg);
+ throw new VersionException(msg);
}
WriteOperation ops = startWriteOperation();
try {
@@ -140,7 +142,9 @@
checkVersionable(state);
InternalVersion v = getVersionHistory(state).getVersionByLabel(versionLabel);
if (v == null) {
- throw new VersionException("No version for label " + versionLabel + " found.");
+ String msg = "No version for label " + versionLabel + " found.";
+ log.error(msg);
+ throw new VersionException(msg);
}
WriteOperation ops = startWriteOperation();
try {
@@ -189,7 +193,9 @@
ops.close();
}
} else {
- throw new ItemExistsException("Unable to restore version. Versionable node already exists.");
+ String msg = "Unable to restore version. Versionable node already exists.";
+ log.error(msg);
+ throw new ItemExistsException(msg);
}
} else {
// create new node below parent
@@ -230,13 +236,11 @@
}
}
if (restored == null) {
- if (numRestored == 0) {
- throw new VersionException("Unable to restore. At least one version needs"
- + " existing versionable node in workspace.");
- } else {
- throw new VersionException("Unable to restore. All versions with non"
- + " existing versionable nodes need parent.");
- }
+ String msg = numRestored == 0
+ ? "Unable to restore. At least one version needs existing versionable node in workspace."
+ : "Unable to restore. All versions with non existing versionable nodes need parent.";
+ log.error(msg);
+ throw new VersionException(msg);
}
}
}
@@ -261,7 +265,9 @@
// fail if root version
if (version.isRootVersion()) {
- throw new VersionException("Restore of root version not allowed.");
+ String msg = "Restore of root version not allowed.";
+ log.error(msg);
+ throw new VersionException(msg);
}
boolean isFull = checkVersionable(state);
@@ -291,11 +297,28 @@
} else {
// with simple versioning, the node is checked in automatically,
// thus not allowing any branches
- vMgr.checkin(session, state, null);
+ vMgr.checkin(session, state);
}
// 3. N's jcr:isCheckedOut property is set to false.
state.setPropertyValue(NameConstants.JCR_ISCHECKEDOUT, InternalValue.create(false));
state.store();
+
+ // check if a baseline is restored
+ if (version instanceof InternalBaseline) {
+ // just restore all base versions
+ InternalBaseline baseline = (InternalBaseline) version;
+ internalRestore(baseline.getBaseVersions(), true);
+
+ // ensure that the restored root node has a jcr:configuration property
+ // since it might not have been recorded by the initial checkin of the
+ // configuration
+ NodeId configId = baseline.getConfigurationId();
+ NodeId rootId = baseline.getConfigurationRootId();
+ NodeStateEx rootNode = state.getNode(rootId);
+ rootNode.setPropertyValue(NameConstants.JCR_CONFIGURATION, InternalValue.create(configId));
+ rootNode.store();
+ }
+
return restored;
}
@@ -317,14 +340,18 @@
// check uuid
if (state.getEffectiveNodeType().includesNodeType(NameConstants.MIX_REFERENCEABLE)) {
if (!state.getNodeId().equals(freeze.getFrozenId())) {
- throw new ItemExistsException("Unable to restore version of " + safeGetJCRPath(state) + ". UUID changed.");
+ String msg = "Unable to restore version of " + safeGetJCRPath(state) + ". UUID changed.";
+ log.error(msg);
+ throw new ItemExistsException(msg);
}
}
// check primary type
if (!freeze.getFrozenPrimaryType().equals(state.getState().getNodeTypeName())) {
// todo: implement
- throw new UnsupportedRepositoryOperationException("Unable to restore version of " + safeGetJCRPath(state) + ". PrimaryType change not supported yet.");
+ String msg = "Unable to restore version of " + safeGetJCRPath(state) + ". PrimaryType change not supported yet.";
+ log.error(msg);
+ throw new UnsupportedRepositoryOperationException(msg);
}
// adjust mixins
@@ -419,10 +446,10 @@
} else {
// since we delete the OPV=Copy children beforehand, all
// found nodes must be outside of this tree
- throw new ItemExistsException(
- "Unable to restore node, item already"
- + " exists outside of restored tree: "
- + existing);
+ String msg = "Unable to restore node, item already exists " +
+ "outside of restored tree: " + safeGetJCRPath(existing);
+ log.error(msg);
+ throw new ItemExistsException(msg);
}
}
@@ -455,9 +482,10 @@
} else {
// since we delete the OPV=Copy children beforehand, all
// found nodes must be outside of this tree
- throw new ItemExistsException(
- "Unable to restore node, item already exists"
- + " outside of restored tree: " + existing);
+ String msg = "Unable to restore node, item already exists " +
+ "outside of restored tree: " + safeGetJCRPath(existing);
+ log.error(msg);
+ throw new ItemExistsException(msg);
}
}
// get desired version from version selector
Modified: jackrabbit/trunk/jackrabbit-core/src/main/resources/org/apache/jackrabbit/core/nodetype/builtin_nodetypes.cnd
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/resources/org/apache/jackrabbit/core/nodetype/builtin_nodetypes.cnd?rev=797094&r1=797093&r2=797094&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/resources/org/apache/jackrabbit/core/nodetype/builtin_nodetypes.cnd (original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/resources/org/apache/jackrabbit/core/nodetype/builtin_nodetypes.cnd Thu Jul 23 15:05:44 2009
@@ -517,18 +517,13 @@
+ * (rep:Configurations) = rep:Configurations protected sns ABORT
/**
- * mixin for baseline versions
- * @prop rep:baseVersions property that holds all base versions of the
- * versioned configuration.
+ * mixin that provides a multi value property for referencing versions.
+ * This is used for recording the baseline versions in the nt:configuration
+ * node, and to setup a bidirectional relationship between activities and
+ * the respective versions
*/
-[rep:Baseline] mixin
- - rep:baseVersions (REFERENCE) protected multiple ABORT
-
-// implementation note: because node references are not maintained within the
-// version storage, we store a bidirectional relationship between activities and
-// the respective versions
[rep:VersionReference] mix
- - rep:versions (REFERENCE) protected multiple ABORT
+ - rep:versions (REFERENCE) protected multiple
// -----------------------------------------------------------------------------
// J A C K R A B B I T S E C U R I T Y
Modified: jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/name/NameConstants.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/name/NameConstants.java?rev=797094&r1=797093&r2=797094&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/name/NameConstants.java (original)
+++ jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/name/NameConstants.java Thu Jul 23 15:05:44 2009
@@ -588,11 +588,6 @@
public static final Name REP_CONFIGURATIONS = FACTORY.create(Name.NS_REP_URI, "Configurations");
/**
- * rep:Baseline
- */
- public static final Name REP_BASELINE = FACTORY.create(Name.NS_REP_URI, "Baseline");
-
- /**
* rep:baseVersions
*/
public static final Name REP_BASEVERSIONS = FACTORY.create(Name.NS_REP_URI, "baseVersions");