Message-ID: <27548935.99903.1398086600066.JavaMail.firstname.lastname@example.org> Subject: Exported From Confluence MIME-Version: 1.0 Content-Type: multipart/related; boundary="----=_Part_99902_1594610785.1398086600066" ------=_Part_99902_1594610785.1398086600066 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.PoolingData= Source 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,16,17. The driverProperties is a
roperties object. You have to add into it a set of property name / p=
roperty value of the
OracleXADataSource class. You have to ref=
er to the driver's documentation to know what can / has to be set. The OracleXADataSource javadoc contains this list for the O=
racle case. BTM will perform conversion from
oolean or to
int when necessary.
18,19.= strong> You can now use the
PoolingDataSource like any other <=
20. Remember to clo= se the
PoolingDataSource after you're done with it to release =
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 =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/ResourceLoader12">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 Configuration12=
Now you also have to know how to get the datasource created by the Resou= rce Loader. There are multiple ways:=20
bitronix.tm.resource.bind=3Dtrueto your resource load= er properties file. The datasources will then be bound to the default JNDI = server using their
uniqueNameas their JNDI name.
addrType somewhere in your JNDI tree. The
bitronix.tm.resource.ResourceOb= jectFactoryclass will just return the datasource with the specified=
uniqueName. This is explained more in-depth in the Tomcat12 integration page.