aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-core/src/main
diff options
context:
space:
mode:
authorsimonbrandhof <simon.brandhof@gmail.com>2010-12-16 14:37:26 +0000
committersimonbrandhof <simon.brandhof@gmail.com>2010-12-16 14:37:26 +0000
commit4b756e42a163a02f2bf29dca930295cfd3c5f0ea (patch)
treee84f9f32ee08d33ff9c844d5b857bca08ad75545 /sonar-core/src/main
parentca75da099a891bdc4fd4e2249deaedb0da2effc8 (diff)
downloadsonarqube-4b756e42a163a02f2bf29dca930295cfd3c5f0ea.tar.gz
sonarqube-4b756e42a163a02f2bf29dca930295cfd3c5f0ea.zip
fix memory leak : hibernate session is not correctly cleared with batch processing mode
Diffstat (limited to 'sonar-core/src/main')
-rw-r--r--sonar-core/src/main/java/org/sonar/jpa/session/JpaDatabaseSession.java13
1 files changed, 4 insertions, 9 deletions
diff --git a/sonar-core/src/main/java/org/sonar/jpa/session/JpaDatabaseSession.java b/sonar-core/src/main/java/org/sonar/jpa/session/JpaDatabaseSession.java
index 8390dd8fd6b..5a350117670 100644
--- a/sonar-core/src/main/java/org/sonar/jpa/session/JpaDatabaseSession.java
+++ b/sonar-core/src/main/java/org/sonar/jpa/session/JpaDatabaseSession.java
@@ -55,7 +55,6 @@ public class JpaDatabaseSession extends DatabaseSession {
public void stop() {
commit();
if (entityManager != null && entityManager.isOpen()) {
- entityManager.clear();
entityManager.close();
entityManager = null;
}
@@ -69,9 +68,10 @@ public class JpaDatabaseSession extends DatabaseSession {
} else {
entityManager.getTransaction().commit();
}
+ entityManager.clear();
+ index = 0;
}
inTransaction = false;
- index = 0;
}
}
@@ -79,7 +79,6 @@ public class JpaDatabaseSession extends DatabaseSession {
if (entityManager != null && inTransaction) {
entityManager.getTransaction().rollback();
inTransaction = false;
- index = 0;
}
}
@@ -110,7 +109,7 @@ public class JpaDatabaseSession extends DatabaseSession {
private void internalSave(Object model, boolean flushIfNeeded) {
entityManager.persist(model);
if (flushIfNeeded && (++index % BATCH_SIZE == 0)) {
- flush();
+ commit();
}
}
@@ -123,7 +122,7 @@ public class JpaDatabaseSession extends DatabaseSession {
startTransaction();
entityManager.remove(model);
if (++index % BATCH_SIZE == 0) {
- flush();
+ commit();
}
}
@@ -144,10 +143,6 @@ public class JpaDatabaseSession extends DatabaseSession {
}
}
- public void flush() {
- entityManager.flush();
- entityManager.clear();
- }
public Query createQuery(String hql) {
startTransaction();