use of org.jdbi.v3.sqlobject.SqlObjectPlugin in project jdbi by jdbi.
the class TestTransactional method setUp.
@Before
public void setUp() throws Exception {
final JdbcDataSource ds = new JdbcDataSource() {
private static final long serialVersionUID = 1L;
@Override
public Connection getConnection() throws SQLException {
final Connection real = super.getConnection();
return (Connection) Proxy.newProxyInstance(real.getClass().getClassLoader(), new Class<?>[] { Connection.class }, new TxnIsolationCheckingInvocationHandler(real));
}
};
// in MVCC mode h2 doesn't shut down immediately on all connections closed, so need random db name
ds.setURL(String.format("jdbc:h2:mem:%s;MVCC=TRUE", UUID.randomUUID()));
db = Jdbi.create(ds);
db.installPlugin(new SqlObjectPlugin());
db.registerRowMapper(new SomethingMapper());
handle = db.open();
handle.execute("create table something (id int primary key, name varchar(100))");
}
use of org.jdbi.v3.sqlobject.SqlObjectPlugin in project dropwizard by dropwizard.
the class JdbiFactory method configure.
/**
* Overridable function to allow extra customization of the created {@link Jdbi}
* instance.
*
* <p>
* If this is overridden it is strongly recommend that
* {@code super.configure(jdbi, configuration)} is invoked before any other
* changes are made if you intend to use the default as a base so that the
* customized settings will supersede the defaults
* </p>
*
* @param jdbi
*/
protected void configure(final Jdbi jdbi) {
jdbi.installPlugin(new SqlObjectPlugin());
jdbi.installPlugin(new JodaTimePlugin());
jdbi.installPlugin(new GuavaPlugin());
}
use of org.jdbi.v3.sqlobject.SqlObjectPlugin in project jdbi by jdbi.
the class IntroductionTest method sqlObject.
// end::sqlobject-declaration[]
@Test
public void sqlObject() {
// tag::sqlobject-usage[]
Jdbi jdbi = Jdbi.create("jdbc:h2:mem:test");
jdbi.installPlugin(new SqlObjectPlugin());
// Jdbi implements your interface based on annotations
List<User> userNames = jdbi.withExtension(UserDao.class, dao -> {
dao.createTable();
dao.insertPositional(0, "Alice");
dao.insertPositional(1, "Bob");
dao.insertNamed(2, "Clarice");
dao.insertBean(new User(3, "David"));
return dao.listUsers();
});
assertThat(userNames).containsExactly(new User(0, "Alice"), new User(1, "Bob"), new User(2, "Clarice"), new User(3, "David"));
// end::sqlobject-usage[]
}
use of org.jdbi.v3.sqlobject.SqlObjectPlugin in project jdbi by jdbi.
the class TestNewApiOnDbiAndHandle method setUp.
@Before
public void setUp() throws Exception {
JdbcDataSource ds = new JdbcDataSource();
ds.setURL("jdbc:h2:mem:" + UUID.randomUUID());
db = Jdbi.create(ds);
db.installPlugin(new SqlObjectPlugin());
db.registerRowMapper(new SomethingMapper());
handle = db.open();
handle.execute("create table something (id int primary key, name varchar(100))");
}
use of org.jdbi.v3.sqlobject.SqlObjectPlugin in project jdbi by jdbi.
the class TestReentrancy method setUp.
@Before
public void setUp() throws Exception {
JdbcDataSource ds = new JdbcDataSource();
// in MVCC mode h2 doesn't shut down immediately on all connections closed, so need random db name
ds.setURL(String.format("jdbc:h2:mem:%s;MVCC=TRUE", UUID.randomUUID()));
db = Jdbi.create(ds);
db.installPlugin(new SqlObjectPlugin());
db.registerRowMapper(new SomethingMapper());
handle = db.open();
handle.execute("create table something (id int primary key, name varchar(100))");
}
Aggregations