Skip to content

Commit

Permalink
[kie-roadmap-52] LogCleanupCommand - keep ExecutionErrorInfo entries …
Browse files Browse the repository at this point in the history
…for active process instances
  • Loading branch information
martinweiler committed Oct 21, 2023
1 parent 748834a commit d3bea61
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,20 @@ protected static class Subquery {
private String queryBase;
private int queryParamId;
private QueryWhere where;
private String join;

private QueryAndParameterAppender queryAndParameterAppender;

public Subquery(String field, String queryBase, int queryParamId) {
this(field, queryBase, queryParamId, "in");
}

public Subquery(String field, String queryBase, int queryParamId, String join) {
this.field = field;
this.queryBase = queryBase;
this.queryParamId = queryParamId;
this.where = new QueryWhere();
this.join = join;
}

public Subquery parameter(String listId, Object... values) {
Expand All @@ -79,7 +85,7 @@ public String build() {
if (queryAndParameterAppender == null) {
queryAndParameterAppender = QueryHelper.createQuery(queryBase, where, new HashMap<>(), queryParamId);
}
return field + " in (" + queryAndParameterAppender.toSQL() + ")";
return field + " " + join + " (" + queryAndParameterAppender.toSQL() + ")";
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import org.jbpm.process.audit.JPAAuditLogService;
import org.jbpm.process.audit.query.AbstractAuditDeleteBuilderImpl;
import org.jbpm.runtime.manager.impl.jpa.ExecutionErrorInfo;
import org.kie.api.runtime.process.ProcessInstance;
import org.kie.internal.runtime.manager.audit.query.ExecutionErrorInfoDeleteBuilder;

import static org.kie.internal.query.QueryParameterIdentifiers.ERROR_DATE_LIST;
Expand Down Expand Up @@ -52,4 +53,24 @@ public ExecutionErrorInfoDeleteBuilder dateRangeEnd(Date rangeEnd) {
addRangeParameter(ERROR_DATE_LIST, "date range end", rangeEnd, false);
return this;
}

@Override
protected boolean isSubquerySupported() {
return true;
}

@Override
protected Subquery applyParameters(Subquery subquery) {
return subquery;
}

@Override
protected Subquery getSubQuery() {
String queryBaseStr = "SELECT spl.processInstanceId FROM ProcessInstanceLog spl where spl.status in (" +
ProcessInstance.STATE_PENDING + "," + // 0
ProcessInstance.STATE_ACTIVE + "," + // 1
ProcessInstance.STATE_SUSPENDED + // 4
")";
return new Subquery("l.processInstanceId", queryBaseStr, 1, "not in");
}
}

0 comments on commit d3bea61

Please sign in to comment.