From 611d41623a6f32a9d0e9371cc4e61114ea682162 Mon Sep 17 00:00:00 2001 From: Julien Lancelot Date: Mon, 27 May 2013 12:57:06 +0200 Subject: SONAR-4301 Rename issues.resource_id by issues.component_id and issues.project_id by issues.root_component_id --- .../java/org/sonar/core/issue/db/IssueDto.java | 38 +++++++++++----------- .../core/persistence/DryRunDatabaseFactory.java | 3 +- .../java/org/sonar/core/persistence/MyBatis.java | 2 +- .../org/sonar/core/issue/db/IssueMapper.xml | 30 ++++++++--------- .../org/sonar/core/persistence/schema-h2.ddl | 6 ++-- .../resources/org/sonar/core/purge/PurgeMapper.xml | 16 ++++----- .../java/org/sonar/core/issue/db/IssueDaoTest.java | 6 ++-- .../java/org/sonar/core/issue/db/IssueDtoTest.java | 6 ++-- .../org/sonar/core/issue/db/IssueMapperTest.java | 8 ++--- .../should_find_by_project.xml | 6 ++-- .../issue/db/IssueDaoTest/should_select_all.xml | 12 +++---- .../IssueDaoTest/should_select_by_action_plans.xml | 12 +++---- .../db/IssueDaoTest/should_select_by_assigned.xml | 12 +++---- .../db/IssueDaoTest/should_select_by_component.xml | 8 ++--- .../should_select_by_component_root.xml | 8 ++--- .../should_select_by_date_creation.xml | 8 ++--- .../issue/db/IssueDaoTest/should_select_by_ids.xml | 12 +++---- .../issue/db/IssueDaoTest/should_select_by_key.xml | 4 +-- .../db/IssueDaoTest/should_select_by_planned.xml | 12 +++---- .../db/IssueDaoTest/should_select_by_query.xml | 4 +-- .../db/IssueDaoTest/should_select_by_resolved.xml | 12 +++---- .../db/IssueDaoTest/should_select_by_rules.xml | 12 +++---- .../should_select_issue_and_component_ids.xml | 12 +++---- ...hould_select_issues_for_authorized_projects.xml | 12 +++---- ...should_select_issues_return_limited_results.xml | 12 +++---- .../should_select_issues_with_sort_column.xml | 12 +++---- .../db/IssueDaoTest/should_select_open_issues.xml | 12 +++---- ...d_select_returned_sorted_result_by_assignee.xml | 12 +++---- ...select_returned_sorted_result_by_close_date.xml | 12 +++---- ...ect_returned_sorted_result_by_creation_date.xml | 12 +++---- ...d_select_returned_sorted_result_by_severity.xml | 12 +++---- ...uld_select_returned_sorted_result_by_status.xml | 12 +++---- ...elect_returned_sorted_result_by_update_date.xml | 12 +++---- .../issue/db/IssueMapperTest/testInsert-result.xml | 4 +-- .../issue/db/IssueMapperTest/testUpdate-result.xml | 4 +-- .../core/issue/db/IssueMapperTest/testUpdate.xml | 4 +-- .../should_insert_new_issues-result.xml | 4 +-- .../should_update_issues-result.xml | 4 +-- .../db/IssueStorageTest/should_update_issues.xml | 4 +-- .../should_create_database_with_issues.xml | 4 +-- .../PurgeCommandsTest/shouldDeleteResource.xml | 2 +- .../purge/PurgeDaoTest/shouldDeleteProject.xml | 4 +-- .../should_delete_all_closed_issues-result.xml | 20 ++++++------ .../should_delete_all_closed_issues.xml | 20 ++++++------ .../should_delete_old_closed_issues-result.xml | 20 ++++++------ .../should_delete_old_closed_issues.xml | 20 ++++++------ 46 files changed, 242 insertions(+), 241 deletions(-) (limited to 'sonar-core') diff --git a/sonar-core/src/main/java/org/sonar/core/issue/db/IssueDto.java b/sonar-core/src/main/java/org/sonar/core/issue/db/IssueDto.java index d6179b68b82..0d1390fd5cd 100644 --- a/sonar-core/src/main/java/org/sonar/core/issue/db/IssueDto.java +++ b/sonar-core/src/main/java/org/sonar/core/issue/db/IssueDto.java @@ -39,8 +39,8 @@ public final class IssueDto { private Long id; private String kee; - private Integer resourceId; - private Integer projectId; + private Integer componentId; + private Integer rootComponentId; private Integer ruleId; private String severity; private boolean manualSeverity; @@ -69,7 +69,7 @@ public final class IssueDto { private transient String ruleKey; private transient String ruleRepo; private transient String componentKey; - private transient String projectKey; + private transient String rootComponentKey; public Long getId() { return id; @@ -89,21 +89,21 @@ public final class IssueDto { return this; } - public Integer getResourceId() { - return resourceId; + public Integer getComponentId() { + return componentId; } - public IssueDto setResourceId(Integer resourceId) { - this.resourceId = resourceId; + public IssueDto setComponentId(Integer componentId) { + this.componentId = componentId; return this; } - public Integer getProjectId() { - return projectId; + public Integer getRootComponentId() { + return rootComponentId; } - public IssueDto setProjectId(Integer projectId) { - this.projectId = projectId; + public IssueDto setRootComponentId(Integer rootComponentId) { + this.rootComponentId = rootComponentId; return this; } @@ -300,8 +300,8 @@ public final class IssueDto { return componentKey; } - public String getProjectKey() { - return projectKey; + public String getRootComponentKey() { + return rootComponentKey; } /** @@ -324,8 +324,8 @@ public final class IssueDto { /** * Only for unit tests */ - public IssueDto setProjectKey_unit_test_only(String projectKey) { - this.projectKey = projectKey; + public IssueDto setRootComponentKey_unit_test_only(String rootComponentKey) { + this.rootComponentKey = rootComponentKey; return this; } @@ -334,7 +334,7 @@ public final class IssueDto { return ToStringBuilder.reflectionToString(this, ToStringStyle.SHORT_PREFIX_STYLE); } - public static IssueDto toDtoForInsert(DefaultIssue issue, Integer componentId, Integer projectId, Integer ruleId, Date now) { + public static IssueDto toDtoForInsert(DefaultIssue issue, Integer componentId, Integer rootComponentId, Integer ruleId, Date now) { return new IssueDto() .setKee(issue.key()) .setLine(issue.line()) @@ -348,8 +348,8 @@ public final class IssueDto { .setReporter(issue.reporter()) .setAssignee(issue.assignee()) .setRuleId(ruleId) - .setResourceId(componentId) - .setProjectId(projectId) + .setComponentId(componentId) + .setRootComponentId(rootComponentId) .setActionPlanKey(issue.actionPlanKey()) .setIssueAttributes(issue.attributes() != null ? KeyValueFormat.format(issue.attributes()) : "") .setAuthorLogin(issue.authorLogin()) @@ -397,7 +397,7 @@ public final class IssueDto { issue.setAssignee(assignee); issue.setAttributes(KeyValueFormat.parse(Objects.firstNonNull(issueAttributes, ""))); issue.setComponentKey(componentKey); - issue.setProjectKey(projectKey); + issue.setProjectKey(rootComponentKey); issue.setManualSeverity(manualSeverity); issue.setRuleKey(RuleKey.of(ruleRepo, ruleKey)); issue.setActionPlanKey(actionPlanKey); diff --git a/sonar-core/src/main/java/org/sonar/core/persistence/DryRunDatabaseFactory.java b/sonar-core/src/main/java/org/sonar/core/persistence/DryRunDatabaseFactory.java index 23bd385d1b8..196da80d360 100644 --- a/sonar-core/src/main/java/org/sonar/core/persistence/DryRunDatabaseFactory.java +++ b/sonar-core/src/main/java/org/sonar/core/persistence/DryRunDatabaseFactory.java @@ -28,6 +28,7 @@ import org.sonar.api.utils.SonarException; import javax.annotation.Nullable; import javax.sql.DataSource; + import java.io.File; import java.io.IOException; import java.sql.SQLException; @@ -80,7 +81,7 @@ public class DryRunDatabaseFactory implements ServerComponent { String snapshotCondition = "islast=" + database.getDialect().getTrueSqlValue() + " and (project_id=" + projectId + " or root_project_id=" + projectId + ")"; template .copyTable(source, dest, "projects", "(id=" + projectId + " or root_id=" + projectId + ")") - .copyTable(source, dest, "issues", "resource_id in (" + projectsConditionForIssues + ")", "status<>'" + Issue.STATUS_CLOSED + "'") + .copyTable(source, dest, "issues", "component_id in (" + projectsConditionForIssues + ")", "status<>'" + Issue.STATUS_CLOSED + "'") .copyTable(source, dest, "snapshots", snapshotCondition); } } diff --git a/sonar-core/src/main/java/org/sonar/core/persistence/MyBatis.java b/sonar-core/src/main/java/org/sonar/core/persistence/MyBatis.java index 368462b040d..542b29a7cf7 100644 --- a/sonar-core/src/main/java/org/sonar/core/persistence/MyBatis.java +++ b/sonar-core/src/main/java/org/sonar/core/persistence/MyBatis.java @@ -126,8 +126,8 @@ public class MyBatis implements BatchComponent, ServerComponent { SemaphoreMapper.class, UserMapper.class, WidgetMapper.class, WidgetPropertyMapper.class, MeasureMapper.class, SnapshotDataMapper.class, SnapshotSourceMapper.class, ActionPlanMapper.class, ActionPlanStatsMapper.class }; - loadMappers(conf, mappers); loadMapper(conf, "org.sonar.core.user.AuthorizationMapper"); + loadMappers(conf, mappers); configureLogback(mappers); sessionFactory = new SqlSessionFactoryBuilder().build(conf); diff --git a/sonar-core/src/main/resources/org/sonar/core/issue/db/IssueMapper.xml b/sonar-core/src/main/resources/org/sonar/core/issue/db/IssueMapper.xml index 318d4184650..198c1fce85f 100644 --- a/sonar-core/src/main/resources/org/sonar/core/issue/db/IssueMapper.xml +++ b/sonar-core/src/main/resources/org/sonar/core/issue/db/IssueMapper.xml @@ -7,8 +7,8 @@ i.id, i.kee as kee, - i.resource_id as resourceId, - i.project_id as projectId, + i.component_id as componentId, + i.root_component_id as rootComponentId, i.rule_id as ruleId, i.action_plan_key as actionPlanKey, i.severity as severity, @@ -31,7 +31,7 @@ r.plugin_rule_key as ruleKey, r.plugin_name as ruleRepo, p.kee as componentKey, - root.kee as projectKey + root.kee as rootComponentKey @@ -60,11 +60,11 @@ - INSERT INTO issues (kee, resource_id, project_id, rule_id, action_plan_key, severity, manual_severity, + INSERT INTO issues (kee, component_id, root_component_id, rule_id, action_plan_key, severity, manual_severity, message, line, effort_to_fix, status, resolution, checksum, reporter, assignee, author_login, issue_attributes, issue_creation_date, issue_update_date, issue_close_date, created_at, updated_at) - VALUES (#{kee}, #{resourceId}, #{projectId}, #{ruleId}, #{actionPlanKey}, #{severity}, #{manualSeverity}, + VALUES (#{kee}, #{componentId}, #{rootComponentId}, #{ruleId}, #{actionPlanKey}, #{severity}, #{manualSeverity}, #{message}, #{line}, #{effortToFix}, #{status}, #{resolution}, #{checksum}, #{reporter}, #{assignee}, #{authorLogin}, #{issueAttributes}, #{issueCreationDate}, #{issueUpdateDate}, #{issueCloseDate}, #{createdAt}, #{updatedAt}) @@ -76,11 +76,11 @@ select issues_seq.NEXTVAL from DUAL - INSERT INTO issues (id, kee, resource_id, project_id, rule_id, action_plan_key, severity, manual_severity, + INSERT INTO issues (id, kee, component_id, root_component_id, rule_id, action_plan_key, severity, manual_severity, message, line, effort_to_fix, status, resolution, checksum, reporter, assignee, author_login, issue_attributes, issue_creation_date, issue_update_date, issue_close_date, created_at, updated_at) - VALUES (#{id}, #{kee}, #{resourceId}, #{projectId}, #{ruleId}, #{actionPlanKey}, #{severity}, #{manualSeverity}, + VALUES (#{id}, #{kee}, #{componentId}, #{rootComponentId}, #{ruleId}, #{actionPlanKey}, #{severity}, #{manualSeverity}, #{message}, #{line}, #{effortToFix}, #{status}, #{resolution}, #{checksum}, #{reporter}, #{assignee}, #{authorLogin}, #{issueAttributes}, #{issueCreationDate}, #{issueUpdateDate}, #{issueCloseDate}, #{createdAt}, #{updatedAt}) @@ -115,7 +115,7 @@ select from issues i, rules r, projects p, projects root - where i.kee=#{kee} and i.rule_id=r.id and p.id=i.resource_id and i.project_id=root.id + where i.kee=#{kee} and i.rule_id=r.id and p.id=i.component_id and i.root_component_id=root.id @@ -141,8 +141,8 @@ and i.rule_id=r.id - and p.id=i.resource_id - and i.project_id=root.id + and p.id=i.component_id + and i.root_component_id=root.id @@ -164,14 +164,14 @@ from issues i - inner join () authorizedProjects on authorizedProjects.root_project_id=i.project_id + inner join () authorizedProjects on authorizedProjects.root_project_id=i.root_component_id inner join projects rootprojects on rootprojects.enabled=${_true} and rootprojects.kee in #{componentRoot} inner join snapshots rootsnapshots on rootsnapshots.project_id=rootprojects.id and rootsnapshots.islast=${_true} - inner join snapshots s on s.project_id=i.resource_id and s.islast=${_true} and + inner join snapshots s on s.project_id=i.component_id and s.islast=${_true} and (s.id=rootsnapshots.id or ((s.root_snapshot_id=rootsnapshots.id or s.root_snapshot_id=rootsnapshots.root_snapshot_id) and @@ -187,7 +187,7 @@ )) - inner join projects project_component on project_component.id=i.resource_id and project_component.enabled=${_true} and project_component.kee in + inner join projects project_component on project_component.id=i.component_id and project_component.enabled=${_true} and project_component.kee in #{component} diff --git a/sonar-core/src/main/resources/org/sonar/core/persistence/schema-h2.ddl b/sonar-core/src/main/resources/org/sonar/core/persistence/schema-h2.ddl index 80ca6029cfd..a52f49cb314 100644 --- a/sonar-core/src/main/resources/org/sonar/core/persistence/schema-h2.ddl +++ b/sonar-core/src/main/resources/org/sonar/core/persistence/schema-h2.ddl @@ -470,8 +470,8 @@ CREATE TABLE "GRAPHS" ( CREATE TABLE "ISSUES" ( "ID" INTEGER NOT NULL GENERATED BY DEFAULT AS IDENTITY (START WITH 1, INCREMENT BY 1), "KEE" VARCHAR(50) UNIQUE NOT NULL, - "RESOURCE_ID" INTEGER NOT NULL, - "PROJECT_ID" INTEGER, + "COMPONENT_ID" INTEGER NOT NULL, + "ROOT_COMPONENT_ID" INTEGER, "RULE_ID" INTEGER, "SEVERITY" VARCHAR(10), "MANUAL_SEVERITY" BOOLEAN NOT NULL, @@ -616,7 +616,7 @@ CREATE UNIQUE INDEX "GRAPHS_PERSPECTIVES" ON "GRAPHS" ("SNAPSHOT_ID", "PERSPECTI CREATE UNIQUE INDEX "ISSUES_KEE" ON "ISSUES" ("KEE"); -CREATE INDEX "ISSUES_RESOURCE_ID" ON "ISSUES" ("RESOURCE_ID"); +CREATE INDEX "ISSUES_COMPONENT_ID" ON "ISSUES" ("COMPONENT_ID"); CREATE INDEX "ISSUES_RULE_ID" ON "ISSUES" ("RULE_ID"); diff --git a/sonar-core/src/main/resources/org/sonar/core/purge/PurgeMapper.xml b/sonar-core/src/main/resources/org/sonar/core/purge/PurgeMapper.xml index 1a38dae3827..936acac2cdf 100644 --- a/sonar-core/src/main/resources/org/sonar/core/purge/PurgeMapper.xml +++ b/sonar-core/src/main/resources/org/sonar/core/purge/PurgeMapper.xml @@ -196,23 +196,23 @@ delete from issue_changes ic - where exists (select * from issues i where i.kee=ic.issue_key and i.resource_id=#{id}) + where exists (select * from issues i where i.kee=ic.issue_key and i.component_id=#{id}) delete issue_changes from issue_changes inner join issues on issue_changes.issue_key=issues.kee - where issues.resource_id=#{id} + where issues.component_id=#{id} - delete ic from issue_changes as ic, issues as i where ic.issue_key=i.kee and i.resource_id=#{id} + delete ic from issue_changes as ic, issues as i where ic.issue_key=i.kee and i.component_id=#{id} - delete from issues where resource_id=#{id} + delete from issues where component_id=#{id} @@ -220,7 +220,7 @@ delete from issue_changes ic where exists ( select * from issues i - where i.project_id=#{rootProjectId} and i.kee=ic.issue_key + where i.root_component_id=#{rootProjectId} and i.kee=ic.issue_key and i.issue_close_date is not null @@ -236,7 +236,7 @@ delete issue_changes from issue_changes inner join issues on issue_changes.issue_key=issues.kee - where issues.project_id=#{rootProjectId} + where issues.root_component_id=#{rootProjectId} and issues.issue_close_date is not null @@ -251,7 +251,7 @@ delete ic from issue_changes as ic, issues as i - where i.project_id=#{rootProjectId} + where i.root_component_id=#{rootProjectId} and ic.issue_key=i.kee @@ -265,7 +265,7 @@ delete from issues - where project_id=#{rootProjectId} + where root_component_id=#{rootProjectId} and issue_close_date is not null diff --git a/sonar-core/src/test/java/org/sonar/core/issue/db/IssueDaoTest.java b/sonar-core/src/test/java/org/sonar/core/issue/db/IssueDaoTest.java index b6a2b60cdc9..f66eb89b3ea 100644 --- a/sonar-core/src/test/java/org/sonar/core/issue/db/IssueDaoTest.java +++ b/sonar-core/src/test/java/org/sonar/core/issue/db/IssueDaoTest.java @@ -49,8 +49,8 @@ public class IssueDaoTest extends AbstractDaoTestCase { IssueDto issue = dao.selectByKey("ABCDE"); assertThat(issue.getKee()).isEqualTo("ABCDE"); assertThat(issue.getId()).isEqualTo(100L); - assertThat(issue.getResourceId()).isEqualTo(401); - assertThat(issue.getProjectId()).isEqualTo(399); + assertThat(issue.getComponentId()).isEqualTo(401); + assertThat(issue.getRootComponentId()).isEqualTo(399); assertThat(issue.getRuleId()).isEqualTo(500); assertThat(issue.getSeverity()).isEqualTo("BLOCKER"); assertThat(issue.isManualSeverity()).isFalse(); @@ -72,7 +72,7 @@ public class IssueDaoTest extends AbstractDaoTestCase { assertThat(issue.getRuleRepo()).isEqualTo("squid"); assertThat(issue.getRule()).isEqualTo("AvoidCycle"); assertThat(issue.getComponentKey()).isEqualTo("Action.java"); - assertThat(issue.getProjectKey()).isEqualTo("struts"); + assertThat(issue.getRootComponentKey()).isEqualTo("struts"); } @Test diff --git a/sonar-core/src/test/java/org/sonar/core/issue/db/IssueDtoTest.java b/sonar-core/src/test/java/org/sonar/core/issue/db/IssueDtoTest.java index 339473eb050..d57d7024ecd 100644 --- a/sonar-core/src/test/java/org/sonar/core/issue/db/IssueDtoTest.java +++ b/sonar-core/src/test/java/org/sonar/core/issue/db/IssueDtoTest.java @@ -58,9 +58,9 @@ public class IssueDtoTest { .setRuleId(1) .setRuleKey_unit_test_only("squid", "AvoidCycle") .setComponentKey_unit_test_only("org.sonar.sample:Sample") - .setProjectKey_unit_test_only("org.sonar.sample") - .setResourceId(1) - .setProjectId(1) + .setRootComponentKey_unit_test_only("org.sonar.sample") + .setComponentId(1) + .setRootComponentId(1) .setStatus(Issue.STATUS_CLOSED) .setResolution(Issue.RESOLUTION_FALSE_POSITIVE) .setEffortToFix(15.0) diff --git a/sonar-core/src/test/java/org/sonar/core/issue/db/IssueMapperTest.java b/sonar-core/src/test/java/org/sonar/core/issue/db/IssueMapperTest.java index f6844202bf3..b026bbadce6 100644 --- a/sonar-core/src/test/java/org/sonar/core/issue/db/IssueMapperTest.java +++ b/sonar-core/src/test/java/org/sonar/core/issue/db/IssueMapperTest.java @@ -39,8 +39,8 @@ public class IssueMapperTest extends AbstractDaoTestCase { @Test public void testInsert() throws Exception { IssueDto dto = new IssueDto(); - dto.setResourceId(123); - dto.setProjectId(100); + dto.setComponentId(123); + dto.setRootComponentId(100); dto.setRuleId(200); dto.setKee("ABCDE"); dto.setLine(500); @@ -73,8 +73,8 @@ public class IssueMapperTest extends AbstractDaoTestCase { setupData("testUpdate"); IssueDto dto = new IssueDto(); - dto.setResourceId(123); - dto.setProjectId(100); + dto.setComponentId(123); + dto.setRootComponentId(100); dto.setRuleId(200); dto.setKee("ABCDE"); dto.setLine(500); diff --git a/sonar-core/src/test/resources/org/sonar/core/issue/db/ActionPlanStatsDaoTest/should_find_by_project.xml b/sonar-core/src/test/resources/org/sonar/core/issue/db/ActionPlanStatsDaoTest/should_find_by_project.xml index 99469f9ac16..5ab673b9e26 100644 --- a/sonar-core/src/test/resources/org/sonar/core/issue/db/ActionPlanStatsDaoTest/should_find_by_project.xml +++ b/sonar-core/src/test/resources/org/sonar/core/issue/db/ActionPlanStatsDaoTest/should_find_by_project.xml @@ -6,7 +6,7 @@ - - - to be purged --> do not purge --> to be purged --> do not purge --> do not purge -->