Retry exception detection unwraps NestedSQLException and UncategorizedSQLException

git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@13916 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Derek Hulley
2009-04-09 15:02:43 +00:00
parent d6586351c1
commit 4fd502de4b

View File

@@ -56,6 +56,8 @@ import org.springframework.dao.DataIntegrityViolationException;
import org.springframework.dao.DeadlockLoserDataAccessException; import org.springframework.dao.DeadlockLoserDataAccessException;
import org.springframework.jdbc.UncategorizedSQLException; import org.springframework.jdbc.UncategorizedSQLException;
import com.ibatis.common.jdbc.exception.NestedSQLException;
/** /**
* A helper that runs a unit of work inside a UserTransaction, * A helper that runs a unit of work inside a UserTransaction,
* transparently retrying the unit of work if the cause of * transparently retrying the unit of work if the cause of
@@ -451,11 +453,31 @@ public class RetryingTransactionHelper
public static Throwable extractRetryCause(Throwable cause) public static Throwable extractRetryCause(Throwable cause)
{ {
Throwable retryCause = ExceptionStackUtil.getCause(cause, RETRY_EXCEPTIONS); Throwable retryCause = ExceptionStackUtil.getCause(cause, RETRY_EXCEPTIONS);
if (retryCause == null || retryCause instanceof SQLGrammarException
&& ((SQLGrammarException) retryCause).getErrorCode() != 3960) if (retryCause == null)
{ {
return null; return null;
} }
else if (retryCause instanceof SQLGrammarException
&& ((SQLGrammarException) retryCause).getErrorCode() != 3960)
{
return null;
}
else if (retryCause instanceof NestedSQLException || retryCause instanceof UncategorizedSQLException)
{
// The exception will have been caused by something else, so check that instead
if (retryCause.getCause() != null && retryCause.getCause() != retryCause)
{
// We dig further into this
cause = retryCause.getCause();
// Recurse
return extractRetryCause(cause);
}
else
{
return null;
}
}
// A simple match // A simple match
return retryCause; return retryCause;
} }