Class JTATransactionImpl
java.lang.Object
org.datanucleus.transaction.TransactionImpl
org.datanucleus.transaction.jta.JTATransactionImpl
- All Implemented Interfaces:
Synchronization, Transaction
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 call
joinTransactionwhich 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 -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected booleanprivate static booleanprotected JTATransactionImpl.JoinStatusprivate JTASyncRegistryprivate TransactionManagerJTA TransactionManager.private TransactionJTA Transaction that we are currently synced with.private UserTransactionFields inherited from class TransactionImpl
active, closed, committing, ec, rollbackOnly, serializeRead, txnMgrFields inherited from interface Transaction
TRANSACTION_ISOLATION_OPTION -
Constructor Summary
ConstructorsConstructorDescriptionJTATransactionImpl(ExecutionContext ec, boolean autoJoin, PropertyStore properties) Constructor. -
Method Summary
Modifier and TypeMethodDescriptionvoidafterCompletion(int status) This method is called by the transaction manager after the transaction is committed or rolled back.voidThe beforeCompletion method is called by the transaction manager prior to the start of the two-phase transaction commit process.voidbegin()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.voidcommit()Method to commit the transaction.booleanSimilar to "isActive" except that it just returns the "active" flag whereas the isActive() method can also embody rejoining to underlying transactions.private intbooleanisActive()Accessor for whether the transaction is active.booleanisJoined()voidMethod to call if you want to join to the underlying UserTransaction.voidrollback()Method to rollback the transaction.voidMutator for the "rollback only" flag.Methods inherited from class 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 Details
-
JBOSS_SERVER
private static boolean JBOSS_SERVER -
jtaTM
JTA TransactionManager. -
jtaTx
JTA Transaction that we are currently synced with. Null when no JTA transaction active or not yet joined. -
jtaSyncRegistry
-
joinStatus
-
userTransaction
-
autoJoin
protected boolean autoJoin
-
-
Constructor Details
-
JTATransactionImpl
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 Details
-
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:TransactionImplSimilar to "isActive" except that it just returns the "active" flag whereas the isActive() method can also embody rejoining to underlying transactions.- Specified by:
getIsActivein interfaceTransaction- Overrides:
getIsActivein 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:
isActivein interfaceTransaction- Overrides:
isActivein 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:
beginin interfaceTransaction- Overrides:
beginin classTransactionImpl
-
commit
public void commit()Description copied from class:TransactionImplMethod to commit the transaction.- Specified by:
commitin interfaceTransaction- Overrides:
commitin classTransactionImpl
-
rollback
public void rollback()Description copied from class:TransactionImplMethod to rollback the transaction.- Specified by:
rollbackin interfaceTransaction- Overrides:
rollbackin classTransactionImpl
-
setRollbackOnly
public void setRollbackOnly()Description copied from class:TransactionImplMutator for the "rollback only" flag. Sets the transaction as for rollback only.- Specified by:
setRollbackOnlyin interfaceTransaction- Overrides:
setRollbackOnlyin 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:
beforeCompletionin interfaceSynchronization
-
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:
afterCompletionin interfaceSynchronization- Parameters:
status- The status
-