From jackrabbit-commits-return-1427-apmail-incubator-jackrabbit-commits-archive=www.apache.org@incubator.apache.org Mon Oct 03 16:30:04 2005 Return-Path: Delivered-To: apmail-incubator-jackrabbit-commits-archive@www.apache.org Received: (qmail 67342 invoked from network); 3 Oct 2005 16:30:04 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur.apache.org with SMTP; 3 Oct 2005 16:30:04 -0000 Received: (qmail 8709 invoked by uid 500); 3 Oct 2005 16:30:03 -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 8698 invoked by uid 500); 3 Oct 2005 16:30:03 -0000 Delivered-To: apmail-incubator-jackrabbit-cvs@incubator.apache.org Received: (qmail 8695 invoked by uid 99); 3 Oct 2005 16:30:03 -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 [209.237.227.194] (HELO minotaur.apache.org) (209.237.227.194) by apache.org (qpsmtpd/0.29) with SMTP; Mon, 03 Oct 2005 09:30:03 -0700 Received: (qmail 67282 invoked by uid 65534); 3 Oct 2005 16:29:43 -0000 Message-ID: <20051003162943.67278.qmail@minotaur.apache.org> Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r293380 - in /incubator/jackrabbit/trunk/src: java/org/apache/jackrabbit/core/ItemImpl.java java/org/apache/jackrabbit/core/NodeImpl.java test/org/apache/jackrabbit/core/XATest.java Date: Mon, 03 Oct 2005 16:29:42 -0000 To: jackrabbit-cvs@incubator.apache.org From: tripod@apache.org X-Mailer: svnmailer-1.0.5 X-Virus-Checked: Checked by ClamAV on apache.org X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N Author: tripod Date: Mon Oct 3 09:29:32 2005 New Revision: 293380 URL: http://svn.apache.org/viewcvs?rev=293380&view=rev Log: JCR-237 - Item.isNew() does not work correctly within a transaction Modified: incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/ItemImpl.java incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/NodeImpl.java incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/core/XATest.java Modified: incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/ItemImpl.java URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/ItemImpl.java?rev=293380&r1=293379&r2=293380&view=diff ============================================================================== --- incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/ItemImpl.java (original) +++ incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/ItemImpl.java Mon Oct 3 09:29:32 2005 @@ -1167,6 +1167,15 @@ * {@inheritDoc} */ public boolean isNew() { + return state.isTransient() && state.getOverlayedState() == null; + } + + /** + * checks if this item is new. running outside of transactions, this + * is the same as {@link #isNew()} but within a transaction an item can + * be saved but not yet persisted. + */ + protected boolean isTransactionalNew() { return state.getStatus() == ItemState.STATUS_NEW; } 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?rev=293380&r1=293379&r2=293380&view=diff ============================================================================== --- incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/NodeImpl.java (original) +++ incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/NodeImpl.java Mon Oct 3 09:29:32 2005 @@ -3754,7 +3754,8 @@ // check state of this instance sanityCheck(); - if (isNew()) { + // todo: fixme for transactions + if (isTransactionalNew()) { throw new LockException("Node not locked: " + safeGetJCRPath()); } @@ -3792,7 +3793,8 @@ // check state of this instance sanityCheck(); - if (!isNodeType(QName.MIX_LOCKABLE) || isNew()) { + // todo: fixme for transactions + if (!isNodeType(QName.MIX_LOCKABLE) || isTransactionalNew()) { // a node that is new or not lockable never holds a lock return false; } @@ -3808,7 +3810,8 @@ // check state of this instance sanityCheck(); - if (isNew()) { + // todo: fixme for transactions + if (isTransactionalNew()) { return false; } @@ -3838,7 +3841,8 @@ * @throws RepositoryException if some other error occurs */ protected void checkLock() throws LockException, RepositoryException { - if (isNew()) { + // todo: fixme for transactions + if (isTransactionalNew()) { // a new node must not be checked return; } Modified: incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/core/XATest.java URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/core/XATest.java?rev=293380&r1=293379&r2=293380&view=diff ============================================================================== --- incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/core/XATest.java (original) +++ incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/core/XATest.java Mon Oct 3 09:29:32 2005 @@ -57,8 +57,12 @@ n.checkin(); + assertFalse("Node must be checked-in", n.isCheckedOut()); + // commit utx.commit(); + + assertFalse("Node must be checked-in", n.isCheckedOut()); } /** @@ -191,6 +195,82 @@ Node n = (Node) otherSuperuser.getItem(testRootNode.getPath()); assertEquals(n.getProperty(propertyName1).getString(), "1"); otherSuperuser.logout(); + } + + /** + * @throws Exception + */ + public void testPropertyIsNew() throws Exception { + // prerequisite: non-existing property + if (testRootNode.hasProperty(propertyName1)) { + testRootNode.getProperty(propertyName1).remove(); + testRootNode.save(); + } + + // get user transaction object + UserTransaction utx = new UserTransactionImpl(superuser); + + // start transaction + utx.begin(); + + // 'add' property and save + testRootNode.setProperty(propertyName1, "0"); + + assertTrue("New property must be new.", testRootNode.getProperty(propertyName1).isNew()); + + testRootNode.save(); + + assertFalse("Saved property must not be new.", testRootNode.getProperty(propertyName1).isNew()); + + // commit + utx.commit(); + } + + /** + * @throws Exception + */ + public void testNewNodeIsLocked() throws Exception { + // get user transaction object + UserTransaction utx = new UserTransactionImpl(superuser); + + // start transaction + utx.begin(); + + // add node and save + Node n = testRootNode.addNode(nodeName1, testNodeType); + testRootNode.save(); + + assertFalse("New node must not be locked.", n.isLocked()); + + // commit + utx.commit(); + } + + /** + * @throws Exception + */ + public void testPropertyIsModified() throws Exception { + // prerequisite: existing property + testRootNode.setProperty(propertyName1, "0"); + testRootNode.save(); + + // get user transaction object + UserTransaction utx = new UserTransactionImpl(superuser); + + // start transaction + utx.begin(); + + // 'add' property and save + testRootNode.setProperty(propertyName1, "1"); + + assertTrue("Unsaved property must be modified.", testRootNode.getProperty(propertyName1).isModified()); + + testRootNode.save(); + + assertFalse("Saved property must not be modified.", testRootNode.getProperty(propertyName1).isModified()); + + // commit + utx.commit(); } /**