use of org.springframework.transaction.interceptor.TransactionInterceptor in project spring-integration by spring-projects.
the class DelayerParserTests method adviceChainSubElement.
// INT-2649
@Test
public void adviceChainSubElement() {
Object endpoint = context.getBean("delayerWithAdviceChain");
DelayHandler delayHandler = TestUtils.getPropertyValue(endpoint, "handler", DelayHandler.class);
List<?> adviceChain = TestUtils.getPropertyValue(delayHandler, "delayedAdviceChain", List.class);
assertEquals(2, adviceChain.size());
assertSame(context.getBean("testAdviceBean"), adviceChain.get(0));
Object txAdvice = adviceChain.get(1);
assertEquals(TransactionInterceptor.class, txAdvice.getClass());
TransactionAttributeSource transactionAttributeSource = ((TransactionInterceptor) txAdvice).getTransactionAttributeSource();
assertEquals(NameMatchTransactionAttributeSource.class, transactionAttributeSource.getClass());
HashMap<?, ?> nameMap = TestUtils.getPropertyValue(transactionAttributeSource, "nameMap", HashMap.class);
assertEquals("{*=PROPAGATION_REQUIRES_NEW,ISOLATION_DEFAULT,readOnly}", nameMap.toString());
}
use of org.springframework.transaction.interceptor.TransactionInterceptor in project spring-integration by spring-projects.
the class IntegrationNamespaceUtils method configureTransactionAttributes.
/**
* Parse a "transactional" element and configure a {@link TransactionInterceptor}
* or {@link TransactionHandleMessageAdvice}
* with "transactionManager" and other "transactionDefinition" properties.
* For example, this advisor will be applied on the Polling Task proxy.
* @param txElement The transactional element.
* @param handleMessageAdvice flag if to use {@link TransactionHandleMessageAdvice}
* or regular {@link TransactionInterceptor}
* @return The bean definition.
* @see AbstractPollingEndpoint
*/
public static BeanDefinition configureTransactionAttributes(Element txElement, boolean handleMessageAdvice) {
BeanDefinition txDefinition = configureTransactionDefinition(txElement);
BeanDefinitionBuilder attributeSourceBuilder = BeanDefinitionBuilder.genericBeanDefinition(MatchAlwaysTransactionAttributeSource.class);
attributeSourceBuilder.addPropertyValue("transactionAttribute", txDefinition);
BeanDefinitionBuilder txInterceptorBuilder = BeanDefinitionBuilder.genericBeanDefinition(handleMessageAdvice ? TransactionHandleMessageAdvice.class : TransactionInterceptor.class);
txInterceptorBuilder.addPropertyReference("transactionManager", txElement.getAttribute("transaction-manager"));
txInterceptorBuilder.addPropertyValue("transactionAttributeSource", attributeSourceBuilder.getBeanDefinition());
return txInterceptorBuilder.getBeanDefinition();
}
use of org.springframework.transaction.interceptor.TransactionInterceptor in project spring-integration by spring-projects.
the class PollerSpec method transactional.
/**
* Specify a {@link TransactionInterceptor} {@link Advice} with default {@code PlatformTransactionManager}
* and {@link DefaultTransactionAttribute} for the {@code pollingTask}.
* @return the spec.
*/
public PollerSpec transactional() {
TransactionInterceptor transactionInterceptor = new TransactionInterceptorBuilder().build();
this.componentsToRegister.put(transactionInterceptor, null);
return transactional(transactionInterceptor);
}
use of org.springframework.transaction.interceptor.TransactionInterceptor in project spring-framework by spring-projects.
the class TxNamespaceHandlerTests method rollbackRules.
@Test
public void rollbackRules() {
TransactionInterceptor txInterceptor = (TransactionInterceptor) context.getBean("txRollbackAdvice");
TransactionAttributeSource txAttrSource = txInterceptor.getTransactionAttributeSource();
TransactionAttribute txAttr = txAttrSource.getTransactionAttribute(getAgeMethod, ITestBean.class);
assertThat(txAttr.rollbackOn(new Exception())).as("should be configured to rollback on Exception").isTrue();
txAttr = txAttrSource.getTransactionAttribute(setAgeMethod, ITestBean.class);
assertThat(txAttr.rollbackOn(new RuntimeException())).as("should not rollback on RuntimeException").isFalse();
}
use of org.springframework.transaction.interceptor.TransactionInterceptor in project spring-framework by spring-projects.
the class AnnotationTransactionInterceptorTests method withMonoFailure.
@Test
public void withMonoFailure() {
ProxyFactory proxyFactory = new ProxyFactory();
proxyFactory.setTarget(new TestWithReactive());
proxyFactory.addAdvice(new TransactionInterceptor(rtm, this.source));
TestWithReactive proxy = (TestWithReactive) proxyFactory.getProxy();
proxy.monoFailure().as(StepVerifier::create).verifyError();
assertReactiveGetTransactionAndRollbackCount(1);
}
Aggregations