From 053323f58b3b779fca1331a94f81008bfe526bf9 Mon Sep 17 00:00:00 2001 From: anudeepg Date: Wed, 10 Feb 2021 19:25:18 +0100 Subject: [PATCH 1/2] Fix database name detection logic for MariaDB See gh-25173 --- .../org/springframework/boot/jdbc/DatabaseDriver.java | 9 +-------- .../springframework/boot/jdbc/DatabaseDriverTests.java | 1 + 2 files changed, 2 insertions(+), 8 deletions(-) diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/jdbc/DatabaseDriver.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/jdbc/DatabaseDriver.java index 1bb245c7f5..b064194ac7 100644 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/jdbc/DatabaseDriver.java +++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/jdbc/DatabaseDriver.java @@ -70,8 +70,7 @@ public enum DatabaseDriver { /** * Maria DB. */ - MARIADB("MySQL", "org.mariadb.jdbc.Driver", "org.mariadb.jdbc.MariaDbDataSource", "SELECT 1") { - + MARIADB("MariaDB", "org.mariadb.jdbc.Driver", "org.mariadb.jdbc.MariaDbDataSource", "SELECT 1") { @Override public String getId() { return "mysql"; @@ -122,7 +121,6 @@ public enum DatabaseDriver { */ SQLSERVER("Microsoft SQL Server", "com.microsoft.sqlserver.jdbc.SQLServerDriver", "com.microsoft.sqlserver.jdbc.SQLServerXADataSource", "SELECT 1") { - @Override protected boolean matchProductName(String productName) { return super.matchProductName(productName) || "SQL SERVER".equalsIgnoreCase(productName); @@ -135,7 +133,6 @@ public enum DatabaseDriver { */ FIREBIRD("Firebird", "org.firebirdsql.jdbc.FBDriver", "org.firebirdsql.ds.FBXADataSource", "SELECT 1 FROM RDB$DATABASE") { - @Override protected Collection getUrlPrefixes() { return Arrays.asList("firebirdsql", "firebird"); @@ -152,7 +149,6 @@ public enum DatabaseDriver { * DB2 Server. */ DB2("DB2", "com.ibm.db2.jcc.DB2Driver", "com.ibm.db2.jcc.DB2XADataSource", "SELECT 1 FROM SYSIBM.SYSDUMMY1") { - @Override protected boolean matchProductName(String productName) { return super.matchProductName(productName) || productName.toLowerCase(Locale.ENGLISH).startsWith("db2/"); @@ -164,7 +160,6 @@ public enum DatabaseDriver { */ DB2_AS400("DB2 UDB for AS/400", "com.ibm.as400.access.AS400JDBCDriver", "com.ibm.as400.access.AS400JDBCXADataSource", "SELECT 1 FROM SYSIBM.SYSDUMMY1") { - @Override public String getId() { return "db2"; @@ -190,7 +185,6 @@ public enum DatabaseDriver { * Informix. */ INFORMIX("Informix Dynamic Server", "com.informix.jdbc.IfxDriver", null, "select count(*) from systables") { - @Override protected Collection getUrlPrefixes() { return Arrays.asList("informix-sqli", "informix-direct"); @@ -208,7 +202,6 @@ public enum DatabaseDriver { * Testcontainers. */ TESTCONTAINERS(null, "org.testcontainers.jdbc.ContainerDatabaseDriver") { - @Override protected Collection getUrlPrefixes() { return Collections.singleton("tc"); diff --git a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/jdbc/DatabaseDriverTests.java b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/jdbc/DatabaseDriverTests.java index 29f282e3a8..e884c7b820 100644 --- a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/jdbc/DatabaseDriverTests.java +++ b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/jdbc/DatabaseDriverTests.java @@ -69,6 +69,7 @@ class DatabaseDriverTests { assertThat(DatabaseDriver.fromProductName("HSQL Database Engine")).isEqualTo(DatabaseDriver.HSQLDB); assertThat(DatabaseDriver.fromProductName("SQLite")).isEqualTo(DatabaseDriver.SQLITE); assertThat(DatabaseDriver.fromProductName("MySQL")).isEqualTo(DatabaseDriver.MYSQL); + assertThat(DatabaseDriver.fromProductName("MariaDB")).isEqualTo(DatabaseDriver.MARIADB); assertThat(DatabaseDriver.fromProductName("Oracle")).isEqualTo(DatabaseDriver.ORACLE); assertThat(DatabaseDriver.fromProductName("PostgreSQL")).isEqualTo(DatabaseDriver.POSTGRESQL); assertThat(DatabaseDriver.fromProductName("Amazon Redshift")).isEqualTo(DatabaseDriver.REDSHIFT); From 9b7581a8effbfeb4396bdde1e978d29dbb9a178b Mon Sep 17 00:00:00 2001 From: Stephane Nicoll Date: Thu, 11 Feb 2021 08:40:56 +0100 Subject: [PATCH 2/2] Polish "Fix database name detection logic for MariaDB" See gh-25173 --- .../autoconfigure/batch/BatchDataSourceInitializer.java | 5 ++++- .../quartz/QuartzDataSourceInitializer.java | 4 ++-- .../org/springframework/boot/jdbc/DatabaseDriver.java | 9 ++++++++- .../springframework/boot/jdbc/DatabaseDriverTests.java | 2 +- 4 files changed, 15 insertions(+), 5 deletions(-) diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/batch/BatchDataSourceInitializer.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/batch/BatchDataSourceInitializer.java index d673bcb4c5..4abf9de4a0 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/batch/BatchDataSourceInitializer.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/batch/BatchDataSourceInitializer.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2019 the original author or authors. + * Copyright 2012-2021 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. @@ -57,6 +57,9 @@ public class BatchDataSourceInitializer extends AbstractDataSourceInitializer { if ("oracle".equals(databaseName)) { return "oracle10g"; } + if ("mariadb".equals(databaseName)) { + return "mysql"; + } return databaseName; } diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/quartz/QuartzDataSourceInitializer.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/quartz/QuartzDataSourceInitializer.java index 5f94f84d62..aeab5908c4 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/quartz/QuartzDataSourceInitializer.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/quartz/QuartzDataSourceInitializer.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2019 the original author or authors. + * Copyright 2012-2021 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. @@ -62,7 +62,7 @@ public class QuartzDataSourceInitializer extends AbstractDataSourceInitializer { if ("db2".equals(databaseName)) { return "db2_v95"; } - if ("mysql".equals(databaseName)) { + if ("mysql".equals(databaseName) || "mariadb".equals(databaseName)) { return "mysql_innodb"; } if ("postgresql".equals(databaseName)) { diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/jdbc/DatabaseDriver.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/jdbc/DatabaseDriver.java index b064194ac7..1229f447c5 100644 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/jdbc/DatabaseDriver.java +++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/jdbc/DatabaseDriver.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2020 the original author or authors. + * Copyright 2012-2021 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. @@ -71,6 +71,7 @@ public enum DatabaseDriver { * Maria DB. */ MARIADB("MariaDB", "org.mariadb.jdbc.Driver", "org.mariadb.jdbc.MariaDbDataSource", "SELECT 1") { + @Override public String getId() { return "mysql"; @@ -121,6 +122,7 @@ public enum DatabaseDriver { */ SQLSERVER("Microsoft SQL Server", "com.microsoft.sqlserver.jdbc.SQLServerDriver", "com.microsoft.sqlserver.jdbc.SQLServerXADataSource", "SELECT 1") { + @Override protected boolean matchProductName(String productName) { return super.matchProductName(productName) || "SQL SERVER".equalsIgnoreCase(productName); @@ -133,6 +135,7 @@ public enum DatabaseDriver { */ FIREBIRD("Firebird", "org.firebirdsql.jdbc.FBDriver", "org.firebirdsql.ds.FBXADataSource", "SELECT 1 FROM RDB$DATABASE") { + @Override protected Collection getUrlPrefixes() { return Arrays.asList("firebirdsql", "firebird"); @@ -149,6 +152,7 @@ public enum DatabaseDriver { * DB2 Server. */ DB2("DB2", "com.ibm.db2.jcc.DB2Driver", "com.ibm.db2.jcc.DB2XADataSource", "SELECT 1 FROM SYSIBM.SYSDUMMY1") { + @Override protected boolean matchProductName(String productName) { return super.matchProductName(productName) || productName.toLowerCase(Locale.ENGLISH).startsWith("db2/"); @@ -160,6 +164,7 @@ public enum DatabaseDriver { */ DB2_AS400("DB2 UDB for AS/400", "com.ibm.as400.access.AS400JDBCDriver", "com.ibm.as400.access.AS400JDBCXADataSource", "SELECT 1 FROM SYSIBM.SYSDUMMY1") { + @Override public String getId() { return "db2"; @@ -185,6 +190,7 @@ public enum DatabaseDriver { * Informix. */ INFORMIX("Informix Dynamic Server", "com.informix.jdbc.IfxDriver", null, "select count(*) from systables") { + @Override protected Collection getUrlPrefixes() { return Arrays.asList("informix-sqli", "informix-direct"); @@ -202,6 +208,7 @@ public enum DatabaseDriver { * Testcontainers. */ TESTCONTAINERS(null, "org.testcontainers.jdbc.ContainerDatabaseDriver") { + @Override protected Collection getUrlPrefixes() { return Collections.singleton("tc"); diff --git a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/jdbc/DatabaseDriverTests.java b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/jdbc/DatabaseDriverTests.java index e884c7b820..4621fe7d58 100644 --- a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/jdbc/DatabaseDriverTests.java +++ b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/jdbc/DatabaseDriverTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2020 the original author or authors. + * Copyright 2012-2021 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.