Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Migrated to Confluence 5.3

...

Code Block
PoolingDataSource myDataSource = new PoolingDataSource();                                         (1)
myDataSource.setClassName("oracle.jdbc.xa.client.OracleXADataSource");                            (2)
myDataSource.setUniqueName("oracle");                                                             (3)
myDataSource.setMinPoolSize(0);                                                                   (4)
myDataSource.setMaxPoolSize(5);                                                                   (5)
myDataSource.setAcquireIncrement(1);                                                              (6)
myDataSource.setAllowLocalTransactions(true);                                                     (7)
myDataSource.setTestQuery("SELECT 1 FROM DUAL");                                                  (8)
myDataSource.setUseTmJoin(true);                                                                  (9)
myDataSource.setDeferConnectionRelease(true);                                                     (10)
myDataSource.setAutomaticEnlistingEnabled(true);                                                  (11)
myDataSource.setAcquisitionTimeout(30);                                                           (12)
myDataSource.setAcquisitionInterval(1);                                                           (13)
myDataSource.setPreparedStatementCacheSize(5);                                                    (14)
myDataSource.setTwoPcOrderingPosition(0);                                                         (15)
myDataSource.setApplyTransactionTimeout(true);                                                    (16)
myDataSource.setIgnoreRecoveryFailures(false);                                                    (17)
myDataSource.setIsolationLevel("READ_COMMITTED");                                                 (18)
myDataSource.getDriverProperties().setProperty("user", "users1");                                 (1819)
myDataSource.getDriverProperties().setProperty("password", "users1");                             (1920)
myDataSource.getDriverProperties().setProperty("URL", "jdbc:oracle:thin:@localhost:1521:XE");     (2021)


Connection c = myDataSource.getConnection();                                                      (2122)
 // do some SQL
c.close();                                                                                        (2223)

myDataSource.close();                                                                             (2324)

1. The Bitronix PoolingDataSource is a javabean that implements java.sql.DataSource.
2. You have to specify the driver's XADataSource implementation here.
3. Each datasource must be assigned a unique name. This is required for distributed crash recovery.
4. This datasource can contain at least 0 connection. 0 is the default value when unspecified.
5. This datasource can contain at most 5 connections.
6. If there aren't enough connections in the pool to fulfill a request, new connections will be created, by increments of 1 at a time.
7. You have to set allowLocalTransactions to true if you want to be able to run SQL statements outside of XA transactions scope. Defaults to false.
8. When specified, this query will be executed to check that the connection is still valid before handing it to the application code.
9. Set useTmJoin to false if the vendor's XADataSource implementation does not implement XAResource.isSameRM() properly. Refer to the JdbcXaSupportEvaluation page to see if your database needs it. Defaults to true.
10. Set deferConnectionRelease to false if the vendor's XADataSource implementation supports transactions interleaving. Refer to the JdbcXaSupportEvaluation page to see if your database supports it. Defaults to true.
11. Set automaticEnlistingEnabled to false if you do not want the PoolingDataSource to automatically enlist/delist the connections into the XA transactions. You then have to enlist XAResource objects manually into the Transaction objects for them to participate in XA transactions. Defaults to true.
12. The amount of seconds the pool will block when a connection is requested but the pool is empty and cannot grow anymore. Defaults to 30.
13. The amount of seconds the pool will wait when a connection has been tested invalid before trying to acquire a new one. Defaults to 1.
14. The amount of prepared statements cached per pooled connection. Defaults to 0, meaning statement caching is disabled.
15. The position of this resource during the 2PC protocol execution. This is required if you want to guarantee that a resource commits before another one. Defaults to 0.
16. Should the transaction timeout be passed to the resource via XAResource.setTransactionTimeout() ? Defaults to false.
17. Should recovery errors be ignored? Ignoring  Ignoring recovery errors jeopardizes the failed transactions atomicity so only set this parameter to true when you know what you're doing. This  This is mostly useful in a development environment.
18. 
Set the default isolation level. All of the four standard READ_COMMITTED, READ_UNCOMMITTED, REPEATABLE_READ and SERIALIZABLE names are supported.
19,20,21.
The driverProperties is a java.util.Properties object. You have to add into it a set of property name / property value of the OracleXADataSource class. You have to refer to the driver's documentation to know what can / has to be set. The OracleXADataSource javadoc contains this list for the Oracle case. BTM will perform conversion from String to boolean or to int when necessary.
2122,2223. You can now use the PoolingDataSource like any other java.sql.DataSource.
2324. Remember to close the PoolingDataSource after you're done with it to release the connections.

...