Hi Jackrabbit Developers,

Could someone have a look at the thread I posted over on the Spring JCR forum.

http://forum.springframework.org/showthread.php?t=27738

Essentially, I am unable to save nodes and then query and find them
within the same session and transaction. One thing to keep in mind, is
that the transaction is never committed in my scenario. I am able to
reproduce this same behavior in Jackrabbit's XATest case by adding few
lines of code to the testAddNodeCommit method. Basically, I run a
query after saving the testRootNode and prior to committing the
transaction. You will see a second assertion which succeeds after the
commit.

Regards,
Rus Pandey

/**
    * Add a node inside a transaction and commit changes. Make sure
    * node exists for other sessions only after commit.
    * @throws Exception
    */
   public void testAddNodeCommit() 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);
       n.addMixin(mixReferenceable);
       testRootNode.save();


       Query q =
superuser.getWorkspace().getQueryManager().createQuery("//"+nodeName1,
Query.XPATH);
       assertEquals("1 result Node from querying  before commit AND
after save",
                                1, q.execute().getNodes().getSize());

       // assertion: node exists in this session
       try {
           superuser.getNodeByUUID(n.getUUID());
       } catch (ItemNotFoundException e) {
           fail("New node not visible after save()");
       }

       // assertion: node does not exist in other session
       Session otherSuperuser = helper.getSuperuserSession();

       try {
           otherSuperuser.getNodeByUUID(n.getUUID());
           fail("Uncommitted node visible for other session");
       } catch (ItemNotFoundException e) {
           /* expected */
       }

       // commit
       utx.commit();

       assertEquals("1 result Node from querying  after commit",
                                1, q.execute().getNodes().getSize());

        // assertion: node exists in this session
       try {
           otherSuperuser.getNodeByUUID(n.getUUID());
       } catch (ItemNotFoundException e) {
           fail("Committed node not visible in this session");
       }

       // assertion: node also exists in other session
       try {
           otherSuperuser.getNodeByUUID(n.getUUID());
       } catch (ItemNotFoundException e) {
           fail("Committed node not visible in other session");
       }

       // logout
       otherSuperuser.logout();
   }

Reply via email to