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;
}
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);
}
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);
}
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);
}
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);
}
Aggregations