use of org.springframework.transaction.interceptor.TransactionInterceptor in project spring-integration by spring-projects.
the class PollerParserTests method pollerWithAdviceChain.
@Test
public void pollerWithAdviceChain() {
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("pollerWithAdviceChain.xml", PollerParserTests.class);
Object poller = context.getBean("poller");
assertNotNull(poller);
PollerMetadata metadata = (PollerMetadata) poller;
assertNotNull(metadata.getAdviceChain());
assertEquals(4, metadata.getAdviceChain().size());
assertSame(context.getBean("adviceBean1"), metadata.getAdviceChain().get(0));
assertEquals(TestAdviceBean.class, metadata.getAdviceChain().get(1).getClass());
assertEquals(2, ((TestAdviceBean) metadata.getAdviceChain().get(1)).getId());
assertSame(context.getBean("adviceBean3"), metadata.getAdviceChain().get(2));
Advice txAdvice = metadata.getAdviceChain().get(3);
assertEquals(TransactionInterceptor.class, txAdvice.getClass());
TransactionAttributeSource transactionAttributeSource = ((TransactionInterceptor) txAdvice).getTransactionAttributeSource();
assertEquals(NameMatchTransactionAttributeSource.class, transactionAttributeSource.getClass());
@SuppressWarnings("rawtypes") HashMap nameMap = TestUtils.getPropertyValue(transactionAttributeSource, "nameMap", HashMap.class);
assertEquals(1, nameMap.size());
assertEquals("{*=PROPAGATION_REQUIRES_NEW,ISOLATION_DEFAULT,readOnly}", nameMap.toString());
context.close();
}
use of org.springframework.transaction.interceptor.TransactionInterceptor in project spring-integration by spring-projects.
the class ConsumerEndpointSpec method transactional.
/**
* Specify a {@link TransactionInterceptor} {@link Advice} with default
* {@code PlatformTransactionManager} and {@link DefaultTransactionAttribute} for the
* {@link MessageHandler}.
* @param handleMessageAdvice the flag to indicate the target {@link Advice} type:
* {@code false} - regular {@link TransactionInterceptor}; {@code true} -
* {@link org.springframework.integration.transaction.TransactionHandleMessageAdvice}
* extension.
* @return the spec.
*/
public S transactional(boolean handleMessageAdvice) {
TransactionInterceptor transactionInterceptor = new TransactionInterceptorBuilder(handleMessageAdvice).build();
this.componentsToRegister.put(transactionInterceptor, null);
return transactional(transactionInterceptor);
}
use of org.springframework.transaction.interceptor.TransactionInterceptor in project spring-integration by spring-projects.
the class ImapIdleChannelAdapterSpec method transactional.
/**
* Specify a {@link TransactionInterceptor} {@link Advice} with default
* {@code PlatformTransactionManager} and {@link DefaultTransactionAttribute} for the
* downstream flow.
* @return the spec.
*/
public ImapIdleChannelAdapterSpec transactional() {
TransactionInterceptor transactionInterceptor = new TransactionInterceptorBuilder(false).build();
this.componentsToRegister.put(transactionInterceptor, null);
return transactional(transactionInterceptor);
}
use of org.springframework.transaction.interceptor.TransactionInterceptor in project spring-data-commons by spring-projects.
the class TransactionRepositoryFactoryBeanSupportUnitTests method disablesDefaultTransactionsIfConfigured.
// DATACMNS-656
@Test
public void disablesDefaultTransactionsIfConfigured() {
SampleTransactionalRepositoryFactoryBean factoryBean = new SampleTransactionalRepositoryFactoryBean();
factoryBean.setEnableDefaultTransactions(false);
factoryBean.setBeanFactory(new DefaultListableBeanFactory());
factoryBean.afterPropertiesSet();
CrudRepository<Object, Long> repository = factoryBean.getObject();
Advisor[] advisors = ((Advised) repository).getAdvisors();
boolean found = false;
for (Advisor advisor : advisors) {
if (advisor.getAdvice() instanceof TransactionInterceptor) {
found = true;
TransactionInterceptor interceptor = (TransactionInterceptor) advisor.getAdvice();
assertThat(getField(interceptor.getTransactionAttributeSource(), "enableDefaultTransactions")).isEqualTo(false);
break;
}
}
assertThat(found).isTrue();
}
use of org.springframework.transaction.interceptor.TransactionInterceptor in project spring-framework by spring-projects.
the class AnnotationTransactionInterceptorTests method withFluxFailure.
@Test
public void withFluxFailure() {
ProxyFactory proxyFactory = new ProxyFactory();
proxyFactory.setTarget(new TestWithReactive());
proxyFactory.addAdvice(new TransactionInterceptor(rtm, this.source));
TestWithReactive proxy = (TestWithReactive) proxyFactory.getProxy();
proxy.fluxFailure().as(StepVerifier::create).verifyError();
assertReactiveGetTransactionAndRollbackCount(1);
}
Aggregations