当前位置: 首页>>代码示例>>Java>>正文


Java Jdbi.create方法代码示例

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


在下文中一共展示了Jdbi.create方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: 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

示例4: 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

示例5: 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

示例6: 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

示例7: 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

示例8: 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

示例9: 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

示例10: 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

示例11: 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

示例12: 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

示例13: dbi

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

示例14: 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(ContactDao.class, dao -> {
    dao.createContactTable();
    dao.createPhoneTable();

    dao.insertFullContact(Contact.create(1, "Alice",
                                         new Phone(2, WORK, "800-555-1234"),
                                         new Phone(3, MOBILE, "801-555-1212")));

    dao.insertFullContact(Contact.create(4, "Bob"));

    Contact alice = dao.getFullContactById(1);
    assertThat(alice)
        .extracting(Contact::getId, Contact::getName)
        .containsExactly(1, "Alice");
    assertThat(alice.getPhones())
        .extracting(Phone::getId, Phone::getType, Phone::getPhone)
        .containsExactly(tuple(2, WORK, "800-555-1234"),
                         tuple(3, MOBILE, "801-555-1212"));

    Contact bob = dao.getFullContactById(4);
    assertThat(bob)
        .extracting(Contact::getId, Contact::getName)
        .containsExactly(4, "Bob");
    assertThat(bob.getPhones())
        .isEmpty();

    List<Contact> fullContacts = dao.listFullContacts();
    assertThat(fullContacts)
        .extracting(Contact::getId, Contact::getName)
        .containsExactly(tuple(1, "Alice"),
                         tuple(4, "Bob"));
    assertThat(fullContacts.get(0).getPhones())
        .extracting(Phone::getId, Phone::getType, Phone::getPhone)
        .containsExactly(tuple(2, WORK, "800-555-1234"),
                         tuple(3, MOBILE, "801-555-1212"));
    assertThat(fullContacts.get(1).getPhones())
        .isEmpty();
  });
}
 
开发者ID:qualidafial,项目名称:jdbi-examples,代码行数:45,代码来源:Example06Joins.java


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