All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.github.zhengframework.jdbc.migrate.FlywayMigrateModule Maven / Gradle / Ivy

There is a newer version: 1.8.0
Show newest version
package com.github.zhengframework.jdbc.migrate;

import static com.google.inject.name.Names.named;

import com.github.zhengframework.configuration.ConfigurationAwareModule;
import com.github.zhengframework.configuration.ConfigurationBeanMapper;
import com.github.zhengframework.jdbc.ManagedSchema;
import com.google.inject.Key;
import com.google.inject.multibindings.OptionalBinder;
import java.util.Map;
import java.util.Map.Entry;
import lombok.EqualsAndHashCode;

@EqualsAndHashCode(callSuper = false)
public class FlywayMigrateModule extends ConfigurationAwareModule {

  @Override
  protected void configure() {
    Map flywayConfigMap = ConfigurationBeanMapper
        .resolve(getConfiguration(), FlywayConfig.class);
    for (Entry entry : flywayConfigMap.entrySet()) {
      String name = entry.getKey();
      FlywayConfig flywayConfig = entry.getValue();
      if (name.isEmpty()) {
        bind(FlywayConfig.class).toInstance(flywayConfig);
        OptionalBinder.newOptionalBinder(binder(), Key.get(ManagedSchema.class))
            .setBinding().toInstance(new FlywayManagedSchema(flywayConfig));
      } else {
        bind(Key.get(FlywayConfig.class, named(name))).toInstance(flywayConfig);
        OptionalBinder.newOptionalBinder(binder(), Key.get(ManagedSchema.class, named(name)))
            .setBinding().toInstance(new FlywayManagedSchema(flywayConfig));
      }

    }

  }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy