![Page 2: Transactions and J2EE - ABIS · JDBC – Java Data Base Connectivity • J2EE defines access to 1 JDBC resource per trx JCA – Java Connector Architecture • integration with EIS](https://reader033.vdocuments.us/reader033/viewer/2022043022/5f3e17093d6e2263be5cc0ca/html5/thumbnails/2.jpg)
2
• What is a transaction?
• Different transaction types?
• How can J2EE manage transactions?
Answer to Your Questions
![Page 3: Transactions and J2EE - ABIS · JDBC – Java Data Base Connectivity • J2EE defines access to 1 JDBC resource per trx JCA – Java Connector Architecture • integration with EIS](https://reader033.vdocuments.us/reader033/viewer/2022043022/5f3e17093d6e2263be5cc0ca/html5/thumbnails/3.jpg)
3
● High-level technological ICT services• Training• Consulting
• Host basedtechnology
• Databaseconsolidation
• Reuse &integration
www.abis.be
OS/390z/OS
TSOCICS
IMS/DC
COBOLVisualAge Generator
SQLServerDB2IMS/DB DB2 UDB Oracle
UNIXAIX
NTW2000
MQSeries
XML
Customer Base
Tech
nolo
gy
OO AD
JavaVisualAge Java
WebSphere
Traditional AD
Abis Training and Consulting
![Page 4: Transactions and J2EE - ABIS · JDBC – Java Data Base Connectivity • J2EE defines access to 1 JDBC resource per trx JCA – Java Connector Architecture • integration with EIS](https://reader033.vdocuments.us/reader033/viewer/2022043022/5f3e17093d6e2263be5cc0ca/html5/thumbnails/4.jpg)
4
● Transaction: definitions and glossary● Transaction participants● Transaction types● J2EE transactions● Q & A
Agenda
![Page 5: Transactions and J2EE - ABIS · JDBC – Java Data Base Connectivity • J2EE defines access to 1 JDBC resource per trx JCA – Java Connector Architecture • integration with EIS](https://reader033.vdocuments.us/reader033/viewer/2022043022/5f3e17093d6e2263be5cc0ca/html5/thumbnails/5.jpg)
5
“Set of related operations that must be completed together”
“Atomic Logical Unit of Work, that must be
treated in a coherent and reliable way.”
Transaction: Definitions
![Page 6: Transactions and J2EE - ABIS · JDBC – Java Data Base Connectivity • J2EE defines access to 1 JDBC resource per trx JCA – Java Connector Architecture • integration with EIS](https://reader033.vdocuments.us/reader033/viewer/2022043022/5f3e17093d6e2263be5cc0ca/html5/thumbnails/6.jpg)
6
● A tomicity● C onsistency● I solation● D urability
Transaction demarcation/boundaries
Transaction properties
● Commit● Rollback
Transaction: Glossary
![Page 7: Transactions and J2EE - ABIS · JDBC – Java Data Base Connectivity • J2EE defines access to 1 JDBC resource per trx JCA – Java Connector Architecture • integration with EIS](https://reader033.vdocuments.us/reader033/viewer/2022043022/5f3e17093d6e2263be5cc0ca/html5/thumbnails/7.jpg)
7
● Transaction: definition and glossary● Transaction participants● Transaction types● J2EE transactions● Q & A
Agenda
![Page 8: Transactions and J2EE - ABIS · JDBC – Java Data Base Connectivity • J2EE defines access to 1 JDBC resource per trx JCA – Java Connector Architecture • integration with EIS](https://reader033.vdocuments.us/reader033/viewer/2022043022/5f3e17093d6e2263be5cc0ca/html5/thumbnails/8.jpg)
8
● Application● Resource manager
• Relational database• TP monitor• JMS provider
● Transaction resource object (E.g. Connection)● Resource adapter – connector● Transaction manager
• Coordination of distributed transactions• Maintains transaction context• XA protocol
Transaction Participants
![Page 9: Transactions and J2EE - ABIS · JDBC – Java Data Base Connectivity • J2EE defines access to 1 JDBC resource per trx JCA – Java Connector Architecture • integration with EIS](https://reader033.vdocuments.us/reader033/viewer/2022043022/5f3e17093d6e2263be5cc0ca/html5/thumbnails/9.jpg)
9
Client
J2EE ApplicationServer
J2EEapplicationcomponent
DB
Transaction manager
Resourcemanager
JDBC
EISResourcemanagerJCA/JMS
Resourceadapters
Transaction Participants
![Page 10: Transactions and J2EE - ABIS · JDBC – Java Data Base Connectivity • J2EE defines access to 1 JDBC resource per trx JCA – Java Connector Architecture • integration with EIS](https://reader033.vdocuments.us/reader033/viewer/2022043022/5f3e17093d6e2263be5cc0ca/html5/thumbnails/10.jpg)
10
● Transaction: definition and glossary● Transaction participants● Transaction types● J2EE transactions● Q & A
Agenda
![Page 11: Transactions and J2EE - ABIS · JDBC – Java Data Base Connectivity • J2EE defines access to 1 JDBC resource per trx JCA – Java Connector Architecture • integration with EIS](https://reader033.vdocuments.us/reader033/viewer/2022043022/5f3e17093d6e2263be5cc0ca/html5/thumbnails/11.jpg)
11
● Local transaction• 1 resource manager• 1 phase commit
● Distributed (global) transaction• Access multiple transactional resources• 2 phase commit
● Flat transaction● Nested transaction● Compensating transaction
● Extended transaction
Transaction Types
![Page 12: Transactions and J2EE - ABIS · JDBC – Java Data Base Connectivity • J2EE defines access to 1 JDBC resource per trx JCA – Java Connector Architecture • integration with EIS](https://reader033.vdocuments.us/reader033/viewer/2022043022/5f3e17093d6e2263be5cc0ca/html5/thumbnails/12.jpg)
12
1 resource manager
DBMS
Application
Local Transaction
![Page 13: Transactions and J2EE - ABIS · JDBC – Java Data Base Connectivity • J2EE defines access to 1 JDBC resource per trx JCA – Java Connector Architecture • integration with EIS](https://reader033.vdocuments.us/reader033/viewer/2022043022/5f3e17093d6e2263be5cc0ca/html5/thumbnails/13.jpg)
13
TeleProcessing monitor+ multiple resourcemanagers
DBMS-1
DBMS-2
Enterprise system
TransactionManager
1 2 3 4 5Program
Traditional Transaction Manager
![Page 14: Transactions and J2EE - ABIS · JDBC – Java Data Base Connectivity • J2EE defines access to 1 JDBC resource per trx JCA – Java Connector Architecture • integration with EIS](https://reader033.vdocuments.us/reader033/viewer/2022043022/5f3e17093d6e2263be5cc0ca/html5/thumbnails/14.jpg)
14
DBMS-1
DBMS-2
Enterprise systemWeb Server system
ApplicationServer
12 3 4 5Program
J2EEapplicationserver
Application Server As Trx Manager
![Page 15: Transactions and J2EE - ABIS · JDBC – Java Data Base Connectivity • J2EE defines access to 1 JDBC resource per trx JCA – Java Connector Architecture • integration with EIS](https://reader033.vdocuments.us/reader033/viewer/2022043022/5f3e17093d6e2263be5cc0ca/html5/thumbnails/15.jpg)
15
Multiple resource managers
Client
J2EE Application Server
EJB A
EJB B
EJB C
JDBC
JCA
JMS
DB
EIS
Distributed Transaction
![Page 16: Transactions and J2EE - ABIS · JDBC – Java Data Base Connectivity • J2EE defines access to 1 JDBC resource per trx JCA – Java Connector Architecture • integration with EIS](https://reader033.vdocuments.us/reader033/viewer/2022043022/5f3e17093d6e2263be5cc0ca/html5/thumbnails/16.jpg)
16
Multiple transaction managers
J2EE ApplicationServer
Client
J2EE ApplicationServer
EJB A
EJB B
JDBC
JCA
DB
EIS2PC
Distributed Transaction
![Page 17: Transactions and J2EE - ABIS · JDBC – Java Data Base Connectivity • J2EE defines access to 1 JDBC resource per trx JCA – Java Connector Architecture • integration with EIS](https://reader033.vdocuments.us/reader033/viewer/2022043022/5f3e17093d6e2263be5cc0ca/html5/thumbnails/17.jpg)
17
2 PhaseCommit
Transactionmanager
Resourcemanager 1
Resourcemanager 2
Prepare to commit
Ready to commit
Prepare to commit
Ready to commit
Commit
Committed
Commit
Committed
Distributed Transaction
![Page 18: Transactions and J2EE - ABIS · JDBC – Java Data Base Connectivity • J2EE defines access to 1 JDBC resource per trx JCA – Java Connector Architecture • integration with EIS](https://reader033.vdocuments.us/reader033/viewer/2022043022/5f3e17093d6e2263be5cc0ca/html5/thumbnails/18.jpg)
18
2 Phaseabort
Transactionmanager
Resourcemanager 1
Resourcemanager 2
Prepare to commit
Ready to commit
Prepare to commit
Don't commit
Abort
Aborted
Abort
Aborted
Distributed Transaction
![Page 19: Transactions and J2EE - ABIS · JDBC – Java Data Base Connectivity • J2EE defines access to 1 JDBC resource per trx JCA – Java Connector Architecture • integration with EIS](https://reader033.vdocuments.us/reader033/viewer/2022043022/5f3e17093d6e2263be5cc0ca/html5/thumbnails/19.jpg)
19
Begin trxco
mm
it ex
ecut
ed
com
mit
or r
ollb
ack
exec
uted
End trx
Transaction contextpropagation
App1 App2 Appn...
Flat Transaction
![Page 20: Transactions and J2EE - ABIS · JDBC – Java Data Base Connectivity • J2EE defines access to 1 JDBC resource per trx JCA – Java Connector Architecture • integration with EIS](https://reader033.vdocuments.us/reader033/viewer/2022043022/5f3e17093d6e2263be5cc0ca/html5/thumbnails/20.jpg)
20
Begin T1
Begin T3
Begin T2
Commit or Rollback T3
Commit or Rollback T2
Commit or Rollback T1
negl
ecte
d
negl
ecte
d
com
mit
exec
uted
rollb
ack
exec
uted
rollb
ack
exec
uted
rollb
ack
exec
uted
Nested Transaction
![Page 21: Transactions and J2EE - ABIS · JDBC – Java Data Base Connectivity • J2EE defines access to 1 JDBC resource per trx JCA – Java Connector Architecture • integration with EIS](https://reader033.vdocuments.us/reader033/viewer/2022043022/5f3e17093d6e2263be5cc0ca/html5/thumbnails/21.jpg)
21
● Undo effect of previously committed transaction• for local transactions (resource adaptors)• programmatic application logic
ExampleupdateEIS();try {
usertrx.begin();updateRDBMS();usertrx.commit();
}catch (RollbackException ex) {
undoUpdateEIS();}
Compensating Transaction
![Page 22: Transactions and J2EE - ABIS · JDBC – Java Data Base Connectivity • J2EE defines access to 1 JDBC resource per trx JCA – Java Connector Architecture • integration with EIS](https://reader033.vdocuments.us/reader033/viewer/2022043022/5f3e17093d6e2263be5cc0ca/html5/thumbnails/22.jpg)
22
● Long lived● Message oriented● Web services
• Business Transaction Protocol (OASIS) – JSR-156• WS-Transaction, WS-Coordination • Activity Service (OMG) – JSR-95
Extended Transaction
![Page 23: Transactions and J2EE - ABIS · JDBC – Java Data Base Connectivity • J2EE defines access to 1 JDBC resource per trx JCA – Java Connector Architecture • integration with EIS](https://reader033.vdocuments.us/reader033/viewer/2022043022/5f3e17093d6e2263be5cc0ca/html5/thumbnails/23.jpg)
23
● Transaction: definition and glossary● Transaction participants● Transaction types● J2EE transactions● Q & A
Agenda
![Page 24: Transactions and J2EE - ABIS · JDBC – Java Data Base Connectivity • J2EE defines access to 1 JDBC resource per trx JCA – Java Connector Architecture • integration with EIS](https://reader033.vdocuments.us/reader033/viewer/2022043022/5f3e17093d6e2263be5cc0ca/html5/thumbnails/24.jpg)
24
● J2EE Technology• JTA – Java Transaction API• JTS – Java Transaction Service
● J2EE tiers• Client tier• Web tier• EJB tier• EIS tier• Web services
● J2EE Resource managers• JDBC• JCA• JMS
J2EE Transactions
![Page 25: Transactions and J2EE - ABIS · JDBC – Java Data Base Connectivity • J2EE defines access to 1 JDBC resource per trx JCA – Java Connector Architecture • integration with EIS](https://reader033.vdocuments.us/reader033/viewer/2022043022/5f3e17093d6e2263be5cc0ca/html5/thumbnails/25.jpg)
25
JTA
JTS
J2EE Technology
![Page 26: Transactions and J2EE - ABIS · JDBC – Java Data Base Connectivity • J2EE defines access to 1 JDBC resource per trx JCA – Java Connector Architecture • integration with EIS](https://reader033.vdocuments.us/reader033/viewer/2022043022/5f3e17093d6e2263be5cc0ca/html5/thumbnails/26.jpg)
26
JTA● javax.transaction.UserTransaction
• explicit in code• implicit in EJB container
JTS● javax.transaction.TransactionManager● javax.transaction.xa.XAResource
handled by J2EE server and EIS resource managers
JTA and JTS
![Page 27: Transactions and J2EE - ABIS · JDBC – Java Data Base Connectivity • J2EE defines access to 1 JDBC resource per trx JCA – Java Connector Architecture • integration with EIS](https://reader033.vdocuments.us/reader033/viewer/2022043022/5f3e17093d6e2263be5cc0ca/html5/thumbnails/27.jpg)
27
● Client tier● Web tier● EJB tier● EIS tier● Web services
J2EE Tiers
![Page 28: Transactions and J2EE - ABIS · JDBC – Java Data Base Connectivity • J2EE defines access to 1 JDBC resource per trx JCA – Java Connector Architecture • integration with EIS](https://reader033.vdocuments.us/reader033/viewer/2022043022/5f3e17093d6e2263be5cc0ca/html5/thumbnails/28.jpg)
28
No J2EE requirements forapplets or application clients
Advise: delegate transactional responsibility to server tiers
J2EE Client Tier
![Page 29: Transactions and J2EE - ABIS · JDBC – Java Data Base Connectivity • J2EE defines access to 1 JDBC resource per trx JCA – Java Connector Architecture • integration with EIS](https://reader033.vdocuments.us/reader033/viewer/2022043022/5f3e17093d6e2263be5cc0ca/html5/thumbnails/29.jpg)
29
J2EE supports programmatic transaction demarcation in servlets/JSPs
● implement in service() method (begin + commit) ● 2 phase commit implied
Advise: Use JNDI to lookup for object java:comp/UserTransaction
J2EE Web Tier
![Page 30: Transactions and J2EE - ABIS · JDBC – Java Data Base Connectivity • J2EE defines access to 1 JDBC resource per trx JCA – Java Connector Architecture • integration with EIS](https://reader033.vdocuments.us/reader033/viewer/2022043022/5f3e17093d6e2263be5cc0ca/html5/thumbnails/30.jpg)
30
public void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {Context ctx = new InitialContext();UserTransaction userTrx = (UserTransaction) ctx.lookup(“java:comp/UserTransaction”);
userTrx.begin();// user code for accessing resourcesuserTrx.commit();
}
Start new transaction context J2EE Web Tier
![Page 31: Transactions and J2EE - ABIS · JDBC – Java Data Base Connectivity • J2EE defines access to 1 JDBC resource per trx JCA – Java Connector Architecture • integration with EIS](https://reader033.vdocuments.us/reader033/viewer/2022043022/5f3e17093d6e2263be5cc0ca/html5/thumbnails/31.jpg)
31
J2EE supports transaction demarcation● programmatic (bean managed)
• Session beans -afterBegin(), beforeCompletion(), afterCompletion()
• Message driven beans -onMessage()
UserTransaction● declarative (container managed)
• Session beans • Entity beanstransaction attributes in deployment descriptor
J2EE EJB Tier
![Page 32: Transactions and J2EE - ABIS · JDBC – Java Data Base Connectivity • J2EE defines access to 1 JDBC resource per trx JCA – Java Connector Architecture • integration with EIS](https://reader033.vdocuments.us/reader033/viewer/2022043022/5f3e17093d6e2263be5cc0ca/html5/thumbnails/32.jpg)
32
public void myMethod(…)throws RemoteException { UserTransaction userTrx = ejbContext.getUserTransaction(); try {
userTrx.begin();// user code for accessing resourcesuserTrx.commit();
} catch (Exception e) { try { userTrx.rollback(); } catch (SystemException se) { … } }}
Bean managed transaction J2EE EJB Tier
![Page 33: Transactions and J2EE - ABIS · JDBC – Java Data Base Connectivity • J2EE defines access to 1 JDBC resource per trx JCA – Java Connector Architecture • integration with EIS](https://reader033.vdocuments.us/reader033/viewer/2022043022/5f3e17093d6e2263be5cc0ca/html5/thumbnails/33.jpg)
33
Container managed transaction attributes Required
NotSupported
Supports
Mandatory
RequiresNew
Never
Client EJB
Client EJBClient EJB
Client EJB Client EJB
Client EJB Client EJB
Client EJB
Client EJB
Exception
Exception
Client EJB
Client EJB
Client EJB
J2EE EJB Tier
![Page 34: Transactions and J2EE - ABIS · JDBC – Java Data Base Connectivity • J2EE defines access to 1 JDBC resource per trx JCA – Java Connector Architecture • integration with EIS](https://reader033.vdocuments.us/reader033/viewer/2022043022/5f3e17093d6e2263be5cc0ca/html5/thumbnails/34.jpg)
34
...<container-transaction> <method> <ejb-name>PersonBean</ejb-name> <method-name>*</method-name> </method> <trans-attribute>Required</trans-attribute></container-transaction><container-transaction> <method> <ejb-name>CompanyBean</ejb-name> <method-name>updateInfo</method-name> </method> <trans-attribute>Mandatory</trans-attribute></container-transaction>...
Container managed transaction descriptor J2EE EJB Tier
![Page 35: Transactions and J2EE - ABIS · JDBC – Java Data Base Connectivity • J2EE defines access to 1 JDBC resource per trx JCA – Java Connector Architecture • integration with EIS](https://reader033.vdocuments.us/reader033/viewer/2022043022/5f3e17093d6e2263be5cc0ca/html5/thumbnails/35.jpg)
35
idemXXXMDB
get/set of CMP/CMR
fields
loggingEntity CMP
XXXEntity BMP
NOT re-
com-men-ded-
EIS trx(no J2EE support)
XXXSession
NeverMandatorySupportsNot Support’d
Requires New
Required
Depends on client
Best practices XXXJ2EE EJB Tier
![Page 36: Transactions and J2EE - ABIS · JDBC – Java Data Base Connectivity • J2EE defines access to 1 JDBC resource per trx JCA – Java Connector Architecture • integration with EIS](https://reader033.vdocuments.us/reader033/viewer/2022043022/5f3e17093d6e2263be5cc0ca/html5/thumbnails/36.jpg)
36
Notes:● Use Container Managed Transactions preferably
● trigger rollback by container via method
setRollbackOnly() on • SessionContext• EntityContext• MessageDrivenContext
J2EE EJB Tier
![Page 37: Transactions and J2EE - ABIS · JDBC – Java Data Base Connectivity • J2EE defines access to 1 JDBC resource per trx JCA – Java Connector Architecture • integration with EIS](https://reader033.vdocuments.us/reader033/viewer/2022043022/5f3e17093d6e2263be5cc0ca/html5/thumbnails/37.jpg)
37
Access via● JTA transaction
• transaction context propagated via J2EE server
● resource manager local transaction• only if no JCA connector is available• requires explicit commit/rollback• provide compensating transactions
J2EE EIS Tier
![Page 38: Transactions and J2EE - ABIS · JDBC – Java Data Base Connectivity • J2EE defines access to 1 JDBC resource per trx JCA – Java Connector Architecture • integration with EIS](https://reader033.vdocuments.us/reader033/viewer/2022043022/5f3e17093d6e2263be5cc0ca/html5/thumbnails/38.jpg)
38
J2EE EIS Tier
Advise:● access EIS system in transaction scope● use appropriate isolation level for EIS
• ReadUncommitted• ReadCommitted• RepeatableRead• Serializable
![Page 39: Transactions and J2EE - ABIS · JDBC – Java Data Base Connectivity • J2EE defines access to 1 JDBC resource per trx JCA – Java Connector Architecture • integration with EIS](https://reader033.vdocuments.us/reader033/viewer/2022043022/5f3e17093d6e2263be5cc0ca/html5/thumbnails/39.jpg)
39
● JDBC – Java Data Base Connectivity• J2EE defines access to 1 JDBC resource per trx
● JCA – Java Connector Architecture• integration with EIS via standard resource adapters
- NoTransaction- LocalTransaction- XATransaction
● JMS – Java Messaging Service• J2EE supports at least 1 JMS provider per trx• messages are delivered/consumed in UoW• transactions are NEVER propagated between
sender and receiver of message!
J2EE Resource Managers
![Page 40: Transactions and J2EE - ABIS · JDBC – Java Data Base Connectivity • J2EE defines access to 1 JDBC resource per trx JCA – Java Connector Architecture • integration with EIS](https://reader033.vdocuments.us/reader033/viewer/2022043022/5f3e17093d6e2263be5cc0ca/html5/thumbnails/40.jpg)
40
● Transaction = logical unit of work, sharing ACID properties
● Transaction participantsapplication, trx manager, resource managers,resource adapters
● Transaction types• local or distributed• flat or nested• extended
● J2EE transaction management
Summary
![Page 41: Transactions and J2EE - ABIS · JDBC – Java Data Base Connectivity • J2EE defines access to 1 JDBC resource per trx JCA – Java Connector Architecture • integration with EIS](https://reader033.vdocuments.us/reader033/viewer/2022043022/5f3e17093d6e2263be5cc0ca/html5/thumbnails/41.jpg)
41
Can you live any longer without transactions?
If not, think of J2EE support!
If You Only Remember One Thing…
![Page 42: Transactions and J2EE - ABIS · JDBC – Java Data Base Connectivity • J2EE defines access to 1 JDBC resource per trx JCA – Java Connector Architecture • integration with EIS](https://reader033.vdocuments.us/reader033/viewer/2022043022/5f3e17093d6e2263be5cc0ca/html5/thumbnails/42.jpg)
42
● Books• Designing Enterprise Applications with the J2EE platform
(2nd edition) by Inderjeet Singh, Beth Stearns, Mark Johnson et al. (Addison Wesley 2002) ISBN 0-201-78790-3
• IBM Redpaper Transactions in J2EE by Jan Smolenski and Peter Kovari (IBM 2003) REDP-3659-00
● URLs• http://java.sun.com/products/jta• http://www-106.ibm.com/developerworks/java/
J2EE Transactions - References
![Page 43: Transactions and J2EE - ABIS · JDBC – Java Data Base Connectivity • J2EE defines access to 1 JDBC resource per trx JCA – Java Connector Architecture • integration with EIS](https://reader033.vdocuments.us/reader033/viewer/2022043022/5f3e17093d6e2263be5cc0ca/html5/thumbnails/43.jpg)
43
Q&A
![Page 44: Transactions and J2EE - ABIS · JDBC – Java Data Base Connectivity • J2EE defines access to 1 JDBC resource per trx JCA – Java Connector Architecture • integration with EIS](https://reader033.vdocuments.us/reader033/viewer/2022043022/5f3e17093d6e2263be5cc0ca/html5/thumbnails/44.jpg)
44
thanks you
JSpring 2004
http://www.abis.be