init: Guess JDBC driver class if not configured
If the JDBC URL points to one of the 3 standard supported database types, guess the Driver class name automatically. This fixes up any old installations that are missing the driver class. Bug: issue 1870 Change-Id: I897ab3a16cf91766a848980302182ab1070f65cb
This commit is contained in:
@@ -16,13 +16,28 @@ package com.google.gerrit.pgm.init;
|
||||
|
||||
import static com.google.gerrit.pgm.init.InitUtil.username;
|
||||
|
||||
class JDBCInitializer implements DatabaseConfigInitializer {
|
||||
import com.google.common.base.Strings;
|
||||
|
||||
class JDBCInitializer implements DatabaseConfigInitializer {
|
||||
@Override
|
||||
public void initConfig(Section databaseSection) {
|
||||
databaseSection.string("Driver class name", "driver", null);
|
||||
databaseSection.string("URL", "url", null);
|
||||
databaseSection.string("Database username", "username", username());
|
||||
databaseSection.password("username", "password");
|
||||
public void initConfig(Section database) {
|
||||
database.string("URL", "url", null);
|
||||
guessDriver(database);
|
||||
database.string("Driver class name", "driver", null);
|
||||
database.string("Database username", "username", username());
|
||||
database.password("username", "password");
|
||||
}
|
||||
|
||||
private void guessDriver(Section database) {
|
||||
String url = Strings.emptyToNull(database.get("url"));
|
||||
if (url != null && Strings.isNullOrEmpty(database.get("driver"))) {
|
||||
if (url.startsWith("jdbc:h2:")) {
|
||||
database.set("driver", "org.h2.Driver");
|
||||
} else if (url.startsWith("jdbc:mysql:")) {
|
||||
database.set("driver", "com.mysql.jdbc.Driver");
|
||||
} else if (url.startsWith("jdbc:postgresql:")) {
|
||||
database.set("driver", "org.postgresql.Driver");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user