org.sonar.db.ce.CeActivityMapper.xml Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of sonar-db-dao Show documentation
Show all versions of sonar-db-dao Show documentation
Open source platform for continuous inspection of code quality
The newest version!
<?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "mybatis-3-mapper.dtd"> <mapper namespace="org.sonar.db.ce.CeActivityMapper"> <!--assumes query includes an left left outer join on table ce_scanner_context with alias csc --> <sql id="hasScannerContextColumn" databaseId="mssql"> cast(case when csc.task_uuid is null then 0 else 1 end as bit) as hasScannerContext </sql> <sql id="hasScannerContextColumn" databaseId="oracle"> case when csc.task_uuid is null then 0 else 1 end as hasScannerContext </sql> <sql id="hasScannerContextColumn"> csc.task_uuid is not null as hasScannerContext </sql> <sql id="columns"> ca.id, ca.uuid, ca.task_type as taskType, ca.component_uuid as componentUuid, ca.analysis_uuid as analysisUuid, ca.status as status, ca.submitter_uuid as submitterUuid, ca.submitted_at as submittedAt, ca.worker_uuid as workerUuid, ca.started_at as startedAt, ca.executed_at as executedAt, ca.created_at as createdAt, ca.updated_at as updatedAt, ca.is_last as isLast, ca.is_last_key as isLastKey, ca.execution_time_ms as executionTimeMs, ca.error_message as errorMessage, ca.error_type as errorType, <include refid="hasScannerContextColumn"/> </sql> <select id="selectByUuid" parameterType="String" resultType="org.sonar.db.ce.CeActivityDto"> select <include refid="columns"/>, ca.error_stacktrace as errorStacktrace from ce_activity ca left outer join ce_scanner_context csc on ca.uuid = csc.task_uuid where ca.uuid=#{uuid,jdbcType=VARCHAR} </select> <select id="selectByQuery" parameterType="map" resultType="org.sonar.db.ce.CeActivityDto"> select <include refid="columns"/> <include refid="sqlSelectByQuery" /> order by ca.id desc limit #{pagination.pageSize,jdbcType=INTEGER} offset #{pagination.offset,jdbcType=INTEGER} </select> <select id="selectByQuery" parameterType="map" resultType="org.sonar.db.ce.CeActivityDto" databaseId="mssql"> select * from ( select row_number() over(order by id desc) as number, <include refid="columns"/> <include refid="sqlSelectByQuery" /> ) as query where query.number between #{pagination.startRowNumber,jdbcType=INTEGER} and #{pagination.endRowNumber,jdbcType=INTEGER} order by id desc </select> <select id="selectByQuery" parameterType="map" resultType="org.sonar.db.ce.CeActivityDto" databaseId="oracle"> select * from ( select rownum as rn, t.* from ( select <include refid="columns"/> <include refid="sqlSelectByQuery" /> order by ca.id desc ) t ) t where t.rn between #{pagination.startRowNumber,jdbcType=INTEGER} and #{pagination.endRowNumber,jdbcType=INTEGER} </select> <sql id="sqlSelectByQuery"> from ce_activity ca left outer join ce_scanner_context csc on csc.task_uuid = ca.uuid <where> <if test="query.onlyCurrents"> and ca.is_last=${_true} </if> <if test="query.componentUuids != null and query.componentUuids.size()>0"> and ca.component_uuid in <foreach collection="query.componentUuids" open="(" close=")" item="cUuid" separator=","> #{cUuid,jdbcType=VARCHAR} </foreach> </if> <if test="query.statuses != null and !query.statuses.isEmpty()"> and ca.status in <foreach collection="query.statuses" open="(" close=")" item="status" separator=","> #{status,jdbcType=VARCHAR} </foreach> </if> <if test="query.type != null"> and ca.task_type=#{query.type,jdbcType=VARCHAR} </if> <if test="query.minSubmittedAt != null"> and ca.submitted_at >= #{query.minSubmittedAt,jdbcType=BIGINT} </if> <if test="query.maxExecutedAt != null"> and ca.executed_at <= #{query.maxExecutedAt,jdbcType=BIGINT} </if> </where> </sql> <select id="selectOlderThan" parameterType="long" resultType="org.sonar.db.ce.CeActivityDto"> select <include refid="columns"/> from ce_activity ca left outer join ce_scanner_context csc on csc.task_uuid = ca.uuid where ca.created_at < #{beforeDate,jdbcType=BIGINT} </select> <select id="countLastByStatusAndComponentUuid" resultType="int"> select count(1) from ce_activity where status=#{status,jdbcType=VARCHAR} and is_last=${_true} <if test="componentUuid!=null"> and component_uuid=#{componentUuid,jdbcType=VARCHAR} </if> </select> <insert id="insert" parameterType="org.sonar.db.ce.CeActivityDto" useGeneratedKeys="false"> insert into ce_activity ( uuid, component_uuid, analysis_uuid, status, task_type, is_last, is_last_key, submitter_uuid, submitted_at, worker_uuid, execution_count, started_at, executed_at, created_at, updated_at, execution_time_ms, error_message, error_stacktrace, error_type ) values ( #{uuid,jdbcType=VARCHAR}, #{componentUuid,jdbcType=VARCHAR}, #{analysisUuid,jdbcType=VARCHAR}, #{status,jdbcType=VARCHAR}, #{taskType,jdbcType=VARCHAR}, #{isLast,jdbcType=BOOLEAN}, #{isLastKey,jdbcType=VARCHAR}, #{submitterUuid,jdbcType=VARCHAR}, #{submittedAt,jdbcType=BIGINT}, #{workerUuid,jdbcType=VARCHAR}, 0, #{startedAt,jdbcType=BIGINT}, #{executedAt,jdbcType=BIGINT}, #{createdAt,jdbcType=BIGINT}, #{updatedAt,jdbcType=BIGINT}, #{executionTimeMs,jdbcType=BIGINT}, #{errorMessage,jdbcType=VARCHAR}, #{errorStacktrace,jdbcType=CLOB}, #{errorType,jdbcType=VARCHAR} ) </insert> <update id="updateIsLastToFalseForLastKey" parameterType="map"> update ce_activity set is_last=${_false}, updated_at=#{updatedAt,jdbcType=BIGINT} where is_last=${_true} and is_last_key=#{isLastKey,jdbcType=VARCHAR} </update> <delete id="deleteByUuids" parameterType="string"> delete from ce_activity where uuid in <foreach collection="uuids" open="(" close=")" item="uuid" separator=","> #{uuid,jdbcType=VARCHAR} </foreach> </delete> </mapper>