Skip to content

Commit

Permalink
Use GraalVM utility class from core (#278)
Browse files Browse the repository at this point in the history
* Use GraalVM utility class from core. Fixes #275

* Upgrade to Micronaut 2.1 and fix compilation issue

* Add missing class for H2
  • Loading branch information
ilopmar authored Oct 21, 2020
1 parent 46b12da commit f90d8d5
Show file tree
Hide file tree
Showing 3 changed files with 122 additions and 212 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
projectVersion=3.2.0.BUILD-SNAPSHOT
micronautBuildVersion=1.1.5
micronautDocsVersion=1.0.24
micronautVersion=2.0.0
micronautVersion=2.1.1
micronautTestVersion=2.1.1

groovyVersion=3.0.3
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@
package io.micronaut.configuration.hibernate.jpa.graal;

import com.oracle.svm.core.annotate.AutomaticFeature;
import io.micronaut.core.annotation.Internal;
import io.micronaut.core.graal.AutomaticFeatureUtils;
import org.graalvm.nativeimage.hosted.Feature;
import org.graalvm.nativeimage.hosted.RuntimeReflection;
import org.hibernate.dialect.*;

/**
Expand All @@ -28,16 +29,14 @@
* @since 2.2.1
*/
@AutomaticFeature
@Internal
final class HibernateFeature implements Feature {

@Override
public void beforeAnalysis(BeforeAnalysisAccess access) {
if (registerIfPresent(access, "org.h2.Driver", H2Dialect.class)) {
Class<?> constClass = access.findClassByName("org.h2.engine.Constants");
if (constClass != null) {
RuntimeReflection.register(constClass);
RuntimeReflection.register(constClass.getDeclaredFields());
}
}
registerIfPresent(access, "org.h2.Driver",
H2Dialect.class
);

registerIfPresent(access, "org.postgresql.Driver",
PostgreSQL9Dialect.class,
Expand All @@ -51,11 +50,6 @@ public void beforeAnalysis(BeforeAnalysisAccess access) {
PostgreSQL82Dialect.class
);

registerIfPresent(access, "com.microsoft.sqlserver.jdbc.SQLServerResource",
SQLServer2005Dialect.class,
SQLServer2008Dialect.class,
SQLServer2012Dialect.class);

registerIfPresent(access, "org.mariadb.jdbc.Driver",
MariaDBDialect.class,
MariaDB10Dialect.class,
Expand All @@ -82,15 +76,13 @@ public void beforeAnalysis(BeforeAnalysisAccess access) {
MySQL8Dialect.class);
}

private boolean registerIfPresent(BeforeAnalysisAccess access, String name, Class<? extends Dialect>... dialects) {
private void registerIfPresent(BeforeAnalysisAccess access, String name, Class<? extends Dialect>... dialects) {
Class<?> driver = access.findClassByName(name);
boolean present = driver != null;
if (present) {
for (Class<? extends Dialect> dialect : dialects) {
RuntimeReflection.register(dialect);
RuntimeReflection.registerForReflectiveInstantiation(dialect);
AutomaticFeatureUtils.registerClassForRuntimeReflectionAndReflectiveInstantiation(access, dialect.getName());
}
}
return present;
}
}
Loading

0 comments on commit f90d8d5

Please sign in to comment.