java.lang.Object | ||
↳ | org.springframework.transaction.support.DefaultTransactionDefinition | |
↳ | org.springframework.transaction.support.TransactionTemplate |
Template class that simplifies programmatic transaction demarcation and transaction exception handling.
The central method is execute(TransactionCallback
, supporting transactional code that
implements the TransactionCallback
interface. This template handles
the transaction lifecycle and possible exceptions such that neither the
TransactionCallback implementation nor the calling code needs to explicitly
handle transactions.
Typical usage: Allows for writing low-level data access objects that use resources such as JDBC DataSources but are not transaction-aware themselves. Instead, they can implicitly participate in transactions handled by higher-level application services utilizing this class, making calls to the low-level services via an inner-class callback object.
Can be used within a service implementation via direct instantiation with a transaction manager reference, or get prepared in an application context and passed to services as bean reference. Note: The transaction manager should always be configured as bean in the application context: in the first case given to the service directly, in the second case given to the prepared template.
Supports setting the propagation behavior and the isolation level by name, for convenient configuration in context definitions.
[Expand]
Inherited Constants | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
From class
org.springframework.transaction.support.DefaultTransactionDefinition
| |||||||||||
From interface
org.springframework.transaction.TransactionDefinition
|
Fields | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
logger | Logger available to subclasses |
Public Constructors | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Construct a new TransactionTemplate for bean usage.
| |||||||||||
Construct a new TransactionTemplate using the given transaction manager.
| |||||||||||
Construct a new TransactionTemplate using the given transaction manager,
taking its default settings from the given transaction definition.
|
Public Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Invoked by a BeanFactory after it has set all bean properties supplied
(and satisfied BeanFactoryAware and ApplicationContextAware).
| |||||||||||
Execute the action specified by the given callback object within a transaction.
| |||||||||||
Return the transaction management strategy to be used.
| |||||||||||
Set the transaction management strategy to be used.
|
[Expand]
Inherited Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
From class
org.springframework.transaction.support.DefaultTransactionDefinition
| |||||||||||
From class
java.lang.Object
| |||||||||||
From interface
org.springframework.beans.factory.InitializingBean
| |||||||||||
From interface
org.springframework.transaction.TransactionDefinition
| |||||||||||
From interface
org.springframework.transaction.support.TransactionOperations
|
Logger available to subclasses
Construct a new TransactionTemplate for bean usage.
Note: The PlatformTransactionManager needs to be set before
any execute
calls.
Construct a new TransactionTemplate using the given transaction manager.
transactionManager | the transaction management strategy to be used |
---|
Construct a new TransactionTemplate using the given transaction manager, taking its default settings from the given transaction definition.
transactionManager | the transaction management strategy to be used |
---|---|
transactionDefinition | the transaction definition to copy the default settings from. Local properties can still be set to change values. |
Invoked by a BeanFactory after it has set all bean properties supplied (and satisfied BeanFactoryAware and ApplicationContextAware).
This method allows the bean instance to perform initialization only possible when all bean properties have been set and to throw an exception in the event of misconfiguration.
Execute the action specified by the given callback object within a transaction.
Allows for returning a result object created within the transaction, that is, a domain object or a collection of domain objects. A RuntimeException thrown by the callback is treated as a fatal exception that enforces a rollback. Such an exception gets propagated to the caller of the template.
action | the callback object that specifies the transactional action |
---|
null
if noneTransactionException |
---|
Return the transaction management strategy to be used.
Set the transaction management strategy to be used.