Skip to content

Commit

Permalink
Enable using SimpleFlatMapper as companion for JOOQ mapping (#218)
Browse files Browse the repository at this point in the history
* Enable using SimpleFlatMapper as companion for JOOQ mapping in GraalVM native build

* Fixed code style

* Make GraalVM substitution conditional based on presence of SimpleFlatMapper on classpath

* Mark SimpleFlatMapperAvailable as internal
  • Loading branch information
morki authored Jun 25, 2020
1 parent e48814b commit efb8e30
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 1 deletion.
1 change: 1 addition & 0 deletions jooq/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ dependencies {
api "org.jooq:jooq:3.13.2"
compileOnly "org.springframework:spring-jdbc:$springVersion"
compileOnly "io.micronaut.data:micronaut-data-tx:$micronautDataVersion"
compileOnly "org.simpleflatmapper:sfm-reflect:8.2.3"

testRuntimeOnly project(":jdbc-tomcat")
testRuntimeOnly "com.h2database:h2:1.4.200"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* Copyright 2017-2020 original authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.micronaut.configuration.jooq.graal;

import com.oracle.svm.core.annotate.Substitute;
import com.oracle.svm.core.annotate.TargetClass;
import org.simpleflatmapper.reflect.asm.AsmFactory;

/**
* Disable not supported ASM bytecode manipulation in GraalVM native image runtime.
*
* @author Lukas Moravec
* @since 2.3.5
*/
@TargetClass(
className = "org.simpleflatmapper.reflect.DefaultReflectionService",
onlyWith = SimpleFlatMapperAvailable.class
)
final class DefaultReflectionServiceSubstitute {
@Substitute
public AsmFactory getAsmFactory(ClassLoader classLoader) {
return null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import com.oracle.svm.core.annotate.TargetClass;

/**
* Disable not supported ProxyMapper in GraalVM native image runtime
* Disable not supported ProxyMapper in GraalVM native image runtime.
*
* @author Lukas Moravec
* @since 2.2.5
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* Copyright 2017-2020 original authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.micronaut.configuration.jooq.graal;

import io.micronaut.core.annotation.Internal;

import java.util.function.BooleanSupplier;

/**
* Companion class for DefaultReflectionServiceSubstitute.
*
* @author Lukas Moravec
* @since 2.3.5
*/
@Internal
public class SimpleFlatMapperAvailable implements BooleanSupplier {
@Override
public boolean getAsBoolean() {
try {
Class.forName("org.simpleflatmapper.reflect.DefaultReflectionService");
return true;
} catch (ClassNotFoundException e) {
return false;
}
}
}

0 comments on commit efb8e30

Please sign in to comment.