提交 | 用户 | 时间
|
722af2
|
1 |
<?xml version="1.0" encoding="UTF-8" ?> |
X |
2 |
<!DOCTYPE mapper |
|
3 |
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" |
|
4 |
"http://mybatis.org/dtd/mybatis-3-mapper.dtd"> |
|
5 |
<mapper namespace="com.dl.generator.mapper.GenTableColumnMapper"> |
|
6 |
|
|
7 |
<resultMap type="GenTableColumn" id="GenTableColumnResult"> |
|
8 |
<id property="columnId" column="column_id" /> |
|
9 |
<result property="tableId" column="table_id" /> |
|
10 |
<result property="columnName" column="column_name" /> |
|
11 |
<result property="columnComment" column="column_comment" /> |
|
12 |
<result property="columnType" column="column_type" /> |
|
13 |
<result property="javaType" column="java_type" /> |
|
14 |
<result property="javaField" column="java_field" /> |
|
15 |
<result property="isPk" column="is_pk" /> |
|
16 |
<result property="isIncrement" column="is_increment" /> |
|
17 |
<result property="isRequired" column="is_required" /> |
|
18 |
<result property="isInsert" column="is_insert" /> |
|
19 |
<result property="isEdit" column="is_edit" /> |
|
20 |
<result property="isList" column="is_list" /> |
|
21 |
<result property="isQuery" column="is_query" /> |
|
22 |
<result property="queryType" column="query_type" /> |
|
23 |
<result property="htmlType" column="html_type" /> |
|
24 |
<result property="dictType" column="dict_type" /> |
|
25 |
<result property="sort" column="sort" /> |
|
26 |
<result property="createBy" column="create_by" /> |
|
27 |
<result property="createTime" column="create_time" /> |
|
28 |
<result property="updateBy" column="update_by" /> |
|
29 |
<result property="updateTime" column="update_time" /> |
|
30 |
</resultMap> |
|
31 |
|
|
32 |
<select id="selectDbTableColumnsByName" parameterType="String" resultMap="GenTableColumnResult"> |
|
33 |
<if test="@com.dl.common.helper.DataBaseHelper@isMySql()"> |
|
34 |
select column_name, |
|
35 |
(case when (is_nullable = 'no' <![CDATA[ && ]]> column_key != 'PRI') then '1' else null end) as is_required, |
|
36 |
(case when column_key = 'PRI' then '1' else '0' end) as is_pk, |
|
37 |
ordinal_position as sort, |
|
38 |
column_comment, |
|
39 |
(case when extra = 'auto_increment' then '1' else '0' end) as is_increment, |
|
40 |
column_type |
|
41 |
from information_schema.columns where table_schema = (select database()) and table_name = (#{tableName}) |
|
42 |
order by ordinal_position |
|
43 |
</if> |
|
44 |
<if test="@com.dl.common.helper.DataBaseHelper@isOracle()"> |
|
45 |
select lower(temp.column_name) as column_name, |
|
46 |
(case when (temp.nullable = 'N' and temp.constraint_type != 'P') then '1' else null end) as is_required, |
|
47 |
(case when temp.constraint_type = 'P' then '1' else '0' end) as is_pk, |
|
48 |
temp.column_id as sort, |
|
49 |
temp.comments as column_comment, |
|
50 |
(case when temp.constraint_type = 'P' then '1' else '0' end) as is_increment, |
|
51 |
lower(temp.data_type) as column_type |
|
52 |
from ( |
|
53 |
select col.column_id, col.column_name,col.nullable, col.data_type, colc.comments, uc.constraint_type, row_number() |
|
54 |
over (partition by col.column_name order by uc.constraint_type desc) as row_flg |
|
55 |
from user_tab_columns col |
|
56 |
left join user_col_comments colc on colc.table_name = col.table_name and colc.column_name = col.column_name |
|
57 |
left join user_cons_columns ucc on ucc.table_name = col.table_name and ucc.column_name = col.column_name |
|
58 |
left join user_constraints uc on uc.constraint_name = ucc.constraint_name |
|
59 |
where col.table_name = upper(#{tableName}) |
|
60 |
) temp |
|
61 |
WHERE temp.row_flg = 1 |
|
62 |
ORDER BY temp.column_id |
|
63 |
</if> |
|
64 |
<if test="@com.dl.common.helper.DataBaseHelper@isPostgerSql()"> |
|
65 |
SELECT column_name, is_required, is_pk, sort, column_comment, is_increment, column_type |
|
66 |
FROM ( |
|
67 |
SELECT c.relname AS table_name, |
|
68 |
a.attname AS column_name, |
|
69 |
d.description AS column_comment, |
|
70 |
CASE WHEN a.attnotnull AND con.conname IS NULL THEN 1 ELSE 0 |
|
71 |
END AS is_required, |
|
72 |
CASE WHEN con.conname IS NOT NULL THEN 1 ELSE 0 |
|
73 |
END AS is_pk, |
|
74 |
a.attnum AS sort, |
|
75 |
CASE WHEN "position"(pg_get_expr(ad.adbin, ad.adrelid), |
|
76 |
((c.relname::text || '_'::text) || a.attname::text) || '_seq'::text) > 0 THEN 1 ELSE 0 |
|
77 |
END AS is_increment, |
|
78 |
btrim( |
|
79 |
CASE WHEN t.typelem <![CDATA[ <> ]]> 0::oid AND t.typlen = '-1'::integer THEN 'ARRAY'::text ELSE |
|
80 |
CASE WHEN t.typtype = 'd'::"char" THEN format_type(t.typbasetype, NULL::integer) |
|
81 |
ELSE format_type(a.atttypid, NULL::integer) END |
|
82 |
END, '"'::text |
|
83 |
) AS column_type |
|
84 |
FROM pg_attribute a |
|
85 |
JOIN (pg_class c JOIN pg_namespace n ON c.relnamespace = n.oid) ON a.attrelid = c.oid |
|
86 |
LEFT JOIN pg_description d ON d.objoid = c.oid AND a.attnum = d.objsubid |
|
87 |
LEFT JOIN pg_constraint con ON con.conrelid = c.oid AND (a.attnum = ANY (con.conkey)) |
|
88 |
LEFT JOIN pg_attrdef ad ON a.attrelid = ad.adrelid AND a.attnum = ad.adnum |
|
89 |
LEFT JOIN pg_type t ON a.atttypid = t.oid |
|
90 |
WHERE (c.relkind = ANY (ARRAY ['r'::"char", 'p'::"char"])) |
|
91 |
AND a.attnum > 0 |
|
92 |
AND n.nspname = 'public'::name |
|
93 |
ORDER BY c.relname, a.attnum |
|
94 |
) temp |
|
95 |
WHERE table_name = (#{tableName}) |
|
96 |
AND column_type <![CDATA[ <> ]]> '-' |
|
97 |
</if> |
|
98 |
<if test="@com.dl.common.helper.DataBaseHelper@isSqlServer()"> |
|
99 |
SELECT |
|
100 |
cast(A.NAME as nvarchar) as column_name, |
|
101 |
cast(B.NAME as nvarchar) + (case when B.NAME = 'numeric' then '(' + cast(A.prec as nvarchar) + ',' + cast(A.scale as nvarchar) + ')' else '' end) as column_type, |
|
102 |
cast(G.[VALUE] as nvarchar) as column_comment, |
|
103 |
(SELECT 1 FROM INFORMATION_SCHEMA.KEY_COLUMN_USAGE Z WHERE TABLE_NAME = D.NAME and A.NAME = Z.column_name ) as is_pk, |
|
104 |
colorder as sort |
|
105 |
FROM SYSCOLUMNS A |
|
106 |
LEFT JOIN SYSTYPES B ON A.XTYPE = B.XUSERTYPE |
|
107 |
INNER JOIN SYSOBJECTS D ON A.ID = D.ID AND D.XTYPE='U' AND D.NAME != 'DTPROPERTIES' |
|
108 |
LEFT JOIN SYS.EXTENDED_PROPERTIES G ON A.ID = G.MAJOR_ID AND A.COLID = G.MINOR_ID |
|
109 |
LEFT JOIN SYS.EXTENDED_PROPERTIES F ON D.ID = F.MAJOR_ID AND F.MINOR_ID = 0 |
|
110 |
WHERE D.NAME = #{tableName} |
|
111 |
ORDER BY A.COLORDER |
|
112 |
</if> |
|
113 |
</select> |
|
114 |
|
|
115 |
</mapper> |