jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tri...@apache.org
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 GMT
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();
     }
 
     /**



Mime
View raw message