use of org.jdbi.v3.core.Handle in project jdbi by jdbi.
the class TestNamedParams method testCascadedLazyArgs.
@Test
public void testCascadedLazyArgs() throws Exception {
Handle h = dbRule.openHandle();
Update s = h.createUpdate("insert into something (id, name) values (:id, :name)");
Map<String, Object> args = new HashMap<>();
args.put("id", 0);
s.bindMap(args);
s.bindBean(new Object() {
@SuppressWarnings("unused")
public String getName() {
return "Keith";
}
});
int insert_count = s.execute();
assertThat(insert_count).isEqualTo(1);
Something something = h.createQuery("select id, name from something").mapToBean(Something.class).findOnly();
assertThat(something).isEqualTo(new Something(0, "Keith"));
}
use of org.jdbi.v3.core.Handle in project jdbi by jdbi.
the class TestVendorArrays method testHsqlDb.
@Test
public void testHsqlDb() {
Jdbi db = Jdbi.create("jdbc:hsqldb:mem:" + UUID.randomUUID());
init(db);
try (Handle handle = db.open()) {
handle.execute("create table player_stats (" + "name varchar(64) primary key, " + "seasons varchar(36) array, " + "points int array)");
handle.createUpdate("insert into player_stats (name,seasons,points) values (?,?,?)").bind(0, "Jack Johnson").bind(1, new String[] { "2013-2014", "2014-2015", "2015-2016" }).bind(2, new Integer[] { 42, 51, 50 }).execute();
String[] seasons = handle.createQuery("select seasons from player_stats where name=:name").bind("name", "Jack Johnson").mapTo(String[].class).findOnly();
assertThat(seasons).containsExactly("2013-2014", "2014-2015", "2015-2016");
}
}
use of org.jdbi.v3.core.Handle in project jdbi by jdbi.
the class TestPlugins method testCustomizeHandle.
@Test
public void testCustomizeHandle() throws Exception {
Handle h = mock(Handle.class);
dbRule.getJdbi().installPlugin(new JdbiPlugin() {
@Override
public Handle customizeHandle(Handle handle) {
return h;
}
});
assertThat(h).isSameAs(dbRule.getJdbi().open());
}
use of org.jdbi.v3.core.Handle in project jdbi by jdbi.
the class TestArgumentFactory method testRegisterOnJdbi.
@Test
public void testRegisterOnJdbi() throws Exception {
final Jdbi db = dbRule.getJdbi();
db.registerArgument(new NameAF());
try (Handle h = db.open()) {
h.createUpdate("insert into something (id, name) values (:id, :name)").bind("id", 7).bind("name", new Name("Brian", "McCallister")).execute();
String full_name = h.createQuery("select name from something where id = 7").mapTo(String.class).findOnly();
assertThat(full_name).isEqualTo("Brian McCallister");
}
}
use of org.jdbi.v3.core.Handle in project jdbi by jdbi.
the class TestArgumentFactory method testRegisterOnHandle.
@Test
public void testRegisterOnHandle() throws Exception {
try (Handle h = dbRule.openHandle()) {
h.registerArgument(new NameAF());
h.createUpdate("insert into something (id, name) values (:id, :name)").bind("id", 7).bind("name", new Name("Brian", "McCallister")).execute();
String full_name = h.createQuery("select name from something where id = 7").mapTo(String.class).findOnly();
assertThat(full_name).isEqualTo("Brian McCallister");
}
}
Aggregations