]> source.dussan.org Git - sonarqube.git/commitdiff
Quality profile's copy should user a different session when reading active rules...
authorJulien Lancelot <julien.lancelot@sonarsource.com>
Wed, 5 Feb 2014 12:02:38 +0000 (13:02 +0100)
committerJulien Lancelot <julien.lancelot@sonarsource.com>
Wed, 5 Feb 2014 12:05:07 +0000 (13:05 +0100)
sonar-server/src/main/java/org/sonar/server/qualityprofile/ESActiveRule.java
sonar-server/src/main/java/org/sonar/server/qualityprofile/QProfileOperations.java
sonar-server/src/test/java/org/sonar/server/qualityprofile/QProfileOperationsTest.java

index 4a1b9042e10dd108fb8a116cb76753ba2049d5e0..4de69c4035aa1a00286062254c838706d34be84d 100644 (file)
@@ -88,6 +88,15 @@ public class ESActiveRule {
     }
   }
 
+  public void bulkIndexProfile(int profileId) {
+    SqlSession session = myBatis.openSession();
+    try {
+      bulkIndexProfile(profileId, session);
+    } finally {
+      MyBatis.closeQuietly(session);
+    }
+  }
+
   public void bulkIndexProfile(int profileId, SqlSession session) {
     bulkIndexActiveRules(activeRuleDao.selectByProfileId(profileId, session), session);
   }
index 8759f9a0b1f549032472d4b743179c3675178a60..1d123e4995a16debf30e723ad959a0ab7a44b3d3 100644 (file)
@@ -198,8 +198,9 @@ public class QProfileOperations implements ServerComponent {
       QualityProfileDto profileDto = findNotNull(profileId, session);
       checkNotAlreadyExists(copyProfileName, profileDto.getLanguage(), session);
       int copyProfileId = profilesManager.copyProfile(profileId, copyProfileName);
-      session.commit();
-      esActiveRule.bulkIndexProfile(copyProfileId, session);
+
+      // Cannot reuse same session as hibernate as create active rules in another session
+      esActiveRule.bulkIndexProfile(copyProfileId);
     } finally {
       MyBatis.closeQuietly(session);
     }
index 3848a6e3799e69aaaad5456ffceb7d65aef030a2..9642793fb1b2931c673a31d1112d9be358751318 100644 (file)
@@ -390,8 +390,7 @@ public class QProfileOperationsTest {
     operations.copyProfile(1, "Copy Default", authorizedUserSession);
 
     verify(profilesManager).copyProfile(1, "Copy Default");
-    verify(session).commit();
-    verify(esActiveRule).bulkIndexProfile(2, session);
+    verify(esActiveRule).bulkIndexProfile(2);
   }
 
   @Test