Polishing
This commit is contained in:
parent
d9e8d3bbe1
commit
a80c5121fe
|
@ -180,9 +180,9 @@ public class SQLErrorCodeSQLExceptionTranslator extends AbstractFallbackSQLExcep
|
||||||
}
|
}
|
||||||
|
|
||||||
// First, try custom translation from overridden method.
|
// First, try custom translation from overridden method.
|
||||||
DataAccessException dex = customTranslate(task, sql, sqlEx);
|
DataAccessException dae = customTranslate(task, sql, sqlEx);
|
||||||
if (dex != null) {
|
if (dae != null) {
|
||||||
return dex;
|
return dae;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Next, try the custom SQLException translator, if available.
|
// Next, try the custom SQLException translator, if available.
|
||||||
|
@ -288,15 +288,15 @@ public class SQLErrorCodeSQLExceptionTranslator extends AbstractFallbackSQLExcep
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Subclasses can override this method to attempt a custom mapping from SQLException
|
* Subclasses can override this method to attempt a custom mapping from
|
||||||
* to DataAccessException.
|
* {@link SQLException} to {@link DataAccessException}.
|
||||||
* @param task readable text describing the task being attempted
|
* @param task readable text describing the task being attempted
|
||||||
* @param sql the SQL query or update that caused the problem. May be {@code null}.
|
* @param sql the SQL query or update that caused the problem (may be {@code null})
|
||||||
* @param sqlEx the offending SQLException
|
* @param sqlEx the offending SQLException
|
||||||
* @return null if no custom translation was possible, otherwise a DataAccessException
|
* @return {@code null} if no custom translation applies, otherwise a {@link DataAccessException}
|
||||||
* resulting from custom translation. This exception should include the sqlEx parameter
|
* resulting from custom translation. This exception should include the {@code sqlEx} parameter
|
||||||
* as a nested root cause. This implementation always returns null, meaning that
|
* as a nested root cause. This implementation always returns {@code null}, meaning that the
|
||||||
* the translator always falls back to the default error codes.
|
* translator always falls back to the default error codes.
|
||||||
*/
|
*/
|
||||||
@Nullable
|
@Nullable
|
||||||
protected DataAccessException customTranslate(String task, @Nullable String sql, SQLException sqlEx) {
|
protected DataAccessException customTranslate(String task, @Nullable String sql, SQLException sqlEx) {
|
||||||
|
@ -304,16 +304,16 @@ public class SQLErrorCodeSQLExceptionTranslator extends AbstractFallbackSQLExcep
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a custom DataAccessException, based on a given exception
|
* Create a custom {@link DataAccessException}, based on a given exception
|
||||||
* class from a CustomSQLErrorCodesTranslation definition.
|
* class from a {@link CustomSQLErrorCodesTranslation} definition.
|
||||||
* @param task readable text describing the task being attempted
|
* @param task readable text describing the task being attempted
|
||||||
* @param sql the SQL query or update that caused the problem. May be {@code null}.
|
* @param sql the SQL query or update that caused the problem (may be {@code null})
|
||||||
* @param sqlEx the offending SQLException
|
* @param sqlEx the offending SQLException
|
||||||
* @param exceptionClass the exception class to use, as defined in the
|
* @param exceptionClass the exception class to use, as defined in the
|
||||||
* CustomSQLErrorCodesTranslation definition
|
* {@link CustomSQLErrorCodesTranslation} definition
|
||||||
* @return null if the custom exception could not be created, otherwise
|
* @return {@code null} if the custom exception could not be created, otherwise
|
||||||
* the resulting DataAccessException. This exception should include the
|
* the resulting {@link DataAccessException}. This exception should include the
|
||||||
* sqlEx parameter as a nested root cause.
|
* {@code sqlEx} parameter as a nested root cause.
|
||||||
* @see CustomSQLErrorCodesTranslation#setExceptionClass
|
* @see CustomSQLErrorCodesTranslation#setExceptionClass
|
||||||
*/
|
*/
|
||||||
@Nullable
|
@Nullable
|
||||||
|
|
|
@ -491,10 +491,10 @@ public abstract class ExtendedEntityManagerCreator {
|
||||||
}
|
}
|
||||||
|
|
||||||
private RuntimeException convertException(RuntimeException ex) {
|
private RuntimeException convertException(RuntimeException ex) {
|
||||||
DataAccessException daex = (this.exceptionTranslator != null) ?
|
DataAccessException dae = (this.exceptionTranslator != null) ?
|
||||||
this.exceptionTranslator.translateExceptionIfPossible(ex) :
|
this.exceptionTranslator.translateExceptionIfPossible(ex) :
|
||||||
EntityManagerFactoryUtils.convertJpaAccessExceptionIfPossible(ex);
|
EntityManagerFactoryUtils.convertJpaAccessExceptionIfPossible(ex);
|
||||||
return (daex != null ? daex : ex);
|
return (dae != null ? dae : ex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -533,9 +533,9 @@ public class JpaTransactionManager extends AbstractPlatformTransactionManager
|
||||||
}
|
}
|
||||||
catch (RollbackException ex) {
|
catch (RollbackException ex) {
|
||||||
if (ex.getCause() instanceof RuntimeException) {
|
if (ex.getCause() instanceof RuntimeException) {
|
||||||
DataAccessException dex = getJpaDialect().translateExceptionIfPossible((RuntimeException) ex.getCause());
|
DataAccessException dae = getJpaDialect().translateExceptionIfPossible((RuntimeException) ex.getCause());
|
||||||
if (dex != null) {
|
if (dae != null) {
|
||||||
throw dex;
|
throw dae;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
throw new TransactionSystemException("Could not commit JPA transaction", ex);
|
throw new TransactionSystemException("Could not commit JPA transaction", ex);
|
||||||
|
|
|
@ -239,8 +239,8 @@ public abstract class DataAccessUtils {
|
||||||
RuntimeException rawException, PersistenceExceptionTranslator pet) {
|
RuntimeException rawException, PersistenceExceptionTranslator pet) {
|
||||||
|
|
||||||
Assert.notNull(pet, "PersistenceExceptionTranslator must not be null");
|
Assert.notNull(pet, "PersistenceExceptionTranslator must not be null");
|
||||||
DataAccessException dex = pet.translateExceptionIfPossible(rawException);
|
DataAccessException dae = pet.translateExceptionIfPossible(rawException);
|
||||||
return (dex != null ? dex : rawException);
|
return (dae != null ? dae : rawException);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue