Package org.datanucleus.transaction.jta
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 boolean
private static boolean
protected JTATransactionImpl.JoinStatus
private JTASyncRegistry
private TransactionManager
JTA TransactionManager.private Transaction
JTA Transaction that we are currently synced with.private 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
ConstructorsConstructorDescriptionJTATransactionImpl
(ExecutionContext ec, boolean autoJoin, PropertyStore properties) Constructor. -
Method Summary
Modifier and TypeMethodDescriptionvoid
afterCompletion
(int status) This method is called by the transaction manager after the transaction is committed or rolled back.void
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
Similar to "isActive" except that it just returns the "active" flag whereas the isActive() method can also embody rejoining to underlying transactions.private int
boolean
isActive()
Accessor for whether the transaction is active.boolean
isJoined()
void
Method to call if you want to join to the underlying UserTransaction.void
rollback()
Method to rollback the transaction.void
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 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: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 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:
afterCompletion
in interfaceSynchronization
- Parameters:
status
- The status
-