spring-Things-Open source jta things that do not depend on the application server

Source: Internet
Author: User
Tags prepare java se

Open source JTA things that do not depend on the application server implement JOTM and Atomikos transactions

Jotm    That is, based on the Java Open Transaction Manager (Java Open Transaction Manager), the implementation of the JTA specification, can be run in a non-application server environment, Web container or standalone Java se environment, the official website address: http://jotm.objectweb.org/.
Atomikos transactions Essentials It is a transaction manager developed for Atomikos, which is an open source product and a commercial extreme transactions. The official website address is: http://www.atomikos.com.

In this article, Atomikos Transactions Essentials is used to demonstrate JTA transaction usage, and because Atomikos is not very good for hsqldb distributed support, the following compatible databases are listed on the Atomikos official website: Oracle, Informix, Firstsql, DB2, MySQL, SQL Server, Sybase, this does not mean that the other databases are not supported, but the Atomikos team is not fully tested, and the author decides to use the Derby memory database to demonstrate JTA distributed transactions.

1 , first prepare Jar Package:

1.1 , prepare Derby Data Jar package, copy the following jar package into the downloaded Spring-framework-3.0.5.release-dependencies.zip:

Com.springsource.org.apache.derby-10.5.1000001.764942.jar


1
. 2.Prepare Atomikos transactions Essentials for JTA Transaction Support JTA Package, Use the AtomikosTransactionsEssentials3.5.5 version here to download Atomikostransactionsessentials-3.5.5.zip on the website and copy the following jar package to the classpath:

  Atomikos-util.jar  transactions-api.jar  transactions-essentials-all.jar  Transactions-jdbc.jar  Transactions-jta.jar  Transactions.jar

Place the above jar package in the Lib\atomikos directory and add it to the classpath.

2 , next look at Spring in how to configure atomikostransactionsessentials JTA transactions:

2.1 , configure a distributed data source:

  

<BeanID= "DataSource1"class= "Com.atomikos.jdbc.AtomikosDataSourceBean"Init-method= "Init"Destroy-method= "Close">    < Propertyname= "Uniqueresourcename"value= "Jdbc/test1"/>    < Propertyname= "Xadatasourceclassname"value= "Org.apache.derby.jdbc.EmbeddedXADataSource"/>    < Propertyname= "Poolsize"value= "5"/>    < Propertyname= "Xaproperties">        <Props>            <propKey= "DatabaseName">Test1</prop>            <propKey= "CreateDatabase">Create</prop>        </Props>    </ Property></Bean> <BeanID= "DataSource2"class= "Com.atomikos.jdbc.AtomikosDataSourceBean"Init-method= "Init"Destroy-method= "Close">...</Bean>

Here we configure two distributed data sources: use Com.atomikos.jdbc.AtomikosDataSourceBean to configure a atomikostransactionsessentials distributed data source:

    • Uniqueresourcename represents a unique resource name, if multiple data sources are not repeatable;
    • Xadatasourceclassname is a specific distributed data source vendor implementation;
    • Poolsize is the size of the data connection pool;
    • The Xaproperties property specifies the specific vendor database properties, such as databasename specifies the database name, CreateDatabase indicates that the specified database is created databasename when the Derby embedded database is started.

Here we also define a "DataSource2" Bean whose properties and "DataSource1" are identical except for the following:

    • Uniqueresourcename: Jdbc/test2 is used here because it cannot be duplicated;
    • DatabaseName: We need to specify two databases, so here we specify as Test2.

2.2. Configure the transaction manager:

<BeanID= "Atomikostransactionmanager"class= "Com.atomikos.icatch.jta.UserTransactionManager"Init-method= "Init"Destroy-method= "Close">        < Propertyname= "Forceshutdown"value= "true"/>  </Bean>  <BeanID= "Atomikosusertransaction"class= "COM.ATOMIKOS.ICATCH.JTA.USERTRANSACTIONIMP">  </Bean>   <BeanID= "TransactionManager"class= "Org.springframework.transaction.jta.JtaTransactionManager">      < Propertyname= "TransactionManager">          <refBean= "Atomikostransactionmanager"/>      </ Property>      < Propertyname= "UserTransaction">          <refBean= "Atomikosusertransaction"/>      </ Property>  </Bean>    

    • Atomikostransactionmanager: Defines the Atomikostransactionsessentials transaction manager;
    • Atomikosusertransaction: Defines the usertransaction, which is thread-safe;
    • TransactionManager: Defines the spring transaction manager, the TransactionManager property specifies the external transaction manager (the real transaction manager), uses UserTransaction to specify the UserTransaction, This property is typically used for local JTA implementations, which are automatically fetched from Jndi if the application Server Transaction manager is used.

Configuration is not easy, but if you do need to use JTA transactions, first select the Application Server Transaction manager, this sample is not suitable for production environment, if you want to apply to the production environment, you can consider purchasing atomikostransactionsessentials business support.

b) Specific server transaction manager

Spring also provides support for the integration of specific application server transaction managers, and currently provides support for IBM WebSphere, BEA WebLogic, Oracle oc4j Application Server advanced transactions, refer to spring Javadoc for specific use.

Now that we have learned how to configure the transaction manager, can only transaction manager spring automate transaction management? Of course not, this needs to be controlled, and now spring supports two types of transaction management: Programmatic and declarative transaction management. Now let's take a look at how to do the programmatic transaction management.

spring-Things-Open source jta things that do not depend on the application server

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.