use of org.springframework.transaction.interceptor.TransactionInterceptor in project spring-framework by spring-projects.
the class AnnotationTransactionInterceptorTests method withMonoRollback.
@Test
public void withMonoRollback() {
ProxyFactory proxyFactory = new ProxyFactory();
proxyFactory.setTarget(new TestWithReactive());
proxyFactory.addAdvice(new TransactionInterceptor(rtm, this.source));
TestWithReactive proxy = (TestWithReactive) proxyFactory.getProxy();
StepVerifier.withVirtualTime(proxy::monoSuccess).thenAwait(Duration.ofSeconds(1)).thenCancel().verify();
assertReactiveGetTransactionAndRollbackCount(1);
}
use of org.springframework.transaction.interceptor.TransactionInterceptor in project spring-framework by spring-projects.
the class AnnotationTransactionAttributeSourceTests method serializable.
@Test
public void serializable() throws Exception {
TestBean1 tb = new TestBean1();
CallCountingTransactionManager ptm = new CallCountingTransactionManager();
AnnotationTransactionAttributeSource tas = new AnnotationTransactionAttributeSource();
TransactionInterceptor ti = new TransactionInterceptor((TransactionManager) ptm, tas);
ProxyFactory proxyFactory = new ProxyFactory();
proxyFactory.setInterfaces(ITestBean1.class);
proxyFactory.addAdvice(ti);
proxyFactory.setTarget(tb);
ITestBean1 proxy = (ITestBean1) proxyFactory.getProxy();
proxy.getAge();
assertThat(ptm.commits).isEqualTo(1);
ITestBean1 serializedProxy = SerializationTestUtils.serializeAndDeserialize(proxy);
serializedProxy.getAge();
Advised advised = (Advised) serializedProxy;
TransactionInterceptor serializedTi = (TransactionInterceptor) advised.getAdvisors()[0].getAdvice();
CallCountingTransactionManager serializedPtm = (CallCountingTransactionManager) serializedTi.getTransactionManager();
assertThat(serializedPtm.commits).isEqualTo(2);
}
use of org.springframework.transaction.interceptor.TransactionInterceptor in project spring-framework by spring-projects.
the class ProxyTransactionManagementConfiguration method transactionInterceptor.
@Bean
@Role(BeanDefinition.ROLE_INFRASTRUCTURE)
public TransactionInterceptor transactionInterceptor() {
TransactionInterceptor interceptor = new TransactionInterceptor();
interceptor.setTransactionAttributeSource(transactionAttributeSource());
if (this.txManager != null) {
interceptor.setTransactionManager(this.txManager);
}
return interceptor;
}
use of org.springframework.transaction.interceptor.TransactionInterceptor in project spring-data-commons by spring-projects.
the class TransactionalRepositoryProxyPostProcessor method postProcess.
/*
* (non-Javadoc)
* @see org.springframework.data.repository.core.support.RepositoryProxyPostProcessor#postProcess(org.springframework.aop.framework.ProxyFactory, org.springframework.data.repository.core.RepositoryInformation)
*/
public void postProcess(ProxyFactory factory, RepositoryInformation repositoryInformation) {
CustomAnnotationTransactionAttributeSource transactionAttributeSource = new CustomAnnotationTransactionAttributeSource();
transactionAttributeSource.setRepositoryInformation(repositoryInformation);
transactionAttributeSource.setEnableDefaultTransactions(enableDefaultTransactions);
// TODO: Remove
@SuppressWarnings("null") TransactionInterceptor transactionInterceptor = new TransactionInterceptor(null, transactionAttributeSource);
transactionInterceptor.setTransactionManagerBeanName(transactionManagerName);
transactionInterceptor.setBeanFactory(beanFactory);
transactionInterceptor.afterPropertiesSet();
factory.addAdvice(transactionInterceptor);
}
use of org.springframework.transaction.interceptor.TransactionInterceptor in project spring-integration by spring-projects.
the class DelayerParserTests method transactionalSubElement.
// INT-2649
@Test
public void transactionalSubElement() throws Exception {
Object endpoint = context.getBean("delayerWithTransactional");
DelayHandler delayHandler = TestUtils.getPropertyValue(endpoint, "handler", DelayHandler.class);
List<?> adviceChain = TestUtils.getPropertyValue(delayHandler, "delayedAdviceChain", List.class);
assertEquals(1, adviceChain.size());
Object advice = adviceChain.get(0);
assertTrue(advice instanceof TransactionInterceptor);
TransactionAttributeSource transactionAttributeSource = ((TransactionInterceptor) advice).getTransactionAttributeSource();
assertTrue(transactionAttributeSource instanceof MatchAlwaysTransactionAttributeSource);
Method method = MessageHandler.class.getMethod("handleMessage", Message.class);
TransactionDefinition definition = transactionAttributeSource.getTransactionAttribute(method, null);
assertEquals(TransactionDefinition.PROPAGATION_REQUIRED, definition.getPropagationBehavior());
assertEquals(TransactionDefinition.ISOLATION_DEFAULT, definition.getIsolationLevel());
assertEquals(TransactionDefinition.TIMEOUT_DEFAULT, definition.getTimeout());
assertFalse(definition.isReadOnly());
}
Aggregations