diff --git a/extensions/reactive-mysql-client/deployment/src/test/java/io/quarkus/reactive/mysql/client/MySQLPoolProducerTest.java b/extensions/reactive-mysql-client/deployment/src/test/java/io/quarkus/reactive/mysql/client/MySQLPoolProducerTest.java index 343b3365a..5620a0828 100644 --- a/extensions/reactive-mysql-client/deployment/src/test/java/io/quarkus/reactive/mysql/client/MySQLPoolProducerTest.java +++ b/extensions/reactive-mysql-client/deployment/src/test/java/io/quarkus/reactive/mysql/client/MySQLPoolProducerTest.java @@ -20,6 +20,7 @@ public class MySQLPoolProducerTest { static final QuarkusUnitTest config = new QuarkusUnitTest() .setArchiveProducer(() -> ShrinkWrap.create(JavaArchive.class) .addClasses(BeanUsingBareMySQLClient.class) + .addClasses(BeanUsingMutinyMySQLClient.class) .addClasses(BeanUsingAxleMySQLClient.class) .addClasses(BeanUsingRXMySQLClient.class)); @@ -32,11 +33,15 @@ public class MySQLPoolProducerTest { @Inject BeanUsingRXMySQLClient beanUsingRx; + @Inject + BeanUsingMutinyMySQLClient beanUsingMutiny; + @Test - public void testVertxInjection() throws Exception { + public void testVertxInjection() { beanUsingBare.verify() .thenCompose(v -> beanUsingAxle.verify()) .thenCompose(v -> beanUsingRx.verify()) + .thenCompose(v -> beanUsingMutiny.verify()) .toCompletableFuture() .join(); } @@ -59,6 +64,20 @@ public class MySQLPoolProducerTest { @ApplicationScoped static class BeanUsingAxleMySQLClient { + @Inject + io.vertx.mutiny.mysqlclient.MySQLPool mysqlClient; + + public CompletionStage verify() { + return mysqlClient.query("SELECT 1") + .onItem().ignore().andContinueWithNull() + .onFailure().recoverWithItem((Void) null) + .subscribeAsCompletionStage(); + } + } + + @ApplicationScoped + static class BeanUsingMutinyMySQLClient { + @Inject io.vertx.axle.mysqlclient.MySQLPool mysqlClient; diff --git a/extensions/reactive-mysql-client/runtime/pom.xml b/extensions/reactive-mysql-client/runtime/pom.xml index bf2be5c32..1c38d5bc9 100644 --- a/extensions/reactive-mysql-client/runtime/pom.xml +++ b/extensions/reactive-mysql-client/runtime/pom.xml @@ -44,6 +44,10 @@ io.smallrye.reactive smallrye-axle-mysql-client + + io.smallrye.reactive + smallrye-mutiny-vertx-mysql-client + diff --git a/extensions/reactive-mysql-client/runtime/src/main/java/io/quarkus/reactive/mysql/client/runtime/MySQLPoolProducer.java b/extensions/reactive-mysql-client/runtime/src/main/java/io/quarkus/reactive/mysql/client/runtime/MySQLPoolProducer.java index 6de7ac9bd..f6cda6659 100644 --- a/extensions/reactive-mysql-client/runtime/src/main/java/io/quarkus/reactive/mysql/client/runtime/MySQLPoolProducer.java +++ b/extensions/reactive-mysql-client/runtime/src/main/java/io/quarkus/reactive/mysql/client/runtime/MySQLPoolProducer.java @@ -4,36 +4,90 @@ import javax.enterprise.context.ApplicationScoped; import javax.enterprise.inject.Produces; import javax.inject.Singleton; +import org.jboss.logging.Logger; + import io.vertx.mysqlclient.MySQLPool; @ApplicationScoped public class MySQLPoolProducer { + private static final Logger LOGGER = Logger.getLogger(MySQLPoolProducer.class); + private volatile MySQLPool mysqlPool; - private volatile io.vertx.axle.mysqlclient.MySQLPool axleMySQLPool; - private volatile io.vertx.reactivex.mysqlclient.MySQLPool rxMySQLPool; + private io.vertx.mutiny.mysqlclient.MySQLPool mutinyMySQLPool; + + /** + * @deprecated The Axle API is deprecated and will be removed in the future, use {@link #mutinyMySQLPool} instead. + */ + @Deprecated + private io.vertx.axle.mysqlclient.MySQLPool axleMySQLPool; + + /** + * @deprecated The RX API is deprecated and will be removed in the future, use {@link #mutinyMySQLPool} instead. + */ + @Deprecated + private io.vertx.reactivex.mysqlclient.MySQLPool rxMySQLPool; void initialize(MySQLPool mysqlPool) { this.mysqlPool = mysqlPool; - this.axleMySQLPool = io.vertx.axle.mysqlclient.MySQLPool.newInstance(mysqlPool); - this.rxMySQLPool = io.vertx.reactivex.mysqlclient.MySQLPool.newInstance(mysqlPool); } + /** + * @return the bare MySQL Pool instance. + */ @Singleton @Produces public MySQLPool mysqlPool() { return mysqlPool; } + /** + * @return the mutiny MySQL Pool instance. The instance is created lazily. + */ @Singleton @Produces - public io.vertx.axle.mysqlclient.MySQLPool axleMySQLPool() { + public synchronized io.vertx.mutiny.mysqlclient.MySQLPool mutinyMySQLPool() { + if (mutinyMySQLPool == null) { + mutinyMySQLPool = io.vertx.mutiny.mysqlclient.MySQLPool.newInstance(mysqlPool); + } + return mutinyMySQLPool; + } + + /** + * Produces the Axle MySQL Pool instance. The instance is created lazily. + * + * @return the Axle MySQL pool instance + * @deprecated The Axle API is deprecated and will be removed in the future, use {@link #mutinyMySQLPool()} instead. + */ + @Singleton + @Produces + @Deprecated + public synchronized io.vertx.axle.mysqlclient.MySQLPool axleMySQLPool() { + if (axleMySQLPool == null) { + LOGGER.warn( + "`io.vertx.axle.mysqlclient.MySQLPool` is deprecated and will be removed in a future version - it is " + + "recommended to switch to `io.vertx.mutiny.mysqlclient.MySQLPool`"); + axleMySQLPool = io.vertx.axle.mysqlclient.MySQLPool.newInstance(mysqlPool); + } return axleMySQLPool; } + /** + * Produces the RX MySQL Pool instance. The instance is created lazily. + * + * @return the RX MySQL pool instance + * @deprecated The RX API is deprecated and will be removed in the future, use {@link #mutinyMySQLPool()} instead. + */ @Singleton @Produces - public io.vertx.reactivex.mysqlclient.MySQLPool rxMySQLPool() { + @Deprecated + public synchronized io.vertx.reactivex.mysqlclient.MySQLPool rxMySQLPool() { + if (rxMySQLPool == null) { + LOGGER.warn( + "`io.vertx.reactivex.mysqlclient.MySQLPool` is deprecated and will be removed in a future version - it is " + + "recommended to switch to `io.vertx.mutiny.mysqlclient.MySQLPool`"); + rxMySQLPool = io.vertx.reactivex.mysqlclient.MySQLPool.newInstance(mysqlPool); + } return rxMySQLPool; } }