org.springframework.transaction.interceptor
Class TransactionProxyFactoryBean

java.lang.Object
  extended byorg.springframework.aop.framework.ProxyConfig
      extended byorg.springframework.transaction.interceptor.TransactionProxyFactoryBean
All Implemented Interfaces:
FactoryBean, InitializingBean

public class TransactionProxyFactoryBean
extends ProxyConfig
implements FactoryBean, InitializingBean

Proxy factory bean for simplified declarative transaction handling. Alternative to the standard AOP ProxyFactoryBean with a TransactionInterceptor.

This class is intended to cover the typical case of declarative transaction demarcation: namely, wrapping a (singleton) target object with a transactional proxy, proxying all the interfaces that the target implements.

In contrast to TransactionInterceptor, the transaction attributes are specified as properties, with method names as keys and transaction attribute descriptors as values. Method names are always applied to the target class.

Internally, a TransactionInterceptor instance is used, but the user of this class does not have to care. Optionally, a MethodPointcut can be specified to cause conditional invocation of the underlying TransactionInterceptor.

The preInterceptors and postInterceptors properties can be set to add additional interceptors to the mix, like PerformanceMonitorInterceptor or HibernateInterceptor/JdoInterceptor.

Since:
21.08.2003
Version:
$Id: TransactionProxyFactoryBean.java,v 1.27 2004/04/22 07:58:25 jhoeller Exp $
Author:
Juergen Hoeller, Dmitriy Kopylenko, Rod Johnson
See Also:
ProxyFactoryBean, TransactionInterceptor, setTransactionAttributes(java.util.Properties)

Field Summary
 
Fields inherited from class org.springframework.aop.framework.ProxyConfig
exposeProxy, logger
 
Constructor Summary
TransactionProxyFactoryBean()
           
 
Method Summary
 void afterPropertiesSet()
          Invoked by a BeanFactory after it has set all bean properties supplied (and satisfied BeanFactoryAware and ApplicationContextAware).
protected  TargetSource createTargetSource(java.lang.Object target)
          Set the target or TargetSource.
 java.lang.Object getObject()
          Return an instance (possibly shared or independent) of the object managed by this factory.
 java.lang.Class getObjectType()
          Return the type of object that this FactoryBean creates, or null if not known in advance.
 boolean isSingleton()
          Is the bean managed by this factory a singleton or a prototype?
 void setPointcut(Pointcut pointcut)
          Set a pointcut, i.e a bean that can cause conditional invocation of the TransactionInterceptor depending on method and attributes passed.
 void setPostInterceptors(java.lang.Object[] preInterceptors)
          Set additional interceptors (or advisors) to be applied after the implicit transaction interceptor, e.g.
 void setPreInterceptors(java.lang.Object[] preInterceptors)
          Set additional interceptors (or advisors) to be applied before the implicit transaction interceptor, e.g.
 void setProxyInterfaces(java.lang.String[] interfaceNames)
          Optional: You only need to set this property to filter the set of interfaces being proxied (default is to pick up all interfaces on the target), or if providing a custom invoker interceptor instead of a target.
 void setTarget(java.lang.Object target)
          Set the target object, i.e. the bean to be wrapped with a transactional proxy.
 void setTransactionAttributes(java.util.Properties transactionAttributes)
          Set properties with method names as keys and transaction attribute descriptors (parsed via TransactionAttributeEditor) as values: e.g. key = "myMethod", value = "PROPAGATION_REQUIRED,readOnly".
 void setTransactionAttributeSource(TransactionAttributeSource transactionAttributeSource)
          Set the transaction attribute source which is used to find transaction attributes.
 void setTransactionManager(PlatformTransactionManager transactionManager)
          Set the transaction manager.
 
Methods inherited from class org.springframework.aop.framework.ProxyConfig
copyFrom, getAopProxyFactory, getExposeProxy, getOptimize, getProxyTargetClass, isFrozen, setAopProxyFactory, setExposeProxy, setFrozen, setOptimize, setProxyTargetClass, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

TransactionProxyFactoryBean

public TransactionProxyFactoryBean()
Method Detail

setTransactionManager

public void setTransactionManager(PlatformTransactionManager transactionManager)
Set the transaction manager. This will perform actual transaction management: This class is just a way of invoking it.


setTarget

public void setTarget(java.lang.Object target)
Set the target object, i.e. the bean to be wrapped with a transactional proxy. The target may be any object, in which case a SingletonTargetSource will be created. If it is a TargetSource, no wrapper TargetSource is created: This enables the use of a pooling or prototype TargetSource etc.

See Also:
TargetSource, SingletonTargetSource

setProxyInterfaces

public void setProxyInterfaces(java.lang.String[] interfaceNames)
                        throws org.aopalliance.aop.AspectException,
                               java.lang.ClassNotFoundException
Optional: You only need to set this property to filter the set of interfaces being proxied (default is to pick up all interfaces on the target), or if providing a custom invoker interceptor instead of a target.

If left null (the default), the AOP infrastructure works out which interfaces need proxying.

Throws:
org.aopalliance.aop.AspectException
java.lang.ClassNotFoundException

setTransactionAttributeSource

public void setTransactionAttributeSource(TransactionAttributeSource transactionAttributeSource)
Set the transaction attribute source which is used to find transaction attributes. If specifying a String property value, a PropertyEditor will create a MethodMapTransactionAttributeSource from the value.

See Also:
setTransactionAttributes(java.util.Properties), TransactionAttributeSourceEditor, MethodMapTransactionAttributeSource, NameMatchTransactionAttributeSource

setTransactionAttributes

public void setTransactionAttributes(java.util.Properties transactionAttributes)
Set properties with method names as keys and transaction attribute descriptors (parsed via TransactionAttributeEditor) as values: e.g. key = "myMethod", value = "PROPAGATION_REQUIRED,readOnly".

Note: Method names are always applied to the target class, no matter if defined in an interface or the class itself.

Internally, a NameMatchTransactionAttributeSource will be created from the given properties.

See Also:
setTransactionAttributeSource(org.springframework.transaction.interceptor.TransactionAttributeSource), TransactionAttributeEditor, NameMatchTransactionAttributeSource

setPointcut

public void setPointcut(Pointcut pointcut)
Set a pointcut, i.e a bean that can cause conditional invocation of the TransactionInterceptor depending on method and attributes passed. Note: Additional interceptors are always invoked.

See Also:
setPreInterceptors(java.lang.Object[]), setPostInterceptors(java.lang.Object[])

setPreInterceptors

public void setPreInterceptors(java.lang.Object[] preInterceptors)
Set additional interceptors (or advisors) to be applied before the implicit transaction interceptor, e.g. PerformanceMonitorInterceptor.

See Also:
PerformanceMonitorInterceptor

setPostInterceptors

public void setPostInterceptors(java.lang.Object[] preInterceptors)
Set additional interceptors (or advisors) to be applied after the implicit transaction interceptor, e.g. HibernateInterceptors for eagerly binding Sessions to the current thread when using JTA.

Note that this is just necessary if you rely on those interceptors in general: HibernateTemplate and JdoTemplate work nicely with JtaTransactionManager through implicit on-demand thread binding.

See Also:
HibernateInterceptor, JdoInterceptor

afterPropertiesSet

public void afterPropertiesSet()
                        throws AopConfigException
Description copied from interface: InitializingBean
Invoked by a BeanFactory after it has set all bean properties supplied (and satisfied BeanFactoryAware and ApplicationContextAware).

This method allows the bean instance to perform initialization only possible when all bean properties have been set and to throw an exception in the event of misconfiguration.

Specified by:
afterPropertiesSet in interface InitializingBean
Throws:
AopConfigException

createTargetSource

protected TargetSource createTargetSource(java.lang.Object target)
Set the target or TargetSource.

Parameters:
target - target. If this is an implementation of TargetSource it is used as our TargetSource; otherwise it is wrapped in a SingletonTargetSource.
Returns:
a TargetSource for this object

getObject

public java.lang.Object getObject()
Description copied from interface: FactoryBean
Return an instance (possibly shared or independent) of the object managed by this factory. As with a BeanFactory, this allows support for both the Singleton and Prototype design pattern.

Specified by:
getObject in interface FactoryBean
Returns:
an instance of the bean (should never be null)

getObjectType

public java.lang.Class getObjectType()
Description copied from interface: FactoryBean
Return the type of object that this FactoryBean creates, or null if not known in advance. This allows to check for specific types of beans without instantiating objects, e.g. on autowiring.

For a singleton, this can simply return getObject().getClass(), or even null, as autowiring will always check the actual objects for singletons. For prototypes, returning a meaningful type here is highly advisable, as autowiring will simply ignore them else.

Specified by:
getObjectType in interface FactoryBean
Returns:
the type of object that this FactoryBean creates, or null
See Also:
ListableBeanFactory.getBeansOfType(java.lang.Class, boolean, boolean)

isSingleton

public boolean isSingleton()
Description copied from interface: FactoryBean
Is the bean managed by this factory a singleton or a prototype? That is, will getObject() always return the same object?

The singleton status of the FactoryBean itself will generally be provided by the owning BeanFactory.

Specified by:
isSingleton in interface FactoryBean
Returns:
if this bean is a singleton


Copyright (C) 2003-2004 The Spring Framework Project.