Top Description Fields Constructors Methods
org.springframework.transaction.jta

public Class SpringJtaSynchronizationAdapter

extends Object
implements Synchronization
Class Inheritance
All Implemented Interfaces
jakarta.transaction.Synchronization
Imports
jakarta.transaction.Status, .Synchronization, .TransactionManager, .UserTransaction, org.apache.commons.logging.Log, .LogFactory, org.springframework.lang.Nullable, org.springframework.transaction.support.TransactionSynchronization, .TransactionSynchronizationManager, org.springframework.util.Assert

Adapter that implements the JTA jakarta.transaction.Synchronization interface delegating to an underlying Spring org.springframework.transaction.support.TransactionSynchronization.

Useful for synchronizing Spring resource management code with plain JTA / EJB CMT transactions, despite the original code being built for Spring transaction synchronization.

Author
Juergen Hoeller
Since
2.0
See Also
jakarta.transaction.Transaction#registerSynchronization, org.springframework.transaction.support.TransactionSynchronization

Field Summary

Modifier and TypeField and Description
private boolean
private UserTransaction
protected static final Log
private final TransactionSynchronization

Constructor Summary

AccessConstructor and Description
public
SpringJtaSynchronizationAdapter(TransactionSynchronization
the Spring TransactionSynchronization to delegate to
springSynchronization
)

Create a new SpringJtaSynchronizationAdapter for the given Spring TransactionSynchronization and JTA TransactionManager.

public
SpringJtaSynchronizationAdapter(TransactionSynchronization
the Spring TransactionSynchronization to delegate to
springSynchronization
,
UserTransaction
the JTA UserTransaction to use for rollback-only setting in case of an exception thrown in beforeCompletion
jtaUserTransaction
)
Deprecated since 6.0.12. as of 6.0.12 since JTA 1.1+ requires implicit rollback-only setting in case of an exception thrown in beforeCompletion, so the regular SpringJtaSynchronizationAdapter(TransactionSynchronization) constructor is sufficient for all scenarios

Create a new SpringJtaSynchronizationAdapter for the given Spring TransactionSynchronization and JTA TransactionManager.

public
SpringJtaSynchronizationAdapter(TransactionSynchronization
the Spring TransactionSynchronization to delegate to
springSynchronization
,
TransactionManager
the JTA TransactionManager to use for rollback-only setting in case of an exception thrown in beforeCompletion
jtaTransactionManager
)
Deprecated since 6.0.12. as of 6.0.12 since JTA 1.1+ requires implicit rollback-only setting in case of an exception thrown in beforeCompletion, so the regular SpringJtaSynchronizationAdapter(TransactionSynchronization) constructor is sufficient for all scenarios

Create a new SpringJtaSynchronizationAdapter for the given Spring TransactionSynchronization and JTA TransactionManager.

Method Summary

Modifier and TypeMethod and Description
public void
afterCompletion(int
The status of the transaction completion.
status
)

Implements jakarta.transaction.Synchronization.afterCompletion.

JTA afterCompletion callback: invoked after commit/rollback.

public void
beforeCompletion()

Implements jakarta.transaction.Synchronization.beforeCompletion.

JTA beforeCompletion callback: just invoked before commit.

private void
setRollbackOnlyIfPossible()

Set the underlying JTA transaction to rollback-only.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

beforeCompletionCalledback to summary
private boolean beforeCompletionCalled
jtaTransactionback to summary
private UserTransaction jtaTransaction
Annotations
@Nullable
loggerback to summary
protected static final Log logger
springSynchronizationback to summary
private final TransactionSynchronization springSynchronization

Constructor Detail

SpringJtaSynchronizationAdapterback to summary
public SpringJtaSynchronizationAdapter(TransactionSynchronization springSynchronization)

Create a new SpringJtaSynchronizationAdapter for the given Spring TransactionSynchronization and JTA TransactionManager.

Parameters
springSynchronization:TransactionSynchronization

the Spring TransactionSynchronization to delegate to

SpringJtaSynchronizationAdapterback to summary
public SpringJtaSynchronizationAdapter(TransactionSynchronization springSynchronization, UserTransaction jtaUserTransaction)

Deprecated

since 6.0.12.

as of 6.0.12 since JTA 1.1+ requires implicit rollback-only setting in case of an exception thrown in beforeCompletion, so the regular SpringJtaSynchronizationAdapter(TransactionSynchronization) constructor is sufficient for all scenarios

Create a new SpringJtaSynchronizationAdapter for the given Spring TransactionSynchronization and JTA TransactionManager.

Parameters
springSynchronization:TransactionSynchronization

the Spring TransactionSynchronization to delegate to

jtaUserTransaction:UserTransaction

the JTA UserTransaction to use for rollback-only setting in case of an exception thrown in beforeCompletion

Annotations
@Deprecated
since:6.0.12
SpringJtaSynchronizationAdapterback to summary
public SpringJtaSynchronizationAdapter(TransactionSynchronization springSynchronization, TransactionManager jtaTransactionManager)

Deprecated

since 6.0.12.

as of 6.0.12 since JTA 1.1+ requires implicit rollback-only setting in case of an exception thrown in beforeCompletion, so the regular SpringJtaSynchronizationAdapter(TransactionSynchronization) constructor is sufficient for all scenarios

Create a new SpringJtaSynchronizationAdapter for the given Spring TransactionSynchronization and JTA TransactionManager.

Parameters
springSynchronization:TransactionSynchronization

the Spring TransactionSynchronization to delegate to

jtaTransactionManager:TransactionManager

the JTA TransactionManager to use for rollback-only setting in case of an exception thrown in beforeCompletion

Annotations
@Deprecated
since:6.0.12

Method Detail

afterCompletionback to summary
public void afterCompletion(int status)

Implements jakarta.transaction.Synchronization.afterCompletion.

JTA afterCompletion callback: invoked after commit/rollback.

Needs to invoke the Spring synchronization's beforeCompletion at this late stage in case of a rollback, since there is no corresponding callback with JTA.

Parameters
status:int

Doc from jakarta.transaction.Synchronization.afterCompletion.

The status of the transaction completion.

Annotations
@Override
See Also
org.springframework.transaction.support.TransactionSynchronization#beforeCompletion, org.springframework.transaction.support.TransactionSynchronization#afterCompletion
beforeCompletionback to summary
public void beforeCompletion()

Implements jakarta.transaction.Synchronization.beforeCompletion.

JTA beforeCompletion callback: just invoked before commit.

In case of an exception, the JTA transaction will be marked as rollback-only.

Annotations
@Override
See Also
org.springframework.transaction.support.TransactionSynchronization#beforeCommit
setRollbackOnlyIfPossibleback to summary
private void setRollbackOnlyIfPossible()

Set the underlying JTA transaction to rollback-only.