mirror of
http://git.pig4cloud.com/pig/pigx.git
synced 2026-11-12 21:49:01 +08:00
✨ Introducing new features. #2151 【代码生成】 支持ORACEL / SQL SERVER /PG 等其他数据源类型代码生成
This commit is contained in:
1 parent
193a1f478b
commit
e69a50c5ee
34 files changed
+826
-193
No files matched your search
@@ -1,47 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<!--
|
||||
~ Copyright (c) 2018-2025, lengleng All rights reserved.
|
||||
~
|
||||
~ Redistribution and use in source and binary forms, with or without
|
||||
~ modification, are permitted provided that the following conditions are met:
|
||||
~
|
||||
~ Redistributions of source code must retain the above copyright notice,
|
||||
~ this list of conditions and the following disclaimer.
|
||||
~ Redistributions in binary form must reproduce the above copyright
|
||||
~ notice, this list of conditions and the following disclaimer in the
|
||||
~ documentation and/or other materials provided with the distribution.
|
||||
~ Neither the name of the pig4cloud.com developer nor the names of its
|
||||
~ contributors may be used to endorse or promote products derived from
|
||||
~ this software without specific prior written permission.
|
||||
~ Author: lengleng (wangiegie@gmail.com)
|
||||
-->
|
||||
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
|
||||
<mapper namespace="com.pig4cloud.pigx.codegen.mapper.GenTableColumnMapper">
|
||||
|
||||
<sql id="queryColumn">
|
||||
SELECT
|
||||
column_name columnName,
|
||||
data_type dataType,
|
||||
column_comment comments,
|
||||
column_key columnKey,
|
||||
extra,
|
||||
is_nullable AS isNullable,
|
||||
column_type AS columnType
|
||||
FROM
|
||||
information_schema.COLUMNS
|
||||
WHERE
|
||||
table_name = #{tableName} and table_schema = (select database()) order by ordinal_position
|
||||
</sql>
|
||||
|
||||
<select id="selectTableColumn" resultType="com.pig4cloud.pigx.codegen.entity.ColumnEntity">
|
||||
<include refid="queryColumn"/>
|
||||
</select>
|
||||
|
||||
<select id="selectMapTableColumn" resultType="map">
|
||||
<include refid="queryColumn"/>
|
||||
</select>
|
||||
|
||||
</mapper>
|
||||
@@ -1,19 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
|
||||
<mapper namespace="com.pig4cloud.pigx.codegen.mapper.GeneratorMapper">
|
||||
<select id="queryList" resultType="map">
|
||||
select table_name tableName, engine, table_comment tableComment, table_collation tableCollation, create_time createTime from information_schema.tables
|
||||
where table_schema = (select database())
|
||||
<if test="tableName != null and tableName.trim() != ''">
|
||||
and table_name like concat('%', #{tableName}, '%')
|
||||
</if>
|
||||
order by create_time desc
|
||||
</select>
|
||||
|
||||
<select id="queryTable" resultType="map">
|
||||
select table_name tableName, engine, table_comment tableComment, create_time createTime from information_schema.tables
|
||||
where table_schema = (select database()) and table_name = #{tableName}
|
||||
</select>
|
||||
|
||||
</mapper>
|
||||
+87
@@ -0,0 +1,87 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
|
||||
<mapper namespace="com.pig4cloud.pigx.codegen.mapper.GeneratorMssqlMapper">
|
||||
|
||||
<select id="queryTable" resultType="map">
|
||||
SELECT *
|
||||
FROM (
|
||||
SELECT CAST
|
||||
(so.NAME AS nvarchar(500)) AS tableName,
|
||||
CAST(sep.VALUE AS nvarchar(500)) AS tableComment
|
||||
FROM sysobjects so
|
||||
LEFT JOIN sys.extended_properties sep ON sep.major_id = so.ID
|
||||
AND sep.minor_id = 0
|
||||
WHERE (xtype = 'U' OR xtype = 'v')
|
||||
) T
|
||||
<where>
|
||||
<if test="tableName != null and tableName.trim() != ''">
|
||||
and T.tableName like concat('%', #{tableName}, '%')
|
||||
</if>
|
||||
</where>
|
||||
ORDER BY T.tableName
|
||||
</select>
|
||||
|
||||
<sql id="queryColumn">
|
||||
SELECT
|
||||
'mssql' AS dbType,
|
||||
CAST ( b.NAME AS NVARCHAR ( 500 ) ) AS columnName,
|
||||
CAST ( sys.types.NAME AS NVARCHAR ( 500 ) ) AS dataType,
|
||||
CAST ( sys.types.NAME AS NVARCHAR ( 500 ) ) AS columnType,
|
||||
CAST ( c.VALUE AS NVARCHAR ( 500 ) ) AS comments,
|
||||
(
|
||||
SELECT
|
||||
CASE
|
||||
COUNT
|
||||
( 1 )
|
||||
WHEN 1 THEN
|
||||
'PRI' ELSE ''
|
||||
END
|
||||
FROM
|
||||
syscolumns,
|
||||
sysobjects,
|
||||
sysindexes,
|
||||
sysindexkeys,
|
||||
systypes
|
||||
WHERE
|
||||
syscolumns.xusertype = systypes.xusertype
|
||||
AND syscolumns.id = object_id( A.NAME )
|
||||
AND sysobjects.xtype = 'PK'
|
||||
AND sysobjects.parent_obj = syscolumns.id
|
||||
AND sysindexes.id = syscolumns.id
|
||||
AND sysobjects.NAME = sysindexes.NAME
|
||||
AND sysindexkeys.id = syscolumns.id
|
||||
AND sysindexkeys.indid = sysindexes.indid
|
||||
AND syscolumns.colid = sysindexkeys.colid
|
||||
AND syscolumns.NAME = B.NAME
|
||||
) AS columnKey,
|
||||
'' AS extra
|
||||
FROM
|
||||
(
|
||||
SELECT
|
||||
name,
|
||||
object_id
|
||||
FROM
|
||||
sys.tables UNION ALL
|
||||
SELECT
|
||||
name,
|
||||
object_id
|
||||
FROM
|
||||
sys.views
|
||||
) a
|
||||
INNER JOIN sys.COLUMNS b ON b.object_id = a.object_id
|
||||
LEFT JOIN sys.types ON b.user_type_id = sys.types.user_type_id
|
||||
LEFT JOIN sys.extended_properties c ON c.major_id = b.object_id
|
||||
AND c.minor_id = b.column_id
|
||||
WHERE a.NAME = #{tableName} and sys.types.NAME != 'sysname'
|
||||
</sql>
|
||||
|
||||
<select id="selectTableColumn" resultType="com.pig4cloud.pigx.codegen.entity.ColumnEntity">
|
||||
<include refid="queryColumn"/>
|
||||
</select>
|
||||
|
||||
<select id="selectMapTableColumn" resultType="map">
|
||||
<include refid="queryColumn"/>
|
||||
</select>
|
||||
|
||||
</mapper>
|
||||
+49
@@ -0,0 +1,49 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
|
||||
<mapper namespace="com.pig4cloud.pigx.codegen.mapper.GeneratorMySqlMapper">
|
||||
|
||||
<select id="queryTable" resultType="map">
|
||||
SELECT
|
||||
'mysql' AS dbType,
|
||||
table_name AS tableName,
|
||||
ENGINE,
|
||||
table_comment AS tableComment,
|
||||
create_time AS createTime
|
||||
FROM
|
||||
information_schema.TABLES
|
||||
WHERE
|
||||
table_schema = (
|
||||
SELECT DATABASE
|
||||
())
|
||||
<if test="tableName != null and tableName.trim() != ''">
|
||||
and table_name like concat('%', #{tableName}, '%')
|
||||
</if>
|
||||
order by create_time desc
|
||||
</select>
|
||||
|
||||
|
||||
<sql id="queryColumn">
|
||||
SELECT
|
||||
column_name columnName,
|
||||
data_type dataType,
|
||||
column_comment comments,
|
||||
column_key columnKey,
|
||||
extra,
|
||||
is_nullable AS isNullable,
|
||||
column_type AS columnType
|
||||
FROM
|
||||
information_schema.COLUMNS
|
||||
WHERE
|
||||
table_name = #{tableName} and table_schema = (select database()) order by ordinal_position
|
||||
</sql>
|
||||
|
||||
<select id="selectTableColumn" resultType="com.pig4cloud.pigx.codegen.entity.ColumnEntity">
|
||||
<include refid="queryColumn"/>
|
||||
</select>
|
||||
|
||||
<select id="selectMapTableColumn" resultType="map">
|
||||
<include refid="queryColumn"/>
|
||||
</select>
|
||||
|
||||
</mapper>
|
||||
+72
@@ -0,0 +1,72 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
|
||||
<mapper namespace="com.pig4cloud.pigx.codegen.mapper.GeneratorOracleMapper">
|
||||
|
||||
<select id="queryTable" resultType="map">
|
||||
SELECT
|
||||
ut.TABLE_NAME AS "tableName",
|
||||
utc.comments AS "tableComment"
|
||||
FROM
|
||||
user_tables ut,
|
||||
user_tab_comments utc
|
||||
WHERE
|
||||
ut.TABLE_NAME = utc.TABLE_NAME
|
||||
<if test="tableName != null and tableName.trim() != ''">
|
||||
and ut.TABLE_NAME = UPPER ( #{tableName} )
|
||||
</if>
|
||||
ORDER BY ut.TABLE_NAME
|
||||
</select>
|
||||
|
||||
<sql id="queryColumn">
|
||||
SELECT
|
||||
'oracle' AS "dbType",
|
||||
TEMP.COLUMN_NAME AS "columnName",
|
||||
TEMP.data_type AS "columnType",
|
||||
TEMP.data_type AS "dataType",
|
||||
TEMP.comments AS comments,
|
||||
CASE
|
||||
TEMP.constraint_type
|
||||
WHEN 'P' THEN
|
||||
'PRI'
|
||||
WHEN 'C' THEN
|
||||
'UNI' ELSE''
|
||||
END "COLUMNKEY"
|
||||
FROM
|
||||
(
|
||||
SELECT
|
||||
col.column_id,
|
||||
col.COLUMN_NAME,
|
||||
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
|
||||
</sql>
|
||||
|
||||
<select id="selectTableColumn" resultType="com.pig4cloud.pigx.codegen.entity.ColumnEntity">
|
||||
<include refid="queryColumn"/>
|
||||
</select>
|
||||
|
||||
<select id="selectMapTableColumn" resultType="map">
|
||||
<include refid="queryColumn"/>
|
||||
</select>
|
||||
|
||||
</mapper>
|
||||
@@ -0,0 +1,57 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
|
||||
<mapper namespace="com.pig4cloud.pigx.codegen.mapper.GeneratorPgMapper">
|
||||
|
||||
<select id="queryTable" resultType="map">
|
||||
SELECT
|
||||
relname AS "tableName",
|
||||
obj_description ( oid ) AS "tableComment"
|
||||
FROM
|
||||
pg_class pc
|
||||
WHERE
|
||||
relkind = 'r'
|
||||
AND relname NOT LIKE'pg_%'
|
||||
AND relname NOT LIKE'sql_%'
|
||||
AND relchecks = 0
|
||||
<if test="tableName != null and tableName.trim() != ''">
|
||||
and pc.relname like concat('%', #{tableName}, '%')
|
||||
</if>
|
||||
ORDER BY relname
|
||||
</select>
|
||||
|
||||
|
||||
<sql id="queryColumn">
|
||||
SELECT
|
||||
'pg' AS "dbType",
|
||||
pa.attname AS "columnName",
|
||||
pg_type.typname AS "columnType",
|
||||
pg_type.typname AS "dataType",
|
||||
col_description ( pa.attrelid, pa.attnum ) AS "comments",
|
||||
(
|
||||
CASE
|
||||
pcon.contype
|
||||
WHEN 'p' THEN
|
||||
'PRI' ELSE''
|
||||
END
|
||||
) AS "columnKey"
|
||||
FROM
|
||||
pg_class AS pc,
|
||||
pg_attribute AS pa
|
||||
INNER JOIN pg_type ON pg_type.oid = pa.atttypid
|
||||
LEFT JOIN pg_constraint pcon ON pa.attnum = pcon.conkey[1]
|
||||
AND pa.attrelid = pcon.conrelid
|
||||
WHERE
|
||||
pc.relname = #{ tableName }
|
||||
AND pa.attrelid = pc.oid
|
||||
AND pa.attnum > 0;
|
||||
</sql>
|
||||
|
||||
<select id="selectTableColumn" resultType="com.pig4cloud.pigx.codegen.entity.ColumnEntity">
|
||||
<include refid="queryColumn"/>
|
||||
</select>
|
||||
|
||||
<select id="selectMapTableColumn" resultType="map">
|
||||
<include refid="queryColumn"/>
|
||||
</select>
|
||||
</mapper>
|
||||
Reference in new issue
Block a user