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

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

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

<!--
  ~ Licensed under the Apache License, Version 2.0 (the "License");
  ~ you may not use this file except in compliance with the License.
  ~ You may obtain a copy of the License at
  ~
  ~       http://www.apache.org/licenses/LICENSE-2.0
  ~
  ~ Unless required by applicable law or agreed to in writing, software
  ~ distributed under the License is distributed on an "AS IS" BASIS,
  ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  ~ See the License for the specific language governing permissions and
  ~ limitations under the License.
  -->

<!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.HistoricActivityInstanceEntityImpl">

  <!-- HISTORIC ACTIVITY INSTANCE INSERT -->
  
  <insert id="insertHistoricActivityInstance" parameterType="org.flowable.engine.impl.persistence.entity.HistoricActivityInstanceEntityImpl">
      insert into ${prefix}ACT_HI_ACTINST (
        ID_,
        REV_,
        PROC_DEF_ID_,
        PROC_INST_ID_,
        EXECUTION_ID_,
        ACT_ID_,
        TASK_ID_,
        CALL_PROC_INST_ID_,
        ACT_NAME_,
        ACT_TYPE_,
        ASSIGNEE_,
        START_TIME_,
        END_TIME_,
        TRANSACTION_ORDER_,
        DURATION_,
        DELETE_REASON_,
        TENANT_ID_
      ) values (
        #{id ,jdbcType=VARCHAR},
        1, #{processDefinitionId, jdbcType=VARCHAR},
        #{processInstanceId, jdbcType=VARCHAR},
        #{executionId, jdbcType=VARCHAR},
        #{activityId ,jdbcType=VARCHAR},
        #{taskId ,jdbcType=VARCHAR},
        #{calledProcessInstanceId ,jdbcType=VARCHAR},
        #{activityName ,jdbcType=VARCHAR},
        #{activityType ,jdbcType=VARCHAR},
        #{assignee ,jdbcType=VARCHAR},
        #{startTime, jdbcType=TIMESTAMP},
        #{endTime, jdbcType=TIMESTAMP},
        #{transactionOrder ,jdbcType=INTEGER},
        #{durationInMillis ,jdbcType=BIGINT},
        #{deleteReason, jdbcType=VARCHAR},
        #{tenantId, jdbcType=VARCHAR}
      )
  </insert>
  
  <insert id="bulkInsertHistoricActivityInstance" parameterType="java.util.List">
      insert into ${prefix}ACT_HI_ACTINST (
        ID_,
        REV_,
        PROC_DEF_ID_,
        PROC_INST_ID_,
        EXECUTION_ID_,
        ACT_ID_,
        TASK_ID_,
        CALL_PROC_INST_ID_,
        ACT_NAME_,
        ACT_TYPE_,
        ASSIGNEE_,
        START_TIME_,
        END_TIME_,
        TRANSACTION_ORDER_,
        DURATION_,
        DELETE_REASON_,
        TENANT_ID_
      ) values 
      <foreach collection="list" item="historicActivityInstance" index="index" separator=",">
         (#{historicActivityInstance.id ,jdbcType=VARCHAR},
          1, #{historicActivityInstance.processDefinitionId, jdbcType=VARCHAR},
          #{historicActivityInstance.processInstanceId, jdbcType=VARCHAR},
          #{historicActivityInstance.executionId, jdbcType=VARCHAR},
          #{historicActivityInstance.activityId ,jdbcType=VARCHAR},
          #{historicActivityInstance.taskId ,jdbcType=VARCHAR},
          #{historicActivityInstance.calledProcessInstanceId ,jdbcType=VARCHAR},
          #{historicActivityInstance.activityName ,jdbcType=VARCHAR},
          #{historicActivityInstance.activityType ,jdbcType=VARCHAR},
          #{historicActivityInstance.assignee ,jdbcType=VARCHAR},
          #{historicActivityInstance.startTime, jdbcType=TIMESTAMP},
          #{historicActivityInstance.endTime, jdbcType=TIMESTAMP},
          #{historicActivityInstance.transactionOrder, jdbcType=INTEGER},
          #{historicActivityInstance.durationInMillis, jdbcType=BIGINT},
          #{historicActivityInstance.deleteReason, jdbcType=VARCHAR},
          #{historicActivityInstance.tenantId, jdbcType=VARCHAR})
      </foreach>
  </insert>
  
  <insert id="bulkInsertHistoricActivityInstance" databaseId="oracle" parameterType="java.util.List">
      INSERT ALL 
      <foreach collection="list" item="historicActivityInstance" index="index">
        INTO ${prefix}ACT_HI_ACTINST (
          ID_,
          REV_,
          PROC_DEF_ID_,
          PROC_INST_ID_,
          EXECUTION_ID_,
          ACT_ID_,
          TASK_ID_,
          CALL_PROC_INST_ID_,
          ACT_NAME_,
          ACT_TYPE_,
          ASSIGNEE_,
          START_TIME_,
          END_TIME_,
          TRANSACTION_ORDER_,
          DURATION_,
          DELETE_REASON_,
          TENANT_ID_
        ) VALUES 
           (#{historicActivityInstance.id ,jdbcType=VARCHAR},
            1, #{historicActivityInstance.processDefinitionId, jdbcType=VARCHAR},
            #{historicActivityInstance.processInstanceId, jdbcType=VARCHAR},
            #{historicActivityInstance.executionId, jdbcType=VARCHAR},
            #{historicActivityInstance.activityId ,jdbcType=VARCHAR},
            #{historicActivityInstance.taskId ,jdbcType=VARCHAR},
            #{historicActivityInstance.calledProcessInstanceId ,jdbcType=VARCHAR},
            #{historicActivityInstance.activityName ,jdbcType=VARCHAR},
            #{historicActivityInstance.activityType ,jdbcType=VARCHAR},
            #{historicActivityInstance.assignee ,jdbcType=VARCHAR},
            #{historicActivityInstance.startTime, jdbcType=TIMESTAMP},
            #{historicActivityInstance.endTime, jdbcType=TIMESTAMP},
            #{historicActivityInstance.transactionOrder, jdbcType=INTEGER},
            #{historicActivityInstance.durationInMillis ,jdbcType=BIGINT},
            #{historicActivityInstance.deleteReason ,jdbcType=VARCHAR},
            #{historicActivityInstance.tenantId, jdbcType=VARCHAR})
      </foreach>
    SELECT * FROM dual
  </insert>

  <!-- HISTORIC ACTIVITY INSTANCE UPDATE -->
  
  <update id="updateHistoricActivityInstance" parameterType="org.flowable.engine.impl.persistence.entity.HistoricActivityInstanceEntityImpl">
    update ${prefix}ACT_HI_ACTINST
    <set>
        REV_ = #{revisionNext, jdbcType=INTEGER},
        <if test="originalPersistentState.processDefinitionId != processDefinitionId">
            PROC_DEF_ID_ = #{processDefinitionId, jdbcType=VARCHAR},
        </if>
        <if test="originalPersistentState.executionId != executionId">
            EXECUTION_ID_ = #{executionId, jdbcType=VARCHAR},
        </if>
        <if test="originalPersistentState.taskId != taskId">
            TASK_ID_ = #{taskId, jdbcType=VARCHAR},
        </if>
        <if test="originalPersistentState.assignee != assignee">
            ASSIGNEE_ = #{assignee, jdbcType=VARCHAR},
        </if>
        <if test="originalPersistentState.endTime != endTime">
            END_TIME_ = #{endTime, jdbcType=VARCHAR},
        </if>
        <if test="originalPersistentState.transactionOrder != transactionOrder">
        	TRANSACTION_ORDER_ = #{transactionOrder, jdbcType=INTEGER}, 
        </if>
        <if test="originalPersistentState.durationInMillis != durationInMillis">
            DURATION_ = #{durationInMillis, jdbcType=VARCHAR},
        </if>
        <if test="originalPersistentState.deleteReason != deleteReason">
            DELETE_REASON_ = #{deleteReason, jdbcType=VARCHAR},
        </if>
        <if test="originalPersistentState.calledProcessInstanceId != calledProcessInstanceId">
            CALL_PROC_INST_ID_ = #{calledProcessInstanceId, jdbcType=VARCHAR},
        </if>
        <if test="originalPersistentState.activityId != activityId">
            ACT_ID_ = #{activityId, jdbcType=VARCHAR},
        </if>
        <if test="originalPersistentState.activityName != activityName">
            ACT_NAME_ = #{activityName, jdbcType=VARCHAR},
        </if>
    </set>
    where ID_ = #{id}
    and REV_ = #{revision, jdbcType=INTEGER}
</update>

  <!-- HISTORIC ACTIVITY INSTANCE DELETE -->
  
  <delete id="deleteHistoricActivityInstancesByProcessInstanceId">
    delete from ${prefix}ACT_HI_ACTINST where PROC_INST_ID_ = #{processInstanceId}
  </delete>

  <delete id="deleteHistoricActivityInstance">
    delete from ${prefix}ACT_HI_ACTINST where ID_ = #{id}
  </delete>

  <delete id="bulkDeleteHistoricActivityInstance" parameterType="java.util.Collection">
        delete from ${prefix}ACT_HI_ACTINST where
        <foreach item="activityInstance" collection="list" index="index" separator=" or ">
            ID_ = #{activityInstance.id, jdbcType=VARCHAR}
        </foreach>
  </delete>
  
  <!-- HISTORIC ACTIVITY INSTANCE RESULT MAP -->

  <resultMap id="historicActivityInstanceResultMap" type="org.flowable.engine.impl.persistence.entity.HistoricActivityInstanceEntityImpl">
    <id property="id" column="ID_" jdbcType="VARCHAR" />
    <result property="revision" column="REV_" jdbcType="INTEGER"/>
    <result property="processDefinitionId" column="PROC_DEF_ID_" jdbcType="VARCHAR" />
    <result property="processInstanceId" column="PROC_INST_ID_" jdbcType="VARCHAR" />
    <result property="executionId" column="EXECUTION_ID_" jdbcType="VARCHAR" />
    <result property="activityId" column="ACT_ID_" jdbcType="VARCHAR" />
    <result property="taskId" column="TASK_ID_" jdbcType="VARCHAR" />
    <result property="calledProcessInstanceId" column="CALL_PROC_INST_ID_" jdbcType="VARCHAR" />
    <result property="activityName" column="ACT_NAME_" jdbcType="VARCHAR" />
    <result property="activityType" column="ACT_TYPE_" jdbcType="VARCHAR" />
    <result property="assignee" column="ASSIGNEE_" jdbcType="VARCHAR" />
    <result property="startTime" column="START_TIME_" jdbcType="TIMESTAMP" />
    <result property="endTime" column="END_TIME_" jdbcType="TIMESTAMP" />
    <result property="transactionOrder" column="TRANSACTION_ORDER_" jdbcType="INTEGER" />
    <result property="durationInMillis" column="DURATION_" jdbcType="BIGINT" />
    <result property="deleteReason" column="DELETE_REASON_" jdbcType="VARCHAR" />
    <result property="tenantId" column="TENANT_ID_" jdbcType="VARCHAR" />
  </resultMap>

  <!-- HISTORIC ACTIVITY INSTANCE SELECT -->
  
  <select id="selectHistoricActivityInstanceByActivityIdAndProcessInstanceId" resultMap="historicActivityInstanceResultMap">
    select * from ${prefix}ACT_HI_ACTINST where ACT_ID_ = #{activityId} and PROC_INST_ID_ = #{processInstanceId}
  </select>

  <select id="selectHistoricActivityInstance" resultMap="historicActivityInstanceResultMap">
    select * from ${prefix}ACT_HI_ACTINST where ID_ =#{id}
  </select>

  <select id="selectHistoricActivityInstancesByQueryCriteria" parameterType="org.flowable.engine.impl.HistoricActivityInstanceQueryImpl" resultMap="historicActivityInstanceResultMap">
    <if test="needsPaging">${limitBefore}</if>
    SELECT RES.* <if test="needsPaging">${limitBetween}</if>
    <include refid="selectHistoricActivityInstancesByQueryCriteriaSql">
        <property name="queryTablePrefixSelect" value="RES"/>
        <property name="queryTablePrefix" value="RES."/>
    </include>
    ${orderBy}
    <if test="needsPaging">${limitAfter}</if>
  </select>
  
  <select id="selectHistoricActivityInstanceCountByQueryCriteria" parameterType="org.flowable.engine.impl.HistoricActivityInstanceQueryImpl" resultType="long">
    select count(RES.ID_)
    <include refid="selectHistoricActivityInstancesByQueryCriteriaSql">
        <property name="queryTablePrefixSelect" value="RES"/>
        <property name="queryTablePrefix" value="RES."/>
    </include>
  </select>
  
  <delete id="bulkDeleteHistoricActivityInstances">
    delete 
    <include refid="selectHistoricActivityInstancesByQueryCriteriaSql">
        <property name="queryTablePrefixSelect" value=""/>
        <property name="queryTablePrefix" value=""/>
    </include>
  </delete>
  
  <delete id="bulkDeleteHistoricActivityInstancesForNonExistingProcessInstances" parameterType="java.util.Map">
    delete <if test="_databaseId != 'postgres' and _databaseId != 'cockroachdb' and _databaseId != 'db2'"> ACTINST </if> from ${prefix}ACT_HI_ACTINST ACTINST where ACTINST.PROC_INST_ID_ is not null and ACTINST.PROC_INST_ID_ != '' and
    NOT EXISTS (select PROCINST.ID_ from ${prefix}ACT_HI_PROCINST PROCINST where ACTINST.PROC_INST_ID_ = PROCINST.ID_)
  </delete>
  
  <delete id="bulkDeleteHistoricActivityInstancesForNonExistingProcessInstances" parameterType="java.util.Map" databaseId="oracle">
      delete from ${prefix}ACT_HI_ACTINST ACTINST where ACTINST.PROC_INST_ID_ is not null and
      NOT EXISTS (select PROCINST.ID_ from ${prefix}ACT_HI_PROCINST PROCINST where ACTINST.PROC_INST_ID_ = PROCINST.ID_)
  </delete>

  <delete id="bulkDeleteHistoricActivityInstancesForNonExistingProcessInstances" databaseId="h2" parameterType="java.util.Map">
    delete from ${prefix}ACT_HI_ACTINST where PROC_INST_ID_ is not null and PROC_INST_ID_ != '' and 
    PROC_INST_ID_ NOT IN (select PROCINST.ID_ from ${prefix}ACT_HI_PROCINST PROCINST)
  </delete>

  <delete id="bulkDeleteHistoricActivityInstancesForNonExistingProcessInstances" databaseId="hsql" parameterType="java.util.Map">
    delete from ${prefix}ACT_HI_ACTINST where PROC_INST_ID_ is not null and PROC_INST_ID_ != '' and
    PROC_INST_ID_ NOT IN (select PROCINST.ID_ from ${prefix}ACT_HI_PROCINST PROCINST)
  </delete>
  
  <sql id="selectHistoricActivityInstancesByQueryCriteriaSql">
    from ${prefix}ACT_HI_ACTINST ${queryTablePrefixSelect}
    <where>
      <if test="processInstanceId != null">
        ${queryTablePrefix}PROC_INST_ID_ = #{processInstanceId}
      </if>
      <if test="activityInstanceId != null">
        and ${queryTablePrefix}ID_ = #{activityInstanceId}
      </if>
      <if test="executionId != null">
        and ${queryTablePrefix}EXECUTION_ID_ = #{executionId}
      </if>
      <if test="processDefinitionId != null">
        and ${queryTablePrefix}PROC_DEF_ID_ = #{processDefinitionId}
      </if>
      <if test="activityId != null">
        and ${queryTablePrefix}ACT_ID_ = #{activityId}
      </if>
      <if test="activityName != null">
        and ${queryTablePrefix}ACT_NAME_ = #{activityName}
      </if>
      <if test="activityType != null">
        and ${queryTablePrefix}ACT_TYPE_ = #{activityType}
      </if>
      <if test="activityTypes != null and !activityTypes.isEmpty()">
        and ${queryTablePrefix}ACT_TYPE_ in
         <foreach item="item" index="index" collection="activityTypes" open="(" separator="," close=")">
              #{item}
         </foreach>
      </if>
      <if test="startedBefore != null">
          and ${queryTablePrefix}START_TIME_ &lt;= #{startedBefore}
      </if>
      <if test="startedAfter != null">
          and ${queryTablePrefix}START_TIME_ &gt;= #{startedAfter}
      </if>
      <if test="finishedBefore != null">
          and ${queryTablePrefix}END_TIME_ &lt;= #{finishedBefore}
      </if>
      <if test="finishedAfter != null">
        and ${queryTablePrefix}END_TIME_ &gt;= #{finishedAfter}
      </if>
      <if test="assignee != null">
        and ${queryTablePrefix}ASSIGNEE_ = #{assignee}
      </if>
      <if test="tenantId != null">
        and ${queryTablePrefix}TENANT_ID_ = #{tenantId}
      </if>
      <if test="tenantIds != null &amp;&amp; !tenantIds.isEmpty()">
        and ${queryTablePrefix}TENANT_ID_ in
        <foreach item="tenantId" index="index" collection="tenantIds" open="(" separator="," close=")">
            #{tenantId}
         </foreach>
      </if>
      <if test="tenantIdLike != null">
        and ${queryTablePrefix}TENANT_ID_ like #{tenantIdLike}${wildcardEscapeClause}
      </if>
      <if test="withoutTenantId">
        and (${queryTablePrefix}TENANT_ID_ = '' or ${queryTablePrefix}TENANT_ID_ is null)
      </if>
      <if test="unfinished">
        and ${queryTablePrefix}END_TIME_ is null
      </if>
      <if test="finished">
       and ${queryTablePrefix}END_TIME_ is not null
      </if>
      <if test="deleteReason != null">
        and ${queryTablePrefix}DELETE_REASON_ = #{deleteReason}
      </if>
      <if test="deleteReasonLike != null">
        and ${queryTablePrefix}DELETE_REASON_ like #{deleteReasonLike}${wildcardEscapeClause}
      </if>
    </where>
  </sql>
  
  <select id="selectHistoricActivityInstanceByNativeQuery" parameterType="java.util.Map" resultMap="historicActivityInstanceResultMap">
  	<include refid="org.flowable.common.engine.db.selectByNativeQuery"/>
  </select>
  
  <select id="selectHistoricActivityInstanceCountByNativeQuery" parameterType="java.util.Map" resultType="long">
    ${sql}
  </select>
  
  <select id="selectUnfinishedHistoricActivityInstanceExecutionIdAndActivityId" parameterType="org.flowable.common.engine.impl.db.ListQueryParameterObject" resultMap="historicActivityInstanceResultMap">
    select * from ${prefix}ACT_HI_ACTINST RES
    where EXECUTION_ID_ = #{parameter.executionId, jdbcType=VARCHAR} and ACT_ID_ = #{parameter.activityId, jdbcType=VARCHAR} and END_TIME_ is null
  </select>
  
  <select id="selectHistoricActivityInstanceExecutionIdAndActivityId" parameterType="org.flowable.common.engine.impl.db.ListQueryParameterObject" resultMap="historicActivityInstanceResultMap">
    select * from ${prefix}ACT_HI_ACTINST RES
    where EXECUTION_ID_ = #{parameter.executionId, jdbcType=VARCHAR} and ACT_ID_ = #{parameter.activityId, jdbcType=VARCHAR}
  </select>
  
   <select id="selectUnfinishedHistoricActivityInstanceByProcessInstanceId" parameterType="org.flowable.common.engine.impl.db.ListQueryParameterObject" resultMap="historicActivityInstanceResultMap">
    select * from ${prefix}ACT_HI_ACTINST RES
    where PROC_INST_ID_ = #{parameter.processInstanceId, jdbcType=VARCHAR} and END_TIME_ is null
  </select>
  
</mapper>




© 2015 - 2024 Weber Informatics LLC | Privacy Policy