|
1 | 1 | /*
|
2 |
| - * Copyright 2012-2021 the original author or authors. |
| 2 | + * Copyright 2012-2023 the original author or authors. |
3 | 3 | *
|
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License");
|
5 | 5 | * you may not use this file except in compliance with the License.
|
|
16 | 16 |
|
17 | 17 | package org.springframework.boot.jdbc.init;
|
18 | 18 |
|
| 19 | +import java.sql.DatabaseMetaData; |
19 | 20 | import java.util.ArrayList;
|
20 | 21 | import java.util.Collections;
|
21 | 22 | import java.util.LinkedHashMap;
|
|
26 | 27 | import javax.sql.DataSource;
|
27 | 28 |
|
28 | 29 | import org.springframework.boot.jdbc.DatabaseDriver;
|
| 30 | +import org.springframework.jdbc.support.JdbcUtils; |
29 | 31 | import org.springframework.util.Assert;
|
30 | 32 | import org.springframework.util.ObjectUtils;
|
31 | 33 | import org.springframework.util.StringUtils;
|
@@ -89,7 +91,6 @@ public PlatformPlaceholderDatabaseDriverResolver withDriverPlatform(DatabaseDriv
|
89 | 91 | * @param dataSource the DataSource from which the {@link DatabaseDriver} is derived
|
90 | 92 | * @param values the values in which placeholders are resolved
|
91 | 93 | * @return the values with their placeholders resolved
|
92 |
| - * @see DatabaseDriver#fromDataSource(DataSource) |
93 | 94 | */
|
94 | 95 | public List<String> resolveAll(DataSource dataSource, String... values) {
|
95 | 96 | Assert.notNull(dataSource, "DataSource must not be null");
|
@@ -134,7 +135,14 @@ private String determinePlatform(DataSource dataSource) {
|
134 | 135 | }
|
135 | 136 |
|
136 | 137 | DatabaseDriver getDatabaseDriver(DataSource dataSource) {
|
137 |
| - return DatabaseDriver.fromDataSource(dataSource); |
| 138 | + try { |
| 139 | + String productName = JdbcUtils.commonDatabaseName( |
| 140 | + JdbcUtils.extractDatabaseMetaData(dataSource, DatabaseMetaData::getDatabaseProductName)); |
| 141 | + return DatabaseDriver.fromProductName(productName); |
| 142 | + } |
| 143 | + catch (Exception ex) { |
| 144 | + throw new IllegalStateException("Failed to determine DatabaseDriver", ex); |
| 145 | + } |
138 | 146 | }
|
139 | 147 |
|
140 | 148 | }
|
0 commit comments