]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-5566 Use existing session for indexing issue permission
authorJulien Lancelot <julien.lancelot@sonarsource.com>
Fri, 12 Sep 2014 13:46:53 +0000 (15:46 +0200)
committerJulien Lancelot <julien.lancelot@sonarsource.com>
Fri, 12 Sep 2014 14:15:52 +0000 (16:15 +0200)
server/sonar-server/src/main/java/org/sonar/server/db/BaseDao.java
server/sonar-server/src/main/java/org/sonar/server/permission/InternalPermissionService.java
server/sonar-server/src/test/java/org/sonar/server/issue/index/IssueAuthorizationIndexMediumTest.java
server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ActiveRuleBackendMediumTest.java
server/sonar-server/src/test/java/org/sonar/server/search/IndexSynchronizerMediumTest.java

index 319fa934581208088589b7623a4d314cd12d0871..bb42fa775c19659bb6b456a8815e52793a93f342 100644 (file)
@@ -345,7 +345,6 @@ public abstract class BaseDao<MAPPER, DTO extends Dto<KEY>, KEY extends Serializ
     } catch (Exception e) {
       throw new IllegalStateException(e);
     }
-    session.commit();
   }
 
   private String getSynchronizeStatementFQN() {
index 8a50c76ff84fa58344bece780709269150e43451..012a77cb2692216a7819113f06218f8589622948 100644 (file)
@@ -117,11 +117,11 @@ public class InternalPermissionService implements ServerComponent {
       }
 
       permissionFacade.grantDefaultRoles(session, component.getId(), component.qualifier());
+      synchronizePermissions(session, componentKey);
       session.commit();
     } finally {
       session.close();
     }
-    synchronizePermissions(componentKey);
   }
 
   public void applyPermissionTemplate(Map<String, Object> params) {
@@ -145,7 +145,7 @@ public class InternalPermissionService implements ServerComponent {
       for (String componentKey : query.getSelectedComponents()) {
         AuthorizedComponentDto component = dbClient.componentDao().getAuthorizedComponentByKey(componentKey, session);
         permissionFacade.applyPermissionTemplate(session, query.getTemplateKey(), component.getId());
-        synchronizePermissions(componentKey);
+        synchronizePermissions(session, componentKey);
       }
       session.commit();
     } finally {
@@ -170,15 +170,16 @@ public class InternalPermissionService implements ServerComponent {
         changed = applyGroupPermissionChange(session, operation, permissionChangeQuery);
       }
       if (changed) {
+        String project = permissionChangeQuery.component();
+        if (project != null) {
+          synchronizePermissions(session, project);
+        }
         session.commit();
       }
     } finally {
       session.close();
     }
-    String project = permissionChangeQuery.component();
-    if (changed && project != null) {
-      synchronizePermissions(project);
-    }
+
   }
 
   private boolean applyGroupPermissionChange(DbSession session, String operation, PermissionChangeQuery permissionChangeQuery) {
@@ -270,16 +271,9 @@ public class InternalPermissionService implements ServerComponent {
     }
   }
 
-  private void synchronizePermissions(String projectKey) {
-    // The synchronisation cannot use an existing session, otherwise it's failing with the error :
-    // org.apache.ibatis.executor.ExecutorException: Executor was closed
-    DbSession session = dbClient.openSession(false);
-    try {
+  private void synchronizePermissions(DbSession session, String projectKey) {
       dbClient.issueAuthorizationDao().synchronizeAfter(session,
         index.get(IssueAuthorizationIndex.class).getLastSynchronization(),
         ImmutableMap.of(IssueAuthorizationDao.PROJECT_KEY, projectKey));
-    } finally {
-      session.close();
-    }
   }
 }
index 3dac0d160955285ff533524edfcd4dafc65c517b..6d3ca263618eac2190d8309cdb6461e7583a4e0a 100644 (file)
@@ -84,6 +84,7 @@ public class IssueAuthorizationIndexMediumTest {
 
     assertThat(index.getByKey(project.getKey())).isNull();
     db.issueAuthorizationDao().synchronizeAfter(session, new Date(0));
+    session.commit();
 
     IssueAuthorizationDoc issueAuthorizationDoc = index.getByKey(project.getKey());
     assertThat(issueAuthorizationDoc).isNotNull();
@@ -118,6 +119,7 @@ public class IssueAuthorizationIndexMediumTest {
     session.commit();
 
     db.issueAuthorizationDao().synchronizeAfter(session, new Date(0));
+    session.commit();
     assertThat(index.getByKey(project.getKey())).isNotNull();
 
     db.issueAuthorizationDao().deleteByKey(session, project.key());
index db00b4efd32eace5d2cf1bbfcd3252ca8b107acc..a730ff72db117d1d73eef55034480ff4e6407a0c 100644 (file)
@@ -62,20 +62,20 @@ public class ActiveRuleBackendMediumTest extends SearchMediumTest {
     db.activeRuleDao().insert(dbSession, activeRule);
     dbSession.commit();
 
-
     // 1. Synchronize since 0
     tester.clearIndexes();
     assertThat(index.get(ActiveRuleIndex.class).getByKey(activeRule.getKey())).isNull();
     db.activeRuleDao().synchronizeAfter(dbSession, new Date(0L));
+    dbSession.commit();
     assertThat(index.get(ActiveRuleIndex.class).getByKey(activeRule.getKey())).isNotNull();
 
     // 2. Synchronize since beginning
     tester.clearIndexes();
     assertThat(index.get(ActiveRuleIndex.class).getByKey(activeRule.getKey())).isNull();
     db.activeRuleDao().synchronizeAfter(dbSession, beginning);
+    dbSession.commit();
     assertThat(index.get(ActiveRuleIndex.class).getByKey(activeRule.getKey())).isNotNull();
 
-
     // 3. Assert startup picks it up
     tester.clearIndexes();
     Date before = index.get(ActiveRuleIndex.class).getLastSynchronization();
index dc45b658f5967349247af3689e8c1c6a4ad3172b..8048b57beca0f1ef123c36b4b760dc9d085a08c3 100644 (file)
@@ -63,7 +63,6 @@ public class IndexSynchronizerMediumTest {
 
   @Test
   public void can_synchronize() throws Exception {
-
     int numberOfRules = 100;
 
     for (int i = 0; i < numberOfRules; i++) {
@@ -76,6 +75,7 @@ public class IndexSynchronizerMediumTest {
     assertThat(indexClient.get(RuleIndex.class).countAll()).isEqualTo(0);
 
     synchronizer.synchronize(dbSession, dbClient.ruleDao(), indexClient.get(RuleIndex.class));
+    dbSession.commit();
     assertThat(indexClient.get(RuleIndex.class).countAll()).isEqualTo(numberOfRules);
   }
 }