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

com.github.zhengframework.jdbc.DSLContextProvider 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.jooq.DSLContext;
import org.jooq.SQLDialect;
import org.jooq.impl.DSL;

public class DSLContextProvider implements Provider {

  private final Annotation qualifier;

  private final Provider injectorProvider;

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

  @Override
  public DSLContext get() {
    DataSource dataSource;
    SQLDialect sqlDialect;
    Injector injector = injectorProvider.get();
    if (qualifier == null) {
      dataSource = injector.getInstance(Key.get(DataSource.class));
      sqlDialect = injector.getInstance(Key.get(SQLDialect.class));
    } else {
      dataSource = injector
          .getInstance(Key.get(DataSource.class, qualifier));
      sqlDialect = injector.getInstance(Key.get(SQLDialect.class, qualifier));
    }
    return DSL.using(dataSource, sqlDialect);
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy