From feabdcf194f01b6aa82c3490108146a6843062f1 Mon Sep 17 00:00:00 2001 From: 2b3c511 Date: Mon, 24 Feb 2025 12:03:39 +0800 Subject: [PATCH 01/14] Add mybatis-generator-plugin module --- mybatis-generator/.gitignore | 7 + mybatis-generator/README-zh.md | 35 +++++ mybatis-generator/README.md | 35 +++++ mybatis-generator/pom.xml | 82 ++++++++++ .../mybatis/plugin/BatchInsertPlugin.java | 120 +++++++++++++++ .../iotdb/mybatis/plugin/LombokPlugin.java | 54 +++++++ .../mybatis/plugin/SerializablePlugin.java | 137 +++++++++++++++++ .../plugin/generator/CNCommentGenerator.java | 125 ++++++++++++++++ .../generator/SwaggerCommentGenerator.java | 141 ++++++++++++++++++ .../resolver/IoTDBJavaTypeResolver.java | 96 ++++++++++++ .../resolver/JavaTypeResolverSelfImpl.java | 59 ++++++++ .../iotdb/mybatis/plugin/util/DateUtil.java | 29 ++++ .../src/main/resources/generatorConfig.xml | 58 +++++++ 13 files changed, 978 insertions(+) create mode 100644 mybatis-generator/.gitignore create mode 100644 mybatis-generator/README-zh.md create mode 100644 mybatis-generator/README.md create mode 100644 mybatis-generator/pom.xml create mode 100644 mybatis-generator/src/main/java/org/apache/iotdb/mybatis/plugin/BatchInsertPlugin.java create mode 100644 mybatis-generator/src/main/java/org/apache/iotdb/mybatis/plugin/LombokPlugin.java create mode 100644 mybatis-generator/src/main/java/org/apache/iotdb/mybatis/plugin/SerializablePlugin.java create mode 100644 mybatis-generator/src/main/java/org/apache/iotdb/mybatis/plugin/generator/CNCommentGenerator.java create mode 100644 mybatis-generator/src/main/java/org/apache/iotdb/mybatis/plugin/generator/SwaggerCommentGenerator.java create mode 100644 mybatis-generator/src/main/java/org/apache/iotdb/mybatis/plugin/generator/resolver/IoTDBJavaTypeResolver.java create mode 100644 mybatis-generator/src/main/java/org/apache/iotdb/mybatis/plugin/generator/resolver/JavaTypeResolverSelfImpl.java create mode 100644 mybatis-generator/src/main/java/org/apache/iotdb/mybatis/plugin/util/DateUtil.java create mode 100644 mybatis-generator/src/main/resources/generatorConfig.xml diff --git a/mybatis-generator/.gitignore b/mybatis-generator/.gitignore new file mode 100644 index 0000000..90c8f11 --- /dev/null +++ b/mybatis-generator/.gitignore @@ -0,0 +1,7 @@ +target/ +.settings/ +.classpath +.project +.idea/ +*.iml +.DS_Store diff --git a/mybatis-generator/README-zh.md b/mybatis-generator/README-zh.md new file mode 100644 index 0000000..54cc853 --- /dev/null +++ b/mybatis-generator/README-zh.md @@ -0,0 +1,35 @@ +# mybatis-generator-plugin + +* 把该项目 `clone` 下来之后,在本地执行 `mvn clean install` 或者 `mvn clean deploy` (`deploy` 需要修改 `pom` 中的 `distributionManagement`)【已经上传 `Maven` 中央仓库,所以此步骤不在需要】 + +* 在要生成的项目的 `pom` 文件中添加如下配置: + +```java + + + + org.mybatis.generator + mybatis-generator-maven-plugin + 1.4.2 + + + org.apache.iotdb + iotdb-mybatis-generator + 1.3.2-SNAPSHOT + + + + true + true + src/main/resources/generatorConfig.xml + + + + +``` + +* `configurationFile` 配置 `generatorConfig.xml` 文件的位置,其内容在本项目的 `src/main/resources` 有一个模板供参考,`copy` 其内容放到相应的位置 + +* 修改 `generatorConfig.xml` 中 想用的内容,主要是:`jdbcConnection`、`javaModelGenerator`、`sqlMapGenerator`、`javaClientGenerator`、`table` + +* 在项目的 `pom` 所在的地方执行命令:`mvn mybatis-generator:generate` 生成相应的 `Java` 类和 `mapper` 文件 \ No newline at end of file diff --git a/mybatis-generator/README.md b/mybatis-generator/README.md new file mode 100644 index 0000000..2bfe68e --- /dev/null +++ b/mybatis-generator/README.md @@ -0,0 +1,35 @@ +# mybatis-generator-plugin + +* After 'clone' the project, execute 'mvn clean install' or 'mvn clean deploy' locally ('deploy' needs to modify 'distributionManagement' in 'pom'). This step is not necessary as it has already been uploaded to the Maven central repository + +* Add the following configuration to the 'pom' file of the project to be generated: + +```java + + + + org.mybatis.generator + mybatis-generator-maven-plugin + 1.4.2 + + + org.apache.iotdb + iotdb-mybatis-generator + 1.3.2-SNAPSHOT + + + + true + true + src/main/resources/generatorConfig.xml + + + + +``` + +* The location of the ` configurationFile ` configuration ` generatorConfig. xml ` file can be found in the ` src/main/resources ` template of this project for reference` Copy its content and place it in the corresponding location + +* Modify the content you want to use in 'generatorConfig. xml', mainly by:` jdbcConnection`、`javaModelGenerator`、`sqlMapGenerator`、`javaClientGenerator`、`table` + +* Execute the command at the location of the 'pom' in the project:` Mvn mybatis generator: generate generates corresponding Java classes and mapper files \ No newline at end of file diff --git a/mybatis-generator/pom.xml b/mybatis-generator/pom.xml new file mode 100644 index 0000000..0c86ff6 --- /dev/null +++ b/mybatis-generator/pom.xml @@ -0,0 +1,82 @@ + + + 4.0.0 + + org.apache.iotdb + iotdb-extras-parent + 1.3.2 + + org.apache.iotdb + mybatis-generator-plugin + 1.3.2 + jar + + + The Apache Software License, Version 2.0 + http://www.apache.org/licenses/LICENSE-2.0.txt + repo + + + + + org.mybatis.generator + mybatis-generator-core + 1.4.2 + + + + mybatis-generator-plugin + + + org.apache.maven.plugins + maven-surefire-plugin + 2.17 + + true + + + + maven-source-plugin + + + attach-sources + + jar-no-fork + + + + + + maven-javadoc-plugin + + + attach-javadocs + + jar + + + + + + maven-deploy-plugin + + + deploy + deploy + + deploy + + + + + + org.apache.maven.plugins + maven-compiler-plugin + + 1.8 + 1.8 + + + + + diff --git a/mybatis-generator/src/main/java/org/apache/iotdb/mybatis/plugin/BatchInsertPlugin.java b/mybatis-generator/src/main/java/org/apache/iotdb/mybatis/plugin/BatchInsertPlugin.java new file mode 100644 index 0000000..ed60ed4 --- /dev/null +++ b/mybatis-generator/src/main/java/org/apache/iotdb/mybatis/plugin/BatchInsertPlugin.java @@ -0,0 +1,120 @@ +/* + * 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.iotdb.mybatis.plugin; + +import org.mybatis.generator.api.IntrospectedColumn; +import org.mybatis.generator.api.IntrospectedTable; +import org.mybatis.generator.api.PluginAdapter; +import org.mybatis.generator.api.dom.java.FullyQualifiedJavaType; +import org.mybatis.generator.api.dom.java.Interface; +import org.mybatis.generator.api.dom.java.JavaVisibility; +import org.mybatis.generator.api.dom.java.Method; +import org.mybatis.generator.api.dom.java.Parameter; +import org.mybatis.generator.api.dom.xml.Attribute; +import org.mybatis.generator.api.dom.xml.Document; +import org.mybatis.generator.api.dom.xml.TextElement; +import org.mybatis.generator.api.dom.xml.XmlElement; + +import java.util.List; +import java.util.Set; +import java.util.TreeSet; + +public class BatchInsertPlugin extends PluginAdapter { + + @Override + public boolean clientGenerated(Interface interfaze, + IntrospectedTable introspectedTable) { + batchInsertMethod(interfaze, introspectedTable); + + return super.clientGenerated(interfaze, introspectedTable); + } + + @Override + public boolean sqlMapDocumentGenerated(Document document, IntrospectedTable introspectedTable) { + addBatchInsertXml(document, introspectedTable); + return super.sqlMapDocumentGenerated(document, introspectedTable); + } + + + @Override + public boolean validate(List list) { + return true; + } + + + private void batchInsertMethod(Interface interfaze, IntrospectedTable introspectedTable) { + Set importedTypes = new TreeSet<>(); + importedTypes.add(FullyQualifiedJavaType.getNewListInstance()); + importedTypes.add(new FullyQualifiedJavaType(introspectedTable.getBaseRecordType())); + + Method ibsmethod = new Method("batchInsert"); + ibsmethod.setVisibility(JavaVisibility.PUBLIC); + ibsmethod.setAbstract(true); + + FullyQualifiedJavaType ibsReturnType = FullyQualifiedJavaType.getIntInstance(); + + ibsmethod.setReturnType(ibsReturnType); + + ibsmethod.setName("batchInsert"); + + FullyQualifiedJavaType paramType = FullyQualifiedJavaType.getNewListInstance(); + FullyQualifiedJavaType paramListType; + paramListType = new FullyQualifiedJavaType(introspectedTable.getBaseRecordType()); + paramType.addTypeArgument(paramListType); + ibsmethod.addParameter(new Parameter(paramType, "records", "@Param(\"records\")")); + interfaze.addImportedTypes(importedTypes); + + interfaze.addMethod(ibsmethod); + } + + private void addBatchInsertXml(Document document, IntrospectedTable introspectedTable) { + List columns = introspectedTable.getAllColumns(); + String incrementField = introspectedTable.getTableConfiguration().getProperties().getProperty("incrementField"); + if (incrementField != null) { + incrementField = incrementField.toUpperCase(); + } + + XmlElement insertBatchElement = new XmlElement("insert"); + insertBatchElement.addAttribute(new Attribute("id", "batchInsert")); + insertBatchElement.addAttribute(new Attribute("parameterType", "java.util.List")); + + StringBuilder sqlElement = new StringBuilder(); + StringBuilder javaPropertyAndDbType = new StringBuilder("("); + for (IntrospectedColumn introspectedColumn : columns) { + String columnName = introspectedColumn.getActualColumnName(); + if (!columnName.toUpperCase().equals(incrementField)) { + sqlElement.append(columnName + ",\n "); + javaPropertyAndDbType.append("\n #{item." + introspectedColumn.getJavaProperty() + ",jdbcType=" + introspectedColumn.getJdbcTypeName() + "},"); + } + } + + XmlElement foreachElement = new XmlElement("foreach"); + foreachElement.addAttribute(new Attribute("collection", "records")); + foreachElement.addAttribute(new Attribute("index", "index")); + foreachElement.addAttribute(new Attribute("item", "item")); + foreachElement.addAttribute(new Attribute("separator", ",")); + insertBatchElement.addElement(new TextElement("insert into " + introspectedTable.getAliasedFullyQualifiedTableNameAtRuntime() + " (")); + insertBatchElement.addElement(new TextElement(" " + sqlElement.delete(sqlElement.lastIndexOf(","), sqlElement.length()).toString())); + insertBatchElement.addElement(new TextElement(") values ")); + foreachElement.addElement(new TextElement(javaPropertyAndDbType.delete(javaPropertyAndDbType.length() - 1, javaPropertyAndDbType.length()).append("\n )").toString())); + insertBatchElement.addElement(foreachElement); + + document.getRootElement().addElement(insertBatchElement); + } + +} \ No newline at end of file diff --git a/mybatis-generator/src/main/java/org/apache/iotdb/mybatis/plugin/LombokPlugin.java b/mybatis-generator/src/main/java/org/apache/iotdb/mybatis/plugin/LombokPlugin.java new file mode 100644 index 0000000..fc5324a --- /dev/null +++ b/mybatis-generator/src/main/java/org/apache/iotdb/mybatis/plugin/LombokPlugin.java @@ -0,0 +1,54 @@ +/* + * 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.iotdb.mybatis.plugin; + +import org.mybatis.generator.api.IntrospectedColumn; +import org.mybatis.generator.api.IntrospectedTable; +import org.mybatis.generator.api.PluginAdapter; +import org.mybatis.generator.api.dom.java.Method; +import org.mybatis.generator.api.dom.java.TopLevelClass; + +import java.util.List; + +public class LombokPlugin extends PluginAdapter { + + @Override + public boolean validate(List list) { + return true; + } + + @Override + public boolean modelBaseRecordClassGenerated(TopLevelClass topLevelClass, IntrospectedTable introspectedTable) { + topLevelClass.addImportedType("lombok.Data"); + + topLevelClass.addAnnotation("@Data"); + + return true; + } + + @Override + public boolean modelSetterMethodGenerated(Method method, TopLevelClass topLevelClass, IntrospectedColumn introspectedColumn, IntrospectedTable introspectedTable, ModelClassType modelClassType) { + return false; + } + + @Override + public boolean modelGetterMethodGenerated(Method method, TopLevelClass topLevelClass, IntrospectedColumn introspectedColumn, IntrospectedTable introspectedTable, ModelClassType modelClassType) { + return false; + } +} \ No newline at end of file diff --git a/mybatis-generator/src/main/java/org/apache/iotdb/mybatis/plugin/SerializablePlugin.java b/mybatis-generator/src/main/java/org/apache/iotdb/mybatis/plugin/SerializablePlugin.java new file mode 100644 index 0000000..6c70914 --- /dev/null +++ b/mybatis-generator/src/main/java/org/apache/iotdb/mybatis/plugin/SerializablePlugin.java @@ -0,0 +1,137 @@ +/* + * 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.iotdb.mybatis.plugin; + +import org.mybatis.generator.api.IntrospectedTable; +import org.mybatis.generator.api.PluginAdapter; +import org.mybatis.generator.api.dom.java.Field; +import org.mybatis.generator.api.dom.java.FullyQualifiedJavaType; +import org.mybatis.generator.api.dom.java.InnerClass; +import org.mybatis.generator.api.dom.java.JavaVisibility; +import org.mybatis.generator.api.dom.java.TopLevelClass; + +import java.util.List; +import java.util.Properties; + +public class SerializablePlugin extends PluginAdapter { + + private FullyQualifiedJavaType serializable; + private FullyQualifiedJavaType gwtSerializable; + private boolean addGWTInterface; + private boolean suppressJavaInterface; + + public SerializablePlugin() { + super(); + serializable = new FullyQualifiedJavaType("java.io.Serializable"); + gwtSerializable = new FullyQualifiedJavaType("com.google.gwt.user.client.rpc.IsSerializable"); + } + + @Override + public boolean validate(List warnings) { + // this plugin is always valid + return true; + } + + @Override + public void setProperties(Properties properties) { + super.setProperties(properties); + addGWTInterface = Boolean.valueOf(properties.getProperty("addGWTInterface")); + suppressJavaInterface = Boolean.valueOf(properties.getProperty("suppressJavaInterface")); + } + + @Override + public boolean modelBaseRecordClassGenerated(TopLevelClass topLevelClass, IntrospectedTable introspectedTable) { + makeSerializable(topLevelClass, introspectedTable); + return true; + } + + @Override + public boolean modelPrimaryKeyClassGenerated(TopLevelClass topLevelClass, IntrospectedTable introspectedTable) { + makeSerializable(topLevelClass, introspectedTable); + return true; + } + + @Override + public boolean modelRecordWithBLOBsClassGenerated(TopLevelClass topLevelClass, IntrospectedTable introspectedTable) { + makeSerializable(topLevelClass, introspectedTable); + return true; + } + + @Override + public boolean modelExampleClassGenerated(TopLevelClass topLevelClass, IntrospectedTable introspectedTable) { + + makeSerializable(topLevelClass, introspectedTable); + + for (InnerClass innerClass : topLevelClass.getInnerClasses()) { + if ("GeneratedCriteria".equals(innerClass.getType().getShortName())) { + addSerialVersionUIDField(innerClass); + } else if ("Criteria".equals(innerClass.getType().getShortName())) { + addSerialVersionUIDField(innerClass); + } else if ("Criterion".equals(innerClass.getType().getShortName())) { + addSerialVersionUIDField(innerClass); + } + } + + return true; + } + + private void addSerialVersionUIDField(InnerClass innerClass) { + innerClass.addSuperInterface(serializable); + Field field = getSerialVersionUIDField(); + innerClass.addField(field); + } + + private Field getSerialVersionUIDField() { + final FullyQualifiedJavaType qualifiedJavaType = new FullyQualifiedJavaType("long"); + Field field = new Field("serialVersionUID",qualifiedJavaType); + field.setFinal(true); + field.setInitializationString("1L"); + field.setName("serialVersionUID"); + field.setStatic(true); + field.setType(qualifiedJavaType); + field.setVisibility(JavaVisibility.PRIVATE); + return field; + } + + protected void makeSerializable(TopLevelClass topLevelClass, IntrospectedTable introspectedTable) { + if (addGWTInterface) { + topLevelClass.addImportedType(gwtSerializable); + topLevelClass.addSuperInterface(gwtSerializable); + } + + List fields = topLevelClass.getFields(); + if (null != fields && fields.size() > 0) { + for (Field field : fields) { + if ("serialVersionUID".equals(field.getName())) { + return; + } + } + } + + if (!suppressJavaInterface) { + topLevelClass.addImportedType(serializable); + topLevelClass.addSuperInterface(serializable); + + Field field = getSerialVersionUIDField(); + context.getCommentGenerator().addFieldComment(field, introspectedTable); + + topLevelClass.addField(field); + } + } +} \ No newline at end of file diff --git a/mybatis-generator/src/main/java/org/apache/iotdb/mybatis/plugin/generator/CNCommentGenerator.java b/mybatis-generator/src/main/java/org/apache/iotdb/mybatis/plugin/generator/CNCommentGenerator.java new file mode 100644 index 0000000..9403dc8 --- /dev/null +++ b/mybatis-generator/src/main/java/org/apache/iotdb/mybatis/plugin/generator/CNCommentGenerator.java @@ -0,0 +1,125 @@ +/* + * 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.iotdb.mybatis.plugin.generator; + +import org.apache.iotdb.mybatis.plugin.util.DateUtil; +import org.mybatis.generator.api.IntrospectedColumn; +import org.mybatis.generator.api.IntrospectedTable; +import org.mybatis.generator.api.dom.java.CompilationUnit; +import org.mybatis.generator.api.dom.java.Field; +import org.mybatis.generator.api.dom.java.FullyQualifiedJavaType; +import org.mybatis.generator.api.dom.java.JavaVisibility; +import org.mybatis.generator.api.dom.java.TopLevelClass; +import org.mybatis.generator.internal.DefaultCommentGenerator; +import org.mybatis.generator.internal.util.StringUtility; + +import java.util.Date; +import java.util.Properties; + +public class CNCommentGenerator extends DefaultCommentGenerator { + private Properties properties; + + @Override + public void addConfigurationProperties(Properties properties) { + super.addConfigurationProperties(properties); + this.properties = new Properties(); + this.properties.putAll(properties); + } + + @Override + public void addJavaFileComment(CompilationUnit compilationUnit) { + compilationUnit.addFileCommentLine("/**"); + + String copyright = " * Copyright From 2025. IoTDB."; + compilationUnit.addFileCommentLine(copyright); + + compilationUnit.addFileCommentLine(" * "); + compilationUnit.addFileCommentLine(" * " + compilationUnit.getType().getShortNameWithoutTypeArguments() + ".java"); + compilationUnit.addFileCommentLine(" */"); + } + + @Override + public void addModelClassComment(TopLevelClass topLevelClass, IntrospectedTable introspectedTable) { + StringBuilder sb = new StringBuilder(); + + topLevelClass.addJavaDocLine("/**"); + topLevelClass.addJavaDocLine(" *"); + + String remarks = introspectedTable.getRemarks(); + if (StringUtility.stringHasValue(remarks)) { + String[] remarkLines = remarks.split(System.getProperty("line.separator")); + for (String remarkLine : remarkLines) { + topLevelClass.addJavaDocLine(" * " + remarkLine); + } + sb.append(" * "); + } + + sb.append("table: "); + sb.append(introspectedTable.getFullyQualifiedTable()); + sb.append(" of model class"); + topLevelClass.addJavaDocLine(sb.toString()); + topLevelClass.addJavaDocLine(" *"); + + String author = "IoTDB"; + if (properties.containsKey("author")) { + author = properties.getProperty("author"); + } + + topLevelClass.addJavaDocLine(" * @author " + author); + topLevelClass.addJavaDocLine(" * @date " + DateUtil.date2Str(new Date())); + topLevelClass.addJavaDocLine(" */"); + FullyQualifiedJavaType serializable = new FullyQualifiedJavaType("java.io.Serializable"); + + topLevelClass.addImportedType(serializable); + topLevelClass.addSuperInterface(serializable); + + final FullyQualifiedJavaType qualifiedJavaType = new FullyQualifiedJavaType("long"); + Field serialVersionUID = new Field("serialVersionUID",qualifiedJavaType); + serialVersionUID.setVisibility(JavaVisibility.PRIVATE); + serialVersionUID.setStatic(true); + serialVersionUID.setFinal(true); + serialVersionUID.setName("serialVersionUID"); + serialVersionUID.setType(qualifiedJavaType); + serialVersionUID.setInitializationString("1L"); + sb = new StringBuilder(); + sb.append("/**\n "); + sb.append(" * class serial version id\n "); + sb.append(" */"); + serialVersionUID.addJavaDocLine(sb.toString()); + + topLevelClass.addField(serialVersionUID); + } + + @Override + public void addFieldComment(Field field, IntrospectedTable introspectedTable, IntrospectedColumn introspectedColumn) { + StringBuffer sb = new StringBuffer(); + + sb.append("/**\n "); + sb.append(" * field: "); + sb.append(introspectedColumn.getActualColumnName()); + + String remarks = introspectedColumn.getRemarks(); + if (StringUtility.stringHasValue(remarks)) { + sb.append(","); + sb.append(remarks); + } + + sb.append("\n */"); + field.addJavaDocLine(sb.toString()); + } +} diff --git a/mybatis-generator/src/main/java/org/apache/iotdb/mybatis/plugin/generator/SwaggerCommentGenerator.java b/mybatis-generator/src/main/java/org/apache/iotdb/mybatis/plugin/generator/SwaggerCommentGenerator.java new file mode 100644 index 0000000..b0eb7d6 --- /dev/null +++ b/mybatis-generator/src/main/java/org/apache/iotdb/mybatis/plugin/generator/SwaggerCommentGenerator.java @@ -0,0 +1,141 @@ +/* + * 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.iotdb.mybatis.plugin.generator; + +import org.apache.iotdb.mybatis.plugin.util.DateUtil; +import org.mybatis.generator.api.IntrospectedColumn; +import org.mybatis.generator.api.IntrospectedTable; +import org.mybatis.generator.api.dom.java.CompilationUnit; +import org.mybatis.generator.api.dom.java.Field; +import org.mybatis.generator.api.dom.java.FullyQualifiedJavaType; +import org.mybatis.generator.api.dom.java.JavaVisibility; +import org.mybatis.generator.api.dom.java.TopLevelClass; +import org.mybatis.generator.internal.DefaultCommentGenerator; +import org.mybatis.generator.internal.util.StringUtility; + +import java.util.Date; +import java.util.Properties; + +public class SwaggerCommentGenerator extends DefaultCommentGenerator { + private Properties properties; + private boolean addRemarkComments = false; + private static final String API_MODEL_FULL_CLASS_NAME = "io.swagger.v3.oas.annotations.media.Schema"; + + @Override + public void addConfigurationProperties(Properties properties) { + super.addConfigurationProperties(properties); + this.addRemarkComments = StringUtility.isTrue(properties.getProperty("addRemarkComments")); + this.properties = new Properties(); + this.properties.putAll(properties); + } + + @Override + public void addFieldComment(Field field, IntrospectedTable introspectedTable, IntrospectedColumn introspectedColumn) { + String remarks = introspectedColumn.getRemarks(); + if (addRemarkComments && StringUtility.stringHasValue(remarks)) { + addFieldJavaDoc(field, introspectedColumn); + if (remarks.contains("\"")) { + remarks = remarks.replace("\"", "'"); + } + field.addJavaDocLine("@Schema(title = \"" + remarks + "\")"); + } + } + + private void addFieldJavaDoc(Field field, IntrospectedColumn introspectedColumn) { + + StringBuffer sb = new StringBuffer(); + sb.append("/**\n "); + sb.append(" * field: "); + sb.append(introspectedColumn.getActualColumnName()); + String remarks = introspectedColumn.getRemarks(); + if (StringUtility.stringHasValue(remarks)) { + sb.append(","); + sb.append(remarks); + } + + sb.append("\n */"); + field.addJavaDocLine(sb.toString()); + } + + @Override + public void addModelClassComment(TopLevelClass topLevelClass, IntrospectedTable introspectedTable) { + StringBuilder sb = new StringBuilder(); + + topLevelClass.addJavaDocLine("/**"); + topLevelClass.addJavaDocLine(" *"); + + String remarks = introspectedTable.getRemarks(); + if (StringUtility.stringHasValue(remarks)) { + String[] remarkLines = remarks.split(System.getProperty("line.separator")); + for (String remarkLine : remarkLines) { + topLevelClass.addJavaDocLine(" * " + remarkLine); + } + sb.append(" * "); + } + + sb.append("table: "); + sb.append(introspectedTable.getFullyQualifiedTable()); + sb.append(" of model class"); + topLevelClass.addJavaDocLine(sb.toString()); + topLevelClass.addJavaDocLine(" *"); + + String author = "IoTDB"; + if (properties.containsKey("author")) { + author = properties.getProperty("author"); + } + + topLevelClass.addJavaDocLine(" * @author " + author); + topLevelClass.addJavaDocLine(" * @date " + DateUtil.date2Str(new Date())); + topLevelClass.addJavaDocLine(" */"); + FullyQualifiedJavaType serializable = new FullyQualifiedJavaType("java.io.Serializable"); + + topLevelClass.addImportedType(serializable); + topLevelClass.addSuperInterface(serializable); + + final FullyQualifiedJavaType fullyQualifiedJavaType = new FullyQualifiedJavaType("long"); + Field serialVersionUID = new Field("serialVersionUID",fullyQualifiedJavaType); + serialVersionUID.setVisibility(JavaVisibility.PRIVATE); + serialVersionUID.setStatic(true); + serialVersionUID.setFinal(true); + serialVersionUID.setName("serialVersionUID"); + serialVersionUID.setType(fullyQualifiedJavaType); + serialVersionUID.setInitializationString("1L"); + sb = new StringBuilder(); + sb.append("/**\n "); + sb.append(" * class serial version id\n "); + sb.append(" */"); + serialVersionUID.addJavaDocLine(sb.toString()); + + topLevelClass.addField(serialVersionUID); + topLevelClass.addImportedType(API_MODEL_FULL_CLASS_NAME); + topLevelClass.addAnnotation("@Schema(title = \"" + introspectedTable.getFullyQualifiedTable() + "\", description = \"" + remarks + "\")"); + } + + @Override + public void addJavaFileComment(CompilationUnit compilationUnit) { + compilationUnit.addFileCommentLine("/**"); + + String copyright = " * Copyright From 2025, IoTDB."; + compilationUnit.addFileCommentLine(copyright); + + compilationUnit.addFileCommentLine(" * "); + compilationUnit.addFileCommentLine(" * " + compilationUnit.getType().getShortNameWithoutTypeArguments() + ".java"); + compilationUnit.addFileCommentLine(" */"); + } +} diff --git a/mybatis-generator/src/main/java/org/apache/iotdb/mybatis/plugin/generator/resolver/IoTDBJavaTypeResolver.java b/mybatis-generator/src/main/java/org/apache/iotdb/mybatis/plugin/generator/resolver/IoTDBJavaTypeResolver.java new file mode 100644 index 0000000..e13ebe8 --- /dev/null +++ b/mybatis-generator/src/main/java/org/apache/iotdb/mybatis/plugin/generator/resolver/IoTDBJavaTypeResolver.java @@ -0,0 +1,96 @@ +/* + * 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.iotdb.mybatis.plugin.generator.resolver; + +import java.sql.Types; +import java.util.HashMap; +import java.util.Map; + +import org.mybatis.generator.api.IntrospectedColumn; +import org.mybatis.generator.api.dom.java.FullyQualifiedJavaType; +import org.mybatis.generator.internal.types.JavaTypeResolverDefaultImpl; + +public class IoTDBJavaTypeResolver extends JavaTypeResolverDefaultImpl { + protected Map typeExtMap; + + public IoTDBJavaTypeResolver() { + super(); + typeExtMap = new HashMap<>(); + initTypeSet(); + } + + @Override + public FullyQualifiedJavaType calculateJavaType(IntrospectedColumn introspectedColumn) { + + for (String jdbcType : typeExtMap.keySet()) { + + String value = properties.getProperty(jdbcType); + + if (hasText(value)) { + typeMap.put(typeExtMap.get(jdbcType), new JdbcTypeInformation(jdbcType.substring(jdbcType.indexOf(".") + 1), new FullyQualifiedJavaType(value))); + } + } + + return super.calculateJavaType(introspectedColumn); + } + + private void initTypeSet() { + typeExtMap.put("jdbcType.ARRAY", Types.ARRAY); + typeExtMap.put("jdbcType.BIGINT", Types.BIGINT); + typeExtMap.put("jdbcType.BINARY", Types.BINARY); + typeExtMap.put("jdbcType.BIT", Types.BIT); + typeExtMap.put("jdbcType.BLOB", Types.BLOB); + typeExtMap.put("jdbcType.BOOLEAN", Types.BOOLEAN); + typeExtMap.put("jdbcType.CHAR", Types.CHAR); + typeExtMap.put("jdbcType.CLOB", Types.CLOB); + typeExtMap.put("jdbcType.DATALINK", Types.DATALINK); + typeExtMap.put("jdbcType.DATE", Types.DATE); + typeExtMap.put("jdbcType.DECIMAL", Types.DECIMAL); + typeExtMap.put("jdbcType.DISTINCT", Types.DISTINCT); + typeExtMap.put("jdbcType.DOUBLE", Types.DOUBLE); + typeExtMap.put("jdbcType.FLOAT", Types.FLOAT); + typeExtMap.put("jdbcType.INTEGER", Types.INTEGER); + typeExtMap.put("jdbcType.JAVA_OBJECT", Types.JAVA_OBJECT); + typeExtMap.put("jdbcType.LONGNVARCHAR", Types.LONGNVARCHAR); + typeExtMap.put("jdbcType.LONGVARBINARY", Types.LONGVARBINARY); + typeExtMap.put("jdbcType.LONGVARCHAR", Types.LONGVARCHAR); + typeExtMap.put("jdbcType.NCHAR", Types.NCHAR); + typeExtMap.put("jdbcType.NCLOB", Types.NCLOB); + typeExtMap.put("jdbcType.NVARCHAR", Types.NVARCHAR); + typeExtMap.put("jdbcType.NULL", Types.NULL); + typeExtMap.put("jdbcType.NUMERIC", Types.NUMERIC); + typeExtMap.put("jdbcType.OTHER", Types.OTHER); + typeExtMap.put("jdbcType.REAL", Types.REAL); + typeExtMap.put("jdbcType.REF", Types.REF); + typeExtMap.put("jdbcType.SMALLINT", Types.SMALLINT); + typeExtMap.put("jdbcType.STRUCT", Types.STRUCT); + typeExtMap.put("jdbcType.TIME", Types.TIME); + typeExtMap.put("jdbcType.TIMESTAMP", Types.TIMESTAMP); + typeExtMap.put("jdbcType.TINYINT", Types.TINYINT); + typeExtMap.put("jdbcType.VARBINARY", Types.VARBINARY); + typeExtMap.put("jdbcType.VARCHAR", Types.VARCHAR); + } + + public static boolean hasText(String text) { + if (text != null && text.trim().length() > 0) { + return true; + } + return false; + } +} diff --git a/mybatis-generator/src/main/java/org/apache/iotdb/mybatis/plugin/generator/resolver/JavaTypeResolverSelfImpl.java b/mybatis-generator/src/main/java/org/apache/iotdb/mybatis/plugin/generator/resolver/JavaTypeResolverSelfImpl.java new file mode 100644 index 0000000..f845beb --- /dev/null +++ b/mybatis-generator/src/main/java/org/apache/iotdb/mybatis/plugin/generator/resolver/JavaTypeResolverSelfImpl.java @@ -0,0 +1,59 @@ +/* + * 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.iotdb.mybatis.plugin.generator.resolver; + +import java.sql.Types; + +import org.mybatis.generator.api.IntrospectedColumn; +import org.mybatis.generator.internal.types.JavaTypeResolverDefaultImpl; + +public class JavaTypeResolverSelfImpl extends JavaTypeResolverDefaultImpl { + + @Override + public String calculateJdbcTypeName(IntrospectedColumn introspectedColumn) { + String answer; + JdbcTypeInformation jdbcTypeInformation = typeMap.get(introspectedColumn.getJdbcType()); + + if (jdbcTypeInformation == null) { + switch (introspectedColumn.getJdbcType()) { + case Types.DECIMAL: + answer = "DECIMAL"; + break; + case Types.NUMERIC: + answer = "NUMERIC"; + break; + case Types.DATE: + answer = "TIMESTAMP"; + break; + default: + answer = null; + break; + } + } else { + if ("DATE".equals(jdbcTypeInformation.getJdbcTypeName())) { + answer = "TIMESTAMP"; + } else { + answer = jdbcTypeInformation.getJdbcTypeName(); + } + } + + return answer; + } + +} diff --git a/mybatis-generator/src/main/java/org/apache/iotdb/mybatis/plugin/util/DateUtil.java b/mybatis-generator/src/main/java/org/apache/iotdb/mybatis/plugin/util/DateUtil.java new file mode 100644 index 0000000..8f9e6bf --- /dev/null +++ b/mybatis-generator/src/main/java/org/apache/iotdb/mybatis/plugin/util/DateUtil.java @@ -0,0 +1,29 @@ +/* + * 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.iotdb.mybatis.plugin.util; + +import java.text.SimpleDateFormat; +import java.util.Date; + +public class DateUtil { + + public static String date2Str(Date date) { + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + return sdf.format(date); + } +} diff --git a/mybatis-generator/src/main/resources/generatorConfig.xml b/mybatis-generator/src/main/resources/generatorConfig.xml new file mode 100644 index 0000000..1125f6d --- /dev/null +++ b/mybatis-generator/src/main/resources/generatorConfig.xml @@ -0,0 +1,58 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+
From 4c4f60504c748cd1d9ea0a61318881c0f3a15c16 Mon Sep 17 00:00:00 2001 From: 2b3c511 Date: Mon, 24 Feb 2025 12:07:48 +0800 Subject: [PATCH 02/14] add module in pom --- pom.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/pom.xml b/pom.xml index f46f2fb..aae7ef1 100644 --- a/pom.xml +++ b/pom.xml @@ -37,6 +37,7 @@ distributions examples iotdb-collector + mybatis-generator From f706aabd8e549d0027f163927a7c31fe61e81cea Mon Sep 17 00:00:00 2001 From: 2b3c511 Date: Mon, 24 Feb 2025 14:57:24 +0800 Subject: [PATCH 03/14] spotless --- .../mybatis/plugin/BatchInsertPlugin.java | 169 +++++++------- .../iotdb/mybatis/plugin/LombokPlugin.java | 50 +++-- .../mybatis/plugin/SerializablePlugin.java | 194 ++++++++-------- .../plugin/generator/CNCommentGenerator.java | 170 +++++++------- .../generator/SwaggerCommentGenerator.java | 207 +++++++++--------- .../resolver/IoTDBJavaTypeResolver.java | 126 +++++------ .../resolver/JavaTypeResolverSelfImpl.java | 62 +++--- .../iotdb/mybatis/plugin/util/DateUtil.java | 8 +- 8 files changed, 513 insertions(+), 473 deletions(-) diff --git a/mybatis-generator/src/main/java/org/apache/iotdb/mybatis/plugin/BatchInsertPlugin.java b/mybatis-generator/src/main/java/org/apache/iotdb/mybatis/plugin/BatchInsertPlugin.java index ed60ed4..cb24f3c 100644 --- a/mybatis-generator/src/main/java/org/apache/iotdb/mybatis/plugin/BatchInsertPlugin.java +++ b/mybatis-generator/src/main/java/org/apache/iotdb/mybatis/plugin/BatchInsertPlugin.java @@ -36,85 +36,98 @@ public class BatchInsertPlugin extends PluginAdapter { - @Override - public boolean clientGenerated(Interface interfaze, - IntrospectedTable introspectedTable) { - batchInsertMethod(interfaze, introspectedTable); - - return super.clientGenerated(interfaze, introspectedTable); - } - - @Override - public boolean sqlMapDocumentGenerated(Document document, IntrospectedTable introspectedTable) { - addBatchInsertXml(document, introspectedTable); - return super.sqlMapDocumentGenerated(document, introspectedTable); - } - - - @Override - public boolean validate(List list) { - return true; - } - - - private void batchInsertMethod(Interface interfaze, IntrospectedTable introspectedTable) { - Set importedTypes = new TreeSet<>(); - importedTypes.add(FullyQualifiedJavaType.getNewListInstance()); - importedTypes.add(new FullyQualifiedJavaType(introspectedTable.getBaseRecordType())); - - Method ibsmethod = new Method("batchInsert"); - ibsmethod.setVisibility(JavaVisibility.PUBLIC); - ibsmethod.setAbstract(true); - - FullyQualifiedJavaType ibsReturnType = FullyQualifiedJavaType.getIntInstance(); - - ibsmethod.setReturnType(ibsReturnType); - - ibsmethod.setName("batchInsert"); - - FullyQualifiedJavaType paramType = FullyQualifiedJavaType.getNewListInstance(); - FullyQualifiedJavaType paramListType; - paramListType = new FullyQualifiedJavaType(introspectedTable.getBaseRecordType()); - paramType.addTypeArgument(paramListType); - ibsmethod.addParameter(new Parameter(paramType, "records", "@Param(\"records\")")); - interfaze.addImportedTypes(importedTypes); - - interfaze.addMethod(ibsmethod); + @Override + public boolean clientGenerated(Interface interfaze, IntrospectedTable introspectedTable) { + batchInsertMethod(interfaze, introspectedTable); + + return super.clientGenerated(interfaze, introspectedTable); + } + + @Override + public boolean sqlMapDocumentGenerated(Document document, IntrospectedTable introspectedTable) { + addBatchInsertXml(document, introspectedTable); + return super.sqlMapDocumentGenerated(document, introspectedTable); + } + + @Override + public boolean validate(List list) { + return true; + } + + private void batchInsertMethod(Interface interfaze, IntrospectedTable introspectedTable) { + Set importedTypes = new TreeSet<>(); + importedTypes.add(FullyQualifiedJavaType.getNewListInstance()); + importedTypes.add(new FullyQualifiedJavaType(introspectedTable.getBaseRecordType())); + + Method ibsmethod = new Method("batchInsert"); + ibsmethod.setVisibility(JavaVisibility.PUBLIC); + ibsmethod.setAbstract(true); + + FullyQualifiedJavaType ibsReturnType = FullyQualifiedJavaType.getIntInstance(); + + ibsmethod.setReturnType(ibsReturnType); + + ibsmethod.setName("batchInsert"); + + FullyQualifiedJavaType paramType = FullyQualifiedJavaType.getNewListInstance(); + FullyQualifiedJavaType paramListType; + paramListType = new FullyQualifiedJavaType(introspectedTable.getBaseRecordType()); + paramType.addTypeArgument(paramListType); + ibsmethod.addParameter(new Parameter(paramType, "records", "@Param(\"records\")")); + interfaze.addImportedTypes(importedTypes); + + interfaze.addMethod(ibsmethod); + } + + private void addBatchInsertXml(Document document, IntrospectedTable introspectedTable) { + List columns = introspectedTable.getAllColumns(); + String incrementField = + introspectedTable.getTableConfiguration().getProperties().getProperty("incrementField"); + if (incrementField != null) { + incrementField = incrementField.toUpperCase(); } - private void addBatchInsertXml(Document document, IntrospectedTable introspectedTable) { - List columns = introspectedTable.getAllColumns(); - String incrementField = introspectedTable.getTableConfiguration().getProperties().getProperty("incrementField"); - if (incrementField != null) { - incrementField = incrementField.toUpperCase(); - } - - XmlElement insertBatchElement = new XmlElement("insert"); - insertBatchElement.addAttribute(new Attribute("id", "batchInsert")); - insertBatchElement.addAttribute(new Attribute("parameterType", "java.util.List")); - - StringBuilder sqlElement = new StringBuilder(); - StringBuilder javaPropertyAndDbType = new StringBuilder("("); - for (IntrospectedColumn introspectedColumn : columns) { - String columnName = introspectedColumn.getActualColumnName(); - if (!columnName.toUpperCase().equals(incrementField)) { - sqlElement.append(columnName + ",\n "); - javaPropertyAndDbType.append("\n #{item." + introspectedColumn.getJavaProperty() + ",jdbcType=" + introspectedColumn.getJdbcTypeName() + "},"); - } - } - - XmlElement foreachElement = new XmlElement("foreach"); - foreachElement.addAttribute(new Attribute("collection", "records")); - foreachElement.addAttribute(new Attribute("index", "index")); - foreachElement.addAttribute(new Attribute("item", "item")); - foreachElement.addAttribute(new Attribute("separator", ",")); - insertBatchElement.addElement(new TextElement("insert into " + introspectedTable.getAliasedFullyQualifiedTableNameAtRuntime() + " (")); - insertBatchElement.addElement(new TextElement(" " + sqlElement.delete(sqlElement.lastIndexOf(","), sqlElement.length()).toString())); - insertBatchElement.addElement(new TextElement(") values ")); - foreachElement.addElement(new TextElement(javaPropertyAndDbType.delete(javaPropertyAndDbType.length() - 1, javaPropertyAndDbType.length()).append("\n )").toString())); - insertBatchElement.addElement(foreachElement); - - document.getRootElement().addElement(insertBatchElement); + XmlElement insertBatchElement = new XmlElement("insert"); + insertBatchElement.addAttribute(new Attribute("id", "batchInsert")); + insertBatchElement.addAttribute(new Attribute("parameterType", "java.util.List")); + + StringBuilder sqlElement = new StringBuilder(); + StringBuilder javaPropertyAndDbType = new StringBuilder("("); + for (IntrospectedColumn introspectedColumn : columns) { + String columnName = introspectedColumn.getActualColumnName(); + if (!columnName.toUpperCase().equals(incrementField)) { + sqlElement.append(columnName + ",\n "); + javaPropertyAndDbType.append( + "\n #{item." + + introspectedColumn.getJavaProperty() + + ",jdbcType=" + + introspectedColumn.getJdbcTypeName() + + "},"); + } } -} \ No newline at end of file + XmlElement foreachElement = new XmlElement("foreach"); + foreachElement.addAttribute(new Attribute("collection", "records")); + foreachElement.addAttribute(new Attribute("index", "index")); + foreachElement.addAttribute(new Attribute("item", "item")); + foreachElement.addAttribute(new Attribute("separator", ",")); + insertBatchElement.addElement( + new TextElement( + "insert into " + + introspectedTable.getAliasedFullyQualifiedTableNameAtRuntime() + + " (")); + insertBatchElement.addElement( + new TextElement( + " " + sqlElement.delete(sqlElement.lastIndexOf(","), sqlElement.length()).toString())); + insertBatchElement.addElement(new TextElement(") values ")); + foreachElement.addElement( + new TextElement( + javaPropertyAndDbType + .delete(javaPropertyAndDbType.length() - 1, javaPropertyAndDbType.length()) + .append("\n )") + .toString())); + insertBatchElement.addElement(foreachElement); + + document.getRootElement().addElement(insertBatchElement); + } +} diff --git a/mybatis-generator/src/main/java/org/apache/iotdb/mybatis/plugin/LombokPlugin.java b/mybatis-generator/src/main/java/org/apache/iotdb/mybatis/plugin/LombokPlugin.java index fc5324a..650d4ec 100644 --- a/mybatis-generator/src/main/java/org/apache/iotdb/mybatis/plugin/LombokPlugin.java +++ b/mybatis-generator/src/main/java/org/apache/iotdb/mybatis/plugin/LombokPlugin.java @@ -15,7 +15,6 @@ * limitations under the License. */ - package org.apache.iotdb.mybatis.plugin; import org.mybatis.generator.api.IntrospectedColumn; @@ -28,27 +27,38 @@ public class LombokPlugin extends PluginAdapter { - @Override - public boolean validate(List list) { - return true; - } + @Override + public boolean validate(List list) { + return true; + } - @Override - public boolean modelBaseRecordClassGenerated(TopLevelClass topLevelClass, IntrospectedTable introspectedTable) { - topLevelClass.addImportedType("lombok.Data"); + @Override + public boolean modelBaseRecordClassGenerated( + TopLevelClass topLevelClass, IntrospectedTable introspectedTable) { + topLevelClass.addImportedType("lombok.Data"); - topLevelClass.addAnnotation("@Data"); + topLevelClass.addAnnotation("@Data"); - return true; - } + return true; + } - @Override - public boolean modelSetterMethodGenerated(Method method, TopLevelClass topLevelClass, IntrospectedColumn introspectedColumn, IntrospectedTable introspectedTable, ModelClassType modelClassType) { - return false; - } + @Override + public boolean modelSetterMethodGenerated( + Method method, + TopLevelClass topLevelClass, + IntrospectedColumn introspectedColumn, + IntrospectedTable introspectedTable, + ModelClassType modelClassType) { + return false; + } - @Override - public boolean modelGetterMethodGenerated(Method method, TopLevelClass topLevelClass, IntrospectedColumn introspectedColumn, IntrospectedTable introspectedTable, ModelClassType modelClassType) { - return false; - } -} \ No newline at end of file + @Override + public boolean modelGetterMethodGenerated( + Method method, + TopLevelClass topLevelClass, + IntrospectedColumn introspectedColumn, + IntrospectedTable introspectedTable, + ModelClassType modelClassType) { + return false; + } +} diff --git a/mybatis-generator/src/main/java/org/apache/iotdb/mybatis/plugin/SerializablePlugin.java b/mybatis-generator/src/main/java/org/apache/iotdb/mybatis/plugin/SerializablePlugin.java index 6c70914..31767c4 100644 --- a/mybatis-generator/src/main/java/org/apache/iotdb/mybatis/plugin/SerializablePlugin.java +++ b/mybatis-generator/src/main/java/org/apache/iotdb/mybatis/plugin/SerializablePlugin.java @@ -15,7 +15,6 @@ * limitations under the License. */ - package org.apache.iotdb.mybatis.plugin; import org.mybatis.generator.api.IntrospectedTable; @@ -31,107 +30,112 @@ public class SerializablePlugin extends PluginAdapter { - private FullyQualifiedJavaType serializable; - private FullyQualifiedJavaType gwtSerializable; - private boolean addGWTInterface; - private boolean suppressJavaInterface; - - public SerializablePlugin() { - super(); - serializable = new FullyQualifiedJavaType("java.io.Serializable"); - gwtSerializable = new FullyQualifiedJavaType("com.google.gwt.user.client.rpc.IsSerializable"); - } - - @Override - public boolean validate(List warnings) { - // this plugin is always valid - return true; - } - - @Override - public void setProperties(Properties properties) { - super.setProperties(properties); - addGWTInterface = Boolean.valueOf(properties.getProperty("addGWTInterface")); - suppressJavaInterface = Boolean.valueOf(properties.getProperty("suppressJavaInterface")); + private FullyQualifiedJavaType serializable; + private FullyQualifiedJavaType gwtSerializable; + private boolean addGWTInterface; + private boolean suppressJavaInterface; + + public SerializablePlugin() { + super(); + serializable = new FullyQualifiedJavaType("java.io.Serializable"); + gwtSerializable = new FullyQualifiedJavaType("com.google.gwt.user.client.rpc.IsSerializable"); + } + + @Override + public boolean validate(List warnings) { + // this plugin is always valid + return true; + } + + @Override + public void setProperties(Properties properties) { + super.setProperties(properties); + addGWTInterface = Boolean.valueOf(properties.getProperty("addGWTInterface")); + suppressJavaInterface = Boolean.valueOf(properties.getProperty("suppressJavaInterface")); + } + + @Override + public boolean modelBaseRecordClassGenerated( + TopLevelClass topLevelClass, IntrospectedTable introspectedTable) { + makeSerializable(topLevelClass, introspectedTable); + return true; + } + + @Override + public boolean modelPrimaryKeyClassGenerated( + TopLevelClass topLevelClass, IntrospectedTable introspectedTable) { + makeSerializable(topLevelClass, introspectedTable); + return true; + } + + @Override + public boolean modelRecordWithBLOBsClassGenerated( + TopLevelClass topLevelClass, IntrospectedTable introspectedTable) { + makeSerializable(topLevelClass, introspectedTable); + return true; + } + + @Override + public boolean modelExampleClassGenerated( + TopLevelClass topLevelClass, IntrospectedTable introspectedTable) { + + makeSerializable(topLevelClass, introspectedTable); + + for (InnerClass innerClass : topLevelClass.getInnerClasses()) { + if ("GeneratedCriteria".equals(innerClass.getType().getShortName())) { + addSerialVersionUIDField(innerClass); + } else if ("Criteria".equals(innerClass.getType().getShortName())) { + addSerialVersionUIDField(innerClass); + } else if ("Criterion".equals(innerClass.getType().getShortName())) { + addSerialVersionUIDField(innerClass); + } } - @Override - public boolean modelBaseRecordClassGenerated(TopLevelClass topLevelClass, IntrospectedTable introspectedTable) { - makeSerializable(topLevelClass, introspectedTable); - return true; + return true; + } + + private void addSerialVersionUIDField(InnerClass innerClass) { + innerClass.addSuperInterface(serializable); + Field field = getSerialVersionUIDField(); + innerClass.addField(field); + } + + private Field getSerialVersionUIDField() { + final FullyQualifiedJavaType qualifiedJavaType = new FullyQualifiedJavaType("long"); + Field field = new Field("serialVersionUID", qualifiedJavaType); + field.setFinal(true); + field.setInitializationString("1L"); + field.setName("serialVersionUID"); + field.setStatic(true); + field.setType(qualifiedJavaType); + field.setVisibility(JavaVisibility.PRIVATE); + return field; + } + + protected void makeSerializable( + TopLevelClass topLevelClass, IntrospectedTable introspectedTable) { + if (addGWTInterface) { + topLevelClass.addImportedType(gwtSerializable); + topLevelClass.addSuperInterface(gwtSerializable); } - @Override - public boolean modelPrimaryKeyClassGenerated(TopLevelClass topLevelClass, IntrospectedTable introspectedTable) { - makeSerializable(topLevelClass, introspectedTable); - return true; - } - - @Override - public boolean modelRecordWithBLOBsClassGenerated(TopLevelClass topLevelClass, IntrospectedTable introspectedTable) { - makeSerializable(topLevelClass, introspectedTable); - return true; - } - - @Override - public boolean modelExampleClassGenerated(TopLevelClass topLevelClass, IntrospectedTable introspectedTable) { - - makeSerializable(topLevelClass, introspectedTable); - - for (InnerClass innerClass : topLevelClass.getInnerClasses()) { - if ("GeneratedCriteria".equals(innerClass.getType().getShortName())) { - addSerialVersionUIDField(innerClass); - } else if ("Criteria".equals(innerClass.getType().getShortName())) { - addSerialVersionUIDField(innerClass); - } else if ("Criterion".equals(innerClass.getType().getShortName())) { - addSerialVersionUIDField(innerClass); - } + List fields = topLevelClass.getFields(); + if (null != fields && fields.size() > 0) { + for (Field field : fields) { + if ("serialVersionUID".equals(field.getName())) { + return; } - - return true; - } - - private void addSerialVersionUIDField(InnerClass innerClass) { - innerClass.addSuperInterface(serializable); - Field field = getSerialVersionUIDField(); - innerClass.addField(field); + } } - private Field getSerialVersionUIDField() { - final FullyQualifiedJavaType qualifiedJavaType = new FullyQualifiedJavaType("long"); - Field field = new Field("serialVersionUID",qualifiedJavaType); - field.setFinal(true); - field.setInitializationString("1L"); - field.setName("serialVersionUID"); - field.setStatic(true); - field.setType(qualifiedJavaType); - field.setVisibility(JavaVisibility.PRIVATE); - return field; - } + if (!suppressJavaInterface) { + topLevelClass.addImportedType(serializable); + topLevelClass.addSuperInterface(serializable); - protected void makeSerializable(TopLevelClass topLevelClass, IntrospectedTable introspectedTable) { - if (addGWTInterface) { - topLevelClass.addImportedType(gwtSerializable); - topLevelClass.addSuperInterface(gwtSerializable); - } + Field field = getSerialVersionUIDField(); + context.getCommentGenerator().addFieldComment(field, introspectedTable); - List fields = topLevelClass.getFields(); - if (null != fields && fields.size() > 0) { - for (Field field : fields) { - if ("serialVersionUID".equals(field.getName())) { - return; - } - } - } - - if (!suppressJavaInterface) { - topLevelClass.addImportedType(serializable); - topLevelClass.addSuperInterface(serializable); - - Field field = getSerialVersionUIDField(); - context.getCommentGenerator().addFieldComment(field, introspectedTable); - - topLevelClass.addField(field); - } + topLevelClass.addField(field); } -} \ No newline at end of file + } +} diff --git a/mybatis-generator/src/main/java/org/apache/iotdb/mybatis/plugin/generator/CNCommentGenerator.java b/mybatis-generator/src/main/java/org/apache/iotdb/mybatis/plugin/generator/CNCommentGenerator.java index 9403dc8..3d16206 100644 --- a/mybatis-generator/src/main/java/org/apache/iotdb/mybatis/plugin/generator/CNCommentGenerator.java +++ b/mybatis-generator/src/main/java/org/apache/iotdb/mybatis/plugin/generator/CNCommentGenerator.java @@ -18,6 +18,7 @@ package org.apache.iotdb.mybatis.plugin.generator; import org.apache.iotdb.mybatis.plugin.util.DateUtil; + import org.mybatis.generator.api.IntrospectedColumn; import org.mybatis.generator.api.IntrospectedTable; import org.mybatis.generator.api.dom.java.CompilationUnit; @@ -32,94 +33,97 @@ import java.util.Properties; public class CNCommentGenerator extends DefaultCommentGenerator { - private Properties properties; - - @Override - public void addConfigurationProperties(Properties properties) { - super.addConfigurationProperties(properties); - this.properties = new Properties(); - this.properties.putAll(properties); + private Properties properties; + + @Override + public void addConfigurationProperties(Properties properties) { + super.addConfigurationProperties(properties); + this.properties = new Properties(); + this.properties.putAll(properties); + } + + @Override + public void addJavaFileComment(CompilationUnit compilationUnit) { + compilationUnit.addFileCommentLine("/**"); + + String copyright = " * Copyright From 2025. IoTDB."; + compilationUnit.addFileCommentLine(copyright); + + compilationUnit.addFileCommentLine(" * "); + compilationUnit.addFileCommentLine( + " * " + compilationUnit.getType().getShortNameWithoutTypeArguments() + ".java"); + compilationUnit.addFileCommentLine(" */"); + } + + @Override + public void addModelClassComment( + TopLevelClass topLevelClass, IntrospectedTable introspectedTable) { + StringBuilder sb = new StringBuilder(); + + topLevelClass.addJavaDocLine("/**"); + topLevelClass.addJavaDocLine(" *"); + + String remarks = introspectedTable.getRemarks(); + if (StringUtility.stringHasValue(remarks)) { + String[] remarkLines = remarks.split(System.getProperty("line.separator")); + for (String remarkLine : remarkLines) { + topLevelClass.addJavaDocLine(" * " + remarkLine); + } + sb.append(" * "); } - @Override - public void addJavaFileComment(CompilationUnit compilationUnit) { - compilationUnit.addFileCommentLine("/**"); + sb.append("table: "); + sb.append(introspectedTable.getFullyQualifiedTable()); + sb.append(" of model class"); + topLevelClass.addJavaDocLine(sb.toString()); + topLevelClass.addJavaDocLine(" *"); - String copyright = " * Copyright From 2025. IoTDB."; - compilationUnit.addFileCommentLine(copyright); - - compilationUnit.addFileCommentLine(" * "); - compilationUnit.addFileCommentLine(" * " + compilationUnit.getType().getShortNameWithoutTypeArguments() + ".java"); - compilationUnit.addFileCommentLine(" */"); + String author = "IoTDB"; + if (properties.containsKey("author")) { + author = properties.getProperty("author"); } - @Override - public void addModelClassComment(TopLevelClass topLevelClass, IntrospectedTable introspectedTable) { - StringBuilder sb = new StringBuilder(); - - topLevelClass.addJavaDocLine("/**"); - topLevelClass.addJavaDocLine(" *"); - - String remarks = introspectedTable.getRemarks(); - if (StringUtility.stringHasValue(remarks)) { - String[] remarkLines = remarks.split(System.getProperty("line.separator")); - for (String remarkLine : remarkLines) { - topLevelClass.addJavaDocLine(" * " + remarkLine); - } - sb.append(" * "); - } - - sb.append("table: "); - sb.append(introspectedTable.getFullyQualifiedTable()); - sb.append(" of model class"); - topLevelClass.addJavaDocLine(sb.toString()); - topLevelClass.addJavaDocLine(" *"); - - String author = "IoTDB"; - if (properties.containsKey("author")) { - author = properties.getProperty("author"); - } - - topLevelClass.addJavaDocLine(" * @author " + author); - topLevelClass.addJavaDocLine(" * @date " + DateUtil.date2Str(new Date())); - topLevelClass.addJavaDocLine(" */"); - FullyQualifiedJavaType serializable = new FullyQualifiedJavaType("java.io.Serializable"); - - topLevelClass.addImportedType(serializable); - topLevelClass.addSuperInterface(serializable); - - final FullyQualifiedJavaType qualifiedJavaType = new FullyQualifiedJavaType("long"); - Field serialVersionUID = new Field("serialVersionUID",qualifiedJavaType); - serialVersionUID.setVisibility(JavaVisibility.PRIVATE); - serialVersionUID.setStatic(true); - serialVersionUID.setFinal(true); - serialVersionUID.setName("serialVersionUID"); - serialVersionUID.setType(qualifiedJavaType); - serialVersionUID.setInitializationString("1L"); - sb = new StringBuilder(); - sb.append("/**\n "); - sb.append(" * class serial version id\n "); - sb.append(" */"); - serialVersionUID.addJavaDocLine(sb.toString()); - - topLevelClass.addField(serialVersionUID); + topLevelClass.addJavaDocLine(" * @author " + author); + topLevelClass.addJavaDocLine(" * @date " + DateUtil.date2Str(new Date())); + topLevelClass.addJavaDocLine(" */"); + FullyQualifiedJavaType serializable = new FullyQualifiedJavaType("java.io.Serializable"); + + topLevelClass.addImportedType(serializable); + topLevelClass.addSuperInterface(serializable); + + final FullyQualifiedJavaType qualifiedJavaType = new FullyQualifiedJavaType("long"); + Field serialVersionUID = new Field("serialVersionUID", qualifiedJavaType); + serialVersionUID.setVisibility(JavaVisibility.PRIVATE); + serialVersionUID.setStatic(true); + serialVersionUID.setFinal(true); + serialVersionUID.setName("serialVersionUID"); + serialVersionUID.setType(qualifiedJavaType); + serialVersionUID.setInitializationString("1L"); + sb = new StringBuilder(); + sb.append("/**\n "); + sb.append(" * class serial version id\n "); + sb.append(" */"); + serialVersionUID.addJavaDocLine(sb.toString()); + + topLevelClass.addField(serialVersionUID); + } + + @Override + public void addFieldComment( + Field field, IntrospectedTable introspectedTable, IntrospectedColumn introspectedColumn) { + StringBuffer sb = new StringBuffer(); + + sb.append("/**\n "); + sb.append(" * field: "); + sb.append(introspectedColumn.getActualColumnName()); + + String remarks = introspectedColumn.getRemarks(); + if (StringUtility.stringHasValue(remarks)) { + sb.append(","); + sb.append(remarks); } - @Override - public void addFieldComment(Field field, IntrospectedTable introspectedTable, IntrospectedColumn introspectedColumn) { - StringBuffer sb = new StringBuffer(); - - sb.append("/**\n "); - sb.append(" * field: "); - sb.append(introspectedColumn.getActualColumnName()); - - String remarks = introspectedColumn.getRemarks(); - if (StringUtility.stringHasValue(remarks)) { - sb.append(","); - sb.append(remarks); - } - - sb.append("\n */"); - field.addJavaDocLine(sb.toString()); - } + sb.append("\n */"); + field.addJavaDocLine(sb.toString()); + } } diff --git a/mybatis-generator/src/main/java/org/apache/iotdb/mybatis/plugin/generator/SwaggerCommentGenerator.java b/mybatis-generator/src/main/java/org/apache/iotdb/mybatis/plugin/generator/SwaggerCommentGenerator.java index b0eb7d6..09a9c78 100644 --- a/mybatis-generator/src/main/java/org/apache/iotdb/mybatis/plugin/generator/SwaggerCommentGenerator.java +++ b/mybatis-generator/src/main/java/org/apache/iotdb/mybatis/plugin/generator/SwaggerCommentGenerator.java @@ -15,10 +15,10 @@ * limitations under the License. */ - package org.apache.iotdb.mybatis.plugin.generator; import org.apache.iotdb.mybatis.plugin.util.DateUtil; + import org.mybatis.generator.api.IntrospectedColumn; import org.mybatis.generator.api.IntrospectedTable; import org.mybatis.generator.api.dom.java.CompilationUnit; @@ -33,109 +33,118 @@ import java.util.Properties; public class SwaggerCommentGenerator extends DefaultCommentGenerator { - private Properties properties; - private boolean addRemarkComments = false; - private static final String API_MODEL_FULL_CLASS_NAME = "io.swagger.v3.oas.annotations.media.Schema"; - - @Override - public void addConfigurationProperties(Properties properties) { - super.addConfigurationProperties(properties); - this.addRemarkComments = StringUtility.isTrue(properties.getProperty("addRemarkComments")); - this.properties = new Properties(); - this.properties.putAll(properties); + private Properties properties; + private boolean addRemarkComments = false; + private static final String API_MODEL_FULL_CLASS_NAME = + "io.swagger.v3.oas.annotations.media.Schema"; + + @Override + public void addConfigurationProperties(Properties properties) { + super.addConfigurationProperties(properties); + this.addRemarkComments = StringUtility.isTrue(properties.getProperty("addRemarkComments")); + this.properties = new Properties(); + this.properties.putAll(properties); + } + + @Override + public void addFieldComment( + Field field, IntrospectedTable introspectedTable, IntrospectedColumn introspectedColumn) { + String remarks = introspectedColumn.getRemarks(); + if (addRemarkComments && StringUtility.stringHasValue(remarks)) { + addFieldJavaDoc(field, introspectedColumn); + if (remarks.contains("\"")) { + remarks = remarks.replace("\"", "'"); + } + field.addJavaDocLine("@Schema(title = \"" + remarks + "\")"); } - - @Override - public void addFieldComment(Field field, IntrospectedTable introspectedTable, IntrospectedColumn introspectedColumn) { - String remarks = introspectedColumn.getRemarks(); - if (addRemarkComments && StringUtility.stringHasValue(remarks)) { - addFieldJavaDoc(field, introspectedColumn); - if (remarks.contains("\"")) { - remarks = remarks.replace("\"", "'"); - } - field.addJavaDocLine("@Schema(title = \"" + remarks + "\")"); - } + } + + private void addFieldJavaDoc(Field field, IntrospectedColumn introspectedColumn) { + + StringBuffer sb = new StringBuffer(); + sb.append("/**\n "); + sb.append(" * field: "); + sb.append(introspectedColumn.getActualColumnName()); + String remarks = introspectedColumn.getRemarks(); + if (StringUtility.stringHasValue(remarks)) { + sb.append(","); + sb.append(remarks); } - private void addFieldJavaDoc(Field field, IntrospectedColumn introspectedColumn) { - - StringBuffer sb = new StringBuffer(); - sb.append("/**\n "); - sb.append(" * field: "); - sb.append(introspectedColumn.getActualColumnName()); - String remarks = introspectedColumn.getRemarks(); - if (StringUtility.stringHasValue(remarks)) { - sb.append(","); - sb.append(remarks); - } - - sb.append("\n */"); - field.addJavaDocLine(sb.toString()); + sb.append("\n */"); + field.addJavaDocLine(sb.toString()); + } + + @Override + public void addModelClassComment( + TopLevelClass topLevelClass, IntrospectedTable introspectedTable) { + StringBuilder sb = new StringBuilder(); + + topLevelClass.addJavaDocLine("/**"); + topLevelClass.addJavaDocLine(" *"); + + String remarks = introspectedTable.getRemarks(); + if (StringUtility.stringHasValue(remarks)) { + String[] remarkLines = remarks.split(System.getProperty("line.separator")); + for (String remarkLine : remarkLines) { + topLevelClass.addJavaDocLine(" * " + remarkLine); + } + sb.append(" * "); } - @Override - public void addModelClassComment(TopLevelClass topLevelClass, IntrospectedTable introspectedTable) { - StringBuilder sb = new StringBuilder(); - - topLevelClass.addJavaDocLine("/**"); - topLevelClass.addJavaDocLine(" *"); - - String remarks = introspectedTable.getRemarks(); - if (StringUtility.stringHasValue(remarks)) { - String[] remarkLines = remarks.split(System.getProperty("line.separator")); - for (String remarkLine : remarkLines) { - topLevelClass.addJavaDocLine(" * " + remarkLine); - } - sb.append(" * "); - } - - sb.append("table: "); - sb.append(introspectedTable.getFullyQualifiedTable()); - sb.append(" of model class"); - topLevelClass.addJavaDocLine(sb.toString()); - topLevelClass.addJavaDocLine(" *"); - - String author = "IoTDB"; - if (properties.containsKey("author")) { - author = properties.getProperty("author"); - } - - topLevelClass.addJavaDocLine(" * @author " + author); - topLevelClass.addJavaDocLine(" * @date " + DateUtil.date2Str(new Date())); - topLevelClass.addJavaDocLine(" */"); - FullyQualifiedJavaType serializable = new FullyQualifiedJavaType("java.io.Serializable"); - - topLevelClass.addImportedType(serializable); - topLevelClass.addSuperInterface(serializable); - - final FullyQualifiedJavaType fullyQualifiedJavaType = new FullyQualifiedJavaType("long"); - Field serialVersionUID = new Field("serialVersionUID",fullyQualifiedJavaType); - serialVersionUID.setVisibility(JavaVisibility.PRIVATE); - serialVersionUID.setStatic(true); - serialVersionUID.setFinal(true); - serialVersionUID.setName("serialVersionUID"); - serialVersionUID.setType(fullyQualifiedJavaType); - serialVersionUID.setInitializationString("1L"); - sb = new StringBuilder(); - sb.append("/**\n "); - sb.append(" * class serial version id\n "); - sb.append(" */"); - serialVersionUID.addJavaDocLine(sb.toString()); - - topLevelClass.addField(serialVersionUID); - topLevelClass.addImportedType(API_MODEL_FULL_CLASS_NAME); - topLevelClass.addAnnotation("@Schema(title = \"" + introspectedTable.getFullyQualifiedTable() + "\", description = \"" + remarks + "\")"); - } - - @Override - public void addJavaFileComment(CompilationUnit compilationUnit) { - compilationUnit.addFileCommentLine("/**"); + sb.append("table: "); + sb.append(introspectedTable.getFullyQualifiedTable()); + sb.append(" of model class"); + topLevelClass.addJavaDocLine(sb.toString()); + topLevelClass.addJavaDocLine(" *"); - String copyright = " * Copyright From 2025, IoTDB."; - compilationUnit.addFileCommentLine(copyright); - - compilationUnit.addFileCommentLine(" * "); - compilationUnit.addFileCommentLine(" * " + compilationUnit.getType().getShortNameWithoutTypeArguments() + ".java"); - compilationUnit.addFileCommentLine(" */"); + String author = "IoTDB"; + if (properties.containsKey("author")) { + author = properties.getProperty("author"); } + + topLevelClass.addJavaDocLine(" * @author " + author); + topLevelClass.addJavaDocLine(" * @date " + DateUtil.date2Str(new Date())); + topLevelClass.addJavaDocLine(" */"); + FullyQualifiedJavaType serializable = new FullyQualifiedJavaType("java.io.Serializable"); + + topLevelClass.addImportedType(serializable); + topLevelClass.addSuperInterface(serializable); + + final FullyQualifiedJavaType fullyQualifiedJavaType = new FullyQualifiedJavaType("long"); + Field serialVersionUID = new Field("serialVersionUID", fullyQualifiedJavaType); + serialVersionUID.setVisibility(JavaVisibility.PRIVATE); + serialVersionUID.setStatic(true); + serialVersionUID.setFinal(true); + serialVersionUID.setName("serialVersionUID"); + serialVersionUID.setType(fullyQualifiedJavaType); + serialVersionUID.setInitializationString("1L"); + sb = new StringBuilder(); + sb.append("/**\n "); + sb.append(" * class serial version id\n "); + sb.append(" */"); + serialVersionUID.addJavaDocLine(sb.toString()); + + topLevelClass.addField(serialVersionUID); + topLevelClass.addImportedType(API_MODEL_FULL_CLASS_NAME); + topLevelClass.addAnnotation( + "@Schema(title = \"" + + introspectedTable.getFullyQualifiedTable() + + "\", description = \"" + + remarks + + "\")"); + } + + @Override + public void addJavaFileComment(CompilationUnit compilationUnit) { + compilationUnit.addFileCommentLine("/**"); + + String copyright = " * Copyright From 2025, IoTDB."; + compilationUnit.addFileCommentLine(copyright); + + compilationUnit.addFileCommentLine(" * "); + compilationUnit.addFileCommentLine( + " * " + compilationUnit.getType().getShortNameWithoutTypeArguments() + ".java"); + compilationUnit.addFileCommentLine(" */"); + } } diff --git a/mybatis-generator/src/main/java/org/apache/iotdb/mybatis/plugin/generator/resolver/IoTDBJavaTypeResolver.java b/mybatis-generator/src/main/java/org/apache/iotdb/mybatis/plugin/generator/resolver/IoTDBJavaTypeResolver.java index e13ebe8..3aefc81 100644 --- a/mybatis-generator/src/main/java/org/apache/iotdb/mybatis/plugin/generator/resolver/IoTDBJavaTypeResolver.java +++ b/mybatis-generator/src/main/java/org/apache/iotdb/mybatis/plugin/generator/resolver/IoTDBJavaTypeResolver.java @@ -15,82 +15,84 @@ * limitations under the License. */ - package org.apache.iotdb.mybatis.plugin.generator.resolver; -import java.sql.Types; -import java.util.HashMap; -import java.util.Map; - import org.mybatis.generator.api.IntrospectedColumn; import org.mybatis.generator.api.dom.java.FullyQualifiedJavaType; import org.mybatis.generator.internal.types.JavaTypeResolverDefaultImpl; -public class IoTDBJavaTypeResolver extends JavaTypeResolverDefaultImpl { - protected Map typeExtMap; +import java.sql.Types; +import java.util.HashMap; +import java.util.Map; - public IoTDBJavaTypeResolver() { - super(); - typeExtMap = new HashMap<>(); - initTypeSet(); - } +public class IoTDBJavaTypeResolver extends JavaTypeResolverDefaultImpl { + protected Map typeExtMap; - @Override - public FullyQualifiedJavaType calculateJavaType(IntrospectedColumn introspectedColumn) { + public IoTDBJavaTypeResolver() { + super(); + typeExtMap = new HashMap<>(); + initTypeSet(); + } - for (String jdbcType : typeExtMap.keySet()) { + @Override + public FullyQualifiedJavaType calculateJavaType(IntrospectedColumn introspectedColumn) { - String value = properties.getProperty(jdbcType); + for (String jdbcType : typeExtMap.keySet()) { - if (hasText(value)) { - typeMap.put(typeExtMap.get(jdbcType), new JdbcTypeInformation(jdbcType.substring(jdbcType.indexOf(".") + 1), new FullyQualifiedJavaType(value))); - } - } + String value = properties.getProperty(jdbcType); - return super.calculateJavaType(introspectedColumn); + if (hasText(value)) { + typeMap.put( + typeExtMap.get(jdbcType), + new JdbcTypeInformation( + jdbcType.substring(jdbcType.indexOf(".") + 1), new FullyQualifiedJavaType(value))); + } } - private void initTypeSet() { - typeExtMap.put("jdbcType.ARRAY", Types.ARRAY); - typeExtMap.put("jdbcType.BIGINT", Types.BIGINT); - typeExtMap.put("jdbcType.BINARY", Types.BINARY); - typeExtMap.put("jdbcType.BIT", Types.BIT); - typeExtMap.put("jdbcType.BLOB", Types.BLOB); - typeExtMap.put("jdbcType.BOOLEAN", Types.BOOLEAN); - typeExtMap.put("jdbcType.CHAR", Types.CHAR); - typeExtMap.put("jdbcType.CLOB", Types.CLOB); - typeExtMap.put("jdbcType.DATALINK", Types.DATALINK); - typeExtMap.put("jdbcType.DATE", Types.DATE); - typeExtMap.put("jdbcType.DECIMAL", Types.DECIMAL); - typeExtMap.put("jdbcType.DISTINCT", Types.DISTINCT); - typeExtMap.put("jdbcType.DOUBLE", Types.DOUBLE); - typeExtMap.put("jdbcType.FLOAT", Types.FLOAT); - typeExtMap.put("jdbcType.INTEGER", Types.INTEGER); - typeExtMap.put("jdbcType.JAVA_OBJECT", Types.JAVA_OBJECT); - typeExtMap.put("jdbcType.LONGNVARCHAR", Types.LONGNVARCHAR); - typeExtMap.put("jdbcType.LONGVARBINARY", Types.LONGVARBINARY); - typeExtMap.put("jdbcType.LONGVARCHAR", Types.LONGVARCHAR); - typeExtMap.put("jdbcType.NCHAR", Types.NCHAR); - typeExtMap.put("jdbcType.NCLOB", Types.NCLOB); - typeExtMap.put("jdbcType.NVARCHAR", Types.NVARCHAR); - typeExtMap.put("jdbcType.NULL", Types.NULL); - typeExtMap.put("jdbcType.NUMERIC", Types.NUMERIC); - typeExtMap.put("jdbcType.OTHER", Types.OTHER); - typeExtMap.put("jdbcType.REAL", Types.REAL); - typeExtMap.put("jdbcType.REF", Types.REF); - typeExtMap.put("jdbcType.SMALLINT", Types.SMALLINT); - typeExtMap.put("jdbcType.STRUCT", Types.STRUCT); - typeExtMap.put("jdbcType.TIME", Types.TIME); - typeExtMap.put("jdbcType.TIMESTAMP", Types.TIMESTAMP); - typeExtMap.put("jdbcType.TINYINT", Types.TINYINT); - typeExtMap.put("jdbcType.VARBINARY", Types.VARBINARY); - typeExtMap.put("jdbcType.VARCHAR", Types.VARCHAR); - } + return super.calculateJavaType(introspectedColumn); + } + + private void initTypeSet() { + typeExtMap.put("jdbcType.ARRAY", Types.ARRAY); + typeExtMap.put("jdbcType.BIGINT", Types.BIGINT); + typeExtMap.put("jdbcType.BINARY", Types.BINARY); + typeExtMap.put("jdbcType.BIT", Types.BIT); + typeExtMap.put("jdbcType.BLOB", Types.BLOB); + typeExtMap.put("jdbcType.BOOLEAN", Types.BOOLEAN); + typeExtMap.put("jdbcType.CHAR", Types.CHAR); + typeExtMap.put("jdbcType.CLOB", Types.CLOB); + typeExtMap.put("jdbcType.DATALINK", Types.DATALINK); + typeExtMap.put("jdbcType.DATE", Types.DATE); + typeExtMap.put("jdbcType.DECIMAL", Types.DECIMAL); + typeExtMap.put("jdbcType.DISTINCT", Types.DISTINCT); + typeExtMap.put("jdbcType.DOUBLE", Types.DOUBLE); + typeExtMap.put("jdbcType.FLOAT", Types.FLOAT); + typeExtMap.put("jdbcType.INTEGER", Types.INTEGER); + typeExtMap.put("jdbcType.JAVA_OBJECT", Types.JAVA_OBJECT); + typeExtMap.put("jdbcType.LONGNVARCHAR", Types.LONGNVARCHAR); + typeExtMap.put("jdbcType.LONGVARBINARY", Types.LONGVARBINARY); + typeExtMap.put("jdbcType.LONGVARCHAR", Types.LONGVARCHAR); + typeExtMap.put("jdbcType.NCHAR", Types.NCHAR); + typeExtMap.put("jdbcType.NCLOB", Types.NCLOB); + typeExtMap.put("jdbcType.NVARCHAR", Types.NVARCHAR); + typeExtMap.put("jdbcType.NULL", Types.NULL); + typeExtMap.put("jdbcType.NUMERIC", Types.NUMERIC); + typeExtMap.put("jdbcType.OTHER", Types.OTHER); + typeExtMap.put("jdbcType.REAL", Types.REAL); + typeExtMap.put("jdbcType.REF", Types.REF); + typeExtMap.put("jdbcType.SMALLINT", Types.SMALLINT); + typeExtMap.put("jdbcType.STRUCT", Types.STRUCT); + typeExtMap.put("jdbcType.TIME", Types.TIME); + typeExtMap.put("jdbcType.TIMESTAMP", Types.TIMESTAMP); + typeExtMap.put("jdbcType.TINYINT", Types.TINYINT); + typeExtMap.put("jdbcType.VARBINARY", Types.VARBINARY); + typeExtMap.put("jdbcType.VARCHAR", Types.VARCHAR); + } - public static boolean hasText(String text) { - if (text != null && text.trim().length() > 0) { - return true; - } - return false; + public static boolean hasText(String text) { + if (text != null && text.trim().length() > 0) { + return true; } + return false; + } } diff --git a/mybatis-generator/src/main/java/org/apache/iotdb/mybatis/plugin/generator/resolver/JavaTypeResolverSelfImpl.java b/mybatis-generator/src/main/java/org/apache/iotdb/mybatis/plugin/generator/resolver/JavaTypeResolverSelfImpl.java index f845beb..ed841ff 100644 --- a/mybatis-generator/src/main/java/org/apache/iotdb/mybatis/plugin/generator/resolver/JavaTypeResolverSelfImpl.java +++ b/mybatis-generator/src/main/java/org/apache/iotdb/mybatis/plugin/generator/resolver/JavaTypeResolverSelfImpl.java @@ -15,45 +15,43 @@ * limitations under the License. */ - package org.apache.iotdb.mybatis.plugin.generator.resolver; -import java.sql.Types; - import org.mybatis.generator.api.IntrospectedColumn; import org.mybatis.generator.internal.types.JavaTypeResolverDefaultImpl; -public class JavaTypeResolverSelfImpl extends JavaTypeResolverDefaultImpl { - - @Override - public String calculateJdbcTypeName(IntrospectedColumn introspectedColumn) { - String answer; - JdbcTypeInformation jdbcTypeInformation = typeMap.get(introspectedColumn.getJdbcType()); +import java.sql.Types; - if (jdbcTypeInformation == null) { - switch (introspectedColumn.getJdbcType()) { - case Types.DECIMAL: - answer = "DECIMAL"; - break; - case Types.NUMERIC: - answer = "NUMERIC"; - break; - case Types.DATE: - answer = "TIMESTAMP"; - break; - default: - answer = null; - break; - } - } else { - if ("DATE".equals(jdbcTypeInformation.getJdbcTypeName())) { - answer = "TIMESTAMP"; - } else { - answer = jdbcTypeInformation.getJdbcTypeName(); - } - } +public class JavaTypeResolverSelfImpl extends JavaTypeResolverDefaultImpl { - return answer; + @Override + public String calculateJdbcTypeName(IntrospectedColumn introspectedColumn) { + String answer; + JdbcTypeInformation jdbcTypeInformation = typeMap.get(introspectedColumn.getJdbcType()); + + if (jdbcTypeInformation == null) { + switch (introspectedColumn.getJdbcType()) { + case Types.DECIMAL: + answer = "DECIMAL"; + break; + case Types.NUMERIC: + answer = "NUMERIC"; + break; + case Types.DATE: + answer = "TIMESTAMP"; + break; + default: + answer = null; + break; + } + } else { + if ("DATE".equals(jdbcTypeInformation.getJdbcTypeName())) { + answer = "TIMESTAMP"; + } else { + answer = jdbcTypeInformation.getJdbcTypeName(); + } } + return answer; + } } diff --git a/mybatis-generator/src/main/java/org/apache/iotdb/mybatis/plugin/util/DateUtil.java b/mybatis-generator/src/main/java/org/apache/iotdb/mybatis/plugin/util/DateUtil.java index 8f9e6bf..327a919 100644 --- a/mybatis-generator/src/main/java/org/apache/iotdb/mybatis/plugin/util/DateUtil.java +++ b/mybatis-generator/src/main/java/org/apache/iotdb/mybatis/plugin/util/DateUtil.java @@ -22,8 +22,8 @@ public class DateUtil { - public static String date2Str(Date date) { - SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); - return sdf.format(date); - } + public static String date2Str(Date date) { + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + return sdf.format(date); + } } From bcc06cdd942be1f01e60637b8351cb61e72bef44 Mon Sep 17 00:00:00 2001 From: 2b3c511 Date: Tue, 25 Feb 2025 18:32:52 +0800 Subject: [PATCH 04/14] add example --- examples/mybatis-generator/pom.xml | 62 +++++++++ examples/mybatis-generator/readme.md | 102 ++++++++++++++ .../src/main/resources/generatorConfig.xml | 58 ++++++++ examples/mybatisplus-generator/pom.xml | 94 +++++++++++++ examples/mybatisplus-generator/readme.md | 128 ++++++++++++++++++ .../src/main/java/org/apache/iotdb/Main.java | 80 +++++++++++ mybatis-generator/README-zh.md | 2 +- .../src/main/resources/generatorConfig.xml | 4 +- 8 files changed, 527 insertions(+), 3 deletions(-) create mode 100644 examples/mybatis-generator/pom.xml create mode 100644 examples/mybatis-generator/readme.md create mode 100644 examples/mybatis-generator/src/main/resources/generatorConfig.xml create mode 100644 examples/mybatisplus-generator/pom.xml create mode 100644 examples/mybatisplus-generator/readme.md create mode 100644 examples/mybatisplus-generator/src/main/java/org/apache/iotdb/Main.java diff --git a/examples/mybatis-generator/pom.xml b/examples/mybatis-generator/pom.xml new file mode 100644 index 0000000..023f6c2 --- /dev/null +++ b/examples/mybatis-generator/pom.xml @@ -0,0 +1,62 @@ + + + + 4.0.0 + + org.apache.iotdb + iotdb-extras-parent + 1.3.2 + ../../pom.xml + + + mybatis-generator-example + + + 21 + 21 + UTF-8 + + + + + org.mybatis.generator + mybatis-generator-maven-plugin + 1.4.2 + + + org.apache.iotdb + mybatis-generator-plugin + 1.3.2 + + + + true + true + src/main/resources/generatorConfig.xml + + + + + + \ No newline at end of file diff --git a/examples/mybatis-generator/readme.md b/examples/mybatis-generator/readme.md new file mode 100644 index 0000000..bbc1c94 --- /dev/null +++ b/examples/mybatis-generator/readme.md @@ -0,0 +1,102 @@ + +# Mybatis-Generator Demo +## Introduction + + This demo shows how to use IoTDB-Mybatis-Generator + +### Version usage + + IoTDB: 2.0.2 + mybatis-generator-plugin: 1.3.2 + +### 1. Install IoTDB + + please refer to [https://iotdb.apache.org/#/Download](https://iotdb.apache.org/#/Download) + +### 2. Startup IoTDB + + please refer to [Quick Start](http://iotdb.apache.org/UserGuide/Master/Get%20Started/QuickStart.html) + + Then we need to create a database 'test' by cli in table model + ``` + create database test; + use test; + ``` + Then we need to create a database 'table' + ``` + create table mix3( + "device_id" STRING TAG, + "deivce_name" STRING TAG, + "type" INT32 FIELD, + "name" DOUBLE FIELD, + "server_url_master" FLOAT FIELD, + "server_url_slave" BOOLEAN FIELD, + "prometheus_url_master" STRING FIELD, + "prometheus_url_slave" BLOB FIELD, + "username" STRING ATTRIBUTE, + "create_time" DATE FIELD, + "update_time" DATE FIELD); + ``` + +### 3. Build Dependencies with Maven in your Project + + ``` + + + + org.mybatis.generator + mybatis-generator-maven-plugin + 1.4.2 + + + org.apache.iotdb + mybatis-generator-plugin + 1.3.2 + + + + true + true + src/main/resources/generatorConfig.xml + + + + + ``` + +### 5. put The generatorConfig.xml in your project + + The location of the ` configurationFile ` configuration ` generatorConfig. xml ` file can be found in the ` src/main/resources ` template of this project for reference` Copy its content and place it in the corresponding location + +### 6. exec 'mvn mybatis-generator:generate' + + Execute the command at the location of the 'pom' in the project:` Mvn mybatis generator: generate generates corresponding Java classes and mapper files + +### 7、the target file location + + You can see the target file in your Project + ``` + org/apache/iotdb/mybatis/plugin/model/Mix.java + org/apache/iotdb/mybatis/plugin/mapper/MixMapper.java + org/apache/iotdb/mybatis/plugin/xml/MixMapper.xml + + ``` diff --git a/examples/mybatis-generator/src/main/resources/generatorConfig.xml b/examples/mybatis-generator/src/main/resources/generatorConfig.xml new file mode 100644 index 0000000..75d62e6 --- /dev/null +++ b/examples/mybatis-generator/src/main/resources/generatorConfig.xml @@ -0,0 +1,58 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+
diff --git a/examples/mybatisplus-generator/pom.xml b/examples/mybatisplus-generator/pom.xml new file mode 100644 index 0000000..8e9613f --- /dev/null +++ b/examples/mybatisplus-generator/pom.xml @@ -0,0 +1,94 @@ + + + + 4.0.0 + + org.apache.iotdb + iotdb-extras-parent + 1.3.2 + ../../pom.xml + + org.apache.iotdb + mybatisplus-generator-example + 1.3.2 + + + 3.5.10 + 21 + 21 + UTF-8 + + + + + com.baomidou + mybatis-plus-spring-boot3-starter + ${mybatisplus.version} + + + + com.baomidou + mybatis-plus-generator + 3.5.10 + + + + + org.apache.velocity + velocity-engine-core + 2.0 + + + + org.apache.iotdb + iotdb-jdbc + 2.0.2-SNAPSHOT + + + org.springframework.boot + spring-boot-starter + 3.4.3 + + + org.springframework.boot + spring-boot-starter-web + 3.4.3 + + + io.springfox + springfox-swagger2 + 3.0.0 + + + io.springfox + springfox-swagger-ui + 3.0.0 + + + org.projectlombok + lombok + 1.18.36 + + + \ No newline at end of file diff --git a/examples/mybatisplus-generator/readme.md b/examples/mybatisplus-generator/readme.md new file mode 100644 index 0000000..4daf1fd --- /dev/null +++ b/examples/mybatisplus-generator/readme.md @@ -0,0 +1,128 @@ + +# Mybatis-Generator Demo +## Introduction + + This demo shows how to use IoTDB-Mybatis-Generator + +### Version usage + + IoTDB: 2.0.2 + mybatisPlus: 3.5.10 + +### 1. Install IoTDB + + please refer to [https://iotdb.apache.org/#/Download](https://iotdb.apache.org/#/Download) + +### 2. Startup IoTDB + + please refer to [Quick Start](http://iotdb.apache.org/UserGuide/Master/Get%20Started/QuickStart.html) + + Then we need to create a database 'test' by cli in table model + ``` + create database test; + use test; + ``` + Then we need to create a database 'table' + ``` + create table mix( + "device_id" STRING TAG, + "deivce_name" STRING TAG, + "type" INT32 FIELD, + "name" DOUBLE FIELD, + "server_url_master" FLOAT FIELD, + "server_url_slave" BOOLEAN FIELD, + "prometheus_url_master" STRING FIELD, + "prometheus_url_slave" BLOB FIELD, + "username" STRING ATTRIBUTE, + "create_time" DATE FIELD, + "update_time" DATE FIELD); + ``` + +### 3. Build Dependencies with Maven in your Project + + ``` + + + com.baomidou + mybatis-plus-spring-boot3-starter + 3.5.10 + + + + com.baomidou + mybatis-plus-generator + 3.5.10 + + + + org.apache.velocity + velocity-engine-core + 2.0 + + + + org.apache.iotdb + iotdb-jdbc + 2.0.2 + + + org.springframework.boot + spring-boot-starter + 3.4.3 + + + org.springframework.boot + spring-boot-starter-web + 3.4.3 + + + io.springfox + springfox-swagger2 + 3.0.0 + + + io.springfox + springfox-swagger-ui + 3.0.0 + + + org.projectlombok + lombok + 1.18.36 + + + ``` + +### 5. Start the Main.java + +### 6、the target file location + + You can see the target file in your Project + ``` + org/apache/iotdb/controller/MixController.java + org/apache/iotdb/entity/Mix.java + org/apache/iotdb/mapper/MixMapper.xml + org/apache/iotdb/service/MixService.java + org/apache/iotdb/service/MixServiceImpl.java + org/apache/iotdb/MixMapper.xml + + ``` diff --git a/examples/mybatisplus-generator/src/main/java/org/apache/iotdb/Main.java b/examples/mybatisplus-generator/src/main/java/org/apache/iotdb/Main.java new file mode 100644 index 0000000..b8e19af --- /dev/null +++ b/examples/mybatisplus-generator/src/main/java/org/apache/iotdb/Main.java @@ -0,0 +1,80 @@ +/* + * 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.iotdb; + +import com.baomidou.mybatisplus.generator.FastAutoGenerator; +import com.baomidou.mybatisplus.generator.config.DataSourceConfig; +import com.baomidou.mybatisplus.generator.config.OutputFile; +import com.baomidou.mybatisplus.generator.config.rules.DateType; +import com.baomidou.mybatisplus.generator.config.rules.DbColumnType; +import org.apache.iotdb.jdbc.IoTDBDataSource; + +import java.sql.Types; +import java.util.Collections; + + +public class Main { + public static void main(String[] args) { + IoTDBDataSource dataSource = new IoTDBDataSource(); + dataSource.setUrl("jdbc:iotdb://127.0.0.1:6667/test?sql_dialect=table"); + dataSource.setUser("root"); + dataSource.setPassword("root"); + FastAutoGenerator generator = FastAutoGenerator.create(new DataSourceConfig.Builder(dataSource).driverClassName("org.apache.iotdb.jdbc.IoTDBDriver")); + generator + .globalConfig(builder -> { + builder.author("IoTDB") + .enableSwagger() + .dateType(DateType.ONLY_DATE) + .outputDir("/apache/iotdb-extras/examples/mybatisplus-generator/src/main/java/"); + }) + .packageConfig(builder -> { + builder.parent("org.apache.iotdb") + .mapper("mapper") + .pathInfo(Collections.singletonMap(OutputFile.xml, "/apache/iotdb-extras/examples/mybatisplus-generator/src/main/java/")); + }) + .dataSourceConfig(builder -> { + builder.typeConvertHandler((globalConfig, typeRegistry, metaInfo) -> { + int typeCode = metaInfo.getJdbcType().TYPE_CODE; + switch (typeCode) { + case Types.FLOAT: + return DbColumnType.FLOAT; + default: + return typeRegistry.getColumnType(metaInfo); + } + }); + }) + .strategyConfig(builder -> { + builder.addInclude("mix"); + builder.entityBuilder() + .enableLombok() + .addIgnoreColumns("create_time") + .enableFileOverride(); + builder.serviceBuilder() + .formatServiceFileName("%sService") + .formatServiceImplFileName("%sServiceImpl") + .convertServiceFileName((entityName -> entityName + "Service")) + .enableFileOverride(); + builder.controllerBuilder() + .enableRestStyle() + .enableFileOverride(); + }) + .execute(); + } +} diff --git a/mybatis-generator/README-zh.md b/mybatis-generator/README-zh.md index 54cc853..a921877 100644 --- a/mybatis-generator/README-zh.md +++ b/mybatis-generator/README-zh.md @@ -14,7 +14,7 @@ org.apache.iotdb - iotdb-mybatis-generator + mybatis-generator-plugin 1.3.2-SNAPSHOT diff --git a/mybatis-generator/src/main/resources/generatorConfig.xml b/mybatis-generator/src/main/resources/generatorConfig.xml index 1125f6d..67d17f1 100644 --- a/mybatis-generator/src/main/resources/generatorConfig.xml +++ b/mybatis-generator/src/main/resources/generatorConfig.xml @@ -18,7 +18,7 @@ --> - + @@ -51,7 +51,7 @@ - +
From d1717c7d979dcf4840654a4df2c37a694fbdbd56 Mon Sep 17 00:00:00 2001 From: 2b3c511 Date: Tue, 11 Mar 2025 18:29:15 +0800 Subject: [PATCH 05/14] update version --- .gitignore | 5 ++++- examples/mybatis-generator/pom.xml | 3 ++- examples/mybatisplus-generator/pom.xml | 6 +++--- mybatis-generator/pom.xml | 4 ++-- 4 files changed, 11 insertions(+), 7 deletions(-) diff --git a/.gitignore b/.gitignore index dced3d9..e42f183 100644 --- a/.gitignore +++ b/.gitignore @@ -7,4 +7,7 @@ target/ *.iml # log -logs/ \ No newline at end of file +logs/ + +.DS_Store +~/ \ No newline at end of file diff --git a/examples/mybatis-generator/pom.xml b/examples/mybatis-generator/pom.xml index 023f6c2..8ff251d 100644 --- a/examples/mybatis-generator/pom.xml +++ b/examples/mybatis-generator/pom.xml @@ -26,11 +26,12 @@ org.apache.iotdb iotdb-extras-parent - 1.3.2 + 2.0.2-SNAPSHOT ../../pom.xml mybatis-generator-example + 2.0.2-SNAPHOT 21 diff --git a/examples/mybatisplus-generator/pom.xml b/examples/mybatisplus-generator/pom.xml index 8e9613f..0141852 100644 --- a/examples/mybatisplus-generator/pom.xml +++ b/examples/mybatisplus-generator/pom.xml @@ -26,12 +26,12 @@ org.apache.iotdb iotdb-extras-parent - 1.3.2 + 2.0.2-SNAPSHOT ../../pom.xml org.apache.iotdb mybatisplus-generator-example - 1.3.2 + 2.0.2-SNAPHOT 3.5.10 @@ -63,7 +63,7 @@ org.apache.iotdb iotdb-jdbc - 2.0.2-SNAPSHOT + 2.0.1-beta org.springframework.boot diff --git a/mybatis-generator/pom.xml b/mybatis-generator/pom.xml index 0c86ff6..128d2fd 100644 --- a/mybatis-generator/pom.xml +++ b/mybatis-generator/pom.xml @@ -4,11 +4,11 @@ org.apache.iotdb iotdb-extras-parent - 1.3.2 + 2.0.2-SNAPSHOT org.apache.iotdb mybatis-generator-plugin - 1.3.2 + 2.0.2-SNAPSHOT jar From dc4b7e006f3c03ce544dc35fa62da2d69af5ba42 Mon Sep 17 00:00:00 2001 From: 2b3c511 Date: Mon, 17 Mar 2025 12:27:10 +0800 Subject: [PATCH 06/14] iotdb-spring-boot-starter --- examples/iotdb-spring-boot-start/pom.xml | 46 +++++ examples/iotdb-spring-boot-start/readme.md | 116 +++++++++++++ .../IotdbSpringBootStartApplication.java | 13 ++ .../service/IoTDBService.java | 51 ++++++ .../src/main/resources/application.properties | 8 + .../IotdbSpringBootStartApplicationTests.java | 22 +++ examples/mybatis-generator/pom.xml | 9 +- .../src/main/resources/generatorConfig.xml | 8 +- examples/mybatisplus-generator/pom.xml | 10 +- iotdb-spring-boot-starter/README.md | 33 ++++ iotdb-spring-boot-starter/pom.xml | 44 +++++ .../iotdb/config/IoTDBSessionProperties.java | 158 ++++++++++++++++++ .../iotdb/session/IoTDBSessionPool.java | 77 +++++++++ ...ot.autoconfigure.AutoConfiguration.imports | 1 + mybatis-generator/README.md | 60 ++++--- 15 files changed, 611 insertions(+), 45 deletions(-) create mode 100644 examples/iotdb-spring-boot-start/pom.xml create mode 100644 examples/iotdb-spring-boot-start/readme.md create mode 100644 examples/iotdb-spring-boot-start/src/main/java/org/apache/iotdb/iotdbspringbootstartexample/IotdbSpringBootStartApplication.java create mode 100644 examples/iotdb-spring-boot-start/src/main/java/org/apache/iotdb/iotdbspringbootstartexample/service/IoTDBService.java create mode 100644 examples/iotdb-spring-boot-start/src/main/resources/application.properties create mode 100644 examples/iotdb-spring-boot-start/src/test/java/org/apache/iotdb/iotdbspringbootstartexample/IotdbSpringBootStartApplicationTests.java create mode 100644 iotdb-spring-boot-starter/README.md create mode 100644 iotdb-spring-boot-starter/pom.xml create mode 100644 iotdb-spring-boot-starter/src/main/java/org/apache/iotdb/config/IoTDBSessionProperties.java create mode 100644 iotdb-spring-boot-starter/src/main/java/org/apache/iotdb/session/IoTDBSessionPool.java create mode 100644 iotdb-spring-boot-starter/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports diff --git a/examples/iotdb-spring-boot-start/pom.xml b/examples/iotdb-spring-boot-start/pom.xml new file mode 100644 index 0000000..a01eed7 --- /dev/null +++ b/examples/iotdb-spring-boot-start/pom.xml @@ -0,0 +1,46 @@ + + + 4.0.0 + + org.springframework.boot + spring-boot-starter-parent + 3.4.3 + + + org.apache.iotdb + iotdb-spring-boot-start-example + 2.0.2-SNAPHOT + iotdb-spring-boot-start + iotdb-spring-boot-start + + 17 + + + + org.springframework.boot + spring-boot-starter + + + + org.springframework.boot + spring-boot-starter-test + test + + + org.apache.iotdb + iotdb-spring-boot-starter + 2.0.2-SNAPSHOT + + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + + + diff --git a/examples/iotdb-spring-boot-start/readme.md b/examples/iotdb-spring-boot-start/readme.md new file mode 100644 index 0000000..4bf3867 --- /dev/null +++ b/examples/iotdb-spring-boot-start/readme.md @@ -0,0 +1,116 @@ + +# IoTDB-Spring-Boot-Starter Demo +## Introduction + + This demo shows how to use iotdb-spring-boot-starter + +### Version usage + + IoTDB: 2.0.1-beta + iotdb-spring-boot-starter: 2.0.2-SNAPSHOT + +### 1. Install IoTDB + + please refer to [https://iotdb.apache.org/#/Download](https://iotdb.apache.org/#/Download) + +### 2. Startup IoTDB + + please refer to [Quick Start](http://iotdb.apache.org/UserGuide/Master/Get%20Started/QuickStart.html) + + Then we need to create a database 'wind' by cli in table model + ``` + create database wind; + use wind; + ``` + Then we need to create a database 'table' + ``` + create table power_data_set( + "device_id" STRING TAG, + "deivce_name" STRING TAG, + "type" INT32 FIELD, + "name" DOUBLE FIELD, + "server_url_master" FLOAT FIELD, + "server_url_slave" BOOLEAN FIELD, + "prometheus_url_master" STRING FIELD, + "prometheus_url_slave" BLOB FIELD, + "username" STRING ATTRIBUTE, + "create_time" DATE FIELD, + "update_time" DATE FIELD); + ``` + +### 3. Build Dependencies with Maven in your Project + + ``` + + + org.springframework.boot + spring-boot-starter + + + + org.springframework.boot + spring-boot-starter-test + test + + + org.apache.iotdb + iotdb-spring-boot-starter + 2.0.2-SNAPSHOT + + + ``` + +### 4、Use The target Bean with @Autowired + + You can use the target Bean in your Project,like: + ``` + @Autowired + private ITableSessionPool ioTDBSessionPool; + @Autowired + private SessionPool sessionPool; + + public void queryTableSessionPool() throws IoTDBConnectionException, StatementExecutionException { + ITableSession tableSession = ioTDBSessionPool.getSession(); + final SessionDataSet sessionDataSet = tableSession.executeQueryStatement("select * from power_data_set limit 10"); + while (sessionDataSet.hasNext()) { + final RowRecord rowRecord = sessionDataSet.next(); + final List fields = rowRecord.getFields(); + for (Field field : fields) { + System.out.print(field.getStringValue()); + } + System.out.println(); + } + } + + public void querySessionPool() throws IoTDBConnectionException, StatementExecutionException { + final SessionDataSetWrapper sessionDataSetWrapper = sessionPool.executeQueryStatement("show databases"); + while (sessionDataSetWrapper.hasNext()) { + final RowRecord rowRecord = sessionDataSetWrapper.next(); + final List fields = rowRecord.getFields(); + for (Field field : fields) { + System.out.print(field.getStringValue()); + } + System.out.println(); + } + } + + ``` diff --git a/examples/iotdb-spring-boot-start/src/main/java/org/apache/iotdb/iotdbspringbootstartexample/IotdbSpringBootStartApplication.java b/examples/iotdb-spring-boot-start/src/main/java/org/apache/iotdb/iotdbspringbootstartexample/IotdbSpringBootStartApplication.java new file mode 100644 index 0000000..185e97f --- /dev/null +++ b/examples/iotdb-spring-boot-start/src/main/java/org/apache/iotdb/iotdbspringbootstartexample/IotdbSpringBootStartApplication.java @@ -0,0 +1,13 @@ +package org.apache.iotdb.iotdbspringbootstartexample; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class IotdbSpringBootStartApplication { + + public static void main(String[] args) { + SpringApplication.run(IotdbSpringBootStartApplication.class, args); + } + +} diff --git a/examples/iotdb-spring-boot-start/src/main/java/org/apache/iotdb/iotdbspringbootstartexample/service/IoTDBService.java b/examples/iotdb-spring-boot-start/src/main/java/org/apache/iotdb/iotdbspringbootstartexample/service/IoTDBService.java new file mode 100644 index 0000000..8b7e703 --- /dev/null +++ b/examples/iotdb-spring-boot-start/src/main/java/org/apache/iotdb/iotdbspringbootstartexample/service/IoTDBService.java @@ -0,0 +1,51 @@ +package org.apache.iotdb.iotdbspringbootstartexample.service; + +import org.apache.iotdb.isession.ITableSession; +import org.apache.iotdb.isession.SessionDataSet; +import org.apache.iotdb.isession.pool.ITableSessionPool; +import org.apache.iotdb.isession.pool.SessionDataSetWrapper; +import org.apache.iotdb.rpc.IoTDBConnectionException; +import org.apache.iotdb.rpc.StatementExecutionException; +import org.apache.iotdb.session.pool.SessionPool; +import org.apache.tsfile.read.common.Field; +import org.apache.tsfile.read.common.RowRecord; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import java.util.List; + +@Service +public class IoTDBService { + + @Autowired + private ITableSessionPool ioTDBSessionPool; + + @Autowired + private SessionPool sessionPool; + + + public void queryTableSessionPool() throws IoTDBConnectionException, StatementExecutionException { + ITableSession tableSession = ioTDBSessionPool.getSession(); + final SessionDataSet sessionDataSet = tableSession.executeQueryStatement("select * from power_data_set limit 10"); + while (sessionDataSet.hasNext()) { + final RowRecord rowRecord = sessionDataSet.next(); + final List fields = rowRecord.getFields(); + for (Field field : fields) { + System.out.print(field.getStringValue()); + } + System.out.println(); + } + } + + public void querySessionPool() throws IoTDBConnectionException, StatementExecutionException { + final SessionDataSetWrapper sessionDataSetWrapper = sessionPool.executeQueryStatement("show databases"); + while (sessionDataSetWrapper.hasNext()) { + final RowRecord rowRecord = sessionDataSetWrapper.next(); + final List fields = rowRecord.getFields(); + for (Field field : fields) { + System.out.print(field.getStringValue()); + } + System.out.println(); + } + } +} diff --git a/examples/iotdb-spring-boot-start/src/main/resources/application.properties b/examples/iotdb-spring-boot-start/src/main/resources/application.properties new file mode 100644 index 0000000..baad5b5 --- /dev/null +++ b/examples/iotdb-spring-boot-start/src/main/resources/application.properties @@ -0,0 +1,8 @@ +spring.application.name=iotdb-spring-boot-start + +iotdb.session.url=172.20.31.56:6668 +iotdb.session.password=root +iotdb.session.username=root +iotdb.session.database=wind +iotdb.session.sql-dialect=table +iotdb.session.max-size=10 \ No newline at end of file diff --git a/examples/iotdb-spring-boot-start/src/test/java/org/apache/iotdb/iotdbspringbootstartexample/IotdbSpringBootStartApplicationTests.java b/examples/iotdb-spring-boot-start/src/test/java/org/apache/iotdb/iotdbspringbootstartexample/IotdbSpringBootStartApplicationTests.java new file mode 100644 index 0000000..32e5d89 --- /dev/null +++ b/examples/iotdb-spring-boot-start/src/test/java/org/apache/iotdb/iotdbspringbootstartexample/IotdbSpringBootStartApplicationTests.java @@ -0,0 +1,22 @@ +package org.apache.iotdb.iotdbspringbootstartexample; + +import org.apache.iotdb.iotdbspringbootstartexample.service.IoTDBService; +import org.apache.iotdb.rpc.IoTDBConnectionException; +import org.apache.iotdb.rpc.StatementExecutionException; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; + +@SpringBootTest +class SpringBootIotdbApplicationTests { + + @Autowired + private IoTDBService iotdbService; + + @Test + void contextLoads() throws IoTDBConnectionException, StatementExecutionException { + iotdbService.querySessionPool(); + iotdbService.queryTableSessionPool(); + } + +} \ No newline at end of file diff --git a/examples/mybatis-generator/pom.xml b/examples/mybatis-generator/pom.xml index 8ff251d..83e2c72 100644 --- a/examples/mybatis-generator/pom.xml +++ b/examples/mybatis-generator/pom.xml @@ -19,9 +19,7 @@ under the License. --> - + 4.0.0 org.apache.iotdb @@ -29,10 +27,8 @@ 2.0.2-SNAPSHOT ../../pom.xml - mybatis-generator-example 2.0.2-SNAPHOT - 21 21 @@ -59,5 +55,4 @@ - - \ No newline at end of file + diff --git a/examples/mybatis-generator/src/main/resources/generatorConfig.xml b/examples/mybatis-generator/src/main/resources/generatorConfig.xml index 75d62e6..530ff4f 100644 --- a/examples/mybatis-generator/src/main/resources/generatorConfig.xml +++ b/examples/mybatis-generator/src/main/resources/generatorConfig.xml @@ -27,7 +27,7 @@ - + @@ -42,14 +42,14 @@ - + - + - + diff --git a/examples/mybatisplus-generator/pom.xml b/examples/mybatisplus-generator/pom.xml index 0141852..1e0b278 100644 --- a/examples/mybatisplus-generator/pom.xml +++ b/examples/mybatisplus-generator/pom.xml @@ -19,9 +19,7 @@ under the License. --> - + 4.0.0 org.apache.iotdb @@ -32,14 +30,12 @@ org.apache.iotdb mybatisplus-generator-example 2.0.2-SNAPHOT - 3.5.10 21 21 UTF-8 - com.baomidou @@ -52,14 +48,12 @@ mybatis-plus-generator 3.5.10 - org.apache.velocity velocity-engine-core 2.0 - org.apache.iotdb iotdb-jdbc @@ -91,4 +85,4 @@ 1.18.36 - \ No newline at end of file + diff --git a/iotdb-spring-boot-starter/README.md b/iotdb-spring-boot-starter/README.md new file mode 100644 index 0000000..b066dfc --- /dev/null +++ b/iotdb-spring-boot-starter/README.md @@ -0,0 +1,33 @@ +# mybatis-generator-plugin + +* After 'clone' the project, execute 'mvn clean install' or 'mvn clean deploy' locally ('deploy' needs to modify 'distributionManagement' in 'pom'). This step is not necessary as it has already been uploaded to the Maven central repository + +```java + + + + org.mybatis.generator + mybatis-generator-maven-plugin + 1.4.2 + + + org.apache.iotdb + iotdb-mybatis-generator + 1.3.2-SNAPSHOT + + + + true + true + src/main/resources/generatorConfig.xml + + + + +``` + +* The location of the ` configurationFile ` configuration ` generatorConfig. xml ` file can be found in the ` src/main/resources ` template of this project for reference` Copy its content and place it in the corresponding location + +* Modify the content you want to use in 'generatorConfig. xml', mainly by:` jdbcConnection`、`javaModelGenerator`、`sqlMapGenerator`、`javaClientGenerator`、`table` + +* Execute the command at the location of the 'pom' in the project:` Mvn mybatis generator: generate generates corresponding Java classes and mapper files \ No newline at end of file diff --git a/iotdb-spring-boot-starter/pom.xml b/iotdb-spring-boot-starter/pom.xml new file mode 100644 index 0000000..3a2e4d3 --- /dev/null +++ b/iotdb-spring-boot-starter/pom.xml @@ -0,0 +1,44 @@ + + + 4.0.0 + + org.springframework.boot + spring-boot-starter-parent + 3.4.3 + + + + org.apache.iotdb + iotdb-spring-boot-starter + 2.0.2-SNAPSHOT + + 21 + 21 + UTF-8 + 3.1.4 + + + + org.apache.iotdb + iotdb-session + 2.0.1-beta + + + org.springframework.boot + spring-boot-starter + ${spring-boot3.version} + + + + org.springframework.boot + spring-boot-autoconfigure + ${spring-boot3.version} + + + + org.springframework.boot + spring-boot-configuration-processor + ${spring-boot3.version} + + + diff --git a/iotdb-spring-boot-starter/src/main/java/org/apache/iotdb/config/IoTDBSessionProperties.java b/iotdb-spring-boot-starter/src/main/java/org/apache/iotdb/config/IoTDBSessionProperties.java new file mode 100644 index 0000000..d20d000 --- /dev/null +++ b/iotdb-spring-boot-starter/src/main/java/org/apache/iotdb/config/IoTDBSessionProperties.java @@ -0,0 +1,158 @@ +package org.apache.iotdb.config; + + +import org.springframework.boot.context.properties.ConfigurationProperties; + +@ConfigurationProperties(prefix = "iotdb.session") +public class IoTDBSessionProperties { + private String url; + private String username; + private String password; + private String database; + private String sql_dialect = "table"; + private Integer max_size = 5; + private Integer fetch_size = 1024; + private long query_timeout_in_ms = 60000L; + private boolean enable_auto_fetch = true; + private boolean use_ssl = false; + private int max_retry_count = 60; + private long wait_to_get_session_timeout_in_msit = 60000L; + private boolean enable_compression = false; + private long retry_interval_in_ms = 500L; + + public String getUrl() { + return url; + } + + public void setUrl(String url) { + this.url = url; + } + + public String getUsername() { + return username; + } + + public void setUsername(String username) { + this.username = username; + } + + public String getPassword() { + return password; + } + + public void setPassword(String password) { + this.password = password; + } + + public String getDatabase() { + return database; + } + + public void setDatabase(String database) { + this.database = database; + } + + public String getSql_dialect() { + return sql_dialect; + } + + public void setSql_dialect(String sql_dialect) { + this.sql_dialect = sql_dialect; + } + + public Integer getMax_size() { + return max_size; + } + + public void setMax_size(Integer max_size) { + this.max_size = max_size; + } + + public Integer getFetch_size() { + return fetch_size; + } + + public void setFetch_size(Integer fetch_size) { + this.fetch_size = fetch_size; + } + + public Long getQuery_timeout_in_ms() { + return query_timeout_in_ms; + } + + public void setQuery_timeout_in_ms(Long query_timeout_in_ms) { + this.query_timeout_in_ms = query_timeout_in_ms; + } + + public Boolean getEnable_auto_fetch() { + return enable_auto_fetch; + } + + public void setEnable_auto_fetch(Boolean enable_auto_fetch) { + this.enable_auto_fetch = enable_auto_fetch; + } + + public Boolean getUse_ssl() { + return use_ssl; + } + + public void setUse_ssl(Boolean use_ssl) { + this.use_ssl = use_ssl; + } + + public Integer getMax_retry_count() { + return max_retry_count; + } + + public void setMax_retry_count(Integer max_retry_count) { + this.max_retry_count = max_retry_count; + } + + public void setQuery_timeout_in_ms(long query_timeout_in_ms) { + this.query_timeout_in_ms = query_timeout_in_ms; + } + + public boolean isEnable_auto_fetch() { + return enable_auto_fetch; + } + + public void setEnable_auto_fetch(boolean enable_auto_fetch) { + this.enable_auto_fetch = enable_auto_fetch; + } + + public boolean isUse_ssl() { + return use_ssl; + } + + public void setUse_ssl(boolean use_ssl) { + this.use_ssl = use_ssl; + } + + public void setMax_retry_count(int max_retry_count) { + this.max_retry_count = max_retry_count; + } + + public long getWait_to_get_session_timeout_in_msit() { + return wait_to_get_session_timeout_in_msit; + } + + public void setWait_to_get_session_timeout_in_msit(long wait_to_get_session_timeout_in_msit) { + this.wait_to_get_session_timeout_in_msit = wait_to_get_session_timeout_in_msit; + } + + public boolean isEnable_compression() { + return enable_compression; + } + + public void setEnable_compression(boolean enable_compression) { + this.enable_compression = enable_compression; + } + + public long getRetry_interval_in_ms() { + return retry_interval_in_ms; + } + + public void setRetry_interval_in_ms(long retry_interval_in_ms) { + this.retry_interval_in_ms = retry_interval_in_ms; + } +} \ No newline at end of file diff --git a/iotdb-spring-boot-starter/src/main/java/org/apache/iotdb/session/IoTDBSessionPool.java b/iotdb-spring-boot-starter/src/main/java/org/apache/iotdb/session/IoTDBSessionPool.java new file mode 100644 index 0000000..d6ae32b --- /dev/null +++ b/iotdb-spring-boot-starter/src/main/java/org/apache/iotdb/session/IoTDBSessionPool.java @@ -0,0 +1,77 @@ +package org.apache.iotdb.session; + +import org.apache.iotdb.config.IoTDBSessionProperties; +import org.apache.iotdb.isession.pool.ITableSessionPool; +import org.apache.iotdb.session.pool.SessionPool; +import org.apache.iotdb.session.pool.TableSessionPoolBuilder; +import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; +import org.springframework.boot.context.properties.EnableConfigurationProperties; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +import java.util.Arrays; + +@Configuration +@ConditionalOnClass({IoTDBSessionProperties.class}) // 确保相关类存在 +@EnableConfigurationProperties(IoTDBSessionProperties.class) +public class IoTDBSessionPool { + + private final IoTDBSessionProperties properties; + private ITableSessionPool tableSessionPool; + private SessionPool treeSessionPool; + + public IoTDBSessionPool(IoTDBSessionProperties properties) { + this.properties = properties; + } + + @Bean + public ITableSessionPool tableSessionPool() { + if(tableSessionPool == null) { + synchronized (IoTDBSessionPool.class) { + if(tableSessionPool == null) { + tableSessionPool = new TableSessionPoolBuilder(). + nodeUrls(Arrays.asList(properties.getUrl().split(";"))). + user(properties.getUsername()). + password(properties.getPassword()). + database(properties.getDatabase()). + maxSize(properties.getMax_size()). + fetchSize(properties.getFetch_size()). + enableAutoFetch(properties.getEnable_auto_fetch()). + useSSL(properties.getUse_ssl()). + queryTimeoutInMs(properties.getQuery_timeout_in_ms()). + maxRetryCount(properties.getMax_retry_count()). + waitToGetSessionTimeoutInMs(properties.getQuery_timeout_in_ms()). + enableCompression(properties.isEnable_compression()). + retryIntervalInMs(properties.getRetry_interval_in_ms()). + build(); + } + } + } + return tableSessionPool; + } + + @Bean + public SessionPool treeSessionPool() { + if(treeSessionPool == null) { + synchronized (IoTDBSessionPool.class) { + if(treeSessionPool == null) { + treeSessionPool = new SessionPool.Builder(). + nodeUrls(Arrays.asList(properties.getUrl().split(";"))). + user(properties.getUsername()). + password(properties.getPassword()). + maxSize(properties.getMax_size()). + fetchSize(properties.getFetch_size()). + enableAutoFetch(properties.getEnable_auto_fetch()). + useSSL(properties.getUse_ssl()). + queryTimeoutInMs(properties.getQuery_timeout_in_ms()). + maxRetryCount(properties.getMax_retry_count()). + waitToGetSessionTimeoutInMs(properties.getQuery_timeout_in_ms()). + enableCompression(properties.isEnable_compression()). + retryIntervalInMs(properties.getRetry_interval_in_ms()). + build(); + } + } + } + return treeSessionPool; + } +} diff --git a/iotdb-spring-boot-starter/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports b/iotdb-spring-boot-starter/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports new file mode 100644 index 0000000..16c6ac0 --- /dev/null +++ b/iotdb-spring-boot-starter/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports @@ -0,0 +1 @@ +org.apache.iotdb.session.IoTDBSessionPool \ No newline at end of file diff --git a/mybatis-generator/README.md b/mybatis-generator/README.md index 2bfe68e..8f03327 100644 --- a/mybatis-generator/README.md +++ b/mybatis-generator/README.md @@ -4,32 +4,40 @@ * Add the following configuration to the 'pom' file of the project to be generated: -```java - - - - org.mybatis.generator - mybatis-generator-maven-plugin - 1.4.2 - - - org.apache.iotdb - iotdb-mybatis-generator - 1.3.2-SNAPSHOT - - - - true - true - src/main/resources/generatorConfig.xml - - - - +``` + + + org.springframework.boot + spring-boot-starter + + + org.springframework.boot + spring-boot-starter-test + test + + + org.apache.iotdb + iotdb-spring-boot-starter + 2.0.2-SNAPSHOT + + ``` -* The location of the ` configurationFile ` configuration ` generatorConfig. xml ` file can be found in the ` src/main/resources ` template of this project for reference` Copy its content and place it in the corresponding location - -* Modify the content you want to use in 'generatorConfig. xml', mainly by:` jdbcConnection`、`javaModelGenerator`、`sqlMapGenerator`、`javaClientGenerator`、`table` +* Use The target Bean with @Autowired like: +```java + @Autowired + private ITableSessionPool ioTDBSessionPool; -* Execute the command at the location of the 'pom' in the project:` Mvn mybatis generator: generate generates corresponding Java classes and mapper files \ No newline at end of file + public void queryTableSessionPool() throws IoTDBConnectionException, StatementExecutionException { + ITableSession tableSession = ioTDBSessionPool.getSession(); + final SessionDataSet sessionDataSet = tableSession.executeQueryStatement("select * from power_data_set limit 10"); + while (sessionDataSet.hasNext()) { + final RowRecord rowRecord = sessionDataSet.next(); + final List fields = rowRecord.getFields(); + for (Field field : fields) { + System.out.print(field.getStringValue()); + } + System.out.println(); + } + } +``` \ No newline at end of file From c7308a059e274fa978f1565084ed81eb449edf8a Mon Sep 17 00:00:00 2001 From: 2b3c511 Date: Mon, 17 Mar 2025 14:11:14 +0800 Subject: [PATCH 07/14] rat --- .../IotdbSpringBootStartApplication.java | 17 +++++++++++++ .../service/IoTDBService.java | 17 +++++++++++++ .../src/main/resources/application.properties | 18 +++++++++++++ iotdb-spring-boot-starter/README.md | 25 +++++++++++++++++-- .../iotdb/config/IoTDBSessionProperties.java | 18 ++++++++++++- .../iotdb/session/IoTDBSessionPool.java | 17 +++++++++++++ ...ot.autoconfigure.AutoConfiguration.imports | 20 ++++++++++++++- 7 files changed, 128 insertions(+), 4 deletions(-) diff --git a/examples/iotdb-spring-boot-start/src/main/java/org/apache/iotdb/iotdbspringbootstartexample/IotdbSpringBootStartApplication.java b/examples/iotdb-spring-boot-start/src/main/java/org/apache/iotdb/iotdbspringbootstartexample/IotdbSpringBootStartApplication.java index 185e97f..8cee140 100644 --- a/examples/iotdb-spring-boot-start/src/main/java/org/apache/iotdb/iotdbspringbootstartexample/IotdbSpringBootStartApplication.java +++ b/examples/iotdb-spring-boot-start/src/main/java/org/apache/iotdb/iotdbspringbootstartexample/IotdbSpringBootStartApplication.java @@ -1,3 +1,20 @@ +/* + * 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.iotdb.iotdbspringbootstartexample; import org.springframework.boot.SpringApplication; diff --git a/examples/iotdb-spring-boot-start/src/main/java/org/apache/iotdb/iotdbspringbootstartexample/service/IoTDBService.java b/examples/iotdb-spring-boot-start/src/main/java/org/apache/iotdb/iotdbspringbootstartexample/service/IoTDBService.java index 8b7e703..95c479b 100644 --- a/examples/iotdb-spring-boot-start/src/main/java/org/apache/iotdb/iotdbspringbootstartexample/service/IoTDBService.java +++ b/examples/iotdb-spring-boot-start/src/main/java/org/apache/iotdb/iotdbspringbootstartexample/service/IoTDBService.java @@ -1,3 +1,20 @@ +/* + * 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.iotdb.iotdbspringbootstartexample.service; import org.apache.iotdb.isession.ITableSession; diff --git a/examples/iotdb-spring-boot-start/src/main/resources/application.properties b/examples/iotdb-spring-boot-start/src/main/resources/application.properties index baad5b5..98953f1 100644 --- a/examples/iotdb-spring-boot-start/src/main/resources/application.properties +++ b/examples/iotdb-spring-boot-start/src/main/resources/application.properties @@ -1,3 +1,21 @@ +# 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. +# + spring.application.name=iotdb-spring-boot-start iotdb.session.url=172.20.31.56:6668 diff --git a/iotdb-spring-boot-starter/README.md b/iotdb-spring-boot-starter/README.md index b066dfc..0cd4447 100644 --- a/iotdb-spring-boot-starter/README.md +++ b/iotdb-spring-boot-starter/README.md @@ -1,6 +1,27 @@ -# mybatis-generator-plugin + + +# iotdb-spring-boot-starter + +* After 'clone' the project, execute 'mvn clean install'. This step is not necessary as it has already been uploaded to the Maven central repository ```java diff --git a/iotdb-spring-boot-starter/src/main/java/org/apache/iotdb/config/IoTDBSessionProperties.java b/iotdb-spring-boot-starter/src/main/java/org/apache/iotdb/config/IoTDBSessionProperties.java index d20d000..b61ee8d 100644 --- a/iotdb-spring-boot-starter/src/main/java/org/apache/iotdb/config/IoTDBSessionProperties.java +++ b/iotdb-spring-boot-starter/src/main/java/org/apache/iotdb/config/IoTDBSessionProperties.java @@ -1,5 +1,21 @@ -package org.apache.iotdb.config; +/* + * 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.iotdb.config; import org.springframework.boot.context.properties.ConfigurationProperties; diff --git a/iotdb-spring-boot-starter/src/main/java/org/apache/iotdb/session/IoTDBSessionPool.java b/iotdb-spring-boot-starter/src/main/java/org/apache/iotdb/session/IoTDBSessionPool.java index d6ae32b..89f7143 100644 --- a/iotdb-spring-boot-starter/src/main/java/org/apache/iotdb/session/IoTDBSessionPool.java +++ b/iotdb-spring-boot-starter/src/main/java/org/apache/iotdb/session/IoTDBSessionPool.java @@ -1,3 +1,20 @@ +/* + * 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.iotdb.session; import org.apache.iotdb.config.IoTDBSessionProperties; diff --git a/iotdb-spring-boot-starter/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports b/iotdb-spring-boot-starter/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports index 16c6ac0..5195201 100644 --- a/iotdb-spring-boot-starter/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports +++ b/iotdb-spring-boot-starter/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports @@ -1 +1,19 @@ -org.apache.iotdb.session.IoTDBSessionPool \ No newline at end of file +# 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. +# + +org.apache.iotdb.session.IoTDBSessionPool \ No newline at end of file From 6d7966a75b8e313efaff528d18b577c07d1b2175 Mon Sep 17 00:00:00 2001 From: 2b3c511 Date: Mon, 17 Mar 2025 14:25:36 +0800 Subject: [PATCH 08/14] rat +1 --- examples/iotdb-spring-boot-start/pom.xml | 29 +++++++++++++++---- .../IotdbSpringBootStartApplicationTests.java | 17 +++++++++++ iotdb-spring-boot-starter/pom.xml | 20 +++++++++++++ 3 files changed, 60 insertions(+), 6 deletions(-) diff --git a/examples/iotdb-spring-boot-start/pom.xml b/examples/iotdb-spring-boot-start/pom.xml index a01eed7..919f52c 100644 --- a/examples/iotdb-spring-boot-start/pom.xml +++ b/examples/iotdb-spring-boot-start/pom.xml @@ -1,12 +1,32 @@ - + + 4.0.0 org.springframework.boot spring-boot-starter-parent 3.4.3 - + + org.apache.iotdb iotdb-spring-boot-start-example @@ -21,7 +41,6 @@ org.springframework.boot spring-boot-starter - org.springframework.boot spring-boot-starter-test @@ -33,7 +52,6 @@ 2.0.2-SNAPSHOT - @@ -42,5 +60,4 @@ - diff --git a/examples/iotdb-spring-boot-start/src/test/java/org/apache/iotdb/iotdbspringbootstartexample/IotdbSpringBootStartApplicationTests.java b/examples/iotdb-spring-boot-start/src/test/java/org/apache/iotdb/iotdbspringbootstartexample/IotdbSpringBootStartApplicationTests.java index 32e5d89..e3b9d71 100644 --- a/examples/iotdb-spring-boot-start/src/test/java/org/apache/iotdb/iotdbspringbootstartexample/IotdbSpringBootStartApplicationTests.java +++ b/examples/iotdb-spring-boot-start/src/test/java/org/apache/iotdb/iotdbspringbootstartexample/IotdbSpringBootStartApplicationTests.java @@ -1,3 +1,20 @@ +/* + * 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.iotdb.iotdbspringbootstartexample; import org.apache.iotdb.iotdbspringbootstartexample.service.IoTDBService; diff --git a/iotdb-spring-boot-starter/pom.xml b/iotdb-spring-boot-starter/pom.xml index 3a2e4d3..e58b982 100644 --- a/iotdb-spring-boot-starter/pom.xml +++ b/iotdb-spring-boot-starter/pom.xml @@ -1,4 +1,24 @@ + 4.0.0 From 03b0d25109e5e2751df96e0e386ca29a815fca77 Mon Sep 17 00:00:00 2001 From: 2b3c511 Date: Mon, 17 Mar 2025 14:46:06 +0800 Subject: [PATCH 09/14] rat +1 --- mybatis-generator/README-zh.md | 20 ++++++++++++++++++++ mybatis-generator/README.md | 20 ++++++++++++++++++++ 2 files changed, 40 insertions(+) diff --git a/mybatis-generator/README-zh.md b/mybatis-generator/README-zh.md index a921877..57d8a9c 100644 --- a/mybatis-generator/README-zh.md +++ b/mybatis-generator/README-zh.md @@ -1,3 +1,23 @@ + # mybatis-generator-plugin * 把该项目 `clone` 下来之后,在本地执行 `mvn clean install` 或者 `mvn clean deploy` (`deploy` 需要修改 `pom` 中的 `distributionManagement`)【已经上传 `Maven` 中央仓库,所以此步骤不在需要】 diff --git a/mybatis-generator/README.md b/mybatis-generator/README.md index 8f03327..cd9c31b 100644 --- a/mybatis-generator/README.md +++ b/mybatis-generator/README.md @@ -1,3 +1,23 @@ + # mybatis-generator-plugin * After 'clone' the project, execute 'mvn clean install' or 'mvn clean deploy' locally ('deploy' needs to modify 'distributionManagement' in 'pom'). This step is not necessary as it has already been uploaded to the Maven central repository From 5931536526c658754bf13b4e9d47ffee505dd867 Mon Sep 17 00:00:00 2001 From: 2b3c511 Date: Mon, 17 Mar 2025 14:52:52 +0800 Subject: [PATCH 10/14] remove chinese comment --- examples/mybatisplus-generator/pom.xml | 2 -- iotdb-spring-boot-starter/pom.xml | 2 -- .../main/java/org/apache/iotdb/session/IoTDBSessionPool.java | 2 +- 3 files changed, 1 insertion(+), 5 deletions(-) diff --git a/examples/mybatisplus-generator/pom.xml b/examples/mybatisplus-generator/pom.xml index 1e0b278..a24d947 100644 --- a/examples/mybatisplus-generator/pom.xml +++ b/examples/mybatisplus-generator/pom.xml @@ -42,13 +42,11 @@ mybatis-plus-spring-boot3-starter ${mybatisplus.version} - com.baomidou mybatis-plus-generator 3.5.10 - org.apache.velocity velocity-engine-core diff --git a/iotdb-spring-boot-starter/pom.xml b/iotdb-spring-boot-starter/pom.xml index e58b982..eb1607a 100644 --- a/iotdb-spring-boot-starter/pom.xml +++ b/iotdb-spring-boot-starter/pom.xml @@ -48,13 +48,11 @@ spring-boot-starter ${spring-boot3.version} - org.springframework.boot spring-boot-autoconfigure ${spring-boot3.version} - org.springframework.boot spring-boot-configuration-processor diff --git a/iotdb-spring-boot-starter/src/main/java/org/apache/iotdb/session/IoTDBSessionPool.java b/iotdb-spring-boot-starter/src/main/java/org/apache/iotdb/session/IoTDBSessionPool.java index 89f7143..0f67f97 100644 --- a/iotdb-spring-boot-starter/src/main/java/org/apache/iotdb/session/IoTDBSessionPool.java +++ b/iotdb-spring-boot-starter/src/main/java/org/apache/iotdb/session/IoTDBSessionPool.java @@ -29,7 +29,7 @@ import java.util.Arrays; @Configuration -@ConditionalOnClass({IoTDBSessionProperties.class}) // 确保相关类存在 +@ConditionalOnClass({IoTDBSessionProperties.class}) @EnableConfigurationProperties(IoTDBSessionProperties.class) public class IoTDBSessionPool { From 14dd2636c1ad0f7341cdf83e8daf73b3d8f93dfc Mon Sep 17 00:00:00 2001 From: 2b3c511 Date: Mon, 17 Mar 2025 15:06:43 +0800 Subject: [PATCH 11/14] update README.md --- examples/mybatisplus-generator/readme.md | 2 +- iotdb-spring-boot-starter/README.md | 67 +++++++++++++---------- mybatis-generator/README-zh.md | 2 +- mybatis-generator/README.md | 68 +++++++++++------------- 4 files changed, 70 insertions(+), 69 deletions(-) diff --git a/examples/mybatisplus-generator/readme.md b/examples/mybatisplus-generator/readme.md index 4daf1fd..3d55126 100644 --- a/examples/mybatisplus-generator/readme.md +++ b/examples/mybatisplus-generator/readme.md @@ -25,7 +25,7 @@ ### Version usage - IoTDB: 2.0.2 + IoTDB: 2.0.1-beta mybatisPlus: 3.5.10 ### 1. Install IoTDB diff --git a/iotdb-spring-boot-starter/README.md b/iotdb-spring-boot-starter/README.md index 0cd4447..cd9c31b 100644 --- a/iotdb-spring-boot-starter/README.md +++ b/iotdb-spring-boot-starter/README.md @@ -18,37 +18,46 @@ under the License. --> +# mybatis-generator-plugin -# iotdb-spring-boot-starter +* After 'clone' the project, execute 'mvn clean install' or 'mvn clean deploy' locally ('deploy' needs to modify 'distributionManagement' in 'pom'). This step is not necessary as it has already been uploaded to the Maven central repository -* After 'clone' the project, execute 'mvn clean install'. This step is not necessary as it has already been uploaded to the Maven central repository +* Add the following configuration to the 'pom' file of the project to be generated: -```java - - - - org.mybatis.generator - mybatis-generator-maven-plugin - 1.4.2 - - - org.apache.iotdb - iotdb-mybatis-generator - 1.3.2-SNAPSHOT - - - - true - true - src/main/resources/generatorConfig.xml - - - - +``` + + + org.springframework.boot + spring-boot-starter + + + org.springframework.boot + spring-boot-starter-test + test + + + org.apache.iotdb + iotdb-spring-boot-starter + 2.0.2-SNAPSHOT + + ``` -* The location of the ` configurationFile ` configuration ` generatorConfig. xml ` file can be found in the ` src/main/resources ` template of this project for reference` Copy its content and place it in the corresponding location - -* Modify the content you want to use in 'generatorConfig. xml', mainly by:` jdbcConnection`、`javaModelGenerator`、`sqlMapGenerator`、`javaClientGenerator`、`table` - -* Execute the command at the location of the 'pom' in the project:` Mvn mybatis generator: generate generates corresponding Java classes and mapper files \ No newline at end of file +* Use The target Bean with @Autowired like: +```java + @Autowired + private ITableSessionPool ioTDBSessionPool; + + public void queryTableSessionPool() throws IoTDBConnectionException, StatementExecutionException { + ITableSession tableSession = ioTDBSessionPool.getSession(); + final SessionDataSet sessionDataSet = tableSession.executeQueryStatement("select * from power_data_set limit 10"); + while (sessionDataSet.hasNext()) { + final RowRecord rowRecord = sessionDataSet.next(); + final List fields = rowRecord.getFields(); + for (Field field : fields) { + System.out.print(field.getStringValue()); + } + System.out.println(); + } + } +``` \ No newline at end of file diff --git a/mybatis-generator/README-zh.md b/mybatis-generator/README-zh.md index 57d8a9c..94eb875 100644 --- a/mybatis-generator/README-zh.md +++ b/mybatis-generator/README-zh.md @@ -35,7 +35,7 @@ org.apache.iotdb mybatis-generator-plugin - 1.3.2-SNAPSHOT + 2.0.2-SNAPSHOT diff --git a/mybatis-generator/README.md b/mybatis-generator/README.md index cd9c31b..e8f848f 100644 --- a/mybatis-generator/README.md +++ b/mybatis-generator/README.md @@ -1,3 +1,4 @@ + -# mybatis-generator-plugin -* After 'clone' the project, execute 'mvn clean install' or 'mvn clean deploy' locally ('deploy' needs to modify 'distributionManagement' in 'pom'). This step is not necessary as it has already been uploaded to the Maven central repository +# iotdb-spring-boot-starter -* Add the following configuration to the 'pom' file of the project to be generated: +* After 'clone' the project, execute 'mvn clean install'. This step is not necessary as it has already been uploaded to the Maven central repository -``` - - - org.springframework.boot - spring-boot-starter - - - org.springframework.boot - spring-boot-starter-test - test - - - org.apache.iotdb - iotdb-spring-boot-starter - 2.0.2-SNAPSHOT - - +```java + + + + org.mybatis.generator + mybatis-generator-maven-plugin + 1.4.2 + + + org.apache.iotdb + iotdb-mybatis-generator + 2.0.2-SNAPSHOT + + + + true + true + src/main/resources/generatorConfig.xml + + + + ``` -* Use The target Bean with @Autowired like: -```java - @Autowired - private ITableSessionPool ioTDBSessionPool; - - public void queryTableSessionPool() throws IoTDBConnectionException, StatementExecutionException { - ITableSession tableSession = ioTDBSessionPool.getSession(); - final SessionDataSet sessionDataSet = tableSession.executeQueryStatement("select * from power_data_set limit 10"); - while (sessionDataSet.hasNext()) { - final RowRecord rowRecord = sessionDataSet.next(); - final List fields = rowRecord.getFields(); - for (Field field : fields) { - System.out.print(field.getStringValue()); - } - System.out.println(); - } - } -``` \ No newline at end of file +* The location of the ` configurationFile ` configuration ` generatorConfig. xml ` file can be found in the ` src/main/resources ` template of this project for reference` Copy its content and place it in the corresponding location + +* Modify the content you want to use in 'generatorConfig. xml', mainly by:` jdbcConnection`、`javaModelGenerator`、`sqlMapGenerator`、`javaClientGenerator`、`table` + +* Execute the command at the location of the 'pom' in the project:` Mvn mybatis generator: generate generates corresponding Java classes and mapper files \ No newline at end of file From c7d983269a950e7834945dfb36c5b3d18664c850 Mon Sep 17 00:00:00 2001 From: 2b3c511 Date: Mon, 17 Mar 2025 15:19:18 +0800 Subject: [PATCH 12/14] update example table name --- examples/iotdb-spring-boot-start/readme.md | 24 +++++++++---------- .../service/IoTDBService.java | 3 ++- examples/mybatis-generator/readme.md | 24 +++++++++---------- examples/mybatisplus-generator/readme.md | 24 +++++++++---------- iotdb-spring-boot-starter/README.md | 6 ++--- .../iotdb/session/IoTDBSessionPool.java | 5 ++-- 6 files changed, 44 insertions(+), 42 deletions(-) diff --git a/examples/iotdb-spring-boot-start/readme.md b/examples/iotdb-spring-boot-start/readme.md index 4bf3867..ba43418 100644 --- a/examples/iotdb-spring-boot-start/readme.md +++ b/examples/iotdb-spring-boot-start/readme.md @@ -43,18 +43,18 @@ ``` Then we need to create a database 'table' ``` - create table power_data_set( - "device_id" STRING TAG, - "deivce_name" STRING TAG, - "type" INT32 FIELD, - "name" DOUBLE FIELD, - "server_url_master" FLOAT FIELD, - "server_url_slave" BOOLEAN FIELD, - "prometheus_url_master" STRING FIELD, - "prometheus_url_slave" BLOB FIELD, - "username" STRING ATTRIBUTE, - "create_time" DATE FIELD, - "update_time" DATE FIELD); + CREATE TABLE table1 ( + time TIMESTAMP TIME, + region STRING TAG, + plant_id STRING TAG, + device_id STRING TAG, + model_id STRING ATTRIBUTE, + maintenance STRING ATTRIBUTE, + temperature FLOAT FIELD, + humidity FLOAT FIELD, + status Boolean FIELD, + arrival_time TIMESTAMP FIELD + ) WITH (TTL=31536000000); ``` ### 3. Build Dependencies with Maven in your Project diff --git a/examples/iotdb-spring-boot-start/src/main/java/org/apache/iotdb/iotdbspringbootstartexample/service/IoTDBService.java b/examples/iotdb-spring-boot-start/src/main/java/org/apache/iotdb/iotdbspringbootstartexample/service/IoTDBService.java index 95c479b..c9a5163 100644 --- a/examples/iotdb-spring-boot-start/src/main/java/org/apache/iotdb/iotdbspringbootstartexample/service/IoTDBService.java +++ b/examples/iotdb-spring-boot-start/src/main/java/org/apache/iotdb/iotdbspringbootstartexample/service/IoTDBService.java @@ -19,6 +19,7 @@ import org.apache.iotdb.isession.ITableSession; import org.apache.iotdb.isession.SessionDataSet; +import org.apache.iotdb.isession.pool.ISessionPool; import org.apache.iotdb.isession.pool.ITableSessionPool; import org.apache.iotdb.isession.pool.SessionDataSetWrapper; import org.apache.iotdb.rpc.IoTDBConnectionException; @@ -38,7 +39,7 @@ public class IoTDBService { private ITableSessionPool ioTDBSessionPool; @Autowired - private SessionPool sessionPool; + private ISessionPool sessionPool; public void queryTableSessionPool() throws IoTDBConnectionException, StatementExecutionException { diff --git a/examples/mybatis-generator/readme.md b/examples/mybatis-generator/readme.md index bbc1c94..4c4e4fe 100644 --- a/examples/mybatis-generator/readme.md +++ b/examples/mybatis-generator/readme.md @@ -43,18 +43,18 @@ ``` Then we need to create a database 'table' ``` - create table mix3( - "device_id" STRING TAG, - "deivce_name" STRING TAG, - "type" INT32 FIELD, - "name" DOUBLE FIELD, - "server_url_master" FLOAT FIELD, - "server_url_slave" BOOLEAN FIELD, - "prometheus_url_master" STRING FIELD, - "prometheus_url_slave" BLOB FIELD, - "username" STRING ATTRIBUTE, - "create_time" DATE FIELD, - "update_time" DATE FIELD); + CREATE TABLE mix3 ( + time TIMESTAMP TIME, + region STRING TAG, + plant_id STRING TAG, + device_id STRING TAG, + model_id STRING ATTRIBUTE, + maintenance STRING ATTRIBUTE, + temperature FLOAT FIELD, + humidity FLOAT FIELD, + status Boolean FIELD, + arrival_time TIMESTAMP FIELD + ) WITH (TTL=31536000000); ``` ### 3. Build Dependencies with Maven in your Project diff --git a/examples/mybatisplus-generator/readme.md b/examples/mybatisplus-generator/readme.md index 3d55126..457b93f 100644 --- a/examples/mybatisplus-generator/readme.md +++ b/examples/mybatisplus-generator/readme.md @@ -43,18 +43,18 @@ ``` Then we need to create a database 'table' ``` - create table mix( - "device_id" STRING TAG, - "deivce_name" STRING TAG, - "type" INT32 FIELD, - "name" DOUBLE FIELD, - "server_url_master" FLOAT FIELD, - "server_url_slave" BOOLEAN FIELD, - "prometheus_url_master" STRING FIELD, - "prometheus_url_slave" BLOB FIELD, - "username" STRING ATTRIBUTE, - "create_time" DATE FIELD, - "update_time" DATE FIELD); + CREATE TABLE mix ( + time TIMESTAMP TIME, + region STRING TAG, + plant_id STRING TAG, + device_id STRING TAG, + model_id STRING ATTRIBUTE, + maintenance STRING ATTRIBUTE, + temperature FLOAT FIELD, + humidity FLOAT FIELD, + status Boolean FIELD, + arrival_time TIMESTAMP FIELD + ) WITH (TTL=31536000000); ``` ### 3. Build Dependencies with Maven in your Project diff --git a/iotdb-spring-boot-starter/README.md b/iotdb-spring-boot-starter/README.md index cd9c31b..20860e1 100644 --- a/iotdb-spring-boot-starter/README.md +++ b/iotdb-spring-boot-starter/README.md @@ -18,9 +18,9 @@ under the License. --> -# mybatis-generator-plugin +# iotdb-spring-boot-starter -* After 'clone' the project, execute 'mvn clean install' or 'mvn clean deploy' locally ('deploy' needs to modify 'distributionManagement' in 'pom'). This step is not necessary as it has already been uploaded to the Maven central repository +* After 'clone' the project, execute 'mvn clean install'. This step is not necessary as it has already been uploaded to the Maven central repository * Add the following configuration to the 'pom' file of the project to be generated: @@ -50,7 +50,7 @@ public void queryTableSessionPool() throws IoTDBConnectionException, StatementExecutionException { ITableSession tableSession = ioTDBSessionPool.getSession(); - final SessionDataSet sessionDataSet = tableSession.executeQueryStatement("select * from power_data_set limit 10"); + final SessionDataSet sessionDataSet = tableSession.executeQueryStatement("select * from table1 limit 10"); while (sessionDataSet.hasNext()) { final RowRecord rowRecord = sessionDataSet.next(); final List fields = rowRecord.getFields(); diff --git a/iotdb-spring-boot-starter/src/main/java/org/apache/iotdb/session/IoTDBSessionPool.java b/iotdb-spring-boot-starter/src/main/java/org/apache/iotdb/session/IoTDBSessionPool.java index 0f67f97..8914cdd 100644 --- a/iotdb-spring-boot-starter/src/main/java/org/apache/iotdb/session/IoTDBSessionPool.java +++ b/iotdb-spring-boot-starter/src/main/java/org/apache/iotdb/session/IoTDBSessionPool.java @@ -18,6 +18,7 @@ package org.apache.iotdb.session; import org.apache.iotdb.config.IoTDBSessionProperties; +import org.apache.iotdb.isession.pool.ISessionPool; import org.apache.iotdb.isession.pool.ITableSessionPool; import org.apache.iotdb.session.pool.SessionPool; import org.apache.iotdb.session.pool.TableSessionPoolBuilder; @@ -35,7 +36,7 @@ public class IoTDBSessionPool { private final IoTDBSessionProperties properties; private ITableSessionPool tableSessionPool; - private SessionPool treeSessionPool; + private ISessionPool treeSessionPool; public IoTDBSessionPool(IoTDBSessionProperties properties) { this.properties = properties; @@ -68,7 +69,7 @@ public ITableSessionPool tableSessionPool() { } @Bean - public SessionPool treeSessionPool() { + public ISessionPool treeSessionPool() { if(treeSessionPool == null) { synchronized (IoTDBSessionPool.class) { if(treeSessionPool == null) { From 744e0a5ef9e02871e672b9b41a9461148072964c Mon Sep 17 00:00:00 2001 From: 2b3c511 Date: Mon, 17 Mar 2025 15:30:00 +0800 Subject: [PATCH 13/14] alignment IoTDB --- connectors/grafana-plugin/README.md | 2 +- ...tApplication.java => IoTDBSpringBootStartApplication.java} | 4 ++-- ...icationTests.java => SpringBootIoTDBApplicationTests.java} | 2 +- examples/spark-table/README.md | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) rename examples/iotdb-spring-boot-start/src/main/java/org/apache/iotdb/iotdbspringbootstartexample/{IotdbSpringBootStartApplication.java => IoTDBSpringBootStartApplication.java} (90%) rename examples/iotdb-spring-boot-start/src/test/java/org/apache/iotdb/iotdbspringbootstartexample/{IotdbSpringBootStartApplicationTests.java => SpringBootIoTDBApplicationTests.java} (96%) diff --git a/connectors/grafana-plugin/README.md b/connectors/grafana-plugin/README.md index 4c52aa1..ce4f07b 100644 --- a/connectors/grafana-plugin/README.md +++ b/connectors/grafana-plugin/README.md @@ -26,7 +26,7 @@ Grafana is an open source volume metrics monitoring and visualization tool, whic We developed the Grafana-Plugin for IoTDB, using the IoTDB REST service to present time series data and providing many visualization methods for time series data. -Iotdb grafana plugin supports grafana version 9.3.0 and above +IoTDB grafana plugin supports grafana version 9.3.0 and above ### How to use Grafana-Plugin diff --git a/examples/iotdb-spring-boot-start/src/main/java/org/apache/iotdb/iotdbspringbootstartexample/IotdbSpringBootStartApplication.java b/examples/iotdb-spring-boot-start/src/main/java/org/apache/iotdb/iotdbspringbootstartexample/IoTDBSpringBootStartApplication.java similarity index 90% rename from examples/iotdb-spring-boot-start/src/main/java/org/apache/iotdb/iotdbspringbootstartexample/IotdbSpringBootStartApplication.java rename to examples/iotdb-spring-boot-start/src/main/java/org/apache/iotdb/iotdbspringbootstartexample/IoTDBSpringBootStartApplication.java index 8cee140..367fe3a 100644 --- a/examples/iotdb-spring-boot-start/src/main/java/org/apache/iotdb/iotdbspringbootstartexample/IotdbSpringBootStartApplication.java +++ b/examples/iotdb-spring-boot-start/src/main/java/org/apache/iotdb/iotdbspringbootstartexample/IoTDBSpringBootStartApplication.java @@ -21,10 +21,10 @@ import org.springframework.boot.autoconfigure.SpringBootApplication; @SpringBootApplication -public class IotdbSpringBootStartApplication { +public class IoTDBSpringBootStartApplication { public static void main(String[] args) { - SpringApplication.run(IotdbSpringBootStartApplication.class, args); + SpringApplication.run(IoTDBSpringBootStartApplication.class, args); } } diff --git a/examples/iotdb-spring-boot-start/src/test/java/org/apache/iotdb/iotdbspringbootstartexample/IotdbSpringBootStartApplicationTests.java b/examples/iotdb-spring-boot-start/src/test/java/org/apache/iotdb/iotdbspringbootstartexample/SpringBootIoTDBApplicationTests.java similarity index 96% rename from examples/iotdb-spring-boot-start/src/test/java/org/apache/iotdb/iotdbspringbootstartexample/IotdbSpringBootStartApplicationTests.java rename to examples/iotdb-spring-boot-start/src/test/java/org/apache/iotdb/iotdbspringbootstartexample/SpringBootIoTDBApplicationTests.java index e3b9d71..0e98959 100644 --- a/examples/iotdb-spring-boot-start/src/test/java/org/apache/iotdb/iotdbspringbootstartexample/IotdbSpringBootStartApplicationTests.java +++ b/examples/iotdb-spring-boot-start/src/test/java/org/apache/iotdb/iotdbspringbootstartexample/SpringBootIoTDBApplicationTests.java @@ -25,7 +25,7 @@ import org.springframework.boot.test.context.SpringBootTest; @SpringBootTest -class SpringBootIotdbApplicationTests { +public class SpringBootIoTDBApplicationTests { @Autowired private IoTDBService iotdbService; diff --git a/examples/spark-table/README.md b/examples/spark-table/README.md index b986b66..69b50ea 100644 --- a/examples/spark-table/README.md +++ b/examples/spark-table/README.md @@ -35,7 +35,7 @@ Import the IoTDB-Table-Spark-Connector dependency in your project. ## Options | Key | Default Value | Comment | Required | |----------------|----------------|-----------------------------------------------------------------------------------------------------------|----------| -| iotdb.database | -- | The database name of Iotdb, which needs to be a database that already exists in IoTDB | true | +| iotdb.database | -- | The database name of IoTDB, which needs to be a database that already exists in IoTDB | true | | iotdb.table | -- | The table name in IoTDB needs to be a table that already exists in IoTDB | true | | iotdb.username | root | the username to access IoTDB | false | | iotdb.password | root | the password to access IoTDB | false | From 9432b585d3ebf783c989bf706b9a27d73b877f18 Mon Sep 17 00:00:00 2001 From: 2b3c511 Date: Mon, 17 Mar 2025 16:03:29 +0800 Subject: [PATCH 14/14] add package in distribution/ --- distributions/pom.xml | 2 + .../assembly/iotdb-spring-boot-starter.xml | 41 ++++++++++++++ .../src/assembly/mybatis-generator-plugin.xml | 41 ++++++++++++++ mybatis-generator/pom.xml | 55 ------------------- 4 files changed, 84 insertions(+), 55 deletions(-) create mode 100644 distributions/src/assembly/iotdb-spring-boot-starter.xml create mode 100644 distributions/src/assembly/mybatis-generator-plugin.xml diff --git a/distributions/pom.xml b/distributions/pom.xml index a4f59d2..92e5be4 100644 --- a/distributions/pom.xml +++ b/distributions/pom.xml @@ -81,6 +81,8 @@ src/assembly/spark-connector.xml src/assembly/flink-sql-connector.xml + src/assembly/mybatis-generator-plugin.xml + src/assembly/iotdb-spring-boot-starter.xml apache-iotdb-${project.version} diff --git a/distributions/src/assembly/iotdb-spring-boot-starter.xml b/distributions/src/assembly/iotdb-spring-boot-starter.xml new file mode 100644 index 0000000..266a498 --- /dev/null +++ b/distributions/src/assembly/iotdb-spring-boot-starter.xml @@ -0,0 +1,41 @@ + + + + spring-boot-starter-bin + + dir + zip + + apache-iotdb-${project.version}-spring-boot-starter-bin + + + ${maven.multiModuleProjectDirectory}/iotdb-spring-boot-starter/target/ + ${file.separator} + + iotdb-spring-boot-starter-*.jar + + + + + common-files.xml + + diff --git a/distributions/src/assembly/mybatis-generator-plugin.xml b/distributions/src/assembly/mybatis-generator-plugin.xml new file mode 100644 index 0000000..271c084 --- /dev/null +++ b/distributions/src/assembly/mybatis-generator-plugin.xml @@ -0,0 +1,41 @@ + + + + mybatis-generator-plugin-bin + + dir + zip + + apache-iotdb-${project.version}-mybatis-generator-plugin-bin + + + ${maven.multiModuleProjectDirectory}/mybatis-generator/target/ + ${file.separator} + + mybatis-generator-plugin-*.jar + + + + + common-files.xml + + diff --git a/mybatis-generator/pom.xml b/mybatis-generator/pom.xml index 128d2fd..43ec0e4 100644 --- a/mybatis-generator/pom.xml +++ b/mybatis-generator/pom.xml @@ -24,59 +24,4 @@ 1.4.2 - - mybatis-generator-plugin - - - org.apache.maven.plugins - maven-surefire-plugin - 2.17 - - true - - - - maven-source-plugin - - - attach-sources - - jar-no-fork - - - - - - maven-javadoc-plugin - - - attach-javadocs - - jar - - - - - - maven-deploy-plugin - - - deploy - deploy - - deploy - - - - - - org.apache.maven.plugins - maven-compiler-plugin - - 1.8 - 1.8 - - - -