Skip to content

Commit dca6e00

Browse files
Add safe query support for process and case instance ids
1 parent 10aa6ea commit dca6e00

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;
@@ -1419,6 +1420,14 @@ public boolean isNeedsCaseDefinitionOuterJoin() {
14191420
return hasOrderByForColumn(HistoricCaseInstanceQueryProperty.CASE_DEFINITION_KEY.getName());
14201421
}
14211422

1423+
public List<List<String>> getSafeCaseInstanceIds() {
1424+
return safeCaseInstanceIds;
1425+
}
1426+
1427+
public void setSafeCaseInstanceIds(List<List<String>> safeCaseInstanceIds) {
1428+
this.safeCaseInstanceIds = safeCaseInstanceIds;
1429+
}
1430+
14221431
public List<List<String>> getSafeInvolvedGroups() {
14231432
return safeInvolvedGroups;
14241433
}

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
@@ -99,6 +99,10 @@ public void bulkDeleteHistoricCaseInstances(Collection<String> caseInstanceIds)
9999
}
100100

101101
protected void setSafeInValueLists(HistoricCaseInstanceQueryImpl caseInstanceQuery) {
102+
if (caseInstanceQuery.getCaseInstanceIds() != null) {
103+
caseInstanceQuery.setSafeCaseInstanceIds(createSafeInValuesList(caseInstanceQuery.getCaseInstanceIds()));
104+
}
105+
102106
if (caseInstanceQuery.getInvolvedGroups() != null) {
103107
caseInstanceQuery.setSafeInvolvedGroups(createSafeInValuesList(caseInstanceQuery.getInvolvedGroups()));
104108
}

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
@@ -350,11 +350,18 @@
350350
<if test="caseInstanceId != null">
351351
and RES.ID_ = #{caseInstanceId, jdbcType=VARCHAR}
352352
</if>
353-
<if test="caseInstanceIds != null">
354-
and RES.ID_ IN
355-
<foreach item="caseInstanceId" index="index" collection="caseInstanceIds" open="(" separator="," close=")">
356-
#{caseInstanceId, jdbcType=VARCHAR}
353+
<if test="caseInstanceIds != null &amp;&amp; !caseInstanceIds.empty">
354+
and (
355+
<foreach item="caseInstanceIdListItem" index="groupIndex" collection="safeCaseInstanceIds">
356+
<if test="groupIndex &gt; 0">
357+
or
358+
</if>
359+
RES.ID_ IN
360+
<foreach item="caseInstanceId" index="index" collection="caseInstanceIdListItem" open="(" separator="," close=")">
361+
#{caseInstanceId, jdbcType=VARCHAR}
362+
</foreach>
357363
</foreach>
364+
)
358365
</if>
359366
<if test="caseDefinitionId != null">
360367
and RES.CASE_DEF_ID_ = #{caseDefinitionId, jdbcType=VARCHAR}
@@ -629,11 +636,18 @@
629636
<if test="orQueryObject.caseInstanceId != null">
630637
or RES.ID_ = #{orQueryObject.caseInstanceId, jdbcType=VARCHAR}
631638
</if>
632-
<if test="orQueryObject.caseInstanceIds != null">
633-
or RES.ID_ IN
634-
<foreach item="caseInstanceId" index="index" collection="orQueryObject.caseInstanceIds" open="(" separator="," close=")">
635-
#{caseInstanceId, jdbcType=VARCHAR}
639+
<if test="orQueryObject.caseInstanceIds != null &amp;&amp; !orQueryObject.caseInstanceIds.empty">
640+
or (
641+
<foreach item="caseInstanceIdListItem" index="groupIndex" collection="orQueryObject.safeCaseInstanceIds">
642+
<if test="groupIndex &gt; 0">
643+
or
644+
</if>
645+
RES.ID_ IN
646+
<foreach item="caseInstanceId" index="index" collection="caseInstanceIdListItem" open="(" separator="," close=")">
647+
#{caseInstanceId, jdbcType=VARCHAR}
648+
</foreach>
636649
</foreach>
650+
)
637651
</if>
638652
<if test="orQueryObject.caseDefinitionId != null">
639653
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
@@ -628,11 +628,17 @@
628628
${queryTablePrefix}ID_ = #{caseInstanceId, jdbcType=VARCHAR}
629629
</if>
630630
<if test="caseInstanceIds != null &amp;&amp; !caseInstanceIds.empty">
631-
and ${queryTablePrefix}ID_ IN
632-
<foreach item="caseInstanceId" index="index" collection="caseInstanceIds"
633-
open="(" separator="," close=")">
634-
#{caseInstanceId, jdbcType=VARCHAR}
631+
and (
632+
<foreach item="caseInstanceIdListItem" index="groupIndex" collection="safeCaseInstanceIds">
633+
<if test="groupIndex &gt; 0">
634+
or
635+
</if>
636+
${queryTablePrefix}ID_ IN
637+
<foreach item="caseInstanceId" index="index" collection="caseInstanceIdListItem" open="(" separator="," close=")">
638+
#{caseInstanceId, jdbcType=VARCHAR}
639+
</foreach>
635640
</foreach>
641+
)
636642
</if>
637643
<if test="caseDefinitionId != null">
638644
and ${queryTablePrefix}CASE_DEF_ID_ = #{caseDefinitionId, jdbcType=VARCHAR}
@@ -794,11 +800,17 @@
794800
${queryTablePrefix}ID_ = #{orQueryObject.caseInstanceId, jdbcType=VARCHAR}
795801
</if>
796802
<if test="orQueryObject.caseInstanceIds != null &amp;&amp; !orQueryObject.caseInstanceIds.empty">
797-
or ${queryTablePrefix}ID_ IN
798-
<foreach item="caseInstanceId" index="index" collection="orQueryObject.caseInstanceIds"
799-
open="(" separator="," close=")">
800-
#{caseInstanceId, jdbcType=VARCHAR}
803+
or (
804+
<foreach item="caseInstanceIdListItem" index="groupIndex" collection="orQueryObject.safeCaseInstanceIds">
805+
<if test="groupIndex &gt; 0">
806+
or
807+
</if>
808+
${queryTablePrefix}ID_ IN
809+
<foreach item="caseInstanceId" index="index" collection="caseInstanceIdListItem" open="(" separator="," close=")">
810+
#{caseInstanceId, jdbcType=VARCHAR}
811+
</foreach>
801812
</foreach>
813+
)
802814
</if>
803815
<if test="orQueryObject.caseDefinitionId != null">
804816
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;
@@ -1436,6 +1437,14 @@ public boolean isNeedsProcessDefinitionOuterJoin() {
14361437
return hasOrderByForColumn(HistoricProcessInstanceQueryProperty.PROCESS_DEFINITION_KEY.getName());
14371438
}
14381439

1440+
public List<List<String>> getSafeProcessInstanceIds() {
1441+
return safeProcessInstanceIds;
1442+
}
1443+
1444+
public void setSafeProcessInstanceIds(List<List<String>> safeProcessInstanceIds) {
1445+
this.safeProcessInstanceIds = safeProcessInstanceIds;
1446+
}
1447+
14391448
public List<List<String>> getSafeInvolvedGroups() {
14401449
return safeInvolvedGroups;
14411450
}

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)