org.jooby.Env.get()方法的使用及代码示例

x33g5p2x  于2022-01-19 转载在 其他  
字(9.6k)|赞(0)|评价(0)|浏览(168)

本文整理了Java中org.jooby.Env.get()方法的一些代码示例,展示了Env.get()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Env.get()方法的具体详情如下:
包路径:org.jooby.Env
类名称:Env
方法名:get

Env.get介绍

[英]Get an object by key or empty when missing.
[中]按键获取对象,丢失时为空。

代码示例

代码示例来源:origin: jooby-project/jooby

/**
  * Get an object by key or empty when missing.
  *
  * @param key Object key.
  * @param <T> Object type.
  * @return Object valur or empty.
  */
 @Nonnull
 default <T> Optional<T> get(Class<T> key) {
  return get(Key.get(key));
 }
}

代码示例来源:origin: jooby-project/jooby

@Override
 public void configure(final Env env, final Config config, final Binder binder) {
  Key<DataSource> dskey = Key.get(DataSource.class, Names.named(name));
  DataSource ds = env.get(dskey)
    .orElseThrow(() -> new NoSuchElementException("DataSource missing: " + dskey));
  Database db = Database.fromDataSource(ds);

  env.serviceKey().generate(Database.class, name, k -> binder.bind(k).toInstance(db));

  // close on shutdown
  env.onStop(db::close);
 }
}

代码示例来源:origin: jooby-project/jooby

@Override
public void configure(final Env env, final Config conf, final Binder binder) {
 Key<DataSource> dskey = Key.get(DataSource.class, Names.named(name));
 DataSource ds = env.get(dskey)
   .orElseThrow(() -> new NoSuchElementException("DataSource missing: " + dskey));
 String dbtype = env.get(Key.get(String.class, Names.named(name + ".dbtype")))
   .orElse("unknown");
 SQLTemplates templates = this.templates.apply(dbtype);
 Configuration querydslconf = new Configuration(templates);
 if (callback != null) {
  callback.accept(querydslconf, conf);
 }
 SQLQueryFactory sqfp = new SQLQueryFactory(querydslconf, ds);
 ServiceKey serviceKey = env.serviceKey();
 serviceKey.generate(SQLTemplates.class, name, k -> binder.bind(k).toInstance(templates));
 serviceKey.generate(Configuration.class, name, k -> binder.bind(k).toInstance(querydslconf));
 serviceKey.generate(SQLQueryFactory.class, name, k -> binder.bind(k).toInstance(sqfp));
}

代码示例来源:origin: jooby-project/jooby

@Override
 public void configure(final Env env, final Config conf, final Binder binder) {
  Key<DataSource> dskey = Key.get(DataSource.class, Names.named(name));
  Supplier<NoSuchElementException> noSuchElement = () -> new NoSuchElementException(
    "DataSource missing: " + dskey);
  HikariDataSource ds = (HikariDataSource) env.get(dskey).orElseThrow(noSuchElement);
  Configuration jooqconf = new DefaultConfiguration();
  ConnectionProvider dscp = new DataSourceConnectionProvider(ds);
  jooqconf.set(JDBCUtils.dialect(env.get(Key.get(String.class, Names.named(name + ".url")))
    .orElseThrow(noSuchElement)));
  jooqconf.set(dscp);
  jooqconf.set(new DefaultTransactionProvider(dscp));

  if (callback != null) {
   callback.accept(jooqconf, conf);
  }

  ServiceKey serviceKey = env.serviceKey();
  serviceKey.generate(Configuration.class, name, k -> binder.bind(k).toInstance(jooqconf));

  Provider<DSLContext> dsl = () -> DSL.using(jooqconf);
  serviceKey.generate(DSLContext.class, name, k -> binder.bind(k).toProvider(dsl));
 }
}

代码示例来源:origin: jooby-project/jooby

.filter(it -> !env.get(Key.get(DataSource.class, Names.named(it))).isPresent())
  .collect(Collectors.toSet());
if (names.size() == 0) {

代码示例来源:origin: jooby-project/jooby

@Override
public void configure(final Env env, final Config conf, final Binder binder) {
 Config $base = flyway(conf.getConfig("flyway"));
 Config $flyway = Try.apply(() -> flyway(conf.getConfig(name)).withFallback($base))
   .orElse($base);
 Flyway flyway = new Flyway();
 Properties props = props($flyway);
 flyway.configure(props);
 if (!props.containsKey("flyway.url")) {
  Key<DataSource> dskey = Key.get(DataSource.class, Names.named(name));
  DataSource dataSource = env.get(dskey)
    .orElseThrow(() -> new NoSuchElementException("DataSource missing: " + dskey));
  flyway.setDataSource(dataSource);
 }
 // bind
 env.serviceKey()
   .generate(Flyway.class, name, key -> binder.bind(key).toInstance(flyway));
 // commands:
 Iterable<Command> cmds = commands(conf);
 // eager initialization
 cmds.forEach(cmd -> cmd.run(flyway));
}

代码示例来源:origin: jooby-project/jooby

@Override public void configure(Env env, Config conf, Binder binder) throws Throwable {
 Key<DataSource> dskey = Key.get(DataSource.class, Names.named(name));
 DataSource dataSource = env.get(dskey)
   .orElseThrow(() -> new NoSuchElementException("DataSource missing: " + dskey));
 Jdbi jdbi = Jdbi.create(dataSource);

代码示例来源:origin: jooby-project/jooby

@SuppressWarnings({"unchecked", "rawtypes"})
@Override
public void configure(final Env env, final Config config, final Binder binder) {
 Key<DataSource> dskey = Key.get(DataSource.class, Names.named(name));
 DataSource ds = env.get(dskey)
   .orElseThrow(() -> new NoSuchElementException("DataSource missing: " + dskey));
 DBI dbi = new DBI2(ds);
 dbi.setSQLLog(new SLF4JLog());
 dbi.registerArgumentFactory(new OptionalArgumentFactory());
 dbi.registerArgumentFactory(new IterableArgumentFactory());
 dbi.registerContainerFactory(new OptionalContainerFactory());
 dbi.setStatementRewriter(new ExpandedStmtRewriter());
 ServiceKey serviceKey = env.serviceKey();
 serviceKey.generate(DBI.class, name, k -> binder.bind(k).toInstance(dbi));
 serviceKey.generate(Handle.class, name, k -> binder.bind(k).toProvider(() -> dbi.open()));
 sqlObjects.forEach(sqlObject -> binder.bind(sqlObject)
   .toProvider((Provider) () -> dbi.open(sqlObject)));
 if (callback != null) {
  callback.accept(dbi, config);
 }
}

代码示例来源:origin: jooby-project/jooby

DataSource ds = env.get(dskey)
  .orElseThrow(() -> new NoSuchElementException("DataSource missing: " + dskey));

代码示例来源:origin: jooby-project/jooby

@Override
public void configure(final Env env, final Config conf, final Binder binder) {
 Key<DataSource> dskey = Key.get(DataSource.class, Names.named(name));
 DataSource dataSource = env.get(dskey)
   .orElseThrow(() -> new NoSuchElementException("DataSource missing: " + dskey));

代码示例来源:origin: jooby-project/jooby

@Override
public void configure(final Env env, final Config conf, final Binder binder) {
 Key<DataSource> dskey = Key.get(DataSource.class, Names.named(name));
 DataSource ds = env.get(dskey)
   .orElseThrow(() -> new NoSuchElementException("DataSource missing: " + dskey));

代码示例来源:origin: org.jooby/jooby

/**
  * Get an object by key or empty when missing.
  *
  * @param key Object key.
  * @param <T> Object type.
  * @return Object valur or empty.
  */
 @Nonnull
 default <T> Optional<T> get(Class<T> key) {
  return get(Key.get(key));
 }
}

代码示例来源:origin: org.jooby/jooby-querydsl

@Override
public void configure(final Env env, final Config conf, final Binder binder) {
 Key<DataSource> dskey = Key.get(DataSource.class, Names.named(name));
 DataSource ds = env.get(dskey)
   .orElseThrow(() -> new NoSuchElementException("DataSource missing: " + dskey));
 String dbtype = env.get(Key.get(String.class, Names.named(name + ".dbtype")))
   .orElse("unknown");
 SQLTemplates templates = this.templates.apply(dbtype);
 Configuration querydslconf = new Configuration(templates);
 if (callback != null) {
  callback.accept(querydslconf, conf);
 }
 SQLQueryFactory sqfp = new SQLQueryFactory(querydslconf, ds);
 ServiceKey serviceKey = env.serviceKey();
 serviceKey.generate(SQLTemplates.class, name, k -> binder.bind(k).toInstance(templates));
 serviceKey.generate(Configuration.class, name, k -> binder.bind(k).toInstance(querydslconf));
 serviceKey.generate(SQLQueryFactory.class, name, k -> binder.bind(k).toInstance(sqfp));
}

代码示例来源:origin: org.jooby/jooby-flyway

@Override
public void configure(final Env env, final Config conf, final Binder binder) {
 Config $base = flyway(conf.getConfig("flyway"));
 Config $flyway = Try.apply(() -> flyway(conf.getConfig(name)).withFallback($base))
   .orElse($base);
 Flyway flyway = new Flyway();
 Properties props = props($flyway);
 flyway.configure(props);
 if (!props.containsKey("flyway.url")) {
  Key<DataSource> dskey = Key.get(DataSource.class, Names.named(name));
  DataSource dataSource = env.get(dskey)
    .orElseThrow(() -> new NoSuchElementException("DataSource missing: " + dskey));
  flyway.setDataSource(dataSource);
 }
 // bind
 env.serviceKey()
   .generate(Flyway.class, name, key -> binder.bind(key).toInstance(flyway));
 // commands:
 Iterable<Command> cmds = commands(conf);
 // eager initialization
 cmds.forEach(cmd -> cmd.run(flyway));
}

代码示例来源:origin: org.jooby/jooby-jdbi

@SuppressWarnings({"unchecked", "rawtypes"})
@Override
public void configure(final Env env, final Config config, final Binder binder) {
 Key<DataSource> dskey = Key.get(DataSource.class, Names.named(name));
 DataSource ds = env.get(dskey)
   .orElseThrow(() -> new NoSuchElementException("DataSource missing: " + dskey));
 DBI dbi = new DBI2(ds);
 dbi.setSQLLog(new SLF4JLog());
 dbi.registerArgumentFactory(new OptionalArgumentFactory());
 dbi.registerArgumentFactory(new IterableArgumentFactory());
 dbi.registerContainerFactory(new OptionalContainerFactory());
 dbi.setStatementRewriter(new ExpandedStmtRewriter());
 ServiceKey serviceKey = env.serviceKey();
 serviceKey.generate(DBI.class, name, k -> binder.bind(k).toInstance(dbi));
 serviceKey.generate(Handle.class, name, k -> binder.bind(k).toProvider(() -> dbi.open()));
 sqlObjects.forEach(sqlObject -> binder.bind(sqlObject)
   .toProvider((Provider) () -> dbi.open(sqlObject)));
 if (callback != null) {
  callback.accept(dbi, config);
 }
}

代码示例来源:origin: org.jooby/jooby-ebean

DataSource ds = env.get(dskey)
  .orElseThrow(() -> new NoSuchElementException("DataSource missing: " + dskey));

代码示例来源:origin: org.jooby/jooby-requery

@Override
public void configure(final Env env, final Config conf, final Binder binder) {
 Key<DataSource> dskey = Key.get(DataSource.class, Names.named(name));
 DataSource dataSource = env.get(dskey)
   .orElseThrow(() -> new NoSuchElementException("DataSource missing: " + dskey));

代码示例来源:origin: org.jooby/jooby-hbm

@Override
public void configure(final Env env, final Config conf, final Binder binder) {
 Key<DataSource> dskey = Key.get(DataSource.class, Names.named(name));
 DataSource ds = env.get(dskey)
   .orElseThrow(() -> new NoSuchElementException("DataSource missing: " + dskey));

相关文章