Search in sources :

Example 1 with TransactionInterceptor

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();
}
Also used : NameMatchTransactionAttributeSource(org.springframework.transaction.interceptor.NameMatchTransactionAttributeSource) TransactionAttributeSource(org.springframework.transaction.interceptor.TransactionAttributeSource) TransactionInterceptor(org.springframework.transaction.interceptor.TransactionInterceptor) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) HashMap(java.util.HashMap) Advice(org.aopalliance.aop.Advice) PollerMetadata(org.springframework.integration.scheduling.PollerMetadata) Test(org.junit.Test)

Example 2 with TransactionInterceptor

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);
}
Also used : TransactionInterceptor(org.springframework.transaction.interceptor.TransactionInterceptor) TransactionInterceptorBuilder(org.springframework.integration.transaction.TransactionInterceptorBuilder)

Example 3 with 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);
}
Also used : TransactionInterceptor(org.springframework.transaction.interceptor.TransactionInterceptor) TransactionInterceptorBuilder(org.springframework.integration.transaction.TransactionInterceptorBuilder)

Example 4 with 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();
}
Also used : TransactionInterceptor(org.springframework.transaction.interceptor.TransactionInterceptor) Advised(org.springframework.aop.framework.Advised) DefaultListableBeanFactory(org.springframework.beans.factory.support.DefaultListableBeanFactory) Advisor(org.springframework.aop.Advisor) Test(org.junit.Test)

Example 5 with TransactionInterceptor

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);
}
Also used : TransactionInterceptor(org.springframework.transaction.interceptor.TransactionInterceptor) ProxyFactory(org.springframework.aop.framework.ProxyFactory) Test(org.junit.jupiter.api.Test)

Aggregations

TransactionInterceptor (org.springframework.transaction.interceptor.TransactionInterceptor)19 Test (org.junit.jupiter.api.Test)8 ProxyFactory (org.springframework.aop.framework.ProxyFactory)7 Test (org.junit.Test)4 TransactionAttributeSource (org.springframework.transaction.interceptor.TransactionAttributeSource)4 TransactionInterceptorBuilder (org.springframework.integration.transaction.TransactionInterceptorBuilder)3 NameMatchTransactionAttributeSource (org.springframework.transaction.interceptor.NameMatchTransactionAttributeSource)3 Advised (org.springframework.aop.framework.Advised)2 Bean (org.springframework.context.annotation.Bean)2 Role (org.springframework.context.annotation.Role)2 DelayHandler (org.springframework.integration.handler.DelayHandler)2 MatchAlwaysTransactionAttributeSource (org.springframework.transaction.interceptor.MatchAlwaysTransactionAttributeSource)2 Method (java.lang.reflect.Method)1 HashMap (java.util.HashMap)1 Advice (org.aopalliance.aop.Advice)1 Advisor (org.springframework.aop.Advisor)1 BeanDefinition (org.springframework.beans.factory.config.BeanDefinition)1 BeanDefinitionBuilder (org.springframework.beans.factory.support.BeanDefinitionBuilder)1 DefaultListableBeanFactory (org.springframework.beans.factory.support.DefaultListableBeanFactory)1 RootBeanDefinition (org.springframework.beans.factory.support.RootBeanDefinition)1