@Test public void testCachesResultAfterFirstLookup() throws Exception { ClassLoader ctx_loader = Thread.currentThread().getContextClassLoader(); final AtomicInteger load_count = new AtomicInteger(0); Thread.currentThread() .setContextClassLoader( new AbstractClassLoader(ctx_loader, ctx_loader, null) { @Override public InputStream getResourceAsStream(String s) { // will be called twice, once for raw name, once for name + .sql InputStream in = super.getResourceAsStream(s); load_count.incrementAndGet(); return in; } }); Handle h = openHandle(); h.execute("caches-result-after-first-lookup", 1, "Brian"); assertThat(load_count.get(), equalTo(2)); // two lookups, name and name.sql h.execute("caches-result-after-first-lookup", 2, "Sean"); assertThat(load_count.get(), equalTo(2)); // has not increased since previous Thread.currentThread().setContextClassLoader(ctx_loader); }
public void setUp() throws Exception { JdbcDataSource ds = new JdbcDataSource(); ds.setURL("jdbc:h2:mem:test"); dbi = new DBI(ds); handle = dbi.open(); handle.execute("create table something (id int primary key, name varchar(100))"); }
public void tearDown() throws Exception { handle.execute("drop table something"); handle.close(); }
public void setUp() throws Exception { dbi = new DBI("jdbc:h2:mem:" + UUID.randomUUID()); handle = dbi.open(); handle.execute("create table something (id int primary key, name varchar(100))"); }