Skip to content

Commit 2b09050

Browse files
committed
Merge branch '1.4.x' into 1.5.x
2 parents 0fbe56e + 477c874 commit 2b09050

File tree

2 files changed

+84
-9
lines changed

2 files changed

+84
-9
lines changed

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

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@
1616

1717
package org.springframework.boot.jdbc;
1818

19+
import java.util.Arrays;
20+
import java.util.Collection;
21+
import java.util.Collections;
22+
1923
import org.springframework.util.Assert;
2024
import org.springframework.util.StringUtils;
2125

@@ -107,6 +111,11 @@ public enum DatabaseDriver {
107111
"org.firebirdsql.pool.FBConnectionPoolDataSource",
108112
"SELECT 1 FROM RDB$DATABASE") {
109113

114+
@Override
115+
protected Collection<String> getUrlPrefixes() {
116+
return Collections.singleton("firebirdsql");
117+
}
118+
110119
@Override
111120
protected boolean matchProductName(String productName) {
112121
return super.matchProductName(productName)
@@ -134,6 +143,11 @@ protected boolean matchProductName(String productName) {
134143
"com.ibm.as400.access.AS400JDBCXADataSource",
135144
"SELECT 1 FROM SYSIBM.SYSDUMMY1") {
136145

146+
@Override
147+
protected Collection<String> getUrlPrefixes() {
148+
return Collections.singleton("as400");
149+
}
150+
137151
@Override
138152
protected boolean matchProductName(String productName) {
139153
return super.matchProductName(productName)
@@ -150,7 +164,13 @@ protected boolean matchProductName(String productName) {
150164
* Informix.
151165
*/
152166
INFORMIX("informix", "Informix Dynamic Server", "com.informix.jdbc.IfxDriver", null,
153-
"select count(*) from systables");
167+
"select count(*) from systables") {
168+
169+
@Override
170+
protected Collection<String> getUrlPrefixes() {
171+
return Arrays.asList("informix-sqli", "informix-direct");
172+
}
173+
};
154174

155175
private final String id;
156176

@@ -192,6 +212,10 @@ protected boolean matchProductName(String productName) {
192212
return this.productName != null && this.productName.equalsIgnoreCase(productName);
193213
}
194214

215+
protected Collection<String> getUrlPrefixes() {
216+
return Collections.singleton(this.name().toLowerCase());
217+
}
218+
195219
/**
196220
* Return the driver class name.
197221
* @return the class name or {@code null}
@@ -226,9 +250,11 @@ public static DatabaseDriver fromJdbcUrl(String url) {
226250
Assert.isTrue(url.startsWith("jdbc"), "URL must start with 'jdbc'");
227251
String urlWithoutPrefix = url.substring("jdbc".length()).toLowerCase();
228252
for (DatabaseDriver driver : values()) {
229-
String prefix = ":" + driver.name().toLowerCase() + ":";
230-
if (driver != UNKNOWN && urlWithoutPrefix.startsWith(prefix)) {
231-
return driver;
253+
for (String urlPrefix : driver.getUrlPrefixes()) {
254+
String prefix = ":" + urlPrefix + ":";
255+
if (driver != UNKNOWN && urlWithoutPrefix.startsWith(prefix)) {
256+
return driver;
257+
}
232258
}
233259
}
234260
}

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

Lines changed: 54 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
*
2828
* @author Phillip Webb
2929
* @author Maciej Walkowiak
30+
* @author Stephane Nicoll
3031
*/
3132
public class DatabaseDriverTests {
3233

@@ -70,25 +71,73 @@ public void unknownOnNullProductName() {
7071
public void databaseProductNameLookups() throws Exception {
7172
assertThat(DatabaseDriver.fromProductName("newone"))
7273
.isEqualTo(DatabaseDriver.UNKNOWN);
74+
assertThat(DatabaseDriver.fromProductName("Apache Derby"))
75+
.isEqualTo(DatabaseDriver.DERBY);
76+
assertThat(DatabaseDriver.fromProductName("H2"))
77+
.isEqualTo(DatabaseDriver.H2);
7378
assertThat(DatabaseDriver.fromProductName("HSQL Database Engine"))
7479
.isEqualTo(DatabaseDriver.HSQLDB);
80+
assertThat(DatabaseDriver.fromProductName("SQLite"))
81+
.isEqualTo(DatabaseDriver.SQLITE);
82+
assertThat(DatabaseDriver.fromProductName("MySQL"))
83+
.isEqualTo(DatabaseDriver.MYSQL);
7584
assertThat(DatabaseDriver.fromProductName("Oracle"))
7685
.isEqualTo(DatabaseDriver.ORACLE);
77-
assertThat(DatabaseDriver.fromProductName("Apache Derby"))
78-
.isEqualTo(DatabaseDriver.DERBY);
86+
assertThat(DatabaseDriver.fromProductName("PostgreSQL"))
87+
.isEqualTo(DatabaseDriver.POSTGRESQL);
88+
assertThat(DatabaseDriver.fromProductName("SQL SERVER"))
89+
.isEqualTo(DatabaseDriver.SQLSERVER);
7990
assertThat(DatabaseDriver.fromProductName("DB2")).isEqualTo(DatabaseDriver.DB2);
91+
assertThat(DatabaseDriver.fromProductName("Firebird 2.5.WI"))
92+
.isEqualTo(DatabaseDriver.FIREBIRD);
93+
assertThat(DatabaseDriver.fromProductName("Firebird 2.1.LI"))
94+
.isEqualTo(DatabaseDriver.FIREBIRD);
8095
assertThat(DatabaseDriver.fromProductName("DB2/LINUXX8664"))
8196
.isEqualTo(DatabaseDriver.DB2);
8297
assertThat(DatabaseDriver.fromProductName("DB2 UDB for AS/400"))
8398
.isEqualTo(DatabaseDriver.DB2_AS400);
8499
assertThat(DatabaseDriver.fromProductName("DB3 XDB for AS/400"))
85100
.isEqualTo(DatabaseDriver.DB2_AS400);
101+
assertThat(DatabaseDriver.fromProductName("Teradata"))
102+
.isEqualTo(DatabaseDriver.TERADATA);
86103
assertThat(DatabaseDriver.fromProductName("Informix Dynamic Server"))
87104
.isEqualTo(DatabaseDriver.INFORMIX);
88-
assertThat(DatabaseDriver.fromProductName("Firebird 2.5.WI"))
89-
.isEqualTo(DatabaseDriver.FIREBIRD);
90-
assertThat(DatabaseDriver.fromProductName("Firebird 2.1.LI"))
105+
}
106+
107+
@Test
108+
public void databaseJdbcUrlLookups() {
109+
assertThat(DatabaseDriver.fromJdbcUrl("jdbc:newone://localhost"))
110+
.isEqualTo(DatabaseDriver.UNKNOWN);
111+
assertThat(DatabaseDriver.fromJdbcUrl("jdbc:derby:sample"))
112+
.isEqualTo(DatabaseDriver.DERBY);
113+
assertThat(DatabaseDriver.fromJdbcUrl("jdbc:h2:~/sample"))
114+
.isEqualTo(DatabaseDriver.H2);
115+
assertThat(DatabaseDriver.fromJdbcUrl("jdbc:hsqldb:hsql://localhost"))
116+
.isEqualTo(DatabaseDriver.HSQLDB);
117+
assertThat(DatabaseDriver.fromJdbcUrl("jdbc:sqlite:sample.db"))
118+
.isEqualTo(DatabaseDriver.SQLITE);
119+
assertThat(DatabaseDriver.fromJdbcUrl("jdbc:mysql://localhost:3306/sample"))
120+
.isEqualTo(DatabaseDriver.MYSQL);
121+
assertThat(DatabaseDriver.fromJdbcUrl("jdbc:oracle:thin:@localhost:1521:orcl"))
122+
.isEqualTo(DatabaseDriver.ORACLE);
123+
assertThat(DatabaseDriver.fromJdbcUrl("jdbc:postgresql://127.0.0.1:5432/sample"))
124+
.isEqualTo(DatabaseDriver.POSTGRESQL);
125+
assertThat(DatabaseDriver.fromJdbcUrl("jdbc:jtds:sqlserver://127.0.0.1:1433/sample"))
126+
.isEqualTo(DatabaseDriver.JTDS);
127+
assertThat(DatabaseDriver.fromJdbcUrl("jdbc:sqlserver://127.0.0.1:1433"))
128+
.isEqualTo(DatabaseDriver.SQLSERVER);
129+
assertThat(DatabaseDriver.fromJdbcUrl("jdbc:firebirdsql://localhost/sample"))
91130
.isEqualTo(DatabaseDriver.FIREBIRD);
131+
assertThat(DatabaseDriver.fromJdbcUrl("jdbc:db2://localhost:50000/sample "))
132+
.isEqualTo(DatabaseDriver.DB2);
133+
assertThat(DatabaseDriver.fromJdbcUrl("jdbc:as400://localhost"))
134+
.isEqualTo(DatabaseDriver.DB2_AS400);
135+
assertThat(DatabaseDriver.fromJdbcUrl("jdbc:teradata://localhost/SAMPLE"))
136+
.isEqualTo(DatabaseDriver.TERADATA);
137+
assertThat(DatabaseDriver.fromJdbcUrl("jdbc:informix-sqli://localhost:1533/sample"))
138+
.isEqualTo(DatabaseDriver.INFORMIX);
139+
assertThat(DatabaseDriver.fromJdbcUrl("jdbc:informix-direct://sample"))
140+
.isEqualTo(DatabaseDriver.INFORMIX);
92141
}
93142

94143
}

0 commit comments

Comments
 (0)