Skip to content

Commit

Permalink
Fix XA support for Oracle in native
Browse files Browse the repository at this point in the history
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 quarkusio#23341
  • Loading branch information
gsmet authored and danielsoro committed Sep 20, 2024
1 parent 3f5a5ca commit 65fbce0
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand All @@ -14,7 +15,8 @@ public final class OracleNativeImage {
* by reflection, as commonly expected.
*/
@BuildStep
void reflection(BuildProducer<ReflectiveClassBuildItem> reflectiveClass) {
void reflection(BuildProducer<ReflectiveClassBuildItem> reflectiveClass,
BuildProducer<AdditionalIndexedClassesBuildItem> 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.
Expand All @@ -23,6 +25,10 @@ void reflection(BuildProducer<ReflectiveClassBuildItem> 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
Expand Down
Original file line number Diff line number Diff line change
@@ -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 {

}

0 comments on commit 65fbce0

Please sign in to comment.