Extending TaskQuery myBatis definition

Hi.

I need to query for tasks by many optional (using OR) queries with required (using AND) subqueries.
For example:
TaskQuery tq1 = taskService.createTaskQuery().taskAssignee(“u1”);
TaskQuery tq2 = taskService.createTaskQuery().taskDefinitionKey(“make-purchase”).processDefinitionKey(“purchasing”).tenantIdIn(“t1”);

I need that whether the whole tq1 be true or the tq2. Like:
select * from tasks where (assignee = u1) OR (taskDefinitionKey = “make-purchase” AND processDefinitionKey = “purchasing” AND tenantID in (“t1”));

I realized that this is not possible now because of the mybatis task implementation of the selectTaskByQueryCriteriaSql sql:

<sql id="selectTaskByQueryCriteriaSql">
....
    <foreach collection="queries" item="query" index="i">
        <choose>
          <when test="i == 0">
            <bind name="queryType" value="'and'" />
          </when>
          <otherwise>
            <bind name="queryType" value="'or'" />
          </otherwise>
        </choose>
        and (  <<<<<<<---- THIS HARDCODED AND 
        ....

There is a hardcoded ‘and’ that makes all queries required.
So I made my own mybatis configuration like that:

<sql id="selectTaskByOrQueryCriteriaSql">
       ....
       <foreach collection="queries" item="query" index="i">
                <choose>
                    <when test="i == 0">
                        <bind name="queryType" value="'and'" />
                    </when>
                    <otherwise>
                        <bind name="queryType" value="'or'" />
                    </otherwise>
                </choose>
                or (   <<<<<<<<<<---- My hardcoded OR
               ....

The problem is that I need to extend the FilterService class in order to call a custom TaskQueryImpl that calls the findTasksByOrQueryCriteria that I created.

It seems to me that this solution is too fragile because is bounded to much on the Camunda implementation.

I don’t want to implement an endpoint to ask for tasks, because I want to use the Camunda builtin endpoints though.

Hi @chimerarocks,

welcome to the forum!

Which version of Camunda are you using?
For task queries, you can actually use the or() methods to create OR joined query blocks.
See here for method reference in Camunda 7.13:
https://docs.camunda.org/javadoc/camunda-bpm-platform/7.13/org/camunda/bpm/engine/task/TaskQuery.html#or--

Does that help?

Best,
Tobias

So my Camunda version is 7.14.0.

The or() method do not satisfy my business because of this hardcoded ‘or’ on my batis of the Task Entity Query.

And I built the solution creating this new my batis configuration file. But this increased the time to query for tasks by 3 seconds. I have a performance issue now.

There is a way to cache or load the myBatis configuration file at compile time?