From 7127ab95012034fc643b743c11c466acd60391f4 Mon Sep 17 00:00:00 2001 From: Fabrice Bellingard Date: Mon, 19 Mar 2012 14:13:00 +0100 Subject: [PATCH] SONAR-1700 Some links to the projects end up in new session --- .../batch/index/DefaultResourcePersister.java | 2 ++ .../index/DefaultResourcePersisterTest.java | 11 +++++++++++ ...emoveRootIndexIfResourceIsProject-result.xml | 17 +++++++++++++++++ ...shouldRemoveRootIndexIfResourceIsProject.xml | 12 ++++++++++++ 4 files changed, 42 insertions(+) create mode 100644 sonar-batch/src/test/resources/org/sonar/batch/index/DefaultResourcePersisterTest/shouldRemoveRootIndexIfResourceIsProject-result.xml create mode 100644 sonar-batch/src/test/resources/org/sonar/batch/index/DefaultResourcePersisterTest/shouldRemoveRootIndexIfResourceIsProject.xml 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 -- 2.39.5