use of org.jdbi.v3.core.Handle in project jdbi by jdbi.
the class TestNamedParams method testFunctionsNestedBinding.
@Test
public void testFunctionsNestedBinding() throws Exception {
Handle h = dbRule.openHandle();
assertThat(h.createUpdate("insert into something (id, name) values (:my.nested.id, :my.nested.name)").bindMethods("my", new Object() {
@SuppressWarnings("unused")
public NoArgFunctions nested() {
return new NoArgFunctions(0, "Keith");
}
}).execute()).isEqualTo(1);
assertThat(h.select("select * from something where id = ?", 0).mapToBean(Something.class).findOnly()).isEqualTo(new Something(0, "Keith"));
}
use of org.jdbi.v3.core.Handle in project jdbi by jdbi.
the class SqlObjectTest method setUp.
@Before
public void setUp() {
final Handle handle = dbRule.getSharedHandle();
dao = handle.attach(SomethingDao.class);
}
use of org.jdbi.v3.core.Handle in project tutorials by eugenp.
the class JdbiTest method whenSelectMapToString_thenStream.
@Test
public void whenSelectMapToString_thenStream() {
Jdbi jdbi = Jdbi.create("jdbc:hsqldb:mem:testDB", "sa", "");
jdbi.useHandle(handle -> {
handle.execute("create table PROJECT_5 (ID IDENTITY, NAME VARCHAR (50), URL VARCHAR (100))");
handle.execute("INSERT INTO PROJECT_5 (NAME, URL) VALUES ('tutorials', 'github.com/eugenp/tutorials')");
handle.execute("INSERT INTO PROJECT_5 (NAME, URL) VALUES ('REST with Spring', 'github.com/eugenp/REST-With-Spring')");
Query query = handle.createQuery("select name, url from PROJECT_5 order by id");
query.mapTo(String.class).useStream((Stream<String> stream) -> assertEquals("tutorials", stream.findFirst().get()));
});
}
use of org.jdbi.v3.core.Handle in project tutorials by eugenp.
the class JdbiTest method whenTransactionRollback_thenNoDataInserted.
@Test
public void whenTransactionRollback_thenNoDataInserted() {
Jdbi jdbi = Jdbi.create("jdbc:hsqldb:mem:testDB", "sa", "");
jdbi.useHandle(handle -> {
handle.useTransaction(h -> {
handle.execute("create table PROJECT_12 (ID IDENTITY, NAME VARCHAR (50), URL VARCHAR (100))");
handle.execute("INSERT INTO PROJECT_12 (NAME, URL) VALUES ('tutorials', 'https://github.com/eugenp/tutorials')");
handle.execute("INSERT INTO PROJECT_12 (NAME, URL) VALUES ('REST with Spring', 'https://github.com/eugenp/REST-With-Spring')");
handle.rollback();
List<Map<String, Object>> list = handle.select("SELECT * FROM PROJECT_12").mapToMap().list();
assertEquals(0, list.size());
});
});
}
use of org.jdbi.v3.core.Handle in project tutorials by eugenp.
the class JdbiTest method whenParameters_thenReplacement.
@Test
public void whenParameters_thenReplacement() {
Jdbi jdbi = Jdbi.create("jdbc:hsqldb:mem:testDB", "sa", "");
jdbi.useHandle(handle -> {
handle.execute("create table PROJECT_10 (ID IDENTITY, NAME VARCHAR (50), URL VARCHAR (100))");
Update update1 = handle.createUpdate("INSERT INTO PROJECT_10 (NAME, URL) VALUES (?, ?)");
update1.bind(0, "tutorials");
update1.bind(1, "github.com/eugenp/tutorials");
int rows = update1.execute();
assertEquals(1, rows);
Update update2 = handle.createUpdate("INSERT INTO PROJECT_10 (NAME, URL) VALUES (:name, :url)");
update2.bind("name", "REST with Spring");
update2.bind("url", "github.com/eugenp/REST-With-Spring");
rows = update2.execute();
assertEquals(1, rows);
List<Map<String, Object>> list = handle.select("SELECT * FROM PROJECT_10 WHERE NAME = 'tutorials'").mapToMap().list();
assertEquals(1, list.size());
list = handle.select("SELECT * FROM PROJECT_10 WHERE NAME = 'REST with Spring'").mapToMap().list();
assertEquals(1, list.size());
});
}
Aggregations