21-08-2012, 04:37 PM
EJB Transaction
transaction.ppt (Size: 317.5 KB / Downloads: 33)
Definition
a transaction is often defined as an indivisible unit of work
Requirement on Transaction
A transaction can end in two ways:
with a commit or
with a rollback.
In case of transaction commits, the data modifications made by its statements are saved. Otherwise, the transaction rolls back, undoing the effects of all statements in the transaction.
Flat Transactions
A series of operations that are performed atomically
A successful transaction is committed
A failed transaction is aborted
all or nothing proposition
EJB specification only mandates to flat transactions
EJB Transactions
Container managed Transactions
Bean managed Transactions
Client managed Transactions
looking up UserTransaction in the JNDI registry
resource injection
Container Managed Transactions
For a enterprise bean
begin transaction
immediately before a method starts
commit transaction
just before the method exits.
Each method can be associated with a single transaction.
Nested or multiple transactions are not allowed within a method.
Requirement
To specify which of the bean’s methods are associated with transactions
set transaction attributes.
must not use any transaction management methods
must not use javax.transaction.UserTransaction interface.
Setting Transaction Attribute
Requires a javax.ejb.TransactionAttribute annotation, and setting it to one of the javax.ejb.TransactionAttributeType constants.
annotation @TransactionAttribute
with class
with method
with both
Rolling Back Transaction
Two types
If a system exception is thrown, the container will automatically roll back the transaction.
By invoking the setRollbackOnly method of the EJBContext interface, the bean method instructs the container to roll back the transaction.
Synchronizing a Session Bean’s Instance Variables
SessionSynchronization interface, which is optional, allows stateful session bean instances to receive transaction synchronization notifications.
The container invokes the SessionSynchronization methods (afterBegin, beforeCompletion, and afterCompletion) at each of the main stages of a transaction.
Methods not allowed
The commit, setAutoCommit, and rollback methods of java.sql.Connection
The getUserTransaction method of javax.ejb.EJBContext
Any method of javax.transaction.UserTransaction
transaction.ppt (Size: 317.5 KB / Downloads: 33)
Definition
a transaction is often defined as an indivisible unit of work
Requirement on Transaction
A transaction can end in two ways:
with a commit or
with a rollback.
In case of transaction commits, the data modifications made by its statements are saved. Otherwise, the transaction rolls back, undoing the effects of all statements in the transaction.
Flat Transactions
A series of operations that are performed atomically
A successful transaction is committed
A failed transaction is aborted
all or nothing proposition
EJB specification only mandates to flat transactions
EJB Transactions
Container managed Transactions
Bean managed Transactions
Client managed Transactions
looking up UserTransaction in the JNDI registry
resource injection
Container Managed Transactions
For a enterprise bean
begin transaction
immediately before a method starts
commit transaction
just before the method exits.
Each method can be associated with a single transaction.
Nested or multiple transactions are not allowed within a method.
Requirement
To specify which of the bean’s methods are associated with transactions
set transaction attributes.
must not use any transaction management methods
must not use javax.transaction.UserTransaction interface.
Setting Transaction Attribute
Requires a javax.ejb.TransactionAttribute annotation, and setting it to one of the javax.ejb.TransactionAttributeType constants.
annotation @TransactionAttribute
with class
with method
with both
Rolling Back Transaction
Two types
If a system exception is thrown, the container will automatically roll back the transaction.
By invoking the setRollbackOnly method of the EJBContext interface, the bean method instructs the container to roll back the transaction.
Synchronizing a Session Bean’s Instance Variables
SessionSynchronization interface, which is optional, allows stateful session bean instances to receive transaction synchronization notifications.
The container invokes the SessionSynchronization methods (afterBegin, beforeCompletion, and afterCompletion) at each of the main stages of a transaction.
Methods not allowed
The commit, setAutoCommit, and rollback methods of java.sql.Connection
The getUserTransaction method of javax.ejb.EJBContext
Any method of javax.transaction.UserTransaction