You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jackrabbit.apache.org by ju...@apache.org on 2008/10/07 14:32:08 UTC
svn commit: r702453 - in
/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core:
./ version/ xml/
Author: jukka
Date: Tue Oct 7 05:32:07 2008
New Revision: 702453
URL: http://svn.apache.org/viewvc?rev=702453&view=rev
Log:
JCR-1775: Transaction-safe versioning
Avoid instantiating full VersionHistoryImpl objects when all we need are the identifiers of the version history and root version nodes.
Added:
jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/version/VersionHistoryInfo.java (with props)
Modified:
jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/BatchedItemOperations.java
jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/ItemImpl.java
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/InternalVersionHistoryImpl.java
jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/version/VersionManager.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/main/java/org/apache/jackrabbit/core/xml/WorkspaceImporter.java
Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/BatchedItemOperations.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/BatchedItemOperations.java?rev=702453&r1=702452&r2=702453&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/BatchedItemOperations.java (original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/BatchedItemOperations.java Tue Oct 7 05:32:07 2008
@@ -37,6 +37,7 @@
import org.apache.jackrabbit.core.state.ChildNodeEntry;
import org.apache.jackrabbit.core.util.ReferenceChangeTracker;
import org.apache.jackrabbit.core.value.InternalValue;
+import org.apache.jackrabbit.core.version.VersionHistoryInfo;
import org.apache.jackrabbit.core.version.VersionManager;
import org.apache.jackrabbit.spi.Name;
import org.apache.jackrabbit.spi.Path;
@@ -58,7 +59,6 @@
import javax.jcr.lock.LockException;
import javax.jcr.nodetype.ConstraintViolationException;
import javax.jcr.version.VersionException;
-import javax.jcr.version.VersionHistory;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Calendar;
@@ -1916,19 +1916,19 @@
VersionManager manager = session.getVersionManager();
if (propName.equals(NameConstants.JCR_VERSIONHISTORY)) {
// jcr:versionHistory
- VersionHistory vh =
+ VersionHistoryInfo history =
manager.getVersionHistory(session, newState);
- newChildState.setValues(new InternalValue[]{InternalValue.create(new UUID(vh.getUUID()))});
- } else if (propName.equals(NameConstants.JCR_BASEVERSION)) {
- // jcr:baseVersion
- VersionHistory vh =
+ InternalValue value = InternalValue.create(
+ history.getVersionHistoryId().getUUID());
+ newChildState.setValues(new InternalValue[] { value });
+ } else if (propName.equals(NameConstants.JCR_BASEVERSION)
+ || propName.equals(NameConstants.JCR_PREDECESSORS)) {
+ // jcr:baseVersion or jcr:predecessors
+ VersionHistoryInfo history =
manager.getVersionHistory(session, newState);
- newChildState.setValues(new InternalValue[]{InternalValue.create(new UUID(vh.getRootVersion().getUUID()))});
- } else if (propName.equals(NameConstants.JCR_PREDECESSORS)) {
- // jcr:predecessors
- VersionHistory vh =
- manager.getVersionHistory(session, newState);
- newChildState.setValues(new InternalValue[]{InternalValue.create(new UUID(vh.getRootVersion().getUUID()))});
+ InternalValue value = InternalValue.create(
+ history.getRootVersionId().getUUID());
+ newChildState.setValues(new InternalValue[] { value });
} else if (propName.equals(NameConstants.JCR_ISCHECKEDOUT)) {
// jcr:isCheckedOut
newChildState.setValues(new InternalValue[]{InternalValue.create(true)});
Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/ItemImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/ItemImpl.java?rev=702453&r1=702452&r2=702453&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/ItemImpl.java (original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/ItemImpl.java Tue Oct 7 05:32:07 2008
@@ -35,6 +35,7 @@
import org.apache.jackrabbit.core.state.StaleItemStateException;
import org.apache.jackrabbit.core.state.ChildNodeEntry;
import org.apache.jackrabbit.core.value.InternalValue;
+import org.apache.jackrabbit.core.version.VersionHistoryInfo;
import org.apache.jackrabbit.core.version.VersionManager;
import org.apache.jackrabbit.spi.Name;
import org.apache.jackrabbit.spi.Path;
@@ -65,7 +66,6 @@
import javax.jcr.nodetype.NodeDefinition;
import javax.jcr.nodetype.NodeType;
import javax.jcr.version.VersionException;
-import javax.jcr.version.VersionHistory;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashSet;
@@ -726,13 +726,22 @@
* IMPORT_UUID_COLLISION_REPLACE_EXISTING;
* otherwise create a new version history
*/
- VersionHistory vh =
+ VersionHistoryInfo history =
vMgr.getVersionHistory(session, nodeState);
- node.internalSetProperty(NameConstants.JCR_VERSIONHISTORY, InternalValue.create(new UUID(vh.getUUID())));
- node.internalSetProperty(NameConstants.JCR_BASEVERSION, InternalValue.create(new UUID(vh.getRootVersion().getUUID())));
- node.internalSetProperty(NameConstants.JCR_ISCHECKEDOUT, InternalValue.create(true));
- node.internalSetProperty(NameConstants.JCR_PREDECESSORS,
- new InternalValue[]{InternalValue.create(new UUID(vh.getRootVersion().getUUID()))});
+ InternalValue historyId = InternalValue.create(
+ history.getVersionHistoryId().getUUID());
+ InternalValue versionId = InternalValue.create(
+ history.getRootVersionId().getUUID());
+ node.internalSetProperty(
+ NameConstants.JCR_VERSIONHISTORY, historyId);
+ node.internalSetProperty(
+ NameConstants.JCR_BASEVERSION, versionId);
+ node.internalSetProperty(
+ NameConstants.JCR_ISCHECKEDOUT,
+ InternalValue.create(true));
+ node.internalSetProperty(
+ NameConstants.JCR_PREDECESSORS,
+ new InternalValue[] { versionId });
createdTransientState = true;
}
}
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=702453&r1=702452&r2=702453&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 Oct 7 05:32:07 2008
@@ -20,7 +20,6 @@
import EDU.oswego.cs.dl.util.concurrent.ReentrantWriterPreferenceReadWriteLock;
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;
@@ -35,7 +34,6 @@
import javax.jcr.Session;
import javax.jcr.Value;
import javax.jcr.version.VersionException;
-import javax.jcr.version.VersionHistory;
/**
* Base implementation of the {@link VersionManager} interface.
@@ -230,9 +228,9 @@
/**
* {@inheritDoc}
*/
- public VersionHistory getVersionHistory(Session session, NodeState node)
+ public VersionHistoryInfo getVersionHistory(Session session, NodeState node)
throws RepositoryException {
- NodeId id = null;
+ VersionHistoryInfo info = null;
acquireReadLock();
try {
@@ -241,17 +239,21 @@
NodeStateEx parent = getParentNode(uuid, false);
if (parent != null && parent.hasNode(name)) {
- id = parent.getState().getChildNodeEntry(name, 1).getId();
+ NodeStateEx history = parent.getNode(name, 1);
+ Name root = NameConstants.JCR_ROOTVERSION;
+ info = new VersionHistoryInfo(
+ history.getNodeId(),
+ history.getState().getChildNodeEntry(root, 1).getId());
}
} finally {
releaseReadLock();
}
- if (id == null) {
- id = createVersionHistory(session, node);
+ if (info == null) {
+ info = createVersionHistory(session, node);
}
- return (VersionHistory) ((SessionImpl) session).getNodeById(id);
+ return info;
}
@@ -265,7 +267,7 @@
* @throws RepositoryException
* @see #getVersionHistory(Session, NodeState)
*/
- protected abstract NodeId createVersionHistory(
+ protected abstract VersionHistoryInfo createVersionHistory(
Session session, NodeState node) throws RepositoryException;
/**
@@ -310,10 +312,10 @@
* Creates a new Version History.
*
* @param node the node for which the version history is to be initialized
- * @return the newly created version history.
+ * @return the identifiers of the newly created version history and root version
* @throws javax.jcr.RepositoryException
*/
- InternalVersionHistory createVersionHistory(NodeState node)
+ NodeStateEx createVersionHistory(NodeState node)
throws RepositoryException {
WriteOperation operation = startWriteOperation();
try {
@@ -327,15 +329,16 @@
}
// create new history node in the persistent state
- InternalVersionHistoryImpl hist =
+ NodeStateEx history =
InternalVersionHistoryImpl.create(this, parent, name, node);
// end update
operation.save();
- log.debug("Created new version history " + hist.getId() + " for " + node + ".");
- return hist;
-
+ log.debug(
+ "Created new version history " + history.getNodeId()
+ + " for " + node + ".");
+ return history;
} catch (ItemStateException e) {
throw new RepositoryException(e);
} finally {
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=702453&r1=702452&r2=702453&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 Tue Oct 7 05:32:07 2008
@@ -501,19 +501,17 @@
}
/**
- * Creates a new <code>InternalVersionHistory</code> below the given parent
- * node and with the given name.
+ * Creates a new version history below the given parent node and with
+ * the given name.
*
* @param parent
* @param name
* @return
* @throws RepositoryException
*/
- static InternalVersionHistoryImpl create(AbstractVersionManager vMgr,
- NodeStateEx parent,
- Name name,
- NodeState nodeState)
- throws RepositoryException {
+ static NodeStateEx create(
+ AbstractVersionManager vMgr, NodeStateEx parent, Name name,
+ NodeState nodeState) throws RepositoryException {
// create history node
NodeId historyId = new NodeId(UUID.randomUUID());
@@ -554,7 +552,7 @@
}
parent.store();
- return new InternalVersionHistoryImpl(vMgr, pNode);
+ return pNode;
}
/**
Added: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/version/VersionHistoryInfo.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/version/VersionHistoryInfo.java?rev=702453&view=auto
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/version/VersionHistoryInfo.java (added)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/version/VersionHistoryInfo.java Tue Oct 7 05:32:07 2008
@@ -0,0 +1,65 @@
+/*
+ * 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 org.apache.jackrabbit.core.NodeId;
+
+/**
+ * Simple data object that carries the identifiers of a version history node
+ * and the related root version node.
+ *
+ * @since Apache Jackrabbit 1.5
+ * @see <a href="https://issues.apache.org/jira/browse/JCR-1775">JCR-1775</a>
+ */
+public class VersionHistoryInfo {
+
+ /**
+ * Identifier of the version history node.
+ */
+ private final NodeId versionHistoryId;
+
+ /**
+ * Identifier of the root version node.
+ */
+ private final NodeId rootVersionId;
+
+ /**
+ * Creates an object that carries the given version history information.
+ *
+ * @param versionHistoryId identifier of the version history node
+ * @param rootVersionId identifier of the root version node
+ */
+ public VersionHistoryInfo(NodeId versionHistoryId, NodeId rootVersionId) {
+ this.versionHistoryId = versionHistoryId;
+ this.rootVersionId = rootVersionId;
+ }
+
+ /**
+ * Returns the identifier of the version history node.
+ */
+ public NodeId getVersionHistoryId() {
+ return versionHistoryId;
+ }
+
+ /**
+ * Returns the identifier of the root version node.
+ */
+ public NodeId getRootVersionId() {
+ return rootVersionId;
+ }
+
+}
Propchange: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/version/VersionHistoryInfo.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/version/VersionManager.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/version/VersionManager.java?rev=702453&r1=702452&r2=702453&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/version/VersionManager.java (original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/version/VersionManager.java Tue Oct 7 05:32:07 2008
@@ -42,17 +42,18 @@
VirtualItemStateProvider getVirtualItemStateProvider();
/**
- * Returns the version history of the specified node. If the given node
- * does not already have an associated version history, then an empty
- * history is automatically created. This method should only be called
- * by code that already knows that the specified node is versionable.
+ * Returns information about the version history of the specified node.
+ * If the given node does not already have an associated version history,
+ * then an empty history is automatically created. This method should
+ * only be called by code that already knows that the specified node
+ * is versionable.
*
* @param session
* @param node node whose version history should be returned
- * @return the version history of the specified node
+ * @return identifiers of the version history and root version nodes
* @throws RepositoryException if an error occurs
*/
- VersionHistory getVersionHistory(Session session, NodeState node)
+ VersionHistoryInfo getVersionHistory(Session session, NodeState node)
throws RepositoryException;
/**
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=702453&r1=702452&r2=702453&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 Oct 7 05:32:07 2008
@@ -211,19 +211,22 @@
* This method must not be synchronized since it could cause deadlocks with
* item-reading listeners in the observation thread.
*/
- protected NodeId createVersionHistory(Session session, final NodeState node)
- throws RepositoryException {
- InternalVersionHistory history = (InternalVersionHistory)
+ protected VersionHistoryInfo createVersionHistory(
+ Session session, final NodeState node) throws RepositoryException {
+ NodeStateEx state = (NodeStateEx)
escFactory.doSourced((SessionImpl) session, new SourcedTarget() {
public Object run() throws RepositoryException {
return createVersionHistory(node);
}
});
- if (history == null) {
+ if (state == null) {
throw new VersionException("History already exists for node " + node.getNodeId());
}
- return history.getId();
+ Name root = NameConstants.JCR_ROOTVERSION;
+ return new VersionHistoryInfo(
+ state.getNodeId(),
+ state.getState().getChildNodeEntry(root, 1).getId());
}
/**
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=702453&r1=702452&r2=702453&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 Oct 7 05:32:07 2008
@@ -131,13 +131,18 @@
/**
* {@inheritDoc}
*/
- protected NodeId createVersionHistory(Session session, NodeState node)
+ protected VersionHistoryInfo createVersionHistory(Session session, NodeState node)
throws RepositoryException {
if (isInXA()) {
- InternalVersionHistory history = createVersionHistory(node);
- xaItems.put(history.getId(), history);
- return history.getId();
+ NodeStateEx state = createVersionHistory(node);
+ InternalVersionHistory history =
+ new InternalVersionHistoryImpl(vMgr, state);
+ xaItems.put(state.getNodeId(), history);
+ Name root = NameConstants.JCR_ROOTVERSION;
+ return new VersionHistoryInfo(
+ state.getNodeId(),
+ state.getState().getChildNodeEntry(root, 1).getId());
}
return vMgr.createVersionHistory(session, node);
}
Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/xml/WorkspaceImporter.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/xml/WorkspaceImporter.java?rev=702453&r1=702452&r2=702453&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/xml/WorkspaceImporter.java (original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/xml/WorkspaceImporter.java Tue Oct 7 05:32:07 2008
@@ -30,6 +30,7 @@
import org.apache.jackrabbit.core.state.ChildNodeEntry;
import org.apache.jackrabbit.core.util.ReferenceChangeTracker;
import org.apache.jackrabbit.core.value.InternalValue;
+import org.apache.jackrabbit.core.version.VersionHistoryInfo;
import org.apache.jackrabbit.core.version.VersionManager;
import org.apache.jackrabbit.spi.Name;
import org.apache.jackrabbit.spi.Path;
@@ -47,9 +48,7 @@
import javax.jcr.RepositoryException;
import javax.jcr.lock.LockException;
import javax.jcr.nodetype.ConstraintViolationException;
-import javax.jcr.version.Version;
import javax.jcr.version.VersionException;
-import javax.jcr.version.VersionHistory;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
@@ -308,29 +307,32 @@
* IMPORT_UUID_COLLISION_REPLACE_EXISTING;
* otherwise create a new version history
*/
- VersionHistory history =
+ VersionHistoryInfo history =
versionManager.getVersionHistory(session, node);
- Version rootVersion = history.getRootVersion();
+ InternalValue historyId = InternalValue.create(
+ history.getVersionHistoryId().getUUID());
+ InternalValue versionId = InternalValue.create(
+ history.getRootVersionId().getUUID());
// jcr:versionHistory
conditionalAddProperty(
- node, NameConstants.JCR_VERSIONHISTORY, PropertyType.REFERENCE, false,
- InternalValue.create(new UUID(history.getUUID())));
+ node, NameConstants.JCR_VERSIONHISTORY,
+ PropertyType.REFERENCE, false, historyId);
// jcr:baseVersion
conditionalAddProperty(
- node, NameConstants.JCR_BASEVERSION, PropertyType.REFERENCE, false,
- InternalValue.create(new UUID(rootVersion.getUUID())));
+ node, NameConstants.JCR_BASEVERSION,
+ PropertyType.REFERENCE, false, versionId);
// jcr:predecessors
conditionalAddProperty(
- node, NameConstants.JCR_PREDECESSORS, PropertyType.REFERENCE, true,
- InternalValue.create(new UUID(rootVersion.getUUID())));
+ node, NameConstants.JCR_PREDECESSORS,
+ PropertyType.REFERENCE, true, versionId);
// jcr:isCheckedOut
conditionalAddProperty(
- node, NameConstants.JCR_ISCHECKEDOUT, PropertyType.BOOLEAN, false,
- InternalValue.create(true));
+ node, NameConstants.JCR_ISCHECKEDOUT,
+ PropertyType.BOOLEAN, false, InternalValue.create(true));
}
}