From 44cd3352a5426388af0c5d0d6abefa9a491ed569 Mon Sep 17 00:00:00 2001 From: Lukas Eder Date: Tue, 2 Jan 2018 12:17:49 +0100 Subject: [PATCH] Detect jOOQ SQLDialect through jOOQ's JDBCUtils This change updates SqlDialectLookup to delegate to jOOQ's JDBCUtils rather than creating an additional mapping between org.springframework.boot.jdbc.DatabaseDriver and org.jooq.SQLDialect. This has the following advantages: 1. jOOQ's `SQLDialect` to URL mappings are already maintained by jOOQ, so no additional changes will be necessary to Spring Boot in the future. 2. Delegating to jOOQ means that the mapping also works for the commercial jOOQ distributions, e.g. when working with DB2, Oracle, SQL Server, etc., as the JDBCUtils of the commercial distribution also contains the relevant logic to map to e.g. `SQLDialect.DB2`, `SQLDialect.ORACLE`, `SQLDialect.SQLSERVER` (which are not available from the open source distribution linked by Spring Boot by default). Closes gh-11466 --- .../autoconfigure/jooq/SqlDialectLookup.java | 24 +++---------------- 1 file changed, 3 insertions(+), 21 deletions(-) diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jooq/SqlDialectLookup.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jooq/SqlDialectLookup.java index 5a4b875a07..91fd197307 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jooq/SqlDialectLookup.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jooq/SqlDialectLookup.java @@ -16,17 +16,13 @@ package org.springframework.boot.autoconfigure.jooq; -import java.util.Collections; -import java.util.EnumMap; -import java.util.Map; - import javax.sql.DataSource; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.jooq.SQLDialect; +import org.jooq.tools.jdbc.JDBCUtils; -import org.springframework.boot.jdbc.DatabaseDriver; import org.springframework.jdbc.support.JdbcUtils; import org.springframework.jdbc.support.MetaDataAccessException; @@ -34,25 +30,12 @@ import org.springframework.jdbc.support.MetaDataAccessException; * Utility to lookup well known {@link SQLDialect SQLDialects} from a {@link DataSource}. * * @author Michael Simons + * @author Lukas Eder */ final class SqlDialectLookup { private static final Log logger = LogFactory.getLog(SqlDialectLookup.class); - private static final Map LOOKUP; - - static { - Map map = new EnumMap<>(DatabaseDriver.class); - map.put(DatabaseDriver.DERBY, SQLDialect.DERBY); - map.put(DatabaseDriver.H2, SQLDialect.H2); - map.put(DatabaseDriver.HSQLDB, SQLDialect.HSQLDB); - map.put(DatabaseDriver.MARIADB, SQLDialect.MARIADB); - map.put(DatabaseDriver.MYSQL, SQLDialect.MYSQL); - map.put(DatabaseDriver.POSTGRESQL, SQLDialect.POSTGRES); - map.put(DatabaseDriver.SQLITE, SQLDialect.SQLITE); - LOOKUP = Collections.unmodifiableMap(map); - } - private SqlDialectLookup() { } @@ -67,8 +50,7 @@ final class SqlDialectLookup { } try { String url = JdbcUtils.extractDatabaseMetaData(dataSource, "getURL"); - DatabaseDriver driver = DatabaseDriver.fromJdbcUrl(url); - SQLDialect sqlDialect = LOOKUP.get(driver); + SQLDialect sqlDialect = JDBCUtils.dialect(url); if (sqlDialect != null) { return sqlDialect; }