• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

how to know that I am in a transaction context

 
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all,
I have the following problem : some code is run in the context of an SessionBean or a Message-Driven Bean.
In the first case, the code assume that I am in bean-managed transaction, so i mark the transaction bounds manually. In the second one, the transaction is container managed.
I have a portion of code that starts a new UserTransaction and do other things... I'd like to re-use this code in the context of the MDB but I'd like to modify it in order to decide or not to start a new UserTransaction (as I should not in case of MDB)...
How can I now that a UserTransaction is currently running ?
The only way I found until now is to do like :
UserTransaction tran = ... ;
boolean transactionAlreadyRunning = false;
try {
tran.begin();
} catch (NotSupportedException) {
transactionAlreadyRunning = true;
}
Any other idea ?
Christophe
 
Ranch Hand
Posts: 162
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Christophe Grosjean:

How can I now that a UserTransaction is currently running ?
Christophe


Did you check UserTransaction.getStatus() method ?
 
author
Posts: 11962
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Vinod John:

Did you check UserTransaction.getStatus() method ?


Just as "VJ" (do people call you that? ) mentioned, you can call UserTransaction.getStatus() which should return javax.transaction.Status.STATUS_NO_TRANSACTION if the current thread has no transaction context.
 
Christophe Grosjean
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you, I'll try that !
Christophe
 
Vinod John
Ranch Hand
Posts: 162
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Lasse Koskela:

do people call you that?


You are the 1st person you have that previlage

 
Are you okay? You look a little big. Maybe this tiny ad will help:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic