diff options
author | Sébastien Lesaint <sebastien.lesaint@sonarsource.com> | 2017-01-11 09:30:11 +0100 |
---|---|---|
committer | Sébastien Lesaint <sebastien.lesaint@sonarsource.com> | 2017-01-16 11:38:43 +0100 |
commit | cef26b66d8d63c52a079ede0d126206424b628b5 (patch) | |
tree | 222aade53f7e23707135a61efb816c463417ed23 /sonar-db/src | |
parent | e701115db2ee8409fe53236f0eb2875df33c0d0e (diff) | |
download | sonarqube-cef26b66d8d63c52a079ede0d126206424b628b5.tar.gz sonarqube-cef26b66d8d63c52a079ede0d126206424b628b5.zip |
SONAR-8595 ComponentDao.selectByUuids returns organization's key
by joining on ORGANIZATIONS table
add organizationKey (read-only) to ComponentDto
Diffstat (limited to 'sonar-db/src')
5 files changed, 39 insertions, 12 deletions
diff --git a/sonar-db/src/main/java/org/sonar/db/component/ComponentDto.java b/sonar-db/src/main/java/org/sonar/db/component/ComponentDto.java index a7c4576e4a7..32e22ffc618 100644 --- a/sonar-db/src/main/java/org/sonar/db/component/ComponentDto.java +++ b/sonar-db/src/main/java/org/sonar/db/component/ComponentDto.java @@ -50,6 +50,12 @@ public class ComponentDto implements Component { private String organizationUuid; /** + * The key of the organization the components belongs to. Read-only and nullable as it is populated only by some + * requests joining on the organizations table. + */ + private String organizationKey; + + /** * Non-empty and unique functional key */ private String kee; @@ -136,6 +142,10 @@ public class ComponentDto implements Component { return this; } + public String getOrganizationKey() { + return organizationKey; + } + public String uuid() { return uuid; } diff --git a/sonar-db/src/main/resources/org/sonar/db/component/ComponentMapper.xml b/sonar-db/src/main/resources/org/sonar/db/component/ComponentMapper.xml index 72722aa0ad0..0c2badea436 100644 --- a/sonar-db/src/main/resources/org/sonar/db/component/ComponentMapper.xml +++ b/sonar-db/src/main/resources/org/sonar/db/component/ComponentMapper.xml @@ -109,14 +109,16 @@ <select id="selectByUuids" parameterType="String" resultType="Component"> select - <include refid="componentColumns"/> + <include refid="componentColumns"/>, + o.kee as organizationKey from projects p - <where> - and p.uuid in + inner join organizations o on + o.uuid = p.organization_uuid + where + p.uuid in <foreach collection="uuids" open="(" close=")" item="uuid" separator=","> #{uuid} </foreach> - </where> </select> <select id="selectExistingUuids" parameterType="String" resultType="String"> diff --git a/sonar-db/src/test/java/org/sonar/db/component/ComponentDaoTest.java b/sonar-db/src/test/java/org/sonar/db/component/ComponentDaoTest.java index accc345bea9..91c5e13e876 100644 --- a/sonar-db/src/test/java/org/sonar/db/component/ComponentDaoTest.java +++ b/sonar-db/src/test/java/org/sonar/db/component/ComponentDaoTest.java @@ -32,6 +32,7 @@ import org.sonar.api.utils.System2; import org.sonar.db.DbSession; import org.sonar.db.DbTester; import org.sonar.db.RowNotFoundException; +import org.sonar.db.organization.OrganizationDto; import static com.google.common.collect.Lists.newArrayList; import static com.google.common.collect.Sets.newHashSet; @@ -74,6 +75,8 @@ public class ComponentDaoTest { ComponentDto result = underTest.selectByUuid(dbSession, "U1").get(); assertThat(result).isNotNull(); + assertThat(result.getOrganizationUuid()).isEqualTo("org1"); + assertThat(result.getOrganizationKey()).isNull(); assertThat(result.uuid()).isEqualTo("U1"); assertThat(result.getUuidPath()).isEqualTo("uuid_path_of_U1"); assertThat(result.moduleUuid()).isEqualTo("module_uuid_of_U1"); @@ -250,7 +253,8 @@ public class ComponentDaoTest { assertThat(results).hasSize(1); ComponentDto result = results.get(0); - assertThat(result).isNotNull(); + assertThat(result.getOrganizationUuid()).isEqualTo("org1"); + assertThat(result.getOrganizationKey()).isEqualTo("org1_key"); assertThat(result.uuid()).isEqualTo("U4"); assertThat(result.moduleUuid()).isEqualTo("module_uuid_of_U4"); assertThat(result.moduleUuidPath()).isEqualTo("module_uuid_path_of_U4"); @@ -859,8 +863,10 @@ public class ComponentDaoTest { @Test public void selectAncestors() { + // organization + OrganizationDto organization = db.organizations().insert(); // project -> module -> file - ComponentDto project = newProjectDto(PROJECT_UUID); + ComponentDto project = newProjectDto(organization, PROJECT_UUID); componentDb.insertProjectAndSnapshot(project); ComponentDto module = newModuleDto(MODULE_UUID, project); componentDb.insertComponent(module); diff --git a/sonar-db/src/test/java/org/sonar/db/organization/OrganizationDbTester.java b/sonar-db/src/test/java/org/sonar/db/organization/OrganizationDbTester.java index a4a8f5af1a9..b9d57942c4e 100644 --- a/sonar-db/src/test/java/org/sonar/db/organization/OrganizationDbTester.java +++ b/sonar-db/src/test/java/org/sonar/db/organization/OrganizationDbTester.java @@ -36,6 +36,10 @@ public class OrganizationDbTester { return insert(OrganizationTesting.newOrganizationDto()); } + public OrganizationDto insertForKey(String key) { + return insert(OrganizationTesting.newOrganizationDto().setKey(key)); + } + /** * Insert the provided {@link OrganizationDto} and commit the session */ diff --git a/sonar-db/src/test/resources/org/sonar/db/component/ComponentDaoTest/shared.xml b/sonar-db/src/test/resources/org/sonar/db/component/ComponentDaoTest/shared.xml index 604d6a81658..f3656c5ba02 100644 --- a/sonar-db/src/test/resources/org/sonar/db/component/ComponentDaoTest/shared.xml +++ b/sonar-db/src/test/resources/org/sonar/db/component/ComponentDaoTest/shared.xml @@ -1,5 +1,11 @@ <dataset> + <organizations uuid="org1" + kee="org1_key" + name="org1_name" + created_at="1000" + updated_at="1000"/> + <!-- Struts projects is authorized for all user --> <group_roles id="1" group_id="[null]" @@ -7,7 +13,6 @@ role="user" organization_uuid="org1"/> - <!-- root project --> <projects organization_uuid="org1" id="1" @@ -54,7 +59,7 @@ created_at="1228222680000" build_date="1228222680000" version="[null]" - /> + /> <snapshots id="10" uuid="u10" component_uuid="ABCD" @@ -79,7 +84,7 @@ created_at="1228136280000" build_date="1228136280000" version="[null]" - /> + /> <!-- module --> <projects organization_uuid="org1" @@ -125,7 +130,7 @@ created_at="1228222680000" build_date="1228222680000" version="[null]" - /> + /> <!-- directory --> <projects organization_uuid="org1" @@ -172,7 +177,7 @@ created_at="1228222680000" build_date="1228222680000" version="[null]" - /> + /> <!-- file --> <projects organization_uuid="org1" @@ -220,7 +225,7 @@ created_at="1228222680000" build_date="1228222680000" version="[null]" - /> + /> <!-- Disabled projects --> <projects organization_uuid="org1" |