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

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

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

Jdbi.create介绍

暂无

代码示例

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

/**
 * This creates a vanilla {@link Jdbi} instance based on the specified data source;
 * this can be overridden if required
 *
 * @param dataSource
 * @return
 */
protected Jdbi newInstance(final ManagedDataSource dataSource) {
  return Jdbi.create(dataSource);
}

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

/**
 * @param url JDBC URL for connections
 *
 * @return a Jdbi which uses {@link DriverManager} as a connection factory.
 */
public static Jdbi create(final String url) {
  Objects.requireNonNull(url, "null url");
  return create(() -> DriverManager.getConnection(url));
}

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

/**
 * @param url   JDBC URL for connections
 * @param properties Properties to pass to DriverManager.getConnection(url, props) for each new handle
 *
 * @return a Jdbi which uses {@link DriverManager} as a connection factory.
 */
public static Jdbi create(final String url, final Properties properties) {
  Objects.requireNonNull(url, "null url");
  Objects.requireNonNull(properties, "null properties");
  return create(() -> DriverManager.getConnection(url, properties));
}

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

/**
 * @param connection db connection
 *
 * @return a Jdbi which works on single connection
 */
public static Jdbi create(Connection connection) {
  return create(new SingleConnectionFactory(connection));
}

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

/**
 * Create a Handle wrapping a particular JDBC Connection
 *
 * @param connection the JDBC connection
 *
 * @return Handle bound to connection
 */
public static Handle open(final Connection connection) {
  Objects.requireNonNull(connection, "null connection");
  return create(() -> connection).open();
}

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

/**
 * Obtain a handle with just a JDBC URL
 *
 * @param url   JDBC Url
 * @param props JDBC properties
 *
 * @return newly opened Handle
 */
public static Handle open(final String url, final Properties props) {
  return create(url, props).open();
}

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

@Override
protected Jdbi createInstance() throws Exception {
  final Jdbi jdbi = Jdbi.create(new SpringConnectionFactory(dataSource));
  if (autoInstallPlugins) {
    jdbi.installPlugins();
  }
  plugins.forEach(jdbi::installPlugin);
  globalDefines.forEach(jdbi::define);
  return jdbi;
}

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

@Inject
public MysqlDaoProvider(DbResourceGroupConfig config)
{
  requireNonNull(config, "DbResourceGroupConfig is null");
  MysqlDataSource dataSource = new MysqlDataSource();
  dataSource.setURL(requireNonNull(config.getConfigDbUrl(), "resource-groups.config-db-url is null"));
  this.dao = Jdbi.create(dataSource)
      .installPlugin(new SqlObjectPlugin())
      .onDemand(ResourceGroupsDao.class);
}

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

@Test
public void testCorrectExceptionOnSQLException() {
  Jdbi db = Jdbi.create(() -> {
    throw new SQLException();
  });
  assertThatThrownBy(db::open).isInstanceOf(ConnectionException.class);
}

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

@Override
protected void before() {
  db = Jdbi.create(innerRule.getTestDatabase());
  plugins.forEach(db::installPlugin);
}

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

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

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

@Test
public void testObtainHandleInCallback() {
  Jdbi db = Jdbi.create("jdbc:h2:mem:" + UUID.randomUUID());
  db.useHandle(handle -> handle.execute("create table silly (id int)"));
}

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

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

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

@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 setUp() {
  JdbcDataSource ds = new JdbcDataSource();
  ds.setURL("jdbc:h2:mem:" + 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))");
}

相关文章