spring-tx

org.springframework.dao.annotation
Class PersistenceExceptionTranslationPostProcessor

java.lang.Object
  extended by org.springframework.aop.framework.ProxyConfig
      extended by org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor
All Implemented Interfaces:
java.io.Serializable, org.springframework.beans.factory.Aware, org.springframework.beans.factory.BeanClassLoaderAware, org.springframework.beans.factory.BeanFactoryAware, org.springframework.beans.factory.config.BeanPostProcessor, org.springframework.core.Ordered

public class PersistenceExceptionTranslationPostProcessor
extends org.springframework.aop.framework.ProxyConfig
implements org.springframework.beans.factory.config.BeanPostProcessor, org.springframework.beans.factory.BeanClassLoaderAware, org.springframework.beans.factory.BeanFactoryAware, org.springframework.core.Ordered

Bean post-processor that automatically applies persistence exception translation to any bean marked with Spring's @Repository annotation, adding a corresponding PersistenceExceptionTranslationAdvisor to the exposed proxy (either an existing AOP proxy or a newly generated proxy that implements all of the target's interfaces).

Translates native resource exceptions to Spring's DataAccessException hierarchy. Autodetects beans that implement the PersistenceExceptionTranslator interface, which are subsequently asked to translate candidate exceptions.

All of Spring's applicable resource factories (e.g. LocalSessionFactoryBean, LocalEntityManagerFactoryBean) implement the PersistenceExceptionTranslator interface out of the box. As a consequence, all that is usually needed to enable automatic exception translation is marking all affected beans (such as Repositories or DAOs) with the @Repository annotation, along with defining this post-processor as a bean in the application context.

Since:
2.0
Author:
Rod Johnson, Juergen Hoeller
See Also:
PersistenceExceptionTranslationAdvisor, Repository, DataAccessException, PersistenceExceptionTranslator, Serialized Form

Field Summary
 
Fields inherited from interface org.springframework.core.Ordered
HIGHEST_PRECEDENCE, LOWEST_PRECEDENCE
 
Constructor Summary
PersistenceExceptionTranslationPostProcessor()
           
 
Method Summary
 int getOrder()
           
 java.lang.Object postProcessAfterInitialization(java.lang.Object bean, java.lang.String beanName)
           
 java.lang.Object postProcessBeforeInitialization(java.lang.Object bean, java.lang.String beanName)
           
 void setBeanClassLoader(java.lang.ClassLoader classLoader)
           
 void setBeanFactory(org.springframework.beans.factory.BeanFactory beanFactory)
           
 void setRepositoryAnnotationType(java.lang.Class<? extends java.lang.annotation.Annotation> repositoryAnnotationType)
          Set the 'repository' annotation type.
 
Methods inherited from class org.springframework.aop.framework.ProxyConfig
copyFrom, isExposeProxy, isFrozen, isOpaque, isOptimize, isProxyTargetClass, setExposeProxy, setFrozen, setOpaque, setOptimize, setProxyTargetClass, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

PersistenceExceptionTranslationPostProcessor

public PersistenceExceptionTranslationPostProcessor()
Method Detail

setRepositoryAnnotationType

public void setRepositoryAnnotationType(java.lang.Class<? extends java.lang.annotation.Annotation> repositoryAnnotationType)
Set the 'repository' annotation type. The default repository annotation type is the Repository annotation.

This setter property exists so that developers can provide their own (non-Spring-specific) annotation type to indicate that a class has a repository role.

Parameters:
repositoryAnnotationType - the desired annotation type

setBeanClassLoader

public void setBeanClassLoader(java.lang.ClassLoader classLoader)
Specified by:
setBeanClassLoader in interface org.springframework.beans.factory.BeanClassLoaderAware

setBeanFactory

public void setBeanFactory(org.springframework.beans.factory.BeanFactory beanFactory)
                    throws org.springframework.beans.BeansException
Specified by:
setBeanFactory in interface org.springframework.beans.factory.BeanFactoryAware
Throws:
org.springframework.beans.BeansException

getOrder

public int getOrder()
Specified by:
getOrder in interface org.springframework.core.Ordered

postProcessBeforeInitialization

public java.lang.Object postProcessBeforeInitialization(java.lang.Object bean,
                                                        java.lang.String beanName)
Specified by:
postProcessBeforeInitialization in interface org.springframework.beans.factory.config.BeanPostProcessor

postProcessAfterInitialization

public java.lang.Object postProcessAfterInitialization(java.lang.Object bean,
                                                       java.lang.String beanName)
Specified by:
postProcessAfterInitialization in interface org.springframework.beans.factory.config.BeanPostProcessor

spring-tx