Recommendation, Connection pooling, Connection pooling using apache c3p0 – HP Integrity NonStop H-Series User Manual
Page 85
![background image](/manuals/397675/85/background.png)
2.
Use the
TransactionDefinition
and
TransactionStatus
objects to initiate
transactions, rollback, and commit.
DefaultTransactionDefinition def = new DefaultTransactionDefinition();
// explicitly setting the transaction name is something that can only be done programmatically
def.setName("SomeTxName");
def.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRED);
TransactionStatus status = txManager.getTransaction(def);
try {
// execute your business logic here
}
catch (MyException ex) {
txManager.rollback(status);
throw ex;
txManager.commit(status);
Recommendation
1.
Programmatic transaction management is usually a good idea only if you have a small
number of transactional operations. For example, if you have a web application that requires
transactions only for certain update operations, you may not want to set up transactional
proxies using Spring or any other technology. In this case, using the
TransactionTemplate
might be a good approach. Being able to set the transaction name explicitly is also something
that can only be done using the programmatic approach to transaction management.
2.
If your application has numerous transactional operations, declarative transaction
management is usually worthwhile. It keeps transaction management out of business logic,
and is not difficult to configure. When using the Spring framework, rather than EJB CMT,
the configuration cost of declarative transaction management is greatly reduced.
Connection Pooling
Connection Pooling is a cache of database connections maintained in the database memory so
that the connections can be reused when the database receives future requests for data. Every
time a database connection needs to be established, a request is made to pool or any object that
holds all the connections. Once that particular database activity is completed, the connection is
returned to the pool.
Many vendors provide their own customized Datasource Interfaces. However, we recommend
the use of Apache C3P0 as the Datasource Interface to be used with Spring applications. Spring
framework distribution contains the necessary files to use Apache C3P0 as the Datasource Interface
for connection pooling.In this section, we will discuss the steps to configure connection pooling
in your application using Apache C3P0.
Connection Pooling using Apache C3P0
C3P0 is an easy-to-use library for augmenting traditional (DriverManager-based) JDBC drivers
with JNDI-bindable DataSources, including DataSources that implement Connection and
Statement Pooling, as described by the jdbc3 spec and jdbc2 std extension.
To configure connection pooling using Apache C3P0, complete the following steps:-
1.
Add the
c3p0-0.9.1.2.jar
in your application
CLASSPATH
.
NOTE:
c3p0-0.9.1.2.jar
is available along with the Spring distribution package at
<Spring Home>/lib/c3p0
directory.
2.
Add the following basic configurations in applicationcontext.xml of your Spring application
to configure Apache C3P0 connection pooling:
Spring Framework Configurations
85