FAQ
Hi,

I am not sure if I understood the concept of user-defined transaction:

I am accessing two different db-schemas at the same time, using two DataDomains, one for each schema.
Now I want to update data (synchronously) on both schemas with my own user-defined transaction-scope.

I have to use two different transactions, one for each Domain.
So that's my plan to handle the transactions:

Transaction tx1 = domain1.createTransaction();
Transaction tx2 = domain2.createTransaction();

Transaction.bindThreadTransaction(tx1);
Transaction.bindThreadTransaction(tx2);

(Here is the first question: is it possible to bind two different transactions to the same thread?)

try {
... doing some work on both schemas through SQLTemplates ...

// success
tx1.commit();
tx2.commit();

} catch (Exception ex) {
// error
tx1.setRollbackOnly();
tx2.setRollbackOnly();
} finally {

Transaction.bindThreadTransaction(null);
// hmm... does that means that both Transactions were unbind?

if ((tx1.getStatus() == Transaction.STATUS_MARKED_ROLLEDBACK) ||
(tx2.getStatus() == Transaction.STATUS_MARKED_ROLLEDBACK)) {
try {
tx1.rollback();
tx2.rollback();
} catch (Exception ex1) {
...
}
}
}

Any help appreciated

Jens


--
"Feel free" - 10 GB Mailbox, 100 FreeSMS/Monat ...
Jetzt GMX TopMail testen: http://www.gmx.net/de/go/topmail

Search Discussions

  • Andrus Adamchik at Apr 26, 2007 at 11:53 am

    On Apr 26, 2007, at 1:04 PM, Jens Mayer wrote:

    (Here is the first question: is it possible to bind two different
    transactions to the same thread?)
    No you can't.
    I am accessing two different db-schemas at the same time, using two
    DataDomains, one for each schema.
    Now I want to update data (synchronously) on both schemas with my
    own user-defined transaction-scope.
    You can use just one... Normally it should not matter whether domain1
    or domain2 created a transaction, or you did it manually. If it is
    bound to an execution thread, Cayenne will figure out how to add all
    JDBC connections to this single transaction.

    Andrus

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupuser @
categoriescayenne
postedApr 26, '07 at 10:05a
activeApr 26, '07 at 11:53a
posts2
users2
websitecayenne.apache.org

2 users in discussion

Jens Mayer: 1 post Andrus Adamchik: 1 post

People

Translate

site design / logo © 2022 Grokbase