|
|
|
@ -1,5 +1,5 @@ |
|
|
|
/* |
|
|
|
/* |
|
|
|
* Copyright 2002-2012 the original author or authors. |
|
|
|
* Copyright 2002-2014 the original author or authors. |
|
|
|
* |
|
|
|
* |
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
|
|
|
* you may not use this file except in compliance with the License. |
|
|
|
* you may not use this file except in compliance with the License. |
|
|
|
@ -45,9 +45,8 @@ import org.springframework.jdbc.BadSqlGrammarException; |
|
|
|
* {@link SQLExceptionTranslator} implementation which analyzes the specific |
|
|
|
* {@link SQLExceptionTranslator} implementation which analyzes the specific |
|
|
|
* {@link java.sql.SQLException} subclass thrown by the JDBC driver. |
|
|
|
* {@link java.sql.SQLException} subclass thrown by the JDBC driver. |
|
|
|
* |
|
|
|
* |
|
|
|
* <p>This is only available with JDBC 4.0 and later drivers when using Java 6 or later. |
|
|
|
* <p>Falls back to a standard {@link SQLStateSQLExceptionTranslator} if the JDBC |
|
|
|
* Falls back to a standard {@link SQLStateSQLExceptionTranslator} if the JDBC driver |
|
|
|
* driver does not actually expose JDBC 4 compliant {@code SQLException} subclasses. |
|
|
|
* does not actually expose JDBC 4 compliant {@code SQLException} subclasses. |
|
|
|
|
|
|
|
* |
|
|
|
* |
|
|
|
* @author Thomas Risberg |
|
|
|
* @author Thomas Risberg |
|
|
|
* @author Juergen Hoeller |
|
|
|
* @author Juergen Hoeller |
|
|
|
@ -65,22 +64,22 @@ public class SQLExceptionSubclassTranslator extends AbstractFallbackSQLException |
|
|
|
@Override |
|
|
|
@Override |
|
|
|
protected DataAccessException doTranslate(String task, String sql, SQLException ex) { |
|
|
|
protected DataAccessException doTranslate(String task, String sql, SQLException ex) { |
|
|
|
if (ex instanceof SQLTransientException) { |
|
|
|
if (ex instanceof SQLTransientException) { |
|
|
|
if (ex instanceof SQLTransactionRollbackException) { |
|
|
|
|
|
|
|
return new ConcurrencyFailureException(buildMessage(task, sql, ex), ex); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if (ex instanceof SQLTransientConnectionException) { |
|
|
|
if (ex instanceof SQLTransientConnectionException) { |
|
|
|
return new TransientDataAccessResourceException(buildMessage(task, sql, ex), ex); |
|
|
|
return new TransientDataAccessResourceException(buildMessage(task, sql, ex), ex); |
|
|
|
} |
|
|
|
} |
|
|
|
if (ex instanceof SQLTimeoutException) { |
|
|
|
else if (ex instanceof SQLTransactionRollbackException) { |
|
|
|
|
|
|
|
return new ConcurrencyFailureException(buildMessage(task, sql, ex), ex); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
else if (ex instanceof SQLTimeoutException) { |
|
|
|
return new QueryTimeoutException(buildMessage(task, sql, ex), ex); |
|
|
|
return new QueryTimeoutException(buildMessage(task, sql, ex), ex); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
else if (ex instanceof SQLNonTransientException) { |
|
|
|
else if (ex instanceof SQLNonTransientException) { |
|
|
|
if (ex instanceof SQLDataException) { |
|
|
|
if (ex instanceof SQLNonTransientConnectionException) { |
|
|
|
return new DataIntegrityViolationException(buildMessage(task, sql, ex), ex); |
|
|
|
return new DataAccessResourceFailureException(buildMessage(task, sql, ex), ex); |
|
|
|
} |
|
|
|
} |
|
|
|
else if (ex instanceof SQLFeatureNotSupportedException) { |
|
|
|
else if (ex instanceof SQLDataException) { |
|
|
|
return new InvalidDataAccessApiUsageException(buildMessage(task, sql, ex), ex); |
|
|
|
return new DataIntegrityViolationException(buildMessage(task, sql, ex), ex); |
|
|
|
} |
|
|
|
} |
|
|
|
else if (ex instanceof SQLIntegrityConstraintViolationException) { |
|
|
|
else if (ex instanceof SQLIntegrityConstraintViolationException) { |
|
|
|
return new DataIntegrityViolationException(buildMessage(task, sql, ex), ex); |
|
|
|
return new DataIntegrityViolationException(buildMessage(task, sql, ex), ex); |
|
|
|
@ -88,12 +87,12 @@ public class SQLExceptionSubclassTranslator extends AbstractFallbackSQLException |
|
|
|
else if (ex instanceof SQLInvalidAuthorizationSpecException) { |
|
|
|
else if (ex instanceof SQLInvalidAuthorizationSpecException) { |
|
|
|
return new PermissionDeniedDataAccessException(buildMessage(task, sql, ex), ex); |
|
|
|
return new PermissionDeniedDataAccessException(buildMessage(task, sql, ex), ex); |
|
|
|
} |
|
|
|
} |
|
|
|
else if (ex instanceof SQLNonTransientConnectionException) { |
|
|
|
|
|
|
|
return new DataAccessResourceFailureException(buildMessage(task, sql, ex), ex); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
else if (ex instanceof SQLSyntaxErrorException) { |
|
|
|
else if (ex instanceof SQLSyntaxErrorException) { |
|
|
|
return new BadSqlGrammarException(task, sql, ex); |
|
|
|
return new BadSqlGrammarException(task, sql, ex); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
else if (ex instanceof SQLFeatureNotSupportedException) { |
|
|
|
|
|
|
|
return new InvalidDataAccessApiUsageException(buildMessage(task, sql, ex), ex); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
else if (ex instanceof SQLRecoverableException) { |
|
|
|
else if (ex instanceof SQLRecoverableException) { |
|
|
|
return new RecoverableDataAccessException(buildMessage(task, sql, ex), ex); |
|
|
|
return new RecoverableDataAccessException(buildMessage(task, sql, ex), ex); |
|
|
|
|