Este contenido no está disponible en el idioma seleccionado.

2.4. PlatformTransactionManager Interface


Overview

The PlatformTransactionManager interface is the key abstraction in the Spring transaction API, providing the classic transaction client operations: begin, commit and rollback. This interface thus provides the essential methods for controlling transactions at run time.
Note
The other key aspect of any transaction system is the API for implementing transactional resources. But transactional resources are generally implemented by the underlying database, so this aspect of transactional programming is rarely a concern for the application programmer.

PlatformTransactionManager interface

Example 2.1, “The PlatformTransactionManager Interface” shows the definition of the org.springframework.transaction.PlatformTransactionManager interface.

Example 2.1. The PlatformTransactionManager Interface

package org.springframework.transaction;

public interface PlatformTransactionManager {
  TransactionStatus getTransaction(TransactionDefinition definition)
    throws TransactionException;

  void commit(TransactionStatus status) throws TransactionException;

  void rollback(TransactionStatus status) throws TransactionException;
}
Copy to Clipboard Toggle word wrap

TransactionDefinition interface

The TransactionDefinition interface is used to specify the characteristics of a newly created transaction. It is used to specify the isolation level and the propagation policy of the new transaction. For more details, see Section 5.3, “Propagation Policies”.

TransactionStatus interface

The TransactionStatus interface can be used to check the status of the current transaction (that is, the transaction associated with the current thread) and to mark the current transaction for rollback. It is defined as follows:
public interface TransactionStatus extends SavepointManager {
    boolean isNewTransaction();

    boolean hasSavepoint();

    void setRollbackOnly();

    boolean isRollbackOnly();

    void flush();

    boolean isCompleted();
}
Copy to Clipboard Toggle word wrap

Using the PlatformTransactionManager interface

The PlatformTransactionManager interface defines the following methods:
getTransaction()
Create a new transaction and associate it with the current thread, passing in a TransactionDefinition object to define the characteristics of the new transaction. This is analogous to the begin() method of many other transaction client APIs.
commit()
Commit the current transaction, making permanent all of the pending changes to the registered resources.
rollback()
Roll back the current transaction, undoing all of the pending changes to the registered resources.
Generally, you do not use the PlatformTransactionManager interface directly. In Apache Camel, you typically use a transaction manager as follows:
  1. Create an instance of a transaction manager (there are several different implementations available in Spring—see Section 2.5, “Transaction Manager Implementations”).
  2. Pass the transaction manager instance either to a Apache Camel component or to the transacted() DSL command in a route. The transactional component or the transacted() command is then responsible for demarcating transactions (see Chapter 5, Transaction Demarcation).
Volver arriba
Red Hat logoGithubredditYoutubeTwitter

Aprender

Pruebe, compre y venda

Comunidades

Acerca de la documentación de Red Hat

Ayudamos a los usuarios de Red Hat a innovar y alcanzar sus objetivos con nuestros productos y servicios con contenido en el que pueden confiar. Explore nuestras recientes actualizaciones.

Hacer que el código abierto sea más inclusivo

Red Hat se compromete a reemplazar el lenguaje problemático en nuestro código, documentación y propiedades web. Para más detalles, consulte el Blog de Red Hat.

Acerca de Red Hat

Ofrecemos soluciones reforzadas que facilitan a las empresas trabajar en plataformas y entornos, desde el centro de datos central hasta el perímetro de la red.

Theme

© 2025 Red Hat