This week's book giveaway is in the Agile and Other Processes forum.
We're giving away four copies of The Little Book of Impediments (e-book only) and have Tom Perry on-line!
See this thread for details.
Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

CMT and Connection Objects

 
Sandeep Vaid
Ranch Hand
Posts: 392
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In Mikalai's notes: it's written that:
@TransactionAttribute(TransactionAttributeType.REQUIRED)
public void someMethod(...) {
// obtain con1 and con2 connection objects
con1 = ...;
con2 = ...;
stmt1 = con1.createStatement();
stmt2 = con2.createStatement();

//
// Perform some updates on con1 and con2. The container
// automatically enlists con1 and con2 with the container-
// managed transaction.
//
}

As we have specified TransactionAttributeType.REQUIRED, container will start a transaction (i guess on a Connection)
Q- a) Container will start transaction on which Connection (database) Object? From where it obtains information about my database ?
In other words does container uses JTA (Distributed transaction manager layer), from where it obtains info regarding my databses,
user password, url etc..
Q- b) What does the statement means "The container automatically enlists con1 and con2 with the container-manager transaction"?
 
Deepika Joshi
Ranch Hand
Posts: 268
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
JTA is (default) transaction manager for EJB3,

From where it obtains information about my database? from where it (JTA) obtains info regarding my databses, user password, url etc..

if you are reading EJB3 In Action, then check out "Listing 11.6 An example persistence.xml, page 411";
where user provides, transaction-type = "JTA", provider=toplink & jta-data-source=dataSourceName
In your application server you provide information for dataSource - i.e. dsName, user, password
check out page 415 of EJB3IA for glassfish App. server DataSource settings....





Container will start transaction on which Connection (database) Object?

if you are ware of ACID properties of transaction which means (in short) all done (commit everything) or nothing (rollback everything),
so all the resources (connections) enclosed in boundary of transaction will participate in transaction.

What does the statement means "The container automatically enlists con1 and con2 with the container-manager transaction"?

container-manager transaction > user is not writing any transaction mgmt code, user is just asking for transaction service
container is initiating transaction service & con1 & con2 are participating...

hope it may be helpful...
 
Sandeep Vaid
Ranch Hand
Posts: 392
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Deepika for the answers...
i was a bit confused about local transaction and distributed transactions...
I found the following good links which clarifies these:
1) http://archive.devx.com/java/free/articles/dd_jta/jta-1.asp
2) http://publib.boulder.ibm.com/infocenter/db2luw/v8/index.jsp?topic=/com.ibm.db2.udb.doc/ad/tjvcmtrl.htm

Crux is:
For local transaction (JDBC) - We first obtain Connection Object and use it's API to control transaction...
For a global distributed transaction(JTA) - We start a transaction and whatever operations we perform on any connection object will be the part of this transaction..
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic