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

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

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

Jdbi.configure介绍

暂无

代码示例

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

@Override
  public void customizeJdbi(Jdbi jdbi) {
    jdbi.configure(configClass, configurer);
  }
}

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

@Test
public void testNonsenseRetryCount() {
  assertThatThrownBy(() -> dbRule.getJdbi().configure(SerializableTransactionRunner.Configuration.class, config -> config.setMaxRetries(-1)))
    .isInstanceOf(IllegalArgumentException.class)
    .hasMessageContaining("Set a number >= 0");
}

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

@Before
public void setUp() {
  Jdbi db = dbRule.getJdbi();
  ParameterCustomizerFactory defaultParameterCustomizerFactory = (sqlObjectType, method, param, index, type) -> {
    invocationCounter.incrementAndGet();
    return (stmt, arg) -> stmt.bind("mybind" + index, arg);
  };
  db.configure(SqlObjects.class, c -> c.setDefaultParameterCustomizerFactory(defaultParameterCustomizerFactory));
  handle = db.open();
}

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

@Before
public void setUp() {
  Jdbi db = dbRule.getJdbi();
  HandlerFactory defaultHandlerFactory = new HandlerFactory() {
    @Override
    public Optional<Handler> buildHandler(Class<?> sqlObjectType, Method method) {
      return getImplementation(sqlObjectType, method).map(m ->
          (Handler) (target, args, handle) -> m.invoke(null, Stream.concat(Stream.of(target), Stream.of(args)).toArray())
      );
    }
    private Optional<Method> getImplementation(Class<?> type, Method method) {
      return Stream.of(type.getClasses())
          .filter(c -> c.getSimpleName().equals("DefaultImpls"))
          .flatMap(c -> Stream.of(c.getMethods()).filter(m -> m.getName().equals(method.getName())))
          .findAny();
    }
  };
  db.configure(Handlers.class, c -> c.register(defaultHandlerFactory));
  handle = db.open();
}

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

@Test
public void configColumnMappersRegister() {
  dbRule.getJdbi()
    .configure(ColumnMappers.class, config -> config.register(new ReversedStringMapper()))
    .useHandle(handle -> {
      handle.execute("insert into something (id, name) values (1, 'abc')");
      assertThat(
        handle.select("SELECT name FROM something")
          .mapTo(QualifiedType.of(String.class).with(Reversed.class))
          .findOnly())
        .isEqualTo("cba");
    });
}

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

@Test
public void configColumnMappersRegisterFactory() {
  dbRule.getJdbi()
    .configure(ColumnMappers.class, config -> config.register(new ReversedStringMapperFactory()))
    .useHandle(handle -> {
      handle.execute("insert into something (id, name) values (1, 'xyz')");
      assertThat(
        handle.select("SELECT name FROM something")
          .mapTo(QualifiedType.of(String.class).with(Reversed.class))
          .findOnly())
        .isEqualTo("zyx");
    });
}

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

@Test
public void configColumnMappersRegisterByQualifiedType() {
  dbRule.getJdbi()
    .configure(ColumnMappers.class, config -> config.register(
      QualifiedType.of(String.class).with(Reversed.class),
      (r, c, ctx) -> reverse(r.getString(c))))
    .useHandle(handle -> {
      handle.execute("insert into something (id, name) values (1, 'abcdef')");
      assertThat(
        handle.select("SELECT name FROM something")
          .mapTo(QualifiedType.of(String.class).with(Reversed.class))
          .findOnly())
        .isEqualTo("fedcba");
    });
}

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

@Test
public void configArgumentsRegister() {
  dbRule.getJdbi()
    .configure(Arguments.class, config -> config.register(new ReversedStringArgumentFactory()))
    .useHandle(handle -> {
      handle.createUpdate("INSERT INTO something (id, name) VALUES (1, :name)")
        .bindByType("name", "abc", QualifiedType.of(String.class).with(Reversed.class))
        .execute();
      assertThat(
        handle.select("SELECT name FROM something")
          .mapTo(String.class)
          .findOnly())
        .isEqualTo("cba");
    });
}

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

@Before
public void setUp() {
  Jdbi db = dbRule.getJdbi();
  ParameterCustomizerFactory defaultParameterCustomizerFactory = (sqlObjectType, method, param, index, type) -> {
    invocationCounter.incrementAndGet();
    return (stmt, arg) -> stmt.bind("mybind" + index, arg);
  };
  db.configure(SqlObjects.class, c -> c.setDefaultParameterCustomizerFactory(defaultParameterCustomizerFactory));
  handle = db.open();
}

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

@Before
public void setUp() {
  Jdbi db = dbRule.getJdbi();
  HandlerFactory defaultHandlerFactory = new HandlerFactory() {
    @Override
    public Optional<Handler> buildHandler(Class<?> sqlObjectType, Method method) {
      return getImplementation(sqlObjectType, method).map(m ->
          (Handler) (target, args, handle) -> m.invoke(null, Stream.concat(Stream.of(target), Stream.of(args)).toArray())
      );
    }
    private Optional<Method> getImplementation(Class<?> type, Method method) {
      return Stream.of(type.getClasses())
          .filter(c -> c.getSimpleName().equals("DefaultImpls"))
          .flatMap(c -> Stream.of(c.getMethods()).filter(m -> m.getName().equals(method.getName())))
          .findAny();
    }
  };
  db.configure(Handlers.class, c -> c.register(defaultHandlerFactory));
  handle = db.open();
}

相关文章