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

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

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

Jdbi.open介绍

[英]Obtain a Handle to the data source wrapped by this Jdbi instance. You own this expensive resource and are required to close it or risk leaks. Using a try-with-resources block is recommended.
[中]获取此Jdbi实例包装的数据源的句柄。您拥有这一昂贵的资源,需要关闭它,否则将面临泄漏风险。建议使用try with resources块。

代码示例

代码示例来源:origin: prestodb/presto

public TestShadowing()
{
  handle = Jdbi.open(URL);
}

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

@Override
  protected Result check() throws Exception {
    return timeBoundHealthCheck.check(() -> {
        try (Handle handle = jdbi.open()) {
          handle.execute(validationQuery);
          return Result.healthy();
        }
      }
    );
  }
}

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

@Test
public void testConnectionConstructor() throws SQLException {
  Connection connection = this.dbRule.getConnectionFactory().openConnection();
  Jdbi db = Jdbi.create(connection);
  try (Handle h = db.open()) {
    assertThat(h).isNotNull();
  }
  assertThat(connection.isClosed()).isFalse();
}

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

@Test
public void testEventuallySucceeds() throws Exception {
  final AtomicInteger remaining = new AtomicInteger(MAX_RETRIES / 2);
  Handle handle = dbRule.getJdbi().open();
  handle.inTransaction(TransactionIsolationLevel.SERIALIZABLE, conn -> {
    if (remaining.decrementAndGet() == 0) {
      return null;
    }
    throw new SQLException("serialization", "40001");
  });
  assertThat(remaining.get()).isZero();
}

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

@Override
protected void before() {
  db = Jdbi.create(uri);
  if (installPlugins) {
    db.installPlugins();
  }
  plugins.forEach(db::installPlugin);
  sharedHandle = db.open();
  con = sharedHandle.getConnection();
}

代码示例来源:origin: prestodb/presto

@Inject
public H2DaoProvider(DbResourceGroupConfig config)
{
  JdbcDataSource ds = new JdbcDataSource();
  ds.setURL(requireNonNull(config.getConfigDbUrl(), "resource-groups.config-db-url is null"));
  // TODO: this should use onDemand()
  this.dao = Jdbi.create(ds)
      .installPlugin(new SqlObjectPlugin())
      .open()
      .attach(H2ResourceGroupsDao.class);
}

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

@Test
public void testCorrectExceptionIfUnableToConnectOnAttach() {
  assertThatThrownBy(() -> Jdbi.create("jdbc:mysql://invalid.invalid/test", "john", "scott")
    .installPlugin(new SqlObjectPlugin())
    .open()
    .attach(Spiffy.class)).isInstanceOf(ConnectionException.class);
}

代码示例来源: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: prestodb/presto

public TestVerifierRewriteQueries()
{
  handle = Jdbi.open(URL);
  handle.execute("CREATE TABLE \"test_table\" (a BIGINT, b DOUBLE, c VARCHAR)");
  parser = new SqlParser();
  config = new VerifierConfig();
  config.setTestGateway(URL);
  config.setTestTimeout(new Duration(10, TimeUnit.SECONDS));
  config.setControlTimeout(new Duration(10, TimeUnit.SECONDS));
  config.setShadowTestTablePrefix("tmp_verifier_test_");
  config.setShadowControlTablePrefix("tmp_verifier_control_");
  ImmutableList.Builder<QueryPair> builder = ImmutableList.builder();
  for (String queryString : QUERY_STRINGS) {
    Query query = new Query(
        CATALOG,
        SCHEMA,
        ImmutableList.of(),
        queryString,
        ImmutableList.of(),
        null,
        null,
        ImmutableMap.of());
    builder.add(new QueryPair(QUERY_SUITE, QUERY_NAME, query, query));
  }
  queryPairs = builder.build();
}

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

@Test
public void testObtainHandleViaOpen() {
  assertThatCode(() -> {
    try (Handle h = dbRule.getJdbi().open()) {
      // nop
    }
  }).doesNotThrowAnyException();
}

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

@Before
public void setUp() {
  ds = new JdbcDataSource();
  // in MVCC mode h2 doesn't shut down immediately on all connections closed, so need random db name
  ds.setURL(String.format("jdbc:h2:mem:%s;MVCC=TRUE", UUID.randomUUID()));
  db = Jdbi.create(ds);
  db.installPlugin(new SqlObjectPlugin());
  handle = db.open();
  handle.execute("create table something (id int primary key, name varchar(100))");
  db.installPlugin(tracker);
}

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

@Before
public void setUp() {
  db = Jdbi.create("jdbc:h2:mem:" + UUID.randomUUID());
  db.installPlugin(new SqlObjectPlugin());
  handle = db.open();
  handle.createUpdate(
      "create table foo (id int, bar varchar(100) default null);")
      .execute();
  dao = db.onDemand(MyDAO.class);
}

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

@Test
public void testMeaningfulExceptionWhenWrongReturnTypeOfSqlBatch() {
  expectedException.expect(UnableToCreateSqlObjectException.class);
  expectedException.expectMessage("BogusSqlBatchDao.getNames method is annotated with @SqlBatch "
    + "so should return void, int[], or boolean[] but is returning: int");
  dbRule.getJdbi().open().attach(BogusSqlBatchDao.class);
}

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

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

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

@Test
public void testMeaningfulExceptionWhenWrongReturnTypeOfSqlUpdate() {
  expectedException.expect(UnableToCreateSqlObjectException.class);
  expectedException.expectMessage("BogusSqlUpdateDao.getNames method is annotated with @SqlUpdate "
    + "so should return void, boolean, or Number but is returning: java.util.List<java.lang.String>");
  dbRule.getJdbi().open().attach(BogusSqlUpdateDao.class);
}

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

@Before
public void setUp() {
  JdbcDataSource ds = new JdbcDataSource();
  // in MVCC mode h2 doesn't shut down immediately on all connections closed, so need random db name
  ds.setURL(String.format("jdbc:h2:mem:%s;MVCC=TRUE", UUID.randomUUID()));
  db = Jdbi.create(ds);
  db.installPlugin(new SqlObjectPlugin());
  db.registerRowMapper(new SomethingMapper());
  handle = db.open();
  handle.execute("create table something (id int primary key, name varchar(100))");
}

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

@Before
public void setUp() {
  Jdbi jdbi = Jdbi.create("jdbc:sqlite::memory:");
  jdbi.installPlugin(new SQLitePlugin());
  handle = jdbi.open();
  handle.useTransaction(handle -> handle.execute("CREATE TABLE foo(url URL);"));
}

代码示例来源: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() {
  final Jdbi db = dbRule.getJdbi();
  db.installPlugin(new SqlObjectPlugin());
  db.registerRowMapper(new SomethingMapper());
  handle = db.open();
  handle.execute("insert into something(id, name) values(1, '1')");
  handle.execute("insert into something(id, name) values(2, '2')");
  // "control group" element that should *not* be returned by the queries
  handle.execute("insert into something(id, name) values(3, '3')");
  expectedSomethings = Arrays.asList(new Something(1, "1"), new Something(2, "2"));
}

相关文章