@Override
public DataAccessException translateExceptionIfPossible(RuntimeException re) {
DataAccessException e = null;
// first make sure the root exception is actually an org.h2.jdbc.JdbcSQLException
if (ExceptionUtils.getRootCause(re) instanceof JdbcSQLException) {
JdbcSQLException rootException = (JdbcSQLException)ExceptionUtils.getRootCause(re);
// now translate the H2 specific error codes into Rave's common application Exceptions
// add more error codes to the switch statement that should be specifically trapped
switch(rootException.getErrorCode()) {
case ErrorCode.DUPLICATE_KEY_1: {
e = new DuplicateItemException("DUPLICATE_ITEM", rootException);
break;
}
default: {
e = new TranslatedH2Exception(rootException.getErrorCode(), "ERROR", "Unknown Database Error");
break;
}
}
} else {
// we got a RuntimeException that wasn't an org.h2.jdbc.JdbcSQLException