当前位置: 首页>>代码示例>>Java>>正文


Java PersistenceExceptionTranslator类代码示例

本文整理汇总了Java中org.springframework.dao.support.PersistenceExceptionTranslator的典型用法代码示例。如果您正苦于以下问题:Java PersistenceExceptionTranslator类的具体用法?Java PersistenceExceptionTranslator怎么用?Java PersistenceExceptionTranslator使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


PersistenceExceptionTranslator类属于org.springframework.dao.support包,在下文中一共展示了PersistenceExceptionTranslator类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: createProxy

import org.springframework.dao.support.PersistenceExceptionTranslator; //导入依赖的package包/类
/**
 * Actually create the EntityManager proxy.
 * @param rawEm raw EntityManager
 * @param emIfc the (potentially vendor-specific) EntityManager
 * interface to proxy, or {@code null} for default detection of all interfaces
 * @param cl the ClassLoader to use for proxy creation (maybe {@code null})
 * @param exceptionTranslator the PersistenceException translator to use
 * @param jta whether to create a JTA-aware EntityManager
 * (or {@code null} if not known in advance)
 * @param containerManaged whether to follow container-managed EntityManager
 * or application-managed EntityManager semantics
 * @param synchronizedWithTransaction whether to automatically join ongoing
 * transactions (according to the JPA 2.1 SynchronizationType rules)
 * @return the EntityManager proxy
 */
private static EntityManager createProxy(
		EntityManager rawEm, Class<? extends EntityManager> emIfc, ClassLoader cl,
		PersistenceExceptionTranslator exceptionTranslator, Boolean jta,
		boolean containerManaged, boolean synchronizedWithTransaction) {

	Assert.notNull(rawEm, "EntityManager must not be null");
	Set<Class<?>> ifcs = new LinkedHashSet<Class<?>>();
	if (emIfc != null) {
		ifcs.add(emIfc);
	}
	else {
		ifcs.addAll(ClassUtils.getAllInterfacesForClassAsSet(rawEm.getClass(), cl));
	}
	ifcs.add(EntityManagerProxy.class);
	return (EntityManager) Proxy.newProxyInstance(
			(cl != null ? cl : ExtendedEntityManagerCreator.class.getClassLoader()),
			ifcs.toArray(new Class<?>[ifcs.size()]),
			new ExtendedEntityManagerInvocationHandler(
					rawEm, exceptionTranslator, jta, containerManaged, synchronizedWithTransaction));
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:36,代码来源:ExtendedEntityManagerCreator.java

示例2: createProxy

import org.springframework.dao.support.PersistenceExceptionTranslator; //导入依赖的package包/类
/**
 * Actually create the EntityManager proxy.
 * @param rawEm raw EntityManager
 * @param emIfc the (potentially vendor-specific) EntityManager
 * interface to proxy, or {@code null} for default detection of all interfaces
 * @param plusOperations an implementation of the EntityManagerPlusOperations
 * interface, if those operations should be exposed (may be {@code null})
 * @param exceptionTranslator the PersistenceException translator to use
 * @param jta whether to create a JTA-aware EntityManager
 * (or {@code null} if not known in advance)
 * @param containerManaged whether to follow container-managed EntityManager
 * or application-managed EntityManager semantics
 * @return the EntityManager proxy
 */
private static EntityManager createProxy(
		EntityManager rawEm, Class<? extends EntityManager> emIfc, ClassLoader cl,
		EntityManagerPlusOperations plusOperations, PersistenceExceptionTranslator exceptionTranslator,
		Boolean jta, boolean containerManaged) {

	Assert.notNull(rawEm, "EntityManager must not be null");
	Set<Class> ifcs = new LinkedHashSet<Class>();
	if (emIfc != null) {
		ifcs.add(emIfc);
	}
	else {
		ifcs.addAll(ClassUtils.getAllInterfacesForClassAsSet(rawEm.getClass(), cl));
	}
	ifcs.add(EntityManagerProxy.class);
	if (plusOperations != null) {
		ifcs.add(EntityManagerPlusOperations.class);
	}
	return (EntityManager) Proxy.newProxyInstance(
			(cl != null ? cl : ExtendedEntityManagerCreator.class.getClassLoader()),
			ifcs.toArray(new Class[ifcs.size()]),
			new ExtendedEntityManagerInvocationHandler(
					rawEm, plusOperations, exceptionTranslator, jta, containerManaged));
}
 
开发者ID:deathspeeder,项目名称:class-guard,代码行数:38,代码来源:ExtendedEntityManagerCreator.java

示例3: PersistenceExceptionTranslationAdvisor

import org.springframework.dao.support.PersistenceExceptionTranslator; //导入依赖的package包/类
/**
 * Create a new PersistenceExceptionTranslationAdvisor.
 * @param persistenceExceptionTranslator the PersistenceExceptionTranslator to use
 * @param repositoryAnnotationType the annotation type to check for
 */
public PersistenceExceptionTranslationAdvisor(
		PersistenceExceptionTranslator persistenceExceptionTranslator,
		Class<? extends Annotation> repositoryAnnotationType) {

	this.advice = new PersistenceExceptionTranslationInterceptor(persistenceExceptionTranslator);
	this.pointcut = new AnnotationMatchingPointcut(repositoryAnnotationType, true);
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:13,代码来源:PersistenceExceptionTranslationAdvisor.java

示例4: ExtendedEntityManagerInvocationHandler

import org.springframework.dao.support.PersistenceExceptionTranslator; //导入依赖的package包/类
private ExtendedEntityManagerInvocationHandler(EntityManager target,
		PersistenceExceptionTranslator exceptionTranslator, Boolean jta,
		boolean containerManaged, boolean synchronizedWithTransaction) {

	this.target = target;
	this.exceptionTranslator = exceptionTranslator;
	this.jta = (jta != null ? jta : isJtaEntityManager());
	this.containerManaged = containerManaged;
	this.synchronizedWithTransaction = synchronizedWithTransaction;
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:11,代码来源:ExtendedEntityManagerCreator.java

示例5: doTestExceptionTranslationWithDialectFound

import org.springframework.dao.support.PersistenceExceptionTranslator; //导入依赖的package包/类
protected void doTestExceptionTranslationWithDialectFound(PersistenceExceptionTranslator pet) throws Exception {
	RuntimeException in1 = new RuntimeException("in1");
	PersistenceException in2 = new PersistenceException();
	assertNull("No translation here", pet.translateExceptionIfPossible(in1));
	DataAccessException dex = pet.translateExceptionIfPossible(in2);
	assertNotNull(dex);
	assertSame(in2, dex.getCause());
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:9,代码来源:ContainerManagedEntityManagerIntegrationTests.java

示例6: addPersistenceExceptionTranslation

import org.springframework.dao.support.PersistenceExceptionTranslator; //导入依赖的package包/类
@Override
protected void addPersistenceExceptionTranslation(ProxyFactory pf, PersistenceExceptionTranslator pet) {
	if (AnnotationUtils.findAnnotation(pf.getTargetClass(), Repository.class) != null) {
		DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
		bf.registerBeanDefinition("peti", new RootBeanDefinition(PersistenceExceptionTranslationInterceptor.class));
		bf.registerSingleton("pet", pet);
		pf.addAdvice((PersistenceExceptionTranslationInterceptor) bf.getBean("peti"));
	}
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:10,代码来源:PersistenceExceptionTranslationInterceptorTests.java

示例7: CustomSqlSessionTemplate

import org.springframework.dao.support.PersistenceExceptionTranslator; //导入依赖的package包/类
public CustomSqlSessionTemplate(SqlSessionFactory sqlSessionFactory, ExecutorType executorType,
		PersistenceExceptionTranslator exceptionTranslator) {

	super(sqlSessionFactory, executorType, exceptionTranslator);

	this.sqlSessionFactory = sqlSessionFactory;
	this.executorType = executorType;
	this.exceptionTranslator = exceptionTranslator;

	this.sqlSessionProxy = (SqlSession) newProxyInstance(SqlSessionFactory.class.getClassLoader(),
			new Class[] { SqlSession.class }, new SqlSessionInterceptor());

	this.defaultTargetSqlSessionFactory = sqlSessionFactory;
}
 
开发者ID:PowerBin,项目名称:sharding-mybatis,代码行数:15,代码来源:CustomSqlSessionTemplate.java

示例8: SimpleSqlSessionTemplate

import org.springframework.dao.support.PersistenceExceptionTranslator; //导入依赖的package包/类
/**
 * Constructs a Spring managed {@code SqlSession} with the given {@code SqlSessionFactory} and {@code ExecutorType}.
 * A custom {@code SQLExceptionTranslator} can be provided as an argument so any {@code PersistenceException} thrown
 * by MyBatis can be custom translated to a {@code RuntimeException} The {@code SQLExceptionTranslator} can also be
 * null and thus no exception translation will be done and MyBatis exceptions will be thrown
 *
 * @param sqlSessionFactory
 * @param executorType
 * @param exceptionTranslator
 */
public SimpleSqlSessionTemplate(SqlSessionFactory sqlSessionFactory, ExecutorType executorType,
		PersistenceExceptionTranslator exceptionTranslator) {
	super(sqlSessionFactory);
	notNull(sqlSessionFactory, "Property 'sqlSessionFactory' is required");
	notNull(executorType, "Property 'executorType' is required");

	this.defaultSqlSessionFactory = sqlSessionFactory;
	this.executorType = executorType;
	this.exceptionTranslator = exceptionTranslator;
	this.sqlSessionProxy = (SqlSession) newProxyInstance(SqlSessionFactory.class.getClassLoader(), new Class[] { SqlSession.class },
			new SqlSessionInterceptor());
}
 
开发者ID:lindzh,项目名称:mybatis-spring-1.2.2,代码行数:23,代码来源:SimpleSqlSessionTemplate.java

示例9: SqlSessionTemplate

import org.springframework.dao.support.PersistenceExceptionTranslator; //导入依赖的package包/类
/**
 * Constructs a Spring managed {@code SqlSession} with the given
 * {@code SqlSessionFactory} and {@code ExecutorType}.
 * A custom {@code SQLExceptionTranslator} can be provided as an
 * argument so any {@code PersistenceException} thrown by MyBatis
 * can be custom translated to a {@code RuntimeException}
 * The {@code SQLExceptionTranslator} can also be null and thus no
 * exception translation will be done and MyBatis exceptions will be
 * thrown
 *
 * @param sqlSessionFactory
 * @param executorType
 * @param exceptionTranslator
 */
public SqlSessionTemplate(SqlSessionFactory sqlSessionFactory, ExecutorType executorType,
    PersistenceExceptionTranslator exceptionTranslator) {

  notNull(sqlSessionFactory, "Property 'sqlSessionFactory' is required");
  notNull(executorType, "Property 'executorType' is required");

  this.sqlSessionFactory = sqlSessionFactory;
  this.executorType = executorType;
  this.exceptionTranslator = exceptionTranslator;
  this.sqlSessionProxy = (SqlSession) newProxyInstance(
      SqlSessionFactory.class.getClassLoader(),
      new Class[] { SqlSession.class },
      new SqlSessionInterceptor());
}
 
开发者ID:lindzh,项目名称:mybatis-spring-1.2.2,代码行数:29,代码来源:SqlSessionTemplate.java

示例10: SqlSessionHolder

import org.springframework.dao.support.PersistenceExceptionTranslator; //导入依赖的package包/类
/**
 * Creates a new holder instance.
 *
 * @param sqlSession the {@code SqlSession} has to be hold.
 * @param executorType the {@code ExecutorType} has to be hold.
 */
public SqlSessionHolder(SqlSession sqlSession,
    ExecutorType executorType,
    PersistenceExceptionTranslator exceptionTranslator) {

  notNull(sqlSession, "SqlSession must not be null");
  notNull(executorType, "ExecutorType must not be null");

  this.sqlSession = sqlSession;
  this.executorType = executorType;
  this.exceptionTranslator = exceptionTranslator;
}
 
开发者ID:lindzh,项目名称:mybatis-spring-1.2.2,代码行数:18,代码来源:SqlSessionHolder.java

示例11: detectPersistenceExceptionTranslators

import org.springframework.dao.support.PersistenceExceptionTranslator; //导入依赖的package包/类
/**
 * 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;
}
 
开发者ID:kuali,项目名称:kc-rice,代码行数:20,代码来源:JpaPersistenceProvider.java

示例12: registerPersistenceExceptionTranslator

import org.springframework.dao.support.PersistenceExceptionTranslator; //导入依赖的package包/类
private void registerPersistenceExceptionTranslator() {
	if (this.applicationContext != null
			&& this.applicationContext.getBeansOfType(PersistenceExceptionTranslator.class).isEmpty()) {
		if (this.applicationContext instanceof ConfigurableApplicationContext) {
			((ConfigurableApplicationContext) this.applicationContext).getBeanFactory().registerSingleton(
					"solrExceptionTranslator", EXCEPTION_TRANSLATOR);
		}
	}
}
 
开发者ID:yiduwangkai,项目名称:dubbox-solr,代码行数:10,代码来源:SolrTemplate.java

示例13: persistenceExceptionTranslator

import org.springframework.dao.support.PersistenceExceptionTranslator; //导入依赖的package包/类
@Bean
public PersistenceExceptionTranslator persistenceExceptionTranslator() {
    return new PersistenceExceptionTranslator() {
        @Override
        public DataAccessException translateExceptionIfPossible(RuntimeException e) {
            return null;
        }
    };
}
 
开发者ID:whyDK37,项目名称:pinenut,代码行数:10,代码来源:Application.java

示例14: ExtendedEntityManagerInvocationHandler

import org.springframework.dao.support.PersistenceExceptionTranslator; //导入依赖的package包/类
private ExtendedEntityManagerInvocationHandler(
		EntityManager target, EntityManagerPlusOperations plusOperations,
		PersistenceExceptionTranslator exceptionTranslator, Boolean jta, boolean containerManaged) {

	this.target = target;
	this.plusOperations = plusOperations;
	this.exceptionTranslator = exceptionTranslator;
	this.jta = (jta != null ? jta : isJtaEntityManager());
	this.containerManaged = containerManaged;
}
 
开发者ID:deathspeeder,项目名称:class-guard,代码行数:11,代码来源:ExtendedEntityManagerCreator.java

示例15: mongoDbFactory

import org.springframework.dao.support.PersistenceExceptionTranslator; //导入依赖的package包/类
@Override
@Bean
public MongoDbFactory mongoDbFactory() {
  return new SimpleMongoDbFactory(mongo, getDatabaseName(), getUserCredentials(), getAuthenticationDatabaseName()) {
    @Override
    public PersistenceExceptionTranslator getExceptionTranslator() {
      return MongoTemplateWithRetry.getExceptionTranslator();
    }
  };
}
 
开发者ID:hypoport,项目名称:robust-mongo-config,代码行数:11,代码来源:MongoConfiguration.java


注:本文中的org.springframework.dao.support.PersistenceExceptionTranslator类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。