Message-ID: <1359523014.783052.1386424597563.JavaMail.email@example.com> Subject: Exported From Confluence MIME-Version: 1.0 Content-Type: multipart/related; boundary="----=_Part_783051_1965615545.1386424597562" ------=_Part_783051_1965615545.1386424597562 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.
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.
Here is an example of datasource creation that connects to an Oracle dat= abase:
1. The Bitronix
PoolingDataSource is a jav=
abean that implements
2. You have to specify the driver's
3. Each datasource must be assigned a un= ique name. This is required for distributed crash recovery.
4= . This datasource can contain at least 0 connection. 0 is the defa= ult value when unspecified.
5. This datasource can c= ontain at most 5 connections.
6. If there aren't eno= ugh connections in the pool to fulfill a request, new connections will be c= reated, 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 co= de.
useTmJoin to false if the ve=
XADataSource implementation does not implement
Resource.isSameRM() properly. Refer to the JdbcXaSupportEvaluation page to see if your dat=
abase needs it. Defaults to true.
rConnectionRelease 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 XAResourc= e.setTransactionTimeout() ? Defaults to false.
18. = Set the default isolation level. All of the four standard= READ_COMMITTED, READ_UNCOMMITTED, REPEATABLE_READ and SERIALIZABLE na= mes are supported.
19,20,21. The dri= verProperties is a
java.util.Properties object. You have to ad=
d into it a set of property name / property value of the
Source class. You have to refer to the driver's documentation to kno=
w what can / has to be set. The OracleXADataSource java=
doc contains this list for the Oracle case. BTM will perform conversion=
boolean or to
22,23. You can now use the
ngDataSource like any other
= 24. Remember to close the
fter 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.
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/ResourceLoader2x">Resource Loader page for more = details.
Here is the equivalent Resource Loader configuration of the previous cod= e example:=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:
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.