Package org.datanucleus.transaction.jta
Class JTATransactionImpl
- java.lang.Object
-
- org.datanucleus.transaction.TransactionImpl
-
- org.datanucleus.transaction.jta.JTATransactionImpl
-
- All Implemented Interfaces:
javax.transaction.Synchronization
,Transaction
public class JTATransactionImpl extends TransactionImpl implements javax.transaction.Synchronization
Transaction that is synchronized with a Java Transaction Service (JTA) transaction. Works only in environments where a TransactionManager is present. This transaction joins to the transaction via the TransactionManager, and the TransactionManager notifies this class of completion via the beforeCompletion/afterCompletion callback hooks. This transaction can be configured as "autoJoin" whereby it will try to join when it is created and otherwise when isActive() is called. When it is not set to "autoJoin" the developer has to calljoinTransaction
which will check the current join status and join as necessary.When this transaction is being used the transactions must be controlled using javax.transaction.UserTransaction, and not using local transactions (e.g PM.currentTransaction().begin()). Should also work for SessionBeans, as per spec UserTransaction reflects SessionBean-based tx demarcation. See also
Transaction
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static class
JTATransactionImpl.JoinStatus
-
Field Summary
Fields Modifier and Type Field Description protected boolean
autoJoin
private static boolean
JBOSS_SERVER
protected JTATransactionImpl.JoinStatus
joinStatus
private JTASyncRegistry
jtaSyncRegistry
private javax.transaction.TransactionManager
jtaTM
JTA TransactionManager.private javax.transaction.Transaction
jtaTx
JTA Transaction that we are currently synced with.private javax.transaction.UserTransaction
userTransaction
-
Fields inherited from class org.datanucleus.transaction.TransactionImpl
active, closed, committing, ec, rollbackOnly, serializeRead, txnMgr
-
Fields inherited from interface org.datanucleus.transaction.Transaction
TRANSACTION_ISOLATION_OPTION
-
-
Constructor Summary
Constructors Constructor Description JTATransactionImpl(ExecutionContext ec, boolean autoJoin, PropertyStore properties)
Constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
afterCompletion(int status)
This method is called by the transaction manager after the transaction is committed or rolled back.void
beforeCompletion()
The beforeCompletion method is called by the transaction manager prior to the start of the two-phase transaction commit process.void
begin()
JDO spec "16.1.3 Stateless Session Bean with Bean Managed Transactions": "acquiring a PM without beginning a UserTransaction results in the PM being able to manage transaction boundaries via begin, commit, and rollback methods on JDO Transaction.void
commit()
Method to commit the transaction.boolean
getIsActive()
Similar to "isActive" except that it just returns the "active" flag whereas the isActive() method can also embody rejoining to underlying transactions.private int
getTransactionStatus()
boolean
isActive()
Accessor for whether the transaction is active.boolean
isJoined()
void
joinTransaction()
Method to call if you want to join to the underlying UserTransaction.void
rollback()
Method to rollback the transaction.void
setRollbackOnly()
Mutator for the "rollback only" flag.-
Methods inherited from class org.datanucleus.transaction.TransactionImpl
addTransactionEventListener, bindTransactionEventListener, close, end, flush, getBeginTime, getNontransactionalRead, getNontransactionalWrite, getNontransactionalWriteAutoCommit, getOptimistic, getOptions, getRestoreValues, getRetainValues, getRollbackOnly, getSerializeRead, getSynchronization, internalBegin, internalCommit, internalPostCommit, internalPreCommit, internalPreRollback, internalRollback, isCommitting, preFlush, releaseSavepoint, removeTransactionEventListener, rollbackToSavepoint, setNontransactionalRead, setNontransactionalWrite, setNontransactionalWriteAutoCommit, setOptimistic, setOption, setOption, setOption, setOption, setProperties, setRestoreValues, setRetainValues, setSavepoint, setSerializeRead, setSynchronization
-
-
-
-
Field Detail
-
JBOSS_SERVER
private static boolean JBOSS_SERVER
-
jtaTM
private javax.transaction.TransactionManager jtaTM
JTA TransactionManager.
-
jtaTx
private javax.transaction.Transaction jtaTx
JTA Transaction that we are currently synced with. Null when no JTA transaction active or not yet joined.
-
jtaSyncRegistry
private JTASyncRegistry jtaSyncRegistry
-
joinStatus
protected JTATransactionImpl.JoinStatus joinStatus
-
userTransaction
private javax.transaction.UserTransaction userTransaction
-
autoJoin
protected boolean autoJoin
-
-
Constructor Detail
-
JTATransactionImpl
public JTATransactionImpl(ExecutionContext ec, boolean autoJoin, PropertyStore properties)
Constructor. Will attempt to join with the transaction manager to get the underlying transaction.- Parameters:
ec
- ExecutionContextautoJoin
- Whether to auto-join to the underlying UserTransaction on isActive and at creation?properties
- Properties to use with the transaction
-
-
Method Detail
-
isJoined
public boolean isJoined()
-
getTransactionStatus
private int getTransactionStatus()
-
joinTransaction
public void joinTransaction()
Method to call if you want to join to the underlying UserTransaction. Will be called by isActive() and constructor if "autoJoin" is set, otherwise has to be called by user code.
-
getIsActive
public boolean getIsActive()
Description copied from class:TransactionImpl
Similar to "isActive" except that it just returns the "active" flag whereas the isActive() method can also embody rejoining to underlying transactions.- Specified by:
getIsActive
in interfaceTransaction
- Overrides:
getIsActive
in classTransactionImpl
- Returns:
- The "active" flag
-
isActive
public boolean isActive()
Accessor for whether the transaction is active. The UserTransaction is considered active if its status is anything other thanStatus.STATUS_NO_TRANSACTION
, i.e. when the current thread is associated with a JTA transaction. Note that this will attempt to join if not yet joined- Specified by:
isActive
in interfaceTransaction
- Overrides:
isActive
in classTransactionImpl
- Returns:
- Whether the transaction is active.
-
begin
public void begin()
JDO spec "16.1.3 Stateless Session Bean with Bean Managed Transactions": "acquiring a PM without beginning a UserTransaction results in the PM being able to manage transaction boundaries via begin, commit, and rollback methods on JDO Transaction. The PM will automatically begin the User-Transaction during Transaction.begin and automatically commit the UserTransaction during Transaction.commit"- Specified by:
begin
in interfaceTransaction
- Overrides:
begin
in classTransactionImpl
-
commit
public void commit()
Description copied from class:TransactionImpl
Method to commit the transaction.- Specified by:
commit
in interfaceTransaction
- Overrides:
commit
in classTransactionImpl
-
rollback
public void rollback()
Description copied from class:TransactionImpl
Method to rollback the transaction.- Specified by:
rollback
in interfaceTransaction
- Overrides:
rollback
in classTransactionImpl
-
setRollbackOnly
public void setRollbackOnly()
Description copied from class:TransactionImpl
Mutator for the "rollback only" flag. Sets the transaction as for rollback only.- Specified by:
setRollbackOnly
in interfaceTransaction
- Overrides:
setRollbackOnly
in classTransactionImpl
-
beforeCompletion
public void beforeCompletion()
The beforeCompletion method is called by the transaction manager prior to the start of the two-phase transaction commit process.- Specified by:
beforeCompletion
in interfacejavax.transaction.Synchronization
-
afterCompletion
public void afterCompletion(int status)
This method is called by the transaction manager after the transaction is committed or rolled back. Must be synchronised because some callers expect to be owner of this object's monitor (internalPostCommit() calls closeSQLConnection() which calls notifyAll()).- Specified by:
afterCompletion
in interfacejavax.transaction.Synchronization
- Parameters:
status
- The status
-
-