diff options
author | Jacek <jacek.poreda@sonarsource.com> | 2020-04-17 16:39:24 +0200 |
---|---|---|
committer | sonartech <sonartech@sonarsource.com> | 2020-05-25 20:05:20 +0000 |
commit | 65e12a8ca01341c1ad00809d807bb8db0f5bf4b2 (patch) | |
tree | f180f5b44896c8d606b14483597bd0f48b5ec4d9 /server/sonar-db-dao | |
parent | 75d31b4c5df84ea9188feba72ed7dec4e558625e (diff) | |
download | sonarqube-65e12a8ca01341c1ad00809d807bb8db0f5bf4b2.tar.gz sonarqube-65e12a8ca01341c1ad00809d807bb8db0f5bf4b2.zip |
SONAR-13221 change PK to uuid of RULES_PARAMETERS table
* change rules_parameter_id of ACTIVE_RULE_PARAMETERS table to rules_parameter_uuid
Diffstat (limited to 'server/sonar-db-dao')
10 files changed, 50 insertions, 39 deletions
diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/qualityprofile/ActiveRuleDao.java b/server/sonar-db-dao/src/main/java/org/sonar/db/qualityprofile/ActiveRuleDao.java index 68e156594d0..bea2f1a725a 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/qualityprofile/ActiveRuleDao.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/qualityprofile/ActiveRuleDao.java @@ -153,7 +153,7 @@ public class ActiveRuleDao implements Dao { public ActiveRuleParamDto insertParam(DbSession dbSession, ActiveRuleDto activeRule, ActiveRuleParamDto activeRuleParam) { checkArgument(activeRule.getUuid() != null, ACTIVE_RULE_IS_NOT_PERSISTED); checkArgument(activeRuleParam.getUuid() == null, ACTIVE_RULE_PARAM_IS_ALREADY_PERSISTED); - Preconditions.checkNotNull(activeRuleParam.getRulesParameterId(), RULE_PARAM_IS_NOT_PERSISTED); + Preconditions.checkNotNull(activeRuleParam.getRulesParameterUuid(), RULE_PARAM_IS_NOT_PERSISTED); activeRuleParam.setActiveRuleUuid(activeRule.getUuid()); activeRuleParam.setUuid(uuidFactory.create()); diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/qualityprofile/ActiveRuleParamDto.java b/server/sonar-db-dao/src/main/java/org/sonar/db/qualityprofile/ActiveRuleParamDto.java index c42c89923a4..ebfcda04ff8 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/qualityprofile/ActiveRuleParamDto.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/qualityprofile/ActiveRuleParamDto.java @@ -31,7 +31,7 @@ public class ActiveRuleParamDto { private String uuid; private String activeRuleUuid; - private Integer rulesParameterId; + private String rulesParameterUuid; private String kee; private String value; @@ -53,13 +53,13 @@ public class ActiveRuleParamDto { return this; } - public Integer getRulesParameterId() { - return rulesParameterId; + public String getRulesParameterUuid() { + return rulesParameterUuid; } // TODO set private or drop - public ActiveRuleParamDto setRulesParameterId(Integer rulesParameterId) { - this.rulesParameterId = rulesParameterId; + public ActiveRuleParamDto setRulesParameterUuid(String rulesParameterUuid) { + this.rulesParameterUuid = rulesParameterUuid; return this; } @@ -87,10 +87,10 @@ public class ActiveRuleParamDto { } public static ActiveRuleParamDto createFor(RuleParamDto param) { - Preconditions.checkArgument(param.getId() != null, "Parameter is not persisted"); + Preconditions.checkArgument(param.getUuid() != null, "Parameter is not persisted"); return new ActiveRuleParamDto() .setKey(param.getName()) - .setRulesParameterId(param.getId()); + .setRulesParameterUuid(param.getUuid()); } public static Map<String, ActiveRuleParamDto> groupByKey(Collection<ActiveRuleParamDto> params) { diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/rule/RuleDao.java b/server/sonar-db-dao/src/main/java/org/sonar/db/rule/RuleDao.java index 2139c8670a7..7fa6d8a3554 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/rule/RuleDao.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/rule/RuleDao.java @@ -28,6 +28,7 @@ import javax.annotation.Nullable; import org.apache.ibatis.session.ResultHandler; import org.sonar.api.rule.RuleKey; import org.sonar.api.rules.RuleQuery; +import org.sonar.core.util.UuidFactory; import org.sonar.db.Dao; import org.sonar.db.DbSession; import org.sonar.db.RowNotFoundException; @@ -43,6 +44,12 @@ import static org.sonar.db.DatabaseUtils.executeLargeUpdates; public class RuleDao implements Dao { + private final UuidFactory uuidFactory; + + public RuleDao(UuidFactory uuidFactory) { + this.uuidFactory = uuidFactory; + } + public Optional<RuleDto> selectByKey(DbSession session, String organizationUuid, RuleKey key) { RuleDto res = mapper(session).selectByKey(organizationUuid, key); ensureOrganizationIsSet(organizationUuid, res); @@ -235,19 +242,21 @@ public class RuleDao implements Dao { public void insertRuleParam(DbSession session, RuleDefinitionDto rule, RuleParamDto param) { checkNotNull(rule.getId(), "Rule id must be set"); param.setRuleId(rule.getId()); + + param.setUuid(uuidFactory.create()); mapper(session).insertParameter(param); } public RuleParamDto updateRuleParam(DbSession session, RuleDefinitionDto rule, RuleParamDto param) { checkNotNull(rule.getId(), "Rule id must be set"); - checkNotNull(param.getId(), "Rule parameter is not yet persisted must be set"); + checkNotNull(param.getUuid(), "Rule parameter is not yet persisted must be set"); param.setRuleId(rule.getId()); mapper(session).updateParameter(param); return param; } - public void deleteRuleParam(DbSession session, int ruleParameterId) { - mapper(session).deleteParameter(ruleParameterId); + public void deleteRuleParam(DbSession session, String ruleParameterUuid) { + mapper(session).deleteParameter(ruleParameterUuid); } public Set<DeprecatedRuleKeyDto> selectAllDeprecatedRuleKeys(DbSession session) { diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/rule/RuleMapper.java b/server/sonar-db-dao/src/main/java/org/sonar/db/rule/RuleMapper.java index 308a422e4a7..8c26caa5e10 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/rule/RuleMapper.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/rule/RuleMapper.java @@ -23,9 +23,9 @@ import java.util.List; import java.util.Set; import org.apache.ibatis.annotations.Param; import org.apache.ibatis.session.ResultHandler; -import org.sonar.db.es.RuleExtensionId; import org.sonar.api.rule.RuleKey; import org.sonar.api.rules.RuleQuery; +import org.sonar.db.es.RuleExtensionId; public interface RuleMapper { @@ -85,7 +85,7 @@ public interface RuleMapper { void updateParameter(RuleParamDto param); - void deleteParameter(Integer paramId); + void deleteParameter(String paramUuid); Set<DeprecatedRuleKeyDto> selectAllDeprecatedRuleKeys(); diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/rule/RuleParamDto.java b/server/sonar-db-dao/src/main/java/org/sonar/db/rule/RuleParamDto.java index 7d35788103e..d30ad25377e 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/rule/RuleParamDto.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/rule/RuleParamDto.java @@ -28,19 +28,19 @@ import static com.google.common.base.Preconditions.checkArgument; public class RuleParamDto { - private Integer id; + private String uuid; private Integer ruleId; private String name; private String type; private String defaultValue; private String description; - public Integer getId() { - return id; + public String getUuid() { + return uuid; } - public RuleParamDto setId(Integer id) { - this.id = id; + public RuleParamDto setUuid(String uuid) { + this.uuid = uuid; return this; } diff --git a/server/sonar-db-dao/src/main/resources/org/sonar/db/qualityprofile/ActiveRuleMapper.xml b/server/sonar-db-dao/src/main/resources/org/sonar/db/qualityprofile/ActiveRuleMapper.xml index 7649914ce45..26e013c0bfb 100644 --- a/server/sonar-db-dao/src/main/resources/org/sonar/db/qualityprofile/ActiveRuleMapper.xml +++ b/server/sonar-db-dao/src/main/resources/org/sonar/db/qualityprofile/ActiveRuleMapper.xml @@ -198,7 +198,7 @@ <sql id="activeRuleParamColumns"> p.uuid, p.active_rule_uuid as activeRuleUuid, - p.rules_parameter_id as rulesParameterId, + p.rules_parameter_uuid as rulesParameterUuid, p.rules_parameter_key as kee, p.value as value </sql> @@ -207,13 +207,13 @@ insert into active_rule_parameters ( uuid, active_rule_uuid, - rules_parameter_id, + rules_parameter_uuid, rules_parameter_key, value ) values ( #{uuid, jdbcType=VARCHAR}, #{activeRuleUuid, jdbcType=VARCHAR}, - #{rulesParameterId, jdbcType=BIGINT}, + #{rulesParameterUuid, jdbcType=BIGINT}, #{key, jdbcType=VARCHAR}, #{value, jdbcType=VARCHAR} ) 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 1c976aacead..b55391d4cbc 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 @@ -461,15 +461,15 @@ and organization_uuid=#{organizationUuid,jdbcType=VARCHAR} </update> - <delete id="deleteParams" parameterType="Integer"> + <delete id="deleteParams" parameterType="String"> delete from active_rule_parameters where - rules_parameter_id=#{id,jdbcType=INTEGER} + rules_parameter_uuid=#{uuid,jdbcType=VARCHAR} </delete> <sql id="paramColumns"> - p.id as "id", + p.uuid as "uuid", p.rule_id as "ruleId", p.name as "name", p.param_type as "type", @@ -512,15 +512,16 @@ </foreach> </select> - <delete id="deleteParameter" parameterType="Integer"> + <delete id="deleteParameter" parameterType="String"> delete from rules_parameters where - id=#{id,jdbcType=INTEGER} + uuid=#{uuid,jdbcType=INTEGER} </delete> - <insert id="insertParameter" parameterType="RuleParam" keyColumn="id" useGeneratedKeys="true" keyProperty="id"> + <insert id="insertParameter" parameterType="RuleParam" useGeneratedKeys="false"> insert into rules_parameters ( + uuid, rule_id, name, param_type, @@ -528,6 +529,7 @@ description ) values ( + #{uuid,jdbcType=VARCHAR}, #{ruleId,jdbcType=INTEGER}, #{name,jdbcType=VARCHAR}, #{type,jdbcType=VARCHAR}, @@ -542,7 +544,7 @@ default_value=#{defaultValue,jdbcType=VARCHAR}, description=#{description,jdbcType=VARCHAR} where - id=#{id,jdbcType=INTEGER} + uuid=#{uuid,jdbcType=VARCHAR} </update> <select id="selectAllDeprecatedRuleKeys" resultType="org.sonar.db.rule.DeprecatedRuleKeyDto"> diff --git a/server/sonar-db-dao/src/schema/schema-sq.ddl b/server/sonar-db-dao/src/schema/schema-sq.ddl index 98df38e2973..bd57c4aec5d 100644 --- a/server/sonar-db-dao/src/schema/schema-sq.ddl +++ b/server/sonar-db-dao/src/schema/schema-sq.ddl @@ -14,11 +14,11 @@ CREATE TABLE "SCHEMA_MIGRATIONS"( ); CREATE TABLE "ACTIVE_RULE_PARAMETERS"( - "RULES_PARAMETER_ID" INTEGER NOT NULL, "VALUE" VARCHAR(4000), "RULES_PARAMETER_KEY" VARCHAR(128), "UUID" VARCHAR(40) NOT NULL, - "ACTIVE_RULE_UUID" VARCHAR(40) NOT NULL + "ACTIVE_RULE_UUID" VARCHAR(40) NOT NULL, + "RULES_PARAMETER_UUID" VARCHAR(40) NOT NULL ); ALTER TABLE "ACTIVE_RULE_PARAMETERS" ADD CONSTRAINT "PK_ACTIVE_RULE_PARAMETERS" PRIMARY KEY("UUID"); CREATE INDEX "ARP_ACTIVE_RULE_UUID" ON "ACTIVE_RULE_PARAMETERS"("ACTIVE_RULE_UUID"); @@ -852,14 +852,14 @@ CREATE TABLE "RULES_METADATA"( ALTER TABLE "RULES_METADATA" ADD CONSTRAINT "PK_RULES_METADATA" PRIMARY KEY("RULE_ID", "ORGANIZATION_UUID"); CREATE TABLE "RULES_PARAMETERS"( - "ID" INTEGER NOT NULL AUTO_INCREMENT (1,1), "RULE_ID" INTEGER NOT NULL, "NAME" VARCHAR(128) NOT NULL, "DESCRIPTION" VARCHAR(4000), "PARAM_TYPE" VARCHAR(512) NOT NULL, - "DEFAULT_VALUE" VARCHAR(4000) + "DEFAULT_VALUE" VARCHAR(4000), + "UUID" VARCHAR(40) NOT NULL ); -ALTER TABLE "RULES_PARAMETERS" ADD CONSTRAINT "PK_RULES_PARAMETERS" PRIMARY KEY("ID"); +ALTER TABLE "RULES_PARAMETERS" ADD CONSTRAINT "PK_RULES_PARAMETERS" PRIMARY KEY("UUID"); CREATE INDEX "RULES_PARAMETERS_RULE_ID" ON "RULES_PARAMETERS"("RULE_ID"); CREATE UNIQUE INDEX "RULES_PARAMETERS_UNIQUE" ON "RULES_PARAMETERS"("RULE_ID", "NAME"); diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/qualityprofile/ActiveRuleDaoTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/qualityprofile/ActiveRuleDaoTest.java index 418fc1b8efb..738d46df976 100644 --- a/server/sonar-db-dao/src/test/java/org/sonar/db/qualityprofile/ActiveRuleDaoTest.java +++ b/server/sonar-db-dao/src/test/java/org/sonar/db/qualityprofile/ActiveRuleDaoTest.java @@ -465,7 +465,7 @@ public class ActiveRuleDaoTest { .matches(p -> Objects.equals(p.getUuid(), activeRuleParam.getUuid())) .matches(p -> p.getKey().equals(activeRuleParam.getKey())) .matches(p -> p.getActiveRuleUuid().equals(activeRule.getUuid())) - .matches(p -> p.getRulesParameterId().equals(rule1Param1.getId())) + .matches(p -> p.getRulesParameterUuid().equals(rule1Param1.getUuid())) .matches(p -> p.getValue().equals("foo")); } @@ -496,7 +496,7 @@ public class ActiveRuleDaoTest { underTest.insertParam(dbSession, createFor(profile1, rule1).setUuid("uuid"), - ActiveRuleParamDto.createFor(rule1Param1).setValue("activeValue1").setRulesParameterId(null)); + ActiveRuleParamDto.createFor(rule1Param1).setValue("activeValue1").setRulesParameterUuid(null)); } @Test @@ -514,7 +514,7 @@ public class ActiveRuleDaoTest { .matches(p -> Objects.equals(p.getUuid(), activeRuleParam.getUuid())) .matches(p -> p.getKey().equals(activeRuleParam.getKey())) .matches(p -> p.getActiveRuleUuid().equals(activeRule.getUuid())) - .matches(p -> p.getRulesParameterId().equals(rule1Param1.getId())) + .matches(p -> p.getRulesParameterUuid().equals(rule1Param1.getUuid())) .matches(p -> p.getValue().equals("bar")); } 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 5fc68e9ab2d..e93569a7d1e 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 @@ -831,7 +831,7 @@ public class RuleDaoTest { assertThat(ruleDtos.size()).isEqualTo(1); RuleParamDto ruleDto = ruleDtos.get(0); - assertThat(ruleDto.getId()).isEqualTo(ruleParam.getId()); + assertThat(ruleDto.getUuid()).isEqualTo(ruleParam.getUuid()); assertThat(ruleDto.getName()).isEqualTo(ruleParam.getName()); assertThat(ruleDto.getDescription()).isEqualTo(ruleParam.getDescription()); assertThat(ruleDto.getType()).isEqualTo(ruleParam.getType()); @@ -899,7 +899,7 @@ public class RuleDaoTest { List<RuleParamDto> params = underTest.selectRuleParamsByRuleKey(db.getSession(), rule.getKey()); assertThat(params).hasSize(1); RuleParamDto param = new RuleParamDto() - .setId(ruleParam.getId()) + .setUuid(ruleParam.getUuid()) .setRuleId(rule.getId()) // Name will not be updated .setName("format") @@ -920,7 +920,7 @@ public class RuleDaoTest { RuleParamDto ruleParam = db.rules().insertRuleParam(rule); assertThat(underTest.selectRuleParamsByRuleKey(db.getSession(), rule.getKey())).hasSize(1); - underTest.deleteRuleParam(db.getSession(), ruleParam.getId()); + underTest.deleteRuleParam(db.getSession(), ruleParam.getUuid()); assertThat(underTest.selectRuleParamsByRuleKey(db.getSession(), rule.getKey())).isEmpty(); } |