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

org.sonar.db.component.SnapshotMapper.xml Maven / Gradle / Ivy

There is a newer version: 6.3.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.sonar.db.component.SnapshotMapper">

  <sql id="snapshotColumns">
    s.id,
    s.parent_snapshot_id as parentId,
    s.root_snapshot_id as rootId,
    s.root_project_id as rootProjectId,
    s.project_id as componentId,
    s.created_at as createdAt,
    s.build_date as buildDate,
    s.status as status,
    s.purge_status as purgeStatus,
    s.islast as last,
    s.scope as scope,
    s.qualifier as qualifier,
    s.version as version,
    s.path as path,
    s.depth as depth,
    s.period1_mode as period1Mode,
    s.period2_mode as period2Mode,
    s.period3_mode as period3Mode,
    s.period4_mode as period4Mode,
    s.period5_mode as period5Mode,
    s.period1_param as period1Param,
    s.period2_param as period2Param,
    s.period3_param as period3Param,
    s.period4_param as period4Param,
    s.period5_param as period5Param,
    s.period1_date as period1Date,
    s.period2_date as period2Date,
    s.period3_date as period3Date,
    s.period4_date as period4Date,
    s.period5_date as period5Date
  </sql>

  <sql id="viewsSnapshotColumns">
    s.id,
    s.created_at as createdAt
  </sql>

  <select id="selectByKey" parameterType="Long" resultType="Snapshot">
    SELECT
    <include refid="snapshotColumns"/>
    FROM snapshots s
    <where>
      AND s.id=#{key}
    </where>
  </select>

  <select id="selectByIds" parameterType="Long" resultType="Snapshot">
    SELECT
    <include refid="snapshotColumns"/>
    FROM snapshots s
    WHERE
    s.id in
    <foreach collection="ids" item="id" separator="," open="(" close=")">
      #{id}
    </foreach>
  </select>

  <select id="selectLastSnapshot" resultType="Snapshot">
    select
    <include refid="snapshotColumns"/>
    from snapshots s
    where s.islast=${_true} and s.project_id = #{resource}
  </select>

  <select id="countLastSnapshotByComponentUuid" resultType="Integer">
    SELECT count(s.id)
    FROM snapshots s
    INNER JOIN projects p ON p.id=s.project_id AND p.uuid=#{componentUuid}
    <where>
      AND s.islast=${_true}
    </where>
  </select>

  <select id="selectSnapshotsByQuery" parameterType="map" resultType="Snapshot">
    SELECT
    <include refid="snapshotColumns"/>
    FROM snapshots s
    <if test="query.componentUuid != null">
      INNER JOIN projects p ON p.id=s.project_id AND p.uuid=#{query.componentUuid} AND p.enabled=${_true}
    </if>
    <where>
      <if test="query.componentId != null">
        AND s.project_id=#{query.componentId}
      </if>
      <if test="query.scope != null">
        AND s.scope=#{query.scope}
      </if>
      <if test="query.qualifier != null">
        AND s.qualifier=#{query.qualifier}
      </if>
      <if test="query.status != null">
        AND s.status=#{query.status}
      </if>
      <if test="query.version != null">
        AND s.version=#{query.version}
      </if>
      <if test="query.isLast != null">
        AND s.islast=#{query.isLast}
      </if>
      <if test="query.createdAfter != null">
        AND s.created_at>=#{query.createdAfter}
      </if>
      <if test="query.createdBefore != null">
        AND s.created_at&lt;#{query.createdBefore}
      </if>
    </where>
    <if test="query.sortField != null">
      ORDER BY
      <if test="query.sortField == 'created_at'">
        created_at
      </if>
      <if test="query.sortOrder == 'asc'">
        asc
      </if>
      <if test="query.sortOrder == 'desc'">
        desc
      </if>
    </if>
  </select>

  <select id="selectPreviousVersionSnapshots" parameterType="map" resultType="Snapshot">
    SELECT
    <include refid="snapshotColumns"/>
    FROM snapshots s
    INNER JOIN events e ON s.id = e.snapshot_id AND e.name &lt;&gt; #{lastVersion} AND e.category='Version'
    <where>
      s.project_id=#{componentId}
    </where>
    ORDER BY e.event_date DESC
  </select>

  <select id="selectOldestSnapshots" parameterType="map" resultType="Snapshot">
    SELECT
    <include refid="snapshotColumns"/>
    FROM snapshots s
    <where>
      s.project_id=#{componentId}
    </where>
    ORDER BY s.created_at ASC
  </select>

  <select id="selectSnapshotAndChildrenOfScope" parameterType="map" resultType="Snapshot">
    select
    <include refid="snapshotColumns"/>
    from snapshots s
    where s.scope = #{scope}
    AND (s.id = #{snapshot} or s.root_snapshot_id = #{snapshot})
  </select>

  <select id="selectSnapshotBefore" resultType="ViewsSnapshot">
    SELECT
    <include refid="viewsSnapshotColumns"/>
    FROM snapshots s
    <where>
      and s.project_id = #{componentId}
      and s.status = 'P'
      and s.created_at &lt; #{date}
    </where>
    order by created_at desc
  </select>

  <select id="selectLatestSnapshot" resultType="ViewsSnapshot">
    SELECT
    <include refid="viewsSnapshotColumns"/>
    FROM snapshots s
    <where>
      and s.project_id = #{componentId}
      and s.status = 'P'
      and s.islast = ${_true}
    </where>
  </select>

  <sql id="insertColumns">
    (parent_snapshot_id, root_snapshot_id, root_project_id, project_id, created_at, build_date, status, purge_status,
    islast, scope, qualifier, version, path, depth,
    period1_mode, period2_mode, period3_mode, period4_mode, period5_mode,
    period1_param, period2_param, period3_param, period4_param, period5_param,
    period1_date, period2_date, period3_date, period4_date, period5_date)
  </sql>

  <update id="updateSnapshotAndChildrenLastFlagAndStatus" parameterType="map">
    update snapshots
    set islast = #{isLast}, status = #{status}
    where root_snapshot_id=#{root} or id=#{root} or (path like #{path} and root_snapshot_id=#{pathRootId})
  </update>

  <update id="updateSnapshotAndChildrenLastFlag" parameterType="map">
    update snapshots
    set islast = #{isLast}
    where root_snapshot_id=#{root} or id=#{root} or (path like #{path} and root_snapshot_id=#{pathRootId})
  </update>

  <insert id="insert" parameterType="Snapshot" keyColumn="id" useGeneratedKeys="true" keyProperty="id">
    insert into snapshots
    <include refid="insertColumns"/>
    values (#{parentId}, #{rootId}, #{rootProjectId}, #{componentId}, #{createdAt}, #{buildDate}, #{status},
    #{purgeStatus}, #{last}, #{scope}, #{qualifier}, #{version}, #{path}, #{depth},
    #{period1Mode}, #{period2Mode}, #{period3Mode}, #{period4Mode}, #{period5Mode},
    #{period1Param}, #{period2Param}, #{period3Param}, #{period4Param}, #{period5Param},
    #{period1Date}, #{period2Date}, #{period3Date}, #{period4Date}, #{period5Date})
  </insert>

</mapper>





© 2015 - 2025 Weber Informatics LLC | Privacy Policy