]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-5618 Close session after use in ComponentDataPersister
authorJulien HENRY <julien.henry@sonarsource.com>
Thu, 11 Sep 2014 21:51:14 +0000 (23:51 +0200)
committerJulien HENRY <julien.henry@sonarsource.com>
Fri, 12 Sep 2014 07:11:12 +0000 (09:11 +0200)
sonar-batch/src/main/java/org/sonar/batch/index/ComponentDataPersister.java

index d00e4cdc84d24aa18ca2472e163209d599e329c4..f53f82675a4f9e8399e495b74ba33e06791dd2e9 100644 (file)
@@ -44,21 +44,25 @@ public class ComponentDataPersister implements ScanPersister {
   @Override
   public void persist() {
     DbSession session = mybatis.openSession(true);
-    for (Map.Entry<String, Snapshot> componentEntry : snapshots.snapshots()) {
-      String componentKey = componentEntry.getKey();
-      Snapshot snapshot = componentEntry.getValue();
-      for (Cache.Entry<Data> dataEntry : data.entries(componentKey)) {
-        Data value = dataEntry.value();
-        if (value != null) {
-          SnapshotDataDto dto = new SnapshotDataDto();
-          dto.setSnapshotId(snapshot.getId());
-          dto.setResourceId(snapshot.getResourceId());
-          dto.setDataType(dataEntry.key()[1].toString());
-          dto.setData(value.writeString());
-          dao.insert(session, dto);
+    try {
+      for (Map.Entry<String, Snapshot> componentEntry : snapshots.snapshots()) {
+        String componentKey = componentEntry.getKey();
+        Snapshot snapshot = componentEntry.getValue();
+        for (Cache.Entry<Data> dataEntry : data.entries(componentKey)) {
+          Data value = dataEntry.value();
+          if (value != null) {
+            SnapshotDataDto dto = new SnapshotDataDto();
+            dto.setSnapshotId(snapshot.getId());
+            dto.setResourceId(snapshot.getResourceId());
+            dto.setDataType(dataEntry.key()[1].toString());
+            dto.setData(value.writeString());
+            dao.insert(session, dto);
+          }
         }
       }
+      session.commit();
+    } finally {
+      MyBatis.closeQuietly(session);
     }
-    session.commit();
   }
 }