org.springframework.dao.support.PersistenceExceptionTranslator Java Examples
The following examples show how to use
org.springframework.dao.support.PersistenceExceptionTranslator.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ReactivePersistenceExceptionTranslationInterceptor.java From sdn-rx with Apache License 2.0 | 6 votes |
@Override public Object invoke(MethodInvocation mi) throws Throwable { // Invoke the method potentially returning a reactive type Object m = mi.proceed(); PersistenceExceptionTranslator translator = getPersistenceExceptionTranslator(); if (translator == null) { return m; } else { // Add the translation. Nothing will happen if no-one subscribe the reactive result. Function<RuntimeException, Throwable> errorMappingFunction = t -> t instanceof DataAccessException ? t : DataAccessUtils.translateIfNecessary(t, translator); if (m instanceof Mono) { return ((Mono<?>) m).onErrorMap(RuntimeException.class, errorMappingFunction); } else if (m instanceof Flux) { return ((Flux<?>) m).onErrorMap(RuntimeException.class, errorMappingFunction); } else { return m; } } }
Example #2
Source File: ExtendedEntityManagerCreator.java From java-technology-stack with MIT License | 6 votes |
/** * 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, @Nullable Class<? extends EntityManager> emIfc, @Nullable ClassLoader cl, @Nullable PersistenceExceptionTranslator exceptionTranslator, @Nullable Boolean jta, boolean containerManaged, boolean synchronizedWithTransaction) { Assert.notNull(rawEm, "EntityManager must not be null"); Set<Class<?>> ifcs = new LinkedHashSet<>(); 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()), ClassUtils.toClassArray(ifcs), new ExtendedEntityManagerInvocationHandler( rawEm, exceptionTranslator, jta, containerManaged, synchronizedWithTransaction)); }
Example #3
Source File: ExtendedEntityManagerCreator.java From lams with GNU General Public License v2.0 | 6 votes |
/** * 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)); }
Example #4
Source File: CustomSqlSessionTemplate.java From tcc-transaction with Apache License 2.0 | 6 votes |
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; }
Example #5
Source File: ExtendedEntityManagerCreator.java From spring4-understanding with Apache License 2.0 | 6 votes |
/** * 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)); }
Example #6
Source File: ExtendedEntityManagerCreator.java From spring-analysis-note with MIT License | 6 votes |
/** * 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, @Nullable Class<? extends EntityManager> emIfc, @Nullable ClassLoader cl, @Nullable PersistenceExceptionTranslator exceptionTranslator, @Nullable Boolean jta, boolean containerManaged, boolean synchronizedWithTransaction) { Assert.notNull(rawEm, "EntityManager must not be null"); Set<Class<?>> ifcs = new LinkedHashSet<>(); 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()), ClassUtils.toClassArray(ifcs), new ExtendedEntityManagerInvocationHandler( rawEm, exceptionTranslator, jta, containerManaged, synchronizedWithTransaction)); }
Example #7
Source File: CustomSqlSessionTemplate.java From galaxy with Apache License 2.0 | 6 votes |
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; }
Example #8
Source File: PersistenceExceptionTranslationAdvisor.java From spring4-understanding with Apache License 2.0 | 5 votes |
/** * 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); }
Example #9
Source File: ContainerManagedEntityManagerIntegrationTests.java From spring4-understanding with Apache License 2.0 | 5 votes |
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()); }
Example #10
Source File: ExtendedEntityManagerCreator.java From spring4-understanding with Apache License 2.0 | 5 votes |
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; }
Example #11
Source File: PersistenceExceptionTranslationInterceptorTests.java From spring4-understanding with Apache License 2.0 | 5 votes |
@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")); } }
Example #12
Source File: SolrTemplate.java From dubbox with Apache License 2.0 | 5 votes |
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); } } }
Example #13
Source File: ExtendedEntityManagerCreator.java From lams with GNU General Public License v2.0 | 5 votes |
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; }
Example #14
Source File: JpaPersistenceProvider.java From rice with Educational Community License v2.0 | 5 votes |
/** * 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; }
Example #15
Source File: ReactivePersistenceExceptionTranslationInterceptor.java From sdn-rx with Apache License 2.0 | 5 votes |
PersistenceExceptionTranslator getPersistenceExceptionTranslator() { PersistenceExceptionTranslator translator = this.persistenceExceptionTranslator; if (translator == null) { synchronized (this) { translator = this.persistenceExceptionTranslator; if (translator == null) { this.persistenceExceptionTranslator = detectPersistenceExceptionTranslators(); translator = this.persistenceExceptionTranslator; } } } return translator; }
Example #16
Source File: PersistenceExceptionTranslationAdvisor.java From lams with GNU General Public License v2.0 | 5 votes |
/** * 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); }
Example #17
Source File: DefaultCollectionOperations.java From spring-data with Apache License 2.0 | 5 votes |
protected DefaultCollectionOperations(final ArangoCollection collection, final Map<CollectionCacheKey, CollectionCacheValue> collectionCache, final PersistenceExceptionTranslator exceptionTranslator) { this.collection = collection; this.collectionCache = collectionCache; this.exceptionTranslator = exceptionTranslator; }
Example #18
Source File: DefaultUserOperation.java From spring-data with Apache License 2.0 | 5 votes |
protected DefaultUserOperation(final ArangoDatabase db, final String username, final PersistenceExceptionTranslator exceptionTranslator, final CollectionCallback collectionCallback) { this.db = db; this.username = username; this.exceptionTranslator = exceptionTranslator; this.collectionCallback = collectionCallback; }
Example #19
Source File: ArangoTemplate.java From spring-data with Apache License 2.0 | 5 votes |
public ArangoTemplate(final ArangoDB arango, final String database, final ArangoConverter converter, final PersistenceExceptionTranslator exceptionTranslator) { super(); this.arango = arango._setCursorInitializer(new ArangoCursorInitializer(converter)); this.databaseName = database; this.databaseExpression = PARSER.parseExpression(databaseName, ParserContext.TEMPLATE_EXPRESSION); this.converter = converter; this.exceptionTranslator = exceptionTranslator; this.context = new StandardEvaluationContext(); // set concurrency level to 1 as writes are very rare compared to reads collectionCache = new ConcurrentHashMap<>(8, 0.9f, 1); databaseCache = new ConcurrentHashMap<>(8, 0.9f, 1); version = null; }
Example #20
Source File: PersistenceExceptionTranslationInterceptorTests.java From java-technology-stack with MIT License | 5 votes |
@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")); } }
Example #21
Source File: ExtendedEntityManagerCreator.java From spring-analysis-note with MIT License | 5 votes |
private ExtendedEntityManagerInvocationHandler(EntityManager target, @Nullable PersistenceExceptionTranslator exceptionTranslator, @Nullable Boolean jta, boolean containerManaged, boolean synchronizedWithTransaction) { this.target = target; this.exceptionTranslator = exceptionTranslator; this.jta = (jta != null ? jta : isJtaEntityManager()); this.containerManaged = containerManaged; this.synchronizedWithTransaction = synchronizedWithTransaction; }
Example #22
Source File: ExtendedEntityManagerCreator.java From spring-analysis-note with MIT License | 5 votes |
public ExtendedEntityManagerSynchronization( EntityManager em, @Nullable PersistenceExceptionTranslator exceptionTranslator) { super(new EntityManagerHolder(em), em); this.entityManager = em; this.exceptionTranslator = exceptionTranslator; }
Example #23
Source File: ReactivePersistenceExceptionTranslationInterceptor.java From sdn-rx with Apache License 2.0 | 5 votes |
/** * Detect all PersistenceExceptionTranslators in the given BeanFactory. * * @return a chained PersistenceExceptionTranslator, combining all * PersistenceExceptionTranslators found in the factory * @see ChainedPersistenceExceptionTranslator */ private PersistenceExceptionTranslator detectPersistenceExceptionTranslators() { // Find all translators, being careful not to activate FactoryBeans. Map<String, PersistenceExceptionTranslator> pets = BeanFactoryUtils.beansOfTypeIncludingAncestors( beanFactory, PersistenceExceptionTranslator.class, false, false); ChainedPersistenceExceptionTranslator cpet = new ChainedPersistenceExceptionTranslator(); pets.values().forEach(cpet::addDelegate); return cpet; }
Example #24
Source File: TransactionAttributeSourcePointcut.java From java-technology-stack with MIT License | 5 votes |
@Override public boolean matches(Method method, Class<?> targetClass) { if (TransactionalProxy.class.isAssignableFrom(targetClass) || PlatformTransactionManager.class.isAssignableFrom(targetClass) || PersistenceExceptionTranslator.class.isAssignableFrom(targetClass)) { return false; } TransactionAttributeSource tas = getTransactionAttributeSource(); return (tas == null || tas.getTransactionAttribute(method, targetClass) != null); }
Example #25
Source File: ContainerManagedEntityManagerIntegrationTests.java From java-technology-stack with MIT License | 5 votes |
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()); }
Example #26
Source File: ExtendedEntityManagerCreator.java From java-technology-stack with MIT License | 5 votes |
public ExtendedEntityManagerSynchronization( EntityManager em, @Nullable PersistenceExceptionTranslator exceptionTranslator) { super(new EntityManagerHolder(em), em); this.entityManager = em; this.exceptionTranslator = exceptionTranslator; }
Example #27
Source File: ExtendedEntityManagerCreator.java From java-technology-stack with MIT License | 5 votes |
private ExtendedEntityManagerInvocationHandler(EntityManager target, @Nullable PersistenceExceptionTranslator exceptionTranslator, @Nullable Boolean jta, boolean containerManaged, boolean synchronizedWithTransaction) { this.target = target; this.exceptionTranslator = exceptionTranslator; this.jta = (jta != null ? jta : isJtaEntityManager()); this.containerManaged = containerManaged; this.synchronizedWithTransaction = synchronizedWithTransaction; }
Example #28
Source File: ContainerManagedEntityManagerIntegrationTests.java From spring-analysis-note with MIT License | 5 votes |
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()); }
Example #29
Source File: TransactionAttributeSourcePointcut.java From spring-analysis-note with MIT License | 5 votes |
@Override public boolean matches(Class<?> clazz) { if (TransactionalProxy.class.isAssignableFrom(clazz) || PlatformTransactionManager.class.isAssignableFrom(clazz) || PersistenceExceptionTranslator.class.isAssignableFrom(clazz)) { return false; } TransactionAttributeSource tas = getTransactionAttributeSource(); return (tas == null || tas.isCandidateClass(clazz)); }
Example #30
Source File: PersistenceExceptionTranslationAdvisor.java From java-technology-stack with MIT License | 5 votes |
/** * 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); }