From 408da8a81f4c1eea7300bb3aeb0ddb24eafd8654 Mon Sep 17 00:00:00 2001 From: Julien Lancelot Date: Wed, 5 Feb 2014 13:02:38 +0100 Subject: [PATCH] Quality profile's copy should user a different session when reading active rules created by hibernate --- .../org/sonar/server/qualityprofile/ESActiveRule.java | 9 +++++++++ .../sonar/server/qualityprofile/QProfileOperations.java | 5 +++-- .../server/qualityprofile/QProfileOperationsTest.java | 3 +-- 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/sonar-server/src/main/java/org/sonar/server/qualityprofile/ESActiveRule.java b/sonar-server/src/main/java/org/sonar/server/qualityprofile/ESActiveRule.java index 4a1b9042e10..4de69c4035a 100644 --- a/sonar-server/src/main/java/org/sonar/server/qualityprofile/ESActiveRule.java +++ b/sonar-server/src/main/java/org/sonar/server/qualityprofile/ESActiveRule.java @@ -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); } diff --git a/sonar-server/src/main/java/org/sonar/server/qualityprofile/QProfileOperations.java b/sonar-server/src/main/java/org/sonar/server/qualityprofile/QProfileOperations.java index 8759f9a0b1f..1d123e4995a 100644 --- a/sonar-server/src/main/java/org/sonar/server/qualityprofile/QProfileOperations.java +++ b/sonar-server/src/main/java/org/sonar/server/qualityprofile/QProfileOperations.java @@ -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); } diff --git a/sonar-server/src/test/java/org/sonar/server/qualityprofile/QProfileOperationsTest.java b/sonar-server/src/test/java/org/sonar/server/qualityprofile/QProfileOperationsTest.java index 3848a6e3799..9642793fb1b 100644 --- a/sonar-server/src/test/java/org/sonar/server/qualityprofile/QProfileOperationsTest.java +++ b/sonar-server/src/test/java/org/sonar/server/qualityprofile/QProfileOperationsTest.java @@ -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 -- 2.39.5