List of usage examples for org.springframework.dao.support DataAccessUtils translateIfNecessary
public static RuntimeException translateIfNecessary(RuntimeException rawException, PersistenceExceptionTranslator pet)
From source file:org.codehaus.grepo.query.jpa.repository.DefaultJpaRepository.java
/** * Convert the given runtime exception to an appropriate exception from the {@code org.springframework.dao} * hierarchy if necessary, or return the exception itself if it is not persistence related. * * @param ex runtime exception that occured, which may or may not be JPA-related * @return the corresponding DataAccessException instance if wrapping should occur, otherwise the raw exception *//* w w w .jav a 2s .com*/ protected RuntimeException translateIfNecessary(RuntimeException ex) { if (isTranslateExceptions()) { return DataAccessUtils.translateIfNecessary(ex, getJpaDialect()); } else { return ex; } }
From source file:org.kuali.rice.krad.data.jpa.JpaPersistenceProvider.java
/** * Surrounds the transaction with a try/catch block that can use the {@link PersistenceExceptionTranslator} to * translate the exception if necessary. * * @param callable The data operation to invoke. * @param <T> The type of the data operation. * * @return The result from the data operation, if successful. */// ww w. j a v a2 s.c o m protected <T> T doWithExceptionTranslation(Callable<T> callable) { try { return callable.call(); } catch (RuntimeException ex) { throw DataAccessUtils.translateIfNecessary(ex, this.persistenceExceptionTranslator); } catch (Exception ex) { // this should really never happen based on the internal usage in this class throw new RiceRuntimeException("Unexpected checked exception during data access.", ex); } }