本文整理了Java中org.jdbi.v3.core.Jdbi.useExtension()
方法的一些代码示例,展示了Jdbi.useExtension()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Jdbi.useExtension()
方法的具体详情如下:
包路径:org.jdbi.v3.core.Jdbi
类名称:Jdbi
方法名:useExtension
[英]A convenience method which opens an extension of the given type, and yields it to a callback. A handle is opened if needed by the extention, and closed before returning to the caller.
[中]一种方便的方法,用于打开给定类型的扩展,并将其生成回调。如果扩展需要,将打开句柄,并在返回调用方之前关闭句柄。
代码示例来源:origin: jdbi/jdbi
@Test
public void canMapToMapWithSqlObject() {
jdbi.useExtension(WithTypicalMap.class, withTypicalMap -> {
List<Map<String, BigDecimal>> list = withTypicalMap.getMapList();
assertThat(list).hasSize(1);
Map<String, BigDecimal> map = list.get(0);
assertThat(map)
.containsOnlyKeys("one", "two", "three")
.containsValues(new BigDecimal("1.0"), new BigDecimal("2.0"), new BigDecimal("3.0"));
});
}
代码示例来源:origin: jdbi/jdbi
@Test
public void testBatch() {
db.useExtension(DAO.class, dao -> {
int[] ids = dao.insert(Arrays.asList("Burt", "Macklin"));
assertThat(dao.findNameById(ids[0])).isEqualTo("Burt");
assertThat(dao.findNameById(ids[1])).isEqualTo("Macklin");
});
}
}
代码示例来源:origin: jdbi/jdbi
@Test
public void testFoo() {
db.useExtension(DAO.class, dao -> {
long brianId = dao.insert("Brian");
long keithId = dao.insert("Keith");
assertThat(dao.findNameById(brianId)).isEqualTo("Brian");
assertThat(dao.findNameById(keithId)).isEqualTo("Keith");
});
}
代码示例来源:origin: jdbi/jdbi
@Test
public void testOpenNewSpiffy() throws Exception {
final AtomicReference<Connection> c = new AtomicReference<>();
db.useExtension(Spiffy.class, spiffy -> {
spiffy.insert(new Something(1, "Tim"));
spiffy.insert(new Something(2, "Diego"));
assertThat(spiffy.findNameById(2)).isEqualTo("Diego");
c.set(spiffy.getHandle().getConnection());
});
assertThat(c.get().isClosed()).isTrue();
}
代码示例来源:origin: jdbi/jdbi
@Test
public void testUseRowMapperUpdate() {
dbRule.getJdbi().useExtension(UseRowMapperDao.class, dao -> {
dao.createTable();
IdCreateTime result = dao.insert("foo");
assertThat(result.id).isEqualTo(1);
assertThat(result.createdOn).isNotNull();
});
}
代码示例来源:origin: jdbi/jdbi
@Test
public void testFiveMinuteSqlObjectExample() {
dbRule.getJdbi().useExtension(MyDAO.class, dao -> {
dao.insert(2, "Aaron");
String name = dao.findNameById(2);
assertThat(name).isEqualTo("Aaron");
});
}
代码示例来源:origin: jdbi/jdbi
@Test
public void testSingleAnnotation() {
db.useExtension(Waffle.class, w -> {
w.insert(1, new Name("Brian", "McCallister"));
assertThat(w.findName(1)).isEqualTo("Brian McCallister");
});
}
代码示例来源:origin: jdbi/jdbi
@Test
public void testRegisterRowMapperUpdate() {
dbRule.getJdbi().useExtension(RegisterRowMapperDao.class, dao -> {
dao.createTable();
IdCreateTime result = dao.insert("foo");
assertThat(result.id).isEqualTo(1);
assertThat(result.createdOn).isNotNull();
});
}
代码示例来源:origin: jdbi/jdbi
@Test
public void testBatch() {
dbRule.getJdbi().useExtension(DAO.class, dao -> {
dao.createSequence();
dao.createTable();
int[] ids = dao.insert(Arrays.asList("Burt", "Macklin"));
assertThat(dao.findNameById(ids[0])).isEqualTo("Burt");
assertThat(dao.findNameById(ids[1])).isEqualTo("Macklin");
});
}
代码示例来源:origin: jdbi/jdbi
@Test
public void testFoo() {
dbRule.getJdbi().useExtension(DAO.class, dao -> {
long brianId = dao.insert("Brian");
long keithId = dao.insert("Keith");
assertThat(dao.findNameById(brianId)).isEqualTo("Brian");
assertThat(dao.findNameById(keithId)).isEqualTo("Keith");
});
}
}
代码示例来源:origin: jdbi/jdbi
@Test
public void testInsert() {
dbRule.getJdbi().useExtension(Inserter.class, i -> {
// this is what is under test here
int rowsAffected = i.insert(2, "Diego");
String name = dbRule.getSharedHandle().createQuery("select name from something where id = 2").mapTo(String.class).findOnly();
assertThat(rowsAffected).isEqualTo(1);
assertThat(name).isEqualTo("Diego");
});
}
代码示例来源:origin: jdbi/jdbi
@Test
public void testSingleValue() {
handle.execute("insert into something (id, name) values (7, 'Tim')");
dbRule.getJdbi().useExtension(Spiffy.class, spiffy -> {
Something s = spiffy.findById(7);
assertThat(s.getName()).isEqualTo("Tim");
});
}
代码示例来源:origin: jdbi/jdbi
@Test
public void testHandleHasExtensionMethodSet() throws Exception {
dbRule.getJdbi().useExtension(StatementContextExtensionMethodDao.class, dao -> dao.check());
}
代码示例来源:origin: jdbi/jdbi
@Test
public void testWithRegisteredMapper() {
handle.execute("insert into something (id, name) values (7, 'Tim')");
dbRule.getJdbi().useExtension(Spiffy.class, spiffy -> {
Something s = spiffy.findById(7).findOnly();
assertThat(s.getName()).isEqualTo("Tim");
});
}
代码示例来源:origin: jdbi/jdbi
@Test
public void testInsertWithVoidReturn() {
dbRule.getJdbi().useExtension(Inserter.class, i -> {
// this is what is under test here
i.insertWithVoidReturn(2, "Diego");
String name = dbRule.getSharedHandle().createQuery("select name from something where id = 2").mapTo(String.class).findOnly();
assertThat(name).isEqualTo("Diego");
});
}
代码示例来源:origin: jdbi/jdbi
@Test
public void testFoo() {
dbRule.getSharedHandle().execute("insert into something (id, name) values (2, 'Martin')");
dbRule.getJdbi().useExtension(Spiffy.class, spiffy -> {
Something s = spiffy.findSame(new Something(2, "Unknown"));
assertThat(s.getName()).isEqualTo("Martin");
});
}
代码示例来源:origin: jdbi/jdbi
@Test
public void testUseRowMapperBatch() {
dbRule.getJdbi().useExtension(UseRowMapperDao.class, dao -> {
dao.createTable();
List<IdCreateTime> results = dao.insertBatch("foo", "bar");
assertThat(results).extracting(ic -> ic.id).containsExactly(1L, 2L);
assertThat(results).extracting(ic -> ic.createdOn).hasSize(2).doesNotContainNull();
});
}
代码示例来源:origin: jdbi/jdbi
@Test
public void testRegisterRowMapperBatch() {
dbRule.getJdbi().useExtension(RegisterRowMapperDao.class, dao -> {
dao.createTable();
List<IdCreateTime> results = dao.insertBatch("foo", "bar");
assertThat(results).extracting(ic -> ic.id).containsExactly(1L, 2L);
assertThat(results).extracting(ic -> ic.createdOn).hasSize(2).doesNotContainNull();
});
}
代码示例来源:origin: jdbi/jdbi
@Test
public void testIterator() {
handle.execute("insert into something (id, name) values (7, 'Tim')");
handle.execute("insert into something (id, name) values (3, 'Diego')");
dbRule.getJdbi().useExtension(Spiffy.class, spiffy -> {
Iterator<Something> itty = spiffy.findByIdRange(2, 10);
assertThat(itty).containsOnlyOnce(new Something(7, "Tim"), new Something(3, "Diego"));
});
}
代码示例来源:origin: jdbi/jdbi
@Test
public void testList() {
handle.execute("insert into something (id, name) values (7, 'Tim')");
handle.execute("insert into something (id, name) values (3, 'Diego')");
dbRule.getJdbi().useExtension(Spiffy.class, spiffy -> {
List<Something> all = spiffy.findTwoByIds(3, 7);
assertThat(all).containsOnlyOnce(new Something(7, "Tim"), new Something(3, "Diego"));
});
}
内容来源于网络,如有侵权,请联系作者删除!