13.6.2Using the PlatformTransactionManager

You can also use theorg.springframework.transaction.PlatformTransactionManagerdirectly to manage your transaction. Simply pass the implementation of thePlatformTransactionManageryou are using to your bean through a bean reference. Then, using theTransactionDefinitionandTransactionStatusobjects you can initiate transactions, roll back, and commit.

DefaultTransactionDefinition def = new DefaultTransactionDefinition();
// explicitly setting the transaction name is something that can only be done programmatically
def.setName("SomeTxName");
def.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRED);

TransactionStatus status = txManager.getTransaction(def);
try {
    // execute your business logic here
}
catch (MyException ex) {
    txManager.rollback(status);
    throw ex;
}
txManager.commit(status);

results matching ""

    No results matching ""