diff --git a/native-image-support/src/main/java/com/google/cloud/nativeimage/features/clients/SpannerFeature.java b/native-image-support/src/main/java/com/google/cloud/nativeimage/features/clients/SpannerFeature.java index 3e5495840d..7c9fca1421 100644 --- a/native-image-support/src/main/java/com/google/cloud/nativeimage/features/clients/SpannerFeature.java +++ b/native-image-support/src/main/java/com/google/cloud/nativeimage/features/clients/SpannerFeature.java @@ -21,6 +21,7 @@ import com.oracle.svm.core.configure.ResourcesRegistry; import org.graalvm.nativeimage.ImageSingletons; import org.graalvm.nativeimage.hosted.Feature; +import org.graalvm.nativeimage.impl.ConfigurationCondition; /** Registers Spanner library classes for reflection. */ @AutomaticFeature @@ -28,6 +29,24 @@ final class SpannerFeature implements Feature { private static final String SPANNER_CLASS = "com.google.spanner.v1.SpannerGrpc"; private static final String SPANNER_TEST_CLASS = "com.google.cloud.spanner.GceTestEnvConfig"; + private static final String CLIENT_SIDE_IMPL_CLASS = + "com.google.cloud.spanner.connection.ClientSideStatementImpl"; + private static final String CLIENT_SIDE_VALUE_CONVERTER = + "com.google.cloud.spanner.connection.ClientSideStatementValueConverters"; + private static final String CONNECTION_IMPL = + "com.google.cloud.spanner.connection.ConnectionImpl"; + private static final String CLIENT_SIDE_STATEMENTS = + "com.google.cloud.spanner.connection.ClientSideStatements"; + private static final String CONNECTION_STATEMENT_EXECUTOR = + "com.google.cloud.spanner.connection.ConnectionStatementExecutor"; + private static final String CLIENT_SIDE_STATEMENT_NO_PARAM_EXECUTOR = + "com.google.cloud.spanner.connection.ClientSideStatementNoParamExecutor"; + private static final String CLIENT_SIDE_STATEMENT_SET_EXECUTOR = + "com.google.cloud.spanner.connection.ClientSideStatementSetExecutor"; + private static final String ABSTRACT_STATEMENT_PARSER = + "com.google.cloud.spanner.connection.AbstractStatementParser"; + private static final String STATEMENT_PARSER = + "com.google.cloud.spanner.connection.SpannerStatementParser"; @Override public void beforeAnalysis(BeforeAnalysisAccess access) { @@ -35,6 +54,34 @@ public void beforeAnalysis(BeforeAnalysisAccess access) { if (spannerTestClass != null) { NativeImageUtils.registerConstructorsForReflection(access, SPANNER_TEST_CLASS); } + if (access.findClassByName(CLIENT_SIDE_IMPL_CLASS) != null) { + NativeImageUtils.registerClassHierarchyForReflection(access, CLIENT_SIDE_IMPL_CLASS); + } + if (access.findClassByName(CLIENT_SIDE_STATEMENT_NO_PARAM_EXECUTOR) != null) { + NativeImageUtils.registerClassForReflection(access, CLIENT_SIDE_STATEMENT_NO_PARAM_EXECUTOR); + } + if (access.findClassByName(CLIENT_SIDE_STATEMENT_SET_EXECUTOR) != null) { + NativeImageUtils.registerClassForReflection(access, CLIENT_SIDE_STATEMENT_SET_EXECUTOR); + } + if (access.findClassByName(CLIENT_SIDE_VALUE_CONVERTER) != null) { + NativeImageUtils.registerClassHierarchyForReflection(access, CLIENT_SIDE_VALUE_CONVERTER); + } + if (access.findClassByName(CLIENT_SIDE_STATEMENTS) != null) { + NativeImageUtils.registerClassForReflection(access, CLIENT_SIDE_STATEMENTS); + } + if (access.findClassByName(CONNECTION_STATEMENT_EXECUTOR) != null) { + NativeImageUtils.registerClassForReflection(access, CONNECTION_STATEMENT_EXECUTOR); + } + if (access.findClassByName(CONNECTION_IMPL) != null) { + NativeImageUtils.registerClassForReflection(access, CONNECTION_IMPL); + } + if (access.findClassByName(ABSTRACT_STATEMENT_PARSER) != null) { + NativeImageUtils.registerClassHierarchyForReflection(access, ABSTRACT_STATEMENT_PARSER); + } + if (access.findClassByName(STATEMENT_PARSER) != null) { + NativeImageUtils.registerConstructorsForReflection(access, STATEMENT_PARSER); + } + Class spannerClass = access.findClassByName(SPANNER_CLASS); if (spannerClass != null) { NativeImageUtils.registerClassHierarchyForReflection( @@ -47,9 +94,13 @@ public void beforeAnalysis(BeforeAnalysisAccess access) { // Resources ResourcesRegistry resourcesRegistry = ImageSingletons.lookup(ResourcesRegistry.class); resourcesRegistry.addResources( + ConfigurationCondition.alwaysTrue(), "\\Qcom/google/cloud/spanner/connection/ClientSideStatements.json\\E"); resourcesRegistry.addResources( "\\Qcom/google/cloud/spanner/spi/v1/grpc-gcp-apiconfig.json\\E"); + resourcesRegistry.addResources( + ConfigurationCondition.alwaysTrue(), + "\\Qcom/google/cloud/spanner/connection/ITSqlScriptTest_TestQueryOptions.sql\\E"); } } }