aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-db
diff options
context:
space:
mode:
authorJulien Lancelot <julien.lancelot@sonarsource.com>2016-08-22 18:45:37 +0200
committerJulien Lancelot <julien.lancelot@sonarsource.com>2016-08-25 11:29:40 +0200
commitf4d9bd4f139e9300dc08adceb370b660b1ec220b (patch)
tree1cc1e6fcca5a7afa96d14fe323a2954b3e965a81 /sonar-db
parent8aa475de8bfa06cd991f02589c03a65df7bb397f (diff)
downloadsonarqube-f4d9bd4f139e9300dc08adceb370b660b1ec220b.tar.gz
sonarqube-f4d9bd4f139e9300dc08adceb370b660b1ec220b.zip
SONAR-7975 Return inherited values in /api/settings/values for modules
Diffstat (limited to 'sonar-db')
-rw-r--r--sonar-db/src/main/java/org/sonar/db/property/PropertiesDao.java9
-rw-r--r--sonar-db/src/main/java/org/sonar/db/property/PropertiesMapper.java2
-rw-r--r--sonar-db/src/main/resources/org/sonar/db/property/PropertiesMapper.xml16
-rw-r--r--sonar-db/src/test/java/org/sonar/db/property/PropertiesDaoTest.java47
4 files changed, 67 insertions, 7 deletions
diff --git a/sonar-db/src/main/java/org/sonar/db/property/PropertiesDao.java b/sonar-db/src/main/java/org/sonar/db/property/PropertiesDao.java
index 140d7edf142..38683018c91 100644
--- a/sonar-db/src/main/java/org/sonar/db/property/PropertiesDao.java
+++ b/sonar-db/src/main/java/org/sonar/db/property/PropertiesDao.java
@@ -168,12 +168,17 @@ public class PropertiesDao implements Dao {
return selectByKeys(session, keys, null);
}
- public List<PropertyDto> selectComponentPropertiesByKeys(DbSession session, Set<String> keys, long componentId) {
+ public List<PropertyDto> selectPropertiesByKeysAndComponentId(DbSession session, Set<String> keys, long componentId) {
return selectByKeys(session, keys, componentId);
}
+ public List<PropertyDto> selectPropertiesByKeysAndComponentIds(DbSession session, Set<String> keys, Set<Long> componentIds) {
+ return executeLargeInputs(keys, partitionKeys -> executeLargeInputs(componentIds,
+ partitionComponentIds -> session.getMapper(PropertiesMapper.class).selectByKeysAndComponentIds(partitionKeys, partitionComponentIds)));
+ }
+
private List<PropertyDto> selectByKeys(DbSession session, Set<String> keys, @Nullable Long componentId) {
- return executeLargeInputs(keys, propertyKeys -> session.getMapper(PropertiesMapper.class).selectByKeys(propertyKeys, componentId));
+ return executeLargeInputs(keys, partitionKeys -> session.getMapper(PropertiesMapper.class).selectByKeys(partitionKeys, componentId));
}
public void insertProperty(DbSession session, PropertyDto property) {
diff --git a/sonar-db/src/main/java/org/sonar/db/property/PropertiesMapper.java b/sonar-db/src/main/java/org/sonar/db/property/PropertiesMapper.java
index e8ef34a84da..781c1ecb79e 100644
--- a/sonar-db/src/main/java/org/sonar/db/property/PropertiesMapper.java
+++ b/sonar-db/src/main/java/org/sonar/db/property/PropertiesMapper.java
@@ -41,6 +41,8 @@ public interface PropertiesMapper {
List<PropertyDto> selectByKeys(@Param("keys") List<String> keys, @Nullable @Param("componentId") Long componentId);
+ List<PropertyDto> selectByKeysAndComponentIds(@Param("keys") List<String> keys, @Param("componentIds") List<Long> componentIds);
+
List<PropertyDto> selectByQuery(@Param("query") PropertyQuery query);
List<PropertyDto> selectDescendantModuleProperties(@Param("moduleUuid") String moduleUuid, @Param(value = "scope") String scope,
diff --git a/sonar-db/src/main/resources/org/sonar/db/property/PropertiesMapper.xml b/sonar-db/src/main/resources/org/sonar/db/property/PropertiesMapper.xml
index a64c3756236..6c8f3d3336a 100644
--- a/sonar-db/src/main/resources/org/sonar/db/property/PropertiesMapper.xml
+++ b/sonar-db/src/main/resources/org/sonar/db/property/PropertiesMapper.xml
@@ -99,6 +99,22 @@
</where>
</select>
+ <select id="selectByKeysAndComponentIds" parameterType="map" resultType="Property">
+ SELECT p.id as id, p.prop_key as "key", p.text_value as value, p.resource_id as resourceId, p.user_id as userId
+ FROM properties p
+ <where>
+ AND p.prop_key in
+ <foreach collection="keys" open="(" close=")" item="key" separator=",">
+ #{key}
+ </foreach>
+ AND p.resource_id in
+ <foreach collection="componentIds" open="(" close=")" item="componentId" separator=",">
+ #{componentId}
+ </foreach>
+ AND p.user_id is null
+ </where>
+ </select>
+
<select id="selectByQuery" parameterType="map" resultType="Property">
select p.id as id, p.prop_key as "key", p.text_value as value, p.resource_id as resourceId, p.user_id as userId
from properties p
diff --git a/sonar-db/src/test/java/org/sonar/db/property/PropertiesDaoTest.java b/sonar-db/src/test/java/org/sonar/db/property/PropertiesDaoTest.java
index 60fcf5edcb1..e4c3b695dfe 100644
--- a/sonar-db/src/test/java/org/sonar/db/property/PropertiesDaoTest.java
+++ b/sonar-db/src/test/java/org/sonar/db/property/PropertiesDaoTest.java
@@ -21,6 +21,7 @@ package org.sonar.db.property;
import com.google.common.collect.ImmutableMap;
import java.util.List;
+import org.assertj.core.groups.Tuple;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
@@ -242,12 +243,48 @@ public class PropertiesDaoTest {
newUserPropertyDto(user).setKey(key),
newComponentPropertyDto(project).setKey(anotherKey));
- assertThat(dao.selectComponentPropertiesByKeys(session, newHashSet(key), project.getId())).extracting("key").containsOnly(key);
- assertThat(dao.selectComponentPropertiesByKeys(session, newHashSet(key, anotherKey), project.getId())).extracting("key").containsOnly(key, anotherKey);
- assertThat(dao.selectComponentPropertiesByKeys(session, newHashSet(key, anotherKey, "unknown"), project.getId())).extracting("key").containsOnly(key, anotherKey);
+ assertThat(dao.selectPropertiesByKeysAndComponentId(session, newHashSet(key), project.getId())).extracting("key").containsOnly(key);
+ assertThat(dao.selectPropertiesByKeysAndComponentId(session, newHashSet(key, anotherKey), project.getId())).extracting("key").containsOnly(key, anotherKey);
+ assertThat(dao.selectPropertiesByKeysAndComponentId(session, newHashSet(key, anotherKey, "unknown"), project.getId())).extracting("key").containsOnly(key, anotherKey);
- assertThat(dao.selectComponentPropertiesByKeys(session, newHashSet("unknown"), project.getId())).isEmpty();
- assertThat(dao.selectComponentPropertiesByKeys(session, newHashSet(key), 123456789L)).isEmpty();
+ assertThat(dao.selectPropertiesByKeysAndComponentId(session, newHashSet("unknown"), project.getId())).isEmpty();
+ assertThat(dao.selectPropertiesByKeysAndComponentId(session, newHashSet(key), 123456789L)).isEmpty();
+ }
+
+ @Test
+ public void select_properties_by_keys_and_component_ids() throws Exception {
+ ComponentDto project = ComponentTesting.newProjectDto();
+ dbClient.componentDao().insert(session, project);
+ ComponentDto project2 = ComponentTesting.newProjectDto();
+ dbClient.componentDao().insert(session, project2);
+
+ UserDto user = UserTesting.newUserDto();
+ dbClient.userDao().insert(session, user);
+
+ String key = "key";
+ String anotherKey = "anotherKey";
+ insertProperties(
+ newGlobalPropertyDto().setKey(key),
+ newComponentPropertyDto(project).setKey(key),
+ newComponentPropertyDto(project2).setKey(key),
+ newComponentPropertyDto(project2).setKey(anotherKey),
+ newUserPropertyDto(user).setKey(key));
+
+ assertThat(dao.selectPropertiesByKeysAndComponentIds(session, newHashSet(key), newHashSet(project.getId())))
+ .extracting("key", "resourceId").containsOnly(Tuple.tuple(key, project.getId()));
+ assertThat(dao.selectPropertiesByKeysAndComponentIds(session, newHashSet(key), newHashSet(project.getId(), project2.getId())))
+ .extracting("key", "resourceId").containsOnly(
+ Tuple.tuple(key, project.getId()),
+ Tuple.tuple(key, project2.getId()));
+ assertThat(dao.selectPropertiesByKeysAndComponentIds(session, newHashSet(key, anotherKey), newHashSet(project.getId(), project2.getId())))
+ .extracting("key", "resourceId").containsOnly(
+ Tuple.tuple(key, project.getId()),
+ Tuple.tuple(key, project2.getId()),
+ Tuple.tuple(anotherKey, project2.getId()));
+
+ assertThat(dao.selectPropertiesByKeysAndComponentIds(session, newHashSet("unknown"), newHashSet(project.getId()))).isEmpty();
+ assertThat(dao.selectPropertiesByKeysAndComponentIds(session, newHashSet("key"), newHashSet(123456789L))).isEmpty();
+ assertThat(dao.selectPropertiesByKeysAndComponentIds(session, newHashSet("unknown"), newHashSet(123456789L))).isEmpty();
}
@Test