Skip to content

Commit b5bede9

Browse files
authored
add mybits to table ecosystem (#817)
1 parent f1a77de commit b5bede9

4 files changed

Lines changed: 572 additions & 0 deletions

File tree

Lines changed: 149 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,149 @@
1+
<!--
2+
Licensed to the Apache Software Foundation (ASF) under one
3+
or more contributor license agreements. See the NOTICE file
4+
distributed with this work for additional information
5+
regarding copyright ownership. The ASF licenses this file
6+
to you under the Apache License, Version 2.0 (the
7+
"License"); you may not use this file except in compliance
8+
with the License. You may obtain a copy of the License at
9+
10+
http://www.apache.org/licenses/LICENSE-2.0
11+
12+
Unless required by applicable law or agreed to in writing,
13+
software distributed under the License is distributed on an
14+
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
KIND, either express or implied. See the License for the
16+
specific language governing permissions and limitations
17+
under the License.
18+
-->
19+
20+
# Mybatis Generator
21+
22+
23+
## 1. Overview
24+
25+
MyBatis Generator is an automated code generation tool officially released by MyBatis for the persistence layer. By parsing database table structures, it automatically generates entity classes (POJOs), Mapper interfaces, and XML mapping files. This enables rapid construction of standardized CRUD operation logic and significantly reduces the development cost of foundational code.
26+
27+
To simplify integration in time-series database scenarios, the IoTDB team has extended this tool to launch ​**​IoTDB MyBatis Generator​**​. Deeply adapted for IoTDB's time-series data model characteristics, it automatically generates entity classes, Mapper interfaces, and corresponding Mapper XML files that conform to time-series storage semantics. This provides a standardized and reusable engineering practice solution for efficient IoTDB integration.
28+
29+
## 2. Usage Steps
30+
31+
### 2.1 Version Requirements
32+
33+
* `IoTDB`: >=2.0.2
34+
35+
* `mybatis-generator-plugin`: >=2.0.3
36+
37+
* `iotdb-jdbc`: >=2.0.3
38+
39+
### 2.2 Operating Procedure
40+
41+
1. ​Install and start IoTDB, Refer to [IoTDB Quick Start](../QuickStart/QuickStart.md)
42+
43+
2. Obtain the plugin​
44+
45+
* ​​Method 1​*: Directly reference the Maven dependency
46+
47+
* ​​Method 2​​: Clone the plugin source code and install locally:
48+
49+
```Bash
50+
git clone https://github.com/apache/iotdb-extras.git
51+
cd .\mybatis-generator\
52+
mvn clean install
53+
```
54+
55+
3. Add dependency
56+
57+
Add the following configuration to your project's `pom.xml`:
58+
59+
```xml
60+
<properties>
61+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
62+
</properties>
63+
64+
<build>
65+
<plugins>
66+
<plugin>
67+
<groupId>org.mybatis.generator</groupId>
68+
<artifactId>mybatis-generator-maven-plugin</artifactId>
69+
<version>1.4.2</version>
70+
<dependencies>
71+
<dependency>
72+
<groupId>org.apache.iotdb</groupId>
73+
<artifactId>mybatis-generator-plugin</artifactId>
74+
<version>{lastest_version}</version>
75+
<!--Example: <version>2.0.3</version> -->
76+
</dependency>
77+
</dependencies>
78+
<configuration>
79+
<verbose>true</verbose>
80+
<overwrite>true</overwrite>
81+
<configurationFile>src/main/resources/generatorConfig.xml</configurationFile>
82+
</configuration>
83+
</plugin>
84+
</plugins>
85+
</build>
86+
```
87+
88+
4. Configure generatorConfig.xml
89+
90+
* Place the following configuration in `src/main/resources/generatorConfig.xml`:
91+
92+
* Key customizable elements: `jdbcConnection`, `javaModelGenerator`, `sqlMapGenerator`, `javaClientGenerator`, `table`
93+
94+
```xml
95+
<?xml version="1.0" encoding="UTF-8"?>
96+
<!DOCTYPE generatorConfiguration PUBLIC "-//mybatis.org//DTD MyBatis Generator Configuration 1.0//EN" "http://mybatis.org/dtd/mybatis-generator-config_1_0.dtd">
97+
<generatorConfiguration>
98+
<classPathEntry location="/apache/iotdb/iotdb-client/jdbc/target/iotdb-jdbc-2.0.4-SNAPSHOT-jar-with-dependencies.jar"/>
99+
<!-- mvn mybatis-generator:generate hierarchical/flat-->
100+
<context id="myBatis3Simple" targetRuntime="MyBatis3Simple" defaultModelType="flat">
101+
<plugin type="org.apache.iotdb.mybatis.plugin.LombokPlugin"/>
102+
<plugin type="org.apache.iotdb.mybatis.plugin.BatchInsertPlugin"/>
103+
<plugin type="org.apache.iotdb.mybatis.plugin.SerializablePlugin"/>
104+
<plugin type="org.mybatis.generator.plugins.VirtualPrimaryKeyPlugin"/>
105+
<commentGenerator type="org.apache.iotdb.mybatis.plugin.generator.SwaggerCommentGenerator">
106+
<property name="suppressAllComments" value="true"/>
107+
<property name="suppressDate" value="true"/>
108+
<property name="addRemarkComments" value="true"/>
109+
</commentGenerator>
110+
<jdbcConnection driverClass="org.apache.iotdb.jdbc.IoTDBDriver" connectionURL="jdbc:iotdb://127.0.0.1:6667/database1?sql_dialect=table" userId="root" password="root"/>
111+
<javaTypeResolver type="org.apache.iotdb.mybatis.plugin.generator.resolver.IoTDBJavaTypeResolver">
112+
<property name="forceBigDecimals" value="false"/>
113+
</javaTypeResolver>
114+
<javaModelGenerator targetPackage="org.apache.iotdb.mybatis.plugin.model" targetProject="src/main/java">
115+
<property name="trimStrings" value="true"/>
116+
</javaModelGenerator>
117+
<sqlMapGenerator targetPackage="org.apache.iotdb.mybatis.plugin.xml" targetProject="src/main/java">
118+
</sqlMapGenerator>
119+
<javaClientGenerator type="XMLMAPPER" targetPackage="org.apache.iotdb.mybatis.plugin.mapper" targetProject="src/main/java">
120+
</javaClientGenerator>
121+
<table schema="database1" tableName="table1" domainObjectName="table1" enableSelectByPrimaryKey="true" enableInsert="true" enableDeleteByPrimaryKey="true">
122+
<property name="virtualKeyColumns" value="time,region,plant_id,device_id,model_id,maintenance,temperature,humidity,status,arrival_time"/>
123+
</table>
124+
</context>
125+
</generatorConfiguration>
126+
```
127+
128+
5. Execute code generation
129+
130+
Run in terminal:
131+
132+
```Shell
133+
mvn mybatis-generator:generate
134+
```
135+
136+
6. View generated code​
137+
138+
Find the generated files in your project:
139+
140+
```Shell
141+
# You can see the target file in your Project
142+
org/apache/iotdb/mybatis/plugin/model/table1.java
143+
org/apache/iotdb/mybatis/plugin/mapper/table1Mapper.java
144+
org/apache/iotdb/mybatis/plugin/xml/table1Mapper.xml
145+
```
146+
147+
## 3. Usage Example
148+
149+
For detailed usage examples, refer to the source code: [examples/mybatis-generator](https://github.com/apache/iotdb-extras/tree/master/examples/mybatis-generator)
Lines changed: 149 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,149 @@
1+
<!--
2+
Licensed to the Apache Software Foundation (ASF) under one
3+
or more contributor license agreements. See the NOTICE file
4+
distributed with this work for additional information
5+
regarding copyright ownership. The ASF licenses this file
6+
to you under the Apache License, Version 2.0 (the
7+
"License"); you may not use this file except in compliance
8+
with the License. You may obtain a copy of the License at
9+
10+
http://www.apache.org/licenses/LICENSE-2.0
11+
12+
Unless required by applicable law or agreed to in writing,
13+
software distributed under the License is distributed on an
14+
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
KIND, either express or implied. See the License for the
16+
specific language governing permissions and limitations
17+
under the License.
18+
-->
19+
20+
# Mybatis Generator
21+
22+
23+
## 1. Overview
24+
25+
MyBatis Generator is an automated code generation tool officially released by MyBatis for the persistence layer. By parsing database table structures, it automatically generates entity classes (POJOs), Mapper interfaces, and XML mapping files. This enables rapid construction of standardized CRUD operation logic and significantly reduces the development cost of foundational code.
26+
27+
To simplify integration in time-series database scenarios, the IoTDB team has extended this tool to launch ​**​IoTDB MyBatis Generator​**​. Deeply adapted for IoTDB's time-series data model characteristics, it automatically generates entity classes, Mapper interfaces, and corresponding Mapper XML files that conform to time-series storage semantics. This provides a standardized and reusable engineering practice solution for efficient IoTDB integration.
28+
29+
## 2. Usage Steps
30+
31+
### 2.1 Version Requirements
32+
33+
* `IoTDB`: >=2.0.2
34+
35+
* `mybatis-generator-plugin`: >=2.0.3
36+
37+
* `iotdb-jdbc`: >=2.0.3
38+
39+
### 2.2 Operating Procedure
40+
41+
1. ​Install and start IoTDB, Refer to [IoTDB Quick Start](../QuickStart/QuickStart.md)
42+
43+
2. Obtain the plugin​
44+
45+
* ​​Method 1​*: Directly reference the Maven dependency
46+
47+
* ​​Method 2​​: Clone the plugin source code and install locally:
48+
49+
```Bash
50+
git clone https://github.com/apache/iotdb-extras.git
51+
cd .\mybatis-generator\
52+
mvn clean install
53+
```
54+
55+
3. Add dependency
56+
57+
Add the following configuration to your project's `pom.xml`:
58+
59+
```xml
60+
<properties>
61+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
62+
</properties>
63+
64+
<build>
65+
<plugins>
66+
<plugin>
67+
<groupId>org.mybatis.generator</groupId>
68+
<artifactId>mybatis-generator-maven-plugin</artifactId>
69+
<version>1.4.2</version>
70+
<dependencies>
71+
<dependency>
72+
<groupId>org.apache.iotdb</groupId>
73+
<artifactId>mybatis-generator-plugin</artifactId>
74+
<version>{lastest_version}</version>
75+
<!--Example: <version>2.0.3</version> -->
76+
</dependency>
77+
</dependencies>
78+
<configuration>
79+
<verbose>true</verbose>
80+
<overwrite>true</overwrite>
81+
<configurationFile>src/main/resources/generatorConfig.xml</configurationFile>
82+
</configuration>
83+
</plugin>
84+
</plugins>
85+
</build>
86+
```
87+
88+
4. Configure generatorConfig.xml
89+
90+
* Place the following configuration in `src/main/resources/generatorConfig.xml`:
91+
92+
* Key customizable elements: `jdbcConnection`, `javaModelGenerator`, `sqlMapGenerator`, `javaClientGenerator`, `table`
93+
94+
```xml
95+
<?xml version="1.0" encoding="UTF-8"?>
96+
<!DOCTYPE generatorConfiguration PUBLIC "-//mybatis.org//DTD MyBatis Generator Configuration 1.0//EN" "http://mybatis.org/dtd/mybatis-generator-config_1_0.dtd">
97+
<generatorConfiguration>
98+
<classPathEntry location="/apache/iotdb/iotdb-client/jdbc/target/iotdb-jdbc-2.0.4-SNAPSHOT-jar-with-dependencies.jar"/>
99+
<!-- mvn mybatis-generator:generate hierarchical/flat-->
100+
<context id="myBatis3Simple" targetRuntime="MyBatis3Simple" defaultModelType="flat">
101+
<plugin type="org.apache.iotdb.mybatis.plugin.LombokPlugin"/>
102+
<plugin type="org.apache.iotdb.mybatis.plugin.BatchInsertPlugin"/>
103+
<plugin type="org.apache.iotdb.mybatis.plugin.SerializablePlugin"/>
104+
<plugin type="org.mybatis.generator.plugins.VirtualPrimaryKeyPlugin"/>
105+
<commentGenerator type="org.apache.iotdb.mybatis.plugin.generator.SwaggerCommentGenerator">
106+
<property name="suppressAllComments" value="true"/>
107+
<property name="suppressDate" value="true"/>
108+
<property name="addRemarkComments" value="true"/>
109+
</commentGenerator>
110+
<jdbcConnection driverClass="org.apache.iotdb.jdbc.IoTDBDriver" connectionURL="jdbc:iotdb://127.0.0.1:6667/database1?sql_dialect=table" userId="root" password="root"/>
111+
<javaTypeResolver type="org.apache.iotdb.mybatis.plugin.generator.resolver.IoTDBJavaTypeResolver">
112+
<property name="forceBigDecimals" value="false"/>
113+
</javaTypeResolver>
114+
<javaModelGenerator targetPackage="org.apache.iotdb.mybatis.plugin.model" targetProject="src/main/java">
115+
<property name="trimStrings" value="true"/>
116+
</javaModelGenerator>
117+
<sqlMapGenerator targetPackage="org.apache.iotdb.mybatis.plugin.xml" targetProject="src/main/java">
118+
</sqlMapGenerator>
119+
<javaClientGenerator type="XMLMAPPER" targetPackage="org.apache.iotdb.mybatis.plugin.mapper" targetProject="src/main/java">
120+
</javaClientGenerator>
121+
<table schema="database1" tableName="table1" domainObjectName="table1" enableSelectByPrimaryKey="true" enableInsert="true" enableDeleteByPrimaryKey="true">
122+
<property name="virtualKeyColumns" value="time,region,plant_id,device_id,model_id,maintenance,temperature,humidity,status,arrival_time"/>
123+
</table>
124+
</context>
125+
</generatorConfiguration>
126+
```
127+
128+
5. Execute code generation
129+
130+
Run in terminal:
131+
132+
```Shell
133+
mvn mybatis-generator:generate
134+
```
135+
136+
6. View generated code​
137+
138+
Find the generated files in your project:
139+
140+
```Shell
141+
# You can see the target file in your Project
142+
org/apache/iotdb/mybatis/plugin/model/table1.java
143+
org/apache/iotdb/mybatis/plugin/mapper/table1Mapper.java
144+
org/apache/iotdb/mybatis/plugin/xml/table1Mapper.xml
145+
```
146+
147+
## 3. Usage Example
148+
149+
For detailed usage examples, refer to the source code: [examples/mybatis-generator](https://github.com/apache/iotdb-extras/tree/master/examples/mybatis-generator)

0 commit comments

Comments
 (0)