java - What is the real delivered value of JTA? -


i'm trying wrap head around value underneath java transactions api (jta) , 1 of implementations, bitronix. dig deeper , deeper documentation, can't think of following, simple example:

public interface transactional {     public void commit(object);     public void rollback(); }  public class transactionalfilewriter extends filewriter implements transactional {     @override     public void commit(object obj) {         string str = (string)obj;          // write string file.         write(str);     }      @override     public void rollback() {         // obtain handler file writing to, , delete file.         // returns file system state in before created file , started writing it.         file f = getfile();          // pseudo-code sake of example.         file.delete(f);     } }  // method in class somewhere... public void dosomething(file somefile) {     transactionalfilewriter txfilewriter = gettxfw(somefile);     try {         txfilewriter.commit("create file , write message it.");     } catch(throwable t) {         txfilewriter.rollback();     } } 

don't caught in actual code above. idea simple: transactional file writer creates file , writes it. it's rollback() method deletes file, returning file system same state in before commit(object).

am missing here? jta offers? or there whole different set of dimensionality/aspects transactionality isn't represented simple example above? i'm guessing latter have yet see concrete in jta docs. if missing something, it, , can show me concrete examples? can see transactionality being huge component of jdbc example of jta in action other databases.

the biggest feature of jta can compose several transactional stores in 1 application , run transactions span across these independent stores.

for instance, can have db, distributed transactional key-value store , simple filewriter , have transaction performs operations on of these , commit changes in stores @ once.

take @ infinispan. that's transactional data grid, uses jta , can used in combination other jta transactional services.

edit:

basically jta connected x/open xa standard , provides means interact x/open xa resources directly in java code. can use alredy existing data-stores hold x/open xa compliant resources, such databases, distributed data-grids , on. or can define own resources implementing javax.transaction.xa.xaresource. then, when user transaction uses these resources, transaction manager orchestrate you, no matter resources located, in data-store.

the whole bussiness managed transaction manager responsible synchronizing independent data-stores. jta doesn't come transaction manager. jta api. write own if wish (javax.transaction.transactionmanager), that's difficult task. instead want use implemented jta service/library features transaction manager. instance, if use infinispan in application can use transaction manager allow transactions interact different data-stores well. it's best seek further information on how accomplish implementators of jta interface.

you can find full jta api documentation here, though it's pretty long. there tutorials available talk how use java ee transaction manager , update multiple data-stores pretty obscure , doesn't provide code samples.

you can check out infinispan's documentation , tutorials, though can't see example combine infinispan other data-store.

edit 2:

to answer question comment: understanding more or less correct, i'll try clarify further.

it'll easier explain architecture , answer question picture. below taken jta spec 1.1

this x/open xa architecture:

x/open xa achitecture

each data-store (a database, message queue, sap erp system, etc) has own resource manager. in case of relational database, jdbc driver resource adapter represents resource manager of database in java. each resource has available through xaresource interface (so transaction manager can manage them without knowing implementation details of specific data-store).

your application communicates both resource managers (to access specific resources) resource adapters, transaction manager (to start/finish transaction) usertransaction interface. each resource manager needs initialized first , has configured global transactions (i.e. spanning across several data-stores).

so basically, yes, data-stores independent logical units group resources. exhibit interface allows perform local transactions (confined specific data-store). interface might better-performing or might expose additional functionality specific data-store not available through jta interface.

this architecture of jta environment:

jta architecture

the small half-circle represents jta interface. in case you're interested in jta usertransaction interface. use ejb (transactional beans) , application server manage transactions you, that's different way go.

from transaction manager’s perspective, actual implementation of transaction services not need exposed; high-level interfaces need defined allow transaction demarcation, resource enlistment, synchronization , recovery process driven users of transaction services.

so transaction manager can understood interface represents actual mechanism used manage transactions such jts implementation, thinking whole not error neither.

from understand, if run instance jboss application server, you're equipped transaction manager underlying transaction service implementation.


Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

jsf - How to ajax update an item in the footer of a PrimeFaces dataTable? -

django - CSRF verification failed. Request aborted. CSRF cookie not set -