Skip to content

Commit c4cb0e7

Browse files
committed
Remove dead code in DomaPersistenceExceptionTranslator
gh-12
1 parent ed656fe commit c4cb0e7

File tree

2 files changed

+10
-24
lines changed

2 files changed

+10
-24
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 & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -53,18 +53,6 @@ public void testOccurSqlExecutionException() {
5353
is("select * from todo where todo_id = ?"));
5454
}
5555

56-
@Test
57-
public void testOccurUniqueConstraintException() {
58-
DataAccessException dataAccessException = translator.translateExceptionIfPossible(
59-
new UniqueConstraintException(SqlLogType.FORMATTED, SqlKind.INSERT,
60-
"insert into todo (todo_id, title) values (?, ?)",
61-
"insert into todo (todo_id, title) values ('000000001', 'Title')",
62-
"TodoDao/insert.sql", new SQLException()));
63-
assertThat(dataAccessException, is(instanceOf(UncategorizedSQLException.class)));
64-
assertThat(UncategorizedSQLException.class.cast(dataAccessException).getSql(),
65-
is("insert into todo (todo_id, title) values (?, ?)"));
66-
}
67-
6856
@Test
6957
public void testThrowOptimisticLockingFailureException() {
7058
DataAccessException dataAccessException = translator.translateExceptionIfPossible(
@@ -82,7 +70,7 @@ public void testThrowDuplicateKeyException() {
8270
new UniqueConstraintException(SqlLogType.FORMATTED, SqlKind.INSERT,
8371
"insert into todo (todo_id, title) values (?, ?)",
8472
"insert into todo (todo_id, title) values ('000000001', 'Title')",
85-
"TodoDao/insert.sql", null));
73+
"TodoDao/insert.sql", new SQLException()));
8674
assertThat(dataAccessException, is(instanceOf(DuplicateKeyException.class)));
8775
}
8876

0 commit comments

Comments
 (0)