@Override @Nullable public DataAccessException translateExceptionIfPossible(RuntimeException ex) { for (PersistenceExceptionTranslator pet : this.delegates) { DataAccessException translatedDex = pet.translateExceptionIfPossible(ex); if (translatedDex != null) { return translatedDex; } } return null; }
/** * Return a translated exception if this is appropriate, * otherwise return the given exception as-is. * @param rawException an exception that we may wish to translate * @param pet the PersistenceExceptionTranslator to use to perform the translation * @return a translated persistence exception if translation is possible, * or the raw exception if it is not */ public static RuntimeException translateIfNecessary( RuntimeException rawException, PersistenceExceptionTranslator pet) { Assert.notNull(pet, "PersistenceExceptionTranslator must not be null"); DataAccessException dae = pet.translateExceptionIfPossible(rawException); return (dae != null ? dae : rawException); }
@Override public DataAccessException translateExceptionIfPossible(RuntimeException ex) { return exceptionTranslator.translateExceptionIfPossible(ex); } }
/** * Tries to convert the given {@link RuntimeException} into a {@link DataAccessException} but returns the original * exception if the conversation failed. Thus allows safe re-throwing of the return value. * * @param ex the exception to translate * @param exceptionTranslator the {@link PersistenceExceptionTranslator} to be used for translation * @return */ static RuntimeException potentiallyConvertRuntimeException(RuntimeException ex, PersistenceExceptionTranslator exceptionTranslator) { RuntimeException resolved = exceptionTranslator.translateExceptionIfPossible(ex); return resolved == null ? ex : resolved; }
/** * Tries to convert the given {@link RuntimeException} into a {@link DataAccessException} but returns the original * exception if the conversation failed. Thus allows safe re-throwing of the return value. * * @param ex the exception to translate * @param exceptionTranslator the {@link PersistenceExceptionTranslator} to be used for translation * @return */ private static RuntimeException potentiallyConvertRuntimeException(RuntimeException ex, PersistenceExceptionTranslator exceptionTranslator) { RuntimeException resolved = exceptionTranslator.translateExceptionIfPossible(ex); return resolved == null ? ex : resolved; }
private RuntimeException convertException(RuntimeException ex) { DataAccessException dae = (this.exceptionTranslator != null) ? this.exceptionTranslator.translateExceptionIfPossible(ex) : EntityManagerFactoryUtils.convertJpaAccessExceptionIfPossible(ex); return (dae != null ? dae : ex); } }
@Override @Nullable public DataAccessException translateExceptionIfPossible(RuntimeException ex) { for (PersistenceExceptionTranslator pet : this.delegates) { DataAccessException translatedDex = pet.translateExceptionIfPossible(ex); if (translatedDex != null) { return translatedDex; } } return null; }
/** * Return a translated exception if this is appropriate, * otherwise return the given exception as-is. * @param rawException an exception that we may wish to translate * @param pet the PersistenceExceptionTranslator to use to perform the translation * @return a translated persistence exception if translation is possible, * or the raw exception if it is not */ public static RuntimeException translateIfNecessary( RuntimeException rawException, PersistenceExceptionTranslator pet) { Assert.notNull(pet, "PersistenceExceptionTranslator must not be null"); DataAccessException dae = pet.translateExceptionIfPossible(rawException); return (dae != null ? dae : rawException); }
@Nullable public DataAccessException translateExceptionIfPossible(RuntimeException ex) { return exceptionTranslator.translateExceptionIfPossible(ex); }
private RuntimeException convertException(RuntimeException ex) { DataAccessException dae = (this.exceptionTranslator != null) ? this.exceptionTranslator.translateExceptionIfPossible(ex) : EntityManagerFactoryUtils.convertJpaAccessExceptionIfPossible(ex); return (dae != null ? dae : ex); } }
/** * Execute an operation and take care of translating exceptions using the {@link MongoTemplate templates} * {@link org.springframework.data.mongodb.core.MongoExceptionTranslator} and passing those on to the * {@link #errorHandler}. * * @param callback must not be {@literal null}. * @param <T> * @return can be {@literal null}. * @throws RuntimeException The potentially translated exception. */ @Nullable private <V> V execute(Supplier<V> callback) { try { return callback.get(); } catch (RuntimeException e) { RuntimeException translated = template.getExceptionTranslator().translateExceptionIfPossible(e); RuntimeException toHandle = translated != null ? translated : e; errorHandler.handleError(toHandle); throw toHandle; } } }
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()); }
/** * Resolves the proxy into its backing object. * * @return */ @Nullable private synchronized Object resolve() { if (!resolved) { try { return callback.resolve(property); } catch (RuntimeException ex) { DataAccessException translatedException = this.exceptionTranslator.translateExceptionIfPossible(ex); if (translatedException instanceof ClientSessionException) { throw new LazyLoadingException("Unable to lazily resolve DBRef! Invalid session state.", ex); } throw new LazyLoadingException("Unable to lazily resolve DBRef!", translatedException != null ? translatedException : ex); } } return result; } }
@Override public DataAccessException translateExceptionIfPossible(RuntimeException ex) { return exceptionTranslator.translateExceptionIfPossible(ex); } }
/** * Tries to convert the given {@link RuntimeException} into a {@link DataAccessException} but returns the original * exception if the conversation failed. Thus allows safe re-throwing of the return value. * * @param ex the exception to translate * @param exceptionTranslator the {@link PersistenceExceptionTranslator} to be used for translation * @return */ private static RuntimeException potentiallyConvertRuntimeException(RuntimeException ex, PersistenceExceptionTranslator exceptionTranslator) { RuntimeException resolved = exceptionTranslator.translateExceptionIfPossible(ex); return resolved == null ? ex : resolved; }
/** * Tries to convert the given {@link RuntimeException} into a {@link DataAccessException} but returns the original * exception if the conversation failed. Thus allows safe re-throwing of the return value. * * @param ex the exception to translate * @param exceptionTranslator the {@link PersistenceExceptionTranslator} to be used for translation * @return */ static RuntimeException potentiallyConvertRuntimeException(RuntimeException ex, PersistenceExceptionTranslator exceptionTranslator) { RuntimeException resolved = exceptionTranslator.translateExceptionIfPossible(ex); return resolved == null ? ex : resolved; }
@Nullable public DataAccessException translateExceptionIfPossible(RuntimeException ex) { return exceptionTranslator.translateExceptionIfPossible(ex); }
/** * Execute an operation and take care of translating exceptions using the {@link MongoTemplate templates} * {@link org.springframework.data.mongodb.core.MongoExceptionTranslator} and passing those on to the * {@link #errorHandler}. * * @param callback must not be {@literal null}. * @param <T> * @return can be {@literal null}. * @throws RuntimeException The potentially translated exception. */ @Nullable private <V> V execute(Supplier<V> callback) { try { return callback.get(); } catch (RuntimeException e) { RuntimeException translated = template.getExceptionTranslator().translateExceptionIfPossible(e); RuntimeException toHandle = translated != null ? translated : e; errorHandler.handleError(toHandle); throw toHandle; } } }
/** * Resolves the proxy into its backing object. * * @return */ @Nullable private synchronized Object resolve() { if (!resolved) { try { return callback.resolve(property); } catch (RuntimeException ex) { DataAccessException translatedException = this.exceptionTranslator.translateExceptionIfPossible(ex); if (translatedException instanceof ClientSessionException) { throw new LazyLoadingException("Unable to lazily resolve DBRef! Invalid session state.", ex); } throw new LazyLoadingException("Unable to lazily resolve DBRef!", translatedException != null ? translatedException : ex); } } return result; } }
@Override public DataAccessException translateExceptionIfPossible(RuntimeException ex) { return exceptionTranslator.translateExceptionIfPossible(ex); } }