• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Java Jdbi类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中org.jdbi.v3.core.Jdbi的典型用法代码示例。如果您正苦于以下问题:Java Jdbi类的具体用法?Java Jdbi怎么用?Java Jdbi使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



Jdbi类属于org.jdbi.v3.core包,在下文中一共展示了Jdbi类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: build

import org.jdbi.v3.core.Jdbi; //导入依赖的package包/类
public Jdbi build(Environment environment,
                  PooledDataSourceFactory configuration,
                  String name) {
    ManagedDataSource dataSource = configuration.build(environment.metrics(), name);
    String validationQuery = configuration.getValidationQuery();
    Jdbi jdbi = Jdbi.create(dataSource);
    jdbi.setTimingCollector(new InstrumentedTimingCollector(environment.metrics(), nameStrategy));
    jdbi.installPlugins();

    environment.lifecycle().manage(dataSource);
    environment.healthChecks().register(name, new JdbiHealthCheck(
            environment.getHealthCheckExecutorService(),
            configuration.getValidationQueryTimeout().orElseGet(() -> Duration.seconds(5)),
            jdbi, validationQuery));

    return jdbi;
}
 
开发者ID:arteam,项目名称:dropwizard-jdbi3,代码行数:18,代码来源:JdbiFactory.java


示例2: test

import org.jdbi.v3.core.Jdbi; //导入依赖的package包/类
@Test
public void test() throws Exception {
  Jdbi jdbi = Jdbi.create(ds.getDataSource());

  try (Handle h = jdbi.open()) {
    h.execute("create table contacts (id int primary key, name varchar(100))");

    h.execute("insert into contacts (id, name) values (?, ?)", 1, "Alice");
    h.execute("insert into contacts (id, name) values (?, ?)", 2, "Bob");

    List<String> names = h.createQuery("select name from contacts order by id")
        .mapTo(String.class)
        .list();
    assertThat(names)
        .containsExactly("Alice", "Bob");

    String name = h.createQuery("select name from contacts where id = :id")
        .bind("id", 1)
        .mapTo(String.class)
        .findOnly();
    assertThat(name)
        .isEqualTo("Alice");

  }
}
 
开发者ID:qualidafial,项目名称:jdbi-examples,代码行数:26,代码来源:Example01FluentApi.java


示例3: classBlock

import org.jdbi.v3.core.Jdbi; //导入依赖的package包/类
@Override
protected Statement classBlock(RunNotifier notifier) {
    final Statement statement = super.classBlock(notifier);
    return new Statement() {
        @Override
        public void evaluate() throws Throwable {
            // Open a new handle for every test
            // It affords to avoid creating a static state which makes tests more independent
            JditProperties jditProperties = klass.getAnnotation(JditProperties.class);
            Jdbi dbi = jditProperties != null ? DBIContextFactory.getDBI(jditProperties.value()) : DBIContextFactory.getDBI();
            try (Handle handle = dbi.open()) {
                injector = new TestObjectsInjector(dbi, handle);
                databaseMaintenance = DatabaseMaintenanceFactory.create(handle);
                dataSetInjector = new DataSetInjector(new DataMigration(handle));
                statement.evaluate();
            }
        }
    };
}
 
开发者ID:arteam,项目名称:jdit,代码行数:20,代码来源:DBIRunner.java


示例4: configureWithCallback

import org.jdbi.v3.core.Jdbi; //导入依赖的package包/类
@Test
public void configureWithCallback() throws Exception {
  new MockUnit(Env.class, Config.class, Binder.class, JdbiPlugin.class)
      .expect(configure)
      .expect(unit -> {
        Jdbi jdbi = unit.get(Jdbi.class);
        expect(jdbi.installPlugin(unit.get(JdbiPlugin.class))).andReturn(jdbi);
      })
      .run(unit -> {
        new Jdbi3()
            .doWith(jdbi -> {
              jdbi.installPlugin(unit.get(JdbiPlugin.class));
            })
            .configure(unit.get(Env.class), unit.get(Config.class), unit.get(Binder.class));
      });
}
 
开发者ID:jooby-project,项目名称:jooby,代码行数:17,代码来源:Jdbi3Test.java


示例5: inClause

import org.jdbi.v3.core.Jdbi; //导入依赖的package包/类
@Test
public void inClause() {
  Jdbi jdbi = Jdbi.create("jdbc:h2:mem:test");
  List<String> names = jdbi.withHandle(h -> {
    h.createUpdate("CREATE TABLE USER (id INTEGER PRIMARY KEY, name VARCHAR)")
        .execute();
    h.createUpdate("INSERT INTO USER(id, name) VALUES (:id, :name)")
        .bind("id", 1)
        .bind("name", "Pedro Picapiedra")
        .execute();
    h.createUpdate("INSERT INTO USER(id, name) VALUES (:id, :name)")
        .bind("id", 2)
        .bind("name", "Pablo Marmol")
        .execute();

    return h.createQuery("select name from USER where id in (<id>)")
        .bindList("id", 1, 2)
        .mapTo(String.class)
        .list();
  });

  assertEquals(2, names.size());
}
 
开发者ID:jooby-project,项目名称:jooby,代码行数:24,代码来源:JdbiInClauseTest.java


示例6: load

import org.jdbi.v3.core.Jdbi; //导入依赖的package包/类
@Override
public void load(Undertow.Builder builder, DeploymentContext deploymentContext) throws IOException {
    log.info( "Creating users and roles..." );
    val script = SystemResource.readFileAsString( "tables.sql", "UTF-8" );
    val jdbi = Jdbi.create( dataSource );
    try ( val handle = jdbi.open() ) {
        handle.useTransaction( h -> h.createScript( script ).execute() );
    }
}
 
开发者ID:Skullabs,项目名称:kikaha-samples,代码行数:10,代码来源:DatabaseInitialPopulation.java


示例7: main

import org.jdbi.v3.core.Jdbi; //导入依赖的package包/类
public static void main(String[] args) {
    Jdbi dbi = Jdbi.create("jdbc:sqlite:behemoth.db");
    String installScript = ClasspathSqlLocator.findSqlOnClasspath(InitDatabase.class.getName() + "_install");
    dbi.useHandle(hnd -> {
        int totalExecuted = 0;
        int[] rowsExecuted = hnd.createScript(installScript).execute();
        for (int rows : rowsExecuted) {
            totalExecuted += rows;
        }
        System.out.println("Executed: " + totalExecuted);
    });

}
 
开发者ID:cloudwall,项目名称:libcwfincore,代码行数:14,代码来源:InitDatabase.java


示例8: JdbiDynamicEnumCache

import org.jdbi.v3.core.Jdbi; //导入依赖的package包/类
public JdbiDynamicEnumCache(Jdbi conn, Class<T> clazz, String tableName, BiFunction<Long, String, T> typeCodeFactory) {
    super(clazz);
    conn.useHandle(handle -> {
        Query q = handle.createQuery("SELECT id, name FROM " + tableName);
        ResultIterable<T> tcIter = q.map((rs, ctx) -> typeCodeFactory.apply(rs.getLong("id"),
                                    rs.getString("name")));
        tcIter.forEach(this::add);
    });
}
 
开发者ID:cloudwall,项目名称:libcwfincore,代码行数:10,代码来源:JdbiDynamicEnumCache.java


示例9: test

import org.jdbi.v3.core.Jdbi; //导入依赖的package包/类
@Test
public void test() throws Exception {
  Jdbi jdbi = Jdbi.create(ds.getDataSource());
  jdbi.registerRowMapper(BeanMapper.factory(Account.class));
  jdbi.registerColumnMapper(new MoneyMapper());
  jdbi.registerArgument(new MoneyArgumentFactory());

  try (Handle h = jdbi.open()) {
    Money tenDollars = Money.of(USD, 10);
    Money fiveDollars = Money.of(USD, 5);

    h.execute("create table accounts (id int primary key, name varchar(100), balance decimal)");

    h.execute("insert into accounts (id, name, balance) values (?, ?, ?)", 1, "Alice", tenDollars);
    h.execute("insert into accounts (id, name, balance) values (?, ?, ?)", 2, "Bob", fiveDollars);

    List<Account> list = h.createQuery("select * from accounts order by id")
        .mapTo(Account.class)
        .list();
    assertThat(list)
        .extracting(Account::getId, Account::getName, Account::getBalance)
        .containsExactly(tuple(1, "Alice", tenDollars),
                         tuple(2, "Bob", fiveDollars));

    Account bob = h.createQuery("select * from accounts where id = :id")
        .bind("id", 2)
        .mapTo(Account.class)
        .findOnly();
    assertThat(bob)
        .extracting(Account::getId, Account::getName, Account::getBalance)
        .containsExactly(2, "Bob", fiveDollars);
  }
}
 
开发者ID:qualidafial,项目名称:jdbi-examples,代码行数:34,代码来源:Example04ColumnMapper.java


示例10: test

import org.jdbi.v3.core.Jdbi; //导入依赖的package包/类
@Test
public void test() throws Exception {
  Jdbi jdbi = Jdbi.create(ds.getDataSource());
  jdbi.installPlugin(new SqlObjectPlugin());

  jdbi.useExtension(AccountDao.class, dao -> {
    Money tenDollars = Money.of(USD, 10);
    Money fiveDollars = Money.of(USD, 5);

    dao.createTable();
    dao.insert(new Account(1, "Alice", tenDollars));
    dao.insert(new Account(2, "Bob", fiveDollars));

    assertThat(dao.list())
        .extracting(Account::getId, Account::getName, Account::getBalance)
        .containsExactly(tuple(1, "Alice", tenDollars),
                         tuple(2, "Bob", fiveDollars));

    assertThat(dao.getById(2))
        .extracting(Account::getId, Account::getName, Account::getBalance)
        .containsExactly(2, "Bob", fiveDollars);

    dao.update(new Account(2, "Robert", tenDollars));

    assertThat(dao.getById(2))
        .extracting(Account::getId, Account::getName, Account::getBalance)
        .containsExactly(2, "Robert", tenDollars);
  });
}
 
开发者ID:qualidafial,项目名称:jdbi-examples,代码行数:30,代码来源:Example05SqlObjectApi.java


示例11: test

import org.jdbi.v3.core.Jdbi; //导入依赖的package包/类
@Test
public void test() throws Exception {
  Jdbi jdbi = Jdbi.create(ds.getDataSource());

  try (Handle h = jdbi.open()) {
    h.execute("create table contacts (id int primary key, name varchar(100))");

    h.execute("insert into contacts (id, name) values (?, ?)", 1, "Alice");
    h.execute("insert into contacts (id, name) values (?, ?)", 2, "Bob");

    List<Contact> list = h.createQuery("select * from contacts order by id")
        .map(new ContactMapper())
        .list();
    assertThat(list)
        .extracting(Contact::getId, Contact::getName)
        .containsExactly(tuple(1, "Alice"),
                         tuple(2, "Bob"));

    Contact bob = h.createQuery("select * from contacts where id = :id")
        .bind("id", 2)
        .map(new ContactMapper())
        .findOnly();
    assertThat(bob)
        .extracting(Contact::getId, Contact::getName)
        .containsExactly(2, "Bob");
  }
}
 
开发者ID:qualidafial,项目名称:jdbi-examples,代码行数:28,代码来源:Example02RowMapper.java


示例12: test

import org.jdbi.v3.core.Jdbi; //导入依赖的package包/类
@Test
public void test() throws Exception {
  Jdbi jdbi = Jdbi.create(ds.getDataSource());
  jdbi.registerRowMapper(new ContactMapper());

  try (Handle h = jdbi.open()) {
    h.execute("create table contacts (id int primary key, name varchar(100))");

    h.execute("insert into contacts (id, name) values (?, ?)", 1, "Alice");
    h.execute("insert into contacts (id, name) values (?, ?)", 2, "Bob");

    List<Contact> list = h.createQuery("select * from contacts order by id")
        .mapTo(Contact.class)
        .list();
    assertThat(list)
        .extracting(Contact::getId, Contact::getName)
        .containsExactly(tuple(1, "Alice"),
                         tuple(2, "Bob"));

    Contact bob = h.createQuery("select * from contacts where id = :id")
        .bind("id", 2)
        .mapTo(Contact.class)
        .findOnly();
    assertThat(bob)
        .extracting(Contact::getId, Contact::getName)
        .containsExactly(2, "Bob");
  }
}
 
开发者ID:qualidafial,项目名称:jdbi-examples,代码行数:29,代码来源:Example03RegisterRowMapper.java


示例13: before

import org.jdbi.v3.core.Jdbi; //导入依赖的package包/类
public void before() throws Exception {
    dbi = Jdbi.create(uri);
    if (installPlugins) {
        dbi.installPlugins();
    }
    plugins.forEach(dbi::installPlugin);
    sharedHandle = dbi.open();
    con = sharedHandle.getConnection();
    try (Statement s = con.createStatement()) {
        s.execute("create table people(id identity primary key, firstName varchar(50), lastName varchar(50), email varchar(255), created timestamp, modified timestamp);");
    }
}
 
开发者ID:zikani03,项目名称:jdbi-utils,代码行数:13,代码来源:HsqldbDatabaseRule.java


示例14: handleDbiInstance

import org.jdbi.v3.core.Jdbi; //导入依赖的package包/类
/**
 * Inject a DBI instance to a field with {@link DBIInstance} annotation.
 *
 * @param test  current test
 * @param field current field
 * @throws IllegalAccessException reflection error
 */
private void handleDbiInstance(Object test, Field field) throws IllegalAccessException {
    if (!field.getType().equals(Jdbi.class)) {
        throw new IllegalArgumentException("Unable inject a DBI instance to " +
                "a field with type " + field.getType());
    }
    if (Modifier.isStatic(field.getModifiers())) {
        throw new IllegalArgumentException("Unable inject a DBI instance to a static field");
    }
    field.setAccessible(true);
    field.set(test, dbi);
}
 
开发者ID:arteam,项目名称:jdit,代码行数:19,代码来源:TestObjectsInjector.java


示例15: createDBI

import org.jdbi.v3.core.Jdbi; //导入依赖的package包/类
@Override
public Jdbi createDBI(Properties properties) {
    Jdbi dbi = Jdbi.create(properties.getProperty("db.url"), properties.getProperty("db.username"),
            properties.getProperty("db.password"));
    dbi.installPlugins();
    return dbi;
}
 
开发者ID:arteam,项目名称:jdit,代码行数:8,代码来源:StandardDBIFactory.java


示例16: createDBI

import org.jdbi.v3.core.Jdbi; //导入依赖的package包/类
/**
 * Create and configure a {@link Jdbi} instance from the properties
 * The DB is created during the first connection.
 *
 * @param properties configuration of DB
 * @return a new {@link Jdbi} instance for performing database access
 */
private Jdbi createDBI(Properties properties) {
    try {
        DBIFactory dbiFactory = (DBIFactory) Class.forName(properties.getProperty("dbi.factory"))
                .newInstance();
        return dbiFactory.createDBI(properties);
    } catch (Exception e) {
        throw new IllegalStateException("Unable instantiate DBI Factory", e);
    }
}
 
开发者ID:arteam,项目名称:jdit,代码行数:17,代码来源:DBIContext.java


示例17: testMapToDbObject

import org.jdbi.v3.core.Jdbi; //导入依赖的package包/类
@Test
public void testMapToDbObject() throws Exception {
    Jdbi dbi = Jdbi.create(DbHelper.getHsqlDataSource());
    dbi.installPlugins();
    Handle handle = dbi.open();
    try {
        DbObject dbObject = handle.createQuery(DbHelper.TEST_DB_OBJECT_QUERY).mapTo(DbObject.class).findFirst().get();
        DbHelper.assertDbObjectMapping(dbObject);
    } finally {
        handle.close();
    }
}
 
开发者ID:arnaudroger,项目名称:SimpleFlatMapper,代码行数:13,代码来源:RowMapperFactoryTest.java


示例18: openHandle

import org.jdbi.v3.core.Jdbi; //导入依赖的package包/类
@Test
public void openHandle() throws Exception {
  new MockUnit(Handle.class, Request.class, Response.class, Route.Chain.class, Jdbi.class, Handle.class)
      .expect(unit -> {
        Handle handle = unit.get(Handle.class);
        expect(handle.setReadOnly(true)).andReturn(handle);
        expect(handle.begin()).andReturn(handle);

        Request request = unit.get(Request.class);
        expect(request.set(Key.get(Handle.class), handle)).andReturn(request);

        Response response = unit.get(Response.class);
        response.after(isA(CommitTransaction.class));
        response.complete(isA(RollbackTransaction.class));
        response.complete(isA(CloseHandle.class));

        Route.Chain chain = unit.get(Route.Chain.class);
        chain.next(request, response);

        Jdbi jdbi = unit.get(Jdbi.class);
        expect(jdbi.open()).andReturn(handle);
      })
      .run(unit -> {
        TransactionalRequest req = new TransactionalRequest();
        req.doWith(h -> {
          h.setReadOnly(true);
        });
        new OpenHandle(unit.get(Jdbi.class), req)
            .handle(unit.get(Request.class), unit.get(Response.class),
                unit.get(Route.Chain.class));
      });
}
 
开发者ID:jooby-project,项目名称:jooby,代码行数:33,代码来源:OpenHandleTest.java


示例19: dbi

import org.jdbi.v3.core.Jdbi; //导入依赖的package包/类
@Provides
@Singleton
Jdbi dbi(DataSource dataSource) {
    return Jdbi.create(dataSource);
}
 
开发者ID:Twister915,项目名称:pl,代码行数:6,代码来源:DbiModule.java


示例20: SqlliteDatetimeSource

import org.jdbi.v3.core.Jdbi; //导入依赖的package包/类
public SqlliteDatetimeSource(Jdbi dbi) {
    this.dbi = dbi;
}
 
开发者ID:cloudwall,项目名称:libcwfincore,代码行数:4,代码来源:SqlliteDatetimeSource.java



注:本文中的org.jdbi.v3.core.Jdbi类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java Fingerprint类代码示例发布时间:2022-05-22
下一篇:
Java ExpectedException类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap