Skip to content

Commit 9cbd6bd

Browse files
committed
Merge pull request #44954 from MelleD
* pr/44954: Polish contribution Use proper default exception translator if no dbName is available Closes gh-44954
2 parents b218e9d + cd31127 commit 9cbd6bd

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jooq/DefaultExceptionTranslatorExecuteListener.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2024 the original author or authors.
2+
* Copyright 2012-2025 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -26,8 +26,8 @@
2626

2727
import org.springframework.dao.DataAccessException;
2828
import org.springframework.jdbc.support.SQLErrorCodeSQLExceptionTranslator;
29+
import org.springframework.jdbc.support.SQLExceptionSubclassTranslator;
2930
import org.springframework.jdbc.support.SQLExceptionTranslator;
30-
import org.springframework.jdbc.support.SQLStateSQLExceptionTranslator;
3131
import org.springframework.util.Assert;
3232

3333
/**
@@ -114,7 +114,7 @@ public SQLExceptionTranslator apply(ExecuteContext context) {
114114
private SQLExceptionTranslator apply(SQLDialect dialect) {
115115
String dbName = getSpringDbName(dialect);
116116
return (dbName != null) ? new SQLErrorCodeSQLExceptionTranslator(dbName)
117-
: new SQLStateSQLExceptionTranslator();
117+
: new SQLExceptionSubclassTranslator();
118118
}
119119

120120
private String getSpringDbName(SQLDialect dialect) {

spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jooq/DefaultExceptionTranslatorExecuteListenerTests.java

+10-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2024 the original author or authors.
2+
* Copyright 2012-2025 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -17,6 +17,7 @@
1717
package org.springframework.boot.autoconfigure.jooq;
1818

1919
import java.sql.SQLException;
20+
import java.sql.SQLSyntaxErrorException;
2021
import java.util.function.Function;
2122

2223
import org.jooq.Configuration;
@@ -93,12 +94,19 @@ private ExecuteContext mockContext(SQLDialect dialect, SQLException sqlException
9394

9495
static Object[] exceptionTranslatesSqlExceptions() {
9596
return new Object[] { new Object[] { SQLDialect.DERBY, sqlException("42802") },
97+
new Object[] { SQLDialect.DERBY, new SQLSyntaxErrorException() },
9698
new Object[] { SQLDialect.H2, sqlException(42000) },
99+
new Object[] { SQLDialect.H2, new SQLSyntaxErrorException() },
97100
new Object[] { SQLDialect.HSQLDB, sqlException(-22) },
101+
new Object[] { SQLDialect.HSQLDB, new SQLSyntaxErrorException() },
98102
new Object[] { SQLDialect.MARIADB, sqlException(1054) },
103+
new Object[] { SQLDialect.MARIADB, new SQLSyntaxErrorException() },
99104
new Object[] { SQLDialect.MYSQL, sqlException(1054) },
105+
new Object[] { SQLDialect.MYSQL, new SQLSyntaxErrorException() },
100106
new Object[] { SQLDialect.POSTGRES, sqlException("03000") },
101-
new Object[] { SQLDialect.SQLITE, sqlException("21000") } };
107+
new Object[] { SQLDialect.POSTGRES, new SQLSyntaxErrorException() },
108+
new Object[] { SQLDialect.SQLITE, sqlException("21000") },
109+
new Object[] { SQLDialect.SQLITE, new SQLSyntaxErrorException() } };
102110
}
103111

104112
private static SQLException sqlException(String sqlState) {

0 commit comments

Comments
 (0)