<commit_before><?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.camunda.bpm.engine.impl.history.event.HistoricDecisionInstanceEntity">

 <!-- insert -->

 <insert id="insertHistoricDecisionInstance" parameterType="org.camunda.bpm.engine.impl.history.event.HistoricDecisionInstanceEntity">
    insert into ${prefix}ACT_HI_DECINST(
      ID_,
      DEC_DEF_ID_,
      DEC_DEF_KEY_,
      DEC_DEF_NAME_,
      PROC_DEF_KEY_,
      PROC_DEF_ID_,
      PROC_INST_ID_,
      CASE_DEF_KEY_,
      CASE_DEF_ID_,
      CASE_INST_ID_,
      ACT_INST_ID_,
      ACT_ID_,
      EVAL_TIME_,
      COLLECT_VALUE_,
      USER_ID_,
      ROOT_DEC_INST_ID_,
      DEC_REQ_ID_,
      DEC_REQ_KEY_,
      TENANT_ID_)
    values (#{id, jdbcType=VARCHAR},
            #{decisionDefinitionId, jdbcType=VARCHAR},
            #{decisionDefinitionKey, jdbcType=VARCHAR},
            #{decisionDefinitionName, jdbcType=VARCHAR},
            #{processDefinitionKey, jdbcType=VARCHAR},
            #{processDefinitionId, jdbcType=VARCHAR},
            #{processInstanceId, jdbcType=VARCHAR},
            #{caseDefinitionKey, jdbcType=VARCHAR},
            #{caseDefinitionId, jdbcType=VARCHAR},
            #{caseInstanceId, jdbcType=VARCHAR},
            #{activityInstanceId, jdbcType=VARCHAR},
            #{activityId, jdbcType=VARCHAR},
            #{evaluationTime, jdbcType=TIMESTAMP},
            #{collectResultValue, jdbcType=DOUBLE},
            #{userId, jdbcType=VARCHAR},
            #{rootDecisionInstanceId, jdbcType=VARCHAR},
            #{decisionRequirementsDefinitionId, jdbcType=VARCHAR},
            #{decisionRequirementsDefinitionKey, jdbcType=VARCHAR},
            #{tenantId, jdbcType=VARCHAR}
           )
  </insert>
  
  <!-- delete -->
  
  <delete id="deleteHistoricDecisionInstance" parameterType="org.camunda.bpm.engine.impl.history.event.HistoricDecisionInstanceEntity">
    delete from ${prefix}ACT_HI_DECINST where ID_ = #{id}
  </delete>

  <!-- result map -->

 <resultMap id="historicDecisionInstanceResultMap" type="org.camunda.bpm.engine.impl.history.event.HistoricDecisionInstanceEntity">
    <id property="id" column="ID_" jdbcType="VARCHAR" />
    <result property="decisionDefinitionId" column="DEC_DEF_ID_" jdbcType="VARCHAR" />
    <result property="decisionDefinitionKey" column="DEC_DEF_KEY_" jdbcType="VARCHAR" />
    <result property="decisionDefinitionName" column="DEC_DEF_NAME_" jdbcType="VARCHAR" />
    <result property="processDefinitionKey" column="PROC_DEF_KEY_" jdbcType="VARCHAR" />
    <result property="processDefinitionId" column="PROC_DEF_ID_" jdbcType="VARCHAR"/>
    <result property="processInstanceId" column="PROC_INST_ID_" jdbcType="VARCHAR"/>
    <result property="caseDefinitionKey" column="CASE_DEF_KEY_" jdbcType="VARCHAR" />
    <result property="caseDefinitionId" column="CASE_DEF_ID_" jdbcType="VARCHAR"/>
    <result property="caseInstanceId" column="CASE_INST_ID_" jdbcType="VARCHAR"/>
    <result property="activityInstanceId" column="ACT_INST_ID_" jdbcType="VARCHAR"/>
    <result property="activityId" column="ACT_ID_" jdbcType="VARCHAR"/>
    <result property="evaluationTime" column="EVAL_TIME_" jdbcType="TIMESTAMP"/>
    <result property="collectResultValue" column="COLLECT_VALUE_" jdbcType="DOUBLE"/>
    <result property="userId" column="USER_ID_" jdbcType="VARCHAR"/>
    <result property="rootDecisionInstanceId" column="ROOT_DEC_INST_ID_" jdbcType="VARCHAR"/>
    <result property="decisionRequirementsDefinitionId" column="DEC_REQ_ID_" jdbcType="VARCHAR"/>
    <result property="decisionRequirementsDefinitionKey" column="DEC_REQ_KEY_" jdbcType="VARCHAR"/>
    <result property="tenantId" column="TENANT_ID_" jdbcType="VARCHAR"/>
  </resultMap>

  <!-- select -->

  <select id="selectHistoricDecisionInstancesByDecisionDefinitionId" parameterType="org.camunda.bpm.engine.impl.db.ListQueryParameterObject" resultMap="historicDecisionInstanceResultMap">
    select * from ${prefix}ACT_HI_DECINST RES
    where DEC_DEF_ID_ = #{parameter, jdbcType=VARCHAR}
    <include refid="org.camunda.bpm.engine.impl.persistence.entity.TenantEntity.queryTenantCheck" />
  </select>

  <select id="selectHistoricDecisionInstancesByQueryCriteria" parameterType="org.camunda.bpm.engine.impl.HistoricDecisionInstanceQueryImpl" resultMap="historicDecisionInstanceResultMap">
    <include refid="org.camunda.bpm.engine.impl.persistence.entity.Commons.bindOrderBy"/>
    ${limitBefore}
    select RES.*
    ${limitBetween}
    <include refid="selectHistoricDecisionInstancesByQueryCriteriaSql"/>
    ${orderBy}
    ${limitAfter}
  </select>

  <select id="selectHistoricDecisionInstanceCountByQueryCriteria" parameterType="org.camunda.bpm.engine.impl.HistoricDecisionInstanceQueryImpl" resultType="long">
    select count(RES.ID_)
    <include refid="selectHistoricDecisionInstancesByQueryCriteriaSql"/>
  </select>
  
  <!-- native queries -->
  
  <select id="selectHistoricDecisionInstancesByNativeQuery" parameterType="java.util.Map" resultMap="historicDecisionInstanceResultMap">
    <if test="resultType == 'LIST_PAGE'">
      ${limitBefore}
    </if>
    ${sql}
    <if test="resultType == 'LIST_PAGE'">
      ${limitAfter}
    </if>
  </select>

  <select id="selectHistoricDecisionInstanceCountByNativeQuery" parameterType="java.util.Map" resultType="long">
    ${sql}
  </select>
  
  <!-- special nativ query for mssql and db2 -->
  
  <select id="selectHistoricDecisionInstancesByNativeQuery_mssql_or_db2" parameterType="java.util.Map" resultMap="historicDecisionInstanceResultMap">
    <if test="resultType == 'LIST_PAGE'">
        ${limitBeforeNativeQuery}
    </if>
    ${sql}
    <if test="resultType == 'LIST_PAGE'">
      ${limitAfter}
    </if>
  </select>
  
  <!-- sql query -->

  <sql id="selectHistoricDecisionInstancesByQueryCriteriaSql">
    from ${prefix}ACT_HI_DECINST RES

    <if test="authCheck.isAuthorizationCheckEnabled &amp;&amp; authCheck.authUserId != null">
      INNER JOIN (
        SELECT
            SELF.DEC_DEF_KEY_ AS KEY_
        FROM
            (SELECT DISTINCT DKEYS.DEC_DEF_KEY_ from ${prefix}ACT_HI_DECINST DKEYS) SELF
        WHERE
            <include refid="org.camunda.bpm.engine.impl.persistence.entity.AuthorizationEntity.querySingleAuthorizationCheck" />
      ) AUTH
      ON AUTH.KEY_ = RES.DEC_DEF_KEY_
    </if>

    <where>
      <if test="decisionInstanceId != null">
        RES.ID_ = #{decisionInstanceId}
      </if>
      <if test="decisionInstanceIdIn != null and decisionInstanceIdIn.length > 0">
        and RES.ID_ in
        <foreach item="item" index="index" collection="decisionInstanceIdIn" open="(" separator="," close=")"><commit_msg>Reduce statement complexity (nested select).<commit_after><?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.camunda.bpm.engine.impl.history.event.HistoricDecisionInstanceEntity">

 <!-- insert -->

 <insert id="insertHistoricDecisionInstance" parameterType="org.camunda.bpm.engine.impl.history.event.HistoricDecisionInstanceEntity">
    insert into ${prefix}ACT_HI_DECINST(
      ID_,
      DEC_DEF_ID_,
      DEC_DEF_KEY_,
      DEC_DEF_NAME_,
      PROC_DEF_KEY_,
      PROC_DEF_ID_,
      PROC_INST_ID_,
      CASE_DEF_KEY_,
      CASE_DEF_ID_,
      CASE_INST_ID_,
      ACT_INST_ID_,
      ACT_ID_,
      EVAL_TIME_,
      COLLECT_VALUE_,
      USER_ID_,
      ROOT_DEC_INST_ID_,
      DEC_REQ_ID_,
      DEC_REQ_KEY_,
      TENANT_ID_)
    values (#{id, jdbcType=VARCHAR},
            #{decisionDefinitionId, jdbcType=VARCHAR},
            #{decisionDefinitionKey, jdbcType=VARCHAR},
            #{decisionDefinitionName, jdbcType=VARCHAR},
            #{processDefinitionKey, jdbcType=VARCHAR},
            #{processDefinitionId, jdbcType=VARCHAR},
            #{processInstanceId, jdbcType=VARCHAR},
            #{caseDefinitionKey, jdbcType=VARCHAR},
            #{caseDefinitionId, jdbcType=VARCHAR},
            #{caseInstanceId, jdbcType=VARCHAR},
            #{activityInstanceId, jdbcType=VARCHAR},
            #{activityId, jdbcType=VARCHAR},
            #{evaluationTime, jdbcType=TIMESTAMP},
            #{collectResultValue, jdbcType=DOUBLE},
            #{userId, jdbcType=VARCHAR},
            #{rootDecisionInstanceId, jdbcType=VARCHAR},
            #{decisionRequirementsDefinitionId, jdbcType=VARCHAR},
            #{decisionRequirementsDefinitionKey, jdbcType=VARCHAR},
            #{tenantId, jdbcType=VARCHAR}
           )
  </insert>
  
  <!-- delete -->
  
  <delete id="deleteHistoricDecisionInstance" parameterType="org.camunda.bpm.engine.impl.history.event.HistoricDecisionInstanceEntity">
    delete from ${prefix}ACT_HI_DECINST where ID_ = #{id}
  </delete>

  <!-- result map -->

 <resultMap id="historicDecisionInstanceResultMap" type="org.camunda.bpm.engine.impl.history.event.HistoricDecisionInstanceEntity">
    <id property="id" column="ID_" jdbcType="VARCHAR" />
    <result property="decisionDefinitionId" column="DEC_DEF_ID_" jdbcType="VARCHAR" />
    <result property="decisionDefinitionKey" column="DEC_DEF_KEY_" jdbcType="VARCHAR" />
    <result property="decisionDefinitionName" column="DEC_DEF_NAME_" jdbcType="VARCHAR" />
    <result property="processDefinitionKey" column="PROC_DEF_KEY_" jdbcType="VARCHAR" />
    <result property="processDefinitionId" column="PROC_DEF_ID_" jdbcType="VARCHAR"/>
    <result property="processInstanceId" column="PROC_INST_ID_" jdbcType="VARCHAR"/>
    <result property="caseDefinitionKey" column="CASE_DEF_KEY_" jdbcType="VARCHAR" />
    <result property="caseDefinitionId" column="CASE_DEF_ID_" jdbcType="VARCHAR"/>
    <result property="caseInstanceId" column="CASE_INST_ID_" jdbcType="VARCHAR"/>
    <result property="activityInstanceId" column="ACT_INST_ID_" jdbcType="VARCHAR"/>
    <result property="activityId" column="ACT_ID_" jdbcType="VARCHAR"/>
    <result property="evaluationTime" column="EVAL_TIME_" jdbcType="TIMESTAMP"/>
    <result property="collectResultValue" column="COLLECT_VALUE_" jdbcType="DOUBLE"/>
    <result property="userId" column="USER_ID_" jdbcType="VARCHAR"/>
    <result property="rootDecisionInstanceId" column="ROOT_DEC_INST_ID_" jdbcType="VARCHAR"/>
    <result property="decisionRequirementsDefinitionId" column="DEC_REQ_ID_" jdbcType="VARCHAR"/>
    <result property="decisionRequirementsDefinitionKey" column="DEC_REQ_KEY_" jdbcType="VARCHAR"/>
    <result property="tenantId" column="TENANT_ID_" jdbcType="VARCHAR"/>
  </resultMap>

  <!-- select -->

  <select id="selectHistoricDecisionInstancesByDecisionDefinitionId" parameterType="org.camunda.bpm.engine.impl.db.ListQueryParameterObject" resultMap="historicDecisionInstanceResultMap">
    select * from ${prefix}ACT_HI_DECINST RES
    where DEC_DEF_ID_ = #{parameter, jdbcType=VARCHAR}
    <include refid="org.camunda.bpm.engine.impl.persistence.entity.TenantEntity.queryTenantCheck" />
  </select>

  <select id="selectHistoricDecisionInstancesByQueryCriteria" parameterType="org.camunda.bpm.engine.impl.HistoricDecisionInstanceQueryImpl" resultMap="historicDecisionInstanceResultMap">
    <include refid="org.camunda.bpm.engine.impl.persistence.entity.Commons.bindOrderBy"/>
    ${limitBefore}
    select RES.*
    ${limitBetween}
    <include refid="selectHistoricDecisionInstancesByQueryCriteriaSql"/>
    ${orderBy}
    ${limitAfter}
  </select>

  <select id="selectHistoricDecisionInstanceCountByQueryCriteria" parameterType="org.camunda.bpm.engine.impl.HistoricDecisionInstanceQueryImpl" resultType="long">
    select count(RES.ID_)
    <include refid="selectHistoricDecisionInstancesByQueryCriteriaSql"/>
  </select>
  
  <!-- native queries -->
  
  <select id="selectHistoricDecisionInstancesByNativeQuery" parameterType="java.util.Map" resultMap="historicDecisionInstanceResultMap">
    <if test="resultType == 'LIST_PAGE'">
      ${limitBefore}
    </if>
    ${sql}
    <if test="resultType == 'LIST_PAGE'">
      ${limitAfter}
    </if>
  </select>

  <select id="selectHistoricDecisionInstanceCountByNativeQuery" parameterType="java.util.Map" resultType="long">
    ${sql}
  </select>
  
  <!-- special nativ query for mssql and db2 -->
  
  <select id="selectHistoricDecisionInstancesByNativeQuery_mssql_or_db2" parameterType="java.util.Map" resultMap="historicDecisionInstanceResultMap">
    <if test="resultType == 'LIST_PAGE'">
      ${limitBeforeNativeQuery}
    </if>
    ${sql}
    <if test="resultType == 'LIST_PAGE'">
      ${limitAfter}
    </if>
  </select>
  
  <!-- sql query -->

  <sql id="selectHistoricDecisionInstancesByQueryCriteriaSql">
    from ${prefix}ACT_HI_DECINST RES

    <if test="authCheck.isAuthorizationCheckEnabled &amp;&amp; authCheck.authUserId != null">
      INNER JOIN (
        SELECT DISTINCT
            SELF.DEC_DEF_KEY_ AS KEY_
        FROM
            ${prefix}ACT_HI_DECINST SELF
        WHERE
            <include refid="org.camunda.bpm.engine.impl.persistence.entity.AuthorizationEntity.querySingleAuthorizationCheck" />
      ) AUTH
      ON AUTH.KEY_ = RES.DEC_DEF_KEY_
    </if>

    <where>
      <if test="decisionInstanceId != null">
        RES.ID_ = #{decisionInstanceId}
      </if>
      <if test="decisionInstanceIdIn != null and decisionInstanceIdIn.length > 0">
        and RES.ID_ in
        <foreach item="item" index="index" collection="decisionInstanceIdIn" open="(" separator="," close=")">
{'fraction_non_alphanumeric': 0.12841328413284134, 'fraction_numerical': 0.0013284132841328412, 'mean_word_length': 4.2502905850445565, 'pattern_counts': {'":': 0, '<': 139, '<?xml version=': 2, '>': 141, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '22896', 'n_tokens_mistral': 4280, 'n_tokens_neox': 4174, 'n_words': 629}