camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject [camel] 04/04: CAMEL-12285: Added mybatis-bean as component to use MyBatis annotation mapper.
Date Wed, 28 Mar 2018 18:45:43 GMT
This is an automated email from the ASF dual-hosted git repository.

davsclaus pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel.git

commit 5b717d774cfd6ab492b2f5313654938b00da5ef9
Author: Claus Ibsen <claus.ibsen@gmail.com>
AuthorDate: Wed Mar 28 20:44:01 2018 +0200

    CAMEL-12285: Added mybatis-bean as component to use MyBatis annotation mapper.
---
 .../src/main/docs/mybatis-bean-component.adoc      | 151 +++++++++++++++++++++
 .../component/mybatis/BaseMyBatisEndpoint.java     |   6 +-
 .../mybatis/bean/MyBatisBeanInsertTest.java        |   6 +-
 .../mybatis/bean/MyBatisBeanSelectListTest.java    |   6 +-
 .../mybatis/bean/MyBatisBeanSelectOneTest.java     |   6 +-
 .../MyBatisBeanSelectOneWithInputHeaderTest.java   |   6 +-
 .../MyBatisBeanSelectOneWithOutputHeaderTest.java  |   6 +-
 components/readme.adoc                             |   5 +-
 docs/user-manual/en/SUMMARY.md                     |   1 +
 9 files changed, 174 insertions(+), 19 deletions(-)

diff --git a/components/camel-mybatis/src/main/docs/mybatis-bean-component.adoc b/components/camel-mybatis/src/main/docs/mybatis-bean-component.adoc
new file mode 100644
index 0000000..4902d4a
--- /dev/null
+++ b/components/camel-mybatis/src/main/docs/mybatis-bean-component.adoc
@@ -0,0 +1,151 @@
+[[mybatis-bean-component]]
+== MyBatis Bean Component
+
+*Available as of Camel version 2.22*
+
+The *mybatis-bean:* component allows you to query, insert, update and
+delete data in a relational database using http://mybatis.org/[MyBatis] bean annotations.
+
+This component can **only** be used as a producer. If you want to consume
+from MyBatis then use the regular **mybatis** component.
+
+Maven users will need to add the following dependency to their `pom.xml`
+for this component:
+
+[source,xml]
+----
+<dependency>
+    <groupId>org.apache.camel</groupId>
+    <artifactId>camel-mybatis</artifactId>
+    <version>x.x.x</version>
+    <!-- use the same version as your Camel core version -->
+</dependency>
+----
+
+This component will by default load the MyBatis SqlMapConfig file from
+the root of the classpath with the expected name of
+`SqlMapConfig.xml`. +
+ If the file is located in another location, you will need to configure
+the `configurationUri` option on the `MyBatisComponent` component.
+
+=== Options
+
+// component options: START
+The MyBatis Bean component supports 3 options which are listed below.
+
+
+
+[width="100%",cols="2,5,^1,2",options="header"]
+|===
+| Name | Description | Default | Type
+| *sqlSessionFactory* (advanced) | To use the SqlSessionFactory |  | SqlSessionFactory
+| *configurationUri* (producer) | Location of MyBatis xml configuration file. The default
value is: SqlMapConfig.xml loaded from the classpath | SqlMapConfig.xml | String
+| *resolveProperty Placeholders* (advanced) | Whether the component should resolve property
placeholders on itself when starting. Only properties which are of String type can use property
placeholders. | true | boolean
+|===
+// component options: END
+
+
+// endpoint options: START
+The MyBatis Bean endpoint is configured using URI syntax:
+
+----
+mybatis-bean:beanName:methodName
+----
+
+with the following path and query parameters:
+
+==== Path Parameters (2 parameters):
+
+
+[width="100%",cols="2,5,^1,2",options="header"]
+|===
+| Name | Description | Default | Type
+| *beanName* | *Required* Name of the bean with the MyBatis annotations. This can either
by a type alias or a FQN class name. |  | String
+| *methodName* | *Required* Name of the method on the bean that has the SQL query to be executed.
|  | String
+|===
+
+
+==== Query Parameters (4 parameters):
+
+
+[width="100%",cols="2,5,^1,2",options="header"]
+|===
+| Name | Description | Default | Type
+| *executorType* (producer) | The executor type to be used while executing statements. simple
- executor does nothing special. reuse - executor reuses prepared statements. batch - executor
reuses statements and batches updates. | SIMPLE | ExecutorType
+| *inputHeader* (producer) | User the header value for input parameters instead of the message
body. By default, inputHeader == null and the input parameters are taken from the message
body. If outputHeader is set, the value is used and query parameters will be taken from the
header instead of the body. |  | String
+| *outputHeader* (producer) | Store the query result in a header instead of the message body.
By default, outputHeader == null and the query result is stored in the message body, any existing
content in the message body is discarded. If outputHeader is set, the value is used as the
name of the header to store the query result and the original message body is preserved. Setting
outputHeader will also omit populating the default CamelMyBatisResult header since it would
be the same as outpu [...]
+| *synchronous* (advanced) | Sets whether synchronous processing should be strictly used,
or Camel is allowed to use asynchronous processing (if supported). | false | boolean
+|===
+// endpoint options: END
+
+
+
+=== Message Headers
+
+Camel will populate the result message, either IN or OUT with a header
+with the statement used:
+
+[width="100%",cols="10%,10%,80%",options="header",]
+|===
+|Header |Type |Description
+
+|`CamelMyBatisResult` |`Object` |The *response* returned from MtBatis in any of the operations.
For
+instance an `INSERT` could return the auto-generated key, or number of
+rows etc.
+|===
+
+=== Message Body
+
+The response from MyBatis will only be set as the body if it's a
+`SELECT` statement. That means, for example, for `INSERT` statements
+Camel will not replace the body. This allows you to continue routing and
+keep the original body. The response from MyBatis is always stored in
+the header with the key `CamelMyBatisResult`.
+
+=== Samples
+
+For example if you wish to consume beans from a JMS queue and insert
+them into a database you could do the following:
+
+[source,java]
+----
+from("activemq:queue:newAccount")
+  .to("mybatis-bean:AccountService:insertBeanAccount");
+----
+
+Notice we have to specify the bean name and method name, as we need to instruct
+Camel which kind of operation to invoke.
+
+Where `AccountService` is the type alias for the bean that has the MyBatis
+bean annotations. You can configure type alias in the SqlMapConfig file:
+
+[source,xml]
+----
+    <typeAliases>
+        <typeAlias alias="Account" type="org.apache.camel.component.mybatis.Account"/>
+        <typeAlias alias="AccountService" type="org.apache.camel.component.mybatis.bean.AccountService"/>
+    </typeAliases>
+----
+[source]
+
+On the `AccountService` bean you can declare the MyBatis mappins using annotations as shown:
+
+[source,java]
+----
+public interface AccountService {
+
+    @Select("select ACC_ID as id, ACC_FIRST_NAME as firstName, ACC_LAST_NAME as lastName"
+        + ", ACC_EMAIL as emailAddress from ACCOUNT where ACC_ID = #{id}")
+    Account selectBeanAccountById(@Param("id") int no);
+
+    @Select("select * from ACCOUNT order by ACC_ID")
+    @ResultMap("Account.AccountResult")
+    List<Account> selectBeanAllAccounts();
+
+    @Insert("insert into ACCOUNT (ACC_ID,ACC_FIRST_NAME,ACC_LAST_NAME,ACC_EMAIL)"
+        + " values (#{id}, #{firstName}, #{lastName}, #{emailAddress})")
+    void insertBeanAccount(Account account);
+
+}
+----
+
diff --git a/components/camel-mybatis/src/main/java/org/apache/camel/component/mybatis/BaseMyBatisEndpoint.java
b/components/camel-mybatis/src/main/java/org/apache/camel/component/mybatis/BaseMyBatisEndpoint.java
index 25abb5f..cefb13c 100644
--- a/components/camel-mybatis/src/main/java/org/apache/camel/component/mybatis/BaseMyBatisEndpoint.java
+++ b/components/camel-mybatis/src/main/java/org/apache/camel/component/mybatis/BaseMyBatisEndpoint.java
@@ -5,9 +5,9 @@
  * 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
- * <p>
- * http://www.apache.org/licenses/LICENSE-2.0
- * <p>
+ *
+ *      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.
diff --git a/components/camel-mybatis/src/test/java/org/apache/camel/component/mybatis/bean/MyBatisBeanInsertTest.java
b/components/camel-mybatis/src/test/java/org/apache/camel/component/mybatis/bean/MyBatisBeanInsertTest.java
index 7950024..56de8d4 100644
--- a/components/camel-mybatis/src/test/java/org/apache/camel/component/mybatis/bean/MyBatisBeanInsertTest.java
+++ b/components/camel-mybatis/src/test/java/org/apache/camel/component/mybatis/bean/MyBatisBeanInsertTest.java
@@ -5,9 +5,9 @@
  * 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
- * <p>
- * http://www.apache.org/licenses/LICENSE-2.0
- * <p>
+ *
+ *      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.
diff --git a/components/camel-mybatis/src/test/java/org/apache/camel/component/mybatis/bean/MyBatisBeanSelectListTest.java
b/components/camel-mybatis/src/test/java/org/apache/camel/component/mybatis/bean/MyBatisBeanSelectListTest.java
index 72cbe1a..9e26b5f 100644
--- a/components/camel-mybatis/src/test/java/org/apache/camel/component/mybatis/bean/MyBatisBeanSelectListTest.java
+++ b/components/camel-mybatis/src/test/java/org/apache/camel/component/mybatis/bean/MyBatisBeanSelectListTest.java
@@ -5,9 +5,9 @@
  * 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
- * <p>
- * http://www.apache.org/licenses/LICENSE-2.0
- * <p>
+ *
+ *      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.
diff --git a/components/camel-mybatis/src/test/java/org/apache/camel/component/mybatis/bean/MyBatisBeanSelectOneTest.java
b/components/camel-mybatis/src/test/java/org/apache/camel/component/mybatis/bean/MyBatisBeanSelectOneTest.java
index 4297eae..b55e36c 100644
--- a/components/camel-mybatis/src/test/java/org/apache/camel/component/mybatis/bean/MyBatisBeanSelectOneTest.java
+++ b/components/camel-mybatis/src/test/java/org/apache/camel/component/mybatis/bean/MyBatisBeanSelectOneTest.java
@@ -5,9 +5,9 @@
  * 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
- * <p>
- * http://www.apache.org/licenses/LICENSE-2.0
- * <p>
+ *
+ *      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.
diff --git a/components/camel-mybatis/src/test/java/org/apache/camel/component/mybatis/bean/MyBatisBeanSelectOneWithInputHeaderTest.java
b/components/camel-mybatis/src/test/java/org/apache/camel/component/mybatis/bean/MyBatisBeanSelectOneWithInputHeaderTest.java
index dcae3a8..0d7c31e 100644
--- a/components/camel-mybatis/src/test/java/org/apache/camel/component/mybatis/bean/MyBatisBeanSelectOneWithInputHeaderTest.java
+++ b/components/camel-mybatis/src/test/java/org/apache/camel/component/mybatis/bean/MyBatisBeanSelectOneWithInputHeaderTest.java
@@ -5,9 +5,9 @@
  * 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
- * <p>
- * http://www.apache.org/licenses/LICENSE-2.0
- * <p>
+ *
+ *      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.
diff --git a/components/camel-mybatis/src/test/java/org/apache/camel/component/mybatis/bean/MyBatisBeanSelectOneWithOutputHeaderTest.java
b/components/camel-mybatis/src/test/java/org/apache/camel/component/mybatis/bean/MyBatisBeanSelectOneWithOutputHeaderTest.java
index b97bde9..dab7422 100644
--- a/components/camel-mybatis/src/test/java/org/apache/camel/component/mybatis/bean/MyBatisBeanSelectOneWithOutputHeaderTest.java
+++ b/components/camel-mybatis/src/test/java/org/apache/camel/component/mybatis/bean/MyBatisBeanSelectOneWithOutputHeaderTest.java
@@ -5,9 +5,9 @@
  * 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
- * <p>
- * http://www.apache.org/licenses/LICENSE-2.0
- * <p>
+ *
+ *      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.
diff --git a/components/readme.adoc b/components/readme.adoc
index 5595cf1..0825da4 100644
--- a/components/readme.adoc
+++ b/components/readme.adoc
@@ -2,7 +2,7 @@ Components
 ^^^^^^^^^^
 
 // components: START
-Number of Components: 291 in 199 JAR artifacts (20 deprecated)
+Number of Components: 292 in 199 JAR artifacts (20 deprecated)
 
 [width="100%",cols="4,1,5",options="header"]
 |===
@@ -569,6 +569,9 @@ Number of Components: 291 in 199 JAR artifacts (20 deprecated)
 | link:camel-mybatis/src/main/docs/mybatis-component.adoc[MyBatis] (camel-mybatis) +
 `mybatis:statement` | 2.7 | Performs a query, poll, insert, update or delete in a relational
database using MyBatis.
 
+| link:camel-mybatis/src/main/docs/mybatis-bean-component.adoc[MyBatis Bean] (camel-mybatis)
+
+`mybatis-bean:beanName:methodName` | 2.22 | Performs a query, insert, update or delete in
a relational database using MyBatis.
+
 | link:camel-nagios/src/main/docs/nagios-component.adoc[Nagios] (camel-nagios) +
 `nagios:host:port` | 2.3 | To send passive checks to Nagios using JSendNSCA.
 
diff --git a/docs/user-manual/en/SUMMARY.md b/docs/user-manual/en/SUMMARY.md
index e23396a..e4897b8 100644
--- a/docs/user-manual/en/SUMMARY.md
+++ b/docs/user-manual/en/SUMMARY.md
@@ -299,6 +299,7 @@
 	* [Mustache](mustache-component.adoc)
 	* [MVEL](mvel-component.adoc)
 	* [MyBatis](mybatis-component.adoc)
+	* [MyBatis Bean](mybatis-bean-component.adoc)
 	* [Nagios](nagios-component.adoc)
 	* [Nats](nats-component.adoc)
 	* [Netty](netty-component.adoc)

-- 
To stop receiving notification emails like this one, please contact
davsclaus@apache.org.

Mime
View raw message