Skip to content

Commit 66ae1ed

Browse files
Add safe query support for process and case instance ids
1 parent 4768a35 commit 66ae1ed

File tree

13 files changed

+138
-28
lines changed

13 files changed

+138
-28
lines changed

modules/flowable-cmmn-engine/src/main/java/org/flowable/cmmn/engine/impl/history/HistoricCaseInstanceQueryImpl.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ public class HistoricCaseInstanceQueryImpl extends AbstractVariableQueryImpl<His
6666
protected Integer caseDefinitionVersion;
6767
protected String caseInstanceId;
6868
protected Set<String> caseInstanceIds;
69+
private List<List<String>> safeCaseInstanceIds;
6970
protected String caseInstanceName;
7071
protected String caseInstanceNameLike;
7172
protected String caseInstanceNameLikeIgnoreCase;
@@ -1441,6 +1442,14 @@ public boolean isNeedsCaseDefinitionOuterJoin() {
14411442
return hasOrderByForColumn(HistoricCaseInstanceQueryProperty.CASE_DEFINITION_KEY.getName());
14421443
}
14431444

1445+
public List<List<String>> getSafeCaseInstanceIds() {
1446+
return safeCaseInstanceIds;
1447+
}
1448+
1449+
public void setSafeCaseInstanceIds(List<List<String>> safeCaseInstanceIds) {
1450+
this.safeCaseInstanceIds = safeCaseInstanceIds;
1451+
}
1452+
14441453
public List<List<String>> getSafeInvolvedGroups() {
14451454
return safeInvolvedGroups;
14461455
}

modules/flowable-cmmn-engine/src/main/java/org/flowable/cmmn/engine/impl/persistence/entity/data/impl/MybatisCaseInstanceDataManagerImpl.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,10 @@ public void clearAllLockTimes(String lockOwner) {
214214
}
215215

216216
protected void setSafeInValueLists(CaseInstanceQueryImpl caseInstanceQuery) {
217+
if (caseInstanceQuery.getCaseInstanceIds() != null) {
218+
caseInstanceQuery.setSafeCaseInstanceIds(createSafeInValuesList(caseInstanceQuery.getCaseInstanceIds()));
219+
}
220+
217221
if (caseInstanceQuery.getInvolvedGroups() != null) {
218222
caseInstanceQuery.setSafeInvolvedGroups(createSafeInValuesList(caseInstanceQuery.getInvolvedGroups()));
219223
}

modules/flowable-cmmn-engine/src/main/java/org/flowable/cmmn/engine/impl/persistence/entity/data/impl/MybatisHistoricCaseInstanceDataManagerImpl.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,10 @@ public void bulkDeleteHistoricCaseInstances(Collection<String> caseInstanceIds)
105105
}
106106

107107
protected void setSafeInValueLists(HistoricCaseInstanceQueryImpl caseInstanceQuery) {
108+
if (caseInstanceQuery.getCaseInstanceIds() != null) {
109+
caseInstanceQuery.setSafeCaseInstanceIds(createSafeInValuesList(caseInstanceQuery.getCaseInstanceIds()));
110+
}
111+
108112
if (caseInstanceQuery.getInvolvedGroups() != null) {
109113
caseInstanceQuery.setSafeInvolvedGroups(createSafeInValuesList(caseInstanceQuery.getInvolvedGroups()));
110114
}

modules/flowable-cmmn-engine/src/main/java/org/flowable/cmmn/engine/impl/runtime/CaseInstanceQueryImpl.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ public class CaseInstanceQueryImpl extends AbstractVariableQueryImpl<CaseInstanc
6868
protected String businessStatusLikeIgnoreCase;
6969
protected String caseInstanceId;
7070
protected Set<String> caseInstanceIds;
71+
private List<List<String>> safeCaseInstanceIds;
7172
protected String caseInstanceParentId;
7273
protected String caseInstanceParentPlanItemInstanceId;
7374
protected Date startedBefore;
@@ -1234,6 +1235,14 @@ public List<CaseInstanceQueryImpl> getOrQueryObjects() {
12341235
return orQueryObjects;
12351236
}
12361237

1238+
public List<List<String>> getSafeCaseInstanceIds() {
1239+
return safeCaseInstanceIds;
1240+
}
1241+
1242+
public void setSafeCaseInstanceIds(List<List<String>> safeCaseInstanceIds) {
1243+
this.safeCaseInstanceIds = safeCaseInstanceIds;
1244+
}
1245+
12371246
public List<List<String>> getSafeInvolvedGroups() {
12381247
return safeInvolvedGroups;
12391248
}

modules/flowable-cmmn-engine/src/main/resources/org/flowable/cmmn/db/mapping/entity/CaseInstance.xml

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -352,11 +352,18 @@
352352
<if test="caseInstanceId != null">
353353
and RES.ID_ = #{caseInstanceId, jdbcType=VARCHAR}
354354
</if>
355-
<if test="caseInstanceIds != null">
356-
and RES.ID_ IN
357-
<foreach item="caseInstanceId" index="index" collection="caseInstanceIds" open="(" separator="," close=")">
358-
#{caseInstanceId, jdbcType=VARCHAR}
355+
<if test="caseInstanceIds != null &amp;&amp; !caseInstanceIds.empty">
356+
and (
357+
<foreach item="caseInstanceIdListItem" index="groupIndex" collection="safeCaseInstanceIds">
358+
<if test="groupIndex &gt; 0">
359+
or
360+
</if>
361+
RES.ID_ IN
362+
<foreach item="caseInstanceId" index="index" collection="caseInstanceIdListItem" open="(" separator="," close=")">
363+
#{caseInstanceId, jdbcType=VARCHAR}
364+
</foreach>
359365
</foreach>
366+
)
360367
</if>
361368
<if test="caseDefinitionId != null">
362369
and RES.CASE_DEF_ID_ = #{caseDefinitionId, jdbcType=VARCHAR}
@@ -631,11 +638,18 @@
631638
<if test="orQueryObject.caseInstanceId != null">
632639
or RES.ID_ = #{orQueryObject.caseInstanceId, jdbcType=VARCHAR}
633640
</if>
634-
<if test="orQueryObject.caseInstanceIds != null">
635-
or RES.ID_ IN
636-
<foreach item="caseInstanceId" index="index" collection="orQueryObject.caseInstanceIds" open="(" separator="," close=")">
637-
#{caseInstanceId, jdbcType=VARCHAR}
641+
<if test="orQueryObject.caseInstanceIds != null &amp;&amp; !orQueryObject.caseInstanceIds.empty">
642+
or (
643+
<foreach item="caseInstanceIdListItem" index="groupIndex" collection="orQueryObject.safeCaseInstanceIds">
644+
<if test="groupIndex &gt; 0">
645+
or
646+
</if>
647+
RES.ID_ IN
648+
<foreach item="caseInstanceId" index="index" collection="caseInstanceIdListItem" open="(" separator="," close=")">
649+
#{caseInstanceId, jdbcType=VARCHAR}
650+
</foreach>
638651
</foreach>
652+
)
639653
</if>
640654
<if test="orQueryObject.caseDefinitionId != null">
641655
or RES.CASE_DEF_ID_ = #{orQueryObject.caseDefinitionId, jdbcType=VARCHAR}

modules/flowable-cmmn-engine/src/main/resources/org/flowable/cmmn/db/mapping/entity/HistoricCaseInstance.xml

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -639,11 +639,17 @@
639639
${queryTablePrefix}ID_ = #{caseInstanceId, jdbcType=VARCHAR}
640640
</if>
641641
<if test="caseInstanceIds != null &amp;&amp; !caseInstanceIds.empty">
642-
and ${queryTablePrefix}ID_ IN
643-
<foreach item="caseInstanceId" index="index" collection="caseInstanceIds"
644-
open="(" separator="," close=")">
645-
#{caseInstanceId, jdbcType=VARCHAR}
642+
and (
643+
<foreach item="caseInstanceIdListItem" index="groupIndex" collection="safeCaseInstanceIds">
644+
<if test="groupIndex &gt; 0">
645+
or
646+
</if>
647+
${queryTablePrefix}ID_ IN
648+
<foreach item="caseInstanceId" index="index" collection="caseInstanceIdListItem" open="(" separator="," close=")">
649+
#{caseInstanceId, jdbcType=VARCHAR}
650+
</foreach>
646651
</foreach>
652+
)
647653
</if>
648654
<if test="caseDefinitionId != null">
649655
and ${queryTablePrefix}CASE_DEF_ID_ = #{caseDefinitionId, jdbcType=VARCHAR}
@@ -805,11 +811,17 @@
805811
${queryTablePrefix}ID_ = #{orQueryObject.caseInstanceId, jdbcType=VARCHAR}
806812
</if>
807813
<if test="orQueryObject.caseInstanceIds != null &amp;&amp; !orQueryObject.caseInstanceIds.empty">
808-
or ${queryTablePrefix}ID_ IN
809-
<foreach item="caseInstanceId" index="index" collection="orQueryObject.caseInstanceIds"
810-
open="(" separator="," close=")">
811-
#{caseInstanceId, jdbcType=VARCHAR}
814+
or (
815+
<foreach item="caseInstanceIdListItem" index="groupIndex" collection="orQueryObject.safeCaseInstanceIds">
816+
<if test="groupIndex &gt; 0">
817+
or
818+
</if>
819+
${queryTablePrefix}ID_ IN
820+
<foreach item="caseInstanceId" index="index" collection="caseInstanceIdListItem" open="(" separator="," close=")">
821+
#{caseInstanceId, jdbcType=VARCHAR}
822+
</foreach>
812823
</foreach>
824+
)
813825
</if>
814826
<if test="orQueryObject.caseDefinitionId != null">
815827
or ${queryTablePrefix}CASE_DEF_ID_ = #{orQueryObject.caseDefinitionId, jdbcType=VARCHAR}

modules/flowable-engine/src/main/java/org/flowable/engine/impl/ExecutionQueryImpl.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1385,6 +1385,10 @@ public String getCallbackType() {
13851385
public List<ExecutionQueryImpl> getOrQueryObjects() {
13861386
return orQueryObjects;
13871387
}
1388+
1389+
public List<List<String>> getSafeProcessInstanceIds() {
1390+
return null;
1391+
}
13881392

13891393
public List<List<String>> getSafeInvolvedGroups() {
13901394
return safeInvolvedGroups;

modules/flowable-engine/src/main/java/org/flowable/engine/impl/HistoricProcessInstanceQueryImpl.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ public class HistoricProcessInstanceQueryImpl extends AbstractVariableQueryImpl<
8888
protected String processDefinitionNameLikeIgnoreCase;
8989
protected Integer processDefinitionVersion;
9090
protected Set<String> processInstanceIds;
91+
private List<List<String>> safeProcessInstanceIds;
9192
protected String activeActivityId;
9293
protected Set<String> activeActivityIds;
9394
protected String involvedUser;
@@ -1458,6 +1459,14 @@ public boolean isNeedsProcessDefinitionOuterJoin() {
14581459
return hasOrderByForColumn(HistoricProcessInstanceQueryProperty.PROCESS_DEFINITION_KEY.getName());
14591460
}
14601461

1462+
public List<List<String>> getSafeProcessInstanceIds() {
1463+
return safeProcessInstanceIds;
1464+
}
1465+
1466+
public void setSafeProcessInstanceIds(List<List<String>> safeProcessInstanceIds) {
1467+
this.safeProcessInstanceIds = safeProcessInstanceIds;
1468+
}
1469+
14611470
public List<List<String>> getSafeInvolvedGroups() {
14621471
return safeInvolvedGroups;
14631472
}

modules/flowable-engine/src/main/java/org/flowable/engine/impl/ProcessInstanceQueryImpl.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ public class ProcessInstanceQueryImpl extends AbstractVariableQueryImpl<ProcessI
6666
protected String processDefinitionNameLikeIgnoreCase;
6767
protected Integer processDefinitionVersion;
6868
protected Set<String> processInstanceIds;
69+
private List<List<String>> safeProcessInstanceIds;
6970
protected String processDefinitionKey;
7071
protected String processDefinitionKeyLike;
7172
protected String processDefinitionKeyLikeIgnoreCase;
@@ -1342,6 +1343,14 @@ public boolean isNeedsProcessDefinitionOuterJoin() {
13421343
return hasOrderByForColumn(ProcessInstanceQueryProperty.PROCESS_DEFINITION_KEY.getName());
13431344
}
13441345

1346+
public List<List<String>> getSafeProcessInstanceIds() {
1347+
return safeProcessInstanceIds;
1348+
}
1349+
1350+
public void setSafeProcessInstanceIds(List<List<String>> safeProcessInstanceIds) {
1351+
this.safeProcessInstanceIds = safeProcessInstanceIds;
1352+
}
1353+
13451354
public List<List<String>> getSafeInvolvedGroups() {
13461355
return safeInvolvedGroups;
13471356
}

modules/flowable-engine/src/main/java/org/flowable/engine/impl/persistence/entity/data/impl/MybatisExecutionDataManager.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -344,6 +344,10 @@ protected void setSafeInValueLists(ExecutionQueryImpl executionQuery) {
344344
}
345345

346346
protected void setSafeInValueLists(ProcessInstanceQueryImpl processInstanceQuery) {
347+
if (processInstanceQuery.getProcessInstanceIds() != null) {
348+
processInstanceQuery.setSafeProcessInstanceIds(createSafeInValuesList(processInstanceQuery.getProcessInstanceIds()));
349+
}
350+
347351
if (processInstanceQuery.getInvolvedGroups() != null) {
348352
processInstanceQuery.setSafeInvolvedGroups(createSafeInValuesList(processInstanceQuery.getInvolvedGroups()));
349353
}

0 commit comments

Comments
 (0)