You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@dolphinscheduler.apache.org by we...@apache.org on 2022/08/28 12:58:27 UTC
[dolphinscheduler] branch dev updated: [Improvement-11662][dao] fix foreach null items in mapper.xml
This is an automated email from the ASF dual-hosted git repository.
wenjun pushed a commit to branch dev
in repository https://gitbox.apache.org/repos/asf/dolphinscheduler.git
The following commit(s) were added to refs/heads/dev by this push:
new 6a5367fd57 [Improvement-11662][dao] fix foreach null items in mapper.xml
6a5367fd57 is described below
commit 6a5367fd57977305ff0c734d8103430ba15acaec
Author: SongTao Zhuang <51...@users.noreply.github.com>
AuthorDate: Sun Aug 28 20:58:12 2022 +0800
[Improvement-11662][dao] fix foreach null items in mapper.xml
---
.../dao/mapper/AlertPluginInstanceMapper.xml | 12 ++--
.../dao/mapper/ProcessInstanceMapper.xml | 71 +++++++++++++---------
.../dolphinscheduler/dao/mapper/ResourceMapper.xml | 21 ++++---
.../dao/mapper/ResourceUserMapper.xml | 10 +--
.../dolphinscheduler/dao/mapper/ScheduleMapper.xml | 10 +--
.../dao/mapper/TaskInstanceMapper.xml | 10 +--
.../dolphinscheduler/dao/mapper/UserMapper.xml | 10 +--
7 files changed, 87 insertions(+), 57 deletions(-)
diff --git a/dolphinscheduler-dao/src/main/resources/org/apache/dolphinscheduler/dao/mapper/AlertPluginInstanceMapper.xml b/dolphinscheduler-dao/src/main/resources/org/apache/dolphinscheduler/dao/mapper/AlertPluginInstanceMapper.xml
index fe25d8d1a3..d79731fb02 100644
--- a/dolphinscheduler-dao/src/main/resources/org/apache/dolphinscheduler/dao/mapper/AlertPluginInstanceMapper.xml
+++ b/dolphinscheduler-dao/src/main/resources/org/apache/dolphinscheduler/dao/mapper/AlertPluginInstanceMapper.xml
@@ -36,11 +36,13 @@
select
<include refid="baseSql"/>
from t_ds_alert_plugin_instance
- where id in
- <foreach item="item" index="index" collection="ids"
- open="(" separator="," close=")">
- #{item}
- </foreach>
+ <if test="ids != null and ids.size() != 0">
+ where id in
+ <foreach item="item" index="index" collection="ids"
+ open="(" separator="," close=")">
+ #{item}
+ </foreach>
+ </if>
</select>
<select id="queryByInstanceNamePage" resultType="org.apache.dolphinscheduler.dao.entity.AlertPluginInstance">
diff --git a/dolphinscheduler-dao/src/main/resources/org/apache/dolphinscheduler/dao/mapper/ProcessInstanceMapper.xml b/dolphinscheduler-dao/src/main/resources/org/apache/dolphinscheduler/dao/mapper/ProcessInstanceMapper.xml
index d77e3cc4d8..0b44f6b027 100644
--- a/dolphinscheduler-dao/src/main/resources/org/apache/dolphinscheduler/dao/mapper/ProcessInstanceMapper.xml
+++ b/dolphinscheduler-dao/src/main/resources/org/apache/dolphinscheduler/dao/mapper/ProcessInstanceMapper.xml
@@ -40,19 +40,23 @@
<if test="host != null and host != ''">
and host=#{host}
</if>
- and state in
- <foreach collection="states" item="i" open="(" close=")" separator=",">
- #{i}
- </foreach>
+ <if test="states != null and states.length != 0">
+ and state in
+ <foreach collection="states" item="i" open="(" close=")" separator=",">
+ #{i}
+ </foreach>
+ </if>
order by id asc
</select>
<select id="queryNeedFailoverProcessInstanceHost" resultType="String">
select distinct host
from t_ds_process_instance
- where state in
- <foreach collection="states" item="i" open="(" close=")" separator=",">
- #{i}
- </foreach>
+ <if test="states != null and states.length != 0">
+ where state in
+ <foreach collection="states" item="i" open="(" close=")" separator=",">
+ #{i}
+ </foreach>
+ </if>
</select>
<select id="queryTopNProcessInstance" resultType="org.apache.dolphinscheduler.dao.entity.ProcessInstance">
@@ -77,10 +81,12 @@
<if test="tenantId != -1">
and tenant_id =#{tenantId}
</if>
- and state in
- <foreach collection="states" item="i" open="(" close=")" separator=",">
- #{i}
- </foreach>
+ <if test="states != null and states.length != 0">
+ and state in
+ <foreach collection="states" item="i" open="(" close=")" separator=",">
+ #{i}
+ </foreach>
+ </if>
order by id asc
</select>
@@ -92,10 +98,12 @@
<if test="workerGroupName != ''">
and worker_group =#{workerGroupName}
</if>
- and state in
- <foreach collection="states" item="i" open="(" close=")" separator=",">
- #{i}
- </foreach>
+ <if test="states != null and states.length != 0">
+ and state in
+ <foreach collection="states" item="i" open="(" close=")" separator=",">
+ #{i}
+ </foreach>
+ </if>
order by id asc
</select>
@@ -134,10 +142,13 @@
<update id="setFailoverByHostAndStateArray">
update t_ds_process_instance
set host=null
- where host =#{host} and state in
- <foreach collection="states" index="index" item="i" open="(" close=")" separator=",">
- #{i}
- </foreach>
+ where host =#{host}
+ <if test="states != null and states.length != 0">
+ and state in
+ <foreach collection="states" index="index" item="i" open="(" close=")" separator=",">
+ #{i}
+ </foreach>
+ </if>
</update>
<update id="updateProcessInstanceByState">
update t_ds_process_instance
@@ -225,10 +236,12 @@
<include refid="baseSql"/>
from t_ds_process_instance
where process_definition_code=#{processDefinitionCode}
- and state in
- <foreach collection="states" item="i" open="(" close=")" separator=",">
- #{i}
- </foreach>
+ <if test="states != null and states.length != 0">
+ and state in
+ <foreach collection="states" item="i" open="(" close=")" separator=",">
+ #{i}
+ </foreach>
+ </if>
order by id asc
</select>
<select id="queryByProcessDefineCodeAndProcessDefinitionVersionAndStatusAndNextId" resultType="org.apache.dolphinscheduler.dao.entity.ProcessInstance">
@@ -237,10 +250,12 @@
from t_ds_process_instance
where process_definition_code=#{processDefinitionCode}
and process_definition_version = #{processDefinitionVersion}
- and state in
- <foreach collection="states" item="i" open="(" close=")" separator=",">
- #{i}
- </foreach>
+ <if test="states != null and states.length != 0">
+ and state in
+ <foreach collection="states" item="i" open="(" close=")" separator=",">
+ #{i}
+ </foreach>
+ </if>
and next_process_instance_id=0
and id <![CDATA[ < ]]> #{id}
order by id desc
diff --git a/dolphinscheduler-dao/src/main/resources/org/apache/dolphinscheduler/dao/mapper/ResourceMapper.xml b/dolphinscheduler-dao/src/main/resources/org/apache/dolphinscheduler/dao/mapper/ResourceMapper.xml
index 416b78e6d3..a87aac4b7b 100644
--- a/dolphinscheduler-dao/src/main/resources/org/apache/dolphinscheduler/dao/mapper/ResourceMapper.xml
+++ b/dolphinscheduler-dao/src/main/resources/org/apache/dolphinscheduler/dao/mapper/ResourceMapper.xml
@@ -129,10 +129,13 @@
</select>
<delete id="deleteIds" parameterType="java.lang.Integer">
- delete from t_ds_resources where id in
- <foreach collection="resIds" item="i" open="(" close=")" separator=",">
- #{i}
- </foreach>
+ delete from t_ds_resources
+ <if test="resIds != null and resIds.length != 0">
+ where id in
+ <foreach collection="resIds" item="i" open="(" close=")" separator=",">
+ #{i}
+ </foreach>
+ </if>
</delete>
<select id="listChildren" resultType="java.lang.Integer">
@@ -170,10 +173,12 @@
<property name="alias" value="r"/>
</include>
from t_ds_resources r
- where r.id in
- <foreach collection="resIds" item="i" open="(" close=")" separator=",">
- #{i}
- </foreach>
+ <if test="resIds != null and resIds.length != 0">
+ where r.id in
+ <foreach collection="resIds" item="i" open="(" close=")" separator=",">
+ #{i}
+ </foreach>
+ </if>
</select>
<select id="existResourceByUser" resultType="java.lang.Boolean">
diff --git a/dolphinscheduler-dao/src/main/resources/org/apache/dolphinscheduler/dao/mapper/ResourceUserMapper.xml b/dolphinscheduler-dao/src/main/resources/org/apache/dolphinscheduler/dao/mapper/ResourceUserMapper.xml
index d5500b40dc..6afdcfc794 100644
--- a/dolphinscheduler-dao/src/main/resources/org/apache/dolphinscheduler/dao/mapper/ResourceUserMapper.xml
+++ b/dolphinscheduler-dao/src/main/resources/org/apache/dolphinscheduler/dao/mapper/ResourceUserMapper.xml
@@ -51,9 +51,11 @@
<if test="userId != 0">
and user_id = #{userId}
</if>
- and resources_id in
- <foreach collection="resIds" item="i" open="(" close=")" separator=",">
- #{i}
- </foreach>
+ <if test="resIds != null and resIds.length != 0">
+ and resources_id in
+ <foreach collection="resIds" item="i" open="(" close=")" separator=",">
+ #{i}
+ </foreach>
+ </if>
</delete>
</mapper>
\ No newline at end of file
diff --git a/dolphinscheduler-dao/src/main/resources/org/apache/dolphinscheduler/dao/mapper/ScheduleMapper.xml b/dolphinscheduler-dao/src/main/resources/org/apache/dolphinscheduler/dao/mapper/ScheduleMapper.xml
index b22ac9f5a4..7558926eeb 100644
--- a/dolphinscheduler-dao/src/main/resources/org/apache/dolphinscheduler/dao/mapper/ScheduleMapper.xml
+++ b/dolphinscheduler-dao/src/main/resources/org/apache/dolphinscheduler/dao/mapper/ScheduleMapper.xml
@@ -75,10 +75,12 @@
select
<include refid="baseSql"/>
from t_ds_schedules
- where process_definition_code in
- <foreach collection="processDefinitionCodeList" item="code" index="index" open="(" close=")" separator=",">
- #{code}
- </foreach>
+ <if test="processDefinitionCodeList != null and processDefinitionCodeList.size() != 0">
+ where process_definition_code in
+ <foreach collection="processDefinitionCodeList" item="code" index="index" open="(" close=")" separator=",">
+ #{code}
+ </foreach>
+ </if>
</select>
<select id="queryReleaseSchedulerListByProcessDefinitionCode"
diff --git a/dolphinscheduler-dao/src/main/resources/org/apache/dolphinscheduler/dao/mapper/TaskInstanceMapper.xml b/dolphinscheduler-dao/src/main/resources/org/apache/dolphinscheduler/dao/mapper/TaskInstanceMapper.xml
index 0ba80db75f..aa13818213 100644
--- a/dolphinscheduler-dao/src/main/resources/org/apache/dolphinscheduler/dao/mapper/TaskInstanceMapper.xml
+++ b/dolphinscheduler-dao/src/main/resources/org/apache/dolphinscheduler/dao/mapper/TaskInstanceMapper.xml
@@ -34,10 +34,12 @@
update t_ds_task_instance
set state = #{destStatus}
where host = #{host}
- and state in
- <foreach collection="states" index="index" item="i" open="(" separator="," close=")">
- #{i}
- </foreach>
+ <if test="states != null and states.length != 0">
+ and state in
+ <foreach collection="states" index="index" item="i" open="(" separator="," close=")">
+ #{i}
+ </foreach>
+ </if>
</update>
<select id="queryTaskByProcessIdAndState" resultType="java.lang.Integer">
select id
diff --git a/dolphinscheduler-dao/src/main/resources/org/apache/dolphinscheduler/dao/mapper/UserMapper.xml b/dolphinscheduler-dao/src/main/resources/org/apache/dolphinscheduler/dao/mapper/UserMapper.xml
index f6b216195c..807a296974 100644
--- a/dolphinscheduler-dao/src/main/resources/org/apache/dolphinscheduler/dao/mapper/UserMapper.xml
+++ b/dolphinscheduler-dao/src/main/resources/org/apache/dolphinscheduler/dao/mapper/UserMapper.xml
@@ -118,10 +118,12 @@
<select id="selectByIds" resultType="org.apache.dolphinscheduler.dao.entity.User">
select *
from t_ds_user
- where id in
- <foreach item="id" index="index" collection="ids" open="(" separator="," close=")">
- #{id}
- </foreach>
+ <if test="ids != null and ids.size() != 0">
+ where id in
+ <foreach item="id" index="index" collection="ids" open="(" separator="," close=")">
+ #{id}
+ </foreach>
+ </if>
</select>
<select id="queryAuthedUserListByProjectId" resultType="org.apache.dolphinscheduler.dao.entity.User">
select