Created
January 9, 2020 09:44
-
-
Save vietj/4dac53c3b51f1d185f17cca61d406e95 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private <T> void executeDirect(ContextInternal ctx, AbstractJDBCAction<T> action, Handler<AsyncResult<T>> handler) { | |
getConnection(ctx, ar1 -> { | |
Future<T> fut = Future.future(); | |
fut.setHandler(ar2 -> ctx.runOnContext(v -> handler.handle(ar2))); | |
if (ar1.succeeded()) { | |
JDBCConnectionImpl conn = (JDBCConnectionImpl) ar1.result(); | |
Tracer tracer = ctx.owner().tracer(); | |
Object trace; | |
if (tracer != null) { | |
trace = tracer.sendRequest(ctx.localContextData(), action); | |
} else { | |
trace = null; | |
} | |
Throwable failure = null; | |
T result = null; | |
try { | |
result = action.execute(conn.conn); | |
fut.complete(result); | |
} catch (Exception e) { | |
failure = e; | |
fut.fail(e); | |
} finally { | |
if (tracer != null) { | |
tracer.receiveResponse(ctx.localContextData(), result, trace, failure); | |
} | |
if (metrics != null) { | |
metrics.end(conn.metric, true); | |
} | |
try { | |
conn.conn.close(); | |
} catch (Exception e) { | |
JDBCConnectionImpl.log.error("Failure in closing connection", ar1.cause()); | |
} | |
} | |
} else { | |
fut.fail(ar1.cause()); | |
} | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment