Return-Path: Delivered-To: apmail-jackrabbit-commits-archive@www.apache.org Received: (qmail 75745 invoked from network); 7 Oct 2008 10:17:10 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 7 Oct 2008 10:17:10 -0000 Received: (qmail 21752 invoked by uid 500); 7 Oct 2008 10:17:09 -0000 Delivered-To: apmail-jackrabbit-commits-archive@jackrabbit.apache.org Received: (qmail 21725 invoked by uid 500); 7 Oct 2008 10:17:08 -0000 Mailing-List: contact commits-help@jackrabbit.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@jackrabbit.apache.org Delivered-To: mailing list commits@jackrabbit.apache.org Received: (qmail 21716 invoked by uid 99); 7 Oct 2008 10:17:08 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 07 Oct 2008 03:17:08 -0700 X-ASF-Spam-Status: No, hits=-1999.9 required=10.0 tests=ALL_TRUSTED,DNS_FROM_SECURITYSAGE X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 07 Oct 2008 10:16:12 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id B63AF2388879; Tue, 7 Oct 2008 03:16:48 -0700 (PDT) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r702425 - in /jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core: ./ version/ xml/ Date: Tue, 07 Oct 2008 10:16:45 -0000 To: commits@jackrabbit.apache.org From: jukka@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20081007101648.B63AF2388879@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: jukka Date: Tue Oct 7 03:16:43 2008 New Revision: 702425 URL: http://svn.apache.org/viewvc?rev=702425&view=rev Log: JCR-1775: Transaction-safe versioning All calls to VersionManager's getVersionHistory and createVersionHistory followed this pattern: VersionHistory vh = manager.getVersionHistory(...); if (vh == null) { vh = manager.createVersionHistory(...); } Simplified things by making getVersionHistory() automatically create the version history if it doesn't already exist. This simplifies the client code to: VersionHistory vh = manager.getVersionHistory(...); 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/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=702425&r1=702424&r2=702425&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 03:16:43 2008 @@ -2003,13 +2003,7 @@ */ private VersionHistory getOrCreateVersionHistory(NodeState node) throws RepositoryException { - VersionManager vMgr = session.getVersionManager(); - VersionHistory vh = vMgr.getVersionHistory(session, node); - if (vh == null) { - // create a new version history - vh = vMgr.createVersionHistory(session, node); - } - return vh; + return session.getVersionManager().getVersionHistory(session, node); } /** 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=702425&r1=702424&r2=702425&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 03:16:43 2008 @@ -726,10 +726,8 @@ * IMPORT_UUID_COLLISION_REPLACE_EXISTING; * otherwise create a new version history */ - VersionHistory vh = vMgr.getVersionHistory(session, nodeState); - if (vh == null) { - vh = vMgr.createVersionHistory(session, nodeState); - } + VersionHistory vh = + 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)); 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=702425&r1=702424&r2=702425&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 03:16:43 2008 @@ -228,16 +228,12 @@ } /** - * Returns the version history associated with the given node. - * - * @param session - * @param node the node whose version history's id is to be returned. - * @return the version history associated with the given node - * or null if that node doesn't have a version history. - * @throws RepositoryException if an error occurs + * {@inheritDoc} */ public VersionHistory getVersionHistory(Session session, NodeState node) throws RepositoryException { + NodeId id = null; + acquireReadLock(); try { String uuid = node.getNodeId().getUUID().toString(); @@ -245,17 +241,33 @@ NodeStateEx parent = getParentNode(uuid, false); if (parent != null && parent.hasNode(name)) { - NodeId id = - parent.getState().getChildNodeEntry(name, 1).getId(); - return (VersionHistory) ((SessionImpl) session).getNodeById(id); - } else { - return null; + id = parent.getState().getChildNodeEntry(name, 1).getId(); } } finally { releaseReadLock(); } + + if (id == null) { + id = createVersionHistory(session, node); + } + + return (VersionHistory) ((SessionImpl) session).getNodeById(id); } + + /** + * Creates a new version history. This action is needed either when creating + * a new 'mix:versionable' node or when adding the 'mix:versionable' mixin + * to a node. + * + * @param node + * @return identifier of the new version history node + * @throws RepositoryException + * @see #getVersionHistory(Session, NodeState) + */ + protected abstract NodeId createVersionHistory( + Session session, NodeState node) throws RepositoryException; + /** * Returns the item with the given persistent id. Subclass responsibility. *

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=702425&r1=702424&r2=702425&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 03:16:43 2008 @@ -42,30 +42,15 @@ VirtualItemStateProvider getVirtualItemStateProvider(); /** - * Creates a new version history. This action is needed either when creating - * a new 'mix:versionable' node or when adding the 'mix:versionable' mixin - * to a node. - * - * @param node - * @return - * @throws RepositoryException - * @see #getVersionHistory(Session, NodeState) - */ - VersionHistory createVersionHistory(Session session, NodeState node) - throws RepositoryException; - - /** - * Returns the version history of the specified node or - * null if the given node doesn't (yet) have an associated - * version history. + * 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. * * @param session * @param node node whose version history should be returned - * @return the version history of the specified node or - * null if the given node doesn't (yet) have an - * associated version history. + * @return the version history of the specified node * @throws RepositoryException if an error occurs - * @see #createVersionHistory(Session, NodeState) */ VersionHistory 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=702425&r1=702424&r2=702425&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 03:16:43 2008 @@ -211,7 +211,7 @@ * This method must not be synchronized since it could cause deadlocks with * item-reading listeners in the observation thread. */ - public VersionHistory createVersionHistory(Session session, final NodeState node) + protected NodeId createVersionHistory(Session session, final NodeState node) throws RepositoryException { InternalVersionHistory history = (InternalVersionHistory) escFactory.doSourced((SessionImpl) session, new SourcedTarget() { @@ -223,7 +223,7 @@ if (history == null) { throw new VersionException("History already exists for node " + node.getNodeId()); } - return (VersionHistory) ((SessionImpl) session).getNodeById(history.getId()); + return history.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=702425&r1=702424&r2=702425&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 03:16:43 2008 @@ -131,13 +131,13 @@ /** * {@inheritDoc} */ - public VersionHistory createVersionHistory(Session session, NodeState node) + protected NodeId createVersionHistory(Session session, NodeState node) throws RepositoryException { if (isInXA()) { InternalVersionHistory history = createVersionHistory(node); xaItems.put(history.getId(), history); - return (VersionHistory) ((SessionImpl) session).getNodeById(history.getId()); + return history.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=702425&r1=702424&r2=702425&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 03:16:43 2008 @@ -308,10 +308,8 @@ * IMPORT_UUID_COLLISION_REPLACE_EXISTING; * otherwise create a new version history */ - VersionHistory history = versionManager.getVersionHistory(session, node); - if (history == null) { - history = versionManager.createVersionHistory(session, node); - } + VersionHistory history = + versionManager.getVersionHistory(session, node); Version rootVersion = history.getRootVersion(); // jcr:versionHistory