diff --git a/deployment/src/main/java/io/quarkiverse/ironjacamar/deployment/IronJacamarProcessor.java b/deployment/src/main/java/io/quarkiverse/ironjacamar/deployment/IronJacamarProcessor.java index 5a386da..213762a 100644 --- a/deployment/src/main/java/io/quarkiverse/ironjacamar/deployment/IronJacamarProcessor.java +++ b/deployment/src/main/java/io/quarkiverse/ironjacamar/deployment/IronJacamarProcessor.java @@ -18,14 +18,15 @@ import org.jboss.jandex.DotName; import org.jboss.jandex.IndexView; import org.jboss.jandex.Type; +import org.jboss.jca.core.api.connectionmanager.ccm.CachedConnectionManager; import org.jboss.jca.core.connectionmanager.pool.mcp.SemaphoreArrayListManagedConnectionPool; +import org.jboss.jca.core.spi.transaction.TransactionIntegration; import org.jboss.jca.core.tx.jbossts.TransactionIntegrationImpl; import io.quarkiverse.ironjacamar.ResourceAdapterFactory; import io.quarkiverse.ironjacamar.ResourceAdapterKind; import io.quarkiverse.ironjacamar.ResourceAdapterTypes; import io.quarkiverse.ironjacamar.ResourceEndpoint; -import io.quarkiverse.ironjacamar.runtime.CachedConnectionManagerProducer; import io.quarkiverse.ironjacamar.runtime.ConnectionManagerFactory; import io.quarkiverse.ironjacamar.runtime.IronJacamarBuildtimeConfig; import io.quarkiverse.ironjacamar.runtime.IronJacamarContainer; @@ -48,6 +49,7 @@ import io.quarkus.deployment.builditem.ServiceStartBuildItem; import io.quarkus.deployment.builditem.nativeimage.NativeImageResourceBuildItem; import io.quarkus.deployment.builditem.nativeimage.ReflectiveClassBuildItem; +import io.quarkus.gizmo.MethodDescriptor; import io.quarkus.logging.Log; import io.quarkus.runtime.RuntimeValue; import io.quarkus.runtime.configuration.ConfigurationException; @@ -70,7 +72,6 @@ void additionalBeans(BuildProducer additionalBeans) { additionalBeans.produce(AdditionalBeanBuildItem.builder() .addBeanClasses( IronJacamarSupport.class, - CachedConnectionManagerProducer.class, ConnectionManagerFactory.class, TransactionIntegrationImpl.class) .setUnremovable() @@ -148,6 +149,27 @@ void registerResourceEndpoints(CombinedIndexBuildItem combinedIndexBuildItem, reflectiveClasses.produce(ReflectiveClassBuildItem.builder(endpoints).methods().build()); } + @BuildStep + @Record(value = ExecutionTime.STATIC_INIT) + void registerSingletonSyntheticBeans(BuildProducer producer, + IronJacamarRecorder recorder) { + // Register the CachedConnectionManager as a Singleton bean + producer.produce(SyntheticBeanBuildItem.configure(CachedConnectionManager.class) + .scope(BuiltinScope.SINGLETON.getInfo()) + .setRuntimeInit() + .unremovable() + .addInjectionPoint(ClassType.create(DotName.createSimple(TransactionIntegration.class))) + .createWith(recorder.createCachedConnectionManager()) + .destroyer(mc -> { + // Invoke CachedConnectionManager#stop() + mc.invokeInterfaceMethod(MethodDescriptor.ofMethod(CachedConnectionManager.class, "stop", void.class), + mc.getMethodParam(0)); + // return is void + mc.returnValue(null); + }) + .done()); + } + @BuildStep @Record(value = ExecutionTime.STATIC_INIT) void registerSyntheticBeans( diff --git a/runtime/src/main/java/io/quarkiverse/ironjacamar/runtime/CachedConnectionManagerProducer.java b/runtime/src/main/java/io/quarkiverse/ironjacamar/runtime/CachedConnectionManagerProducer.java deleted file mode 100644 index eab22d6..0000000 --- a/runtime/src/main/java/io/quarkiverse/ironjacamar/runtime/CachedConnectionManagerProducer.java +++ /dev/null @@ -1,27 +0,0 @@ -package io.quarkiverse.ironjacamar.runtime; - -import jakarta.enterprise.context.ApplicationScoped; -import jakarta.enterprise.inject.Disposes; -import jakarta.enterprise.inject.Produces; - -import org.jboss.jca.core.api.connectionmanager.ccm.CachedConnectionManager; -import org.jboss.jca.core.connectionmanager.ccm.CachedConnectionManagerImpl; -import org.jboss.jca.core.spi.transaction.TransactionIntegration; - -import io.quarkus.arc.DefaultBean; - -public class CachedConnectionManagerProducer { - - @Produces - @ApplicationScoped - @DefaultBean - public CachedConnectionManager createCachedConnectionManager(TransactionIntegration transactionIntegration) { - CachedConnectionManager ccm = new CachedConnectionManagerImpl(transactionIntegration); - ccm.start(); - return ccm; - } - - public void destroyCachedConnectionManager(@Disposes CachedConnectionManager ccm) { - ccm.stop(); - } -} diff --git a/runtime/src/main/java/io/quarkiverse/ironjacamar/runtime/IronJacamarRecorder.java b/runtime/src/main/java/io/quarkiverse/ironjacamar/runtime/IronJacamarRecorder.java index 23e04c3..941351a 100644 --- a/runtime/src/main/java/io/quarkiverse/ironjacamar/runtime/IronJacamarRecorder.java +++ b/runtime/src/main/java/io/quarkiverse/ironjacamar/runtime/IronJacamarRecorder.java @@ -9,6 +9,9 @@ import jakarta.resource.spi.XATerminator; import jakarta.transaction.TransactionSynchronizationRegistry; +import org.jboss.jca.core.api.connectionmanager.ccm.CachedConnectionManager; +import org.jboss.jca.core.connectionmanager.ccm.CachedConnectionManagerImpl; +import org.jboss.jca.core.spi.transaction.TransactionIntegration; import org.jboss.logging.Logger; import io.quarkus.arc.Arc; @@ -53,6 +56,18 @@ public Object apply(SyntheticCreationalContext context) { }; } + public Function, CachedConnectionManager> createCachedConnectionManager() { + return new Function, CachedConnectionManager>() { + @Override + public CachedConnectionManager apply(SyntheticCreationalContext context) { + TransactionIntegration ti = context.getInjectedReference(TransactionIntegration.class); + CachedConnectionManagerImpl cachedConnectionManager = new CachedConnectionManagerImpl(ti); + cachedConnectionManager.start(); + return cachedConnectionManager; + } + }; + } + public RuntimeValue> initResourceAdapter( String key, Supplier vertxSupplier)