use of org.jaffa.persistence.engines.jdbcengine.SQLApplicationException in project jaffa-framework by jaffa-projects.
the class ExceptionHelper method extractApplicationExceptionsFromSQLException.
/**
* This method will loop through the input exception and its cause, looking for an instance of ApplicationException or ApplicationExceptions.
* If ApplicationException is found, it'll be returned wrapped inside a new ApplicationExceptions instance.
* If ApplicationExceptions is found, it'll be returned as is.
* It will return an instance of LockedApplicationException wrapped inside a new ApplicationExceptions instance if any lockign errors had occured.
* It will then loop through the cause of the input exception, looking for an instance of SQLException
* If the error code for the SQLException falls in the range specified by the global-rule 'jaffa.persistence.jdbcengine.customSqlErrorCodeRange',
* an instance of SQLApplicationException will be returned wrapped inside a new ApplicationExceptions instance.
* Else a null will be returned.
*
* @param exception The input exception.
* @return an instance of ApplicationExceptions if found in the cause stack of the input exception.
*/
public static ApplicationExceptions extractApplicationExceptionsFromSQLException(SQLException exception) {
ApplicationExceptions appExps = null;
// Check for SQLException
SQLException sqlException = (SQLException) ExceptionHelper.extractException(exception, SQLException.class);
if (sqlException != null) {
if ("40001".equals(sqlException.getSQLState()) || "61000".equals(sqlException.getSQLState())) {
if (log.isDebugEnabled())
log.debug("Found a SQL for locking errors: " + sqlException.getSQLState());
appExps = new ApplicationExceptions(new LockedApplicationException(exception));
} else {
int errorCode = sqlException.getErrorCode();
if (c_customSqlErrorCodeStart != null) {
if (errorCode >= c_customSqlErrorCodeStart.intValue() && errorCode <= c_customSqlErrorCodeEnd.intValue()) {
// Extract the first line from the message, since we do not want to pass the SQL stacktrace
String reason = sqlException.getMessage();
if (reason != null) {
int i = reason.indexOf('\n');
if (i > -1)
reason = reason.substring(0, i);
}
if (log.isDebugEnabled())
log.debug("Convert SQLException to SQLApplicationException since it has a custom sqlErrorCode of " + errorCode);
appExps = new ApplicationExceptions(new SQLApplicationException(reason, exception));
} else {
if (log.isDebugEnabled())
log.debug("Ignoring SQLException since its ErrorCode is not custom: " + errorCode);
}
}
}
}
return appExps;
}
Aggregations