PlatformTransactionManager

Spring's transaction abstraction is based on a transaction strategy. That is, for different underlying transaction APIs, there is a specific implementation. And all of these implementations implement the org.springframework.transaction.PlatformTransactionManager interface, which is quite simple and looks like this:

public interface PlatformTransactionManager {
TransactionStatus getTransaction(TransactionDefinition definition) throws TransactionException;
void commit(TransactionStatus status) throws TransactionException;
void rollback(TransactionStatus status) throws TransactionException;
}

You can use the getTransaction() method with a TransactionDefinition object to get an object of TransactionStatus. And the returned TransactionStatus object could represent a new transaction or an existing one when there is a matching transaction that exists in the current call stack. With the TransactionStatus object, you can perform a commit or a rollback.

And for Hibernate, the implementation of PlatformTransactionManager is HibernateTransactionManager. For JDBC, the implementation is DataSourceTransactionManager. For JPA, the implementation is JpaTransactionManager. For, JTA, the implementation is JtaTransactionManager. And for JMS, the implementation is JmsTransactionManager. For different APIs, you need to create the corresponding implementation of PlatformTransactionManager.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.116.65.130