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


Java Jdbi.useExtension方法代码示例

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


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

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

示例2: 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.useExtension方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。