use of com.google.inject.Binding in project gerrit by GerritCodeReview.
the class InitDatabase method run.
@Override
public void run() {
ui.header("SQL Database");
Set<String> allowedValues = Sets.newTreeSet();
Injector i = Guice.createInjector(PRODUCTION, new DatabaseConfigModule(site));
List<Binding<DatabaseConfigInitializer>> dbConfigBindings = i.findBindingsByType(new TypeLiteral<DatabaseConfigInitializer>() {
});
for (Binding<DatabaseConfigInitializer> binding : dbConfigBindings) {
Annotation annotation = binding.getKey().getAnnotation();
if (annotation instanceof Named) {
allowedValues.add(((Named) annotation).value());
}
}
if (!Strings.isNullOrEmpty(database.get("url")) && Strings.isNullOrEmpty(database.get("type"))) {
database.set("type", "jdbc");
}
String dbType = database.select("Database server type", "type", "h2", allowedValues);
DatabaseConfigInitializer dci = i.getInstance(Key.get(DatabaseConfigInitializer.class, Names.named(dbType.toLowerCase())));
if (dci instanceof MySqlInitializer) {
libraries.mysqlDriver.downloadRequired();
} else if (dci instanceof MariaDbInitializer) {
libraries.mariadbDriver.downloadRequired();
} else if (dci instanceof OracleInitializer) {
libraries.oracleDriver.downloadRequired();
} else if (dci instanceof DB2Initializer) {
libraries.db2Driver.downloadRequired();
} else if (dci instanceof HANAInitializer) {
libraries.hanaDriver.downloadRequired();
}
dci.initConfig(database);
// Initialize UUID for NoteDb on first init.
String id = idSection.get(GerritServerIdProvider.KEY);
if (Strings.isNullOrEmpty(id)) {
idSection.set(GerritServerIdProvider.KEY, GerritServerIdProvider.generate());
}
}
Aggregations