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

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

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

Jdbi.installPlugin介绍

[英]Install a given JdbiPlugin instance that will configure any provided Handle instances.
[中]安装一个给定的JdbiPlugin实例,该实例将配置任何提供的句柄实例。

代码示例

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

/**
   * Overridable function to allow extra customization of the created {@link Jdbi}
   * instance.
   *
   * <p>
   * If this is overridden it is strongly recommend that
   * {@code super.configure(jdbi, configuration)} is invoked before any other
   * changes are made if you intend to use the default as a base so that the
   * customized settings will supersede the defaults
   * </p>
   *
   * @param jdbi
   */
  protected void configure(final Jdbi jdbi) {
    jdbi.installPlugin(new SqlObjectPlugin());
    jdbi.installPlugin(new JodaTimePlugin());
    jdbi.installPlugin(new GuavaPlugin());
  }
}

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

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

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

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

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

@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

@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

@Test
public void testCustomizeHandle() {
  Handle h = mock(Handle.class);
  dbRule.getJdbi().installPlugin(new JdbiPlugin() {
    @Override
    public Handle customizeHandle(Handle handle) {
      return h;
    }
  });
  assertThat(h).isSameAs(dbRule.getJdbi().open());
}

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

@Before
  public void before() {
    jdbi = db.getJdbi().installPlugin(new Gson2Plugin());
  }
}

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

@Test
  public void testCustomizeConnection() {
    Connection c = mock(Connection.class);

    dbRule.getJdbi().installPlugin(new JdbiPlugin() {
      @Override
      public Connection customizeConnection(Connection conn) {
        return c;
      }
    });

    assertThat(c).isSameAs(dbRule.getJdbi().open().getConnection());
  }
}

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

@Before
public void setUp() {
  final JdbcDataSource ds = new JdbcDataSource() {
    private static final long serialVersionUID = 1L;
    @Override
    public Connection getConnection() {
      throw new UnsupportedOperationException();
    }
  };
  db = Jdbi.create(ds);
  db.installPlugin(new SqlObjectPlugin());
  dao = db.onDemand(UselessDao.class);
}

代码示例来源: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() {
  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 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))");
}

代码示例来源: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"));
}

代码示例来源: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"));
}

代码示例来源: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"));
}

相关文章