Skip to content

Commit

Permalink
Fix apache#1384 camel-mybatis native support
Browse files Browse the repository at this point in the history
  • Loading branch information
zhfeng committed Feb 8, 2022
1 parent 90f3d3f commit 5c9c973
Show file tree
Hide file tree
Showing 31 changed files with 619 additions and 239 deletions.
6 changes: 3 additions & 3 deletions docs/modules/ROOT/examples/components/mybatis-bean.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
# This file was generated by camel-quarkus-maven-plugin:update-extension-doc-page
cqArtifactId: camel-quarkus-mybatis
cqArtifactIdBase: mybatis
cqNativeSupported: false
cqStatus: Preview
cqNativeSupported: true
cqStatus: Stable
cqDeprecated: false
cqJvmSince: 1.1.0
cqNativeSince: n/a
cqNativeSince: 2.8.0
cqCamelPartName: mybatis-bean
cqCamelPartTitle: MyBatis Bean
cqCamelPartDescription: Perform queries, inserts, updates or deletes in a relational database using MyBatis.
Expand Down
6 changes: 3 additions & 3 deletions docs/modules/ROOT/examples/components/mybatis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
# This file was generated by camel-quarkus-maven-plugin:update-extension-doc-page
cqArtifactId: camel-quarkus-mybatis
cqArtifactIdBase: mybatis
cqNativeSupported: false
cqStatus: Preview
cqNativeSupported: true
cqStatus: Stable
cqDeprecated: false
cqJvmSince: 1.1.0
cqNativeSince: n/a
cqNativeSince: 2.8.0
cqCamelPartName: mybatis
cqCamelPartTitle: MyBatis
cqCamelPartDescription: Performs a query, poll, insert, update or delete in a relational database using MyBatis.
Expand Down
27 changes: 22 additions & 5 deletions docs/modules/ROOT/pages/reference/extensions/mybatis.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@
= MyBatis
:linkattrs:
:cq-artifact-id: camel-quarkus-mybatis
:cq-native-supported: false
:cq-status: Preview
:cq-status-deprecation: Preview
:cq-native-supported: true
:cq-status: Stable
:cq-status-deprecation: Stable
:cq-description: Performs a query, poll, insert, update or delete in a relational database using MyBatis.
:cq-deprecated: false
:cq-jvm-since: 1.1.0
:cq-native-since: n/a
:cq-native-since: 2.8.0

[.badges]
[.badge-key]##JVM since##[.badge-supported]##1.1.0## [.badge-key]##Native##[.badge-unsupported]##unsupported##
[.badge-key]##JVM since##[.badge-supported]##1.1.0## [.badge-key]##Native since##[.badge-supported]##2.8.0##

Performs a query, poll, insert, update or delete in a relational database using MyBatis.

Expand All @@ -25,6 +25,10 @@ Please refer to the above links for usage and configuration details.

== Maven coordinates

https://code.quarkus.io/?extension-search=camel-quarkus-mybatis[Create a new project with this extension on code.quarkus.io, window="_blank"]

Or add the coordinates to your existing project:

[source,xml]
----
<dependency>
Expand All @@ -34,3 +38,16 @@ Please refer to the above links for usage and configuration details.
----

Check the xref:user-guide/index.adoc[User guide] for more information about writing Camel Quarkus applications.

== Additional Camel Quarkus configuration

Please refer to https://quarkiverse.github.io/quarkiverse-docs/quarkus-mybatis/dev/index.html[Quarkus MyBatis] for configuration. It must enable the following options

[source, properties]
----
quarkus.mybatis.xmlconfig.enable=true
quarkus.mybatis.xmlconfig.path=SqlMapConfig.xml
----
TIP: `quarkus.mybatis.xmlconfig.path` must be the same with `configurationUri` param in the mybatis endpoint.


This file was deleted.

1 change: 0 additions & 1 deletion extensions-jvm/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,6 @@
<module>management</module>
<module>milo</module>
<module>mvel</module>
<module>mybatis</module>
<module>ognl</module>
<module>printer</module>
<module>pulsar</module>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@
<groupId>org.apache.camel.quarkus</groupId>
<artifactId>camel-quarkus-core-deployment</artifactId>
</dependency>
<dependency>
<groupId>io.quarkiverse.mybatis</groupId>
<artifactId>quarkus-mybatis-deployment</artifactId>
</dependency>
<dependency>
<groupId>org.apache.camel.quarkus</groupId>
<artifactId>camel-quarkus-mybatis</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You 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
*
* http://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 org.apache.camel.quarkus.component.mybatis.deployment;

import java.util.List;
import java.util.function.Supplier;

import io.quarkiverse.mybatis.deployment.SqlSessionFactoryBuildItem;
import io.quarkus.deployment.annotations.BuildStep;
import io.quarkus.deployment.annotations.ExecutionTime;
import io.quarkus.deployment.annotations.Record;
import io.quarkus.deployment.builditem.FeatureBuildItem;
import io.quarkus.runtime.configuration.ConfigurationException;
import org.apache.camel.component.mybatis.MyBatisBeanComponent;
import org.apache.camel.component.mybatis.MyBatisComponent;
import org.apache.camel.quarkus.component.mybatis.runtime.CamelMyBatisRecorder;
import org.apache.camel.quarkus.core.deployment.spi.CamelBeanBuildItem;
import org.jboss.logging.Logger;

class MybatisProcessor {

private static final Logger LOG = Logger.getLogger(MybatisProcessor.class);
private static final String FEATURE = "camel-mybatis";

@BuildStep
FeatureBuildItem feature() {
return new FeatureBuildItem(FEATURE);
}

@Record(ExecutionTime.STATIC_INIT)
@BuildStep
CamelBeanBuildItem mybatisComponent(
List<SqlSessionFactoryBuildItem> sqlSessionFactoryBuildItems, CamelMyBatisRecorder recorder) throws Throwable {
return new CamelBeanBuildItem("mybatis", MyBatisComponent.class.getName(),
recorder.createMyBatisComponent(
findXmlSqlSessionFactory(sqlSessionFactoryBuildItems).getSqlSessionFactory()));
}

@Record(ExecutionTime.STATIC_INIT)
@BuildStep
CamelBeanBuildItem mybatisBeanComponent(
List<SqlSessionFactoryBuildItem> sqlSessionFactoryBuildItems, CamelMyBatisRecorder recorder) throws Throwable {
return new CamelBeanBuildItem("mybatis-bean", MyBatisBeanComponent.class.getName(),
recorder.createMyBatisBeanComponent(
findXmlSqlSessionFactory(sqlSessionFactoryBuildItems).getSqlSessionFactory()));
}

private SqlSessionFactoryBuildItem findXmlSqlSessionFactory(
List<SqlSessionFactoryBuildItem> sqlSessionFactoryBuildItems) throws Throwable {
return sqlSessionFactoryBuildItems.stream().filter(s -> s.isFromXmlConfig()).findFirst()
.orElseThrow((Supplier<Throwable>) () -> new ConfigurationException("No MyBatis XML Config"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.apache.camel.quarkus</groupId>
<artifactId>camel-quarkus-extensions-jvm</artifactId>
<artifactId>camel-quarkus-extensions</artifactId>
<version>2.8.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@

<properties>
<camel.quarkus.jvmSince>1.1.0</camel.quarkus.jvmSince>
<camel.quarkus.nativeSince>2.8.0</camel.quarkus.nativeSince>
</properties>

<dependencyManagement>
Expand All @@ -55,6 +56,10 @@
<groupId>org.apache.camel</groupId>
<artifactId>camel-mybatis</artifactId>
</dependency>
<dependency>
<groupId>io.quarkiverse.mybatis</groupId>
<artifactId>quarkus-mybatis</artifactId>
</dependency>
</dependencies>

<build>
Expand Down
9 changes: 9 additions & 0 deletions extensions/mybatis/runtime/src/main/doc/configuration.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
Please refer to https://quarkiverse.github.io/quarkiverse-docs/quarkus-mybatis/dev/index.html[Quarkus MyBatis] for configuration. It must enable the following options

[source, properties]
----
quarkus.mybatis.xmlconfig.enable=true
quarkus.mybatis.xmlconfig.path=SqlMapConfig.xml
----
TIP: `quarkus.mybatis.xmlconfig.path` must be the same with `configurationUri` param in the mybatis endpoint.

Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You 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
*
* http://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 org.apache.camel.quarkus.component.mybatis.runtime;

import io.quarkus.runtime.RuntimeValue;
import io.quarkus.runtime.annotations.Recorder;
import org.apache.camel.component.mybatis.MyBatisBeanComponent;
import org.apache.camel.component.mybatis.MyBatisComponent;
import org.apache.ibatis.session.SqlSessionFactory;

@Recorder
public class CamelMyBatisRecorder {

public RuntimeValue<MyBatisComponent> createMyBatisComponent(RuntimeValue<SqlSessionFactory> sqlSessionFactory) {
MyBatisComponent component = new MyBatisComponent();
component.setSqlSessionFactory(sqlSessionFactory.getValue());

return new RuntimeValue<>(component);
}

public RuntimeValue<MyBatisBeanComponent> createMyBatisBeanComponent(RuntimeValue<SqlSessionFactory> sqlSessionFactory) {
MyBatisBeanComponent component = new MyBatisBeanComponent();
component.setSqlSessionFactory(sqlSessionFactory.getValue());

return new RuntimeValue<>(component);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,8 @@
name: "Camel MyBatis"
description: "Performs a query, poll, insert, update or delete in a relational database using MyBatis"
metadata:
unlisted: true
guide: "https://camel.apache.org/camel-quarkus/latest/reference/extensions/mybatis.html"
categories:
- "integration"
status:
- "preview"
- "stable"
1 change: 1 addition & 0 deletions extensions/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@
<module>mongodb-gridfs</module>
<module>msv</module>
<module>mustache</module>
<module>mybatis</module>
<module>nagios</module>
<module>nats</module>
<module>netty</module>
Expand Down
83 changes: 0 additions & 83 deletions integration-tests-jvm/mybatis/pom.xml

This file was deleted.

Loading

0 comments on commit 5c9c973

Please sign in to comment.