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

com.github.zhengframework.jdbc.Sql2oProvider Maven / Gradle / Ivy

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

import com.google.inject.Injector;
import com.google.inject.Key;
import java.lang.annotation.Annotation;
import javax.inject.Provider;
import javax.sql.DataSource;
import org.sql2o.Sql2o;

public class Sql2oProvider implements Provider {

  private final Annotation qualifier;
  private Provider injectorProvider;

  public Sql2oProvider(Annotation qualifier, Provider injectorProvider) {
    this.qualifier = qualifier;
    this.injectorProvider = injectorProvider;
  }

  @Override
  public Sql2o get() {
    DataSource dataSource;

    Injector injector = injectorProvider.get();
    if (qualifier == null) {
      dataSource = injector.getInstance(Key.get(DataSource.class));
    } else {
      dataSource = injector
          .getInstance(Key.get(DataSource.class, qualifier));
    }
    return new Sql2o(dataSource);
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy