Reputation: 8903
I am trying to understand the distributed transactions
in Java EE
. After reading some online materials and books I came to know that in Java EE, there is specific API, called as JTA
which is one of the technology stacks of Java EE for taking care of distributed transactions. In addition to JTA, there are other concepts like: 2PC (two-phase commit) strategy
, XA, the eXtended Architecture
.
Considering only database, I have the following question in regards to distributed transactions:
Q1) Does the real support for distributed transactions come from the database drivers itself?
Q2) Are databases (the real db) aware of distributed transactions or it is taken care by other components?
Can anyone help me in clearing these queries please?
Upvotes: 0
Views: 369
Reputation: 722
JTA (as Java EE specification) defines interfaces (http://docs.oracle.com/javaee/7/api/javax/transaction/package-summary.html) for communication of transaction manager with application server (e.g. WildFly), application (your code) and resources (e.g. database). Transaction manager implements the specification and its purpose is to manage XA transactions. Transaction manager is part of the Java EE application server.
To answer your questions
A1) Distributed/XA transaction is managed by transaction manager as part of the application server. Any interaction from application server with database goes through jdbc driver (based at app server). For database being a full participant of the XA transaction then database and driver have to have capabilities for it.
Jdbc specification defines interfaces which jdbc have to provide for transaction manager being able to manage it. See for example PostgreSQL jdbc driver package xa (https://github.com/pgjdbc/pgjdbc/tree/master/pgjdbc/src/main/java/org/postgresql/xa) or check the jdbc spec itself.
Database has to offer capabilities to correctly respond to jdbc driver xa calls and specifically has to implement 2PC. When transaction manager commands to prepare database has to remember that there is some prepared transaction which works with such and such data for being able to finish it after transaction manager calls commit.
A2) If you understand the XA transaction as transaction compound from operation on several resources (some databases, a jms broker) then database itself does not have any notion which are other participants (how large the XA transaction is). Database knows only there is a XA transaction and I'm a participant.
All XA transaction management is responsibility of transaction manager. Database runs 2PC which is driven by transaction manager. Database only cares what data is part of such two phase commit and responds on calls coming from transaction manager in compliance with XA specification.
Upvotes: 0
Reputation: 683
In short, it's data base who actually has transactional functionality. It's database who must care that data after commit is consistent and correctly stored to disk.
At the same time, a driver can help you manage transactions. For instance, open it for you upon first request or automatically commit it.
Edit: Sorry, the main question was about distributed transactions. Distributed transactions are handled by driver and transaction manager. There is nothing special in this transaction from the data base's point of view.
Upvotes: 1