Skip to content

Commit

Permalink
Register the CachedConnectionManager as a Synthetic bean (#24)
Browse files Browse the repository at this point in the history
  • Loading branch information
gastaldi authored Sep 2, 2023
1 parent 4f8edfe commit 16bd0b0
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -70,7 +72,6 @@ void additionalBeans(BuildProducer<AdditionalBeanBuildItem> additionalBeans) {
additionalBeans.produce(AdditionalBeanBuildItem.builder()
.addBeanClasses(
IronJacamarSupport.class,
CachedConnectionManagerProducer.class,
ConnectionManagerFactory.class,
TransactionIntegrationImpl.class)
.setUnremovable()
Expand Down Expand Up @@ -148,6 +149,27 @@ void registerResourceEndpoints(CombinedIndexBuildItem combinedIndexBuildItem,
reflectiveClasses.produce(ReflectiveClassBuildItem.builder(endpoints).methods().build());
}

@BuildStep
@Record(value = ExecutionTime.STATIC_INIT)
void registerSingletonSyntheticBeans(BuildProducer<SyntheticBeanBuildItem> 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(
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -53,6 +56,18 @@ public Object apply(SyntheticCreationalContext<Object> context) {
};
}

public Function<SyntheticCreationalContext<CachedConnectionManager>, CachedConnectionManager> createCachedConnectionManager() {
return new Function<SyntheticCreationalContext<CachedConnectionManager>, CachedConnectionManager>() {
@Override
public CachedConnectionManager apply(SyntheticCreationalContext<CachedConnectionManager> context) {
TransactionIntegration ti = context.getInjectedReference(TransactionIntegration.class);
CachedConnectionManagerImpl cachedConnectionManager = new CachedConnectionManagerImpl(ti);
cachedConnectionManager.start();
return cachedConnectionManager;
}
};
}

public RuntimeValue<Future<String>> initResourceAdapter(
String key,
Supplier<Vertx> vertxSupplier)
Expand Down

0 comments on commit 16bd0b0

Please sign in to comment.