XAPool Project
Project Mail Lists
FAQs

Software
Downloads
License
Documentation
Examples
Success Stories

About Enhydra.org


Examples


GenericPool: use of the pool, just to show it is a classical pool
Pool Datasource: a sample to use connection from a datasource
XA Pool Datasource: to get connection which can be used in distributed transactions (this example comes from JOTM)
MultipleConnection: demonstrate the use of multiple connections in the same transaction
MultipleTransaction: one connection and multiple transaction
FalseRollback: here no transaction, but a rollback on the connection close()
SaveAutoCommit: save the state of the autocommit flag before the beginnig of the transaction and restore it after the commit or the rollback of the transaction
SimpleStatement: test the Statement implementation

  ds : datasource
  utx : UserTransaction
  c : Connection
  ... : means in most of the case, an executeUpdate on a PreparedStatement object

MultipleConnection:

source file: MultipleConnection.java
This example shows how to start a transaction, get and close connections, and commit or rollback the transaction.
   utx.begin();
   c = ds.getConnection();
   ...
   c.close();
   c = ds.getConnection();
   ...
   c.close();
   utx.commit() or utx.rollback();

MultipleTransaction:

source file: MultipleConnection.java
This example starts to get a connection, begin and commit a transaction, and begin and rollback an other one.
   c = ds.getConnection();
   utx.begin();
   ...
   utx.commit();
   utx.begin();
   ...
   utx.rollback();
   utx.close();

FalseRollback:

source file: FalseRollback.java
This example demonstrates that if you set the AutoCommit flag to false, do some update on your database, and close the connection, all datas are rollbacked. This example does not use transaction.
   c = ds.getConnection();
   c.setAutocommit(true);
   ...
   c.close();
   c = ds.getConnection();
   c.setAutoCommit(false);
   ...
   c.close();

SaveAutoCommit:

source file: SaveAutoCommit.java
This example shows that the AutoCommit flag is saved and restored after the commit of the transaction, in our case, autocommit2 and autocommit are equals.
   c = ds.getConnection();
   c.setAutoCommit(autocommit);
   utx.begin();
   ...
   utx.commit();
   autocommit2 = c.getAutoCommit();
   c.close();

GenericPool:

source file: SimpleGenericPool.java
source file: Car.java
source file: SimplePoolHelper.java

Pool DataSource:

source file: StandardPoolDataSourceExample.java

XA Pool DataSource:

source file: StandardXAPoolDataSourceExample.java
source file: DatabaseHelper.java

SimpleStatement:

source file: SimpleStatement.java