Hi,

A query is always executed against the persistent workspace content the session is connected to. Which means it does not take un-committed content into account.

The spec says:

<spec>
6.6.7 Search Scope
A query searches the persistent workspace associated with the current session. It does not search any pending changes that may be recorded on the session but not yet saved.
</spec>

The last sentence is a bit misleading because it does not take XA transactions into account. Later in the spec there is this clarification:

<spec>
7.1.1.3 Effect of Transactions
In repositories that support transactions, all changes, whether workspace-direct or session-mediated, may be further insulated from persistent storage by their transaction context. If a set of write methods is within the scope of a transaction then the changes they make will only be reflected in persistent storage upon commit of that transaction.
</spec>

Section "8.1.3 Save vs. Commit" also talks about the effects of XA transactions in more detail.

regards
 marcel

Rasik Pandey wrote:
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