use of org.springframework.transaction.PlatformTransactionManager in project BroadleafCommerce by BroadleafCommerce.
the class PersistenceServiceImpl method identifyTransactionManager.
@Override
public PlatformTransactionManager identifyTransactionManager(String className, TargetModeType targetModeType) {
String cacheKey = buildManagerCacheKey(targetModeType.getType(), className);
PlatformTransactionManager txManager = TRANSACTION_MANAGER_CACHE.get(cacheKey);
if (txManager == null) {
throw new RuntimeException("Unable to determine the PlatformTransactionManager for the following " + "targetModeType and class pair: " + cacheKey);
}
return txManager;
}
use of org.springframework.transaction.PlatformTransactionManager in project BroadleafCommerce by BroadleafCommerce.
the class DynamicEntityRemoteService method inspect.
@Override
public PersistenceResponse inspect(final PersistencePackage persistencePackage) throws ServiceException {
final PersistenceResponse[] response = new PersistenceResponse[1];
try {
PlatformTransactionManager transactionManager = identifyTransactionManager(persistencePackage);
transUtil.runOptionalTransactionalOperation(new StreamCapableTransactionalOperationAdapter() {
@Override
public void execute() throws Throwable {
response[0] = nonTransactionalInspect(persistencePackage);
}
}, RuntimeException.class, true, TransactionDefinition.PROPAGATION_REQUIRED, TransactionDefinition.ISOLATION_DEFAULT, true, transactionManager);
} catch (RuntimeException e) {
if (e.getCause() instanceof ServiceException) {
throw (ServiceException) e.getCause();
}
throw e;
}
return response[0];
}
use of org.springframework.transaction.PlatformTransactionManager in project BroadleafCommerce by BroadleafCommerce.
the class DynamicEntityRemoteService method remove.
@Override
public PersistenceResponse remove(final PersistencePackage persistencePackage) throws ServiceException {
final PersistenceResponse[] response = new PersistenceResponse[1];
try {
PlatformTransactionManager transactionManager = identifyTransactionManager(persistencePackage);
transUtil.runTransactionalOperation(new StreamCapableTransactionalOperationAdapter() {
@Override
public void execute() throws Throwable {
response[0] = nonTransactionalRemove(persistencePackage);
}
@Override
public boolean shouldRetryOnTransactionLockAcquisitionFailure() {
return super.shouldRetryOnTransactionLockAcquisitionFailure();
}
}, RuntimeException.class, transactionManager);
} catch (RuntimeException e) {
if (e.getCause() instanceof ServiceException) {
throw (ServiceException) e.getCause();
}
throw e;
}
return response[0];
}
use of org.springframework.transaction.PlatformTransactionManager in project spring-framework by spring-projects.
the class BeanFactoryTransactionTests method doTestGetsAreNotTransactional.
private void doTestGetsAreNotTransactional(final ITestBean testBean) {
// Install facade
PlatformTransactionManager ptm = mock(PlatformTransactionManager.class);
PlatformTransactionManagerFacade.delegate = ptm;
assertThat(testBean.getAge() == 666).as("Age should not be " + testBean.getAge()).isTrue();
// Expect no methods
verifyNoInteractions(ptm);
// Install facade expecting a call
final TransactionStatus ts = mock(TransactionStatus.class);
ptm = new PlatformTransactionManager() {
private boolean invoked;
@Override
public TransactionStatus getTransaction(@Nullable TransactionDefinition def) throws TransactionException {
if (invoked) {
throw new IllegalStateException("getTransaction should not get invoked more than once");
}
invoked = true;
if (!(def.getName().contains(DerivedTestBean.class.getName()) && def.getName().contains("setAge"))) {
throw new IllegalStateException("transaction name should contain class and method name: " + def.getName());
}
return ts;
}
@Override
public void commit(TransactionStatus status) throws TransactionException {
assertThat(status == ts).isTrue();
}
@Override
public void rollback(TransactionStatus status) throws TransactionException {
throw new IllegalStateException("rollback should not get invoked");
}
};
PlatformTransactionManagerFacade.delegate = ptm;
// TODO same as old age to avoid ordering effect for now
int age = 666;
testBean.setAge(age);
assertThat(testBean.getAge() == age).isTrue();
}
use of org.springframework.transaction.PlatformTransactionManager in project spring-framework by spring-projects.
the class AbstractTransactionAspectTests method transactionShouldSucceedWithNotNew.
/**
* Check that a transaction is created and committed.
*/
@Test
public void transactionShouldSucceedWithNotNew() throws Exception {
TransactionAttribute txatt = new DefaultTransactionAttribute();
MapTransactionAttributeSource tas = new MapTransactionAttributeSource();
tas.register(getNameMethod, txatt);
TransactionStatus status = mock(TransactionStatus.class);
PlatformTransactionManager ptm = mock(PlatformTransactionManager.class);
// expect a transaction
given(ptm.getTransaction(txatt)).willReturn(status);
TestBean tb = new TestBean();
ITestBean itb = (ITestBean) advised(tb, ptm, tas);
checkTransactionStatus(false);
// verification!?
itb.getName();
checkTransactionStatus(false);
verify(ptm).commit(status);
}
Aggregations