Skip to content

Commit

Permalink
native support
Browse files Browse the repository at this point in the history
  • Loading branch information
zhfeng committed Jul 17, 2020
1 parent 942edbc commit b2a29c0
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import javax.inject.Singleton;

import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.cache.impl.PerpetualCache;
import org.apache.ibatis.javassist.util.proxy.ProxyFactory;
import org.apache.ibatis.logging.log4j.Log4jImpl;
import org.apache.ibatis.scripting.defaults.RawLanguageDriver;
Expand All @@ -26,6 +27,8 @@
import io.quarkus.deployment.annotations.Record;
import io.quarkus.deployment.builditem.CombinedIndexBuildItem;
import io.quarkus.deployment.builditem.FeatureBuildItem;
import io.quarkus.deployment.builditem.nativeimage.NativeImageProxyDefinitionBuildItem;
import io.quarkus.deployment.builditem.nativeimage.NativeImageResourceBuildItem;
import io.quarkus.deployment.builditem.nativeimage.ReflectiveClassBuildItem;
import io.quarkus.deployment.builditem.nativeimage.RuntimeInitializedClassBuildItem;
import io.quarkus.deployment.configuration.ConfigurationError;
Expand Down Expand Up @@ -55,14 +58,22 @@ void reflectiveClasses(BuildProducer<ReflectiveClassBuildItem> reflectiveClass)
ProxyFactory.class,
XMLLanguageDriver.class,
RawLanguageDriver.class));

reflectiveClass.produce(new ReflectiveClassBuildItem(true, true,
PerpetualCache.class));
}

@BuildStep
void addMyBatisMappers(BuildProducer<MyBatisMapperBuildItem> mappers, CombinedIndexBuildItem indexBuildItem) {
void addMyBatisMappers(BuildProducer<MyBatisMapperBuildItem> mappers,
BuildProducer<ReflectiveClassBuildItem> reflective,
BuildProducer<NativeImageProxyDefinitionBuildItem> proxy,
CombinedIndexBuildItem indexBuildItem) {
for (AnnotationInstance i : indexBuildItem.getIndex().getAnnotations(MYBATIS_MAPPER)) {
if (i.target().kind() == AnnotationTarget.Kind.CLASS) {
DotName dotName = i.target().asClass().name();
mappers.produce(new MyBatisMapperBuildItem(dotName));
reflective.produce(new ReflectiveClassBuildItem(true, false, dotName.toString()));
proxy.produce(new NativeImageProxyDefinitionBuildItem(dotName.toString()));
}
}
}
Expand All @@ -72,6 +83,13 @@ void unremovableBeans(BuildProducer<AdditionalBeanBuildItem> beanProducer) {
beanProducer.produce(AdditionalBeanBuildItem.unremovableOf(MyBatisProducers.class));
}

@BuildStep
void initalSql(BuildProducer<NativeImageResourceBuildItem> resource, MyBatisRuntimeConfig config) {
if (config.initialSql.isPresent()) {
resource.produce(new NativeImageResourceBuildItem(config.initialSql.get()));
}
}

@Record(ExecutionTime.RUNTIME_INIT)
@BuildStep
SqlSessionFactoryBuildItem generateSqlSessionFactory(MyBatisRuntimeConfig myBatisRuntimeConfig,
Expand Down
3 changes: 3 additions & 0 deletions integration-tests/mybatis/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,9 @@
<name>native</name>
</property>
</activation>
<properties>
<quarkus.native.additional-build-args>--report-unsupported-elements-at-runtime</quarkus.native.additional-build-args>
</properties>
<build>
<plugins>
<plugin>
Expand Down

0 comments on commit b2a29c0

Please sign in to comment.