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-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.component.ComponentMapper"> <sql id="componentColumns"> p.id, p.organization_uuid as organizationUuid, p.uuid as uuid, p.uuid_path as uuidPath, p.project_uuid as projectUuid, p.module_uuid as moduleUuid, p.module_uuid_path as moduleUuidPath, p.main_branch_project_uuid as mainBranchProjectUuid, p.kee as kee, p.deprecated_kee as deprecatedKey, p.name as name, p.long_name as longName, p.description as description, p.tags as tagsString, p.qualifier as qualifier, p.scope as scope, p.language as language, p.root_uuid as rootUuid, p.path as path, p.enabled as enabled, p.copy_component_uuid as copyComponentUuid, p.private as isPrivate, p.created_at as createdAt </sql> <select id="selectByKey" parameterType="String" resultType="Component"> SELECT <include refid="componentColumns"/> FROM projects p where p.kee=#{key,jdbcType=VARCHAR} </select> <select id="selectByKeyAndBranchKey" parameterType="String" resultType="Component"> SELECT <include refid="componentColumns"/> FROM projects p INNER JOIN project_branches pb on pb.uuid = p.project_uuid <where> (p.kee=#{dbKey,jdbcType=VARCHAR} OR p.kee=#{key,jdbcType=VARCHAR}) AND pb.kee=#{branch,jdbcType=VARCHAR} </where> </select> <select id="selectComponentsHavingSameKeyOrderedById" parameterType="String" resultType="Component"> select <include refid="componentColumns"/> from projects p where p.kee=#{key,jdbcType=VARCHAR} order BY p.id ASC </select> <select id="selectById" parameterType="long" resultType="Component"> SELECT <include refid="componentColumns"/> FROM projects p where p.id = #{id,jdbcType=BIGINT} </select> <select id="selectByUuid" parameterType="String" resultType="Component"> SELECT <include refid="componentColumns"/> FROM projects p where p.uuid=#{uuid,jdbcType=VARCHAR} </select> <select id="selectByProjectUuid" parameterType="string" resultType="Component"> select <include refid="componentColumns"/> from projects root inner join projects p on p.project_uuid=root.uuid and p.organization_uuid=root.organization_uuid where root.uuid=#{projectUuid,jdbcType=VARCHAR} </select> <select id="selectByKeys" parameterType="String" resultType="Component"> select <include refid="componentColumns"/> from projects p where p.enabled=${_true} and p.main_branch_project_uuid is null and p.kee in <foreach collection="keys" open="(" close=")" item="key" separator=","> #{key,jdbcType=VARCHAR} </foreach> </select> <select id="selectByKeysAndBranch" parameterType="String" resultType="Component"> SELECT <include refid="componentColumns"/> FROM projects p INNER JOIN project_branches pb on pb.uuid = p.project_uuid <where> p.enabled=${_true} AND p.kee IN <foreach collection="keys" open="(" close=")" item="key" separator=","> #{key,jdbcType=VARCHAR} </foreach> AND pb.kee=#{branch,jdbcType=VARCHAR} </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,jdbcType=BIGINT} </foreach> </select> <select id="selectByUuids" parameterType="String" resultType="Component"> select <include refid="componentColumns"/> from projects p where p.uuid in <foreach collection="uuids" open="(" close=")" item="uuid" separator=","> #{uuid,jdbcType=VARCHAR} </foreach> </select> <select id="selectExistingUuids" parameterType="String" resultType="String"> select p.uuid from projects p where p.uuid in <foreach collection="uuids" open="(" close=")" item="uuid" separator=","> #{uuid,jdbcType=VARCHAR} </foreach> </select> <select id="selectSubProjectsByComponentUuids" parameterType="String" resultType="Component"> SELECT <include refid="componentColumns"/> FROM projects p INNER JOIN projects child ON child.root_uuid=p.uuid and child.enabled=${_true} and child.organization_uuid=p.organization_uuid where p.enabled=${_true} and p.scope='PRJ' and child.uuid in <foreach collection="uuids" open="(" close=")" item="uuid" separator=","> #{uuid,jdbcType=VARCHAR} </foreach> </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.organization_uuid = p.organization_uuid and module.uuid = #{moduleUuid} and module.scope='PRJ' AND module.enabled = ${_true} where p.scope = #{scope,jdbcType=VARCHAR} <if test="excludeDisabled"> and p.enabled = ${_true} </if> 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> </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 root INNER JOIN projects p on p.project_uuid=root.uuid and p.organization_uuid=root.organization_uuid and p.enabled=${_true} and p.scope='FIL' INNER JOIN file_sources fs ON fs.file_uuid=p.uuid and fs.data_type='SOURCE' where root.uuid=#{projectUuid,jdbcType=VARCHAR} </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="selectProjects" resultType="Component"> select <include refid="componentColumns"/> from projects p where p.enabled=${_true} AND p.scope='PRJ' AND p.qualifier='TRK' AND p.main_branch_project_uuid IS NULL </select> <select id="selectAllRootsByOrganization" resultType="Component"> select <include refid="componentColumns"/> from projects p where p.scope='PRJ' and (p.qualifier='TRK' or p.qualifier='VW' or p.qualifier='APP') and p.organization_uuid = #{organizationUuid,jdbcType=VARCHAR} and p.main_branch_project_uuid IS NULL </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,jdbcType=VARCHAR} </foreach> </select> <select id="countComponentByOrganizationAndId" resultType="int"> select count(1) from projects p where p.organization_uuid = #{organizationUuid,jdbcType=VARCHAR} and p.id = #{componentId,jdbcType=BIGINT} </select> <select id="selectByQuery" resultType="Component"> select <include refid="componentColumns"/> <include refid="sqlSelectByQuery"/> ORDER BY LOWER(p.name), p.name, p.id </select> <select id="countByQuery" resultType="int"> select count(p.id) <include refid="sqlSelectByQuery"/> </select> <sql id="sqlSelectByQuery"> from projects p <if test="query.analyzedBefore!=null"> inner join snapshots sa on sa.component_uuid=p.uuid and sa.status='P' and sa.islast=${_true} and sa.created_at < #{query.analyzedBefore,jdbcType=BIGINT} </if> where p.enabled=${_true} AND p.main_branch_project_uuid is null AND p.copy_component_uuid is null <if test="organizationUuid!=null"> and p.organization_uuid=#{organizationUuid,jdbcType=VARCHAR} </if> <if test="query.qualifiers!=null"> and p.qualifier in <foreach collection="query.qualifiers" item="qualifier" open="(" close=")" separator=","> #{qualifier,jdbcType=VARCHAR} </foreach> </if> <if test="query.language!=null"> and p.language = #{query.language,jdbcType=VARCHAR} </if> <if test="query.componentIds!=null"> and p.id in <foreach collection="query.componentIds" item="componentId" open="(" close=")" separator=","> #{componentId,jdbcType=BIGINT} </foreach> </if> <if test="query.componentKeys!=null"> and p.kee in <foreach collection="query.componentKeys" item="componentKey" open="(" close=")" separator=","> #{componentKey,jdbcType=BIGINT} </foreach> </if> <if test="query.componentUuids!=null"> and p.uuid in <foreach collection="query.componentUuids" item="componentUuid" open="(" close=")" separator=","> #{componentUuid,jdbcType=BIGINT} </foreach> </if> <if test="query.nameOrKeyQuery!=null"> and ( upper(p.name) like #{query.nameOrKeyUpperLikeQuery,jdbcType=VARCHAR} escape '/' or <choose> <when test="query.isPartialMatchOnKey()"> upper(p.kee) like #{query.nameOrKeyUpperLikeQuery,jdbcType=VARCHAR} escape '/' </when> <otherwise> p.kee = #{query.nameOrKeyQuery,jdbcType=VARCHAR} </otherwise> </choose> ) </if> <if test="query.private!=null"> <if test="query.private.equals(true)"> and p.private=${_true} </if> <if test="query.private.equals(false)"> and p.private=${_false} </if> </if> <if test="query.isOnProvisionedOnly()"> and not exists(select 1 from snapshots sp where sp.component_uuid=p.uuid) and not exists( select 1 from snapshots sp inner join project_branches pb on sp.component_uuid = pb.uuid where pb.project_uuid = p.uuid ) </if> </sql> <select id="selectDescendants" resultType="Component"> select <include refid="componentColumns"/> from projects p <include refid="selectDescendantsJoins"/> <where> <include refid="selectDescendantsFilters"/> </where> </select> <sql id="selectDescendantsJoins"> inner join projects base on base.project_uuid = p.project_uuid and base.uuid = #{baseUuid} <choose> <when test="query.getStrategy().name() == 'CHILDREN'"> and p.uuid_path = #{baseUuidPath,jdbcType=VARCHAR} </when> <otherwise> and p.uuid_path like #{baseUuidPath,jdbcType=VARCHAR} ESCAPE '/' </otherwise> </choose> </sql> <sql id="selectDescendantsFilters"> and p.enabled = ${_true} <if test="query.qualifiers != null"> and p.qualifier in <foreach collection="query.qualifiers" item="qualifier" open="(" close=")" separator=","> #{qualifier,jdbcType=VARCHAR} </foreach> </if> <if test="query.scopes != null"> and p.scope in <foreach collection="query.scopes" item="scope" open="(" close=")" separator=","> #{scope,jdbcType=VARCHAR} </foreach> </if> <if test="query.nameOrKeyQuery != null"> and ( p.kee = #{query.nameOrKeyQuery,jdbcType=VARCHAR} or upper(p.name) like #{query.nameOrKeyUpperLikeQuery,jdbcType=VARCHAR} escape '/' ) </if> </sql> <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,jdbcType=VARCHAR} </foreach> </select> <select id="selectViewKeysWithEnabledCopyOfProject" resultType="String"> select distinct p.kee from projects p inner join projects leaf on leaf.qualifier = 'TRK' and leaf.scope = 'FIL' and leaf.enabled = ${_true} and leaf.copy_component_uuid in <foreach collection="projectUuids" open="(" close=")" item="uuid" separator=",">#{uuid,jdbcType=VARCHAR}</foreach> where p.enabled = ${_true} and p.uuid = leaf.project_uuid and p.scope = 'PRJ' and p.qualifier in ('VW', 'APP') </select> <select id="selectProjectsFromView" resultType="String"> select p.copy_component_uuid from projects p where p.enabled = ${_true} and p.project_uuid = #{projectViewUuid,jdbcType=VARCHAR} and p.module_uuid_path like #{viewUuidLikeQuery,jdbcType=VARCHAR} and p.qualifier = 'TRK' and p.copy_component_uuid is not null </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,jdbcType=VARCHAR} <where> <if test="excludeDisabled"> p.enabled = ${_true} </if> <if test="scope != null"> AND p.scope=#{scope,jdbcType=VARCHAR} </if> </where> </select> <select id="selectUuidsByKeyFromProjectKey" parameterType="string" resultType="KeyWithUuid"> SELECT p.kee, p.uuid FROM projects p INNER JOIN projects root ON root.uuid=p.project_uuid AND root.kee=#{projectKey,jdbcType=VARCHAR} </select> <select id="selectGhostProjects" parameterType="map" resultType="Component"> select distinct <include refid="componentColumns"/> from projects p <include refid="ghostProjectClauses"/> </select> <select id="countGhostProjects" parameterType="map" resultType="long"> select count(distinct p.id) from projects p <include refid="ghostProjectClauses"/> </select> <sql id="ghostProjectClauses"> inner join snapshots s1 on s1.component_uuid = p.uuid and s1.status='U' left join snapshots s2 on s2.component_uuid = p.uuid and s2.status='P' where s2.id is null and p.qualifier='TRK' and p.main_branch_project_uuid is null and p.copy_component_uuid is null <if test="query!=null"> and ( UPPER(p.name) like #{query} ESCAPE '/' or UPPER(p.kee) like #{query} ESCAPE '/' ) </if> </sql> <select id="scrollForIndexing" parameterType="map" resultType="Component" fetchSize="${_scrollFetchSize}" resultSetType="FORWARD_ONLY"> select <include refid="componentColumns"/> from projects p where p.enabled=${_true} and p.copy_component_uuid is null and p.main_branch_project_uuid is null <if test="projectUuid != null"> and p.project_uuid = #{projectUuid,jdbcType=VARCHAR} </if> </select> <select id="scrollAllFilesForFileMove" parameterType="map" resultType="org.sonar.db.component.FileMoveRowDto" fetchSize="${_scrollFetchSize}" resultSetType="FORWARD_ONLY"> select p.id, p.uuid as uuid, p.kee as kee, p.path as path, fs.line_count as lineCount from projects p inner join file_sources fs on fs.file_uuid = p.uuid and fs.data_type = 'SOURCE' where p.project_uuid = #{projectUuid,jdbcType=VARCHAR} and p.enabled = ${_true} and p.scope = 'FIL' and p.qualifier in ('FIL', 'UTS') and p.path is not null </select> <select id="selectProjectsByNameQuery" resultType="Component"> select <include refid="componentColumns"/> from projects p <where> p.enabled=${_true} AND p.main_branch_project_uuid is null AND p.copy_component_uuid is null <if test="includeModules == false"> AND p.qualifier = 'TRK' </if> <if test="includeModules == true"> AND (p.qualifier = 'TRK' OR p.qualifier = 'BRC') </if> <if test="nameQuery != null"> AND UPPER(p.name) like #{nameQuery,jdbcType=VARCHAR} ESCAPE '/' </if> </where> ORDER BY p.name </select> <insert id="insert" parameterType="Component" keyColumn="id" useGeneratedKeys="true" keyProperty="id"> INSERT INTO projects ( organization_uuid, kee, deprecated_kee, uuid, uuid_path, project_uuid, module_uuid, module_uuid_path, main_branch_project_uuid, name, long_name, qualifier, scope, language, description, private, tags, root_uuid, path, copy_component_uuid, enabled, created_at, b_changed, b_copy_component_uuid, b_description, b_enabled, b_language, b_long_name, b_module_uuid, b_module_uuid_path, b_name, b_path, b_qualifier ) VALUES ( #{organizationUuid,jdbcType=VARCHAR}, #{kee,jdbcType=VARCHAR}, #{deprecatedKey,jdbcType=VARCHAR}, #{uuid,jdbcType=VARCHAR}, #{uuidPath,jdbcType=VARCHAR}, #{projectUuid,jdbcType=VARCHAR}, #{moduleUuid,jdbcType=VARCHAR}, #{moduleUuidPath,jdbcType=VARCHAR}, #{mainBranchProjectUuid, jdbcType=VARCHAR}, #{name,jdbcType=VARCHAR}, #{longName,jdbcType=VARCHAR}, #{qualifier,jdbcType=VARCHAR}, #{scope,jdbcType=VARCHAR}, #{language,jdbcType=VARCHAR}, #{description,jdbcType=VARCHAR}, #{isPrivate,jdbcType=BOOLEAN}, #{tagsString, jdbcType=VARCHAR}, #{rootUuid,jdbcType=VARCHAR}, #{path,jdbcType=VARCHAR}, #{copyComponentUuid,jdbcType=VARCHAR}, #{enabled,jdbcType=BOOLEAN}, #{createdAt,jdbcType=TIMESTAMP}, ${_false}, null, null, ${_false}, null, null, null, null, null, null, null ) </insert> <update id="updateTags" parameterType="Component" useGeneratedKeys="false"> update projects set tags = #{tagsString,jdbcType=VARCHAR} where uuid = #{uuid,jdbcType=VARCHAR} </update> <update id="update" parameterType="org.sonar.db.component.ComponentUpdateDto" useGeneratedKeys="false"> update projects set b_changed = #{bChanged,jdbcType=BOOLEAN}, b_copy_component_uuid = #{bCopyComponentUuid,jdbcType=VARCHAR}, b_description = #{bDescription,jdbcType=VARCHAR}, b_enabled = #{bEnabled,jdbcType=BOOLEAN}, b_uuid_path = #{bUuidPath,jdbcType=VARCHAR}, b_language = #{bLanguage,jdbcType=VARCHAR}, b_long_name = #{bLongName,jdbcType=VARCHAR}, b_module_uuid = #{bModuleUuid,jdbcType=VARCHAR}, b_module_uuid_path = #{bModuleUuidPath,jdbcType=VARCHAR}, b_name = #{bName,jdbcType=VARCHAR}, b_path = #{bPath,jdbcType=VARCHAR}, b_qualifier = #{bQualifier,jdbcType=VARCHAR} where uuid = #{uuid,jdbcType=VARCHAR} </update> <update id="updateBEnabledToFalse" parameterType="org.sonar.db.component.ComponentUpdateDto" useGeneratedKeys="false"> update projects set b_changed = ${_true}, b_copy_component_uuid = copy_component_uuid, b_description = description, b_enabled = ${_false}, b_uuid_path = uuid_path, b_language = language, b_long_name = long_name, b_module_uuid = module_uuid, b_module_uuid_path = module_uuid_path, b_name = name, b_path = path, b_qualifier = qualifier where uuid in <foreach collection="uuids" open="(" close=")" item="uuid" separator=",">#{uuid,jdbcType=VARCHAR}</foreach> </update> <update id="applyBChangesForRootComponentUuid" parameterType="string" useGeneratedKeys="false"> update projects set copy_component_uuid = b_copy_component_uuid, description = b_description, enabled = b_enabled, uuid_path = b_uuid_path, language = b_language, long_name = b_long_name, module_uuid = b_module_uuid, module_uuid_path = b_module_uuid_path, name = b_name, path = b_path, qualifier = b_qualifier, b_changed = ${_false}, b_copy_component_uuid = null, b_description = null, b_enabled = ${_false}, b_language = null, b_long_name = null, b_module_uuid = null, b_module_uuid_path = null, b_name = null, b_path = null, b_qualifier = null where project_uuid = #{projectUuid,jdbcType=VARCHAR} and b_changed = ${_true} </update> <update id="resetBChangedForRootComponentUuid" parameterType="map" > update projects set b_changed = ${_false} where project_uuid = #{projectUuid,jdbcType=VARCHAR} and b_changed = ${_true} </update> <update id="setPrivateForRootComponentUuid" parameterType="map" > update projects set private = #{isPrivate,jdbcType=BOOLEAN} where project_uuid = #{projectUuid,jdbcType=VARCHAR} and private <> #{isPrivate,jdbcType=BOOLEAN} </update> <delete id="delete" parameterType="long"> DELETE FROM projects WHERE id=#{id,jdbcType=BIGINT} </delete> <select id="selectComponentKeysHavingIssuesToMerge" resultType="KeyWithUuid"> SELECT DISTINCT p.kee as kee, p.uuid as uuid FROM projects p JOIN issues i ON p.uuid = i.component_uuid JOIN project_branches b ON i.project_uuid = b.uuid AND (b.branch_type = 'SHORT' OR b.branch_type = 'PULL_REQUEST') AND b.merge_branch_uuid = #{mergeBranchUuid,jdbcType=VARCHAR} AND i.status != 'CLOSED' </select> </mapper>