diff --git a/src/main/java/com/ricky/common/constant/Constants.java b/src/main/java/com/ricky/common/constant/Constants.java index 2897ca8d76249377458e8ce2451ba73454013d29..40a8d4a3653778ad2b3076fe53cdc5b8bc10c4f9 100644 --- a/src/main/java/com/ricky/common/constant/Constants.java +++ b/src/main/java/com/ricky/common/constant/Constants.java @@ -89,5 +89,8 @@ public class Constants /** Oracle数据库连接类型-服务名 */ public static final String ORACLE_CONN_TYPE_SERVICE_NAME = "service_name"; + + /**数据库类型-金仓数据库 */ + public static final String DATABASE_KINGBASE = "kingbase"; } diff --git a/src/main/java/com/ricky/common/utils/DataSourceComposeUtils.java b/src/main/java/com/ricky/common/utils/DataSourceComposeUtils.java index f02df0963e9fbea479551dc374cc7403219bf7ca..647a9924fc32b40705c6d67bb11053ce0aae4733 100644 --- a/src/main/java/com/ricky/common/utils/DataSourceComposeUtils.java +++ b/src/main/java/com/ricky/common/utils/DataSourceComposeUtils.java @@ -18,7 +18,8 @@ public class DataSourceComposeUtils private static String URL_TEMPLATE_SQLSERVER = "jdbc:sqlserver://{}:{};SelectMethod=cursor;DatabaseName={}"; /** PostgreSQL连接字符串模板 */ private static String URL_TEMPLATE_POSTGRESQL = "jdbc:postgresql://{}:{}/{}?currentSchema={}&ssl=false"; - + /** KingBaseSQL链接字符串模板 */ + private static String URL_TEMPLATE_KINGBASE = "jdbc:kingbase8://{}:{}/{}?currentSchema={}&characterEncoding=utf8&useSSL=true&serverTimezone=GMT%2B8"; public static DruidDataSource composeDruidDataSource(SysDataSource dataSource) throws BusinessException { DruidDataSource druidDataSource = new DruidDataSource(); @@ -57,6 +58,10 @@ public class DataSourceComposeUtils { druidDataSource.setUrl(StringUtils.format(URL_TEMPLATE_POSTGRESQL, dataSource.getHost(), dataSource.getPort(), dataSource.getName(), dataSource.getSchemaName())); + }else if (StringUtils.equals(dataSource.getDbType(), Constants.DATABASE_KINGBASE)) { + druidDataSource.setUrl(StringUtils.format(URL_TEMPLATE_KINGBASE, dataSource.getHost(), + dataSource.getPort(), dataSource.getName(), dataSource.getName())); + druidDataSource.setDriverClassName("com.kingbase8.Driver"); } else { diff --git a/src/main/java/com/ricky/project/controller/GenController.java b/src/main/java/com/ricky/project/controller/GenController.java index 5a2f1f3c5172ccbbe697184c66078bb4f7a5775c..11235e15d04348b881c31295df7efd4d0886f773 100644 --- a/src/main/java/com/ricky/project/controller/GenController.java +++ b/src/main/java/com/ricky/project/controller/GenController.java @@ -78,7 +78,8 @@ public class GenController extends BaseController public TableDataInfo dataList(GenTable genTable) { SysDataSource dataSource = dataSourceService.selectSysDataSource(genTable.getDataSourceId()); - startPage(); + /** 此处暂查所有表信息数据,不分页,分页需给PageHelper设置dialog*/ + // startPage(); List list = genTableService.selectDbTableList(genTable, dataSource); return getDataTable(list); } diff --git a/src/main/resources/libs/KingBaseES.MD b/src/main/resources/libs/KingBaseES.MD new file mode 100644 index 0000000000000000000000000000000000000000..4e9e7a0f5453216602f9d84ebeba992381430a58 --- /dev/null +++ b/src/main/resources/libs/KingBaseES.MD @@ -0,0 +1,14 @@ +#### 驱动 +~~~ +初始化字典 +INSERT INTO sys_dict_data ( dict_code, dict_sort, dict_label, dict_value, dict_type, list_class, is_default, status,remark) VALUES ( 24, 7, 'kingbase', 'kingbase', 'sys_db_type', 'default' ,'N', 0,'kingbase'); +~~~ + +~~~ +code-generator\src\main\resources\libs\kingbase8-8.6.0.jar + +自行上传私服通过pom引入或添加项目依赖 + +~~~ + + diff --git a/src/main/resources/libs/kingbase8-8.6.0.jar b/src/main/resources/libs/kingbase8-8.6.0.jar new file mode 100644 index 0000000000000000000000000000000000000000..92b2ad7475cc85caab9cf11f00ff1dbc9cb8382f Binary files /dev/null and b/src/main/resources/libs/kingbase8-8.6.0.jar differ diff --git a/src/main/resources/mybatis/mapper/GenTableMapper.xml b/src/main/resources/mybatis/mapper/GenTableMapper.xml index 8df24a5886bc527324c17c6de1aadf7493f46cdc..26a77ac2a6cae26e65c206add38796d35036550c 100644 --- a/src/main/resources/mybatis/mapper/GenTableMapper.xml +++ b/src/main/resources/mybatis/mapper/GenTableMapper.xml @@ -1,35 +1,35 @@ + PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" + "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> - - + + - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + @@ -53,88 +53,88 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" - - + + select table_id, data_source_id, table_name, table_comment, sub_table_name, sub_table_fk_name, class_name, tpl_category, package_name, module_name, business_name, function_name, function_author, gen_type, gen_path, options, create_by, create_time, update_by, update_time, remark from gen_table - + - - - - - - + + + + + + - - + + insert into gen_table ( - table_name, - data_source_id, - table_comment, - class_name, - tpl_category, - package_name, - module_name, - business_name, - function_name, - function_author, - gen_type, - gen_path, - remark, - create_by, - create_time - )values( - #{tableName}, - #{dataSourceId}, - #{tableComment}, - #{className}, - #{tplCategory}, - #{packageName}, - #{moduleName}, - #{businessName}, - #{functionName}, - #{functionAuthor}, - #{genType}, - #{genPath}, - #{remark}, - #{createBy}, - strftime('%Y-%m-%d %H:%M:%S', 'now', 'localtime') - ) + table_name, + data_source_id, + table_comment, + class_name, + tpl_category, + package_name, + module_name, + business_name, + function_name, + function_author, + gen_type, + gen_path, + remark, + create_by, + create_time + )values( + #{tableName}, + #{dataSourceId}, + #{tableComment}, + #{className}, + #{tplCategory}, + #{packageName}, + #{moduleName}, + #{businessName}, + #{functionName}, + #{functionAuthor}, + #{genType}, + #{genPath}, + #{remark}, + #{createBy}, + strftime('%Y-%m-%d %H:%M:%S', 'now', 'localtime') + ) - + update gen_table @@ -159,14 +159,14 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" where table_id = #{tableId} - + - delete from gen_table where table_id in + delete from gen_table where table_id in #{tableId} - + - + - + - + select table_name, table_comment, create_time, update_time from information_schema.tables @@ -257,7 +266,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" - select a.relname as table_name, b.description as table_comment + select a.relname as table_name, b.description as table_comment from pg_class a left join (select * from pg_description where objsubid = 0 ) b on a.oid = b.objoid where a.relname in (select tablename from pg_tables where schemaname = (select current_schema())) @@ -282,8 +291,17 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" AND lower(table_comment) like lower(concat('%', #{genTable.tableComment}, '%')) + + select table_name, comments table_comment from all_tab_comments where lower(table_type) = 'table' + + AND lower(table_name) like lower(concat('%', #{genTable.tableName}, '%')) + + + AND lower(table_comment) like lower(concat('%', #{genTable.tableComment}, '%')) + + - + select table_name, table_comment, create_time, update_time from information_schema.tables @@ -291,7 +309,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" and table_name in #{name} - + 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 @@ -303,10 +321,10 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" and lower(dt.table_name) in #{name} - + - select a.relname as table_name, b.description as table_comment + select a.relname as table_name, b.description as table_comment from pg_class a left join (select * from pg_description where objsubid = 0 ) b on a.oid = b.objoid where a.relname in (select tablename from pg_tables where schemaname = (select current_schema())) @@ -314,7 +332,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" AND a.relname in #{name} - + SELECT cast(D.NAME as nvarchar) as table_name,cast(F.VALUE as nvarchar) as table_comment, @@ -325,10 +343,17 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" AND D.NAME in #{name} - + + + + select table_name, comments table_comment from all_tab_comments + where lower(table_type) = 'table' and table_name in + + #{name} + - + select column_name, (case when (is_nullable = 'no' and column_key != 'PRI') 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 @@ -337,49 +362,49 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" 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, - (case when temp.constraint_type = 'P' then '1' else '0' end) as is_pk, - temp.column_id as sort, - temp.comments as column_comment, - (case when temp.constraint_type = 'P' then '1' else '0' end) as is_increment, - lower(temp.data_type) as column_type - from ( - select col.column_id, col.column_name,col.nullable, col.data_type, colc.comments, uc.constraint_type - , row_number() over (partition by col.column_name order by uc.constraint_type desc) as row_flg - from user_tab_columns col - left join user_col_comments colc on colc.table_name = col.table_name and colc.column_name = col.column_name - left join user_cons_columns ucc on ucc.table_name = col.table_name and ucc.column_name = col.column_name - left join user_constraints uc on uc.constraint_name = ucc.constraint_name + (case when (temp.nullable = 'N' and temp.constraint_type != 'P') then '1' else null end) as is_required, + (case when temp.constraint_type = 'P' then '1' else '0' end) as is_pk, + temp.column_id as sort, + temp.comments as column_comment, + (case when temp.constraint_type = 'P' then '1' else '0' end) as is_increment, + lower(temp.data_type) as column_type + from ( + select col.column_id, col.column_name,col.nullable, col.data_type, colc.comments, uc.constraint_type + , row_number() over (partition by col.column_name order by uc.constraint_type desc) as row_flg + from user_tab_columns col + left join user_col_comments colc on colc.table_name = col.table_name and colc.column_name = col.column_name + left join user_cons_columns ucc on ucc.table_name = col.table_name and ucc.column_name = col.column_name + left join user_constraints uc on uc.constraint_name = ucc.constraint_name where col.table_name = upper(#{tableName}) - ) temp - WHERE temp.row_flg = 1 - ORDER BY temp.column_id + ) temp + WHERE temp.row_flg = 1 + ORDER BY temp.column_id select sc.column_name, - (case when sc.is_nullable = 'NO' then '1' else '0' end) as is_required, - (case when b.pk_name is null then '0' else '1' end) as is_pk, - ordinal_position as sort, - c.column_comment, - (case when sc.is_identity = 'NO' then '0' else '1' end) as is_increment, - udt_name as column_type + (case when sc.is_nullable = 'NO' then '1' else '0' end) as is_required, + (case when b.pk_name is null then '0' else '1' end) as is_pk, + ordinal_position as sort, + c.column_comment, + (case when sc.is_identity = 'NO' then '0' else '1' end) as is_increment, + udt_name as column_type from information_schema.columns sc - left join( - select pg_attr.attname as column_name,pg_constraint.conname as pk_name - from pg_constraint - inner join pg_class on pg_constraint.conrelid = pg_class.oid - inner join pg_attribute pg_attr on pg_attr.attrelid = pg_class.oid and pg_attr.attnum = pg_constraint.conkey[1] - inner join pg_type on pg_type.oid = pg_attr.atttypid - where pg_class.relname = #{tableName} - and pg_constraint.contype='p' + left join( + select pg_attr.attname as column_name,pg_constraint.conname as pk_name + from pg_constraint + inner join pg_class on pg_constraint.conrelid = pg_class.oid + inner join pg_attribute pg_attr on pg_attr.attrelid = pg_class.oid and pg_attr.attnum = pg_constraint.conkey[1] + inner join pg_type on pg_type.oid = pg_attr.atttypid + where pg_class.relname = #{tableName} + and pg_constraint.contype='p' ) b on b.column_name = sc.column_name - left join ( - select attname as column_name,description as column_comment + left join ( + select attname as column_name,description as column_comment from pg_class - left join pg_attribute pg_attr on pg_attr.attrelid= pg_class.oid - left join pg_description pg_desc on pg_desc.objoid = pg_attr.attrelid and pg_desc.objsubid=pg_attr.attnum - where pg_attr.attnum > 0 and pg_attr.attrelid = pg_class.oid - and pg_class.relname = #{tableName} + left join pg_attribute pg_attr on pg_attr.attrelid= pg_class.oid + left join pg_description pg_desc on pg_desc.objoid = pg_attr.attrelid and pg_desc.objsubid=pg_attr.attnum + where pg_attr.attnum > 0 and pg_attr.attrelid = pg_class.oid + and pg_class.relname = #{tableName} ) c on c.column_name = sc.column_name where table_schema=(select current_schema()) and table_name=#{tableName} order by ordinal_position asc @@ -391,12 +416,19 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" (SELECT 1 FROM INFORMATION_SCHEMA.KEY_COLUMN_USAGE Z WHERE TABLE_NAME=D.NAME and A.NAME = Z.column_name ) as is_pk, colorder as sort FROM SYSCOLUMNS A - LEFT JOIN SYSTYPES B ON A.XTYPE=B.XUSERTYPE - INNER JOIN SYSOBJECTS D ON A.ID=D.ID AND D.XTYPE='U' AND D.NAME!='DTPROPERTIES' + LEFT JOIN SYSTYPES B ON A.XTYPE=B.XUSERTYPE + INNER JOIN SYSOBJECTS D ON A.ID=D.ID AND D.XTYPE='U' AND D.NAME!='DTPROPERTIES' LEFT JOIN SYS.EXTENDED_PROPERTIES G ON A.ID=G.MAJOR_ID AND A.COLID=G.MINOR_ID LEFT JOIN SYS.EXTENDED_PROPERTIES F ON D.ID=F.MAJOR_ID AND F.MINOR_ID =0 where D.NAME = #{tableName} ORDER BY A.COLORDER + + select a.column_name, + b.comments column_comment + from all_tab_columns a + left join all_col_comments b on lower(a.owner) = lower(b.owner) and lower(a.table_name) = lower(b.table_name) and lower(a.column_name) = lower(b.column_name) + where a.table_name = #{tableName} + - \ No newline at end of file + \ No newline at end of file