You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@openjpa.apache.org by dw...@apache.org on 2010/10/13 17:30:26 UTC
svn commit: r1022142 -
/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/common/utils/AbstractTestCase.java
Author: dwoods
Date: Wed Oct 13 15:30:24 2010
New Revision: 1022142
URL: http://svn.apache.org/viewvc?rev=1022142&view=rev
Log:
add note about how created EMFs are handled and add check for null EM before using it in endEm().
Modified:
openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/common/utils/AbstractTestCase.java
Modified: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/common/utils/AbstractTestCase.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/common/utils/AbstractTestCase.java?rev=1022142&r1=1022141&r2=1022142&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/common/utils/AbstractTestCase.java (original)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/common/utils/AbstractTestCase.java Wed Oct 13 15:30:24 2010
@@ -132,12 +132,17 @@ public abstract class AbstractTestCase e
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 e
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 e
"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 e
}
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) {