From e807ca86b8d85d8429ea07a30507bf9b07965817 Mon Sep 17 00:00:00 2001 From: Donald Woods Date: Wed, 13 Oct 2010 15:30:24 +0000 Subject: [PATCH] add note about how created EMFs are handled and add check for null EM before using it in endEm(). git-svn-id: https://svn.apache.org/repos/asf/openjpa/trunk@1022142 13f79535-47bb-0310-9956-ffa450edef68 --- .../common/utils/AbstractTestCase.java | 20 +++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/common/utils/AbstractTestCase.java b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/common/utils/AbstractTestCase.java index 6744870cd..6f8c3dc19 100644 --- a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/common/utils/AbstractTestCase.java +++ b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/common/utils/AbstractTestCase.java @@ -132,12 +132,17 @@ public abstract class AbstractTestCase extends AbstractCachedEMFTestCase { this.props = props; } + /** + * Closes any EMFs created by getEmf() + * + */ public void tearDown() throws Exception { try { super.tearDown(); } finally { for (EntityManagerFactory emf : emfs.values()) { try { + // closeEMF() will also close any open/active EMs closeEMF(emf); emf = null; } catch (Exception e) { @@ -194,6 +199,12 @@ public abstract class AbstractTestCase extends AbstractCachedEMFTestCase { return ret; } + /** + * Creates a EMF and adds it to a Map for cleanup in tearDown() + * + * @param map + * @return + */ protected OpenJPAEntityManagerFactory getEmf(Map map) { if (map == null) map = new HashMap(); @@ -238,6 +249,11 @@ public abstract class AbstractTestCase extends AbstractCachedEMFTestCase { "SchemaAction='add,deleteTableContents')"); } + /** + * Creates a EMF and adds it to a Map for cleanup in tearDown() + * + * @return + */ protected OpenJPAEntityManagerFactory getEmf() { Map m = new HashMap(); return getEmf(m); @@ -285,10 +301,10 @@ public abstract class AbstractTestCase extends AbstractCachedEMFTestCase { } protected void endEm(EntityManager em) { - if (em.isOpen()) + if (em != null && em.isOpen()) em.close(); if (em == currentEntityManager) - currentEntityManager = null; + currentEntityManager = null; } protected Object getStackTrace(Throwable t) {