private DefaultTokenServices txProxiedTokenServices(DefaultTokenServices tokenServices, DataSource dataSource) { AnnotationTransactionAttributeSource attrSource = new AnnotationTransactionAttributeSource(); DataSourceTransactionManager txManager = new DataSourceTransactionManager(dataSource); TransactionInterceptor txInterceptor = transactionInterceptor(attrSource, txManager); BeanFactoryTransactionAttributeSourceAdvisor txAdvisor = transactionAdvisor(attrSource, txInterceptor); ClassLoader classLoader = ClassUtils.getDefaultClassLoader(); ProxyFactory proxyFactory = new ProxyFactory(tokenServices); proxyFactory.addAdvice(txInterceptor); proxyFactory.addAdvisor(txAdvisor); proxyFactory.setInterfaces( ClassUtils.getAllInterfacesForClass( new SingletonTargetSource(tokenServices).getTargetClass(), classLoader)); return (DefaultTokenServices) proxyFactory.getProxy(classLoader); }
public TLETransactionInterceptor(AnnotationTransactionAttributeSource attributes, Provider<TLETransactionManager> managerProvider, String factoryName, boolean system) { this.attributes = attributes; this.factoryName = factoryName; this.system = system; this.managerProvider = managerProvider; }
/** * Note: resolution does not occur. Thus we can't make a class transactional if * it implements a transactionally annotated interface. This behaviour could only * be changed in AbstractFallbackTransactionAttributeSource in Spring proper. */ public void testDoesNotResolveTxAnnotationOnMethodFromClassImplementingAnnotatedInterface() throws Exception { AnnotationTransactionAttributeSource atas = new AnnotationTransactionAttributeSource(); Method m = ImplementsAnnotatedInterface.class.getMethod("echo", Throwable.class); TransactionAttribute ta = atas.getTransactionAttribute(m, ImplementsAnnotatedInterface.class); assertNull(ta); }
public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException { String[] beanNameArray = beanFactory.getBeanDefinitionNames(); for (int i = 0; i < beanNameArray.length; i++) { String beanName = beanNameArray[i]; BeanDefinition beanDef = beanFactory.getBeanDefinition(beanName); String beanClassName = beanDef.getBeanClassName(); if (org.springframework.transaction.interceptor.TransactionProxyFactoryBean.class.getName().equals(beanClassName)) { throw new FatalBeanException(String.format( "Declaring transactions by configuration is not supported yet, please use annotations to declare transactions(beanId= %s).", beanName)); } if (org.springframework.transaction.interceptor.TransactionInterceptor.class.getName().equals(beanClassName)) { boolean errorExists = true; MutablePropertyValues mpv = beanDef.getPropertyValues(); PropertyValue pv = mpv.getPropertyValue("transactionAttributeSource"); Object value = pv == null ? null : pv.getValue(); if (value != null && RuntimeBeanReference.class.isInstance(value)) { RuntimeBeanReference reference = (RuntimeBeanReference) value; BeanDefinition refBeanDef = beanFactory.getBeanDefinition(reference.getBeanName()); String refBeanClassName = refBeanDef.getBeanClassName(); errorExists = AnnotationTransactionAttributeSource.class.getName().equals(refBeanClassName) == false; } if (errorExists) { throw new FatalBeanException(String.format( "Declaring transactions by configuration is not supported yet, please use annotations to declare transactions(beanId= %s).", beanName)); } } } }
@Override protected void configure() { // TransactionManager PlatformTransactionManager transactionManager = new DataSourceTransactionManager(dataSource); // TransactionInterceptor TransactionInterceptor transactionInterceptor = new TransactionInterceptor(transactionManager, new AnnotationTransactionAttributeSource(false)); bindInterceptor(Matchers.any(), Matchers.annotatedWith(Transactional.class), transactionInterceptor); bind(PlatformTransactionManager.class).toInstance(transactionManager); }
private BeanFactoryTransactionAttributeSourceAdvisor transactionAdvisor( AnnotationTransactionAttributeSource source, TransactionInterceptor interceptor) { BeanFactoryTransactionAttributeSourceAdvisor advisor = new BeanFactoryTransactionAttributeSourceAdvisor(); advisor.setTransactionAttributeSource(source); advisor.setAdvice(interceptor); return advisor; }
private TransactionInterceptor transactionInterceptor( AnnotationTransactionAttributeSource source, PlatformTransactionManager txManager) { TransactionInterceptor interceptor = new TransactionInterceptor(); interceptor.setTransactionAttributeSource(source); interceptor.setTransactionManager(txManager); return interceptor; }
@Override protected void configure() { // TransactionManager bind(PlatformTransactionManager.class).toProvider(getPlatformTransactionManagerType()).in(Singleton.class); // TransactionInterceptor final TransactionInterceptor transactionInterceptor = new TransactionInterceptorEx(getProvider(PlatformTransactionManager.class), new AnnotationTransactionAttributeSource(false)); bindInterceptor(Matchers.any(), Matchers.annotatedWith(Transactional.class), transactionInterceptor); }
@Bean public TransactionInterceptor transactionInterceptorRealm() { return new TransactionInterceptor(transactionManagerRealm(), new AnnotationTransactionAttributeSource()); }
@Bean public TransactionInterceptor transactionInterceptorWorld() { return new TransactionInterceptor(transactionManagerWorld(), new AnnotationTransactionAttributeSource()); }
@Bean public TransactionInterceptor transactionInterceptorAuth() { return new TransactionInterceptor(transactionManagerAuth(), new AnnotationTransactionAttributeSource()); }
/** * Note: resolution does not occur. Thus we can't make a class transactional if * it implements a transactionally annotated interface. This behaviour could only * be changed in AbstractFallbackTransactionAttributeSource in Spring proper. * @throws SecurityException * @throws NoSuchMethodException */ public void testDoesNotResolveTxAnnotationOnMethodFromClassImplementingAnnotatedInterface() throws SecurityException, NoSuchMethodException { AnnotationTransactionAttributeSource atas = new AnnotationTransactionAttributeSource(); Method m = ImplementsAnnotatedInterface.class.getMethod("echo", Throwable.class); TransactionAttribute ta = atas.getTransactionAttribute(m, ImplementsAnnotatedInterface.class); assertNull(ta); }
/** * Sets the annotationTransactionAttributeSource attribute value. * * @param annotationTransactionAttributeSource The annotationTransactionAttributeSource to set. */ public void setAnnotationTransactionAttributeSource(AnnotationTransactionAttributeSource annotationTransactionAttributeSource) { this.annotationTransactionAttributeSource = annotationTransactionAttributeSource; }