فهرست منبع

mysql转oracle数据库相关代码修改

wangggziwen 1 ماه پیش
والد
کامیت
8a682bf21e

+ 18 - 3
rc-generator/src/main/resources/mapper/generator/GenTableColumnMapper.xml

@@ -40,9 +40,24 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
     </select>
 
     <select id="selectDbTableColumnsByName" parameterType="String" resultMap="GenTableColumnResult">
-		select column_name, (case when (is_nullable = 'no' <![CDATA[ && ]]> column_key != 'PRI') then '1' else '0' 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_schema = (select database()) and table_name = (#{tableName})
-		order by ordinal_position
+		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
+                 where col.table_name = upper(#{tableName})
+                  ) temp
+           WHERE temp.row_flg = 1
+          ORDER BY temp.column_id
 	</select>
 
     <insert id="insertGenTableColumn" parameterType="GenTableColumn">

+ 35 - 29
rc-generator/src/main/resources/mapper/generator/GenTableMapper.xml

@@ -67,48 +67,54 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
 			<if test="tableComment != null and tableComment != ''">
 				AND lower(table_comment) like lower(concat('%', #{tableComment}, '%'))
 			</if>
-			<if test="params.beginTime != null and params.beginTime != ''"><!-- 开始时间检索 -->
-				AND date_format(create_time,'%Y%m%d') &gt;= date_format(#{params.beginTime},'%Y%m%d')
-			</if>
-			<if test="params.endTime != null and params.endTime != ''"><!-- 结束时间检索 -->
-				AND date_format(create_time,'%Y%m%d') &lt;= date_format(#{params.endTime},'%Y%m%d')
-			</if>
+			<!--<if test="params.beginTime != null and params.beginTime != ''">&lt;!&ndash; 开始时间检索 &ndash;&gt;-->
+				<!--AND date_format(create_time,'%Y%m%d') &gt;= date_format(#{params.beginTime},'%Y%m%d')-->
+			<!--</if>-->
+			<!--<if test="params.endTime != null and params.endTime != ''">&lt;!&ndash; 结束时间检索 &ndash;&gt;-->
+				<!--AND date_format(create_time,'%Y%m%d') &lt;= date_format(#{params.endTime},'%Y%m%d')-->
+			<!--</if>-->
 		</where>
 	</select>
 
 	<select id="selectDbTableList" parameterType="GenTable" resultMap="GenTableResult">
-		select table_name, table_comment, create_time, update_time from information_schema.tables
-		where table_schema = (select database())
-		AND table_name NOT LIKE 'qrtz\_%' AND table_name NOT LIKE 'gen\_%'
-		AND table_name NOT IN (select CONVERT(table_name USING utf8) COLLATE utf8_unicode_ci from gen_table)
+		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
+		where dt.table_name = dtc.table_name
+		and dt.table_name = uo.object_name
+		and uo.object_type = 'TABLE'
+		AND dt.table_name NOT LIKE 'QRTZ_%' AND dt.table_name NOT LIKE 'GEN_%'
+		AND lower(dt.table_name) NOT IN (select table_name from gen_table)
 		<if test="tableName != null and tableName != ''">
-			AND lower(table_name) like lower(concat('%', #{tableName}, '%'))
+			AND lower(dt.table_name)  like lower(concat(concat('%', #{tableName}), '%'))
 		</if>
 		<if test="tableComment != null and tableComment != ''">
-			AND lower(table_comment) like lower(concat('%', #{tableComment}, '%'))
-		</if>
-		<if test="params.beginTime != null and params.beginTime != ''"><!-- 开始时间检索 -->
-			AND date_format(create_time,'%Y%m%d') &gt;= date_format(#{params.beginTime},'%Y%m%d')
+			AND lower(dtc.comments) like lower(concat(concat('%', #{tableComment}), '%'))
 		</if>
-		<if test="params.endTime != null and params.endTime != ''"><!-- 结束时间检索 -->
-			AND date_format(create_time,'%Y%m%d') &lt;= date_format(#{params.endTime},'%Y%m%d')
-		</if>
-        order by create_time desc
 	</select>
 	
 	<select id="selectDbTableListByNames" resultMap="GenTableResult">
-		select table_name, table_comment, create_time, update_time from information_schema.tables
-		where table_name NOT LIKE 'qrtz\_%' and table_name NOT LIKE 'gen\_%' and table_schema = (select database())
-		and table_name in
-	    <foreach collection="array" item="name" open="(" separator="," close=")">
- 			#{name}
-        </foreach> 
+		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
+		where dt.table_name = dtc.table_name
+		and dt.table_name = uo.object_name
+		and uo.object_type = 'TABLE'
+		AND dt.table_name NOT LIKE 'QRTZ_%' AND dt.table_name NOT LIKE 'GEN_%'
+		AND dt.table_name NOT IN (select table_name from gen_table)
+		and lower(dt.table_name) in
+		<foreach collection="array" item="name" open="(" separator="," close=")">
+			#{name}
+		</foreach>
 	</select>
 	
 	<select id="selectTableByName" parameterType="String" resultMap="GenTableResult">
-		select table_name, table_comment, create_time, update_time from information_schema.tables
-		where table_comment <![CDATA[ <> ]]> '' and table_schema = (select database())
-		and table_name = #{tableName}
+		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
+		where dt.table_name = dtc.table_name
+		and dt.table_name = uo.object_name
+		and uo.object_type = 'TABLE'
+		AND dt.table_name NOT LIKE 'QRTZ_%' AND dt.table_name NOT LIKE 'GEN_%'
+		AND dt.table_name NOT IN (select table_name from gen_table)
+		and lower(dt.table_name) = #{tableName}
 	</select>
 	
 	<select id="selectGenTableById" parameterType="Long" resultMap="GenTableResult">
@@ -120,7 +126,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
 	</select>
 	
 	<select id="selectGenTableByName" parameterType="String" resultMap="GenTableResult">
-	    SELECT t.table_id, t.table_name, t.table_comment, t.sub_table_name, t.sub_table_fk_name, t.class_name, t.tpl_category, t.tpl_web_type, t.package_name, t.module_name, t.business_name, t.function_name, t.function_author, t.gen_type, t.gen_path, t.options, t.remark,
+	    SELECT t.table_id, t.table_name, t.table_comment, t.class_name, t.tpl_category, t.package_name, t.module_name, t.business_name, t.function_name, t.function_author, t.gen_type, t.gen_path, t.options, t.remark,
 			   c.column_id, c.column_name, c.column_comment, c.column_type, c.java_type, c.java_field, c.is_pk, c.is_increment, c.is_required, c.is_insert, c.is_edit, c.is_list, c.is_query, c.query_type, c.html_type, c.dict_type, c.sort
 		FROM gen_table t
 			 LEFT JOIN gen_table_column c ON t.table_id = c.table_id