jackrabbit-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Tobias Bocanegra" <tobias.bocane...@day.com>
Subject Re: Transactions Saving Querying
Date Wed, 09 Aug 2006 08:42:23 GMT
the search index is not transactional. i.e. the items are indexed
after the transaction is comitted. that's why you can't find them
unless you commit the transaction.

regards, toby

On 8/8/06, Rasik Pandey <rbpandey@gmail.com> 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();
>     }
>


-- 
-----------------------------------------< tobias.bocanegra@day.com >---
Tobias Bocanegra, Day Management AG, Barfuesserplatz 6, CH - 4001 Basel
T +41 61 226 98 98, F +41 61 226 98 97
-----------------------------------------------< http://www.day.com >---

Mime
View raw message