Search in sources :

Example 91 with Binding

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());
    }
}
Also used : Binding(com.google.inject.Binding) Named(com.google.inject.name.Named) Annotation(java.lang.annotation.Annotation) Injector(com.google.inject.Injector)

Aggregations

Binding (com.google.inject.Binding)91 Injector (com.google.inject.Injector)57 Key (com.google.inject.Key)35 AbstractModule (com.google.inject.AbstractModule)33 InstanceBinding (com.google.inject.spi.InstanceBinding)23 Map (java.util.Map)21 HttpServletRequest (javax.servlet.http.HttpServletRequest)21 Element (com.google.inject.spi.Element)18 Module (com.google.inject.Module)17 ProviderInstanceBinding (com.google.inject.spi.ProviderInstanceBinding)17 LinkedKeyBinding (com.google.inject.spi.LinkedKeyBinding)16 HttpServlet (javax.servlet.http.HttpServlet)14 HttpServletResponse (javax.servlet.http.HttpServletResponse)13 DefaultBindingTargetVisitor (com.google.inject.spi.DefaultBindingTargetVisitor)12 ProviderKeyBinding (com.google.inject.spi.ProviderKeyBinding)12 ServletContext (javax.servlet.ServletContext)12 ImmutableMap (com.google.common.collect.ImmutableMap)11 HashMap (java.util.HashMap)11 TypeLiteral (com.google.inject.TypeLiteral)10 MapBinderBinding (com.google.inject.multibindings.MapBinderBinding)10