Skip to content

Commit

Permalink
Remove dead code in DomaPersistenceExceptionTranslator fixes #12
Browse files Browse the repository at this point in the history
  • Loading branch information
kazuki43zoo authored and making committed Jul 24, 2016
2 parents 27c924c + c4cb0e7 commit 3afd21e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,17 +43,6 @@ public DataAccessException translateExceptionIfPossible(RuntimeException ex) {
return null;
}

if (ex.getCause() instanceof SQLException) {
SQLException e = (SQLException) ex.getCause();
String sql = null;
if (ex instanceof SqlExecutionException) {
sql = ((SqlExecutionException) ex).getRawSql();
}
else if (ex instanceof UniqueConstraintException) {
sql = ((UniqueConstraintException) ex).getRawSql();
}
return translator.translate(ex.getMessage(), sql, e);
}
if (ex instanceof OptimisticLockException) {
return new OptimisticLockingFailureException(ex.getMessage(), ex);
}
Expand All @@ -72,6 +61,15 @@ else if (ex instanceof UnknownColumnException
return new TypeMismatchDataAccessException(ex.getMessage(), ex);
}

if (ex.getCause() instanceof SQLException) {
SQLException e = (SQLException) ex.getCause();
String sql = null;
if (ex instanceof SqlExecutionException) {
sql = ((SqlExecutionException) ex).getRawSql();
}
return translator.translate(ex.getMessage(), sql, e);
}

return new UncategorizedDataAccessException(ex.getMessage(), ex) {
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,20 +54,6 @@ public void testOccurSqlExecutionException() {
is("select * from todo where todo_id = ?"));
}

@Test
public void testOccurUniqueConstraintException() {
DataAccessException dataAccessException = translator
.translateExceptionIfPossible(new UniqueConstraintException(
SqlLogType.FORMATTED,
SqlKind.INSERT,
"insert into todo (todo_id, title) values (?, ?)",
"insert into todo (todo_id, title) values ('000000001', 'Title')",
"TodoDao/insert.sql", new SQLException()));
assertThat(dataAccessException, is(instanceOf(UncategorizedSQLException.class)));
assertThat(UncategorizedSQLException.class.cast(dataAccessException).getSql(),
is("insert into todo (todo_id, title) values (?, ?)"));
}

@Test
public void testThrowOptimisticLockingFailureException() {
DataAccessException dataAccessException = translator
Expand All @@ -89,7 +75,7 @@ public void testThrowDuplicateKeyException() {
SqlKind.INSERT,
"insert into todo (todo_id, title) values (?, ?)",
"insert into todo (todo_id, title) values ('000000001', 'Title')",
"TodoDao/insert.sql", null));
"TodoDao/insert.sql", new SQLException()));
assertThat(dataAccessException, is(instanceOf(DuplicateKeyException.class)));
}

Expand Down

0 comments on commit 3afd21e

Please sign in to comment.