open class TransactionTemplate : DefaultTransactionDefinition, TransactionOperations, InitializingBean
Template class that simplifies programmatic transaction demarcation and transaction exception handling.
The central method is #execute
, 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.
Author
Juergen Hoeller
Since
17.03.2003
See Also
#execute#setTransactionManagerorg.springframework.transaction.PlatformTransactionManager
TransactionTemplate()
Construct a new TransactionTemplate for bean usage. Note: The PlatformTransactionManager needs to be set before any TransactionTemplate(transactionManager: PlatformTransactionManager)
Construct a new TransactionTemplate using the given transaction manager. TransactionTemplate(transactionManager: PlatformTransactionManager, transactionDefinition: TransactionDefinition)
Construct a new TransactionTemplate using the given transaction manager, taking its default settings from the given transaction definition. |
static val PREFIX_ISOLATION: String
Prefix for the isolation constants defined in TransactionDefinition |
|
static val PREFIX_PROPAGATION: String
Prefix for the propagation constants defined in TransactionDefinition |
|
static val PREFIX_TIMEOUT: String
Prefix for transaction timeout values in description strings |
|
static val READ_ONLY_MARKER: String
Marker for read-only transactions in description strings |
open fun afterPropertiesSet(): Unit |
|
open fun <T : Any> execute(action: TransactionCallback<T>): T |
|
open fun getTransactionManager(): PlatformTransactionManager
Return the transaction management strategy to be used. |
|
open fun setTransactionManager(transactionManager: PlatformTransactionManager): Unit
Set the transaction management strategy to be used. |
open fun equals(other: Any?): Boolean
This implementation compares the |
|
fun getIsolationLevel(): Int |
|
fun getName(): String |
|
fun getPropagationBehavior(): Int |
|
fun getTimeout(): Int |
|
open fun hashCode(): Int
This implementation returns |
|
fun isReadOnly(): Boolean |
|
fun setIsolationLevel(isolationLevel: Int): Unit
Set the isolation level. Must be one of the isolation constants in the TransactionDefinition interface. Default is ISOLATION_DEFAULT. |
|
fun setIsolationLevelName(constantName: String): Unit
Set the isolation level by the name of the corresponding constant in TransactionDefinition, e.g. "ISOLATION_DEFAULT". |
|
fun setName(name: String): Unit
Set the name of this transaction. Default is none. This will be used as transaction name to be shown in a transaction monitor, if applicable (for example, WebLogic's). |
|
fun setPropagationBehavior(propagationBehavior: Int): Unit
Set the propagation behavior. Must be one of the propagation constants in the TransactionDefinition interface. Default is PROPAGATION_REQUIRED. |
|
fun setPropagationBehaviorName(constantName: String): Unit
Set the propagation behavior by the name of the corresponding constant in TransactionDefinition, e.g. "PROPAGATION_REQUIRED". |
|
fun setReadOnly(readOnly: Boolean): Unit
Set whether to optimize as read-only transaction. Default is "false". |
|
fun setTimeout(timeout: Int): Unit
Set the timeout to apply, as number of seconds. Default is TIMEOUT_DEFAULT (-1). |
|
open fun toString(): String
Return an identifying description for this transaction definition. The format matches the one used by org.springframework.transaction.interceptor.TransactionAttributeEditor, to be able to feed Has to be overridden in subclasses for correct |