Transaction Model and Policy

Source: Internet
Author: User

See: http://www.ibm.com/developerworks/cn/java/j-ts2.html

 

I. Transaction Model:

1. Local Transaction Model

JDBC local transaction,

Dbconnection. setautocommit (true );

In the local transaction model, transactions are managed and maintained by the underlying database (DBMS) or message provider (Message provider). From the developer's perspective, you only need to manage connections) you do not need to manage transactions. The local transaction model works well in simple update operations of small projects, but in more complex application scenarios, one problem is that it is difficult to coordinate resources in an Xa global transaction. Generally, the EJB project does not use such a transaction model.

 

2. Programmatic Transaction Model

Bean management transactions in EJB

In the programming transaction model, developers no longer develop for connections but transactions. In the EJB project, this type of transaction model is embodied in bean-managed transactions (bean-managed transactions -- BMT). Generally, usertransaction is obtained through sessioncontext or JNDI. The programmatic transaction model has a major architectural limitation: we cannot transmit the transaction context (transaction context) between two beans that use the programmatic transaction mode ). However, we can pass the transaction context of an EJB or client that uses the programmatic transaction model to an EJB that uses the declarative transaction model. Therefore, in general, we only use the programmatic transaction model in the client that calls EJB.

 

Obtain the platform Transaction Manager in spring, commit () or rollback ()

 

3. Declarative Transaction Model

In the declarative transaction model, containers manage and maintain transactions, which means that developers do not need to write Java code to start or commit a transaction, instead, a certain "Declaration" is used to tell the container how to manage transactions. We can declare the container through the ejb-jar.xml configuration file, or use annotations or deployment descriptors to declare the use of transactions. In EJB, the declarative transaction model is reflected in the container-managed transactions-CMT ).

 

Container managed transactions(CMT)

Spring usage@TransactionalAnnotations, while EJB 3.0 uses@TransactionAttributeAnnotations. When the declarative transaction model is used, the container will not automatically roll back the transaction for the detected exceptions. The developer must specify where the exception occurred and when to roll back the transaction. In spring framework, you can use@TransactionalComment onrollbackForAttribute to specify it. In EJB, you callSessionContextOnsetRollbackOnly()Method to specify it.

 

In most cases, we use a declarative transaction model (CMT) when implementing ejbs, while a programmatic transaction model is used in client code that calls these ejbs.

 

 

Ii. Transaction Policy

 

  • Client orchestration transaction policy
  • API layer transaction policy
  • High concurrency transaction policy
  • High-speed processing transaction policy
  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.