Skip to content

Commit 3afd21e

Browse files
kazuki43zoomaking
authored andcommitted
Remove dead code in DomaPersistenceExceptionTranslator fixes #12
2 parents 27c924c + c4cb0e7 commit 3afd21e

File tree

2 files changed

+10
-26
lines changed

2 files changed

+10
-26
lines changed

doma-spring-boot-autoconfigure/src/main/java/org/seasar/doma/boot/autoconfigure/DomaPersistenceExceptionTranslator.java

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -43,17 +43,6 @@ public DataAccessException translateExceptionIfPossible(RuntimeException ex) {
4343
return null;
4444
}
4545

46-
if (ex.getCause() instanceof SQLException) {
47-
SQLException e = (SQLException) ex.getCause();
48-
String sql = null;
49-
if (ex instanceof SqlExecutionException) {
50-
sql = ((SqlExecutionException) ex).getRawSql();
51-
}
52-
else if (ex instanceof UniqueConstraintException) {
53-
sql = ((UniqueConstraintException) ex).getRawSql();
54-
}
55-
return translator.translate(ex.getMessage(), sql, e);
56-
}
5746
if (ex instanceof OptimisticLockException) {
5847
return new OptimisticLockingFailureException(ex.getMessage(), ex);
5948
}
@@ -72,6 +61,15 @@ else if (ex instanceof UnknownColumnException
7261
return new TypeMismatchDataAccessException(ex.getMessage(), ex);
7362
}
7463

64+
if (ex.getCause() instanceof SQLException) {
65+
SQLException e = (SQLException) ex.getCause();
66+
String sql = null;
67+
if (ex instanceof SqlExecutionException) {
68+
sql = ((SqlExecutionException) ex).getRawSql();
69+
}
70+
return translator.translate(ex.getMessage(), sql, e);
71+
}
72+
7573
return new UncategorizedDataAccessException(ex.getMessage(), ex) {
7674
};
7775
}

doma-spring-boot-autoconfigure/src/test/java/org/seasar/doma/boot/autoconfigure/DomaPersistenceExceptionTranslatorTest.java

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -54,20 +54,6 @@ public void testOccurSqlExecutionException() {
5454
is("select * from todo where todo_id = ?"));
5555
}
5656

57-
@Test
58-
public void testOccurUniqueConstraintException() {
59-
DataAccessException dataAccessException = translator
60-
.translateExceptionIfPossible(new UniqueConstraintException(
61-
SqlLogType.FORMATTED,
62-
SqlKind.INSERT,
63-
"insert into todo (todo_id, title) values (?, ?)",
64-
"insert into todo (todo_id, title) values ('000000001', 'Title')",
65-
"TodoDao/insert.sql", new SQLException()));
66-
assertThat(dataAccessException, is(instanceOf(UncategorizedSQLException.class)));
67-
assertThat(UncategorizedSQLException.class.cast(dataAccessException).getSql(),
68-
is("insert into todo (todo_id, title) values (?, ?)"));
69-
}
70-
7157
@Test
7258
public void testThrowOptimisticLockingFailureException() {
7359
DataAccessException dataAccessException = translator
@@ -89,7 +75,7 @@ public void testThrowDuplicateKeyException() {
8975
SqlKind.INSERT,
9076
"insert into todo (todo_id, title) values (?, ?)",
9177
"insert into todo (todo_id, title) values ('000000001', 'Title')",
92-
"TodoDao/insert.sql", null));
78+
"TodoDao/insert.sql", new SQLException()));
9379
assertThat(dataAccessException, is(instanceOf(DuplicateKeyException.class)));
9480
}
9581

0 commit comments

Comments
 (0)