From 40822746306f5d0e5d553504275046ec4906309b Mon Sep 17 00:00:00 2001 From: Juergen Hoeller Date: Mon, 7 Jul 2014 16:26:25 +0200 Subject: [PATCH] SQLStateSQLExceptionTranslator checks exception class name for timeout indication before resorting to UncategorizedSQLException Issue: SPR-11959 --- .../jdbc/support/SQLStateSQLExceptionTranslator.java | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/spring-jdbc/src/main/java/org/springframework/jdbc/support/SQLStateSQLExceptionTranslator.java b/spring-jdbc/src/main/java/org/springframework/jdbc/support/SQLStateSQLExceptionTranslator.java index 0fc68068b1..1cd9144ff3 100644 --- a/spring-jdbc/src/main/java/org/springframework/jdbc/support/SQLStateSQLExceptionTranslator.java +++ b/spring-jdbc/src/main/java/org/springframework/jdbc/support/SQLStateSQLExceptionTranslator.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2013 the original author or authors. + * Copyright 2002-2014 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -24,6 +24,7 @@ import org.springframework.dao.ConcurrencyFailureException; import org.springframework.dao.DataAccessException; import org.springframework.dao.DataAccessResourceFailureException; import org.springframework.dao.DataIntegrityViolationException; +import org.springframework.dao.QueryTimeoutException; import org.springframework.dao.TransientDataAccessResourceException; import org.springframework.jdbc.BadSqlGrammarException; @@ -87,6 +88,7 @@ public class SQLStateSQLExceptionTranslator extends AbstractFallbackSQLException @Override protected DataAccessException doTranslate(String task, String sql, SQLException ex) { + // First, the getSQLState check... String sqlState = getSqlState(ex); if (sqlState != null && sqlState.length() >= 2) { String classCode = sqlState.substring(0, 2); @@ -109,6 +111,14 @@ public class SQLStateSQLExceptionTranslator extends AbstractFallbackSQLException return new ConcurrencyFailureException(buildMessage(task, sql, ex), ex); } } + + // For MySQL: exception class name indicating a timeout? + // (since MySQL doesn't throw the JDBC 4 SQLTimeoutException) + if (ex.getClass().getName().contains("Timeout")) { + return new QueryTimeoutException(buildMessage(task, sql, ex), ex); + } + + // Couldn't resolve anything proper - resort to UncategorizedSQLException. return null; }