<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="mappings.LogMapping">
  
    <resultMap id="logResultMap" type="Log">
        <id property="id" column="entry_no" /> 
        <result property="version" column="children" /> 
        <result property="owner" column="owner" /> 
        <result property="level" column="level_name" /> 
        <result property="md5Entry" column="md5entry" /> 
        <result property="md5Recent" column="md5recent" /> 
        <result property="createdDate" column="createdDate" /> 
        <result property="modifiedDate" column="modifiedDate" /> 
        <result property="subject" column="subject" /> 
        <result property="description" column="description" /> 
        <collection property="properties" ofType="Property" javaType="ArrayList">
            <result property="name" column="prop_name" /> 
            <result property="value" column="prop_value" /> 
        </collection>
        <collection property="logbooks" ofType="Logbook" javaType="ArrayList">
            <id property="name" column="lbook_name" /> 
            <result property="owner" column="lbook_owner" /> 
        </collection>
        <collection property="tags" ofType="Tag" javaType="ArrayList">
            <id property="name" column="tag_name" /> 
        </collection>
    </resultMap>
   
  <!-- SELECT -->
    <select id="getIdsFromLogbookAndTagMatch" parameterType="HashMap" resultMap="logResultMap">
        <![CDATA[
            SELECT log.id as entry_no, log.*, t.*, level.name, (SELECT logs.created FROM logs WHERE log.parent_id=logs.id) as parent_created, log.id as entry_no,
                (SELECT COUNT(id) FROM logs WHERE parent_id=log.parent_id GROUP BY parent_id) as children FROM `logs` as log 
                LEFT JOIN `logs` as parent ON log.id = parent.parent_id LEFT JOIN logs_logbooks as lt ON log.id = lt.log_id 
                LEFT JOIN logbooks as t ON lt.logbook_id = t.id LEFT JOIN levels as level ON log.level_id = level.id 
                LEFT JOIN statuses as status ON log.status_id = status.id LEFT JOIN statuses as ltstatus ON lt.status_id = status.id 
                LEFT JOIN statuses as tstatus ON t.status_id = status.id WHERE (parent.parent_id IS NULL and log.parent_id IS NULL 
                OR log.id IN (SELECT MAX(logs.id) FROM logs WHERE logs.parent_id=log.parent_id)) AND status.name = 'Active' 
                AND ltstatus.name = 'Active' AND tstatus.name = 'Active'
        ]]>
        <if test="list != null">
            <![CDATA[
                AND (
            ]]>
            <foreach item="item" index="index" collection="list" separator="OR">
            <![CDATA[
                LOWER(t.name) LIKE #{item}
            ]]>
            </foreach>
            <![CDATA[ 
                )
            ]]>
        </if>
        <![CDATA[
            GROUP BY log.id HAVING COUNT(log.id) = #{size} ORDER BY ifnull(parent_created,log.created) DESC
        ]]>
    </select>
    
    <select id="getIdsFromPropertiesMatch" parameterType="HashMap" resultMap="logResultMap">
        <![CDATA[
            SELECT log.id as entry_no, log.*, t.*, level.name, (SELECT logs.created FROM logs WHERE log.parent_id=logs.id) as parent_created, log.id as entry_no,
                (SELECT COUNT(id) FROM logs WHERE parent_id=log.parent_id GROUP BY parent_id) as children FROM `logs` as log 
                LEFT JOIN `logs` as parent ON log.id = parent.parent_id LEFT JOIN logs_logbooks as lt ON log.id = lt.log_id 
                LEFT JOIN logbooks as t ON lt.logbook_id = t.id LEFT JOIN levels as level ON log.level_id = level.id 
                LEFT JOIN statuses as status ON log.status_id = status.id LEFT JOIN statuses as ltstatus ON lt.status_id = status.id 
                LEFT JOIN statuses as tstatus ON t.status_id = status.id LEFT JOIN properties as prop ON log.id = prop.log_id 
                WHERE (parent.parent_id IS NULL and log.parent_id IS NULL OR log.id IN (SELECT MAX(logs.id) FROM logs 
                WHERE logs.parent_id=log.parent_id)) AND status.name = 'Active' AND ltstatus.name = 'Active' 
                AND tstatus.name = 'Active'
        ]]>
        <if test="propNameList != null">
            <![CDATA[
            AND
            ]]>
            <foreach item="item" index="index" collection="propNameList" open="(" separator="OR" close=")">
        <![CDATA[
            LOWER(prop.name) = #{item} AND
        ]]>
                <foreach item="item" index="index" collection="propValueList" open="(" separator="OR" close=")">
                    <![CDATA[
                        prop.value LIKE #{item}
                    ]]>
                </foreach>
            </foreach>
        </if>
        <![CDATA[
            GROUP BY log.id HAVING COUNT(log.id) = #{size} ORDER BY ifnull(parent_created,log.created) DESC
        ]]>
    </select>
    
    <select id="getIdsFromLogbookMatch" parameterType="String" resultMap="logResultMap">
        <![CDATA[
            SELECT log.id as entry_no, (SELECT logs.created FROM logs WHERE log.parent_id=logs.id) as parent_created FROM `logs` as log
                LEFT JOIN `logs` as parent ON log.id = parent.parent_id LEFT JOIN logs_logbooks as lt ON log.id = lt.log_id 
                LEFT JOIN logbooks as t ON lt.logbook_id = t.id LEFT JOIN statuses as status ON log.status_id = status.id 
                LEFT JOIN statuses as ltstatus ON lt.status_id = status.id LEFT JOIN statuses as tstatus ON t.status_id = status.id 
                WHERE t.is_tag = FALSE AND (parent.parent_id IS NULL and log.parent_id IS NULL OR log.id IN 
                (SELECT MAX(logs.id) FROM logs WHERE logs.parent_id=log.parent_id)) AND t.name LIKE #{name} AND status.name = 'Active' 
                AND ltstatus.name = 'Active' AND tstatus.name = 'Active' GROUP BY lt.id ORDER BY ifnull(parent_created,log.created)
                DESC, t.name
        ]]>
    </select>
    
    <select id="getIdsFromTagMatch" parameterType="String" resultMap="logResultMap">
        <![CDATA[
            SELECT log.id as entry_no, (SELECT logs.created FROM logs WHERE log.parent_id=logs.id) as parent_created FROM `logs` as log
                LEFT JOIN `logs` as parent ON log.id = parent.parent_id LEFT JOIN logs_logbooks as lt ON log.id = lt.log_id 
                LEFT JOIN logbooks as t ON lt.logbook_id = t.id LEFT JOIN statuses as status ON log.status_id = status.id 
                LEFT JOIN statuses as ltstatus ON lt.status_id = status.id LEFT JOIN statuses as tstatus ON t.status_id = status.id 
                WHERE t.is_tag = TRUE AND (parent.parent_id IS NULL and log.parent_id IS NULL OR log.id IN 
                (SELECT MAX(logs.id) FROM logs WHERE logs.parent_id=log.parent_id)) AND t.name LIKE #{name} AND status.name = 'Active' 
                AND ltstatus.name = 'Active' AND tstatus.name = 'Active' GROUP BY lt.id ORDER BY ifnull(parent_created,log.created)
                DESC, t.name
        ]]>
    </select>
    
    <select id="getIdsFromPagination" parameterType="HashMap" resultMap="logResultMap">
        <![CDATA[
            SELECT log.id as entry_no, log.*, t.*, level.name, prop.name, prop.value, 
                (SELECT logs.created FROM logs WHERE log.parent_id=logs.id) as parent_created, log.id as entry_no,
                (SELECT COUNT(id) FROM logs WHERE parent_id=log.parent_id GROUP BY parent_id) as children FROM `logs` as log 
                LEFT JOIN `logs` as parent ON log.id = parent.parent_id LEFT JOIN logs_logbooks as lt ON log.id = lt.log_id 
                LEFT JOIN logbooks as t ON lt.logbook_id = t.id LEFT JOIN levels as level ON log.level_id = level.id 
                LEFT JOIN statuses as status ON log.status_id = status.id LEFT JOIN statuses as ltstatus ON lt.status_id = status.id 
                LEFT JOIN statuses as tstatus ON t.status_id = status.id LEFT JOIN properties as prop ON log.id = prop.log_id 
                WHERE (parent.parent_id IS NULL and log.parent_id IS NULL OR log.id IN (SELECT MAX(logs.id) FROM logs 
                WHERE logs.parent_id=log.parent_id)) AND status.name = 'Active' AND ltstatus.name = 'Active' 
                AND tstatus.name = 'Active'
        ]]>
        <if test="start != null">
        <![CDATA[
            AND log.created > FROM_UNIXTIME(#{start})
        ]]>
        </if>
        <if test="end != null">
        <![CDATA[
            AND log.created <= FROM_UNIXTIME(#{end})
        ]]>
        </if>
        <if test="idsList != null">
            <![CDATA[
                AND (log.id IN
            ]]>
            <foreach item="item" index="index" collection="idsList" open="(" separator="," close=")">
                <![CDATA[
                    #{item}
                ]]>
            </foreach>
            <![CDATA[<commit_msg>Added equality operator to query<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="mappings.LogMapping">
  
    <resultMap id="logResultMap" type="Log">
        <id property="id" column="entry_no" /> 
        <result property="version" column="children" /> 
        <result property="owner" column="owner" /> 
        <result property="level" column="level_name" /> 
        <result property="md5Entry" column="md5entry" /> 
        <result property="md5Recent" column="md5recent" /> 
        <result property="createdDate" column="createdDate" /> 
        <result property="modifiedDate" column="modifiedDate" /> 
        <result property="subject" column="subject" /> 
        <result property="description" column="description" /> 
        <collection property="properties" ofType="Property" javaType="ArrayList">
            <result property="name" column="prop_name" /> 
            <result property="value" column="prop_value" /> 
        </collection>
        <collection property="logbooks" ofType="Logbook" javaType="ArrayList">
            <id property="name" column="lbook_name" /> 
            <result property="owner" column="lbook_owner" /> 
        </collection>
        <collection property="tags" ofType="Tag" javaType="ArrayList">
            <id property="name" column="tag_name" /> 
        </collection>
    </resultMap>
   
  <!-- SELECT -->
    <select id="getIdsFromLogbookAndTagMatch" parameterType="HashMap" resultMap="logResultMap">
        <![CDATA[
            SELECT log.id as entry_no, log.*, t.*, level.name, (SELECT logs.created FROM logs WHERE log.parent_id=logs.id) as parent_created, log.id as entry_no,
                (SELECT COUNT(id) FROM logs WHERE parent_id=log.parent_id GROUP BY parent_id) as children FROM `logs` as log 
                LEFT JOIN `logs` as parent ON log.id = parent.parent_id LEFT JOIN logs_logbooks as lt ON log.id = lt.log_id 
                LEFT JOIN logbooks as t ON lt.logbook_id = t.id LEFT JOIN levels as level ON log.level_id = level.id 
                LEFT JOIN statuses as status ON log.status_id = status.id LEFT JOIN statuses as ltstatus ON lt.status_id = status.id 
                LEFT JOIN statuses as tstatus ON t.status_id = status.id WHERE (parent.parent_id IS NULL and log.parent_id IS NULL 
                OR log.id IN (SELECT MAX(logs.id) FROM logs WHERE logs.parent_id=log.parent_id)) AND status.name = 'Active' 
                AND ltstatus.name = 'Active' AND tstatus.name = 'Active'
        ]]>
        <if test="list != null">
            <![CDATA[
                AND (
            ]]>
            <foreach item="item" index="index" collection="list" separator="OR">
            <![CDATA[
                LOWER(t.name) LIKE #{item}
            ]]>
            </foreach>
            <![CDATA[ 
                )
            ]]>
        </if>
        <![CDATA[
            GROUP BY log.id HAVING COUNT(log.id) = #{size} ORDER BY ifnull(parent_created,log.created) DESC
        ]]>
    </select>
    
    <select id="getIdsFromPropertiesMatch" parameterType="HashMap" resultMap="logResultMap">
        <![CDATA[
            SELECT log.id as entry_no, log.*, t.*, level.name, (SELECT logs.created FROM logs WHERE log.parent_id=logs.id) as parent_created, log.id as entry_no,
                (SELECT COUNT(id) FROM logs WHERE parent_id=log.parent_id GROUP BY parent_id) as children FROM `logs` as log 
                LEFT JOIN `logs` as parent ON log.id = parent.parent_id LEFT JOIN logs_logbooks as lt ON log.id = lt.log_id 
                LEFT JOIN logbooks as t ON lt.logbook_id = t.id LEFT JOIN levels as level ON log.level_id = level.id 
                LEFT JOIN statuses as status ON log.status_id = status.id LEFT JOIN statuses as ltstatus ON lt.status_id = status.id 
                LEFT JOIN statuses as tstatus ON t.status_id = status.id LEFT JOIN properties as prop ON log.id = prop.log_id 
                WHERE (parent.parent_id IS NULL and log.parent_id IS NULL OR log.id IN (SELECT MAX(logs.id) FROM logs 
                WHERE logs.parent_id=log.parent_id)) AND status.name = 'Active' AND ltstatus.name = 'Active' 
                AND tstatus.name = 'Active'
        ]]>
        <if test="propNameList != null">
            <![CDATA[
            AND
            ]]>
            <foreach item="item" index="index" collection="propNameList" open="(" separator="OR" close=")">
        <![CDATA[
            LOWER(prop.name) = #{item} AND
        ]]>
                <foreach item="item" index="index" collection="propValueList" open="(" separator="OR" close=")">
                    <![CDATA[
                        prop.value LIKE #{item}
                    ]]>
                </foreach>
            </foreach>
        </if>
        <![CDATA[
            GROUP BY log.id HAVING COUNT(log.id) = #{size} ORDER BY ifnull(parent_created,log.created) DESC
        ]]>
    </select>
    
    <select id="getIdsFromLogbookMatch" parameterType="String" resultMap="logResultMap">
        <![CDATA[
            SELECT log.id as entry_no, (SELECT logs.created FROM logs WHERE log.parent_id=logs.id) as parent_created FROM `logs` as log
                LEFT JOIN `logs` as parent ON log.id = parent.parent_id LEFT JOIN logs_logbooks as lt ON log.id = lt.log_id 
                LEFT JOIN logbooks as t ON lt.logbook_id = t.id LEFT JOIN statuses as status ON log.status_id = status.id 
                LEFT JOIN statuses as ltstatus ON lt.status_id = status.id LEFT JOIN statuses as tstatus ON t.status_id = status.id 
                WHERE t.is_tag = FALSE AND (parent.parent_id IS NULL and log.parent_id IS NULL OR log.id IN 
                (SELECT MAX(logs.id) FROM logs WHERE logs.parent_id=log.parent_id)) AND t.name LIKE #{name} AND status.name = 'Active' 
                AND ltstatus.name = 'Active' AND tstatus.name = 'Active' GROUP BY lt.id ORDER BY ifnull(parent_created,log.created)
                DESC, t.name
        ]]>
    </select>
    
    <select id="getIdsFromTagMatch" parameterType="String" resultMap="logResultMap">
        <![CDATA[
            SELECT log.id as entry_no, (SELECT logs.created FROM logs WHERE log.parent_id=logs.id) as parent_created FROM `logs` as log
                LEFT JOIN `logs` as parent ON log.id = parent.parent_id LEFT JOIN logs_logbooks as lt ON log.id = lt.log_id 
                LEFT JOIN logbooks as t ON lt.logbook_id = t.id LEFT JOIN statuses as status ON log.status_id = status.id 
                LEFT JOIN statuses as ltstatus ON lt.status_id = status.id LEFT JOIN statuses as tstatus ON t.status_id = status.id 
                WHERE t.is_tag = TRUE AND (parent.parent_id IS NULL and log.parent_id IS NULL OR log.id IN 
                (SELECT MAX(logs.id) FROM logs WHERE logs.parent_id=log.parent_id)) AND t.name LIKE #{name} AND status.name = 'Active' 
                AND ltstatus.name = 'Active' AND tstatus.name = 'Active' GROUP BY lt.id ORDER BY ifnull(parent_created,log.created)
                DESC, t.name
        ]]>
    </select>
    
    <select id="getIdsFromPagination" parameterType="HashMap" resultMap="logResultMap">
        <![CDATA[
            SELECT log.id as entry_no, log.*, t.*, level.name, prop.name, prop.value, 
                (SELECT logs.created FROM logs WHERE log.parent_id=logs.id) as parent_created, log.id as entry_no,
                (SELECT COUNT(id) FROM logs WHERE parent_id=log.parent_id GROUP BY parent_id) as children FROM `logs` as log 
                LEFT JOIN `logs` as parent ON log.id = parent.parent_id LEFT JOIN logs_logbooks as lt ON log.id = lt.log_id 
                LEFT JOIN logbooks as t ON lt.logbook_id = t.id LEFT JOIN levels as level ON log.level_id = level.id 
                LEFT JOIN statuses as status ON log.status_id = status.id LEFT JOIN statuses as ltstatus ON lt.status_id = status.id 
                LEFT JOIN statuses as tstatus ON t.status_id = status.id LEFT JOIN properties as prop ON log.id = prop.log_id 
                WHERE (parent.parent_id IS NULL and log.parent_id IS NULL OR log.id IN (SELECT MAX(logs.id) FROM logs 
                WHERE logs.parent_id=log.parent_id)) AND status.name = 'Active' AND ltstatus.name = 'Active' 
                AND tstatus.name = 'Active'
        ]]>
        <if test="start != null">
        <![CDATA[
            AND log.created >= FROM_UNIXTIME(#{start})
        ]]>
        </if>
        <if test="end != null">
        <![CDATA[
            AND log.created <= FROM_UNIXTIME(#{end})
        ]]>
        </if>
        <if test="idsList != null">
            <![CDATA[
                AND (log.id IN
            ]]>
            <foreach item="item" index="index" collection="idsList" open="(" separator="," close=")">
                <![CDATA[
                    #{item}
                ]]>
            </foreach>
            <![CDATA[
{'fraction_non_alphanumeric': 0.11248461796621546, 'fraction_numerical': 0.0011186933661483387, 'mean_word_length': 2.1830158447569876, 'pattern_counts': {'":': 0, '<': 147, '<?xml version=': 2, '>': 145, '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': '7142571', 'n_tokens_mistral': 5618, 'n_tokens_neox': 5010, 'n_words': 1567}