1 16 17 package org.springframework.transaction.interceptor; 18 19 import java.util.Properties ; 20 21 import org.springframework.aop.Pointcut; 22 import org.springframework.aop.framework.AbstractSingletonProxyFactoryBean; 23 import org.springframework.aop.support.DefaultPointcutAdvisor; 24 import org.springframework.beans.factory.BeanFactory; 25 import org.springframework.beans.factory.BeanFactoryAware; 26 import org.springframework.beans.factory.BeanFactoryUtils; 27 import org.springframework.beans.factory.FactoryBean; 28 import org.springframework.beans.factory.ListableBeanFactory; 29 import org.springframework.transaction.PlatformTransactionManager; 30 31 105 public class TransactionProxyFactoryBean extends AbstractSingletonProxyFactoryBean 106 implements FactoryBean, BeanFactoryAware { 107 108 private final TransactionInterceptor transactionInterceptor = new TransactionInterceptor(); 109 110 private Pointcut pointcut; 111 112 113 118 public void setTransactionManager(PlatformTransactionManager transactionManager) { 119 this.transactionInterceptor.setTransactionManager(transactionManager); 120 } 121 122 135 public void setTransactionAttributes(Properties transactionAttributes) { 136 this.transactionInterceptor.setTransactionAttributes(transactionAttributes); 137 } 138 139 151 public void setTransactionAttributeSource(TransactionAttributeSource transactionAttributeSource) { 152 this.transactionInterceptor.setTransactionAttributeSource(transactionAttributeSource); 153 } 154 155 162 public void setPointcut(Pointcut pointcut) { 163 this.pointcut = pointcut; 164 } 165 166 173 public void setBeanFactory(BeanFactory beanFactory) { 174 if (this.transactionInterceptor.getTransactionManager() == null && 175 beanFactory instanceof ListableBeanFactory) { 176 ListableBeanFactory lbf = (ListableBeanFactory) beanFactory; 177 PlatformTransactionManager ptm = (PlatformTransactionManager) 178 BeanFactoryUtils.beanOfTypeIncludingAncestors(lbf, PlatformTransactionManager.class); 179 this.transactionInterceptor.setTransactionManager(ptm); 180 } 181 } 182 183 184 187 protected Object createMainInterceptor() { 188 this.transactionInterceptor.afterPropertiesSet(); 189 if (this.pointcut != null) { 190 return new DefaultPointcutAdvisor(this.pointcut, this.transactionInterceptor); 191 } 192 else { 193 return new TransactionAttributeSourceAdvisor(this.transactionInterceptor); 195 } 196 } 197 198 } 199 | Popular Tags |