Search in sources :

Example 1 with InvalidResultSetAccessException

use of cn.taketoday.jdbc.InvalidResultSetAccessException in project today-framework by TAKETODAY.

the class SQLErrorCodeSQLExceptionTranslatorTests method errorCodeTranslation.

@Test
public void errorCodeTranslation() {
    SQLExceptionTranslator sext = new SQLErrorCodeSQLExceptionTranslator(ERROR_CODES);
    SQLException badSqlEx = new SQLException("", "", 1);
    BadSqlGrammarException bsgex = (BadSqlGrammarException) sext.translate("task", "SQL", badSqlEx);
    assertThat(bsgex.getSql()).isEqualTo("SQL");
    assertThat((Object) bsgex.getSQLException()).isEqualTo(badSqlEx);
    SQLException invResEx = new SQLException("", "", 4);
    InvalidResultSetAccessException irsex = (InvalidResultSetAccessException) sext.translate("task", "SQL", invResEx);
    assertThat(irsex.getSql()).isEqualTo("SQL");
    assertThat((Object) irsex.getSQLException()).isEqualTo(invResEx);
    checkTranslation(sext, 5, DataAccessResourceFailureException.class);
    checkTranslation(sext, 6, DataIntegrityViolationException.class);
    checkTranslation(sext, 7, CannotAcquireLockException.class);
    checkTranslation(sext, 8, DeadlockLoserDataAccessException.class);
    checkTranslation(sext, 9, CannotSerializeTransactionException.class);
    checkTranslation(sext, 10, DuplicateKeyException.class);
    SQLException dupKeyEx = new SQLException("", "", 10);
    DataAccessException dksex = sext.translate("task", "SQL", dupKeyEx);
    assertThat(DataIntegrityViolationException.class.isInstance(dksex)).as("Not instance of DataIntegrityViolationException").isTrue();
    // Test fallback. We assume that no database will ever return this error code,
    // but 07xxx will be bad grammar picked up by the fallback SQLState translator
    SQLException sex = new SQLException("", "07xxx", 666666666);
    BadSqlGrammarException bsgex2 = (BadSqlGrammarException) sext.translate("task", "SQL2", sex);
    assertThat(bsgex2.getSql()).isEqualTo("SQL2");
    assertThat((Object) bsgex2.getSQLException()).isEqualTo(sex);
}
Also used : BadSqlGrammarException(cn.taketoday.jdbc.BadSqlGrammarException) SQLException(java.sql.SQLException) InvalidResultSetAccessException(cn.taketoday.jdbc.InvalidResultSetAccessException) DeadlockLoserDataAccessException(cn.taketoday.dao.DeadlockLoserDataAccessException) DataAccessException(cn.taketoday.dao.DataAccessException) DataIntegrityViolationException(cn.taketoday.dao.DataIntegrityViolationException) Test(org.junit.jupiter.api.Test)

Example 2 with InvalidResultSetAccessException

use of cn.taketoday.jdbc.InvalidResultSetAccessException in project today-infrastructure by TAKETODAY.

the class SQLErrorCodeSQLExceptionTranslatorTests method errorCodeTranslation.

@Test
public void errorCodeTranslation() {
    SQLExceptionTranslator sext = new SQLErrorCodeSQLExceptionTranslator(ERROR_CODES);
    SQLException badSqlEx = new SQLException("", "", 1);
    BadSqlGrammarException bsgex = (BadSqlGrammarException) sext.translate("task", "SQL", badSqlEx);
    assertThat(bsgex.getSql()).isEqualTo("SQL");
    assertThat((Object) bsgex.getSQLException()).isEqualTo(badSqlEx);
    SQLException invResEx = new SQLException("", "", 4);
    InvalidResultSetAccessException irsex = (InvalidResultSetAccessException) sext.translate("task", "SQL", invResEx);
    assertThat(irsex.getSql()).isEqualTo("SQL");
    assertThat((Object) irsex.getSQLException()).isEqualTo(invResEx);
    checkTranslation(sext, 5, DataAccessResourceFailureException.class);
    checkTranslation(sext, 6, DataIntegrityViolationException.class);
    checkTranslation(sext, 7, CannotAcquireLockException.class);
    checkTranslation(sext, 8, DeadlockLoserDataAccessException.class);
    checkTranslation(sext, 9, CannotSerializeTransactionException.class);
    checkTranslation(sext, 10, DuplicateKeyException.class);
    SQLException dupKeyEx = new SQLException("", "", 10);
    DataAccessException dksex = sext.translate("task", "SQL", dupKeyEx);
    assertThat(DataIntegrityViolationException.class.isInstance(dksex)).as("Not instance of DataIntegrityViolationException").isTrue();
    // Test fallback. We assume that no database will ever return this error code,
    // but 07xxx will be bad grammar picked up by the fallback SQLState translator
    SQLException sex = new SQLException("", "07xxx", 666666666);
    BadSqlGrammarException bsgex2 = (BadSqlGrammarException) sext.translate("task", "SQL2", sex);
    assertThat(bsgex2.getSql()).isEqualTo("SQL2");
    assertThat((Object) bsgex2.getSQLException()).isEqualTo(sex);
}
Also used : BadSqlGrammarException(cn.taketoday.jdbc.BadSqlGrammarException) SQLException(java.sql.SQLException) InvalidResultSetAccessException(cn.taketoday.jdbc.InvalidResultSetAccessException) DeadlockLoserDataAccessException(cn.taketoday.dao.DeadlockLoserDataAccessException) DataAccessException(cn.taketoday.dao.DataAccessException) DataIntegrityViolationException(cn.taketoday.dao.DataIntegrityViolationException) Test(org.junit.jupiter.api.Test)

Aggregations

DataAccessException (cn.taketoday.dao.DataAccessException)2 DataIntegrityViolationException (cn.taketoday.dao.DataIntegrityViolationException)2 DeadlockLoserDataAccessException (cn.taketoday.dao.DeadlockLoserDataAccessException)2 BadSqlGrammarException (cn.taketoday.jdbc.BadSqlGrammarException)2 InvalidResultSetAccessException (cn.taketoday.jdbc.InvalidResultSetAccessException)2 SQLException (java.sql.SQLException)2 Test (org.junit.jupiter.api.Test)2