From 5d27c7e501142ee1a383aa483d4bc82054dfd91c Mon Sep 17 00:00:00 2001 From: Stephane Nicoll Date: Fri, 10 Mar 2017 16:27:44 +0100 Subject: [PATCH] Handle non supported JOOQ dialect This commit uses a fallback translator if the JOOQ Dialect in use is not one we support. Closes gh-8521 --- .../boot/autoconfigure/jooq/JooqExceptionTranslator.java | 9 ++++++--- .../autoconfigure/jooq/JooqExceptionTranslatorTests.java | 5 +++-- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jooq/JooqExceptionTranslator.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jooq/JooqExceptionTranslator.java index 3118e4bed21..93be2b591b3 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jooq/JooqExceptionTranslator.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jooq/JooqExceptionTranslator.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2016 the original author or authors. + * Copyright 2012-2017 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -36,6 +36,7 @@ import org.springframework.jdbc.support.SQLStateSQLExceptionTranslator; * @author Lukas Eder * @author Andreas Ahlenstorf * @author Phillip Webb + * @author Stephane Nicoll */ class JooqExceptionTranslator extends DefaultExecuteListener { @@ -58,8 +59,10 @@ class JooqExceptionTranslator extends DefaultExecuteListener { private SQLExceptionTranslator getTranslator(ExecuteContext context) { SQLDialect dialect = context.configuration().dialect(); if (dialect != null && dialect.thirdParty() != null) { - return new SQLErrorCodeSQLExceptionTranslator( - dialect.thirdParty().springDbName()); + String dbName = dialect.thirdParty().springDbName(); + if (dbName != null) { + return new SQLErrorCodeSQLExceptionTranslator(dbName); + } } return new SQLStateSQLExceptionTranslator(); } diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jooq/JooqExceptionTranslatorTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jooq/JooqExceptionTranslatorTests.java index 9cdb0730b86..35bb938cb00 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jooq/JooqExceptionTranslatorTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jooq/JooqExceptionTranslatorTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2016 the original author or authors. + * Copyright 2012-2017 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -58,7 +58,8 @@ public class JooqExceptionTranslatorTests { new Object[] { SQLDialect.POSTGRES, sqlException("03000") }, new Object[] { SQLDialect.POSTGRES_9_3, sqlException("03000") }, new Object[] { SQLDialect.POSTGRES_9_4, sqlException("03000") }, - new Object[] { SQLDialect.POSTGRES_9_5, sqlException("03000") } }; + new Object[] { SQLDialect.POSTGRES_9_5, sqlException("03000") }, + new Object[] { SQLDialect.SQLITE, sqlException("21000") }}; } private static SQLException sqlException(String sqlState) {