Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions vertx-sql-client/src/main/java/io/vertx/sqlclient/Pool.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
import io.vertx.core.Vertx;
import io.vertx.core.net.NetClientOptions;
import io.vertx.core.internal.ContextInternal;
import io.vertx.sqlclient.internal.pool.PoolImpl;
import io.vertx.sqlclient.impl.TransactionPropagationLocal;
import io.vertx.sqlclient.impl.Utils;
import io.vertx.sqlclient.spi.Driver;

Expand Down Expand Up @@ -158,7 +158,7 @@ static Pool pool(Vertx vertx, SqlConnectOptions database, PoolOptions options) {
default <T> Future<@Nullable T> withTransaction(TransactionPropagation txPropagation, Function<SqlConnection, Future<@Nullable T>> function) {
if (txPropagation == TransactionPropagation.CONTEXT) {
ContextInternal context = (ContextInternal) Vertx.currentContext();
SqlConnection sqlConnection = context.getLocal(PoolImpl.PROPAGATABLE_CONNECTION);
SqlConnection sqlConnection = context.getLocal(TransactionPropagationLocal.KEY);
if (sqlConnection == null) {
return startPropagatableConnection(this, function);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package io.vertx.sqlclient.impl;

import io.vertx.core.internal.VertxBootstrap;
import io.vertx.core.spi.VertxServiceProvider;
import io.vertx.core.spi.context.storage.ContextLocal;
import io.vertx.sqlclient.SqlConnection;

public class TransactionPropagationLocal implements VertxServiceProvider {

public static final ContextLocal<SqlConnection> KEY = ContextLocal.registerLocal(SqlConnection.class);

@Override
public void init(VertxBootstrap builder) {
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import io.vertx.core.spi.metrics.PoolMetrics;
import io.vertx.core.spi.metrics.VertxMetrics;
import io.vertx.sqlclient.*;
import io.vertx.sqlclient.impl.TransactionPropagationLocal;
import io.vertx.sqlclient.impl.pool.SqlConnectionPool;
import io.vertx.sqlclient.internal.Connection;
import io.vertx.sqlclient.internal.SqlClientBase;
Expand Down Expand Up @@ -54,8 +55,6 @@ public class PoolImpl extends SqlClientBase implements Pool, Closeable {
private final Handler<SqlConnection> connectionInitializer;
private long timerID;

public static final String PROPAGATABLE_CONNECTION = "propagatable_connection";

public PoolImpl(VertxInternal vertx,
Driver driver,
boolean pipelined,
Expand Down Expand Up @@ -149,7 +148,7 @@ public Future<SqlConnection> getConnection() {

public static <T> Future<@Nullable T> startPropagatableConnection(Pool pool, Function<SqlConnection, Future<@Nullable T>> function) {
ContextInternal context = (ContextInternal) Vertx.currentContext();
return pool.getConnection().onComplete(handler -> context.putLocal(PROPAGATABLE_CONNECTION, handler.result()))
return pool.getConnection().onComplete(handler -> context.putLocal(TransactionPropagationLocal.KEY, handler.result()))
.flatMap(conn -> conn
.begin()
.flatMap(tx -> function
Expand All @@ -167,7 +166,7 @@ public Future<SqlConnection> getConnection() {
.compose(v -> context.failedFuture(err), failure -> context.failedFuture(err));
}
}))
.onComplete(ar -> conn.close().onComplete(v -> context.removeLocal(PROPAGATABLE_CONNECTION))));
.onComplete(ar -> conn.close().onComplete(v -> context.removeLocal(TransactionPropagationLocal.KEY))));
}

@Override
Expand Down
5 changes: 5 additions & 0 deletions vertx-sql-client/src/main/java/module-info.java
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import io.vertx.core.spi.VertxServiceProvider;
import io.vertx.sqlclient.impl.TransactionPropagationLocal;

module io.vertx.sql.client {

requires io.netty.common;
Expand All @@ -18,6 +21,8 @@

uses io.vertx.sqlclient.spi.Driver;

provides io.vertx.core.spi.VertxServiceProvider with io.vertx.sqlclient.impl.TransactionPropagationLocal;

// Expose enough for implementing a client back-end on top of this API (e.g. vertx-jdbc-client)

exports io.vertx.sqlclient.internal;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
io.vertx.sqlclient.impl.TransactionPropagationLocal