Merge "Merge branch 'stable-2.14'"

This commit is contained in:
David Pursehouse
2017-08-12 20:43:45 +00:00
committed by Gerrit Code Review

View File

@@ -41,6 +41,12 @@ import org.slf4j.LoggerFactory;
public abstract class JdbcAccountPatchReviewStore public abstract class JdbcAccountPatchReviewStore
implements AccountPatchReviewStore, LifecycleListener { implements AccountPatchReviewStore, LifecycleListener {
private static final String ACCOUNT_PATCH_REVIEW_DB = "accountPatchReviewDb";
private static final String H2_DB = "h2";
private static final String MARIADB = "mariadb";
private static final String MYSQL = "mysql";
private static final String POSTGRESQL = "postgresql";
private static final String URL = "url";
private static final Logger log = LoggerFactory.getLogger(JdbcAccountPatchReviewStore.class); private static final Logger log = LoggerFactory.getLogger(JdbcAccountPatchReviewStore.class);
public static class Module extends LifecycleModule { public static class Module extends LifecycleModule {
@@ -52,20 +58,20 @@ public abstract class JdbcAccountPatchReviewStore
@Override @Override
protected void configure() { protected void configure() {
String url = cfg.getString("accountPatchReviewDb", null, "url"); String url = cfg.getString(ACCOUNT_PATCH_REVIEW_DB, null, URL);
if (url == null || url.contains("h2")) { if (url == null || url.contains(H2_DB)) {
DynamicItem.bind(binder(), AccountPatchReviewStore.class) DynamicItem.bind(binder(), AccountPatchReviewStore.class)
.to(H2AccountPatchReviewStore.class); .to(H2AccountPatchReviewStore.class);
listener().to(H2AccountPatchReviewStore.class); listener().to(H2AccountPatchReviewStore.class);
} else if (url.contains("postgresql")) { } else if (url.contains(POSTGRESQL)) {
DynamicItem.bind(binder(), AccountPatchReviewStore.class) DynamicItem.bind(binder(), AccountPatchReviewStore.class)
.to(PostgresqlAccountPatchReviewStore.class); .to(PostgresqlAccountPatchReviewStore.class);
listener().to(PostgresqlAccountPatchReviewStore.class); listener().to(PostgresqlAccountPatchReviewStore.class);
} else if (url.contains("mysql")) { } else if (url.contains(MYSQL)) {
DynamicItem.bind(binder(), AccountPatchReviewStore.class) DynamicItem.bind(binder(), AccountPatchReviewStore.class)
.to(MysqlAccountPatchReviewStore.class); .to(MysqlAccountPatchReviewStore.class);
listener().to(MysqlAccountPatchReviewStore.class); listener().to(MysqlAccountPatchReviewStore.class);
} else if (url.contains("mariadb")) { } else if (url.contains(MARIADB)) {
DynamicItem.bind(binder(), AccountPatchReviewStore.class) DynamicItem.bind(binder(), AccountPatchReviewStore.class)
.to(MariaDBAccountPatchReviewStore.class); .to(MariaDBAccountPatchReviewStore.class);
listener().to(MariaDBAccountPatchReviewStore.class); listener().to(MariaDBAccountPatchReviewStore.class);
@@ -80,19 +86,21 @@ public abstract class JdbcAccountPatchReviewStore
public static JdbcAccountPatchReviewStore createAccountPatchReviewStore( public static JdbcAccountPatchReviewStore createAccountPatchReviewStore(
Config cfg, SitePaths sitePaths) { Config cfg, SitePaths sitePaths) {
String url = cfg.getString("accountPatchReviewDb", null, "url"); String url = cfg.getString(ACCOUNT_PATCH_REVIEW_DB, null, URL);
if (url == null || url.contains("h2")) { if (url == null || url.contains(H2_DB)) {
return new H2AccountPatchReviewStore(cfg, sitePaths); return new H2AccountPatchReviewStore(cfg, sitePaths);
} else if (url.contains("postgresql")) {
return new PostgresqlAccountPatchReviewStore(cfg, sitePaths);
} else if (url.contains("mysql")) {
return new MysqlAccountPatchReviewStore(cfg, sitePaths);
} else if (url.contains("mariadb")) {
return new MariaDBAccountPatchReviewStore(cfg, sitePaths);
} else {
throw new IllegalArgumentException(
"unsupported driver type for account patch reviews db: " + url);
} }
if (url.contains(POSTGRESQL)) {
return new PostgresqlAccountPatchReviewStore(cfg, sitePaths);
}
if (url.contains(MYSQL)) {
return new MysqlAccountPatchReviewStore(cfg, sitePaths);
}
if (url.contains(MARIADB)) {
return new MariaDBAccountPatchReviewStore(cfg, sitePaths);
}
throw new IllegalArgumentException(
"unsupported driver type for account patch reviews db: " + url);
} }
protected JdbcAccountPatchReviewStore(Config cfg, SitePaths sitePaths) { protected JdbcAccountPatchReviewStore(Config cfg, SitePaths sitePaths) {
@@ -104,7 +112,7 @@ public abstract class JdbcAccountPatchReviewStore
} }
private static String getUrl(@GerritServerConfig Config cfg, SitePaths sitePaths) { private static String getUrl(@GerritServerConfig Config cfg, SitePaths sitePaths) {
String url = cfg.getString("accountPatchReviewDb", null, "url"); String url = cfg.getString(ACCOUNT_PATCH_REVIEW_DB, null, URL);
if (url == null) { if (url == null) {
return H2.createUrl(sitePaths.db_dir.resolve("account_patch_reviews")); return H2.createUrl(sitePaths.db_dir.resolve("account_patch_reviews"));
} }
@@ -113,13 +121,13 @@ public abstract class JdbcAccountPatchReviewStore
protected static DataSource createDataSource(String url) { protected static DataSource createDataSource(String url) {
BasicDataSource datasource = new BasicDataSource(); BasicDataSource datasource = new BasicDataSource();
if (url.contains("postgresql")) { if (url.contains(POSTGRESQL)) {
datasource.setDriverClassName("org.postgresql.Driver"); datasource.setDriverClassName("org.postgresql.Driver");
} else if (url.contains("h2")) { } else if (url.contains(H2_DB)) {
datasource.setDriverClassName("org.h2.Driver"); datasource.setDriverClassName("org.h2.Driver");
} else if (url.contains("mysql")) { } else if (url.contains(MYSQL)) {
datasource.setDriverClassName("com.mysql.jdbc.Driver"); datasource.setDriverClassName("com.mysql.jdbc.Driver");
} else if (url.contains("mariadb")) { } else if (url.contains(MARIADB)) {
datasource.setDriverClassName("org.mariadb.jdbc.Driver"); datasource.setDriverClassName("org.mariadb.jdbc.Driver");
} }
datasource.setUrl(url); datasource.setUrl(url);