From 65fbce093d4230822d54e1c1e3c078373d3eaa2a Mon Sep 17 00:00:00 2001 From: Guillaume Smet Date: Fri, 17 May 2024 17:40:32 +0200 Subject: [PATCH] Fix XA support for Oracle in native We need to register a few more classes for reflection and also all their nested classes, which is why I use `@RegisterForReflection` instead of the usual build item. Fixes #23341 --- .../jdbc/oracle/deployment/OracleNativeImage.java | 8 +++++++- .../oracle/runtime/graal/OracleReflections.java | 13 +++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 extensions/jdbc/jdbc-oracle/runtime/src/main/java/io/quarkus/jdbc/oracle/runtime/graal/OracleReflections.java diff --git a/extensions/jdbc/jdbc-oracle/deployment/src/main/java/io/quarkus/jdbc/oracle/deployment/OracleNativeImage.java b/extensions/jdbc/jdbc-oracle/deployment/src/main/java/io/quarkus/jdbc/oracle/deployment/OracleNativeImage.java index 9bfd954d11e47d..8167b900a952ea 100644 --- a/extensions/jdbc/jdbc-oracle/deployment/src/main/java/io/quarkus/jdbc/oracle/deployment/OracleNativeImage.java +++ b/extensions/jdbc/jdbc-oracle/deployment/src/main/java/io/quarkus/jdbc/oracle/deployment/OracleNativeImage.java @@ -2,6 +2,7 @@ import io.quarkus.deployment.annotations.BuildProducer; import io.quarkus.deployment.annotations.BuildStep; +import io.quarkus.deployment.builditem.AdditionalIndexedClassesBuildItem; import io.quarkus.deployment.builditem.nativeimage.ReflectiveClassBuildItem; /** @@ -14,7 +15,8 @@ public final class OracleNativeImage { * by reflection, as commonly expected. */ @BuildStep - void reflection(BuildProducer reflectiveClass) { + void reflection(BuildProducer reflectiveClass, + BuildProducer additionalIndexedClasses) { //Not strictly necessary when using Agroal, as it also registers //any JDBC driver being configured explicitly through its configuration. //We register it for the sake of people not using Agroal. @@ -23,6 +25,10 @@ void reflection(BuildProducer reflectiveClass) { final String driverName = "oracle.jdbc.driver.OracleDriver"; reflectiveClass.produce(ReflectiveClassBuildItem.builder(driverName).build()); + // This is needed when using XA and we use the `@RegisterForReflection` trick to make sure all nested classes are registered for reflection + additionalIndexedClasses + .produce(new AdditionalIndexedClassesBuildItem("io.quarkus.jdbc.oracle.runtime.graal.OracleReflections")); + // for ldap style jdbc urls. e.g. jdbc:oracle:thin:@ldap://oid:5000/mydb1,cn=OracleContext,dc=myco,dc=com // // Note that all JDK provided InitialContextFactory impls from the JDK registered via module descriptors diff --git a/extensions/jdbc/jdbc-oracle/runtime/src/main/java/io/quarkus/jdbc/oracle/runtime/graal/OracleReflections.java b/extensions/jdbc/jdbc-oracle/runtime/src/main/java/io/quarkus/jdbc/oracle/runtime/graal/OracleReflections.java new file mode 100644 index 00000000000000..f489dc605beeae --- /dev/null +++ b/extensions/jdbc/jdbc-oracle/runtime/src/main/java/io/quarkus/jdbc/oracle/runtime/graal/OracleReflections.java @@ -0,0 +1,13 @@ +package io.quarkus.jdbc.oracle.runtime.graal; + +import io.quarkus.runtime.annotations.RegisterForReflection; + +/** + * We don't use a build item here as we also need to register all the nested classes and there's no way to do it easily with the + * build item for now. + */ +@RegisterForReflection(targets = { oracle.jdbc.xa.OracleXADataSource.class, + oracle.jdbc.datasource.impl.OracleDataSource.class }) +public class OracleReflections { + +}