Message-ID: <878654753.1799.1429465903562.JavaMail.firstname.lastname@example.org> Subject: Exported From Confluence MIME-Version: 1.0 Content-Type: multipart/related; boundary="----=_Part_1798_1720390223.1429465903562" ------=_Part_1798_1720390223.1429465903562 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Content-Location: file:///C:/exported.html
BTM XA datasources can be created via some java code or via a BTM-specif= ic tool called the Resource Loader. You are free to choose the method you p= refer, there is absolutely no difference between them.=20
BTM comes bundled with a JDBC XA connection pool which is very easy to c= onfigure. You basically have to create an instance of bitronix.tm.resource.jdbc.PoolingDa= taSource set some properties and you're done.=20
Here is an example of datasource creation that connects to an Oracle dat= abase:=20 =20
1. The Bitronix
PoolingDataSource is a ja=
vabean that implements
2.= strong> You have to specify the driver's
3. Each datasource must be assigned a u= nique name. This is required for distributed crash recovery.
= 4. This datasource can contain at least 0 connection. 0 is the def= ault value when unspecified.
5. This datasource can = contain at most 5 connections.
6. If there aren't en= ough connections in the pool to fulfill a request, new connections will be = created, by increments of 1 at a time.
7. You have t= o 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 chec= k that the connection is still valid before handing it to the application c= ode.
useTmJoin to false if the v=
XADataSource implementation does not implement
AResource.isSameRM() properly. Refer to the JdbcXaSupportEvaluation page to see if your da=
tabase needs it. Defaults to true.
erConnectionRelease 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.
automaticEnlistingEnabled to false if you do not wa=
PoolingDataSource to automatically enlist/delist the co=
nnections into the XA transactions. You then have to enlist
e objects manually into the
Transaction objects for the=
m to participate in XA transactions. Defaults to true.
12. The amount of seconds the pool will block when a connection is reque= sted but the pool is empty and cannot grow anymore. Defaults to 30.
<= strong>13. The amount of seconds the pool will wait when a connect= ion 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 prot= ocol execution. This is required if you want to guarantee that a resource c= ommits before another one. Defaults to 0.
16. Should= the transaction timeout be passed to the resource via XAResource.se= tTransactionTimeout() ? Defaults to false.
17,18,19. The driverProperties is a
java.util.Properties object. Yo=
u have to add into it a set of property name / property value of the
OracleXADataSource class. You have to refer to the driver's document=
ation to know what can / has to be set. The OracleXADat=
aSource javadoc contains this list for the Oracle case. BTM will perfor=
m conversion from
boolean or to
nt when necessary.
20,21. You can now use the=
PoolingDataSource like any other
22. Remember to close the
rce after you're done with it to release the connections.
You do not have to set properties that have a default value. Here is a s=
implified version of the previous code creating a
code> with minimal settings:
This will create a
PoolingDataSource that will work exactly=
the same as the previous one. The only difference is that unspecified prop=
erties have been left untouched with their default value.
The connection pool will be initialized during the first call to
etConnection(). It might be desirable to initialize the pool eagerly=
, like during application startup rather than having to wait for the first =
requests. This can be done by calling
Now line 10 will initialize the pool instead of line 11.=20
A datasource configuration utility is also bundled with BTM. It is conve= nient to use it rather than create your datasources in code. Refer to the <= a href=3D"/display/BTM/ResourceLoader13">Resource Loader page for more = details.=20
Here is the equivalent Resource Loader configuration of the previous cod= e example:=20 =20 =20
You just have to write those properties in a simple text file and tell B=
TM where to load it by setting the
resourceConfigurationFilename property of the Configuration=
Now you also have to know how to get the datasource created by the Resou= rce Loader. There are multiple ways:=20
addrTypesomewhere in your JNDI tree. The
bitronix.t= m.resource.ResourceObjectFactoryclass will just return the datasour= ce with the specified
uniqueName. This is explained more in-de= pth in the Tomcat and Jetty integration page.