Skip to content

Commit 9b7581a

Browse files
committed
Polish "Fix database name detection logic for MariaDB"
See gh-25173
1 parent 053323f commit 9b7581a

File tree

4 files changed

+15
-5
lines changed

4 files changed

+15
-5
lines changed

spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/batch/BatchDataSourceInitializer.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2019 the original author or authors.
2+
* Copyright 2012-2021 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.
@@ -57,6 +57,9 @@ protected String getDatabaseName() {
5757
if ("oracle".equals(databaseName)) {
5858
return "oracle10g";
5959
}
60+
if ("mariadb".equals(databaseName)) {
61+
return "mysql";
62+
}
6063
return databaseName;
6164
}
6265

spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/quartz/QuartzDataSourceInitializer.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2019 the original author or authors.
2+
* Copyright 2012-2021 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.
@@ -62,7 +62,7 @@ protected String getDatabaseName() {
6262
if ("db2".equals(databaseName)) {
6363
return "db2_v95";
6464
}
65-
if ("mysql".equals(databaseName)) {
65+
if ("mysql".equals(databaseName) || "mariadb".equals(databaseName)) {
6666
return "mysql_innodb";
6767
}
6868
if ("postgresql".equals(databaseName)) {

spring-boot-project/spring-boot/src/main/java/org/springframework/boot/jdbc/DatabaseDriver.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2020 the original author or authors.
2+
* Copyright 2012-2021 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.
@@ -71,6 +71,7 @@ public enum DatabaseDriver {
7171
* Maria DB.
7272
*/
7373
MARIADB("MariaDB", "org.mariadb.jdbc.Driver", "org.mariadb.jdbc.MariaDbDataSource", "SELECT 1") {
74+
7475
@Override
7576
public String getId() {
7677
return "mysql";
@@ -121,6 +122,7 @@ protected Collection<String> getUrlPrefixes() {
121122
*/
122123
SQLSERVER("Microsoft SQL Server", "com.microsoft.sqlserver.jdbc.SQLServerDriver",
123124
"com.microsoft.sqlserver.jdbc.SQLServerXADataSource", "SELECT 1") {
125+
124126
@Override
125127
protected boolean matchProductName(String productName) {
126128
return super.matchProductName(productName) || "SQL SERVER".equalsIgnoreCase(productName);
@@ -133,6 +135,7 @@ protected boolean matchProductName(String productName) {
133135
*/
134136
FIREBIRD("Firebird", "org.firebirdsql.jdbc.FBDriver", "org.firebirdsql.ds.FBXADataSource",
135137
"SELECT 1 FROM RDB$DATABASE") {
138+
136139
@Override
137140
protected Collection<String> getUrlPrefixes() {
138141
return Arrays.asList("firebirdsql", "firebird");
@@ -149,6 +152,7 @@ protected boolean matchProductName(String productName) {
149152
* DB2 Server.
150153
*/
151154
DB2("DB2", "com.ibm.db2.jcc.DB2Driver", "com.ibm.db2.jcc.DB2XADataSource", "SELECT 1 FROM SYSIBM.SYSDUMMY1") {
155+
152156
@Override
153157
protected boolean matchProductName(String productName) {
154158
return super.matchProductName(productName) || productName.toLowerCase(Locale.ENGLISH).startsWith("db2/");
@@ -160,6 +164,7 @@ protected boolean matchProductName(String productName) {
160164
*/
161165
DB2_AS400("DB2 UDB for AS/400", "com.ibm.as400.access.AS400JDBCDriver",
162166
"com.ibm.as400.access.AS400JDBCXADataSource", "SELECT 1 FROM SYSIBM.SYSDUMMY1") {
167+
163168
@Override
164169
public String getId() {
165170
return "db2";
@@ -185,6 +190,7 @@ protected boolean matchProductName(String productName) {
185190
* Informix.
186191
*/
187192
INFORMIX("Informix Dynamic Server", "com.informix.jdbc.IfxDriver", null, "select count(*) from systables") {
193+
188194
@Override
189195
protected Collection<String> getUrlPrefixes() {
190196
return Arrays.asList("informix-sqli", "informix-direct");
@@ -202,6 +208,7 @@ protected Collection<String> getUrlPrefixes() {
202208
* Testcontainers.
203209
*/
204210
TESTCONTAINERS(null, "org.testcontainers.jdbc.ContainerDatabaseDriver") {
211+
205212
@Override
206213
protected Collection<String> getUrlPrefixes() {
207214
return Collections.singleton("tc");

spring-boot-project/spring-boot/src/test/java/org/springframework/boot/jdbc/DatabaseDriverTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2020 the original author or authors.
2+
* Copyright 2012-2021 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.

0 commit comments

Comments
 (0)