Project

General

Profile

Sample-jta-plain » History » Version 11

Henning Blohm, 18.09.2012 18:50

1 3 Henning Blohm
h1. Using Z2 with a Transaction Manager
2 1 Henning Blohm
3 2 Henning Blohm
This sample demonstrates how to use Z2 with the Atomikos transaction manager. There is another sample that shows how to use Z2 with a Spring configured transaction manager. See [[sample-jta-spring]]. In contrast to that, this sample is less sophisticated but probably better suited to understand the underlying mechanics.
4 1 Henning Blohm
5
The Wiki page [[How_to_TransactionManager]] explains the general principles behind transaction handling in Z2.
6
7 11 Henning Blohm
This sample is stored in "z2-samples.jta-plain":http://redmine.z2-environment.net/projects/z2-samples/repository/z2-samples-jta-plain. It implements exactly the same scenario as [[Sample-hibernate-basic]] with the exception of not using the built-in JTA implementation.
8 2 Henning Blohm
9
h2. Pre-Requisites
10
11
This sample assumes the presence of a MySQL database system on localhost with a database called "z_tx_tests" for which a user "tx" with password "tx" has full permissions. If you have a running MySQL server these SQL commands do the trick:
12
13
<pre><code class="SQL">
14
create database z_tx_tests;
15
grant all on z_tx_tests.* to tx@localhost identified by 'tx';
16
</code></pre>
17
18
h2. Running the sample
19
20
This sample is run as explained in [[How to run a sample]]. The 5 minutes version:
21
22
<pre><code class="ruby">
23
mkdir install
24
cd install 
25
git clone -b master http://git.z2-environment.net/z2-base.core
26
git clone -b master http://git.z2-environment.net/z2-samples.jta-plain
27
28
# on Linux / Mac OS:
29
cd z2-base.core/run/bin
30
./gui.sh
31
32
# on Windows:
33
cd z2-base.core\run\bin
34
gui.bat
35 1 Henning Blohm
</code></pre>
36 3 Henning Blohm
37
h2. Verifying
38
39
When everything is up, go to http://localhost:8080/tx.plain. You see something like this: 
40
41
!plain_thingies.png!
42
43 5 Henning Blohm
And indeed, the implemented function is rather obvious: Manage a table of strings - called Thingies in the sample.
44 3 Henning Blohm
45
h2. Now to the point...
46 4 Henning Blohm
47 1 Henning Blohm
The idea behind this sample is to provide a template for transaction manager integration. Note that before you integrate with a complete transaction management system, you should be sure that you need it. Distributed transactions come at a price in terms of complexity and overhead of local transaction logs. If you do not have multiple data sources, or if those have no strong inherent consistency requirement you may well be better off without a full-blown, XA capable transaction manager. Please also see [[How to transaction management]].
48 5 Henning Blohm
49 6 Henning Blohm
h2. Detailed explanation
50 5 Henning Blohm
51
The sample has four modules:
52
53 7 Henning Blohm
* *com.atomikos*: This module holds the "Atomikos Transaction Essentials":http://www.atomikos.com/Main/TransactionsEssentials libraries - the actual transaction manager implementation* 
54
* *com.zfabrik.samples.jta-plain*: This module implements supporting functions for the actual applications.
55
* *com.zfabrik.samples.jta-plain.domain*: The domain definition module. This contains the JPA entities and a "Thingy Repository" implementation.
56 1 Henning Blohm
* *com.zfabrik.samples.jta-plain.web*: The simple web application that lists the database content and allows to add and delete thingies.
57 7 Henning Blohm
58 6 Henning Blohm
59 11 Henning Blohm
Let's start by looking at the supporting functions. 
60 9 Henning Blohm
61 11 Henning Blohm
TBC