Hi all,

I have a number of Jcr-based Daos that operate on my beans.  In some cases,
I have been using the session as a means to control a simple transaction. 
For example, I create a session and pass it to two different DAO create()
methods.  Only when all my Dao work is complete do I call session.save(). 
See my example code below:


        Session session = getSession();

        JcrUserDao userDao = new JcrUserDao();
        JcrProductDao productDao = new JcrProductDao();

        userDao.create(aUser, session);

        productDao.create(aProduct, session);

        session.save();


The problem I have is that during a single transaction, I would like to
create a multiple value property that contains strings for all node UUIDs
create during the single transaction (i.e. hold 'weak' references to any
newly created node UUIDs).  I read in the specification that it is not safe
to use a referenceable node's UUID until session.save() has been called and
the changes have been persisted.  However, with the above example, if I call
save() before the two create methods have completed, I ruin my simple
transaction.

I have been reading the spec again regarding user managed transactions. 
Consider the following code:


        Session session = getSession();

        // Get user transaction (for example, through JNDI)
        UserTransaction utx = ... 

        JcrUserDao userDao = new JcrUserDao();
        JcrProductDao productDao = new JcrProductDao();

        utx.begin();

        Node newUserNode = userDao.create(aUser, session);

        session.save();

        String UUID = newUserNode.getUUID();

        Node newProductNode = productDao.create(aProduct, session);

        session.save();

        utx.commit();


After the first call to session.save(), would it then be safe to get a
node's UUID?

For example, in my JcrProductDao's create() method I create one Product node
and then call another Dao to create N number of Element nodes.  I would like
my multiple value property of Product to hold all new Element node UUIDs.

However, I also read this in the JCR 1.0 spec:

        "Note, however, that changes made in the transient storage are not 
recorded
by a transaction.
        This means that a rollback will not revert changes made to the transient
storage of the Session.
        After a rollback the Session object state will still contain any pending
changes that were present before the rollback."

I don't mind if I cannot revert a session's pending changes just as long as
I can control when the changes are made persistent with a user managed
transaction.

Any help or advice would be greatly appreciated.  Thanks for reading.
-- 
View this message in context: 
http://www.nabble.com/User-Managed-Transactions...-tp24687924p24687924.html
Sent from the Jackrabbit - Users mailing list archive at Nabble.com.

Reply via email to