} catch (SQLException | IOException | ConfigurationGenerationException ex) { LOG.error("Error: " + ex.getMessage(), ex); DbUtils.rollbackAndCloseQuietly(conn); } finally { DbUtils.rollbackAndCloseQuietly(conn);
@Test public void rollbackAndCloseQuietly() throws Exception { Connection mockConnection = mock(Connection.class); DbUtils.rollbackAndCloseQuietly(mockConnection); verify(mockConnection).rollback(); verify(mockConnection).close(); }
@Test public void rollbackAndCloseQuietlyWithException() throws Exception { Connection mockConnection = mock(Connection.class); doThrow(SQLException.class).when(mockConnection).rollback(); DbUtils.rollbackAndCloseQuietly(mockConnection); verify(mockConnection).rollback(); verify(mockConnection).close(); }
@Test public void rollbackAndCloseQuietlyNull() throws Exception { DbUtils.rollbackAndCloseQuietly(null); }
} catch (SQLException | IOException e) { DbUtils.rollbackAndCloseQuietly(connection);
/** * @see io.apiman.gateway.engine.IRegistry#registerClient(io.apiman.gateway.engine.beans.Client, io.apiman.gateway.engine.async.IAsyncResultHandler) */ @Override public void registerClient(Client client, IAsyncResultHandler<Void> handler) { Connection conn = null; try { conn = ds.getConnection(); conn.setAutoCommit(false); QueryRunner run = new QueryRunner(); // Validate the client and populate the api map with apis found during validation. validateClient(client, conn); // Remove any old data first, then (re)insert run.update(conn, "DELETE FROM gw_clients WHERE org_id = ? AND id = ? AND version = ?", //$NON-NLS-1$ client.getOrganizationId(), client.getClientId(), client.getVersion()); String bean = mapper.writeValueAsString(client); run.update(conn, "INSERT INTO gw_clients (api_key, org_id, id, version, bean) VALUES (?, ?, ?, ?, ?)", //$NON-NLS-1$ client.getApiKey(), client.getOrganizationId(), client.getClientId(), client.getVersion(), bean); DbUtils.commitAndClose(conn); handler.handle(AsyncResultImpl.create((Void) null)); } catch (Exception re) { DbUtils.rollbackAndCloseQuietly(conn); handler.handle(AsyncResultImpl.create(re, Void.class)); } }
/** * @see io.apiman.gateway.engine.IRegistry#registerClient(io.apiman.gateway.engine.beans.Client, io.apiman.gateway.engine.async.IAsyncResultHandler) */ @Override public void registerClient(Client client, IAsyncResultHandler<Void> handler) { Connection conn = null; try { conn = ds.getConnection(); conn.setAutoCommit(false); QueryRunner run = new QueryRunner(); // Validate the client and populate the api map with apis found during validation. validateClient(client, conn); // Remove any old data first, then (re)insert run.update(conn, "DELETE FROM gw_clients WHERE org_id = ? AND id = ? AND version = ?", //$NON-NLS-1$ client.getOrganizationId(), client.getClientId(), client.getVersion()); String bean = mapper.writeValueAsString(client); run.update(conn, "INSERT INTO gw_clients (api_key, org_id, id, version, bean) VALUES (?, ?, ?, ?, ?)", //$NON-NLS-1$ client.getApiKey(), client.getOrganizationId(), client.getClientId(), client.getVersion(), bean); DbUtils.commitAndClose(conn); handler.handle(AsyncResultImpl.create((Void) null)); } catch (Exception re) { DbUtils.rollbackAndCloseQuietly(conn); handler.handle(AsyncResultImpl.create(re, Void.class)); } }