本文整理了Java中org.jdbi.v3.core.Handle.attach()
方法的一些代码示例,展示了Handle.attach()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Handle.attach()
方法的具体详情如下:
包路径:org.jdbi.v3.core.Handle
类名称:Handle
方法名:attach
[英]Create a Jdbi extension object of the specified type bound to this handle. The returned extension's lifecycle is coupled to the lifecycle of this handle. Closing the handle will render the extension unusable.
[中]创建绑定到此句柄的指定类型的Jdbi扩展对象。返回的扩展的生命周期耦合到此句柄的生命周期。关闭句柄将使扩展无法使用。
代码示例来源:origin: jdbi/jdbi
/**
* Attach an extension (such as a SqlObject) to the managed handle.
*/
public <T> T attach(final Class<T> extension) {
return getHandle().attach(extension);
}
}
代码示例来源:origin: jdbi/jdbi
@Test
public void testNotEquals() {
DAO dao = handle.attach(DAO.class);
DAO oad = handle.attach(DAO.class);
assertThat(dao).isNotEqualTo(oad);
}
代码示例来源:origin: jdbi/jdbi
@Test
public void testSomethingByArrayHandleVoidWithEmptyArray() {
final SomethingByArrayHandleVoid s = handle.attach(SomethingByArrayHandleVoid.class);
final List<Something> out = s.get(new int[]{});
assertThat(out).isEmpty();
}
代码示例来源:origin: jdbi/jdbi
@Test
public void testSqlObjectReadOnly() throws Exception {
try (Handle h = db.openHandle()) {
RODao dao = h.attach(RODao.class);
assertThat(h.isReadOnly()).isFalse();
assertThat(dao.verifyReadOnly()).isTrue();
assertThat(h.isReadOnly()).isFalse();
}
}
代码示例来源:origin: jdbi/jdbi
@Before
public void setUp() {
handle = dbRule.getSharedHandle();
dao = handle.attach(Dao.class);
}
代码示例来源:origin: jdbi/jdbi
@Test
public void defineListWithoutName() {
assertThatThrownBy(() -> h.attach(DefineListWithoutNameDao.class).listByIds("1"))
.isInstanceOf(UnsupportedOperationException.class)
.hasMessageContaining("parameter was not given a name");
}
代码示例来源:origin: jdbi/jdbi
@Test
public void testGetHandle() {
WithGetHandle g = handle.attach(WithGetHandle.class);
Handle h = g.getHandle();
assertThat(h).isSameAs(handle);
}
代码示例来源:origin: jdbi/jdbi
@Test
public void testSqlObjectJoinRow() {
Handle handle = dbRule.getSharedHandle();
// tag::joinrowusage[]
Multimap<User, Article> joined = HashMultimap.create();
handle.attach(UserArticleDao.class)
.getAuthorship()
.forEach(jr -> joined.put(jr.get(User.class), jr.get(Article.class)));
assertThat(joined).isEqualTo(JoinRowMapperTest.getExpected());
// end::joinrowusage[]
}
代码示例来源:origin: jdbi/jdbi
@Test
public void testReadOnlyOuter() {
try (Handle h = db.openHandle()) {
RODao dao = h.attach(RODao.class);
assertThatThrownBy(() -> dao.readTxn(() -> dao.writeTxn(() -> {}))).isInstanceOf(TransactionException.class);
}
}
代码示例来源:origin: jdbi/jdbi
@Test
public void testInClauseExpansion() {
handle.execute("insert into something (name, id) values ('Brian', 1), ('Jeff', 2), ('Tom', 3)");
DAO dao = handle.attach(DAO.class);
assertThat(dao.findIdsForNames(asList(1, 2))).containsExactly("Brian", "Jeff");
}
代码示例来源:origin: prestodb/presto
@Inject
public H2DaoProvider(DbResourceGroupConfig config)
{
JdbcDataSource ds = new JdbcDataSource();
ds.setURL(requireNonNull(config.getConfigDbUrl(), "resource-groups.config-db-url is null"));
// TODO: this should use onDemand()
this.dao = Jdbi.create(ds)
.installPlugin(new SqlObjectPlugin())
.open()
.attach(H2ResourceGroupsDao.class);
}
代码示例来源:origin: jdbi/jdbi
@Before
public void setUp() {
handle = dbRule.openHandle();
handle.execute("create table something (id serial primary key, name varchar)");
b = handle.attach(UsesBatching.class);
}
代码示例来源:origin: jdbi/jdbi
@Test
public void testInTransaction() {
TransactionStuff txl = handle.attach(TransactionStuff.class);
txl.insert(7, "Keith");
Something s = txl.inTransaction(h -> h.byId(7));
assertThat(s.getName()).isEqualTo("Keith");
}
代码示例来源:origin: jdbi/jdbi
public void testBaz(int id) {
Wombat wombat = handle.attach(Wombat.class);
wombat.insert(new Something(id, "Doo" + id));
String name = handle.createQuery("select name from something where id = " + id)
.mapTo(String.class)
.findOnly();
assertThat(name).isEqualTo("Doo" + id);
}
代码示例来源:origin: jdbi/jdbi
@Test
public void testSqlObjectApi() {
CampaignDao campaignDao = handle.attach(CampaignDao.class);
campaignDao.insertCampaign(3, caps);
assertThat(campaignDao.getCampaignsCaps(3)).isEqualTo(caps);
}
代码示例来源:origin: jdbi/jdbi
@Test
public void testSqlObjectBindRawMapApi() {
CampaignDao campaignDao = handle.attach(CampaignDao.class);
campaignDao.insertCampaignRaw(3, caps);
assertThat(campaignDao.getCampaignsCaps(3)).isEqualTo(caps);
}
代码示例来源:origin: jdbi/jdbi
@Test
public void testWithHandle() {
WithGetHandle g = handle.attach(WithGetHandle.class);
String name = g.withHandle(handle1 -> {
handle1.execute("insert into something (id, name) values (8, 'Mike')");
return handle1.createQuery("select name from something where id = 8").mapTo(String.class).findOnly();
});
assertThat(name).isEqualTo("Mike");
}
代码示例来源:origin: jdbi/jdbi
@Test
public void bindQualifiedField() {
FieldDao fieldDao = handle.attach(FieldDao.class);
fieldDao.insertBindFields(new QualifiedFieldThing(1, "abc"));
assertThat(
handle.select("select name from something")
.mapTo(String.class)
.findOnly())
.isEqualTo("cba");
}
代码示例来源:origin: jdbi/jdbi
@Before
public void createTable() {
h = dbRule.openHandle();
h.createUpdate("create table testBean (valueType varchar(50))").execute();
dao = h.attach(TestDao.class);
}
代码示例来源:origin: jdbi/jdbi
@Test
public void testPluginInstallsJpaMapper() {
Thing brian = new Thing(1, "Brian");
Thing keith = new Thing(2, "Keith");
ThingDao dao = dbRule.getSharedHandle().attach(ThingDao.class);
dao.insert(brian);
dao.insert(keith);
List<Thing> rs = dao.list();
assertThat(rs).containsOnlyOnce(brian, keith);
}
}
内容来源于网络,如有侵权,请联系作者删除!