Skip to content

Commit 777604a

Browse files
author
Ola Sæter Heitmann
committed
Associate futures under propagated connection handling with the current context
1 parent db554f0 commit 777604a

File tree

1 file changed

+6
-6
lines changed
  • vertx-sql-client/src/main/java/io/vertx/sqlclient/impl

1 file changed

+6
-6
lines changed

vertx-sql-client/src/main/java/io/vertx/sqlclient/impl/PoolImpl.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -159,12 +159,12 @@ public Future<SqlConnection> getConnection() {
159159
}
160160

161161
public <T> Future<@Nullable T> withPropagatedTransaction(Function<SqlConnection, Future<@Nullable T>> function) {
162-
Context context = Vertx.currentContext();
162+
ContextInternal context = (ContextInternal) Vertx.currentContext();
163163
SqlConnection sqlConnection = context.getLocal(PROPAGATABLE_CONNECTION);
164164
if (sqlConnection == null) {
165165
return initializePropagatedConnectionAndTransaction(function);
166166
}
167-
return Future.succeededFuture(sqlConnection)
167+
return context.succeededFuture(sqlConnection)
168168
.flatMap(conn -> function.apply(conn)
169169
.onFailure(err -> {
170170
if (!(err instanceof TransactionRollbackException)) {
@@ -174,7 +174,7 @@ public Future<SqlConnection> getConnection() {
174174
}
175175

176176
private <T> Future<@Nullable T> initializePropagatedConnectionAndTransaction(Function<SqlConnection, Future<@Nullable T>> function) {
177-
Context context = Vertx.currentContext();
177+
ContextInternal context = (ContextInternal) Vertx.currentContext();
178178
return getConnection().onComplete(handler -> context.putLocal(PROPAGATABLE_CONNECTION, handler.result()))
179179
.flatMap(conn -> conn
180180
.begin()
@@ -183,14 +183,14 @@ public Future<SqlConnection> getConnection() {
183183
.compose(
184184
res -> tx
185185
.commit()
186-
.flatMap(v -> Future.succeededFuture(res)),
186+
.flatMap(v -> context.succeededFuture(res)),
187187
err -> {
188188
if (err instanceof TransactionRollbackException) {
189-
return Future.failedFuture(err);
189+
return context.failedFuture(err);
190190
} else {
191191
return tx
192192
.rollback()
193-
.compose(v -> Future.failedFuture(err), failure -> Future.failedFuture(err));
193+
.compose(v -> context.failedFuture(err), failure -> context.failedFuture(err));
194194
}
195195
}))
196196
.onComplete(ar -> conn.close(v -> context.removeLocal(PROPAGATABLE_CONNECTION))));

0 commit comments

Comments
 (0)