Return-Path: Delivered-To: apmail-incubator-jackrabbit-commits-archive@www.apache.org Received: (qmail 73741 invoked from network); 21 Jan 2005 11:55:06 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur-2.apache.org with SMTP; 21 Jan 2005 11:55:06 -0000 Received: (qmail 61634 invoked by uid 500); 21 Jan 2005 11:55:05 -0000 Mailing-List: contact jackrabbit-commits-help@incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: jackrabbit-dev@incubator.apache.org Delivered-To: mailing list jackrabbit-commits@incubator.apache.org Received: (qmail 61620 invoked by uid 500); 21 Jan 2005 11:55:05 -0000 Delivered-To: apmail-incubator-jackrabbit-cvs@incubator.apache.org Received: (qmail 61617 invoked by uid 99); 21 Jan 2005 11:55:05 -0000 X-ASF-Spam-Status: No, hits=-9.8 required=10.0 tests=ALL_TRUSTED,NO_REAL_NAME X-Spam-Check-By: apache.org Received: from minotaur.apache.org (HELO minotaur.apache.org) (209.237.227.194) by apache.org (qpsmtpd/0.28) with SMTP; Fri, 21 Jan 2005 03:55:04 -0800 Received: (qmail 73712 invoked by uid 65534); 21 Jan 2005 11:55:03 -0000 Date: 21 Jan 2005 11:55:03 -0000 Message-ID: <20050121115503.73709.qmail@minotaur.apache.org> From: tripod@apache.org To: jackrabbit-cvs@incubator.apache.org Subject: svn commit: r125924 - in incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core: . state state/xml version version/persistence MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 X-Virus-Checked: Checked X-Spam-Rating: minotaur-2.apache.org 1.6.2 0/1000/N Author: tripod Date: Fri Jan 21 03:55:02 2005 New Revision: 125924 URL: http://svn.apache.org/viewcvs?view=rev&rev=125924 Log: - use seperate persistence manager for versioning Modified: incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/NodeImpl.java incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/RepositoryImpl.java incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/state/PersistentNodeState.java incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/state/xml/XMLPersistenceManager.java incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/version/VersionItemStateProvider.java incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/version/persistence/InternalFrozenNodeImpl.java incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/version/persistence/NativePVM.java incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/version/persistence/PersistentNode.java Modified: incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/NodeImpl.java Url: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/NodeImpl.java?view=diff&rev=125924&p1=incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/NodeImpl.java&r1=125923&p2=incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/NodeImpl.java&r2=125924 ============================================================================== --- incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/NodeImpl.java (original) +++ incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/NodeImpl.java Fri Jan 21 03:55:02 2005 @@ -2339,17 +2339,30 @@ throws VersionException, UnsupportedRepositoryOperationException, RepositoryException { + // check if versionable + checkVersionable(); + + // check if checked out if (!isCheckedOut()) { - String msg = "Unable to checkin node. Is not checked-out. " + safeGetJCRPath(); + String msg = safeGetJCRPath() + ": Node is already checked-in. ignoring."; log.debug(msg); - throw new VersionException(msg); + return getBaseVersion(); } + // check transient state if (isModified()) { String msg = "Unable to checkin node. Not allowed on transient node. " + safeGetJCRPath(); log.debug(msg); - throw new IllegalStateException(msg); + throw new InvalidItemStateException(msg); } + + // check if not merge failed + if (hasProperty(ItemImpl.PROPNAME_MERGE_FAILED) && getProperty(ItemImpl.PROPNAME_MERGE_FAILED).getValues().length>0) { + String msg = "Unable to checkin node. Clear 'jcr:mergeFailed' first. " + safeGetJCRPath(); + log.debug(msg); + throw new VersionException(msg); + } + Version v = session.versionMgr.checkin(this); Property prop = internalSetProperty(VersionManager.PROPNAME_IS_CHECKED_OUT, InternalValue.create(false)); prop.save(); @@ -2365,11 +2378,23 @@ */ public void checkout() throws UnsupportedRepositoryOperationException, RepositoryException { + // check if versionable + checkVersionable(); + + // check if already checked out if (isCheckedOut()) { - String msg = "Unable to checkout node. Is not checked-in. " + safeGetJCRPath(); + String msg = safeGetJCRPath() + ": Node is already checked-out. ignoring."; log.debug(msg); - throw new VersionException(msg); + return; + } + + // check transient state + if (isModified()) { + String msg = "Unable to checkout node. Not allowed on transient node. " + safeGetJCRPath(); + log.debug(msg); + throw new InvalidItemStateException(msg); } + Property prop = internalSetProperty(VersionManager.PROPNAME_IS_CHECKED_OUT, InternalValue.create(true)); prop.save(); prop = internalSetProperty(VersionManager.PROPNAME_PREDECESSORS, @@ -2679,7 +2704,7 @@ // search nearest ancestor that is versionable NodeImpl node = this; while (!node.hasProperty(VersionManager.PROPNAME_IS_CHECKED_OUT)) { - if (node.isRepositoryRoot() || !inherit) { + if (!inherit || node.isRepositoryRoot()) { return true; } node = (NodeImpl) node.getParent(); @@ -2700,16 +2725,18 @@ public void restore(String versionName) throws VersionException, UnsupportedRepositoryOperationException, RepositoryException { + boolean removeExisting = true; - if (!isCheckedOut()) { - String msg = "Unable to restore version. Node is not checked-out " + safeGetJCRPath(); - log.debug(msg); - throw new VersionException(msg); + // check if transient + if (session.hasPendingChanges()) { + String msg = "Unable to restore version. Session has pending changes."; + log.error(msg); + throw new InvalidItemStateException(msg); } GenericVersionSelector gvs = new GenericVersionSelector(); gvs.setName(versionName); - internalRestore(getVersionHistory().getVersion(versionName), gvs); + internalRestore(getVersionHistory().getVersion(versionName), gvs, removeExisting); save(); } @@ -2718,18 +2745,20 @@ */ public void restore(Version version) throws UnsupportedRepositoryOperationException, RepositoryException { + boolean removeExisting = true; - if (!isCheckedOut()) { - String msg = "Unable to restore version. Node is not checked-out " + safeGetJCRPath(); - log.debug(msg); - throw new VersionException(msg); + // check if transient + if (session.hasPendingChanges()) { + String msg = "Unable to restore version. Session has pending changes."; + log.error(msg); + throw new InvalidItemStateException(msg); } // check if 'own' version if (!version.getParent().getUUID().equals(getVersionHistory().getUUID())) { throw new VersionException("Unable to restore version. Not same version history."); } - internalRestore(version, new GenericVersionSelector(version.getCreated())); + internalRestore(version, new GenericVersionSelector(version.getCreated()), removeExisting); save(); } @@ -2741,22 +2770,24 @@ throws PathNotFoundException, ItemExistsException, ConstraintViolationException, UnsupportedRepositoryOperationException, RepositoryException { + boolean removeExisting = true; + + // check if transient + if (session.hasPendingChanges()) { + String msg = "Unable to restore version. Session has pending changes."; + log.error(msg); + throw new InvalidItemStateException(msg); + } // if node exists, do a 'normal' restore if (hasNode(relPath)) { getNode(relPath).restore(version); + } else { + // recreate node from frozen state + NodeImpl node = addNode(relPath, ((VersionImpl) version).getFrozenNode()); + node.internalRestore(version, new GenericVersionSelector(version.getCreated()), removeExisting); + node.getParent().save(); } - - // recreate node from frozen state - NodeImpl node = addNode(relPath, ((VersionImpl) version).getFrozenNode()); - if (!node.isCheckedOut()) { - String msg = "Unable to restore version. Node is not checked-out " + node.safeGetJCRPath(); - log.debug(msg); - throw new VersionException(msg); - } - - node.internalRestore(version, new GenericVersionSelector(version.getCreated())); - node.getParent().save(); } /** @@ -2764,18 +2795,20 @@ */ public void restoreByLabel(String versionLabel) throws UnsupportedRepositoryOperationException, RepositoryException { + boolean removeExisting = false; - if (!isCheckedOut()) { - String msg = "Unable to restore version. Node is not checked-out " + safeGetJCRPath(); - log.debug(msg); - throw new VersionException(msg); + // check if transient + if (session.hasPendingChanges()) { + String msg = "Unable to restore version. Session has pending changes."; + log.error(msg); + throw new InvalidItemStateException(msg); } Version v = getVersionHistory().getVersionByLabel(versionLabel); if (v == null) { throw new VersionException("No version for label " + versionLabel + " found."); } - internalRestore(v, new GenericVersionSelector(versionLabel)); + internalRestore(v, new GenericVersionSelector(versionLabel), removeExisting); save(); } @@ -2886,9 +2919,54 @@ * * @throws RepositoryException */ - private void internalRestore(Version version, VersionSelector vsel) + private void internalRestore(Version version, VersionSelector vsel, boolean removeExisting) throws UnsupportedRepositoryOperationException, RepositoryException { - internalRestore(((VersionImpl) version).getInternalVersion(), vsel); + internalRestore(((VersionImpl) version).getInternalVersion(), vsel, removeExisting); + } + + /** + * Checks if any frozen uuid in the given frozen node or its descendants + * collides with the one in the workspace. if 'removeExisting' is true, + * collisions will be removed, otherwise an ItemExistsException is thrown. + * If a frozen version history is already restored outside this nodes + * subtree, a exception is thrown, too, if the removeExisting is true. + * @param f + * @param removeExisting + * @throws RepositoryException + */ + private void checkUUIDCollisions(InternalFrozenNode f, boolean removeExisting) + throws RepositoryException { + + if (itemMgr.itemExists(new NodeId(f.getFrozenUUID()))) { + NodeImpl node = (NodeImpl) session.getNodeByUUID(f.getFrozenUUID()); + if (removeExisting) { + node.remove(); + } else { + throw new ItemExistsException("Unable to restore. UUID collides with " + node.safeGetJCRPath()); + } + } + InternalFreeze[] fs = f.getFrozenChildNodes(); + for (int i=0; i0 ? values[0].getType() : prop.getDefinition().getRequiredType(); - setPropertyValues(prop.getQName(), type, values); + setPropertyValues(prop.getQName(), values[0].getType(), values); } else { setPropertyValue(prop.getQName(), prop.internalGetValue()); }