本文整理了Java中org.jdbi.v3.core.Jdbi.onDemand()
方法的一些代码示例,展示了Jdbi.onDemand()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Jdbi.onDemand()
方法的具体详情如下:
包路径:org.jdbi.v3.core.Jdbi
类名称:Jdbi
方法名:onDemand
暂无
代码示例来源: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
@Test
public void testSqlFromExternalFileWorks() {
Spiffy spiffy = db.onDemand(Spiffy.class);
ExternalSql external = db.onDemand(ExternalSql.class);
spiffy.insert(1, "Tom");
spiffy.insert(2, "Sam");
List<Something> all = external.findAll();
assertThat(all).hasSize(2);
}
代码示例来源:origin: jdbi/jdbi
@Test
public void testSqlQuery() {
AdvancedDAO advancedDAO = db.onDemand(AdvancedDAO.class);
advancedDAO.insertBatch(Arrays.asList(1, 2, 3), Arrays.asList("Mary", "David", "Kate"));
String name = advancedDAO.findNameById(3);
assertThat(name).isEqualTo("Kate");
assertThat(timingCollector.statementNames).containsOnly(
"org.jdbi.v3.sqlobject.AdvancedDAO.insertBatch",
"org.jdbi.v3.sqlobject.AdvancedDAO.findNameById");
}
代码示例来源:origin: jdbi/jdbi
@Test
public void testExceptionThrown() {
db.registerExtension(new UselessDaoExtension());
UselessDao uselessDao = db.onDemand(UselessDao.class);
assertThatThrownBy(uselessDao::blowUp).isInstanceOf(SQLException.class);
}
}
代码示例来源:origin: jdbi/jdbi
@Test
public void testGetHandleProvidesSeperateHandle() {
final TheBasics dao = db.onDemand(TheBasics.class);
Handle h = dao.getHandle();
assertThatThrownBy(() -> h.execute("insert into something (id, name) values (1, 'Stephen')"))
.isInstanceOf(UnableToCreateStatementException.class);
}
代码示例来源:origin: jdbi/jdbi
private <T, R, P extends FoodProvider<T, R, ? extends Food<T, R>>> void testFoodToppingRestrictions(P provider, int id) {
Food<T, R> food = dbRule.getJdbi().onDemand(provider.getDao());
T topping = provider.getTopping();
R restriction = provider.getRestriction();
food.insertTopping(id, topping);
List<Topping<T>> toppings = food.getToppings(id, restriction);
assertThat(toppings).hasSize(1);
assertThat(toppings.get(0).value).isEqualTo(topping);
}
代码示例来源:origin: jdbi/jdbi
@Test
public void testIteratorCloseHandleOnError() throws Exception {
Spiffy s = db.onDemand(Spiffy.class);
assertThatExceptionOfType(JdbiException.class).isThrownBy(s::crashNow);
assertThat(tracker.hasOpenedHandle()).isFalse();
}
代码示例来源:origin: jdbi/jdbi
@Test
public void testIteratorPrepatureClose() throws Exception {
Spiffy spiffy = db.onDemand(Spiffy.class);
spiffy.insert(1, "Tom");
try (ResultIterator<Something> all = spiffy.findAll()) {
// skip
}
assertThat(tracker.hasOpenedHandle()).isFalse();
}
代码示例来源:origin: jdbi/jdbi
@Test
public void testDefaultMethod() {
Spiffy dao = dbRule.getJdbi().onDemand(Spiffy.class);
Something test = dao.insertAndReturn(3, "test");
assertThat(test).isEqualTo(new Something(3, "test"));
}
代码示例来源:origin: jdbi/jdbi
@Test
public void testSimple() {
FooDao fooDao = dbRule.getJdbi().onDemand(FooDao.class);
List<Foo> foos = fooDao.select();
assertThat(foos).isEmpty();
fooDao.insert(1, "John Doe");
fooDao.insert(2, "Jane Doe");
List<Foo> foos2 = fooDao.select();
assertThat(foos2).hasSize(2);
}
代码示例来源:origin: jdbi/jdbi
@Test
public void macAddr() {
MacAddrDao dao = db.getJdbi().onDemand(MacAddrDao.class);
dao.insert(1, "deadbeef1234");
assertThat(dao.select(1)).isEqualTo("de:ad:be:ef:12:34");
dao.insert(2, "1234567890ab");
assertThat(dao.select(2)).isEqualTo("12:34:56:78:90:ab");
}
代码示例来源:origin: jdbi/jdbi
@Test
public void testRegisterRowMapperAnnotationWorks() {
Kabob bob = dbRule.getJdbi().onDemand(Kabob.class);
bob.insert(1, "Henning");
Something henning = bob.find(1);
assertThat(henning).isEqualTo(new Something(1, "Henning"));
}
代码示例来源:origin: jdbi/jdbi
@Test
public void testSimpleTransactionsSucceed() {
SomethingDao dao = dbRule.getJdbi().onDemand(SomethingDao.class);
dao.insertInSingleTransaction(10, "Linda");
}
代码示例来源:origin: jdbi/jdbi
@Test
public void testOnDemandSpiffy() {
Spiffy spiffy = db.onDemand(Spiffy.class);
spiffy.insert(new Something(1, "Tim"));
spiffy.insert(new Something(2, "Diego"));
assertThat(spiffy.findNameById(2)).isEqualTo("Diego");
}
代码示例来源:origin: jdbi/jdbi
@Test
public void testDoublyTransactional() {
final TheBasics dao = db.onDemand(TheBasics.class);
dao.inTransaction(TransactionIsolationLevel.SERIALIZABLE, transactional -> {
transactional.insert(new Something(1, "2"));
inTransaction.set(true);
transactional.insert(new Something(2, "3"));
inTransaction.set(false);
return null;
});
}
代码示例来源:origin: jdbi/jdbi
@Test
public void testIteratorClosedOnReadError() throws Exception {
Spiffy spiffy = db.onDemand(Spiffy.class);
spiffy.insert(1, "Tom");
Iterator<Something> i = spiffy.crashOnFirstRead();
assertThatExceptionOfType(JdbiException.class).isThrownBy(i::next);
assertThat(tracker.hasOpenedHandle()).isFalse();
}
代码示例来源:origin: jdbi/jdbi
@Test
public void testExplicitTransaction() {
Dao dao = dbRule.getJdbi().onDemand(Dao.class);
Something s = dao.inTransaction(transactional -> {
transactional.insert(1, "Brian");
return transactional.findById(1);
});
assertThat(s).isEqualTo(new Something(1, "Brian"));
}
代码示例来源:origin: jdbi/jdbi
@Before
public void setUp() {
db = dbRule.getJdbi();
db.useHandle(h -> h.execute("CREATE ALIAS custom_insert FOR "
+ "\"org.jdbi.v3.sqlobject.TestTimingCollector.customInsert\";"));
db.setTimingCollector(timingCollector);
dao = db.onDemand(DAO.class);
}
代码示例来源:origin: jdbi/jdbi
@Test
public void testWithSqlObjectSetReturnValue() {
Dao dao = dbRule.getJdbi().onDemand(Dao.class);
dao.insert(new Something(1, "Coda"));
dao.insert(new Something(2, "Brian"));
SortedSet<String> rs = dao.findAllAsSet();
assertThat(rs).containsExactly("Brian", "Coda");
}
代码示例来源:origin: jdbi/jdbi
@Before
public void before() {
TimestampedFactory.setTimeSource(clock::withZone);
dbRule.getJdbi().getConfig(TimestampedConfig.class).setTimezone(GMT_PLUS_2);
personDAO = dbRule.getJdbi().onDemand(PersonDAO.class);
personDAO.createTable();
}
内容来源于网络,如有侵权,请联系作者删除!