aboutsummaryrefslogtreecommitdiffstats
path: root/server/sonar-db-dao/src
diff options
context:
space:
mode:
authorLéo Geoffroy <99647462+leo-geoffroy-sonarsource@users.noreply.github.com>2022-05-16 10:55:00 +0200
committersonartech <sonartech@sonarsource.com>2022-05-16 20:03:56 +0000
commite4b1356084b1cd0502619c639bf48cbe27d445ed (patch)
tree28086b75f5e402b6d09bd6b3a6ff39a247f2960a /server/sonar-db-dao/src
parente774fdb3e5fbb4d6153b4379fc0af5606d1fcab3 (diff)
downloadsonarqube-e4b1356084b1cd0502619c639bf48cbe27d445ed.tar.gz
sonarqube-e4b1356084b1cd0502619c639bf48cbe27d445ed.zip
SONAR-16302 - Update to add mybatis automapping (#5926)
Diffstat (limited to 'server/sonar-db-dao/src')
-rw-r--r--server/sonar-db-dao/src/main/resources/org/sonar/db/rule/RuleMapper.xml49
-rw-r--r--server/sonar-db-dao/src/test/java/org/sonar/db/rule/RuleDaoTest.java26
2 files changed, 28 insertions, 47 deletions
diff --git a/server/sonar-db-dao/src/main/resources/org/sonar/db/rule/RuleMapper.xml b/server/sonar-db-dao/src/main/resources/org/sonar/db/rule/RuleMapper.xml
index 261298c4cd3..f96f6862310 100644
--- a/server/sonar-db-dao/src/main/resources/org/sonar/db/rule/RuleMapper.xml
+++ b/server/sonar-db-dao/src/main/resources/org/sonar/db/rule/RuleMapper.xml
@@ -9,9 +9,10 @@
</sql>
<sql id="selectJoinedTablesColumns">
+ rds.content as "rds_content",
rds.uuid as "rds_uuid",
rds.kee as "rds_kee",
- rds.content as "rds_content",
+
r.uuid as "r_uuid",
r.plugin_rule_key as "ruleKey",
r.plugin_name as "repositoryKey",
@@ -64,50 +65,12 @@
<include refid="leftOuterJoinRulesDescriptionSections"/>
</select>
- <resultMap id="ruleResultMap" type="org.sonar.db.rule.RuleDto">
+ <resultMap id="ruleResultMap" type="org.sonar.db.rule.RuleDto" autoMapping="true">
<id property="uuid" column="r_uuid"/>
- <result property="createdAt" column="createdAt"/>
- <result property="updatedAt" column="updatedAt"/>
- <result property="noteData" column="noteData" typeHandler="org.apache.ibatis.type.StringTypeHandler"/>
- <result property="noteUserUuid" column="noteUserUuid"/>
- <result property="noteCreatedAt" column="noteCreatedAt"/>
- <result property="noteUpdatedAt" column="noteUpdatedAt"/>
- <result property="remediationFunction" column="remediationFunction"/>
- <result property="remediationGapMultiplier" column="remediationGapMultiplier"/>
- <result property="remediationBaseEffort" column="remediationBaseEffort"/>
- <result property="tagsField" column="tagsField"/>
- <result property="adHocName" column="adHocName"/>
- <result property="adHocDescription" column="adHocDescription" typeHandler="org.apache.ibatis.type.StringTypeHandler"/>
- <result property="adHocSeverity" column="adHocSeverity"/>
- <result property="adHocType" column="adHocType"/>
-
- <result property="ruleKey" column="ruleKey"/>
- <result property="repositoryKey" column="repositoryKey"/>
- <result property="descriptionFormat" column="descriptionFormat"/>
- <result property="status" column="status"/>
- <result property="name" column="name"/>
- <result property="configKey" column="configKey"/>
- <result property="severity" column="severity"/>
- <result property="isTemplate" column="isTemplate"/>
- <result property="isExternal" column="isExternal"/>
- <result property="isAdHoc" column="isAdHoc"/>
- <result property="language" column="language"/>
- <result property="templateUuid" column="templateUuid"/>
- <result property="defRemediationFunction" column="defRemediationFunction"/>
- <result property="defRemediationGapMultiplier" column="defRemediationGapMultiplier"/>
- <result property="defRemediationBaseEffort" column="defRemediationBaseEffort"/>
- <result property="gapDescription" column="gapDescription"/>
- <result property="systemTagsField" column="systemTagsField"/>
- <result property="securityStandardsField" column="securityStandardsField"/>
- <result property="type" column="type"/>
- <result property="pluginKey" column="pluginKey"/>
- <result property="scope" column="scope"/>
-
- <collection property="ruleDescriptionSectionDtos" ofType="org.sonar.db.rule.RuleDescriptionSectionDto">
- <id property="uuid" column="rds_uuid"/>
- <result property="key" column="rds_kee"/>
- <result property="content" column="rds_content" typeHandler="org.apache.ibatis.type.StringTypeHandler"/>
+ <collection property="ruleDescriptionSectionDtos" ofType="org.sonar.db.rule.RuleDescriptionSectionDto" autoMapping="true"
+ columnPrefix="rds_">
+ <result property="key" column="kee"/>
</collection>
</resultMap>
diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/rule/RuleDaoTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/rule/RuleDaoTest.java
index 15b4249eace..e859952d32f 100644
--- a/server/sonar-db-dao/src/test/java/org/sonar/db/rule/RuleDaoTest.java
+++ b/server/sonar-db-dao/src/test/java/org/sonar/db/rule/RuleDaoTest.java
@@ -131,6 +131,25 @@ public class RuleDaoTest {
}
@Test
+ public void selectByUuidWithDifferentsValuesOfBooleans() {
+ for (int i = 0; i < 3; i++) {
+ int indexBoolean = i;
+ RuleDto ruleDto = db.rules().insert((ruleDto1 -> {
+ ruleDto1.setIsTemplate(indexBoolean == 0);
+ ruleDto1.setIsExternal(indexBoolean == 1);
+ ruleDto1.setIsAdHoc(indexBoolean == 2);
+ }));
+ RuleMetadataDto metadata = newRuleMetadata(ruleDto);
+ RuleDto expected = db.rules().insertRule(ruleDto, metadata);
+
+ assertThat(underTest.selectByUuid(expected.getUuid() + 500, db.getSession())).isEmpty();
+ RuleDto rule = underTest.selectByUuid(expected.getUuid(), db.getSession()).get();
+ assertEquals(rule, ruleDto);
+ verifyMetadata(rule.getMetadata(), metadata);
+ }
+ }
+
+ @Test
public void selectDefinitionByUuid() {
RuleDto rule = db.rules().insert();
@@ -251,6 +270,7 @@ public class RuleDaoTest {
assertThat(actual.getSeverityString()).isEqualTo(expected.getSeverityString());
assertThat(actual.isExternal()).isEqualTo(expected.isExternal());
assertThat(actual.isTemplate()).isEqualTo(expected.isTemplate());
+ assertThat(actual.isCustomRule()).isEqualTo(expected.isCustomRule());
assertThat(actual.getLanguage()).isEqualTo(expected.getLanguage());
assertThat(actual.getTemplateUuid()).isEqualTo(expected.getTemplateUuid());
assertThat(actual.getDefRemediationFunction()).isEqualTo(expected.getDefRemediationFunction());
@@ -851,15 +871,14 @@ public class RuleDaoTest {
.containsExactlyInAnyOrder(tuple(r1.getUuid(), r1.getKey()), tuple(r2.getUuid(), r2.getKey()));
Iterator<RuleForIndexingDto> it = accumulator.list.iterator();
-
assertThat(firstRule.getRepository()).isEqualTo(r1.getRepositoryKey());
assertThat(firstRule.getPluginRuleKey()).isEqualTo(r1.getRuleKey());
assertThat(firstRule.getName()).isEqualTo(r1.getName());
assertThat(firstRule.getRuleDescriptionSectionsDtos().stream()
.filter(s -> s.getKey().equals(ruleDescriptionSectionDto.getKey()))
.collect(MoreCollectors.onlyElement()))
- .usingRecursiveComparison()
- .isEqualTo(ruleDescriptionSectionDto);
+ .usingRecursiveComparison()
+ .isEqualTo(ruleDescriptionSectionDto);
assertThat(firstRule.getDescriptionFormat()).isEqualTo(r1.getDescriptionFormat());
assertThat(firstRule.getSeverity()).isEqualTo(r1.getSeverity());
assertThat(firstRule.getStatus()).isEqualTo(r1.getStatus());
@@ -910,7 +929,6 @@ public class RuleDaoTest {
.findFirst().orElseThrow();
}
-
@Test
public void scrollIndexingRulesByKeys() {
Accumulator<RuleForIndexingDto> accumulator = new Accumulator<>();