org.sonar.db.component.ComponentMapper.xml Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of sonar-db Show documentation
Show all versions of sonar-db Show documentation
Create and request SonarQube schema
<?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.ComponentMapper"> <sql id="componentColumns"> p.id, p.uuid as uuid, p.project_uuid as projectUuid, p.module_uuid as moduleUuid, p.module_uuid_path as moduleUuidPath, p.kee as kee, p.deprecated_kee as deprecatedKey, p.name as name, p.long_name as longName, p.description as description, p.qualifier as qualifier, p.scope as scope, p.language as language, p.root_id as parentProjectId, p.path as path, p.enabled as enabled, p.copy_resource_id as copyResourceId, p.person_id as developerId, p.authorization_updated_at as authorizationUpdatedAt, p.created_at as createdAt </sql> <sql id="viewsComponentColumns"> p.id, p.name, p.uuid as uuid, p.kee as kee, p.qualifier as qualifier, p.scope as scope, P.copy_resource_id as copyResourceId, p.module_uuid as moduleUuid </sql> <sql id="authorizedComponentColumns"> p.id, p.uuid as uuid, p.kee as kee, p.qualifier as qualifier, p.scope as scope </sql> <select id="selectByKey" parameterType="String" resultType="Component"> SELECT <include refid="componentColumns"/> FROM projects p <where> AND p.kee=#{key} </where> </select> <select id="selectComponentsHavingSameKeyOrderedById" parameterType="String" resultType="Component"> SELECT <include refid="componentColumns"/> FROM projects p <where> AND p.kee=#{key} </where> ORDER BY p.id ASC </select> <select id="selectById" parameterType="long" resultType="Component"> SELECT <include refid="componentColumns"/> FROM projects p <where> AND p.id=#{id} </where> </select> <select id="selectByUuid" parameterType="String" resultType="Component"> SELECT <include refid="componentColumns"/> FROM projects p <where> AND p.uuid=#{uuid} </where> </select> <select id="selectByProjectUuid" parameterType="string" resultType="Component"> SELECT <include refid="componentColumns"/> FROM projects p <where> p.project_uuid=#{projectUuid} </where> </select> <select id="countById" parameterType="long" resultType="long"> SELECT count(p.id) FROM projects p <where> AND p.id=#{id} </where> </select> <select id="selectByKeys" parameterType="String" resultType="Component"> select <include refid="componentColumns"/> from projects p <where> p.enabled=${_true} and p.kee in <foreach collection="keys" open="(" close=")" item="key" separator=","> #{key} </foreach> </where> </select> <select id="selectByIds" parameterType="long" resultType="Component"> select <include refid="componentColumns"/> from projects p <where> p.enabled=${_true} and p.id in <foreach collection="ids" open="(" close=")" item="id" separator=","> #{id} </foreach> </where> </select> <select id="selectByUuids" parameterType="String" resultType="Component"> select <include refid="componentColumns"/> from projects p <where> and p.uuid in <foreach collection="uuids" open="(" close=")" item="uuid" separator=","> #{uuid} </foreach> </where> </select> <select id="selectExistingUuids" parameterType="String" resultType="String"> select p.uuid from projects p <where> and p.uuid in <foreach collection="uuids" open="(" close=")" item="uuid" separator=","> #{uuid} </foreach> </where> </select> <select id="selectSubProjectsByComponentUuids" parameterType="String" resultType="Component"> SELECT <include refid="componentColumns"/> FROM projects p INNER JOIN projects child ON child.root_id=p.id AND child.enabled=${_true} <where> AND p.enabled=${_true} AND p.scope='PRJ' AND child.uuid in <foreach collection="uuids" open="(" close=")" item="uuid" separator=","> #{uuid} </foreach> </where> </select> <select id="selectDescendantModules" parameterType="map" resultType="Component"> SELECT <include refid="componentColumns"/> FROM projects p <include refid="modulesTreeQuery"/> </select> <sql id="modulesTreeQuery"> INNER JOIN projects module ON module.project_uuid = p.project_uuid AND module.uuid = #{moduleUuid} AND module.scope='PRJ' AND module.enabled = ${_true} <where> <if test="excludeDisabled"> p.enabled = ${_true} </if> AND p.scope = #{scope} AND <choose> <when test="_databaseId == 'mssql'"> p.module_uuid_path LIKE module.module_uuid_path + '%' </when> <when test="_databaseId == 'mysql'"> p.module_uuid_path LIKE concat(module.module_uuid_path, '%') </when> <otherwise> p.module_uuid_path LIKE module.module_uuid_path || '%' </otherwise> </choose> </where> </sql> <select id="selectEnabledFilesFromProject" parameterType="map" resultType="FilePathWithHash"> SELECT p.uuid, p.path, p.module_uuid as moduleUuid, fs.src_hash as srcHash, fs.revision FROM projects p INNER JOIN file_sources fs ON fs.file_uuid=p.uuid and fs.data_type='SOURCE' <where> AND p.project_uuid=#{projectUuid} AND p.enabled=${_true} AND p.scope='FIL' </where> </select> <select id="selectDescendantFiles" parameterType="map" resultType="FilePathWithHash"> SELECT p.uuid, p.path, p.module_uuid as moduleUuid, fs.src_hash as srcHash, fs.revision FROM projects p INNER JOIN file_sources fs ON fs.file_uuid=p.uuid and fs.data_type='SOURCE' <include refid="modulesTreeQuery"/> </select> <select id="selectProjectUuids" resultType="String"> SELECT p.uuid FROM projects p <where> AND p.enabled=${_true} AND p.scope='PRJ' AND p.qualifier='TRK' </where> </select> <select id="selectProjects" resultType="Component"> select <include refid="componentColumns"/> from projects p <where> p.enabled=${_true} AND p.scope='PRJ' AND p.qualifier='TRK' </where> </select> <select id="selectComponentsByQualifiers" resultType="Component"> SELECT <include refid="componentColumns"/> FROM projects p <where> <foreach collection="qualifiers" open="(" close=")" item="qualifier" separator="OR "> p.qualifier=#{qualifier} </foreach> </where> </select> <select id="selectComponents" resultType="Component"> select <include refid="componentColumns"/> from projects p <where> AND p.enabled=${_true} AND p.copy_resource_id is null AND p.qualifier in <foreach collection="qualifiers" open="(" close=")" item="qualifier" separator=","> #{qualifier} </foreach> <if test="query!=null"> and ( UPPER(p.name) like #{query} or UPPER(p.kee) like #{query} ) </if> </where> ORDER BY UPPER(p.name), p.name </select> <select id="selectByQuery" resultType="Component"> select <include refid="componentColumns"/> <include refid="sqlSelectByQuery"/> ORDER BY LOWER(p.name), p.name </select> <select id="countByQuery" resultType="int"> select count(p.id) <include refid="sqlSelectByQuery"/> </select> <sql id="sqlSelectByQuery"> from projects p <where> AND p.enabled=${_true} AND p.copy_resource_id is null <if test="query.qualifiers!=null"> AND p.qualifier in <foreach collection="query.qualifiers" item="qualifier" open="(" close=")" separator=","> #{qualifier} </foreach> </if> <if test="query.language!=null"> AND p.language = #{query.language} </if> <if test="query.nameOrKeyQuery!=null"> AND ( p.kee=#{query.nameOrKeyQuery} OR p.id IN ( SELECT ri.resource_id FROM resource_index ri WHERE ri.kee like #{query.nameOrKeyQueryToSqlForResourceIndex} ESCAPE '/' <if test="query.qualifiers!=null"> AND ri.qualifier in <foreach collection="query.qualifiers" item="qualifier" open="(" close=")" separator=","> #{qualifier} </foreach> </if> ) ) </if> </where> </sql> <select id="selectDirectChildren" resultType="ComponentWithSnapshot"> select <include refid="componentColumns"/>, s.id as snapshotId <include refid="sqlSelectByTreeQuery"/> and s.parent_snapshot_id = #{query.baseSnapshot.id} order by ${query.sqlSort} </select> <select id="countDirectChildren" resultType="int"> select count(p.id) <include refid="sqlSelectByTreeQuery"/> and s.parent_snapshot_id = #{query.baseSnapshot.id} </select> <select id="selectAllChildren" resultType="ComponentWithSnapshot"> select <include refid="componentColumns"/>, s.id as snapshotId <include refid="sqlSelectAllChildren" /> order by ${query.sqlSort} </select> <select id="countAllChildren" resultType="int"> select count(p.id) <include refid="sqlSelectAllChildren"/> </select> <sql id="sqlSelectAllChildren"> <include refid="sqlSelectByTreeQuery"/> <if test="query.baseSnapshot.rootId!=null"> and s.root_snapshot_id = #{query.baseSnapshot.rootId} </if> <if test="query.baseSnapshot.rootId==null"> and s.root_snapshot_id = #{query.baseSnapshot.id} </if> and s.path like #{query.baseSnapshotPath} ESCAPE '/' </sql> <sql id="sqlSelectByTreeQuery"> from projects p inner join snapshots s on p.id = s.project_id where p.enabled=${_true} <if test="query.qualifiers!=null"> AND p.qualifier in <foreach collection="query.qualifiers" item="qualifier" open="(" close=")" separator=","> #{qualifier} </foreach> </if> <if test="query.nameOrKeyQuery!=null"> AND ( p.kee=#{query.nameOrKeyQuery} OR p.id IN ( SELECT ri.resource_id FROM resource_index ri WHERE ri.kee like #{query.nameOrKeyQueryToSqlForResourceIndex} ESCAPE '/' ) OR p.copy_resource_id IN ( SELECT ri.resource_id FROM resource_index ri WHERE ri.kee like #{query.nameOrKeyQueryToSqlForResourceIndex} ESCAPE '/' ) ) </if> </sql> <select id="countRootComponents" resultType="int"> select count(p.id) from projects p <where> p.enabled=${_true} AND p.copy_resource_id is null AND p.qualifier in <foreach collection="qualifiers" open="(" close=")" item="qualifier" separator=","> #{qualifier} </foreach> <if test="query!=null"> and ( UPPER(p.name) like #{query} or UPPER(p.kee) like #{query} ) </if> </where> </select> <select id="selectUuidsForQualifiers" resultType="UuidWithProjectUuid"> SELECT p.uuid as "uuid", p.project_uuid as "projectUuid" FROM projects p <where> <foreach collection="qualifiers" open="(" close=")" item="qualifier" separator="OR "> p.qualifier=#{qualifier} </foreach> </where> </select> <select id="selectProjectsFromView" resultType="String"> SELECT p.uuid FROM projects technical_projects INNER JOIN projects p on p.id=technical_projects.copy_resource_id AND p.enabled=${_true} <where> technical_projects.enabled=${_true} AND technical_projects.project_uuid=#{projectViewUuid} AND technical_projects.module_uuid_path LIKE #{viewUuidLikeQuery} </where> </select> <select id="selectComponentsFromProjectKeyAndScope" parameterType="map" resultType="Component"> SELECT <include refid="componentColumns"/> FROM projects p INNER JOIN projects root ON root.uuid=p.project_uuid AND root.kee=#{projectKey} <where> <if test="excludeDisabled"> p.enabled = ${_true} </if> <if test="scope != null"> AND p.scope=#{scope} </if> </where> </select> <select id="selectProvisionedProjects" parameterType="map" resultType="Component"> select <include refid="componentColumns"/> from projects p <include refid="provisionClauses"/> </select> <select id="countProvisionedProjects" parameterType="map" resultType="int"> select count(p.id) from projects p <include refid="provisionClauses"/> </select> <sql id="provisionClauses"> left join snapshots s on s.project_id=p.id where s.id is null and p.enabled=${_true} and p.qualifier=#{qualifier} and p.copy_resource_id is null <if test="query!=null"> and ( UPPER(p.name) like #{query} or UPPER(p.kee) like #{query} ) </if> </sql> <select id="selectGhostProjects" parameterType="map" resultType="Component"> select distinct <include refid="componentColumns"/> from projects p <include refid="ghostClauses"/> </select> <select id="countGhostProjects" parameterType="map" resultType="long"> select count(p.id) from projects p <include refid="ghostClauses"/> </select> <sql id="ghostClauses"> inner join snapshots s1 on s1.project_id = p.id and s1.status='U' left join snapshots s2 on s2.project_id = p.id and s2.status='P' where s2.id is null and p.qualifier=#{qualifier} and p.copy_resource_id is null <if test="query!=null"> and ( UPPER(p.name) like #{query} or UPPER(p.kee) like #{query} ) </if> </sql> <sql id="insertSql"> INSERT INTO projects (kee, deprecated_kee, uuid, project_uuid, module_uuid, module_uuid_path, name, long_name, qualifier, scope, language, description, root_id, path, copy_resource_id, person_id, enabled, created_at, authorization_updated_at) VALUES (#{kee,jdbcType=VARCHAR}, #{deprecatedKey,jdbcType=VARCHAR}, #{uuid,jdbcType=VARCHAR}, #{projectUuid,jdbcType=VARCHAR}, #{moduleUuid,jdbcType=VARCHAR}, #{moduleUuidPath,jdbcType=VARCHAR}, #{name,jdbcType=VARCHAR}, #{longName,jdbcType=VARCHAR}, #{qualifier,jdbcType=VARCHAR}, #{scope,jdbcType=VARCHAR}, #{language,jdbcType=VARCHAR}, #{description,jdbcType=VARCHAR}, #{parentProjectId,jdbcType=BIGINT}, #{path,jdbcType=VARCHAR}, #{copyResourceId,jdbcType=BIGINT}, #{developerId,jdbcType=BIGINT}, #{enabled,jdbcType=BOOLEAN}, #{createdAt,jdbcType=TIMESTAMP}, #{authorizationUpdatedAt,jdbcType=BIGINT}) </sql> <insert id="insert" parameterType="Component" keyColumn="id" useGeneratedKeys="true" keyProperty="id"> <include refid="insertSql"/> </insert> <insert id="insertBatch" parameterType="Component" useGeneratedKeys="false"> <include refid="insertSql"/> </insert> <update id="update" parameterType="Component" useGeneratedKeys="false"> UPDATE projects SET kee=#{kee,jdbcType=VARCHAR}, deprecated_kee=#{deprecatedKey,jdbcType=VARCHAR}, project_uuid=#{projectUuid,jdbcType=VARCHAR}, module_uuid=#{moduleUuid,jdbcType=VARCHAR}, module_uuid_path=#{moduleUuidPath,jdbcType=VARCHAR}, name=#{name,jdbcType=VARCHAR}, long_name=#{longName,jdbcType=VARCHAR}, qualifier=#{qualifier,jdbcType=VARCHAR}, scope=#{scope,jdbcType=VARCHAR}, language=#{language,jdbcType=VARCHAR}, description=#{description,jdbcType=VARCHAR}, root_id=#{parentProjectId,jdbcType=BIGINT}, path=#{path,jdbcType=VARCHAR}, copy_resource_id=#{copyResourceId,jdbcType=BIGINT}, person_id=#{developerId,jdbcType=BIGINT}, enabled=#{enabled,jdbcType=BOOLEAN}, authorization_updated_at=#{authorizationUpdatedAt,jdbcType=BIGINT} WHERE uuid=#{uuid} </update> <delete id="delete" parameterType="long"> DELETE FROM projects WHERE id=#{id} </delete> </mapper>
© 2015 - 2025 Weber Informatics LLC | Privacy Policy