TransactionInterceptor is able to serialize "transactionManagerBeanName" as well (SPR-6680)
git-svn-id: https://src.springframework.org/svn/spring-framework/trunk@2889 50f2f4bb-b051-0410-bef5-90022cba6387
This commit is contained in:
parent
0bdaa0732b
commit
9991a013fd
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2009 the original author or authors.
|
* Copyright 2002-2010 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|
@ -139,6 +139,13 @@ public abstract class TransactionAspectSupport implements BeanFactoryAware, Init
|
||||||
this.transactionManagerBeanName = transactionManagerBeanName;
|
this.transactionManagerBeanName = transactionManagerBeanName;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return the name of the default transaction manager bean.
|
||||||
|
*/
|
||||||
|
protected final String getTransactionManagerBeanName() {
|
||||||
|
return this.transactionManagerBeanName;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Specify the target transaction manager.
|
* Specify the target transaction manager.
|
||||||
*/
|
*/
|
||||||
|
|
@ -210,6 +217,13 @@ public abstract class TransactionAspectSupport implements BeanFactoryAware, Init
|
||||||
this.beanFactory = beanFactory;
|
this.beanFactory = beanFactory;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return the BeanFactory to use for retrieving PlatformTransactionManager beans.
|
||||||
|
*/
|
||||||
|
protected final BeanFactory getBeanFactory() {
|
||||||
|
return this.beanFactory;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check that required properties were set.
|
* Check that required properties were set.
|
||||||
*/
|
*/
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2009 the original author or authors.
|
* Copyright 2002-2010 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|
@ -25,6 +25,7 @@ import java.util.Properties;
|
||||||
import org.aopalliance.intercept.MethodInterceptor;
|
import org.aopalliance.intercept.MethodInterceptor;
|
||||||
import org.aopalliance.intercept.MethodInvocation;
|
import org.aopalliance.intercept.MethodInvocation;
|
||||||
|
|
||||||
|
import org.springframework.beans.factory.BeanFactory;
|
||||||
import org.springframework.transaction.PlatformTransactionManager;
|
import org.springframework.transaction.PlatformTransactionManager;
|
||||||
import org.springframework.transaction.TransactionStatus;
|
import org.springframework.transaction.TransactionStatus;
|
||||||
import org.springframework.transaction.support.CallbackPreferringPlatformTransactionManager;
|
import org.springframework.transaction.support.CallbackPreferringPlatformTransactionManager;
|
||||||
|
|
@ -173,8 +174,10 @@ public class TransactionInterceptor extends TransactionAspectSupport implements
|
||||||
oos.defaultWriteObject();
|
oos.defaultWriteObject();
|
||||||
|
|
||||||
// Deserialize superclass fields.
|
// Deserialize superclass fields.
|
||||||
|
oos.writeObject(getTransactionManagerBeanName());
|
||||||
oos.writeObject(getTransactionManager());
|
oos.writeObject(getTransactionManager());
|
||||||
oos.writeObject(getTransactionAttributeSource());
|
oos.writeObject(getTransactionAttributeSource());
|
||||||
|
oos.writeObject(getBeanFactory());
|
||||||
}
|
}
|
||||||
|
|
||||||
private void readObject(ObjectInputStream ois) throws IOException, ClassNotFoundException {
|
private void readObject(ObjectInputStream ois) throws IOException, ClassNotFoundException {
|
||||||
|
|
@ -184,8 +187,10 @@ public class TransactionInterceptor extends TransactionAspectSupport implements
|
||||||
// Serialize all relevant superclass fields.
|
// Serialize all relevant superclass fields.
|
||||||
// Superclass can't implement Serializable because it also serves as base class
|
// Superclass can't implement Serializable because it also serves as base class
|
||||||
// for AspectJ aspects (which are not allowed to implement Serializable)!
|
// for AspectJ aspects (which are not allowed to implement Serializable)!
|
||||||
|
setTransactionManagerBeanName((String) ois.readObject());
|
||||||
setTransactionManager((PlatformTransactionManager) ois.readObject());
|
setTransactionManager((PlatformTransactionManager) ois.readObject());
|
||||||
setTransactionAttributeSource((TransactionAttributeSource) ois.readObject());
|
setTransactionAttributeSource((TransactionAttributeSource) ois.readObject());
|
||||||
|
setBeanFactory((BeanFactory) ois.readObject());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2007 the original author or authors.
|
* Copyright 2002-2010 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|
@ -16,6 +16,8 @@
|
||||||
|
|
||||||
package org.springframework.transaction.config;
|
package org.springframework.transaction.config;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
|
||||||
import junit.framework.TestCase;
|
import junit.framework.TestCase;
|
||||||
import org.aopalliance.intercept.MethodInterceptor;
|
import org.aopalliance.intercept.MethodInterceptor;
|
||||||
import org.aopalliance.intercept.MethodInvocation;
|
import org.aopalliance.intercept.MethodInvocation;
|
||||||
|
|
@ -24,6 +26,7 @@ import org.springframework.aop.support.AopUtils;
|
||||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||||
import org.springframework.transaction.CallCountingTransactionManager;
|
import org.springframework.transaction.CallCountingTransactionManager;
|
||||||
import org.springframework.transaction.support.TransactionSynchronizationManager;
|
import org.springframework.transaction.support.TransactionSynchronizationManager;
|
||||||
|
import org.springframework.util.SerializationTestUtils;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Rob Harrop
|
* @author Rob Harrop
|
||||||
|
|
@ -51,14 +54,31 @@ public class AnnotationDrivenTests extends TestCase {
|
||||||
assertEquals(2, tm2.commits);
|
assertEquals(2, tm2.commits);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void testSerializableWithPreviousUsage() throws Exception {
|
||||||
|
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("annotationDrivenProxyTargetClassTests.xml", getClass());
|
||||||
|
TransactionalService service = context.getBean("service", TransactionalService.class);
|
||||||
|
service.setSomething("someName");
|
||||||
|
service = (TransactionalService) SerializationTestUtils.serializeAndDeserialize(service);
|
||||||
|
service.setSomething("someName");
|
||||||
|
}
|
||||||
|
|
||||||
public static class TransactionCheckingInterceptor implements MethodInterceptor {
|
public void testSerializableWithoutPreviousUsage() throws Exception {
|
||||||
|
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("annotationDrivenProxyTargetClassTests.xml", getClass());
|
||||||
|
TransactionalService service = context.getBean("service", TransactionalService.class);
|
||||||
|
service = (TransactionalService) SerializationTestUtils.serializeAndDeserialize(service);
|
||||||
|
service.setSomething("someName");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static class TransactionCheckingInterceptor implements MethodInterceptor, Serializable {
|
||||||
|
|
||||||
public Object invoke(MethodInvocation methodInvocation) throws Throwable {
|
public Object invoke(MethodInvocation methodInvocation) throws Throwable {
|
||||||
if (methodInvocation.getMethod().getName().equals("setSomething")) {
|
if (methodInvocation.getMethod().getName().equals("setSomething")) {
|
||||||
|
assertTrue(TransactionSynchronizationManager.isActualTransactionActive());
|
||||||
assertTrue(TransactionSynchronizationManager.isSynchronizationActive());
|
assertTrue(TransactionSynchronizationManager.isSynchronizationActive());
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
assertFalse(TransactionSynchronizationManager.isActualTransactionActive());
|
||||||
assertFalse(TransactionSynchronizationManager.isSynchronizationActive());
|
assertFalse(TransactionSynchronizationManager.isSynchronizationActive());
|
||||||
}
|
}
|
||||||
return methodInvocation.proceed();
|
return methodInvocation.proceed();
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2009 the original author or authors.
|
* Copyright 2002-2010 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|
@ -16,14 +16,15 @@
|
||||||
|
|
||||||
package org.springframework.transaction.config;
|
package org.springframework.transaction.config;
|
||||||
|
|
||||||
import org.springframework.beans.factory.BeanNameAware;
|
import java.io.Serializable;
|
||||||
|
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Rob Harrop
|
* @author Rob Harrop
|
||||||
* @author Juergen Hoeller
|
* @author Juergen Hoeller
|
||||||
*/
|
*/
|
||||||
public class TransactionalService {
|
public class TransactionalService implements Serializable {
|
||||||
|
|
||||||
@Transactional("synch")
|
@Transactional("synch")
|
||||||
public void setSomething(String name) {
|
public void setSomething(String name) {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue