Search in sources :

Example 1 with TransactionManager

use of cn.taketoday.transaction.TransactionManager in project today-infrastructure by TAKETODAY.

the class TransactionAspectSupport method determineQualifiedTransactionManager.

private TransactionManager determineQualifiedTransactionManager(BeanFactory beanFactory, String qualifier) {
    TransactionManager txManager = this.transactionManagerCache.get(qualifier);
    if (txManager == null) {
        txManager = BeanFactoryAnnotationUtils.qualifiedBeanOfType(beanFactory, PlatformTransactionManager.class, qualifier);
        this.transactionManagerCache.putIfAbsent(qualifier, txManager);
    }
    return txManager;
}
Also used : CallbackPreferringPlatformTransactionManager(cn.taketoday.transaction.support.CallbackPreferringPlatformTransactionManager) TransactionManager(cn.taketoday.transaction.TransactionManager) ReactiveTransactionManager(cn.taketoday.transaction.ReactiveTransactionManager) PlatformTransactionManager(cn.taketoday.transaction.PlatformTransactionManager) CallbackPreferringPlatformTransactionManager(cn.taketoday.transaction.support.CallbackPreferringPlatformTransactionManager) PlatformTransactionManager(cn.taketoday.transaction.PlatformTransactionManager)

Example 2 with TransactionManager

use of cn.taketoday.transaction.TransactionManager in project today-infrastructure by TAKETODAY.

the class TransactionInterceptorTests method determineTransactionManagerDefaultSeveralTimes.

@Test
public void determineTransactionManagerDefaultSeveralTimes() {
    BeanFactory beanFactory = mock(BeanFactory.class);
    TransactionInterceptor ti = simpleTransactionInterceptor(beanFactory);
    PlatformTransactionManager txManager = mock(PlatformTransactionManager.class);
    given(beanFactory.getBean(TransactionManager.class)).willReturn(txManager);
    DefaultTransactionAttribute attribute = new DefaultTransactionAttribute();
    TransactionManager actual = ti.determineTransactionManager(attribute);
    assertThat(actual).isSameAs(txManager);
    // Call again, should be cached
    TransactionManager actual2 = ti.determineTransactionManager(attribute);
    assertThat(actual2).isSameAs(txManager);
    verify(beanFactory, times(1)).getBean(TransactionManager.class);
}
Also used : TransactionManager(cn.taketoday.transaction.TransactionManager) PlatformTransactionManager(cn.taketoday.transaction.PlatformTransactionManager) BeanFactory(cn.taketoday.beans.factory.BeanFactory) PlatformTransactionManager(cn.taketoday.transaction.PlatformTransactionManager) Test(org.junit.jupiter.api.Test)

Example 3 with TransactionManager

use of cn.taketoday.transaction.TransactionManager in project today-infrastructure by TAKETODAY.

the class TransactionInterceptorTests method determineTransactionManagerWithQualifierSeveralTimes.

@Test
public void determineTransactionManagerWithQualifierSeveralTimes() {
    BeanFactory beanFactory = mock(BeanFactory.class);
    TransactionInterceptor ti = simpleTransactionInterceptor(beanFactory);
    PlatformTransactionManager txManager = associateTransactionManager(beanFactory, "fooTransactionManager");
    DefaultTransactionAttribute attribute = new DefaultTransactionAttribute();
    attribute.setQualifier("fooTransactionManager");
    TransactionManager actual = ti.determineTransactionManager(attribute);
    assertThat(actual).isSameAs(txManager);
    // Call again, should be cached
    TransactionManager actual2 = ti.determineTransactionManager(attribute);
    assertThat(actual2).isSameAs(txManager);
    verify(beanFactory, times(1)).containsBean("fooTransactionManager");
    verify(beanFactory, times(1)).getBean("fooTransactionManager", PlatformTransactionManager.class);
}
Also used : TransactionManager(cn.taketoday.transaction.TransactionManager) PlatformTransactionManager(cn.taketoday.transaction.PlatformTransactionManager) BeanFactory(cn.taketoday.beans.factory.BeanFactory) PlatformTransactionManager(cn.taketoday.transaction.PlatformTransactionManager) Test(org.junit.jupiter.api.Test)

Example 4 with TransactionManager

use of cn.taketoday.transaction.TransactionManager in project today-framework by TAKETODAY.

the class TransactionInterceptorTests method determineTransactionManagerWithQualifierSeveralTimes.

@Test
public void determineTransactionManagerWithQualifierSeveralTimes() {
    BeanFactory beanFactory = mock(BeanFactory.class);
    TransactionInterceptor ti = simpleTransactionInterceptor(beanFactory);
    PlatformTransactionManager txManager = associateTransactionManager(beanFactory, "fooTransactionManager");
    DefaultTransactionAttribute attribute = new DefaultTransactionAttribute();
    attribute.setQualifier("fooTransactionManager");
    TransactionManager actual = ti.determineTransactionManager(attribute);
    assertThat(actual).isSameAs(txManager);
    // Call again, should be cached
    TransactionManager actual2 = ti.determineTransactionManager(attribute);
    assertThat(actual2).isSameAs(txManager);
    verify(beanFactory, times(1)).containsBean("fooTransactionManager");
    verify(beanFactory, times(1)).getBean("fooTransactionManager", PlatformTransactionManager.class);
}
Also used : TransactionManager(cn.taketoday.transaction.TransactionManager) PlatformTransactionManager(cn.taketoday.transaction.PlatformTransactionManager) BeanFactory(cn.taketoday.beans.factory.BeanFactory) PlatformTransactionManager(cn.taketoday.transaction.PlatformTransactionManager) Test(org.junit.jupiter.api.Test)

Example 5 with TransactionManager

use of cn.taketoday.transaction.TransactionManager in project today-framework by TAKETODAY.

the class TransactionInterceptorTests method determineTransactionManagerWithBeanNameSeveralTimes.

@Test
public void determineTransactionManagerWithBeanNameSeveralTimes() {
    BeanFactory beanFactory = mock(BeanFactory.class);
    TransactionInterceptor ti = transactionInterceptorWithTransactionManagerName("fooTransactionManager", beanFactory);
    PlatformTransactionManager txManager = associateTransactionManager(beanFactory, "fooTransactionManager");
    DefaultTransactionAttribute attribute = new DefaultTransactionAttribute();
    TransactionManager actual = ti.determineTransactionManager(attribute);
    assertThat(actual).isSameAs(txManager);
    // Call again, should be cached
    TransactionManager actual2 = ti.determineTransactionManager(attribute);
    assertThat(actual2).isSameAs(txManager);
    verify(beanFactory, times(1)).getBean("fooTransactionManager", PlatformTransactionManager.class);
}
Also used : TransactionManager(cn.taketoday.transaction.TransactionManager) PlatformTransactionManager(cn.taketoday.transaction.PlatformTransactionManager) BeanFactory(cn.taketoday.beans.factory.BeanFactory) PlatformTransactionManager(cn.taketoday.transaction.PlatformTransactionManager) Test(org.junit.jupiter.api.Test)

Aggregations

PlatformTransactionManager (cn.taketoday.transaction.PlatformTransactionManager)12 TransactionManager (cn.taketoday.transaction.TransactionManager)12 BeanFactory (cn.taketoday.beans.factory.BeanFactory)10 Test (org.junit.jupiter.api.Test)6 Nullable (cn.taketoday.lang.Nullable)4 ReactiveTransactionManager (cn.taketoday.transaction.ReactiveTransactionManager)4 CallbackPreferringPlatformTransactionManager (cn.taketoday.transaction.support.CallbackPreferringPlatformTransactionManager)4 BeansException (cn.taketoday.beans.BeansException)2 BeanFactoryAware (cn.taketoday.beans.factory.BeanFactoryAware)2 InitializingBean (cn.taketoday.beans.factory.InitializingBean)2 BeanFactoryAnnotationUtils (cn.taketoday.beans.factory.annotation.BeanFactoryAnnotationUtils)2 NamedThreadLocal (cn.taketoday.core.NamedThreadLocal)2 ReactiveAdapter (cn.taketoday.core.ReactiveAdapter)2 ReactiveAdapterRegistry (cn.taketoday.core.ReactiveAdapterRegistry)2 Assert (cn.taketoday.lang.Assert)2 Logger (cn.taketoday.logging.Logger)2 LoggerFactory (cn.taketoday.logging.LoggerFactory)2 NoTransactionException (cn.taketoday.transaction.NoTransactionException)2 ReactiveTransaction (cn.taketoday.transaction.ReactiveTransaction)2 TransactionStatus (cn.taketoday.transaction.TransactionStatus)2