org.jdbi.v3.core.Jdbi.getConfig()方法的使用及代码示例

x33g5p2x  于2022-01-21 转载在 其他  
字(6.0k)|赞(0)|评价(0)|浏览(189)

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

Jdbi.getConfig介绍

暂无

代码示例

代码示例来源:origin: jdbi/jdbi

@Test
public void testGlobalDefinedAttribute() {
  assertThat(jdbi.getConfig(SqlStatements.class).getAttribute("foo"))
      .isEqualTo("bar"); // see test-context.xml
}

代码示例来源:origin: jdbi/jdbi

@Override
  public void customizeJdbi(Jdbi jdbi) {
    jdbi.installPlugin(new JsonPlugin());
    jdbi.getConfig(JsonConfig.class).setJsonMapper(new JacksonJsonMapper());
  }
}

代码示例来源:origin: jdbi/jdbi

@Test
public void testAutoInstalledPlugin() {
  assertThat(jdbi.getConfig(SqlStatements.class).getAttribute(AutoPlugin.KEY))
      .isEqualTo(AutoPlugin.VALUE);
}

代码示例来源:origin: jdbi/jdbi

@Test
public void testManualInstalledPlugin() {
  assertThat(jdbi.getConfig(SqlStatements.class).getAttribute(ManualPlugin.KEY))
      .isEqualTo(ManualPlugin.VALUE);
}

代码示例来源:origin: jdbi/jdbi

@Override
  public void customizeJdbi(Jdbi jdbi) {
    jdbi.installPlugin(new JsonPlugin());
    jdbi.getConfig(JsonConfig.class).setJsonMapper(new GsonJsonMapper());
  }
}

代码示例来源:origin: jdbi/jdbi

@Test
public void byNameIsDefault() {
  assertThat(db.getJdbi().getConfig(Enums.class).getDefaultStrategy())
    .isEqualTo(EnumStrategy.BY_NAME);
}

代码示例来源:origin: jdbi/jdbi

@Test
public void testConflictingSourceAnnotations() {
  assertThatThrownBy(() -> db.getJdbi().getConfig(EnumStrategies.class).findStrategy(QualifiedType.of(BiPolar.class)))
    .isInstanceOf(IllegalArgumentException.class);
}

代码示例来源:origin: jdbi/jdbi

@Test
public void testUnannotated() {
  dbRule.getJdbi().getConfig(SqlStatements.class).setUnusedBindingAllowed(true);
  assertThat(dao.unannotated("42")).isTrue();
}

代码示例来源:origin: jdbi/jdbi

@Test
  public void registerByGenericType() {
    @SuppressWarnings("unchecked")
    RowMapper<Iterable<Calendar>> mapper = mock(RowMapper.class);
    GenericType<Iterable<Calendar>> iterableOfCalendarType = new GenericType<Iterable<Calendar>>() {};

    db.registerRowMapper(iterableOfCalendarType, mapper);

    assertThat(db.getConfig(RowMappers.class).findFor(iterableOfCalendarType))
      .contains(mapper);
  }
}

代码示例来源:origin: jdbi/jdbi

@Test
public void testConflictingQualifiers() {
  QualifiedType<RetentionPolicy> type = QualifiedType.of(RetentionPolicy.class).with(EnumByName.class, EnumByOrdinal.class);
  assertThatThrownBy(() -> db.getJdbi().getConfig(EnumStrategies.class).findStrategy(type))
    .isInstanceOf(IllegalArgumentException.class);
}

代码示例来源:origin: jdbi/jdbi

@Before
  public void before() {
    jdbi = db.getJdbi().installPlugin(new Jackson2Plugin());
    jdbi.getConfig(Jackson2Config.class).setMapper(new ObjectMapper().registerModule(new ParameterNamesModule()));
  }
}

代码示例来源:origin: jdbi/jdbi

@Test
public void testLocateConfigDriven() throws Exception {
  Jdbi jdbi = dbRule.getJdbi();
  jdbi.useHandle(h -> {
    h.execute("create table something (id int, name text)");
    h.execute("insert into something (id, name) values (?, ?)", 2, "Alice");
    h.execute("insert into something (id, name) values (?, ?)", 1, "Bob");
  });
  jdbi.getConfig(SqlObjects.class).setSqlLocator(
    (type, method, config) -> config.get(TestConfig.class).sql);
  jdbi.getConfig(TestConfig.class).sql = "select * from something order by id";
  assertThat(jdbi.withExtension(TestDao.class, TestDao::list))
    .containsExactly(new Something(1, "Bob"), new Something(2, "Alice"));
  jdbi.getConfig(TestConfig.class).sql = "select * from something order by name";
  assertThat(jdbi.withExtension(TestDao.class, TestDao::list))
    .containsExactly(new Something(2, "Alice"), new Something(1, "Bob"));
}

代码示例来源:origin: jdbi/jdbi

@Before
public void setUp() {
  dbRule.getJdbi().getConfig(BindTime.Config.class).clock = mockClock;
  Handle handle = dbRule.getSharedHandle();
  handle.execute("CREATE TABLE characters (id INT, name VARCHAR, created TIMESTAMP, modified TIMESTAMP)");
}

代码示例来源:origin: jdbi/jdbi

@SuppressWarnings("unchecked")
private <M extends Map<Long, String>> void testMapCollector(Class<? extends Map> erasedType, GenericType<M> genericType) {
  JdbiCollectors registry = dbRule.getJdbi().getConfig(JdbiCollectors.class);
  assertThat(registry.findElementTypeFor(genericType.getType()))
      .contains(new GenericType<Map.Entry<Long, String>>(){}.getType());
  Collector<Map.Entry<Long, String>, ?, M> collector = (Collector<Map.Entry<Long, String>, ?, M>) registry
      .findFor(genericType.getType())
      .orElseThrow(() -> new IllegalStateException("Missing collector for " + genericType));
  M map = Stream.of(entry(1L, "foo"), entry(2L, "bar")).collect(collector);
  assertThat(map)
      .isInstanceOf(erasedType)
      .containsExactly(entry(1L, "foo"), entry(2L, "bar"));
}

代码示例来源:origin: jdbi/jdbi

protected Handle openHandle() {
  tc = new TTC();
  dbRule.getJdbi().getConfig(SqlStatements.class).setTimingCollector(tc);
  return dbRule.getJdbi().open();
}

代码示例来源:origin: jdbi/jdbi

@Before
public void before() {
  logger = new TalkativeSqlLogger();
  dbRule.getJdbi().getConfig(SqlStatements.class).setSqlLogger(logger);
  h = dbRule.getJdbi().open();
}

代码示例来源:origin: jdbi/jdbi

@Before
public void before() {
  logger = new TalkativeSqlLogger();
  dbRule.getJdbi().getConfig(SqlStatements.class).setSqlLogger(logger);
  h = dbRule.getJdbi().open();
}

代码示例来源:origin: jdbi/jdbi

@Before
public void before() {
  TimestampedFactory.setTimeSource(clock::withZone);
  dbRule.getJdbi().getConfig(TimestampedConfig.class).setTimezone(GMT_PLUS_2);
  personDAO = dbRule.getJdbi().onDemand(PersonDAO.class);
  personDAO.createTable();
}

代码示例来源:origin: jdbi/jdbi

@Before
public void before() {
  db.getJdbi().getConfig(JsonConfig.class).setJsonMapper(jsonMapper);
  db.getJdbi().useHandle(h -> h.createUpdate("create table foo(bar varchar)").execute());
}

代码示例来源:origin: jdbi/jdbi

@Before
public void setUp() {
  dbRule.getJdbi().setTransactionHandler(new SerializableTransactionRunner());
  dbRule.getJdbi().getConfig(SerializableTransactionRunner.Configuration.class)
    .setMaxRetries(MAX_RETRIES)
    .setOnFailure(onFailure)
    .setOnSuccess(onSuccess);
}

相关文章