From f8d31b6d91e254c22d82b6bb3ae49d51af154afa Mon Sep 17 00:00:00 2001 From: Suomm <1474983351@qq.com> Date: Wed, 21 Jun 2023 22:02:16 +0800 Subject: [PATCH 01/15] =?UTF-8?q?style:=20=E6=B7=BB=E5=8A=A0=20package-inf?= =?UTF-8?q?o.java=20=E6=96=B9=E4=BE=BF=E5=BC=80=E5=8F=91=E8=80=85=E7=90=86?= =?UTF-8?q?=E8=A7=A3=E5=8C=85=E5=86=85=E5=AE=B9=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../codegen/config/package-info.java | 20 +++++++++++++++++++ .../codegen/constant/package-info.java | 20 +++++++++++++++++++ .../codegen/dialect/package-info.java | 20 +++++++++++++++++++ .../codegen/entity/package-info.java | 20 +++++++++++++++++++ .../codegen/generator/impl/package-info.java | 20 +++++++++++++++++++ .../codegen/generator/package-info.java | 20 +++++++++++++++++++ .../codegen/template/impl/package-info.java | 20 +++++++++++++++++++ .../codegen/template/package-info.java | 20 +++++++++++++++++++ 8 files changed, 160 insertions(+) create mode 100644 mybatis-flex-codegen/src/main/java/com/mybatisflex/codegen/config/package-info.java create mode 100644 mybatis-flex-codegen/src/main/java/com/mybatisflex/codegen/constant/package-info.java create mode 100644 mybatis-flex-codegen/src/main/java/com/mybatisflex/codegen/dialect/package-info.java create mode 100644 mybatis-flex-codegen/src/main/java/com/mybatisflex/codegen/entity/package-info.java create mode 100644 mybatis-flex-codegen/src/main/java/com/mybatisflex/codegen/generator/impl/package-info.java create mode 100644 mybatis-flex-codegen/src/main/java/com/mybatisflex/codegen/generator/package-info.java create mode 100644 mybatis-flex-codegen/src/main/java/com/mybatisflex/codegen/template/impl/package-info.java create mode 100644 mybatis-flex-codegen/src/main/java/com/mybatisflex/codegen/template/package-info.java diff --git a/mybatis-flex-codegen/src/main/java/com/mybatisflex/codegen/config/package-info.java b/mybatis-flex-codegen/src/main/java/com/mybatisflex/codegen/config/package-info.java new file mode 100644 index 00000000..94681442 --- /dev/null +++ b/mybatis-flex-codegen/src/main/java/com/mybatisflex/codegen/config/package-info.java @@ -0,0 +1,20 @@ +/* + * Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com). + *
+ * Licensed 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 com.mybatisflex.codegen.config; \ No newline at end of file diff --git a/mybatis-flex-codegen/src/main/java/com/mybatisflex/codegen/constant/package-info.java b/mybatis-flex-codegen/src/main/java/com/mybatisflex/codegen/constant/package-info.java new file mode 100644 index 00000000..ba6aeec5 --- /dev/null +++ b/mybatis-flex-codegen/src/main/java/com/mybatisflex/codegen/constant/package-info.java @@ -0,0 +1,20 @@ +/* + * Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com). + *
+ * Licensed 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 com.mybatisflex.codegen.constant; \ No newline at end of file diff --git a/mybatis-flex-codegen/src/main/java/com/mybatisflex/codegen/dialect/package-info.java b/mybatis-flex-codegen/src/main/java/com/mybatisflex/codegen/dialect/package-info.java new file mode 100644 index 00000000..30014ccc --- /dev/null +++ b/mybatis-flex-codegen/src/main/java/com/mybatisflex/codegen/dialect/package-info.java @@ -0,0 +1,20 @@ +/* + * Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com). + *
+ * Licensed 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. + */ + +/** + * SQL 方言。 + */ +package com.mybatisflex.codegen.dialect; \ No newline at end of file diff --git a/mybatis-flex-codegen/src/main/java/com/mybatisflex/codegen/entity/package-info.java b/mybatis-flex-codegen/src/main/java/com/mybatisflex/codegen/entity/package-info.java new file mode 100644 index 00000000..1a670c74 --- /dev/null +++ b/mybatis-flex-codegen/src/main/java/com/mybatisflex/codegen/entity/package-info.java @@ -0,0 +1,20 @@ +/* + * Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com). + *
+ * Licensed 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 com.mybatisflex.codegen.entity; \ No newline at end of file diff --git a/mybatis-flex-codegen/src/main/java/com/mybatisflex/codegen/generator/impl/package-info.java b/mybatis-flex-codegen/src/main/java/com/mybatisflex/codegen/generator/impl/package-info.java new file mode 100644 index 00000000..379ba6c4 --- /dev/null +++ b/mybatis-flex-codegen/src/main/java/com/mybatisflex/codegen/generator/impl/package-info.java @@ -0,0 +1,20 @@ +/* + * Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com). + *
+ * Licensed 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 com.mybatisflex.codegen.generator.impl; \ No newline at end of file diff --git a/mybatis-flex-codegen/src/main/java/com/mybatisflex/codegen/generator/package-info.java b/mybatis-flex-codegen/src/main/java/com/mybatisflex/codegen/generator/package-info.java new file mode 100644 index 00000000..a05e47c9 --- /dev/null +++ b/mybatis-flex-codegen/src/main/java/com/mybatisflex/codegen/generator/package-info.java @@ -0,0 +1,20 @@ +/* + * Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com). + *
+ * Licensed 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 com.mybatisflex.codegen.generator; \ No newline at end of file diff --git a/mybatis-flex-codegen/src/main/java/com/mybatisflex/codegen/template/impl/package-info.java b/mybatis-flex-codegen/src/main/java/com/mybatisflex/codegen/template/impl/package-info.java new file mode 100644 index 00000000..8e33ee0e --- /dev/null +++ b/mybatis-flex-codegen/src/main/java/com/mybatisflex/codegen/template/impl/package-info.java @@ -0,0 +1,20 @@ +/* + * Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com). + *
+ * Licensed 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 com.mybatisflex.codegen.template.impl; \ No newline at end of file diff --git a/mybatis-flex-codegen/src/main/java/com/mybatisflex/codegen/template/package-info.java b/mybatis-flex-codegen/src/main/java/com/mybatisflex/codegen/template/package-info.java new file mode 100644 index 00000000..6f8d09fc --- /dev/null +++ b/mybatis-flex-codegen/src/main/java/com/mybatisflex/codegen/template/package-info.java @@ -0,0 +1,20 @@ +/* + * Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com). + *
+ * Licensed 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 com.mybatisflex.codegen.template; \ No newline at end of file From 61b6773700bed4861c0de5670ebd25f84814750a Mon Sep 17 00:00:00 2001 From: Suomm <1474983351@qq.com> Date: Wed, 21 Jun 2023 22:09:56 +0800 Subject: [PATCH 02/15] =?UTF-8?q?style:=20=E6=B7=BB=E5=8A=A0=20Column=20?= =?UTF-8?q?=E5=AD=97=E6=AE=B5=E6=B3=A8=E9=87=8A=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../mybatisflex/codegen/entity/Column.java | 63 +++++++++++++------ 1 file changed, 45 insertions(+), 18 deletions(-) diff --git a/mybatis-flex-codegen/src/main/java/com/mybatisflex/codegen/entity/Column.java b/mybatis-flex-codegen/src/main/java/com/mybatisflex/codegen/entity/Column.java index 97c1cfc8..4a3feef3 100644 --- a/mybatis-flex-codegen/src/main/java/com/mybatisflex/codegen/entity/Column.java +++ b/mybatis-flex-codegen/src/main/java/com/mybatisflex/codegen/entity/Column.java @@ -1,17 +1,17 @@ -/** - * Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com). - *
- * Licensed 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. +/* + * Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com). + *
+ * Licensed 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 com.mybatisflex.codegen.entity;
@@ -24,22 +24,51 @@ import com.mybatisflex.core.util.StringUtil;
import java.util.ArrayList;
import java.util.List;
+/**
+ * 数据库表里面的列信息。
+ */
public class Column {
+ /**
+ * 字段名称。
+ */
private String name;
+
+ /**
+ * 属性名称。
+ */
private String property;
+
+ /**
+ * 属性类型。
+ */
private String propertyType;
+ /**
+ * 字段注释。
+ */
private String comment;
+ /**
+ * 是否为主键。
+ */
private boolean isPrimaryKey = false;
+
+ /**
+ * 是否自增。
+ */
private Boolean isAutoIncrement;
+ /**
+ * 是否需要生成 @Column 注解。
+ */
private boolean needGenColumnAnnotation = false;
+ /**
+ * 字段配置。
+ */
private ColumnConfig columnConfig;
-
public String getName() {
return name;
}
@@ -106,7 +135,6 @@ public class Column {
return "set" + StringUtil.firstCharToUpperCase(property);
}
-
public String buildComment() {
if (StringUtil.isBlank(comment)) {
return "";
@@ -118,7 +146,6 @@ public class Column {
}
}
-
public String buildPropertyName() {
String entityJavaFileName = name;
return StringUtil.firstCharToLowerCase(StringUtil.underlineToCamel(entityJavaFileName));
@@ -285,7 +312,6 @@ public class Column {
return importClasses;
}
-
@Override
public String toString() {
return "Column{" +
@@ -295,4 +321,5 @@ public class Column {
", isAutoIncrement=" + isAutoIncrement +
'}';
}
+
}
From 04f28261764382e265eb62eb7e32d898f50da06d Mon Sep 17 00:00:00 2001
From: Suomm <1474983351@qq.com>
Date: Wed, 21 Jun 2023 22:11:03 +0800
Subject: [PATCH 03/15] =?UTF-8?q?style:=20=E6=B7=BB=E5=8A=A0=20Table=20?=
=?UTF-8?q?=E5=AD=97=E6=AE=B5=E6=B3=A8=E9=87=8A=EF=BC=8C=E4=BC=98=E5=8C=96?=
=?UTF-8?q?=E7=B1=BB=E7=BB=93=E6=9E=84=E3=80=82?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../com/mybatisflex/codegen/entity/Table.java | 279 ++++++++++--------
1 file changed, 162 insertions(+), 117 deletions(-)
diff --git a/mybatis-flex-codegen/src/main/java/com/mybatisflex/codegen/entity/Table.java b/mybatis-flex-codegen/src/main/java/com/mybatisflex/codegen/entity/Table.java
index 2d7e5119..c0e96cc0 100644
--- a/mybatis-flex-codegen/src/main/java/com/mybatisflex/codegen/entity/Table.java
+++ b/mybatis-flex-codegen/src/main/java/com/mybatisflex/codegen/entity/Table.java
@@ -22,17 +22,46 @@ import java.math.BigInteger;
import java.util.*;
import java.util.stream.Collectors;
+/**
+ * 数据库表信息。
+ */
public class Table {
- private String schema;
+ /**
+ * 表名。
+ */
private String name;
+
+ /**
+ * schema(模式)。
+ */
+ private String schema;
+
+ /**
+ * 表注释。
+ */
private String comment;
+
+ /**
+ * 主键。
+ */
private Set
- * Licensed 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.
+/*
+ * Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com).
+ *
+ * Licensed 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 com.mybatisflex.codegen.config;
@@ -21,30 +21,81 @@ import org.apache.ibatis.type.TypeHandler;
import java.io.Serializable;
+/**
+ * 表字段的单独设置。
+ */
public class ColumnConfig implements Serializable {
+ /**
+ * 字段名称。
+ */
private String columnName;
+ /**
+ * insert 的时候默认值,这个值会直接被拼接到 sql 而不通过参数设置。
+ */
private String onInsertValue;
+
+ /**
+ * update 的时候自动赋值,这个值会直接被拼接到 sql 而不通过参数设置。
+ */
private String onUpdateValue;
+ /**
+ * 是否是大字段,大字段 APT 不会生成到 DEFAULT_COLUMNS 里。
+ */
private Boolean isLarge;
+
+ /**
+ * 是否是逻辑删除字段,一张表中只能存在 1 一个逻辑删除字段。
+ */
private Boolean isLogicDelete;
+
+ /**
+ * 是否为乐观锁字段。
+ */
private Boolean version;
+ /**
+ * 配置的 jdbcType。
+ */
private JdbcType jdbcType;
+
+ /**
+ * 自定义 TypeHandler。
+ */
private Class extends TypeHandler> typeHandler;
+ /**
+ * 脱敏方式。
+ */
private String mask;
+ /**
+ * 字段是否为主键。
+ */
private boolean isPrimaryKey = false;
+
+ /**
+ * ID 生成策略。
+ */
private KeyType keyType;
+
+ /**
+ * ID 生成器值。
+ */
private String keyValue;
+
+ /**
+ * sequence 序列执行顺序。
+ */
private Boolean keyBefore;
+ /**
+ * 是否是租户 ID。
+ */
private Boolean tenantId;
-
public String getColumnName() {
return columnName;
}
@@ -156,4 +207,5 @@ public class ColumnConfig implements Serializable {
public void setTenantId(Boolean tenantId) {
this.tenantId = tenantId;
}
+
}
From 86284b932a3ab9710aaa9db8b68e31bc8ebfd4ee Mon Sep 17 00:00:00 2001
From: Suomm <1474983351@qq.com>
Date: Wed, 21 Jun 2023 22:12:14 +0800
Subject: [PATCH 05/15] =?UTF-8?q?style:=20=E6=B7=BB=E5=8A=A0=20TableConfig?=
=?UTF-8?q?=20=E7=B1=BB=E7=9A=84=E5=B1=9E=E6=80=A7=E6=B3=A8=E9=87=8A?=
=?UTF-8?q?=E3=80=82?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../codegen/config/TableConfig.java | 59 ++++++++++++-------
1 file changed, 37 insertions(+), 22 deletions(-)
diff --git a/mybatis-flex-codegen/src/main/java/com/mybatisflex/codegen/config/TableConfig.java b/mybatis-flex-codegen/src/main/java/com/mybatisflex/codegen/config/TableConfig.java
index f403c11c..707d5ad5 100644
--- a/mybatis-flex-codegen/src/main/java/com/mybatisflex/codegen/config/TableConfig.java
+++ b/mybatis-flex-codegen/src/main/java/com/mybatisflex/codegen/config/TableConfig.java
@@ -1,17 +1,17 @@
-/**
- * Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com).
- *
- * Licensed 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.
+/*
+ * Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com).
+ *
+ * Licensed 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 com.mybatisflex.codegen.config;
@@ -22,35 +22,51 @@ import com.mybatisflex.annotation.UpdateListener;
import java.util.HashMap;
import java.util.Map;
+/**
+ * 表的单独设置。
+ */
public class TableConfig {
+ /**
+ * 表名。
+ */
private String tableName;
/**
- * 数据库的 schema(模式)
+ * 数据库的 schema(模式)。
*/
private String schema;
/**
- * 默认为 驼峰属性 转换为 下划线字段
+ * 默认为 驼峰属性 转换为 下划线字段。
*/
private Boolean camelToUnderline;
-
+ /**
+ * 监听 entity 的 insert 行为。
+ */
private Class extends InsertListener> insertListenerClass;
-
+ /**
+ * 监听 entity 的 update 行为。
+ */
private Class extends UpdateListener> updateListenerClass;
-
+ /**
+ * 监听 entity 的查询数据的 set 行为。
+ */
private Class extends SetListener> setListenerClass;
-
+ /**
+ * 对应列的配置。
+ */
private Map
- * Licensed 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.
+/*
+ * Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com).
+ *
+ * Licensed 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 com.mybatisflex.codegen.template;
import java.io.File;
import java.util.Map;
+/**
+ * 模板引擎。
+ */
+@FunctionalInterface
public interface ITemplate {
+ /**
+ * 使用模板引擎生成代码。
+ *
+ * @param params 生成参数
+ * @param templateFilePath 模板文件位置
+ * @param generateFile 生成文件位置
+ */
void generate(Map
- * Licensed 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.
+/*
+ * Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com).
+ *
+ * Licensed 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 com.mybatisflex.codegen;
@@ -31,6 +31,9 @@ import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
+/**
+ * 代码生成器。
+ */
public class Generator {
protected DataSource dataSource;
@@ -40,20 +43,17 @@ public class Generator {
protected Connection conn = null;
protected DatabaseMetaData dbMeta = null;
-
public Generator(DataSource dataSource, GlobalConfig globalConfig) {
this.dataSource = dataSource;
this.globalConfig = globalConfig;
}
-
public Generator(DataSource dataSource, GlobalConfig globalConfig, IDialect dialect) {
this.dataSource = dataSource;
this.globalConfig = globalConfig;
this.dialect = dialect;
}
-
public void generate() {
try {
conn = dataSource.getConnection();
@@ -74,7 +74,6 @@ public class Generator {
}
}
-
protected void buildPrimaryKey(Table table) throws SQLException {
try (ResultSet rs = dbMeta.getPrimaryKeys(conn.getCatalog(), null, table.getName())) {
while (rs.next()) {
@@ -84,7 +83,6 @@ public class Generator {
}
}
-
private List
- * Licensed 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.
+/*
+ * Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com).
+ *
+ * Licensed 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 com.mybatisflex.codegen.template.impl;
@@ -28,6 +28,9 @@ import java.io.File;
import java.io.FileOutputStream;
import java.util.Map;
+/**
+ * JFinal Enjoy 模板引擎实现。
+ */
public class EnjoyTemplate implements ITemplate {
private final Engine engine;
@@ -43,17 +46,22 @@ public class EnjoyTemplate implements ITemplate {
@Override
public void generate(Map
- * Licensed 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.
+/*
+ * Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com).
+ *
+ * Licensed 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 com.mybatisflex.codegen.dialect;
@@ -24,8 +24,14 @@ import java.sql.DatabaseMetaData;
import java.sql.ResultSet;
import java.sql.SQLException;
+/**
+ * 方言接口。
+ */
public interface IDialect {
+ /**
+ * 默认方言。
+ */
IDialect DEFAULT = new JdbcDialect() {
@Override
String forBuildColumnsSql(String schema, String tableName) {
@@ -33,7 +39,9 @@ public interface IDialect {
}
};
-
+ /**
+ * MySQL 方言。
+ */
IDialect MYSQL = new JdbcDialect() {
@Override
String forBuildColumnsSql(String schema, String tableName) {
@@ -41,7 +49,9 @@ public interface IDialect {
}
};
-
+ /**
+ * Oracle 方言。
+ */
IDialect ORACLE = new JdbcDialect() {
@Override
public String forBuildColumnsSql(String schema, String tableName) {
@@ -54,10 +64,32 @@ public interface IDialect {
}
};
+ /**
+ * Sqlite 方言。
+ */
IDialect SQLITE = new SqliteDialect();
-
+ /**
+ * 构建表和列的信息。
+ *
+ * @param table 存入的表对象
+ * @param globalConfig 全局配置
+ * @param dbMeta 数据库元数据
+ * @param conn 连接
+ * @throws SQLException 发生 SQL 异常时抛出
+ */
void buildTableColumns(Table table, GlobalConfig globalConfig, DatabaseMetaData dbMeta, Connection conn) throws SQLException;
+ /**
+ * 获取表的描述信息。
+ *
+ * @param dbMeta 数据库元数据
+ * @param conn 连接
+ * @param schema 模式
+ * @param types 结果集类型
+ * @return 结果集
+ * @throws SQLException 发生 SQL 异常时抛出
+ */
ResultSet getTablesResultSet(DatabaseMetaData dbMeta, Connection conn, String schema, String[] types) throws SQLException;
+
}
From e98f2bd1f36950aca0a850c3694d2ff94a876455 Mon Sep 17 00:00:00 2001
From: Suomm <1474983351@qq.com>
Date: Thu, 22 Jun 2023 09:18:00 +0800
Subject: [PATCH 13/15] =?UTF-8?q?style:=20=E6=B7=BB=E5=8A=A0=20JdbcDialect?=
=?UTF-8?q?=20=E6=B3=A8=E9=87=8A=E3=80=82?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../codegen/dialect/JdbcDialect.java | 42 +++++++++++--------
1 file changed, 25 insertions(+), 17 deletions(-)
diff --git a/mybatis-flex-codegen/src/main/java/com/mybatisflex/codegen/dialect/JdbcDialect.java b/mybatis-flex-codegen/src/main/java/com/mybatisflex/codegen/dialect/JdbcDialect.java
index 676e7ba1..2f4258f9 100644
--- a/mybatis-flex-codegen/src/main/java/com/mybatisflex/codegen/dialect/JdbcDialect.java
+++ b/mybatis-flex-codegen/src/main/java/com/mybatisflex/codegen/dialect/JdbcDialect.java
@@ -1,17 +1,17 @@
-/**
- * Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com).
- *
- * Licensed 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.
+/*
+ * Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com).
+ *
+ * Licensed 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 com.mybatisflex.codegen.dialect;
@@ -23,6 +23,9 @@ import java.sql.*;
import java.util.HashMap;
import java.util.Map;
+/**
+ * 默认方言抽象类。
+ */
public abstract class JdbcDialect implements IDialect {
@Override
@@ -52,7 +55,6 @@ public abstract class JdbcDialect implements IDialect {
}
}
-
private Map
- * Licensed 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.
+/*
+ * Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com).
+ *
+ * Licensed 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 com.mybatisflex.codegen.dialect;
@@ -23,6 +23,9 @@ import java.math.BigDecimal;
import java.math.BigInteger;
import java.sql.*;
+/**
+ * Sqlite 方言实现。
+ */
public class SqliteDialect implements IDialect {
@Override
@@ -48,13 +51,11 @@ public class SqliteDialect implements IDialect {
}
}
-
@Override
public ResultSet getTablesResultSet(DatabaseMetaData dbMeta, Connection conn, String schema, String[] types) throws SQLException {
return dbMeta.getTables(conn.getCatalog(), schema, null, types);
}
-
private String type2ClassName(String type) {
int indexOf = type.indexOf("(");
if (indexOf > 0) {
@@ -94,4 +95,5 @@ public class SqliteDialect implements IDialect {
return String.class.getName();
}
}
+
}
From 27c4ced2d82c2c8b2e6cdce324585626263db8ea Mon Sep 17 00:00:00 2001
From: Suomm <1474983351@qq.com>
Date: Thu, 22 Jun 2023 09:18:33 +0800
Subject: [PATCH 15/15] =?UTF-8?q?style:=20=E6=B7=BB=E5=8A=A0=20JdbcTypeMap?=
=?UTF-8?q?ping=20=E6=B3=A8=E9=87=8A=E3=80=82?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../codegen/dialect/JdbcTypeMapping.java | 36 +++++++++++--------
1 file changed, 21 insertions(+), 15 deletions(-)
diff --git a/mybatis-flex-codegen/src/main/java/com/mybatisflex/codegen/dialect/JdbcTypeMapping.java b/mybatis-flex-codegen/src/main/java/com/mybatisflex/codegen/dialect/JdbcTypeMapping.java
index 14eb7d00..3f8f3e50 100644
--- a/mybatis-flex-codegen/src/main/java/com/mybatisflex/codegen/dialect/JdbcTypeMapping.java
+++ b/mybatis-flex-codegen/src/main/java/com/mybatisflex/codegen/dialect/JdbcTypeMapping.java
@@ -1,17 +1,17 @@
-/**
- * Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com).
- *
- * Licensed 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.
+/*
+ * Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com).
+ *
+ * Licensed 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 com.mybatisflex.codegen.dialect;
@@ -20,8 +20,14 @@ import com.mybatisflex.core.util.StringUtil;
import java.util.HashMap;
import java.util.Map;
+/**
+ * 字段类型映射。
+ */
public class JdbcTypeMapping {
+ private JdbcTypeMapping() {
+ }
+
private static final Map buildTables() throws SQLException {
StrategyConfig strategyConfig = globalConfig.getStrategyConfig();
String schemaName = strategyConfig.getGenerateSchema();
@@ -117,7 +115,6 @@ public class Generator {
return tables;
}
-
protected ResultSet getTablesResultSet(String schema) throws SQLException {
if (globalConfig.getStrategyConfig().isGenerateForView()) {
return dialect.getTablesResultSet(dbMeta, conn, schema, new String[]{"TABLE", "VIEW"});
@@ -125,4 +122,5 @@ public class Generator {
return dialect.getTablesResultSet(dbMeta, conn, schema, new String[]{"TABLE"});
}
}
+
}
From ab2c5b706ab6c12ef1423248d27f4991244aeca6 Mon Sep 17 00:00:00 2001
From: Suomm <1474983351@qq.com>
Date: Wed, 21 Jun 2023 22:17:07 +0800
Subject: [PATCH 10/15] =?UTF-8?q?style:=20=E6=B7=BB=E5=8A=A0=20GeneratorFa?=
=?UTF-8?q?ctory=20=E6=B3=A8=E9=87=8A=E3=80=82?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../codegen/generator/GeneratorFactory.java | 28 +++++++++++++++++--
1 file changed, 26 insertions(+), 2 deletions(-)
diff --git a/mybatis-flex-codegen/src/main/java/com/mybatisflex/codegen/generator/GeneratorFactory.java b/mybatis-flex-codegen/src/main/java/com/mybatisflex/codegen/generator/GeneratorFactory.java
index 9bfb5b68..3cd21890 100644
--- a/mybatis-flex-codegen/src/main/java/com/mybatisflex/codegen/generator/GeneratorFactory.java
+++ b/mybatis-flex-codegen/src/main/java/com/mybatisflex/codegen/generator/GeneratorFactory.java
@@ -22,6 +22,11 @@ import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
+/**
+ * 代码生成器工厂,用于创建各种类型文件的生成。
+ *
+ * @see GenTypeConst
+ */
public class GeneratorFactory {
private static final Map