本文整理汇总了Java中org.springframework.transaction.interceptor.TransactionInterceptor类的典型用法代码示例。如果您正苦于以下问题:Java TransactionInterceptor类的具体用法?Java TransactionInterceptor怎么用?Java TransactionInterceptor使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
TransactionInterceptor类属于org.springframework.transaction.interceptor包,在下文中一共展示了TransactionInterceptor类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: defaultPointcutAdvisor
import org.springframework.transaction.interceptor.TransactionInterceptor; //导入依赖的package包/类
/**
* 织入
*/
@Bean
public DefaultPointcutAdvisor defaultPointcutAdvisor(TransactionInterceptor interceptor) {
// 切入点
AspectJExpressionPointcut expression = new AspectJExpressionPointcut();
expression.setExpression("execution(* org.sj.alexa.service.tx.I*Service.*(..))");
return new DefaultPointcutAdvisor(expression, interceptor);
}
示例2: serializable
import org.springframework.transaction.interceptor.TransactionInterceptor; //导入依赖的package包/类
@Test
public void serializable() throws Exception {
TestBean1 tb = new TestBean1();
CallCountingTransactionManager ptm = new CallCountingTransactionManager();
AnnotationTransactionAttributeSource tas = new AnnotationTransactionAttributeSource();
TransactionInterceptor ti = new TransactionInterceptor(ptm, tas);
ProxyFactory proxyFactory = new ProxyFactory();
proxyFactory.setInterfaces(new Class[] {ITestBean.class});
proxyFactory.addAdvice(ti);
proxyFactory.setTarget(tb);
ITestBean proxy = (ITestBean) proxyFactory.getProxy();
proxy.getAge();
assertEquals(1, ptm.commits);
ITestBean serializedProxy = (ITestBean) SerializationTestUtils.serializeAndDeserialize(proxy);
serializedProxy.getAge();
Advised advised = (Advised) serializedProxy;
TransactionInterceptor serializedTi = (TransactionInterceptor) advised.getAdvisors()[0].getAdvice();
CallCountingTransactionManager serializedPtm =
(CallCountingTransactionManager) serializedTi.getTransactionManager();
assertEquals(2, serializedPtm.commits);
}
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:24,代码来源:AnnotationTransactionAttributeSourceTests.java
示例3: before
import org.springframework.transaction.interceptor.TransactionInterceptor; //导入依赖的package包/类
@Override
public void before(Method method, Object[] args, Object target) throws Throwable {
// do transaction checks
if (requireTransactionContext) {
TransactionInterceptor.currentTransactionStatus();
}
else {
try {
TransactionInterceptor.currentTransactionStatus();
throw new RuntimeException("Shouldn't have a transaction");
}
catch (NoTransactionException ex) {
// this is Ok
}
}
super.before(method, args, target);
}
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:18,代码来源:AdvisorAutoProxyCreatorIntegrationTests.java
示例4: txProxiedTokenServices
import org.springframework.transaction.interceptor.TransactionInterceptor; //导入依赖的package包/类
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);
}
示例5: testSerializable
import org.springframework.transaction.interceptor.TransactionInterceptor; //导入依赖的package包/类
@Test
public void testSerializable() throws Exception {
TestBean1 tb = new TestBean1();
CallCountingTransactionManager ptm = new CallCountingTransactionManager();
AnnotationTransactionAttributeSource tas = new AnnotationTransactionAttributeSource();
TransactionInterceptor ti = new TransactionInterceptor(ptm, tas);
ProxyFactory proxyFactory = new ProxyFactory();
proxyFactory.setInterfaces(new Class[] {ITestBean.class});
proxyFactory.addAdvice(ti);
proxyFactory.setTarget(tb);
ITestBean proxy = (ITestBean) proxyFactory.getProxy();
proxy.getAge();
assertEquals(1, ptm.commits);
ITestBean serializedProxy = (ITestBean) SerializationTestUtils.serializeAndDeserialize(proxy);
serializedProxy.getAge();
Advised advised = (Advised) serializedProxy;
TransactionInterceptor serializedTi = (TransactionInterceptor) advised.getAdvisors()[0].getAdvice();
CallCountingTransactionManager serializedPtm =
(CallCountingTransactionManager) serializedTi.getTransactionManager();
assertEquals(2, serializedPtm.commits);
}
示例6: transactionInterceptor
import org.springframework.transaction.interceptor.TransactionInterceptor; //导入依赖的package包/类
/**
* 定义事务切入点,方法名称就是Bean名称
*/
@Bean
public TransactionInterceptor transactionInterceptor(PlatformTransactionManager manager) {
Properties props = new Properties();
props.setProperty("save*", "PROPAGATION_REQUIRED,-java.lang.RuntimeException");
props.setProperty("update*", "PROPAGATION_REQUIRED,-java.lang.RuntimeException");
props.setProperty("remove*", "PROPAGATION_REQUIRED,-java.lang.RuntimeException");
props.setProperty("*", "PROPAGATION_NOT_SUPPORTED,readOnly");
return new TransactionInterceptor(manager, props);
}
示例7: transactionInterceptor
import org.springframework.transaction.interceptor.TransactionInterceptor; //导入依赖的package包/类
@Bean
@Role(BeanDefinition.ROLE_INFRASTRUCTURE)
public TransactionInterceptor transactionInterceptor() {
TransactionInterceptor interceptor = new TransactionInterceptor();
interceptor.setTransactionAttributeSource(transactionAttributeSource());
if (this.txManager != null) {
interceptor.setTransactionManager(this.txManager);
}
return interceptor;
}
示例8: configureAutoProxyCreator
import org.springframework.transaction.interceptor.TransactionInterceptor; //导入依赖的package包/类
public static void configureAutoProxyCreator(Element element, ParserContext parserContext) {
AopNamespaceUtils.registerAutoProxyCreatorIfNecessary(parserContext, element);
String txAdvisorBeanName = TransactionManagementConfigUtils.TRANSACTION_ADVISOR_BEAN_NAME;
if (!parserContext.getRegistry().containsBeanDefinition(txAdvisorBeanName)) {
Object eleSource = parserContext.extractSource(element);
// Create the TransactionAttributeSource definition.
RootBeanDefinition sourceDef = new RootBeanDefinition(
"org.springframework.transaction.annotation.AnnotationTransactionAttributeSource");
sourceDef.setSource(eleSource);
sourceDef.setRole(BeanDefinition.ROLE_INFRASTRUCTURE);
String sourceName = parserContext.getReaderContext().registerWithGeneratedName(sourceDef);
// Create the TransactionInterceptor definition.
RootBeanDefinition interceptorDef = new RootBeanDefinition(TransactionInterceptor.class);
interceptorDef.setSource(eleSource);
interceptorDef.setRole(BeanDefinition.ROLE_INFRASTRUCTURE);
registerTransactionManager(element, interceptorDef);
interceptorDef.getPropertyValues().add("transactionAttributeSource", new RuntimeBeanReference(sourceName));
String interceptorName = parserContext.getReaderContext().registerWithGeneratedName(interceptorDef);
// Create the TransactionAttributeSourceAdvisor definition.
RootBeanDefinition advisorDef = new RootBeanDefinition(BeanFactoryTransactionAttributeSourceAdvisor.class);
advisorDef.setSource(eleSource);
advisorDef.setRole(BeanDefinition.ROLE_INFRASTRUCTURE);
advisorDef.getPropertyValues().add("transactionAttributeSource", new RuntimeBeanReference(sourceName));
advisorDef.getPropertyValues().add("adviceBeanName", interceptorName);
if (element.hasAttribute("order")) {
advisorDef.getPropertyValues().add("order", element.getAttribute("order"));
}
parserContext.getRegistry().registerBeanDefinition(txAdvisorBeanName, advisorDef);
CompositeComponentDefinition compositeDef = new CompositeComponentDefinition(element.getTagName(), eleSource);
compositeDef.addNestedComponent(new BeanComponentDefinition(sourceDef, sourceName));
compositeDef.addNestedComponent(new BeanComponentDefinition(interceptorDef, interceptorName));
compositeDef.addNestedComponent(new BeanComponentDefinition(advisorDef, txAdvisorBeanName));
parserContext.registerComponent(compositeDef);
}
}
示例9: transactionInterceptor
import org.springframework.transaction.interceptor.TransactionInterceptor; //导入依赖的package包/类
@Bean
public TransactionInterceptor transactionInterceptor(PlatformTransactionManager transactionManager) {
Properties attributes = new Properties();
attributes.setProperty("get*", "PROPAGATION_REQUIRED");
attributes.setProperty("put*", "PROPAGATION_REQUIRED");
attributes.setProperty("post*", "PROPAGATION_REQUIRED");
attributes.setProperty("delete*", "PROPAGATION_REQUIRED");
return new TransactionInterceptor(transactionManager, attributes);
}
示例10: getAdvisor
import org.springframework.transaction.interceptor.TransactionInterceptor; //导入依赖的package包/类
@Bean(name="txAdvice")
public TransactionInterceptor getAdvisor() throws Exception{
Properties properties = new Properties();
properties.setProperty("*", "PROPAGATION_REQUIRED,-Exception");
TransactionInterceptor tsi = new TransactionInterceptor(transactionManager,properties);
return tsi;
}
示例11: setTxAdvice
import org.springframework.transaction.interceptor.TransactionInterceptor; //导入依赖的package包/类
/**
* 读取事务管理中的策略
*
* @param txAdvice
* @throws Exception
*/
@SuppressWarnings("unchecked")
public void setTxAdvice(TransactionInterceptor txAdvice) throws Exception {
if (txAdvice == null) {
// 没有配置事务管理策略
return;
}
// 从txAdvice获取到策略配置信息
TransactionAttributeSource transactionAttributeSource = txAdvice.getTransactionAttributeSource();
if (!(transactionAttributeSource instanceof NameMatchTransactionAttributeSource)) {
return;
}
// 使用反射技术获取到NameMatchTransactionAttributeSource对象中的nameMap属性值
NameMatchTransactionAttributeSource matchTransactionAttributeSource = (NameMatchTransactionAttributeSource) transactionAttributeSource;
Field nameMapField = ReflectionUtils.findField(NameMatchTransactionAttributeSource.class, "nameMap");
nameMapField.setAccessible(true); // 设置该字段可访问
// 获取nameMap的值
Map<String, TransactionAttribute> map = (Map<String, TransactionAttribute>) nameMapField.get(matchTransactionAttributeSource);
// 遍历nameMap
for (Map.Entry<String, TransactionAttribute> entry : map.entrySet()) {
if (!entry.getValue().isReadOnly()) {// 判断之后定义了ReadOnly的策略才加入到slaveMethodPattern
continue;
}
slaveMethodPattern.add(entry.getKey());
}
}
示例12: rollbackRules
import org.springframework.transaction.interceptor.TransactionInterceptor; //导入依赖的package包/类
@Test
public void rollbackRules() {
TransactionInterceptor txInterceptor = (TransactionInterceptor) context.getBean("txRollbackAdvice");
TransactionAttributeSource txAttrSource = txInterceptor.getTransactionAttributeSource();
TransactionAttribute txAttr = txAttrSource.getTransactionAttribute(getAgeMethod,ITestBean.class);
assertTrue("should be configured to rollback on Exception",txAttr.rollbackOn(new Exception()));
txAttr = txAttrSource.getTransactionAttribute(setAgeMethod, ITestBean.class);
assertFalse("should not rollback on RuntimeException",txAttr.rollbackOn(new RuntimeException()));
}
示例13: evaluateNoteModificationResult
import org.springframework.transaction.interceptor.TransactionInterceptor; //导入依赖的package包/类
/**
* Evaluate the result of the note creation operation and send appropriate feedback messages.
*
* @param result
* the note creation result
* @param sender
* the user that sent the processed enauk
* @param blogId
* the ID of the target blog
* @param creatorId
* Id of the messages author.
*/
private void evaluateNoteModificationResult(NoteModificationResult result, User sender,
Long blogId, Long creatorId) {
String alias = userManagement.findUserByUserId(creatorId).getAlias();
result.getUserNotificationResult().getUnresolvableUsers().remove(alias);
result.getUserNotificationResult().getUninformableUsers().remove(alias);
if (result.getStatus().equals(NoteModificationStatus.SUCCESS)) {
if (result.getUserNotificationResult().getUnresolvableUsers().size() != 0
|| result.getUserNotificationResult().getUninformableUsers().size() != 0
|| result.getUnresolvableBlogs().size() != 0
|| result.getUnwritableBlogs().size() != 0) {
sendErrorMailMessage(new WarningMailMessage(sender, result
.getUserNotificationResult().getUnresolvableUsers(), result
.getUserNotificationResult().getUninformableUsers(),
result.getUnresolvableBlogs(), result.getUnwritableBlogs(),
getBlogTitle(blogId), result.isDirect()));
}
} else {
if (TransactionInterceptor.currentTransactionStatus().isRollbackOnly()) {
// explicitly mark this transaction as rollback-only because inner transaction
// is marked too
TransactionInterceptor.currentTransactionStatus().setRollbackOnly();
}
String errorMessage = CreateBlogPostHelper.getFeedbackMessageAfterModification(result,
sender.getLanguageLocale());
sendErrorMailMessage(new GenericErrorMailMessage(sender, errorMessage,
getBlogTitle(blogId)));
}
}
示例14: configure
import org.springframework.transaction.interceptor.TransactionInterceptor; //导入依赖的package包/类
@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);
}
示例15: testAutoConfigureComponents
import org.springframework.transaction.interceptor.TransactionInterceptor; //导入依赖的package包/类
@Test
public void testAutoConfigureComponents() {
// @AutoConfigureMybatis
this.applicationContext.getBean(JdbcTemplate.class);
this.applicationContext.getBean(NamedParameterJdbcTemplate.class);
this.applicationContext.getBean(DataSourceTransactionManager.class);
this.applicationContext.getBean(TransactionInterceptor.class);
// @AutoConfigureCache
this.applicationContext.getBean(CacheManager.class);
this.applicationContext.getBean(CacheInterceptor.class);
}