Browse Source

Merge pull request #36991 from ramilS

* pr/36991:
  Polish "Reuse JOOQ helper to determine the dialect to use"
  Reuse JOOQ helper to determine the dialect to use

Closes gh-36991
pull/37013/head
Stephane Nicoll 2 years ago
parent
commit
5762e41b6e
  1. 23
      spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jooq/SqlDialectLookup.java

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

@ -1,5 +1,5 @@
/* /*
* Copyright 2012-2022 the original author or authors. * Copyright 2012-2023 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -16,7 +16,8 @@
package org.springframework.boot.autoconfigure.jooq; package org.springframework.boot.autoconfigure.jooq;
import java.sql.DatabaseMetaData; import java.sql.Connection;
import java.sql.SQLException;
import javax.sql.DataSource; import javax.sql.DataSource;
@ -25,14 +26,12 @@ import org.apache.commons.logging.LogFactory;
import org.jooq.SQLDialect; import org.jooq.SQLDialect;
import org.jooq.tools.jdbc.JDBCUtils; import org.jooq.tools.jdbc.JDBCUtils;
import org.springframework.jdbc.support.JdbcUtils;
import org.springframework.jdbc.support.MetaDataAccessException;
/** /**
* Utility to lookup well known {@link SQLDialect SQLDialects} from a {@link DataSource}. * Utility to lookup well known {@link SQLDialect SQLDialects} from a {@link DataSource}.
* *
* @author Michael Simons * @author Michael Simons
* @author Lukas Eder * @author Lukas Eder
* @author Ramil Saetov
*/ */
final class SqlDialectLookup { final class SqlDialectLookup {
@ -47,18 +46,12 @@ final class SqlDialectLookup {
* @return the most suitable {@link SQLDialect} * @return the most suitable {@link SQLDialect}
*/ */
static SQLDialect getDialect(DataSource dataSource) { static SQLDialect getDialect(DataSource dataSource) {
if (dataSource == null) {
return SQLDialect.DEFAULT;
}
try { try {
String url = JdbcUtils.extractDatabaseMetaData(dataSource, DatabaseMetaData::getURL); Connection connection = (dataSource != null) ? dataSource.getConnection() : null;
SQLDialect sqlDialect = JDBCUtils.dialect(url); return JDBCUtils.dialect(connection);
if (sqlDialect != null) {
return sqlDialect;
}
} }
catch (MetaDataAccessException ex) { catch (SQLException ex) {
logger.warn("Unable to determine jdbc url from datasource", ex); logger.warn("Unable to determine dialect from datasource", ex);
} }
return SQLDialect.DEFAULT; return SQLDialect.DEFAULT;
} }

Loading…
Cancel
Save