All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.flowable.db.mapping.entity.Execution.xml Maven / Gradle / Ivy

There is a newer version: 7.0.1
Show newest version
<?xml version="1.0" encoding="UTF-8" ?>

<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">

<mapper namespace="org.flowable.engine.impl.persistence.entity.ExecutionEntityImpl">

  <!-- EXECUTION INSERT -->

  <insert id="insertExecution" parameterType="org.flowable.engine.impl.persistence.entity.ExecutionEntityImpl">
    insert into ${prefix}ACT_RU_EXECUTION (ID_, REV_, PROC_INST_ID_, BUSINESS_KEY_, PROC_DEF_ID_, ACT_ID_, IS_ACTIVE_, IS_CONCURRENT_,
                                           IS_SCOPE_,IS_EVENT_SCOPE_, IS_MI_ROOT_, PARENT_ID_, SUPER_EXEC_, ROOT_PROC_INST_ID_, SUSPENSION_STATE_,
                                           TENANT_ID_, NAME_, START_ACT_ID_, START_TIME_, START_USER_ID_, IS_COUNT_ENABLED_, EVT_SUBSCR_COUNT_,
                                           TASK_COUNT_, JOB_COUNT_, TIMER_JOB_COUNT_, SUSP_JOB_COUNT_, DEADLETTER_JOB_COUNT_, EXTERNAL_WORKER_JOB_COUNT_, VAR_COUNT_, ID_LINK_COUNT_,
                                           CALLBACK_ID_, CALLBACK_TYPE_, REFERENCE_ID_, REFERENCE_TYPE_, PROPAGATED_STAGE_INST_ID_)
    values (
      #{id ,jdbcType=VARCHAR},
      1, #{processInstanceId, jdbcType=VARCHAR},
      #{businessKey, jdbcType=VARCHAR},
      #{processDefinitionId ,jdbcType=VARCHAR},
      #{activityId ,jdbcType=VARCHAR},
      #{isActive ,jdbcType=BOOLEAN},
      #{isConcurrent ,jdbcType=BOOLEAN},
      #{isScope ,jdbcType=BOOLEAN},
      #{isEventScope ,jdbcType=BOOLEAN},
      #{isMultiInstanceRoot, jdbcType=BOOLEAN},
      #{parentId, jdbcType=VARCHAR},
      #{superExecutionId, jdbcType=VARCHAR},
      #{rootProcessInstanceId, jdbcType=VARCHAR},
      #{suspensionState, jdbcType=INTEGER},
      #{tenantId, jdbcType=VARCHAR},
      #{name, jdbcType=VARCHAR},
      #{startActivityId, jdbcType=VARCHAR},
      #{startTime, jdbcType=TIMESTAMP},
      #{startUserId, jdbcType=VARCHAR},
      #{isCountEnabled, jdbcType=BOOLEAN},
      #{eventSubscriptionCount, jdbcType=INTEGER},
      #{taskCount, jdbcType=INTEGER},
      #{jobCount, jdbcType=INTEGER},
      #{timerJobCount, jdbcType=INTEGER},
      #{suspendedJobCount, jdbcType=INTEGER},
      #{deadLetterJobCount, jdbcType=INTEGER},
      #{externalWorkerJobCount, jdbcType=INTEGER},
      #{variableCount, jdbcType=INTEGER},
      #{identityLinkCount, jdbcType=INTEGER},
      #{callbackId, jdbcType=VARCHAR},
      #{callbackType, jdbcType=VARCHAR},
      #{referenceId, jdbcType=VARCHAR},
      #{referenceType, jdbcType=VARCHAR},
      #{propagatedStageInstanceId, jdbcType=VARCHAR}
    )
  </insert>

  <insert id="bulkInsertExecution" parameterType="java.util.List">
    insert into ${prefix}ACT_RU_EXECUTION (ID_, REV_, PROC_INST_ID_, BUSINESS_KEY_, PROC_DEF_ID_, ACT_ID_, IS_ACTIVE_, IS_CONCURRENT_,
                                           IS_SCOPE_,IS_EVENT_SCOPE_, IS_MI_ROOT_, PARENT_ID_, SUPER_EXEC_, ROOT_PROC_INST_ID_, SUSPENSION_STATE_,
                                           TENANT_ID_, NAME_, START_ACT_ID_, START_TIME_, START_USER_ID_, IS_COUNT_ENABLED_, EVT_SUBSCR_COUNT_,
                                           TASK_COUNT_, JOB_COUNT_, TIMER_JOB_COUNT_, SUSP_JOB_COUNT_, DEADLETTER_JOB_COUNT_, EXTERNAL_WORKER_JOB_COUNT_, VAR_COUNT_, ID_LINK_COUNT_,
                                           CALLBACK_ID_, CALLBACK_TYPE_, REFERENCE_ID_, REFERENCE_TYPE_, PROPAGATED_STAGE_INST_ID_)
    values
      <foreach collection="list" item="execution" index="index" separator=",">
        (#{execution.id ,jdbcType=VARCHAR},
         1, #{execution.processInstanceId, jdbcType=VARCHAR},
         #{execution.businessKey, jdbcType=VARCHAR},
         #{execution.processDefinitionId ,jdbcType=VARCHAR},
         #{execution.activityId ,jdbcType=VARCHAR},
         #{execution.isActive ,jdbcType=BOOLEAN},
         #{execution.isConcurrent ,jdbcType=BOOLEAN},
         #{execution.isScope ,jdbcType=BOOLEAN},
         #{execution.isEventScope ,jdbcType=BOOLEAN},
         #{execution.isMultiInstanceRoot, jdbcType=BOOLEAN},
         #{execution.parentId, jdbcType=VARCHAR},
         #{execution.superExecutionId, jdbcType=VARCHAR},
         #{execution.rootProcessInstanceId, jdbcType=VARCHAR},
         #{execution.suspensionState, jdbcType=INTEGER},
         #{execution.tenantId, jdbcType=VARCHAR},
         #{execution.name, jdbcType=VARCHAR},
         #{execution.startActivityId, jdbcType=VARCHAR},
         #{execution.startTime, jdbcType=TIMESTAMP},
         #{execution.startUserId, jdbcType=VARCHAR},
         #{execution.isCountEnabled, jdbcType=BOOLEAN},
         #{execution.eventSubscriptionCount, jdbcType=INTEGER},
         #{execution.taskCount, jdbcType=INTEGER},
         #{execution.jobCount, jdbcType=INTEGER},
         #{execution.timerJobCount, jdbcType=INTEGER},
         #{execution.suspendedJobCount, jdbcType=INTEGER},
         #{execution.deadLetterJobCount, jdbcType=INTEGER},
         #{execution.externalWorkerJobCount, jdbcType=INTEGER},
         #{execution.variableCount, jdbcType=INTEGER},
         #{execution.identityLinkCount, jdbcType=INTEGER},
         #{execution.callbackId, jdbcType=VARCHAR},
         #{execution.callbackType, jdbcType=VARCHAR},
         #{execution.referenceId, jdbcType=VARCHAR},
         #{execution.referenceType, jdbcType=VARCHAR},
         #{execution.propagatedStageInstanceId, jdbcType=VARCHAR}
        )
      </foreach>
  </insert>

  <insert id="bulkInsertExecution" databaseId="oracle" parameterType="java.util.List">
    INSERT ALL
      <foreach collection="list" item="execution" index="index">
        into ${prefix}ACT_RU_EXECUTION (ID_, REV_, PROC_INST_ID_, BUSINESS_KEY_, PROC_DEF_ID_, ACT_ID_, IS_ACTIVE_, IS_CONCURRENT_,
                                        IS_SCOPE_,IS_EVENT_SCOPE_, IS_MI_ROOT_, PARENT_ID_, SUPER_EXEC_, ROOT_PROC_INST_ID_, SUSPENSION_STATE_,
                                        TENANT_ID_, NAME_, START_ACT_ID_, START_TIME_, START_USER_ID_, IS_COUNT_ENABLED_, EVT_SUBSCR_COUNT_,
                                        TASK_COUNT_, JOB_COUNT_, TIMER_JOB_COUNT_, SUSP_JOB_COUNT_, DEADLETTER_JOB_COUNT_, EXTERNAL_WORKER_JOB_COUNT_, VAR_COUNT_, ID_LINK_COUNT_,
                                        CALLBACK_ID_, CALLBACK_TYPE_, REFERENCE_ID_, REFERENCE_TYPE_, PROPAGATED_STAGE_INST_ID_) VALUES
            (
             #{execution.id ,jdbcType=VARCHAR},
             1, #{execution.processInstanceId, jdbcType=VARCHAR},
             #{execution.businessKey, jdbcType=VARCHAR},
             #{execution.processDefinitionId ,jdbcType=VARCHAR},
             #{execution.activityId ,jdbcType=VARCHAR},
             #{execution.isActive ,jdbcType=BOOLEAN},
             #{execution.isConcurrent ,jdbcType=BOOLEAN},
             #{execution.isScope ,jdbcType=BOOLEAN},
             #{execution.isEventScope ,jdbcType=BOOLEAN},
             #{execution.isMultiInstanceRoot, jdbcType=BOOLEAN},
             #{execution.parentId, jdbcType=VARCHAR},
             #{execution.superExecutionId, jdbcType=VARCHAR},
             #{execution.rootProcessInstanceId, jdbcType=VARCHAR},
             #{execution.suspensionState, jdbcType=INTEGER},
             #{execution.tenantId, jdbcType=VARCHAR},
             #{execution.name, jdbcType=VARCHAR},
             #{execution.startActivityId, jdbcType=VARCHAR},
             #{execution.startTime, jdbcType=TIMESTAMP},
             #{execution.startUserId, jdbcType=VARCHAR},
             #{execution.isCountEnabled, jdbcType=BOOLEAN},
             #{execution.eventSubscriptionCount, jdbcType=INTEGER},
             #{execution.taskCount, jdbcType=INTEGER},
             #{execution.jobCount, jdbcType=INTEGER},
             #{execution.timerJobCount, jdbcType=INTEGER},
             #{execution.suspendedJobCount, jdbcType=INTEGER},
             #{execution.deadLetterJobCount, jdbcType=INTEGER},
             #{execution.externalWorkerJobCount, jdbcType=INTEGER},
             #{execution.variableCount, jdbcType=INTEGER},
             #{execution.identityLinkCount, jdbcType=INTEGER},
             #{execution.callbackId, jdbcType=VARCHAR},
             #{execution.callbackType, jdbcType=VARCHAR},
             #{execution.referenceId, jdbcType=VARCHAR},
             #{execution.referenceType, jdbcType=VARCHAR},
             #{execution.propagatedStageInstanceId, jdbcType=VARCHAR}
            )
      </foreach>
    SELECT * FROM dual
  </insert>

  <!-- EXECUTION UPDATE -->

  <update id="updateExecution" parameterType="org.flowable.engine.impl.persistence.entity.ExecutionEntityImpl">
    update ${prefix}ACT_RU_EXECUTION
        <set>
            REV_ = #{revisionNext, jdbcType=INTEGER},
            <if test="originalPersistentState.businessKey != businessKey">
                BUSINESS_KEY_ = #{businessKey, jdbcType=VARCHAR},
            </if>
            <if test="originalPersistentState.processDefinitionId != processDefinitionId">
                PROC_DEF_ID_ = #{processDefinitionId, jdbcType=VARCHAR},
            </if>
            <if test="originalPersistentState.activityId != activityId">
                ACT_ID_ = #{activityId, jdbcType=VARCHAR},
            </if>
            <if test="originalPersistentState.isActive != isActive">
                IS_ACTIVE_ = #{isActive, jdbcType=BOOLEAN},
            </if>
            <if test="originalPersistentState.isConcurrent != isConcurrent">
                IS_CONCURRENT_ = #{isConcurrent, jdbcType=BOOLEAN},
            </if>
            <if test="originalPersistentState.isScope != isScope">
                IS_SCOPE_ = #{isScope, jdbcType=BOOLEAN},
            </if>
            <if test="originalPersistentState.isEventScope != isEventScope">
                IS_EVENT_SCOPE_ = #{isEventScope, jdbcType=BOOLEAN},
            </if>
            <if test="originalPersistentState.isMultiInstanceRoot != isMultiInstanceRoot">
                IS_MI_ROOT_ = #{isMultiInstanceRoot, jdbcType=BOOLEAN},
            </if>
            <if test="originalPersistentState.parentId != parentId">
                PARENT_ID_ = #{parentId, jdbcType=VARCHAR},
            </if>
            <if test="originalPersistentState.superExecutionId != superExecutionId">
                SUPER_EXEC_ = #{superExecutionId, jdbcType=VARCHAR},
            </if>
            <if test="originalPersistentState.rootProcessInstanceId != rootProcessInstanceId">
                ROOT_PROC_INST_ID_ = #{rootProcessInstanceId, jdbcType=VARCHAR},
            </if>
            <if test="originalPersistentState.suspensionState != suspensionState">
                SUSPENSION_STATE_ = #{suspensionState, jdbcType=INTEGER},
            </if>
            <if test="originalPersistentState.name != name">
                NAME_ = #{name, jdbcType=VARCHAR},
            </if>
            <if test="originalPersistentState.isCountEnabled != isCountEnabled">
                IS_COUNT_ENABLED_ = #{isCountEnabled, jdbcType=BOOLEAN},
            </if>
            <if test="originalPersistentState.eventSubscriptionCount != eventSubscriptionCount">
                EVT_SUBSCR_COUNT_ = #{eventSubscriptionCount, jdbcType=INTEGER},
            </if>
            <if test="originalPersistentState.taskCount != taskCount">
                TASK_COUNT_ = #{taskCount, jdbcType=INTEGER},
            </if>
            <if test="originalPersistentState.jobCount != jobCount">
                JOB_COUNT_ = #{jobCount, jdbcType=INTEGER},
            </if>
            <if test="originalPersistentState.timerJobCount != timerJobCount">
                TIMER_JOB_COUNT_ = #{timerJobCount, jdbcType=INTEGER},
            </if>
            <if test="originalPersistentState.suspendedJobCount != suspendedJobCount">
                SUSP_JOB_COUNT_ = #{suspendedJobCount, jdbcType=INTEGER},
            </if>
            <if test="originalPersistentState.deadLetterJobCount != deadLetterJobCount">
                DEADLETTER_JOB_COUNT_ = #{deadLetterJobCount, jdbcType=INTEGER},
            </if>
            <if test="originalPersistentState.externalWorkerJobCount != externalWorkerJobCount">
                EXTERNAL_WORKER_JOB_COUNT_ = #{externalWorkerJobCount, jdbcType=INTEGER},
            </if>
            <if test="originalPersistentState.variableCount != variableCount">
                VAR_COUNT_ = #{variableCount, jdbcType=INTEGER},
            </if>
            <if test="originalPersistentState.identityLinkCount != identityLinkCount">
                ID_LINK_COUNT_ = #{identityLinkCount, jdbcType=INTEGER},
            </if>
            <if test="originalPersistentState.callbackId != callbackId">
                CALLBACK_ID_ = #{callbackId, jdbcType=VARCHAR},
            </if>
            <if test="originalPersistentState.callbackType != callbackType">
                CALLBACK_ID_ = #{callbackType, jdbcType=VARCHAR},
            </if>
            <if test="originalPersistentState.referenceId != referenceId">
                REFERENCE_ID_ = #{referenceId, jdbcType=VARCHAR},
            </if>
            <if test="originalPersistentState.referenceType != referenceType">
                REFERENCE_TYPE_ = #{referenceType, jdbcType=VARCHAR},
            </if>
            <if test="originalPersistentState.propagatedStageInstanceId != propagatedStageInstanceId">
                PROPAGATED_STAGE_INST_ID_ = #{propagatedStageInstanceId, jdbcType=VARCHAR},
            </if>
        </set>
    where ID_ = #{id, jdbcType=VARCHAR}
      and REV_ = #{revision, jdbcType=INTEGER}
  </update>

  <update id="updateExecutionTenantIdForDeployment" parameterType="java.util.Map">
    update ${prefix}ACT_RU_EXECUTION set
      TENANT_ID_ = #{tenantId, jdbcType=VARCHAR}
    where
      ID_ in (
        SELECT E.ID_ from ${prefix}ACT_RU_EXECUTION E
        inner join ${prefix}ACT_RE_PROCDEF P on E.PROC_DEF_ID_  = P.ID_
        inner join ${prefix}ACT_RE_DEPLOYMENT D on P.DEPLOYMENT_ID_ = D.ID_
        where D.ID_ = #{deploymentId, jdbcType=VARCHAR}
      )
  </update>

  <!-- See http://stackoverflow.com/questions/4429319/you-cant-specify-target-table-for-update-in-from-clause
       Tested this on MySQL 5.6: does NOT use a temporary table (so good, performance) -->
  <update id="updateExecutionTenantIdForDeployment" databaseId="mysql" parameterType="java.util.Map">
    update ${prefix}ACT_RU_EXECUTION set
      TENANT_ID_ = #{tenantId, jdbcType=VARCHAR}
    where
      ID_ in (

          SELECT tempExecution.tempId
          FROM (
                SELECT E.ID_ as tempId
                FROM  ${prefix}ACT_RU_EXECUTION E
                inner join ${prefix}ACT_RE_PROCDEF P on E.PROC_DEF_ID_  = P.ID_
                inner join ${prefix}ACT_RE_DEPLOYMENT D on P.DEPLOYMENT_ID_ = D.ID_
                where D.ID_ = #{deploymentId, jdbcType=VARCHAR}

        ) AS tempExecution

    )
  </update>

  <update id="updateProcessInstanceLockTime" parameterType="java.util.Map">
    update ${prefix}ACT_RU_EXECUTION
    set
      LOCK_TIME_ = #{lockTime, jdbcType=TIMESTAMP},
      LOCK_OWNER_ = #{lockOwner, jdbcType=VARCHAR}
    where ID_ = #{id}
      and (LOCK_TIME_ is null OR LOCK_TIME_ &lt; #{expirationTime, jdbcType=TIMESTAMP})
  </update>

  <update id="clearProcessInstanceLockTime" parameterType="java.util.Map">
    update ${prefix}ACT_RU_EXECUTION
    set
      LOCK_TIME_ = null,
      LOCK_OWNER_ = null
    where ID_ = #{id}
  </update>

  <update id="clearAllProcessInstanceLockTimes" parameterType="java.util.Map">
    update ${prefix}ACT_RU_EXECUTION
    set
      LOCK_TIME_ = null,
      LOCK_OWNER_ = null
    where LOCK_OWNER_ = #{lockOwner, jdbcType=VARCHAR}
  </update>

  <update id="updateExecutionRelatedEntityCountEnabled" parameterType="boolean">
    update ${prefix}ACT_RU_EXECUTION
    set IS_COUNT_ENABLED_ = #{parameter, jdbcType=BOOLEAN}
  </update>

  <!-- EXECUTION DELETE -->

  <delete id="deleteExecution" parameterType="org.flowable.engine.impl.persistence.entity.ExecutionEntityImpl">
    delete from ${prefix}ACT_RU_EXECUTION where ID_ = #{id} and REV_ = #{revision}
  </delete>

  <delete id="bulkDeleteExecution" parameterType="java.util.Collection">
    delete from ${prefix}ACT_RU_EXECUTION where
     <foreach item="execution" collection="list" index="index" separator=" or ">
        ID_ = #{execution.id, jdbcType=VARCHAR}
    </foreach>
  </delete>

  <!-- EXECUTION RESULTMAP -->

  <resultMap id="executionResultMap" type="org.flowable.engine.impl.persistence.entity.ExecutionEntityImpl">
    <id property="id" column="ID_" jdbcType="VARCHAR" />
    <result property="revision" column="REV_" jdbcType="INTEGER" />
    <result property="processInstanceId" column="PROC_INST_ID_" jdbcType="VARCHAR" />
    <result property="businessKey" column="BUSINESS_KEY_" jdbcType="VARCHAR" />
    <result property="processDefinitionId" column="PROC_DEF_ID_" jdbcType="VARCHAR" />
    <result property="activityId" column="ACT_ID_" jdbcType="VARCHAR" />
    <result property="isActive" column="IS_ACTIVE_" jdbcType="BOOLEAN" />
    <result property="isConcurrent" column="IS_CONCURRENT_" jdbcType="BOOLEAN" />
    <result property="isScope" column="IS_SCOPE_" jdbcType="BOOLEAN" />
    <result property="isEventScope" column="IS_EVENT_SCOPE_" jdbcType="BOOLEAN" />
    <result property="isMultiInstanceRoot" column="IS_MI_ROOT_" jdbcType="BOOLEAN" />
    <result property="parentId" column="PARENT_ID_" jdbcType="VARCHAR" />
    <result property="superExecutionId" column="SUPER_EXEC_" jdbcType="VARCHAR" />
    <result property="rootProcessInstanceId" column="ROOT_PROC_INST_ID_" jdbcType="VARCHAR" />
    <result property="suspensionState" column="SUSPENSION_STATE_" jdbcType="INTEGER"/>
    <result property="tenantId" column="TENANT_ID_" jdbcType="VARCHAR" />
    <result property="name" column="NAME_" jdbcType="VARCHAR" />
    <result property="startActivityId" column="START_ACT_ID_" jdbcType="VARCHAR" />
    <result property="startTime" column="START_TIME_" jdbcType="TIMESTAMP" />
    <result property="startUserId" column="START_USER_ID_" jdbcType="VARCHAR" />
    <result property="isCountEnabled" column="IS_COUNT_ENABLED_" jdbcType="BOOLEAN" />
    <result property="eventSubscriptionCount" column="EVT_SUBSCR_COUNT_" jdbcType="INTEGER" />
    <result property="taskCount" column="TASK_COUNT_" jdbcType="INTEGER" />
    <result property="jobCount" column="JOB_COUNT_" jdbcType="INTEGER" />
    <result property="timerJobCount" column="TIMER_JOB_COUNT_" jdbcType="INTEGER" />
    <result property="suspendedJobCount" column="SUSP_JOB_COUNT_" jdbcType="INTEGER" />
    <result property="deadLetterJobCount" column="DEADLETTER_JOB_COUNT_" jdbcType="INTEGER" />
    <result property="externalWorkerJobCount" column="EXTERNAL_WORKER_JOB_COUNT_" jdbcType="INTEGER" />
    <result property="variableCount" column="VAR_COUNT_" jdbcType="INTEGER" />
    <result property="identityLinkCount" column="ID_LINK_COUNT_" jdbcType="INTEGER" />
    <result property="callbackId" column="CALLBACK_ID_" jdbcType="VARCHAR" />
    <result property="callbackType" column="CALLBACK_TYPE_" jdbcType="VARCHAR" />
    <result property="referenceId" column="REFERENCE_ID_" jdbcType="VARCHAR" />
    <result property="referenceType" column="REFERENCE_TYPE_" jdbcType="VARCHAR" />
    <result property="propagatedStageInstanceId" column="PROPAGATED_STAGE_INST_ID_" jdbcType="VARCHAR" />
  </resultMap>

  <resultMap id="processInstanceResultMap" type="org.flowable.engine.impl.persistence.entity.ExecutionEntityImpl">
    <id property="id" column="ID_" jdbcType="VARCHAR" />
    <result property="revision" column="REV_" jdbcType="INTEGER" />
    <result property="processInstanceId" column="PROC_INST_ID_" jdbcType="VARCHAR" />
    <result property="businessKey" column="BUSINESS_KEY_" jdbcType="VARCHAR" />

    <!-- Lowercase 'columns', as they are filled in during a query and are not mapped directly to a table column -->
    <result property="processDefinitionId" column="PROC_DEF_ID_" jdbcType="VARCHAR" />
    <result property="processDefinitionName" column="ProcessDefinitionName" jdbcType="VARCHAR" />
    <result property="processDefinitionKey" column="ProcessDefinitionKey" jdbcType="VARCHAR" />
    <result property="processDefinitionVersion" column="ProcessDefinitionVersion" jdbcType="INTEGER" />
    <result property="deploymentId" column="DeploymentId" jdbcType="VARCHAR" />

    <result property="activityId" column="ACT_ID_" jdbcType="VARCHAR" />
    <result property="isActive" column="IS_ACTIVE_" jdbcType="BOOLEAN" />
    <result property="isConcurrent" column="IS_CONCURRENT_" jdbcType="BOOLEAN" />
    <result property="isScope" column="IS_SCOPE_" jdbcType="BOOLEAN" />
    <result property="isEventScope" column="IS_EVENT_SCOPE_" jdbcType="BOOLEAN" />
    <result property="isMultiInstanceRoot" column="IS_MI_ROOT_" jdbcType="BOOLEAN" />
    <result property="parentId" column="PARENT_ID_" jdbcType="VARCHAR" />
    <result property="superExecutionId" column="SUPER_EXEC_" jdbcType="VARCHAR" />
    <result property="rootProcessInstanceId" column="ROOT_PROC_INST_ID_" jdbcType="VARCHAR" />
    <result property="suspensionState" column="SUSPENSION_STATE_" jdbcType="INTEGER"/>
    <result property="tenantId" column="TENANT_ID_" jdbcType="VARCHAR" />
    <result property="name" column="NAME_" jdbcType="VARCHAR" />
    <result property="lockTime" column="LOCK_TIME_" jdbcType="TIMESTAMP" />
    <result property="lockOwner" column="LOCK_OWNER_" jdbcType="VARCHAR" />
    <result property="startActivityId" column="START_ACT_ID_" jdbcType="VARCHAR" />
    <result property="startTime" column="START_TIME_" jdbcType="TIMESTAMP" />
    <result property="startUserId" column="START_USER_ID_" jdbcType="VARCHAR" />
    <result property="isCountEnabled" column="IS_COUNT_ENABLED_" jdbcType="BOOLEAN" />
    <result property="eventSubscriptionCount" column="EVT_SUBSCR_COUNT_" jdbcType="INTEGER" />
    <result property="taskCount" column="TASK_COUNT_" jdbcType="INTEGER" />
    <result property="jobCount" column="JOB_COUNT_" jdbcType="INTEGER" />
    <result property="timerJobCount" column="TIMER_JOB_COUNT_" jdbcType="INTEGER" />
    <result property="suspendedJobCount" column="SUSP_JOB_COUNT_" jdbcType="INTEGER" />
    <result property="deadLetterJobCount" column="DEADLETTER_JOB_COUNT_" jdbcType="INTEGER" />
    <result property="externalWorkerJobCount" column="EXTERNAL_WORKER_JOB_COUNT_" jdbcType="INTEGER" />
    <result property="variableCount" column="VAR_COUNT_" jdbcType="INTEGER" />
    <result property="identityLinkCount" column="ID_LINK_COUNT_" jdbcType="INTEGER" />
    <result property="callbackId" column="CALLBACK_ID_" jdbcType="VARCHAR" />
    <result property="callbackType" column="CALLBACK_TYPE_" jdbcType="VARCHAR" />
    <result property="referenceId" column="REFERENCE_ID_" jdbcType="VARCHAR" />
    <result property="referenceType" column="REFERENCE_TYPE_" jdbcType="VARCHAR" />
    <result property="propagatedStageInstanceId" column="PROPAGATED_STAGE_INST_ID_" jdbcType="VARCHAR" />
  </resultMap>

  <resultMap id="executionAndVariablesResultMap" type="org.flowable.engine.impl.persistence.entity.ExecutionEntityImpl">
    <id property="id" column="ID_" jdbcType="VARCHAR" />
    <result property="revision" column="REV_" jdbcType="INTEGER" />
    <result property="processInstanceId" column="PROC_INST_ID_" jdbcType="VARCHAR" />
    <result property="businessKey" column="BUSINESS_KEY_" jdbcType="VARCHAR" />
    <result property="processDefinitionId" column="PROC_DEF_ID_" jdbcType="VARCHAR" />
    <result property="activityId" column="ACT_ID_" jdbcType="VARCHAR" />
    <result property="isActive" column="IS_ACTIVE_" jdbcType="BOOLEAN" />
    <result property="isConcurrent" column="IS_CONCURRENT_" jdbcType="BOOLEAN" />
    <result property="isScope" column="IS_SCOPE_" jdbcType="BOOLEAN" />
    <result property="isEventScope" column="IS_EVENT_SCOPE_" jdbcType="BOOLEAN" />
    <result property="isMultiInstanceRoot" column="IS_MI_ROOT_" jdbcType="BOOLEAN" />
    <result property="parentId" column="PARENT_ID_" jdbcType="VARCHAR" />
    <result property="superExecutionId" column="SUPER_EXEC_" jdbcType="VARCHAR" />
    <result property="rootProcessInstanceId" column="ROOT_PROC_INST_ID_" jdbcType="VARCHAR" />
    <result property="suspensionState" column="SUSPENSION_STATE_" jdbcType="INTEGER"/>
    <result property="tenantId" column="TENANT_ID_" jdbcType="VARCHAR" />
    <result property="name" column="NAME_" jdbcType="VARCHAR" />
    <result property="startActivityId" column="START_ACT_ID_" jdbcType="VARCHAR" />
    <result property="startTime" column="START_TIME_" jdbcType="TIMESTAMP" />
    <result property="startUserId" column="START_USER_ID_" jdbcType="VARCHAR" />
    <result property="isCountEnabled" column="IS_COUNT_ENABLED_" jdbcType="BOOLEAN" />
    <result property="eventSubscriptionCount" column="EVT_SUBSCR_COUNT_" jdbcType="INTEGER" />
    <result property="taskCount" column="TASK_COUNT_" jdbcType="INTEGER" />
    <result property="jobCount" column="JOB_COUNT_" jdbcType="INTEGER" />
    <result property="timerJobCount" column="TIMER_JOB_COUNT_" jdbcType="INTEGER" />
    <result property="suspendedJobCount" column="SUSP_JOB_COUNT_" jdbcType="INTEGER" />
    <result property="deadLetterJobCount" column="DEADLETTER_JOB_COUNT_" jdbcType="INTEGER" />
    <result property="externalWorkerJobCount" column="EXTERNAL_WORKER_JOB_COUNT_" jdbcType="INTEGER" />
    <result property="variableCount" column="VAR_COUNT_" jdbcType="INTEGER" />
    <result property="identityLinkCount" column="ID_LINK_COUNT_" jdbcType="INTEGER" />
    <result property="callbackId" column="CALLBACK_ID_" jdbcType="VARCHAR" />
    <result property="callbackType" column="CALLBACK_TYPE_" jdbcType="VARCHAR" />
    <result property="referenceId" column="REFERENCE_ID_" jdbcType="VARCHAR" />
    <result property="referenceType" column="REFERENCE_TYPE_" jdbcType="VARCHAR" />
    <result property="propagatedStageInstanceId" column="PROPAGATED_STAGE_INST_ID_" jdbcType="VARCHAR" />
    <collection property="queryVariables" column="EXECUTION_ID_" javaType="ArrayList" ofType="org.flowable.variable.service.impl.persistence.entity.VariableInstanceEntityImpl">
      <id property="id" column="VAR_ID_"/>
      <result property="name" column="VAR_NAME_" javaType="String" jdbcType="VARCHAR" />
      <result property="type" column="VAR_TYPE_" javaType="org.flowable.variable.api.types.VariableType" jdbcType="VARCHAR" />
      <result property="revision" column="VAR_REV_" jdbcType="INTEGER" />
      <result property="processInstanceId" column="VAR_PROC_INST_ID_" jdbcType="VARCHAR" />
      <result property="executionId" column="VAR_EXECUTION_ID_" jdbcType="VARCHAR" />
      <result property="taskId" column="VAR_TASK_ID_" jdbcType="VARCHAR" />
      <result property="byteArrayRef" column="VAR_BYTEARRAY_ID_" typeHandler="VariableByteArrayRefTypeHandler"/>
      <result property="doubleValue" column="VAR_DOUBLE_" jdbcType="DOUBLE" />
      <result property="textValue" column="VAR_TEXT_" jdbcType="VARCHAR" />
      <result property="textValue2" column="VAR_TEXT2_" jdbcType="VARCHAR" />
      <result property="longValue" column="VAR_LONG_" jdbcType="BIGINT" />
    </collection>
  </resultMap>

  <resultMap id="processInstanceAndVariablesResultMap" type="org.flowable.engine.impl.persistence.entity.ExecutionEntityImpl">
    <id property="id" column="ID_" jdbcType="VARCHAR" />
    <result property="revision" column="REV_" jdbcType="INTEGER" />
    <result property="processInstanceId" column="PROC_INST_ID_" jdbcType="VARCHAR" />
    <result property="businessKey" column="BUSINESS_KEY_" jdbcType="VARCHAR" />
    <result property="processDefinitionId" column="PROC_DEF_ID_" jdbcType="VARCHAR" />
    <result property="processDefinitionName" column="ProcessDefinitionName" jdbcType="VARCHAR" />
    <result property="processDefinitionKey" column="ProcessDefinitionKey" jdbcType="VARCHAR" />
    <result property="processDefinitionVersion" column="ProcessDefinitionVersion" jdbcType="INTEGER" />
    <result property="deploymentId" column="DeploymentId" jdbcType="VARCHAR" />
    <result property="activityId" column="ACT_ID_" jdbcType="VARCHAR" />
    <result property="isActive" column="IS_ACTIVE_" jdbcType="BOOLEAN" />
    <result property="isConcurrent" column="IS_CONCURRENT_" jdbcType="BOOLEAN" />
    <result property="isScope" column="IS_SCOPE_" jdbcType="BOOLEAN" />
    <result property="isEventScope" column="IS_EVENT_SCOPE_" jdbcType="BOOLEAN" />
    <result property="isMultiInstanceRoot" column="IS_MI_ROOT_" jdbcType="BOOLEAN" />
    <result property="parentId" column="PARENT_ID_" jdbcType="VARCHAR" />
    <result property="superExecutionId" column="SUPER_EXEC_" jdbcType="VARCHAR" />
    <result property="rootProcessInstanceId" column="ROOT_PROC_INST_ID_" jdbcType="VARCHAR" />
    <result property="suspensionState" column="SUSPENSION_STATE_" jdbcType="INTEGER"/>
    <result property="tenantId" column="TENANT_ID_" jdbcType="VARCHAR" />
    <result property="name" column="NAME_" jdbcType="VARCHAR" />
    <result property="lockTime" column="LOCK_TIME_" jdbcType="TIMESTAMP" />
    <result property="lockOwner" column="LOCK_OWNER_" jdbcType="VARCHAR" />
    <result property="startActivityId" column="START_ACT_ID_" jdbcType="VARCHAR" />
    <result property="startTime" column="START_TIME_" jdbcType="TIMESTAMP" />
    <result property="startUserId" column="START_USER_ID_" jdbcType="VARCHAR" />
    <result property="isCountEnabled" column="IS_COUNT_ENABLED_" jdbcType="BOOLEAN" />
    <result property="eventSubscriptionCount" column="EVT_SUBSCR_COUNT_" jdbcType="INTEGER" />
    <result property="taskCount" column="TASK_COUNT_" jdbcType="INTEGER" />
    <result property="jobCount" column="JOB_COUNT_" jdbcType="INTEGER" />
    <result property="timerJobCount" column="TIMER_JOB_COUNT_" jdbcType="INTEGER" />
    <result property="suspendedJobCount" column="SUSP_JOB_COUNT_" jdbcType="INTEGER" />
    <result property="deadLetterJobCount" column="DEADLETTER_JOB_COUNT_" jdbcType="INTEGER" />
    <result property="externalWorkerJobCount" column="EXTERNAL_WORKER_JOB_COUNT_" jdbcType="INTEGER" />
    <result property="variableCount" column="VAR_COUNT_" jdbcType="INTEGER" />
    <result property="identityLinkCount" column="ID_LINK_COUNT_" jdbcType="INTEGER" />
    <result property="callbackId" column="CALLBACK_ID_" jdbcType="VARCHAR" />
    <result property="callbackType" column="CALLBACK_TYPE_" jdbcType="VARCHAR" />
    <result property="referenceId" column="REFERENCE_ID_" jdbcType="VARCHAR" />
    <result property="referenceType" column="REFERENCE_TYPE_" jdbcType="VARCHAR" />
    <result property="propagatedStageInstanceId" column="PROPAGATED_STAGE_INST_ID_" jdbcType="VARCHAR" />
    <collection property="queryVariables" column="EXECUTION_ID_" javaType="ArrayList" ofType="org.flowable.variable.service.impl.persistence.entity.VariableInstanceEntityImpl">
      <id property="id" column="VAR_ID_"/>
      <result property="name" column="VAR_NAME_" javaType="String" jdbcType="VARCHAR" />
      <result property="type" column="VAR_TYPE_" javaType="org.flowable.variable.api.types.VariableType" jdbcType="VARCHAR" />
      <result property="revision" column="VAR_REV_" jdbcType="INTEGER" />
      <result property="processInstanceId" column="VAR_PROC_INST_ID_" jdbcType="VARCHAR" />
      <result property="executionId" column="VAR_EXECUTION_ID_" jdbcType="VARCHAR" />
      <result property="taskId" column="VAR_TASK_ID_" jdbcType="VARCHAR" />
      <result property="byteArrayRef" column="VAR_BYTEARRAY_ID_" typeHandler="VariableByteArrayRefTypeHandler"/>
      <result property="doubleValue" column="VAR_DOUBLE_" jdbcType="DOUBLE" />
      <result property="textValue" column="VAR_TEXT_" jdbcType="VARCHAR" />
      <result property="textValue2" column="VAR_TEXT2_" jdbcType="VARCHAR" />
      <result property="longValue" column="VAR_LONG_" jdbcType="BIGINT" />
    </collection>
  </resultMap>

  <!-- EXECUTION SELECT -->

  <select id="selectExecutionsWithSameRootProcessInstanceId" parameterType="org.flowable.common.engine.impl.db.ListQueryParameterObject" resultMap="executionResultMap">
    select * from ${prefix}ACT_RU_EXECUTION
    where ROOT_PROC_INST_ID_ = (select ROOT_PROC_INST_ID_ from ${prefix}ACT_RU_EXECUTION where ID_ = #{parameter})
  </select>

  <select id="selectExecution" parameterType="string" resultMap="executionResultMap">
    select * from ${prefix}ACT_RU_EXECUTION where ID_ = #{id, jdbcType=VARCHAR}
  </select>

  <select id="selectExecutionsByParentExecutionId" parameterType="org.flowable.common.engine.impl.db.ListQueryParameterObject" resultMap="executionResultMap">
    select * from ${prefix}ACT_RU_EXECUTION
    where PARENT_ID_ = #{parameter}
  </select>

  <select id="selectExecutionsByRootProcessInstanceId" parameterType="org.flowable.common.engine.impl.db.ListQueryParameterObject" resultMap="executionResultMap">
    select * from ${prefix}ACT_RU_EXECUTION
    where ROOT_PROC_INST_ID_ = #{parameter}
  </select>

  <select id="selectChildExecutionsByProcessInstanceId" parameterType="org.flowable.common.engine.impl.db.ListQueryParameterObject" resultMap="executionResultMap">
    select * from ${prefix}ACT_RU_EXECUTION
    where PROC_INST_ID_ = #{parameter} and PARENT_ID_ is not null
  </select>

  <select id="selectExecutionsByProcessInstanceId" parameterType="org.flowable.common.engine.impl.db.ListQueryParameterObject" resultMap="executionResultMap">
    select * from ${prefix}ACT_RU_EXECUTION
    where PROC_INST_ID_ = #{parameter}
  </select>

  <select id="selectProcessInstanceIdsByProcessDefinitionId" parameterType="org.flowable.common.engine.impl.db.ListQueryParameterObject" resultType="string">
    select ID_
    from ${prefix}ACT_RU_EXECUTION
    where PROC_DEF_ID_ = #{parameter} and PARENT_ID_ is null
  </select>

  <select id="selectInactiveExecutionsForProcessInstance" parameterType="org.flowable.common.engine.impl.db.ListQueryParameterObject" resultMap="executionResultMap">
  	select *
  	from ${prefix}ACT_RU_EXECUTION
  	where PROC_INST_ID_ = #{parameter.processInstanceId}
  	and IS_ACTIVE_ = #{parameter.isActive}
  </select>

  <select id="selectInactiveExecutionsInActivityAndProcessInstance" parameterType="org.flowable.common.engine.impl.db.ListQueryParameterObject" resultMap="executionResultMap">
  	select *
  	from ${prefix}ACT_RU_EXECUTION
  	where ACT_ID_ = #{parameter.activityId}
  	and PROC_INST_ID_ = #{parameter.processInstanceId}
  	and IS_ACTIVE_ = #{parameter.isActive}
  </select>

  <select id="selectExecutionsByParentExecutionAndActivityIds" parameterType="org.flowable.common.engine.impl.db.ListQueryParameterObject" resultMap="executionResultMap">
    select *
    from ${prefix}ACT_RU_EXECUTION
    where PARENT_ID_ = #{parameter.parentExecutionId}
    and ACT_ID_ in
    <foreach item="activityId" collection="parameter.activityIds" open="(" separator="," close=")">
          #{activityId}
    </foreach>
  </select>

  <select id="selectExecutionsByQueryCriteria" parameterType="org.flowable.engine.impl.ExecutionQueryImpl" resultMap="executionResultMap">
  	<if test="firstResult != null and firstResult &gt;= 0">${limitBefore}</if>
    select distinct RES.* <if test="firstResult != null and firstResult &gt;= 0">${limitBetween}</if>, P.KEY_ as ProcessDefinitionKey, P.ID_ as ProcessDefinitionId
    <include refid="selectExecutionsByQueryCriteriaSql"/>
    ${orderBy}
    <if test="firstResult != null and firstResult &gt;= 0">${limitAfter}</if>
  </select>

  <select id="selectExecutionCountByQueryCriteria" parameterType="org.flowable.engine.impl.ExecutionQueryImpl" resultType="long">
    select count(distinct RES.ID_)
    <include refid="selectExecutionsByQueryCriteriaSql"/>
  </select>

  <!--  same as selectExecutionsByQueryCriteria, but with different parameterType -->
  <select id="selectProcessInstanceByQueryCriteria" parameterType="org.flowable.engine.impl.ProcessInstanceQueryImpl" resultMap="processInstanceResultMap">
  	<if test="firstResult != null and firstResult &gt;= 0">${limitBefore}</if>
    select distinct RES.* <if test="firstResult != null and firstResult &gt;= 0">${limitBetween}</if>, P.KEY_ as ProcessDefinitionKey, P.ID_ as ProcessDefinitionId, P.NAME_ as ProcessDefinitionName, P.VERSION_ as ProcessDefinitionVersion, P.DEPLOYMENT_ID_ as DeploymentId
    <include refid="selectExecutionsByQueryCriteriaSql"/>
    ${orderBy}
    <if test="firstResult != null and firstResult &gt;= 0">${limitAfter}</if>
  </select>

  <select id="selectProcessInstanceCountByQueryCriteria" parameterType="org.flowable.engine.impl.ProcessInstanceQueryImpl" resultType="long">
    select count(distinct RES.ID_)
    <include refid="selectExecutionsByQueryCriteriaSql"/>
  </select>

  <sql id="selectExecutionsByQueryCriteriaSql">
    from ${prefix}ACT_RU_EXECUTION RES
    inner join ${prefix}ACT_RE_PROCDEF P on RES.PROC_DEF_ID_ = P.ID_
    <include refid="commonSelectExecutionsByQueryCriteriaSql"/>
  </sql>

  <select id="selectProcessInstanceWithVariablesByQueryCriteria" parameterType="org.flowable.engine.impl.ProcessInstanceQueryImpl" resultMap="processInstanceAndVariablesResultMap">
    <include refid="selectProcessInstanceWithVariablesByQueryCriteriaColumns"/>
    <include refid="selectProcessInstanceWithVariablesByQueryCriteriaSql"/>
    ${orderBy}
    <if test="firstResult != null and firstResult &gt;= 0">${limitAfter}</if>
  </select>

  <sql id="selectProcessInstanceWithVariablesByQueryCriteriaColumns">
   <if test="firstResult != null and firstResult &gt;= 0">${limitBefore}</if>
   <if test="_databaseId != 'db2' and _databaseId != 'mssql'">
    select distinct RES.*, P.KEY_ as ProcessDefinitionKey, P.ID_ as ProcessDefinitionId, P.NAME_ as ProcessDefinitionName, P.VERSION_ as ProcessDefinitionVersion, P.DEPLOYMENT_ID_ as DeploymentId,
    VAR.ID_ as VAR_ID_, VAR.NAME_ as VAR_NAME_, VAR.TYPE_ as VAR_TYPE_, VAR.REV_ as VAR_REV_,
    VAR.PROC_INST_ID_ as VAR_PROC_INST_ID_, VAR.EXECUTION_ID_ as VAR_EXECUTION_ID_, VAR.TASK_ID_ as VAR_TASK_ID_,
    VAR.BYTEARRAY_ID_ as VAR_BYTEARRAY_ID_, VAR.DOUBLE_ as VAR_DOUBLE_,
    VAR.TEXT_ as VAR_TEXT_, VAR.TEXT2_ as VAR_TEXT2_, VAR.LONG_ as VAR_LONG_
    <if test="firstResult != null and firstResult &gt;= 0">${limitBetween}</if>
   </if>
   <if test="_databaseId == 'db2' || _databaseId == 'mssql'">
    select distinct TEMPRES_ID_ as ID_, TEMPP_KEY_ as ProcessDefinitionKey, TEMPP_ID_ as ProcessDefinitionId, TEMPP_NAME_ as ProcessDefinitionName, TEMPP_VERSION_ as ProcessDefinitionVersion, TEMPP_DEPLOYMENT_ID_ as DeploymentId,
    TEMPRES_REV_ as REV_, TEMPRES_ACT_ID_ as ACT_ID_,
    TEMPRES_BUSINESS_KEY_ as BUSINESS_KEY_, TEMPRES_IS_ACTIVE_ as IS_ACTIVE_,
    TEMPRES_IS_CONCURRENT_ as IS_CONCURRENT_, TEMPRES_IS_SCOPE_ as IS_SCOPE_,
    TEMPRES_IS_EVENT_SCOPE_ as IS_EVENT_SCOPE_, TEMPRES_IS_MI_ROOT_ as IS_MI_ROOT_,
    TEMPRES_PARENT_ID_ as PARENT_ID_, TEMPRES_PROC_INST_ID_ as PROC_INST_ID_,
    TEMPRES_SUPER_EXEC_ as SUPER_EXEC_, TEMPRES_PROC_DEF_ID_ as PROC_DEF_ID_,
    TEMPRES_NAME_ as NAME_, TEMPRES_TENANT_ID_ as TENANT_ID_,
    TEMPRES_SUSPENSION_STATE_ as SUSPENSION_STATE_,
    TEMPRES_START_TIME_ as START_TIME_, TEMPRES_START_USER_ID_ as START_USER_ID_,
    TEMPRES_IS_COUNT_ENABLED_ as IS_COUNT_ENABLED_,
    TEMPRES_EVT_SUBSCR_COUNT_ as EVT_SUBSCR_COUNT_,
    TEMPRES_TASK_COUNT_ as TASK_COUNT_,
    TEMPRES_JOB_COUNT_ as JOB_COUNT_,
    TEMPRES_TIMER_JOB_ as TIMER_JOB_COUNT_,
    TEMPRES_SUSP_JOB_COUNT_ as SUSP_JOB_COUNT_,
    TEMPRES_DEADLETTER_JOB_COUNT_ as DEADLETTER_JOB_COUNT_,
    TEMPRES_VAR_COUNT_ as VAR_COUNT_,
    TEMPRES_ID_LINK_COUNT_ as ID_LINK_COUNT_,
    TEMPVAR_ID_ as VAR_ID_, TEMPVAR_NAME_ as VAR_NAME_, TEMPVAR_TYPE_ as VAR_TYPE_, TEMPVAR_REV_ as VAR_REV_,
    TEMPVAR_PROC_INST_ID_ as VAR_PROC_INST_ID_, TEMPVAR_EXECUTION_ID_ as VAR_EXECUTION_ID_, TEMPVAR_TASK_ID_ as VAR_TASK_ID_,
    TEMPVAR_BYTEARRAY_ID_ as VAR_BYTEARRAY_ID_, TEMPVAR_DOUBLE_ as VAR_DOUBLE_,
    TEMPVAR_TEXT_ as VAR_TEXT_, TEMPVAR_TEXT2_ as VAR_TEXT2_, TEMPVAR_LONG_ as VAR_LONG_
     <if test="firstResult != null and firstResult &gt;= 0">${limitOuterJoinBetween}</if>
    RES.ID_ as TEMPRES_ID_, RES.REV_ as TEMPRES_REV_, P.KEY_ as TEMPP_KEY_, P.ID_ as TEMPP_ID_, P.NAME_ as TEMPP_NAME_, P.VERSION_ as TEMPP_VERSION_, P.DEPLOYMENT_ID_ as TEMPP_DEPLOYMENT_ID_,

    RES.ACT_ID_ as TEMPRES_ACT_ID_,
    RES.PROC_INST_ID_ as TEMPRES_PROC_INST_ID_,
    RES.BUSINESS_KEY_ as TEMPRES_BUSINESS_KEY_,
    RES.IS_ACTIVE_ as TEMPRES_IS_ACTIVE_,
    RES.IS_CONCURRENT_ as TEMPRES_IS_CONCURRENT_,
    RES.IS_SCOPE_ as TEMPRES_IS_SCOPE_,
    RES.IS_EVENT_SCOPE_ as TEMPRES_IS_EVENT_SCOPE_,
    RES.IS_MI_ROOT_ as TEMPRES_IS_MI_ROOT_,
    RES.PARENT_ID_ as TEMPRES_PARENT_ID_,
    RES.SUPER_EXEC_ as TEMPRES_SUPER_EXEC_,
    RES.SUSPENSION_STATE_ as TEMPRES_SUSPENSION_STATE_,
    RES.PROC_DEF_ID_ as TEMPRES_PROC_DEF_ID_,
    RES.NAME_ as TEMPRES_NAME_,
    RES.TENANT_ID_ as TEMPRES_TENANT_ID_,
    RES.START_TIME_ as TEMPRES_START_TIME_,
    RES.START_USER_ID_ as TEMPRES_START_USER_ID_,

    RES.IS_COUNT_ENABLED_ as TEMPRES_IS_COUNT_ENABLED_,
    RES.EVT_SUBSCR_COUNT_ as TEMPRES_EVT_SUBSCR_COUNT_,
    RES.TASK_COUNT_ as TEMPRES_TASK_COUNT_,
    RES.JOB_COUNT_ as TEMPRES_JOB_COUNT_,
    RES.TIMER_JOB_COUNT_ as TEMPRES_TIMER_JOB_,
    RES.SUSP_JOB_COUNT_ as TEMPRES_SUSP_JOB_COUNT_,
    RES.DEADLETTER_JOB_COUNT_ as TEMPRES_DEADLETTER_JOB_COUNT_,
    RES.VAR_COUNT_ as TEMPRES_VAR_COUNT_,
    RES.ID_LINK_COUNT_ as TEMPRES_ID_LINK_COUNT_,

    VAR.ID_ as TEMPVAR_ID_, VAR.NAME_ as TEMPVAR_NAME_, VAR.TYPE_ as TEMPVAR_TYPE_, VAR.REV_ as TEMPVAR_REV_,
    VAR.PROC_INST_ID_ as TEMPVAR_PROC_INST_ID_, VAR.EXECUTION_ID_ as TEMPVAR_EXECUTION_ID_, VAR.TASK_ID_ as TEMPVAR_TASK_ID_,
    VAR.BYTEARRAY_ID_ as TEMPVAR_BYTEARRAY_ID_, VAR.DOUBLE_ as TEMPVAR_DOUBLE_,
    VAR.TEXT_ as TEMPVAR_TEXT_, VAR.TEXT2_ as TEMPVAR_TEXT2_, VAR.LONG_ as TEMPVAR_LONG_
   </if>
  </sql>

  <sql id="selectProcessInstanceWithVariablesByQueryCriteriaSql">
    from ${prefix}ACT_RU_EXECUTION RES
    inner join ${prefix}ACT_RE_PROCDEF P on RES.PROC_DEF_ID_ = P.ID_
    <if test="includeProcessVariables">
        left outer join ${prefix}ACT_RU_VARIABLE VAR ON RES.PROC_INST_ID_ = VAR.EXECUTION_ID_
    </if>
    <include refid="commonSelectExecutionsByQueryCriteriaSql"/>
  </sql>

  <sql id="commonSelectExecutionsByQueryCriteriaSql">
    <foreach collection="queryVariableValues" index="index" item="queryVariableValue">
      <if test="!queryVariableValue.operator.equals('EXISTS') &amp;&amp; !queryVariableValue.operator.equals('NOT_EXISTS')">
        <choose>
            <when test="queryVariableValue.local">
                inner join ${prefix}ACT_RU_VARIABLE A${index} on RES.ID_ = A${index}.EXECUTION_ID_
            </when>
            <otherwise>
                inner join ${prefix}ACT_RU_VARIABLE A${index} on RES.PROC_INST_ID_ = A${index}.PROC_INST_ID_
            </otherwise>
        </choose>
      </if>
    </foreach>
    <foreach collection="orQueryObjects" index="orIndex" item="orQueryObject">
      <if test="orQueryObject.processDefinitionId != null || orQueryObject.processDefinitionKey != null || orQueryObject.processDefinitionVersion != null || orQueryObject.processDefinitionCategory != null || orQueryObject.processDefinitionName != null || (orQueryObject.processDefinitionIds != null &amp;&amp; !orQueryObject.processDefinitionIds.isEmpty()) || (orQueryObject.processDefinitionKeys != null &amp;&amp; !orQueryObject.processDefinitionKeys.isEmpty())">
        inner join ${prefix}ACT_RE_PROCDEF P_OR${orIndex} on RES.PROC_DEF_ID_ = P_OR${orIndex}.ID_
      </if>
      <if test="orQueryObject.queryVariableValues != null &amp;&amp; orQueryObject.queryVariableValues.size() &gt; 0">
         <if test="orQueryObject.hasValueComparisonQueryVariables()">
            left outer join ${prefix}ACT_RU_VARIABLE A_OR${orIndex} on RES.PROC_INST_ID_ = A_OR${orIndex}.PROC_INST_ID_
         </if>
      </if>
      <if test="orQueryObject.deploymentId != null || (orQueryObject.deploymentIds != null &amp;&amp; orQueryObject.deploymentIds.size() &gt; 0)">
        left outer join ${prefix}ACT_RE_PROCDEF DEPLOY_P_OR${orIndex} ON RES.PROC_DEF_ID_ = DEPLOY_P_OR${orIndex}.ID_
      </if>
    </foreach>
    <if test="eventSubscriptions != null">
      <foreach collection="eventSubscriptions" index="index" item="eventSubscriptionValue">
    	inner join ${prefix}ACT_RU_EVENT_SUBSCR EVT${index} on RES.ID_ = EVT${index}.EXECUTION_ID_
	   </foreach>
    </if>
    <if test="businessKey != null and includeChildExecutionsWithBusinessKeyQuery">
        inner join ${prefix}ACT_RU_EXECUTION INST on RES.PROC_INST_ID_ = INST.ID_
    </if>
    <if test="deploymentId != null || (deploymentIds != null &amp;&amp; deploymentIds.size() &gt; 0)">
      left outer join ${prefix}ACT_RE_PROCDEF DEPLOY_P ON RES.PROC_DEF_ID_ = DEPLOY_P.ID_
    </if>
    <if test="onlyProcessInstances &amp;&amp; withJobException">
      left outer join ${prefix}ACT_RU_TIMER_JOB JOB ON RES.PROC_INST_ID_ = JOB.PROCESS_INSTANCE_ID_
    </if>
    <where>
      <if test="onlyProcessInstances">
        RES.PARENT_ID_ is null
      </if>
      <if test="processDefinitionId != null">
        and P.ID_ = #{processDefinitionId}
      </if>
      <if test="processDefinitionIds != null and !processDefinitionIds.isEmpty()">
        and P.ID_ in
        <foreach item="item" index="index" collection="processDefinitionIds" open="(" separator="," close=")">
          #{item}
        </foreach>
      </if>
      <if test="processDefinitionKey != null">
        and P.KEY_ = #{processDefinitionKey}
      </if>
      <if test="processDefinitionKeys != null and !processDefinitionKeys.isEmpty()">
        and P.KEY_ in
        <foreach item="item" index="index" collection="processDefinitionKeys" open="(" separator="," close=")">
          #{item}
        </foreach>
      </if>
      <if test="processDefinitionCategory != null">
        and P.CATEGORY_ = #{processDefinitionCategory}
      </if>
      <if test="processDefinitionName != null">
        and P.NAME_ = #{processDefinitionName}
      </if>
      <if test="processDefinitionVersion != null">
        and P.VERSION_ = #{processDefinitionVersion}
      </if>
      <if test="processDefinitionEngineVersion != null">
        and P.ENGINE_VERSION_ = #{processDefinitionEngineVersion}
      </if>
      <if test="executionId != null">
        and RES.ID_ = #{executionId}
      </if>
      <if test="processInstanceId != null">
        and RES.PROC_INST_ID_ = #{processInstanceId}
      </if>
      <if test="rootProcessInstanceId != null">
        and RES.ROOT_PROC_INST_ID_ = #{rootProcessInstanceId}
      </if>
      <if test="processInstanceIds != null and !processInstanceIds.isEmpty()">
        and RES.PROC_INST_ID_ in
        <foreach item="item" index="index" collection="processInstanceIds" open="(" separator="," close=")">
          #{item}
        </foreach>
      </if>
      <if test="businessKey != null and !includeChildExecutionsWithBusinessKeyQuery">
        and RES.BUSINESS_KEY_ = #{businessKey}
      </if>
      <if test="businessKey != null and includeChildExecutionsWithBusinessKeyQuery">
        and INST.BUSINESS_KEY_ = #{businessKey}
      </if>
      <if test="businessKeyLike != null and !includeChildExecutionsWithBusinessKeyQuery">
        and RES.BUSINESS_KEY_ like #{businessKeyLike}${wildcardEscapeClause}
      </if>
      <if test="businessKeyLike != null and includeChildExecutionsWithBusinessKeyQuery">
        and INST.BUSINESS_KEY_ like #{businessKeyLike}${wildcardEscapeClause}
      </if>
      <if test="activityId != null">
        and RES.ACT_ID_ = #{activityId} and RES.IS_ACTIVE_ = #{isActive}
      </if>
      <if test="parentId != null">
        and RES.PARENT_ID_ = #{parentId}
      </if>
      <if test="onlyChildExecutions">
      	and RES.PARENT_ID_ is not null
      </if>
      <if test="onlySubProcessExecutions">
        and ((RES.PARENT_ID_ is not null or RES.SUPER_EXEC_ is not null) and RES.IS_SCOPE_ = #{onlySubProcessExecutions,typeHandler=org.apache.ibatis.type.BooleanTypeHandler})
      </if>
      <if test="onlyProcessInstanceExecutions">
        and RES.PARENT_ID_ is null
      </if>
      <if test="deploymentId != null">
        and DEPLOY_P.DEPLOYMENT_ID_ = #{deploymentId}
      </if>
      <if test="deploymentIds != null &amp;&amp; deploymentIds.size() &gt; 0">
        and DEPLOY_P.DEPLOYMENT_ID_ IN
        <foreach item="deployment" index="index" collection="deploymentIds"
                 open="(" separator="," close=")">
          #{deployment}
        </foreach>
      </if>
      <if test="superProcessInstanceId != null">
        <!-- A sub process instance is stored under a certain *execution*, potentially nested.
             A sub process instance is NOT stored under the process instanc, hence the following: -->
        and RES.SUPER_EXEC_ IN (select ID_ from ${prefix}ACT_RU_EXECUTION where PROC_INST_ID_ = #{superProcessInstanceId})
      </if>
      <if test="subProcessInstanceId != null">
        and RES.ID_ = (select PROC_INST_ID_ from ${prefix}ACT_RU_EXECUTION where ID_ = (select SUPER_EXEC_ from ${prefix}ACT_RU_EXECUTION where ID_ = #{subProcessInstanceId}))
      </if>
      <if test="excludeSubprocesses">
        and RES.SUPER_EXEC_ is null
      </if>
      <if test="suspensionState != null">
      	<if test="suspensionState.stateCode == 1">
        	and (RES.SUSPENSION_STATE_ = 1)
        </if>
        <if test="suspensionState.stateCode == 2">
        	and (RES.SUSPENSION_STATE_ = 2)
        </if>
      </if>
      <if test="callbackId != null">
            and CALLBACK_ID_ = #{callbackId}
      </if>
      <if test="callbackType != null">
           and CALLBACK_TYPE_ = #{callbackType}
      </if>
      <if test="referenceId != null">
            and REFERENCE_ID_ = #{referenceId}
      </if>
      <if test="referenceType != null">
           and REFERENCE_TYPE_ = #{referenceType}
      </if>
      <if test="tenantId != null">
        and RES.TENANT_ID_ = #{tenantId}
      </if>
      <if test="tenantIdLike != null">
        and RES.TENANT_ID_ like #{tenantIdLike}${wildcardEscapeClause}
      </if>
      <if test="withoutTenantId">
        and (RES.TENANT_ID_ = '' or RES.TENANT_ID_ is null)
      </if>
      <if test="name != null">
        and RES.NAME_ = #{name}
      </if>
      <if test="nameLike != null">
        and RES.NAME_ like #{nameLike}${wildcardEscapeClause}
      </if>
      <if test="nameLikeIgnoreCase != null">
        and lower(RES.NAME_) like #{nameLikeIgnoreCase}${wildcardEscapeClause}
      </if>
      <if test="involvedUser != null">
        and EXISTS(select ID_ from ${prefix}ACT_RU_IDENTITYLINK I where I.PROC_INST_ID_ = RES.ID_ and I.USER_ID_ = #{involvedUser})
      </if>
      <if test="involvedUserIdentityLink != null">
        and EXISTS(select ID_ from ${prefix}ACT_RU_IDENTITYLINK I where I.PROC_INST_ID_ = RES.ID_ and 
        I.USER_ID_ = #{involvedUserIdentityLink.userId} and I.TYPE_ = #{involvedUserIdentityLink.type})
      </if>
      <if test="involvedGroups != null">
        and EXISTS(
          select ID_ from ${prefix}ACT_RU_IDENTITYLINK I where I.PROC_INST_ID_ = RES.ID_ and I.GROUP_ID_ in
          <foreach item="involvedGroup" index="index" collection="involvedGroups" open="(" separator="," close=")">
              #{involvedGroup}
          </foreach>
        )
      </if>
      <if test="involvedGroupIdentityLink != null">
        and EXISTS(select ID_ from ${prefix}ACT_RU_IDENTITYLINK I where I.PROC_INST_ID_ = RES.ID_ and 
        I.GROUP_ID_ = #{involvedGroupIdentityLink.groupId} and I.TYPE_ = #{involvedGroupIdentityLink.type})
      </if>
      <!-- PLEASE NOTE: If you change anything have a look into the HistoricVariableInstance & HistoricProcessInstance, the same query object is used there! -->
      <foreach collection="queryVariableValues" index="index" item="queryVariableValue">
        <choose>
            <when test="queryVariableValue.operator.equals('EXISTS')">
              and EXISTS (
                select ID_ from ${prefix}ACT_RU_VARIABLE where NAME_ = #{queryVariableValue.name}
                <if test="!queryVariableValue.local">
                    and RES.PROC_INST_ID_ = EXECUTION_ID_
                </if>
                <if test="queryVariableValue.local">
                    and RES.ID_ = EXECUTION_ID_
                </if>
              )
            </when>
            <when test="queryVariableValue.operator.equals('NOT_EXISTS')">
              and NOT EXISTS (
                select ID_ from ${prefix}ACT_RU_VARIABLE where NAME_ = #{queryVariableValue.name}
                <if test="!queryVariableValue.local">
                    and RES.PROC_INST_ID_ = EXECUTION_ID_
                </if>
                <if test="queryVariableValue.local">
                    and RES.ID_ = EXECUTION_ID_
                </if>
              )
            </when>
            <otherwise>
                <if test="!queryVariableValue.local">
                  <!-- When process instance variable is queried for, only process variables are taken into account -->
                  and A${index}.EXECUTION_ID_ = A${index}.PROC_INST_ID_
                </if>
                <if test="queryVariableValue.name != null">
                  <!-- Match-all variable-names when name is null -->
                  and A${index}.NAME_= #{queryVariableValue.name}
                </if>
                <if test="queryVariableValue.needsTypeCheck()">
                  and A${index}.TYPE_ = #{queryVariableValue.type}
                </if>
              	<if test="queryVariableValue.textValue != null &amp;&amp; queryVariableValue.longValue == null &amp;&amp; queryVariableValue.doubleValue == null">
                  <choose>
                    <when test="queryVariableValue.operator.equals('EQUALS_IGNORE_CASE') || queryVariableValue.operator.equals('NOT_EQUALS_IGNORE_CASE') || queryVariableValue.operator.equals('LIKE_IGNORE_CASE')">
                      and (lower(A${index}.TEXT_)
                    </when>
                    <otherwise>
                      and (A${index}.TEXT_
                    </otherwise>
                  </choose>
        	      <choose>
        	        <when test="queryVariableValue.operator.equals('LIKE') || queryVariableValue.operator.equals('LIKE_IGNORE_CASE')">LIKE</when>
        	        <otherwise><include refid="executionVariableOperator" /></otherwise>
        	      </choose>
          	      #{queryVariableValue.textValue}
          	      <choose>
        			<when test="queryVariableValue.operator.equals('LIKE') || queryVariableValue.operator.equals('LIKE_IGNORE_CASE')">${wildcardEscapeClause}</when>
        		  </choose>
                  <if test="queryVariableValue.operator.equals('NOT_EQUALS') || queryVariableValue.operator.equals('NOT_EQUALS_IGNORE_CASE')">
                      or A${index}.TEXT_ is null
                  </if>
                  )
              	</if>
              	<if test="queryVariableValue.textValue2 != null">
        	      and A${index}.TEXT2_
        	      <choose>
        	        <when test="queryVariableValue.operator.equals('LIKE')">LIKE</when>
        	        <otherwise><include refid="executionVariableOperator" /></otherwise>
        	      </choose>
        	        #{queryVariableValue.textValue2}
        	      <choose>
        			<when test="queryVariableValue.operator.equals('LIKE')">${wildcardEscapeClause}</when>
        		  </choose>
              	</if>
              	<if test="queryVariableValue.longValue != null">
        	      and (A${index}.LONG_
        	      <include refid="executionVariableOperator" />
        	      #{queryVariableValue.longValue}
                  <if test="queryVariableValue.operator.equals('NOT_EQUALS') || queryVariableValue.operator.equals('NOT_EQUALS_IGNORE_CASE')">
                      or A${index}.LONG_ is null
                  </if>
                  )
              	</if>
              	<if test="queryVariableValue.doubleValue != null">
        	      and (A${index}.DOUBLE_
        	      <include refid="executionVariableOperator" />
        	      #{queryVariableValue.doubleValue}
                  <if test="queryVariableValue.operator.equals('NOT_EQUALS') || queryVariableValue.operator.equals('NOT_EQUALS_IGNORE_CASE')">
                      or A${index}.DOUBLE_ is null
                  </if>
                  )
              	</if>
              	<!-- Null variable type -->
              	<if test="queryVariableValue.textValue == null &amp;&amp; queryVariableValue.textValue2 == null &amp;&amp; queryVariableValue.longValue == null &amp;&amp; queryVariableValue.doubleValue == null">
                  <choose>
        	        <when test="queryVariableValue.operator.equals('NOT_EQUALS')">
        	          and (A${index}.TEXT_ is not null or A${index}.TEXT2_ is not null or A${index}.LONG_ is not null or A${index}.DOUBLE_ is not null or A${index}.BYTEARRAY_ID_ is not null)
        	        </when>
        	        <otherwise>
        			  and A${index}.TEXT_ is null and A${index}.TEXT2_ is null and A${index}.LONG_ is null and A${index}.DOUBLE_ is null and A${index}.BYTEARRAY_ID_ is null
        	        </otherwise>
        	      </choose>
              	</if>
            </otherwise>
        </choose>
      </foreach>
      <!-- event subscriptions -->
      <if test="eventSubscriptions != null">
        <foreach collection="eventSubscriptions" index="index" item="eventSubscriptionValue">
    	    and (EVT${index}.EVENT_TYPE_ = #{eventSubscriptionValue.eventType} and EVT${index}.EVENT_NAME_ = #{eventSubscriptionValue.eventName})
	      </foreach>
      </if>
      <foreach item="orQueryObject" index="orIndex" collection="orQueryObjects">
        and
        <trim prefix="(" prefixOverrides="OR" suffix=")">
          <if test="orQueryObject.processDefinitionId != null">
            P_OR${orIndex}.ID_ = #{orQueryObject.processDefinitionId}
          </if>
          <if test="orQueryObject.processDefinitionIds != null and !orQueryObject.processDefinitionIds.isEmpty()">
            or P_OR${orIndex}.ID_ in
            <foreach item="item" index="index" collection="orQueryObject.processDefinitionIds" open="(" separator="," close=")">
              #{item}
            </foreach>
          </if>
          <if test="orQueryObject.processDefinitionKey != null">
            or P_OR${orIndex}.KEY_ = #{orQueryObject.processDefinitionKey}
          </if>
          <if test="orQueryObject.processDefinitionKeys != null and !orQueryObject.processDefinitionKeys.isEmpty()">
            or P_OR${orIndex}.KEY_ in
            <foreach item="item" index="index" collection="orQueryObject.processDefinitionKeys" open="(" separator="," close=")">
              #{item}
            </foreach>
          </if>
          <if test="orQueryObject.processDefinitionCategory != null">
            or P_OR${orIndex}.CATEGORY_ = #{orQueryObject.processDefinitionCategory}
          </if>
          <if test="orQueryObject.processDefinitionName != null">
            or P_OR${orIndex}.NAME_ = #{orQueryObject.processDefinitionName}
          </if>
          <if test="orQueryObject.processDefinitionVersion != null">
            or P_OR${orIndex}.VERSION_ = #{orQueryObject.processDefinitionVersion}
          </if>
          <if test="orQueryObject.processDefinitionEngineVersion != null">
            or P_OR${orIndex}.ENGINE_VERSION_ = #{orQueryObject.processDefinitionEngineVersion}
          </if>
          <if test="orQueryObject.executionId != null">
            or RES.ID_ = #{orQueryObject.executionId}
          </if>
          <if test="orQueryObject.processInstanceId != null">
            or RES.PROC_INST_ID_ = #{orQueryObject.processInstanceId}
          </if>
          <if test="orQueryObject.processInstanceIds != null and !orQueryObject.processInstanceIds.isEmpty()">
            or RES.PROC_INST_ID_ in
            <foreach item="item" index="index" collection="orQueryObject.processInstanceIds" open="(" separator="," close=")">
              #{item}
            </foreach>
          </if>
          <if test="orQueryObject.businessKey != null">
            or RES.BUSINESS_KEY_ = #{orQueryObject.businessKey}
          </if>
          <if test="orQueryObject.activityId != null">
            or (RES.ACT_ID_ = #{orQueryObject.activityId} and RES.IS_ACTIVE_ = #{isActive})
          </if>
          <if test="orQueryObject.parentId != null">
            or RES.PARENT_ID_ = #{orQueryObject.parentId}
          </if>
          <if test="orQueryObject.deploymentId != null">
            or DEPLOY_P_OR${orIndex}.DEPLOYMENT_ID_ = #{orQueryObject.deploymentId}
          </if>
          <if test="orQueryObject.deploymentIds != null &amp;&amp; orQueryObject.deploymentIds.size() &gt; 0">
            or DEPLOY_P_OR${orIndex}.DEPLOYMENT_ID_ IN
            <foreach item="deployment" index="index" collection="orQueryObject.deploymentIds"
                     open="(" separator="," close=")">
              #{deployment}
            </foreach>
          </if>
          <if test="orQueryObject.superProcessInstanceId != null">
            <!-- A sub process instance is stored under a certain *execution*, potentially nested.
                 A sub process instance is NOT stored under the process instanc, hence the following: -->
            or RES.SUPER_EXEC_ IN (select ID_ from ${prefix}ACT_RU_EXECUTION where PROC_INST_ID_ = #{orQueryObject.superProcessInstanceId})
          </if>
          <if test="orQueryObject.subProcessInstanceId != null">
            or RES.ID_ = (select PROC_INST_ID_ from ${prefix}ACT_RU_EXECUTION where ID_ = (select SUPER_EXEC_ from ${prefix}ACT_RU_EXECUTION where ID_ = #{orQueryObject.subProcessInstanceId}))
          </if>
          <if test="orQueryObject.excludeSubprocesses">
            or RES.SUPER_EXEC_ is null
          </if>
          <if test="orQueryObject.suspensionState != null">
            <if test="orQueryObject.suspensionState.stateCode == 1">
              or (RES.SUSPENSION_STATE_ = 1)
            </if>
            <if test="orQueryObject.suspensionState.stateCode == 2">
              or (RES.SUSPENSION_STATE_ = 2)
            </if>
          </if>
          <if test="orQueryObject.callbackId != null">
              or CALLBACK_ID_ = #{orQueryObject.callbackId}
          </if>
          <if test="orQueryObject.callbackType != null">
              or CALLBACK_TYPE_ = #{orQueryObject.callbackType}
          </if>
          <if test="orQueryObject.referenceId != null">
              or REFERENCE_ID_ = #{orQueryObject.referenceId}
          </if>
          <if test="orQueryObject.referenceType != null">
              or REFERENCE_TYPE_ = #{orQueryObject.referenceType}
          </if>
          <if test="orQueryObject.tenantId != null">
            or RES.TENANT_ID_ = #{orQueryObject.tenantId}
          </if>
          <if test="orQueryObject.tenantIdLike != null">
            or RES.TENANT_ID_ like #{orQueryObject.tenantIdLike}${wildcardEscapeClause}
          </if>
          <if test="orQueryObject.withoutTenantId">
            or (RES.TENANT_ID_ = '' or RES.TENANT_ID_ is null)
          </if>
          <if test="orQueryObject.name != null">
            or RES.NAME_ = #{orQueryObject.name}
          </if>
          <if test="orQueryObject.nameLike != null">
            or RES.NAME_ like #{orQueryObject.nameLike}${wildcardEscapeClause}
          </if>
          <if test="orQueryObject.nameLikeIgnoreCase != null">
            or lower(RES.NAME_) like #{orQueryObject.nameLikeIgnoreCase}${wildcardEscapeClause}
          </if>
          <if test="orQueryObject.involvedUser != null">
            or EXISTS(select ID_ from ${prefix}ACT_RU_IDENTITYLINK I where I.PROC_INST_ID_ = RES.ID_ and I.USER_ID_ = #{orQueryObject.involvedUser})
          </if>
          <if test="orQueryObject.involvedUserIdentityLink != null">
	        or EXISTS(select ID_ from ${prefix}ACT_RU_IDENTITYLINK I where I.PROC_INST_ID_ = RES.ID_ and 
	        I.USER_ID_ = #{orQueryObject.involvedUserIdentityLink.userId} and I.TYPE_ = #{orQueryObject.involvedUserIdentityLink.type})
	      </if>
          <if test="orQueryObject.involvedGroups != null">
            or EXISTS(select ID_ from ${prefix}ACT_RU_IDENTITYLINK I where I.PROC_INST_ID_ = RES.ID_ and I.GROUP_ID_ in
              <foreach item="involvedGroup" index="index" collection="orQueryObject.involvedGroups" open="(" separator="," close=")">
                  #{involvedGroup}
              </foreach>
            )
          </if>
          <if test="orQueryObject.involvedGroupIdentityLink != null">
	        or EXISTS(select ID_ from ${prefix}ACT_RU_IDENTITYLINK I where I.PROC_INST_ID_ = RES.ID_ and 
	        I.GROUP_ID_ = #{orQueryObject.involvedGroupIdentityLink.groupId} and I.TYPE_ = #{orQueryObject.involvedGroupIdentityLink.type})
	      </if>
          <!-- PLEASE NOTE: If you change anything have a look into the HistoricVariableInstance & HistoricProcessInstance, the same query object is used there! -->
          <foreach collection="orQueryObject.queryVariableValues" index="index" item="queryVariableValue">
            or
            <trim prefix="(" prefixOverrides="AND" suffix=")">
              <choose>
                <when test="queryVariableValue.operator.equals('EXISTS')">
                    and EXISTS (
                        select ID_ from ${prefix}ACT_RU_VARIABLE where NAME_ = #{queryVariableValue.name}
                    <if test="!queryVariableValue.local">
                        and RES.PROC_INST_ID_ = PROC_INST_ID_ and TASK_ID_ is null
                    </if>
                    <if test="queryVariableValue.local">
                        and RES.ID_ = TASK_ID_
                    </if>
                    )
                </when>
                <when test="queryVariableValue.operator.equals('NOT_EXISTS')">
                    and NOT EXISTS (
                        select ID_ from ${prefix}ACT_RU_VARIABLE where NAME_ = #{queryVariableValue.name}
                    <if test="!queryVariableValue.local">
                        and RES.PROC_INST_ID_ = PROC_INST_ID_ and TASK_ID_ is null
                    </if>
                    <if test="queryVariableValue.local">
                        and RES.ID_ = TASK_ID_
                    </if>
                    )
                </when>
                <otherwise>
                  <if test="!queryVariableValue.local">
                    <!-- When process instance variable is queried for, only process variables are taken into account -->
                    and A_OR${orIndex}.EXECUTION_ID_ = A_OR${orIndex}.PROC_INST_ID_
                  </if>
                  <if test="queryVariableValue.name != null">
                    <!-- Match-all variable-names when name is null -->
                    and A_OR${orIndex}.NAME_= #{queryVariableValue.name}
                  </if>
                  <if test="queryVariableValue.needsTypeCheck()">
                    and A_OR${orIndex}.TYPE_ = #{queryVariableValue.type}
                  </if>
                  <if test="queryVariableValue.textValue != null &amp;&amp; queryVariableValue.longValue == null &amp;&amp; queryVariableValue.doubleValue == null">
                    <choose>
                      <when test="queryVariableValue.operator.equals('EQUALS_IGNORE_CASE') || queryVariableValue.operator.equals('NOT_EQUALS_IGNORE_CASE') || queryVariableValue.operator.equals('LIKE_IGNORE_CASE')">
                        and (lower(A_OR${orIndex}.TEXT_)
                      </when>
                      <otherwise>
                        and (A_OR${orIndex}.TEXT_
                      </otherwise>
                    </choose>
                  <choose>
                    <when test="queryVariableValue.operator.equals('LIKE') || queryVariableValue.operator.equals('LIKE_IGNORE_CASE')">LIKE</when>
                    <otherwise><include refid="executionVariableOperator" /></otherwise>
                  </choose>
                    #{queryVariableValue.textValue}
                  <choose>
                    <when test="queryVariableValue.operator.equals('LIKE') || queryVariableValue.operator.equals('LIKE_IGNORE_CASE')">${wildcardEscapeClause}</when>
                  </choose>
                    <if test="queryVariableValue.operator.equals('NOT_EQUALS') || queryVariableValue.operator.equals('NOT_EQUALS_IGNORE_CASE')">
                        or A_OR${index}.TEXT_ is null
                    </if>
                    )
                  </if>
                  <if test="queryVariableValue.textValue2 != null">
                  and A_OR${orIndex}.TEXT2_
                  <choose>
                    <when test="queryVariableValue.operator.equals('LIKE')">LIKE</when>
                    <otherwise><include refid="executionVariableOperator" /></otherwise>
                  </choose>
                    #{queryVariableValue.textValue2}
                    <choose>
                      <when test="queryVariableValue.operator.equals('LIKE')">${wildcardEscapeClause}</when>
                    </choose>
                  </if>
                  <if test="queryVariableValue.longValue != null">
                  and (A_OR${orIndex}.LONG_
                  <include refid="executionVariableOperator" />
                  #{queryVariableValue.longValue}
                    <if test="queryVariableValue.operator.equals('NOT_EQUALS') || queryVariableValue.operator.equals('NOT_EQUALS_IGNORE_CASE')">
                        or A_OR${index}.LONG_ is null
                    </if>
                    )
                  </if>
                  <if test="queryVariableValue.doubleValue != null">
                  and (A_OR${orIndex}.DOUBLE_
                  <include refid="executionVariableOperator" />
                  #{queryVariableValue.doubleValue}
                    <if test="queryVariableValue.operator.equals('NOT_EQUALS') || queryVariableValue.operator.equals('NOT_EQUALS_IGNORE_CASE')">
                        or A_OR${index}.DOUBLE_ is null
                    </if>
                    )
                  </if>
                  <!-- Null variable type -->
                  <if test="queryVariableValue.textValue == null &amp;&amp; queryVariableValue.textValue2 == null &amp;&amp; queryVariableValue.longValue == null &amp;&amp; queryVariableValue.doubleValue == null">
                    <choose>
                      <when test="queryVariableValue.operator.equals('NOT_EQUALS')">
                        and (A_OR${orIndex}.TEXT_ is not null or A_OR${orIndex}.TEXT2_ is not null or A_OR${orIndex}.LONG_ is not null or A_OR${orIndex}.DOUBLE_ is not null or A_OR${orIndex}.BYTEARRAY_ID_ is not null)
                      </when>
                      <otherwise>
                        and A_OR${orIndex}.TEXT_ is null and A_OR${orIndex}.TEXT2_ is null and A_OR${orIndex}.LONG_ is null and A_OR${orIndex}.DOUBLE_ is null and A_OR${orIndex}.BYTEARRAY_ID_ is null
                      </otherwise>
                    </choose>
                  </if>
                </otherwise>
              </choose>
            </trim>
          </foreach>
        </trim>
      </foreach>
      <if test="onlyProcessInstances &amp;&amp; withJobException">
        and (JOB.EXCEPTION_MSG_ is not null or JOB.EXCEPTION_STACK_ID_ is not null)
      </if>
      <if test="startedBefore != null">
        and RES.START_TIME_ &lt;= #{startedBefore}
      </if>
      <if test="startedAfter != null">
        and RES.START_TIME_ &gt;= #{startedAfter}
      </if>
      <if test="startedBy != null">
        and RES.START_USER_ID_ = #{startedBy}
      </if>
    </where>
  </sql>

  <sql id="executionVariableOperator">
    <choose>
   	  <when test="queryVariableValue.operator.equals('EQUALS')">=</when>
   	  <when test="queryVariableValue.operator.equals('EQUALS_IGNORE_CASE')">=</when>
   	  <when test="queryVariableValue.operator.equals('NOT_EQUALS')">&lt;&gt;</when>
   	  <when test="queryVariableValue.operator.equals('NOT_EQUALS_IGNORE_CASE')">&lt;&gt;</when>
   	  <when test="queryVariableValue.operator.equals('GREATER_THAN')">&gt;</when>
   	  <when test="queryVariableValue.operator.equals('GREATER_THAN_OR_EQUAL')">&gt;=</when>
   	  <when test="queryVariableValue.operator.equals('LESS_THAN')">&lt;</when>
   	  <when test="queryVariableValue.operator.equals('LESS_THAN_OR_EQUAL')">&lt;=</when>
   </choose>
  </sql>

  <select id="selectSubProcessInstanceBySuperExecutionId" parameterType="string" resultMap="executionResultMap">
    select *
    from ${prefix}ACT_RU_EXECUTION
    where SUPER_EXEC_ = #{parameter}
  </select>

  <select id="selectExecutionByNativeQuery" parameterType="java.util.Map" resultMap="executionResultMap">
  	<include refid="org.flowable.engine.db.common.selectByNativeQuery"/>
  </select>

  <select id="selectExecutionCountByNativeQuery" parameterType="java.util.Map" resultType="long">
    ${sql}
  </select>

</mapper>




© 2015 - 2024 Weber Informatics LLC | Privacy Policy