use of io.quarkiverse.mybatis.runtime.meta.MapperDataSource in project quarkus-mybatis by quarkiverse.
the class QuarkusDataSource method buildXmlMapper.
private void buildXmlMapper(InputStream filterStream, InputStream resourceStream, String resource, Configuration configuration, String dataSourceName) throws ClassNotFoundException {
final XPathParser xPathParser = new XPathParser(filterStream, true, configuration.getVariables(), new XMLMapperEntityResolver());
String nameSpace = xPathParser.evalNode("/mapper").getStringAttribute("namespace");
final Class<?> mapperClass = Resources.classForName(nameSpace);
final MapperDataSource annotation = mapperClass.getAnnotation(MapperDataSource.class);
if ((annotation != null && annotation.value().equals(dataSourceName)) || (annotation == null && dataSourceName.equals("<default>"))) {
XMLMapperBuilder xmlMapperBuilder = new XMLMapperBuilder(resourceStream, configuration, resource, configuration.getSqlFragments());
xmlMapperBuilder.parse();
}
}
use of io.quarkiverse.mybatis.runtime.meta.MapperDataSource in project quarkus-mybatis by quarkiverse.
the class MyBatisProcessor method addMyBatisMappers.
@BuildStep
@Overridable
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();
reflective.produce(new ReflectiveClassBuildItem(true, false, dotName.toString()));
proxy.produce(new NativeImageProxyDefinitionBuildItem(dotName.toString()));
Optional<AnnotationInstance> mapperDatasource = i.target().asClass().annotations().entrySet().stream().filter(entry -> entry.getKey().equals(MYBATIS_MAPPER_DATA_SOURCE)).map(Map.Entry::getValue).map(annotationList -> annotationList.get(0)).findFirst();
if (mapperDatasource.isPresent()) {
String dataSourceName = mapperDatasource.get().value().asString();
mappers.produce(new MyBatisMapperBuildItem(dotName, dataSourceName));
} else {
mappers.produce(new MyBatisMapperBuildItem(dotName, "<default>"));
}
}
}
}
Aggregations