fix: h2代码生成器

V0.5.x
jay 2023-06-24 21:02:25 +08:00
parent 86584d1fa3
commit 4fde0db036
6 changed files with 84 additions and 5 deletions

View File

@ -41,6 +41,11 @@ public class DataBaseHelper {
return DataBaseType.MY_SQL == getDataBaseType();
}
public static boolean isH2() {
return DataBaseType.H2 == getDataBaseType();
}
public static boolean isOracle() {
return DataBaseType.ORACLE == getDataBaseType();
}

View File

@ -19,6 +19,7 @@ public enum DataBaseType {
*/
MY_SQL("MySQL"),
H2("H2"),
/**
* Oracle
*/

View File

@ -19,6 +19,18 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
from information_schema.columns where table_schema = (select database()) and table_name = (#{tableName})
order by ordinal_position
</if>
<if test="@cc.iotkit.generator.core.DataBaseHelper@isH2()">
select column_name,
-- (case when (is_nullable = 'no' <![CDATA[ && ]]> column_key != 'PRI') then '1' else null end) as is_required,
(case when (is_nullable = 'no' ) then '1' else null end) as is_required,
-- (case when column_key = 'PRI' then '1' else '0' end) as is_pk,
ordinal_position as sort
-- column_comment,
-- (case when extra = 'auto_increment' then '1' else '0' end) as is_increment,
-- column_type
from information_schema.columns where table_name = (#{tableName})
order by ordinal_position
</if>
<if test="@cc.iotkit.generator.core.DataBaseHelper@isOracle()">
select lower(temp.column_name) as column_name,
(case when (temp.nullable = 'N' and temp.constraint_type != 'P') then '1' else null end) as is_required,

View File

@ -74,6 +74,25 @@
</if>
order by create_time desc
</if>
<if test="@cc.iotkit.generator.core.DataBaseHelper@isH2()">
select table_name
from information_schema.tables
where
table_name NOT LIKE 'pj_%' AND table_name NOT LIKE 'gen_%'
<if test="genTable.params.genTableNames != null and genTable.params.genTableNames.size > 0">
AND table_name NOT IN
<foreach collection="genTable.params.genTableNames" open="(" close=")" separator="," item="item">
#{item}
</foreach>
</if>
<if test="genTable.tableName != null and genTable.tableName != ''">
AND lower(table_name) like lower(concat('%', #{genTable.tableName}, '%'))
</if>
<if test="genTable.tableComment != null and genTable.tableComment != ''">
AND lower(table_comment) like lower(concat('%', #{genTable.tableComment}, '%'))
</if>
order by table_name desc
</if>
<if test="@cc.iotkit.generator.core.DataBaseHelper@isOracle()">
select lower(dt.table_name) as table_name, dtc.comments as table_comment, uo.created as create_time, uo.last_ddl_time as update_time
from user_tables dt, user_tab_comments dtc, user_objects uo
@ -158,6 +177,14 @@
#{name}
</foreach>
</if>
<if test="@cc.iotkit.generator.core.DataBaseHelper@isH2()">
select table_name from information_schema.tables
where table_name NOT LIKE 'pj_%' and table_name NOT LIKE 'gen_%'
and table_name in
<foreach collection="list" item="name" open="(" separator="," close=")">
#{name}
</foreach>
</if>
<if test="@cc.iotkit.generator.core.DataBaseHelper@isOracle()">
select lower(dt.table_name) as table_name, dtc.comments as table_comment, uo.created as create_time, uo.last_ddl_time as update_time
from user_tables dt, user_tab_comments dtc, user_objects uo

View File

@ -17,12 +17,45 @@ spring:
properties:
hibernate:
format_sql: true
sql:
init:
schema-locations: classpath:sql/schema.sql
mode: ALWAYS
datasource:
url: jdbc:h2:./data/iotkit;MODE=MySQL
username: sa
password: 123456
driverClassName: org.h2.Driver
type: com.zaxxer.hikari.HikariDataSource
# 动态数据源文档 https://www.kancloud.cn/tracy5546/dynamic-datasource/content
dynamic:
hikari:
connection-timeout: 5000
idle-timeout: 30000 # 经过idle-timeout时间如果连接还处于空闲状态, 该连接会被回收
min-idle: 5 # 池中维护的最小空闲连接数, 默认为 10 个
max-pool-size: 16 # 池中最大连接数, 包括闲置和使用中的连接, 默认为 10 个
max-lifetime: 60000 # 如果一个连接超过了时长,且没有被使用, 连接会被回收
is-auto-commit: true
primary: master #设置默认的数据源或者数据源组,默认值即为master
strict: true #严格匹配数据源,默认false. true未匹配到指定数据源时抛异常,false使用默认数据源
datasource:
# 主库数据源
master:
type: ${spring.datasource.type}
driverClassName: org.h2.Driver
# jdbc 所有参数配置参考 https://lionli.blog.csdn.net/article/details/122018562
# rewriteBatchedStatements=true 批处理优化 大幅提升批量插入更新删除性能(对数据库有性能损耗 使用批量操作应考虑性能问题)
url: jdbc:h2:./data/iotkit;MODE=MySQL
username: sa
password: 123456
# 从库数据源
slave:
lazy: true
type: ${spring.datasource.type}
driverClassName: org.h2.Driver
url: jdbc:h2:./data/iotkit;MODE=MySQL
username: sa
password: 123456
# 内置h2 web console设置
platform: h2
@ -84,6 +117,8 @@ spring:
mvc:
pathmatch:
matching-strategy: ant_path_matcher
# profiles:
# active: mysql
#application.yml中打开注释支持rocketMq作为消息总线pom.xml中打开注释使用rocketmq消息总线
#rocketmq:

View File

@ -1,8 +1,7 @@
-- ----------------------------
-- 18、代码生成业务表
-- ----------------------------
drop table if exists gen_table;
create table gen_table (
create table if not exists gen_table (
table_id bigint(20) not null comment '编号',
data_name varchar(200) default '' comment '数据源名称',
table_name varchar(200) default '' comment '表名称',
@ -32,8 +31,8 @@ create table gen_table (
-- ----------------------------
-- 19、代码生成业务表字段
-- ----------------------------
drop table if exists gen_table_column;
create table gen_table_column (
create table if not exists gen_table_column (
column_id bigint(20) not null comment '编号',
table_id bigint(20) comment '归属表编号',
column_name varchar(200) comment '列名称',