use of org.jdbi.v3.core.CloseException in project jdbi by jdbi.
the class StatementContext method close.
@Override
public void close() {
SQLException exception = null;
try {
List<Cleanable> cleanables = new ArrayList<>(this.cleanables);
this.cleanables.clear();
Collections.reverse(cleanables);
for (Cleanable cleanable : cleanables) {
try {
cleanable.close();
} catch (SQLException e) {
if (exception == null) {
exception = e;
} else {
exception.addSuppressed(e);
}
}
}
} finally {
if (exception != null) {
throw new CloseException("Exception thrown while cleaning StatementContext", exception);
}
}
}
use of org.jdbi.v3.core.CloseException in project jdbi by jdbi.
the class TestOnDemandSqlObject method testExceptionOnClose.
@Test(expected = TransactionException.class)
public void testExceptionOnClose() throws Exception {
JdbiPlugin plugin = new JdbiPlugin() {
@Override
public Handle customizeHandle(Handle handle) {
Handle h = spy(handle);
when(h.createUpdate(anyString())).thenThrow(new TransactionException("connection reset"));
doThrow(new CloseException("already closed", null)).when(h).close();
return h;
}
};
db.installPlugin(plugin);
Spiffy s = db.onDemand(Spiffy.class);
s.insert(1, "Tom");
}
Aggregations