From: Fabrice Bellingard Date: Mon, 19 Mar 2012 13:13:00 +0000 (+0100) Subject: SONAR-1700 Some links to the projects end up in new session X-Git-Tag: 3.0~173^2 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=7127ab95012034fc643b743c11c466acd60391f4;p=sonarqube.git SONAR-1700 Some links to the projects end up in new session --- diff --git a/sonar-batch/src/main/java/org/sonar/batch/index/DefaultResourcePersister.java b/sonar-batch/src/main/java/org/sonar/batch/index/DefaultResourcePersister.java index a6f736eea56..0917fa776b2 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/index/DefaultResourcePersister.java +++ b/sonar-batch/src/main/java/org/sonar/batch/index/DefaultResourcePersister.java @@ -72,6 +72,8 @@ public final class DefaultResourcePersister implements ResourcePersister { // assume that the parent project has already been saved parentSnapshot = snapshotsByResource.get(project.getParent()); model.setRootId((Integer) ObjectUtils.defaultIfNull(parentSnapshot.getRootProjectId(), parentSnapshot.getResourceId())); + } else { + model.setRootId(null); } model = session.save(model); project.setId(model.getId()); diff --git a/sonar-batch/src/test/java/org/sonar/batch/index/DefaultResourcePersisterTest.java b/sonar-batch/src/test/java/org/sonar/batch/index/DefaultResourcePersisterTest.java index a8b7e4d986b..c85ca8a895f 100644 --- a/sonar-batch/src/test/java/org/sonar/batch/index/DefaultResourcePersisterTest.java +++ b/sonar-batch/src/test/java/org/sonar/batch/index/DefaultResourcePersisterTest.java @@ -137,4 +137,15 @@ public class DefaultResourcePersisterTest extends AbstractDbUnitTestCase { checkTablesWithExcludedColumns("shouldUpdateExistingResource", new String[]{"build_date"}, "projects", "snapshots"); } + // SONAR-1700 + @Test + public void shouldRemoveRootIndexIfResourceIsProject() { + setupData("shouldRemoveRootIndexIfResourceIsProject"); + + ResourcePersister persister = new DefaultResourcePersister(getSession()); + persister.saveProject(singleProject, null); + + checkTablesWithExcludedColumns("shouldRemoveRootIndexIfResourceIsProject", new String[]{"build_date"}, "projects", "snapshots"); + } + } diff --git a/sonar-batch/src/test/resources/org/sonar/batch/index/DefaultResourcePersisterTest/shouldRemoveRootIndexIfResourceIsProject-result.xml b/sonar-batch/src/test/resources/org/sonar/batch/index/DefaultResourcePersisterTest/shouldRemoveRootIndexIfResourceIsProject-result.xml new file mode 100644 index 00000000000..147b3c37abf --- /dev/null +++ b/sonar-batch/src/test/resources/org/sonar/batch/index/DefaultResourcePersisterTest/shouldRemoveRootIndexIfResourceIsProject-result.xml @@ -0,0 +1,17 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/sonar-batch/src/test/resources/org/sonar/batch/index/DefaultResourcePersisterTest/shouldRemoveRootIndexIfResourceIsProject.xml b/sonar-batch/src/test/resources/org/sonar/batch/index/DefaultResourcePersisterTest/shouldRemoveRootIndexIfResourceIsProject.xml new file mode 100644 index 00000000000..56b2ab204d2 --- /dev/null +++ b/sonar-batch/src/test/resources/org/sonar/batch/index/DefaultResourcePersisterTest/shouldRemoveRootIndexIfResourceIsProject.xml @@ -0,0 +1,12 @@ + + + + + + + + \ No newline at end of file