Message-ID: <322230582.41244.1371647588379.JavaMail.firstname.lastname@example.org> Subject: Exported From Confluence MIME-Version: 1.0 Content-Type: multipart/related; boundary="----=_Part_41243_1071797559.1371647587890" ------=_Part_41243_1071797559.1371647587890 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-specific tool called the Resource Loader. You are free to choose = the method you prefer, there is absolutely no difference between them.<= h4 id=3D"JdbcConfiguration2x-Contents">Contents
BTM comes bundled with a JDBC XA connection pool which is very e= asy to configure. You basically have to create an instance of bitronix.tm.resource.jdbc.P= oolingDataSource set some properties and you're done.
Here is an = example of datasource creation that connects to an Oracle database:
1. The Bitronix
PoolingDataSource is a javabean that implements
<= strong>2. You have to specify the driver's
XADataSource implementation here. like any other
3. Each datasource must be a= ssigned 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 data= source can contain at most 5 connections.
6. If ther= e aren't enough connections in the pool to fulfill a request, new connectio= ns 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 t=
8. When specified, this query will be execu= ted to check that the connection is still valid before handing it to the ap= plication code.
useTmJoin to fal=
se if the vendor's
XADataSource implementation does not implem=
XAResource.isSameRM() properly. Refer to the JdbcXaSupportEvaluation page to see=
if your database needs it. Defaults to true.
10. Se= t
deferConnectionRelease to false if the vendor's
Source implementation supports transactions interleaving. Refer to t=
page to see if your database supports it. Defaults to true.
automaticEnlistingEnabled to false if you=
do not want the
PoolingDataSource to automatically enlist/del=
ist the connections into the XA transactions. You then have to enlist
XAResource objects manually into the
ts for them to participate in XA transactions. Defaults to true.
13. The amount of seconds the pool will wait when= a connection has been tested invalid before trying to acquire a new one. D= efaults to 1.
14. The amount of prepared statements = cached per pooled connection. Defaults to 0, meaning statement caching is d= isabled.
15. The position of this resource during th= e 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.
<= strong>17.=C2=A0Should recovery errors b= e ignored?=C2=A0Ignoring recovery errors jeopardizes the fa= iled transactions atomicity so only set this parameter to true when you kno= w what you're doing.=C2=A0This is mostly useful in a deve= lopment environment.
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
acleXADataSource class. You have to refer to the driver's documentat=
ion to know what can / has to be set. The OracleXADataS=
ource javadoc contains this list for the Oracle case. BTM will perform =
boolean or to
22,23. You can now use the <= code>PoolingDataSource
24. Remember to close the
e after you're done with it to release the connections.
|No XADataSource implementation ?|
If your database =
vendor does not provide a
You do not have to =
set properties that have a default value. Here is a simplified version of t=
he previous code creating a
PoolingDataSource with minimal set=
This will create a
PoolingDataSource that will =
work exactly the same as the previous one. The only difference is that unsp=
ecified properties have been left untouched with their default value.
ge= tConnection(). It might be desirable to initialize the pool eagerly,= like during application startup rather than having to wait for the first r= equests. 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 convenient to use it rather than create your datasources in code. Refer= to the Resource Loader page = for more details.
Here is the equivalent Resource Loader configuratio= n of the previous code example:
resource= .ds.className=3Doracle.jdbc.xa.client.OracleXADataSource resource.ds.uniqueName=3Doracle resource.ds.maxPoolSize=3D5 resource.ds.allowLocalTransactions=3Dtrue resource.ds.testQuery=3DSELECT 1 FROM DUAL resource.ds.driverProperties.user=3Dusers1 resource.ds.driverProperties.password=3Dusers1 resource.ds.driverProperties.URL=3Djdbc:oracle:thin:@localhost:1521:XE=09=09
|Datasource initialization / shutdown<=
The Resource Loader will always eager initialize the created dataso= urces and close them when the transaction manager shuts down.
You just have to write those properties in a simple text f=
ile and tell BTM where to load it by setting the
nFilename property of the C=
Now you also have to know how to get the dat= asource created by the Resource Loader. There are multiple ways:
addrTypesomewhere in your JNDI= tree. The
bitronix.tm.resource.ResourceObjectFactoryclass wi= ll just return the datasource with the specified
uniqueName. T= his is explained more in-depth in the Tom= cat and Jetty integration page.