To integrate with Altibase, the user can specify a dataSource in iBATIS or a dataSource in Spring. This chapter describes how to interface with Altibase using these two methods.
When Setting dataSource in Spring
To use iBATIS and Spring together, the user can specify iBATIS SqlMapClientFactoryBean bean in Spring's applicationContext.xml file.
If SqlMapClientFactoryBean bean is then set up to refer to each DAO bean, the methods corresponding to the CRUD can be invoked using the SqlMapClient object in the other bean.
To set up dataSource on Spring in an environment linked to iBATIS and Spring, select one of the methods described in the "Spring Integration Guide for Altibase" document, specify the dataSource in applicationContext.xml, and connect with iBATIS in the SqlMapClientFactoryBean bean of iBATIS.
At this time, specify the name of the SqlMapConfig file in the configLocation property of the SqlMapClientFactoryBean bean.
spring-jdbc.jar, spring-orm.jar,
Ex) ApplicationContext.xml file of SpringbatisConnection1
Spring Integration Guide for Altibase
When Setting dataSource to iBATIS
To set up dataSource on iBATIS in an environment connected to iBATIS and Spring is the same as described in the section "Configuring the data source in the SqlMapConfig file to interact with ALTIBASE" above. The user can specify Altibase in <Attributes for connecting to transactionManager> in SqlMapConfig file.
However, in order to link iBATIS in Spring, the SqlMapClientFactoryBean of iBATIS must be specified in the applicationContext.xml file as in the above "When Setting the dataSource in Spring".
The following example sets the dataSource on iBATIS in iBATIS and Spring integrating environments to work with ALTIBASE.
Ex) ApplicationContext.xml file of SpringIbatisConnection2
Ex) SqlMapConfigExample.xml file of SpringIbatisConnection2
The example above shows that the dataSource is set in SqlMapConfigExample.xml, and the SqlMapClientFactoryBean is set in the applicationContext.xml file by reading this SqlMapConfigExample.xml file.
To run SpringIbatisConnection2 example, Altibase.jar, ibatis-2.3.4.x.jar file and spring-orm.jar, spring.jar, and commons-logging.jar files are required. The spring-orm.jar, spring.jar, and commons-logging.jar files are files included in the Spring Framework. For detailed directory location, refer to the document "Spring Integration Guide for Altibase".
Using Altibase's ConnectionPool
The user can use AltibaseConnectionPool by using the ABConnectionPoolDataSource class provided by Altibase. In iBATIS and Spring interworking environment, the user can define dataSource bean by using ABConnectionPoolDataSource class in Spring's applicationContext.xml file.
It should be noted that there is no way to used Altibase ConnectionPool only in iBATIS without integrating with Spring. For more detailed information, please refer to the document "Spring Integration Guide for Altibase".
Ex) AltibaseConnection Pool's applicationContext.xml file attached to "
In iBATIS, if you specify the dataSource in <transactionManager> of the SqlMapConfig file, the setAutoComit (false); is automatically invoked when each CRUD method defined in the SqlMap file is invoked. After that, when the method is terminated, the transaction is committed and the mode is changed back to the default autocommit mode.
This also allows programmers to explicitly manage transactions in the application.
If iBATIS and Spring are integrated, transactions can be managed in Spring as well.
This chapter introduces these transaction management methods.
Transaction Management in iBATIS
When linking with DB in iBATIS, if dataSource is specified in <transactionManager> of SqlMapConfig file, setAutoCommit (false) automatically when each CRUD method defined in SqlMap file is called; is called. After that, when the method is terminated, the transaction is committed and the mode is changed back to the default autocommit mode.
In addition, the programmer can manage transactions directly in the application.
At this time, to start a transaction, call startTransaction () method of SqlMapClient, commitTransaction () method to commit, or endTransaction () method to rollback without commit.
The following is an example of explicitly processing a transaction in an application.
In order to execute the above example TransactionSample project, Altibase.jar and abates-2.3.4x.jar files are needed as in "Set dataSource in SqlMapConfig file to link with ALTIBASE".
Transaction Management in Spring
If iBATIS and Spring are connected, transactions can be managed in Spring. This document includes an example (LobSpringIbatisSample) for managing/processing transactions declaratively in Spring's applicationContext.xml file. For more detailed information, refer to the document "Spring Integration Guide for Altibase".