Java 类org.springframework.dao.support.ChainedPersistenceExceptionTranslator 实例源码

项目:kc-rice    文件:JpaPersistenceProvider.java   
/**
 * Gets any {@link PersistenceExceptionTranslator}s from the {@link BeanFactory}.
 *
 * @param beanFactory The {@link BeanFactory} to use.
 *
 * @return A {@link PersistenceExceptionTranslator} from the {@link BeanFactory}.
 */
protected PersistenceExceptionTranslator detectPersistenceExceptionTranslators(ListableBeanFactory beanFactory) {
    // Find all translators, being careful not to activate FactoryBeans.
    Map<String, PersistenceExceptionTranslator> pets = BeanFactoryUtils.beansOfTypeIncludingAncestors(beanFactory,
            PersistenceExceptionTranslator.class, false, false);
    ChainedPersistenceExceptionTranslator cpet = new ChainedPersistenceExceptionTranslator();
    for (PersistenceExceptionTranslator pet : pets.values()) {
        cpet.addDelegate(pet);
    }
    // always add one last persistence exception translator as a catch all
    cpet.addDelegate(new DefaultPersistenceExceptionTranslator());
    return cpet;
}
项目:class-guard    文件:PersistenceExceptionTranslationPostProcessorTests.java   
public void testProxiesCorrectly() {
    GenericApplicationContext gac = new GenericApplicationContext();
    gac.registerBeanDefinition("translator",
            new RootBeanDefinition(PersistenceExceptionTranslationPostProcessor.class));
    gac.registerBeanDefinition("notProxied", new RootBeanDefinition(RepositoryInterfaceImpl.class));
    gac.registerBeanDefinition("proxied", new RootBeanDefinition(StereotypedRepositoryInterfaceImpl.class));
    gac.registerBeanDefinition("classProxied", new RootBeanDefinition(RepositoryWithoutInterface.class));
    gac.registerBeanDefinition("classProxiedAndAdvised",
            new RootBeanDefinition(RepositoryWithoutInterfaceAndOtherwiseAdvised.class));
    gac.registerBeanDefinition("chainedTranslator",
            new RootBeanDefinition(ChainedPersistenceExceptionTranslator.class));
    gac.registerBeanDefinition("proxyCreator",
            BeanDefinitionBuilder.rootBeanDefinition(AnnotationAwareAspectJAutoProxyCreator.class).
                    addPropertyValue("order", 50).getBeanDefinition());
    gac.registerBeanDefinition("logger", new RootBeanDefinition(LogAllAspect.class));
    gac.refresh();

    RepositoryInterface shouldNotBeProxied = (RepositoryInterface) gac.getBean("notProxied");
    assertFalse(AopUtils.isAopProxy(shouldNotBeProxied));
    RepositoryInterface shouldBeProxied = (RepositoryInterface) gac.getBean("proxied");
    assertTrue(AopUtils.isAopProxy(shouldBeProxied));
    RepositoryWithoutInterface rwi = (RepositoryWithoutInterface) gac.getBean("classProxied");
    assertTrue(AopUtils.isAopProxy(rwi));
    checkWillTranslateExceptions(rwi);

    Additional rwi2 = (Additional) gac.getBean("classProxiedAndAdvised");
    assertTrue(AopUtils.isAopProxy(rwi2));
    rwi2.additionalMethod();
    checkWillTranslateExceptions(rwi2);
}
项目:rice    文件:JpaPersistenceProvider.java   
/**
 * Gets any {@link PersistenceExceptionTranslator}s from the {@link BeanFactory}.
 *
 * @param beanFactory The {@link BeanFactory} to use.
 *
 * @return A {@link PersistenceExceptionTranslator} from the {@link BeanFactory}.
 */
protected PersistenceExceptionTranslator detectPersistenceExceptionTranslators(ListableBeanFactory beanFactory) {
    // Find all translators, being careful not to activate FactoryBeans.
    Map<String, PersistenceExceptionTranslator> pets = BeanFactoryUtils.beansOfTypeIncludingAncestors(beanFactory,
            PersistenceExceptionTranslator.class, false, false);
    ChainedPersistenceExceptionTranslator cpet = new ChainedPersistenceExceptionTranslator();
    for (PersistenceExceptionTranslator pet : pets.values()) {
        cpet.addDelegate(pet);
    }
    // always add one last persistence exception translator as a catch all
    cpet.addDelegate(new DefaultPersistenceExceptionTranslator());
    return cpet;
}