<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.PropertyMapping">
    
    <resultMap id="propertyResultMap" type="Property">
        <id property="id" column="id" />
        <result property="name" column="prop_name" /> 
        <collection property="attributes" ofType="HashMap" resultMap="attributesResultMap" />
    </resultMap>
    
    <resultMap id="attributesResultMap" type="HashMap">
        <result property="attr_value" column="attr_value" />
        <result property="attr_name" column="attr_name" />
    </resultMap>
   
  <!-- SELECT -->
    <select id="allProperties" resultType="Property">
        <![CDATA[
            SELECT p.name, p.id, s.id, s.name FROM properties p, statuses s WHERE p.status_id = s.id AND s.name = 'Active' 
                ORDER BY p.name
        ]]>
    </select>
    
    <select id="getProperty" resultType="Property" parameterType="String">
        <![CDATA[
            SELECT id, name FROM properties as prop WHERE name = #{name}
        ]]>
    </select>
    
    <select id="getAttribute" resultType="Long" parameterType="HashMap">
        <![CDATA[
            SELECT id FROM attributes WHERE name = #{aname} AND property_id = (SELECT id FROM properties WHERE name = #{pname})
        ]]>
    </select>
    
    <select id="attributesForProperty" resultType="String" parameterType="Long">
        <![CDATA[
            SELECT attr.name FROM attributes as attr WHERE attr.property_id = #{pid} 
                AND status_id = (SELECT id FROM statuses WHERE name = 'Active')
        ]]>
    </select>
    
    <select id="attributesForLog" resultType="Map" parameterType="Hashmap"> 
        <![CDATA[
            SELECT attr.name, attr_val.value FROM `logs` as log 
                LEFT JOIN `logs` as parent ON log.id = parent.parent_id LEFT JOIN statuses as status ON log.status_id = status.id
                LEFT JOIN logs_attributes as attr_val ON attr_val.log_id = log.id 
                LEFT JOIN attributes as attr ON attr.id = attr_val.attribute_id
                LEFT JOIN properties as prop ON prop.id = attr.property_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 (log.id = #{lid} OR log.parent_id = #{lid})
                AND prop.id = #{pid} AND attr_val.grouping_num = #{gnum}
        ]]>
    </select>
    
    <select id="lastId" resultType="int">
        <![CDATA[
            SELECT LAST_INSERT_ID() as propId
        ]]>
    </select>
    
    <select id="getIdsFromPropertiesMatch" resultType="Long" parameterType="HashMap">
        <![CDATA[
            SELECT log_id FROM logs_attributes WHERE attribute_id = 
                (SELECT id FROM attributes WHERE name = #{attribute} 
                    AND property_id = 
                        (SELECT id FROM properties WHERE name = #{property} 
                        AND status_id = (SELECT id FROM statuses WHERE name = 'Active')) 
                    AND status_id = (SELECT id FROM statuses WHERE name = 'Active'))
                AND value LIKE #{value}
        ]]>
    </select>
    
        <select id="getIdsFromPropertyMatch" resultType="Long" parameterType="String">
        <![CDATA[
            SELECT log_id FROM logs_attributes WHERE attribute_id = 
                (SELECT id FROM attributes WHERE property_id = 
                        (SELECT id FROM properties WHERE name = #{match} 
                            AND status_id = (SELECT id FROM statuses WHERE name = 'Active'))
                    AND status_id = (SELECT id FROM statuses WHERE name = 'Active'))
        ]]>
    </select>
  
    
  <!-- UPDATE -->
    <update id="setAsInactive" parameterType="String">
        <![CDATA[
            UPDATE properties p, statuses s SET p.status_id = s.id WHERE s.name = 'Inactive' AND p.name = #{property}<commit_msg>Make sure logs being returned from property matches are active and current<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.PropertyMapping">
    
    <resultMap id="propertyResultMap" type="Property">
        <id property="id" column="id" />
        <result property="name" column="prop_name" /> 
        <collection property="attributes" ofType="HashMap" resultMap="attributesResultMap" />
    </resultMap>
    
    <resultMap id="attributesResultMap" type="HashMap">
        <result property="attr_value" column="attr_value" />
        <result property="attr_name" column="attr_name" />
    </resultMap>
   
  <!-- SELECT -->
    <select id="allProperties" resultType="Property">
        <![CDATA[
            SELECT p.name, p.id, s.id, s.name FROM properties p, statuses s WHERE p.status_id = s.id AND s.name = 'Active' 
                ORDER BY p.name
        ]]>
    </select>
    
    <select id="getProperty" resultType="Property" parameterType="String">
        <![CDATA[
            SELECT id, name FROM properties as prop WHERE name = #{name}
        ]]>
    </select>
    
    <select id="getAttribute" resultType="Long" parameterType="HashMap">
        <![CDATA[
            SELECT id FROM attributes WHERE name = #{aname} AND property_id = (SELECT id FROM properties WHERE name = #{pname})
        ]]>
    </select>
    
    <select id="attributesForProperty" resultType="String" parameterType="Long">
        <![CDATA[
            SELECT attr.name FROM attributes as attr WHERE attr.property_id = #{pid} 
                AND status_id = (SELECT id FROM statuses WHERE name = 'Active')
        ]]>
    </select>
    
    <select id="attributesForLog" resultType="Map" parameterType="Hashmap"> 
        <![CDATA[
            SELECT attr.name, attr_val.value FROM `logs` as log 
                LEFT JOIN `logs` as parent ON log.id = parent.parent_id LEFT JOIN statuses as status ON log.status_id = status.id
                LEFT JOIN logs_attributes as attr_val ON attr_val.log_id = log.id 
                LEFT JOIN attributes as attr ON attr.id = attr_val.attribute_id
                LEFT JOIN properties as prop ON prop.id = attr.property_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 (log.id = #{lid} OR log.parent_id = #{lid})
                AND prop.id = #{pid} AND attr_val.grouping_num = #{gnum}
        ]]>
    </select>
    
    <select id="lastId" resultType="int">
        <![CDATA[
            SELECT LAST_INSERT_ID() as propId
        ]]>
    </select>
    
    <select id="getIdsFromPropertiesMatch" resultType="Long" parameterType="HashMap">
        <![CDATA[
            SELECT log_id FROM logs_attributes
            LEFT JOIN logs AS log ON log.id = log_id LEFT JOIN logs AS parent ON log.id = parent.parent_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 attribute_id = 
                (SELECT id FROM attributes WHERE name = #{attribute} 
                    AND property_id = 
                        (SELECT id FROM properties WHERE name = #{property} 
                        AND status_id = (SELECT id FROM statuses WHERE name = 'Active')) 
                    AND status_id = (SELECT id FROM statuses WHERE name = 'Active'))
                AND value LIKE #{value} AND log.status_id = (SELECT id FROM statuses WHERE name = 'Active')
        ]]>
    </select>
    
        <select id="getIdsFromPropertyMatch" resultType="Long" parameterType="String">
        <![CDATA[
            SELECT log_id FROM logs_attributes
            LEFT JOIN logs AS log ON log.id = log_id LEFT JOIN logs AS parent ON log.id = parent.parent_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 attribute_id = 
                (SELECT id FROM attributes WHERE property_id = 
                        (SELECT id FROM properties WHERE name = #{match} 
                            AND status_id = (SELECT id FROM statuses WHERE name = 'Active'))
                    AND status_id = (SELECT id FROM statuses WHERE name = 'Active'))
            AND log.status_id = (SELECT id FROM statuses WHERE name = 'Active')
        ]]>
    </select>
  
    
  <!-- UPDATE -->
    <update id="setAsInactive" parameterType="String">
        <![CDATA[
            UPDATE properties p, statuses s SET p.status_id = s.id WHERE s.name = 'Inactive' AND p.name = #{property}
{'fraction_non_alphanumeric': 0.11160714285714286, 'fraction_numerical': 0.0013392857142857143, 'mean_word_length': 2.1742826780021254, 'pattern_counts': {'":': 0, '<': 83, '<?xml version=': 2, '>': 81, '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': '821757', 'n_tokens_mistral': 2607, 'n_tokens_neox': 2416, 'n_words': 752}