Oracle 5.0 Reference Manual page 2129

Table of Contents

Advertisement

public class Ex3DaoImpl implements Ex3Dao {
protected DataSource dataSource;
protected SqlUpdate updateQuery;
protected SqlFunction idQuery;
public Integer createCity(String name, String countryCode,
String district, Integer population) {
}
protected Integer getLastId() {
return idQuery.run();
}
}
You can see that we only operate on abstract query objects here and do not deal directly with the
JDBC API. Also, this is the complete implementation. All of our transaction management will be dealt
with in the configuration. To get the configuration started, we need to create the DAO.
<bean id="dao" class="code.Ex3DaoImpl">
<property name="dataSource" ref="dataSource"/>
<property name="updateQuery">...</property>
<property name="idQuery">...</property>
</bean>
Now you need to set up the transaction configuration. The first thing you must do is create transaction
manager to manage the data source and a specification of what transaction properties are required for
the
methods.
dao
<bean id="transactionManager"
class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource"/>
</bean>
<tx:advice id="txAdvice" transaction-manager="transactionManager">
<tx:attributes>
<tx:method name="*"/>
</tx:attributes>
</tx:advice>
The preceding code creates a transaction manager that handles transactions for the data source
provided to it. The
transaction for all methods. Finally you need to apply this advice with an AOP pointcut.
<aop:config>
<aop:pointcut id="daoMethods"
expression="execution(* code.Ex3Dao.*(..))"/>
<aop:advisor advice-ref="txAdvice" pointcut-ref="daoMethods"/>
</aop:config>
This basically says that all methods called on the
make use of this, you only have to retrieve the
the
instance.
dao
Ex3Dao dao = (Ex3Dao) ctx.getBean("dao");
Integer id = dao.createCity(name,
We can verify from this that there is no transaction management happening in our Java code and it is
all configured with Spring. This is a very powerful notion and regarded as one of the most beneficial
features of Spring.
20.3.13.3. Connection Pooling with Spring
Using Connector/J with Spring
updateQuery.update(new Object[] { name, countryCode,
district, population });
return getLastId();
uses this transaction manager and the attributes specify to create a
txAdvice
interface will be wrapped in a transaction. To
Ex3Dao
from the application context and call a method on
dao
countryCode, district, pop);
2109

Advertisement

Table of Contents
loading

This manual is also suitable for:

Mysql 5.0

Table of Contents