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 2009/07/08 15:41:44 UTC
svn commit: r792135 -
/openjpa/trunk/openjpa-integration/validation/src/test/java/org/apache/openjpa/integration/validation/TestConstraints.java
Author: dwoods
Date: Wed Jul 8 13:41:44 2009
New Revision: 792135
URL: http://svn.apache.org/viewvc?rev=792135&view=rev
Log:
OPENJPA-1157 improved EMF cleanup
Modified:
openjpa/trunk/openjpa-integration/validation/src/test/java/org/apache/openjpa/integration/validation/TestConstraints.java
Modified: openjpa/trunk/openjpa-integration/validation/src/test/java/org/apache/openjpa/integration/validation/TestConstraints.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-integration/validation/src/test/java/org/apache/openjpa/integration/validation/TestConstraints.java?rev=792135&r1=792134&r2=792135&view=diff
==============================================================================
--- openjpa/trunk/openjpa-integration/validation/src/test/java/org/apache/openjpa/integration/validation/TestConstraints.java (original)
+++ openjpa/trunk/openjpa-integration/validation/src/test/java/org/apache/openjpa/integration/validation/TestConstraints.java Wed Jul 8 13:41:44 2009
@@ -21,6 +21,7 @@
import org.apache.openjpa.lib.log.Log;
import org.apache.openjpa.persistence.OpenJPAEntityManager;
import org.apache.openjpa.persistence.OpenJPAEntityManagerFactory;
+import org.apache.openjpa.persistence.OpenJPAEntityManagerFactorySPI;
import org.apache.openjpa.persistence.OpenJPAPersistence;
import org.apache.openjpa.persistence.test.SingleEMFTestCase;
@@ -142,8 +143,8 @@
// Part 1 - Create an invalid entity
// create our EMF w/ props
- OpenJPAEntityManagerFactory emf = OpenJPAPersistence
- .createEntityManagerFactory(
+ OpenJPAEntityManagerFactorySPI emf = (OpenJPAEntityManagerFactorySPI)
+ OpenJPAPersistence.createEntityManagerFactory(
"null-none-mode",
"org/apache/openjpa/integration/validation/persistence.xml");
assertNotNull(emf);
@@ -167,19 +168,16 @@
getLog().trace("testNullDeleteIgnored() Part 1 of 2 failed");
fail("Caught unexpected exception = " + e);
} finally {
- if ((em != null) && em.isOpen()) {
- if (em.getTransaction().isActive())
- em.getTransaction().rollback();
- em.close();
- }
- if ((emf != null) && emf.isOpen()) {
- emf.close();
+ if (em.getTransaction().isActive()) {
+ em.getTransaction().rollback();
}
+ cleanup(emf);
}
// Part 2 - Verify delete using default group does not cause Validation
// create our EMF w/ validation mode=CALLBACK
- emf = OpenJPAPersistence.createEntityManagerFactory(
+ emf = (OpenJPAEntityManagerFactorySPI)OpenJPAPersistence
+ .createEntityManagerFactory(
"null-callback-mode",
"org/apache/openjpa/integration/validation/persistence.xml");
assertNotNull(emf);
@@ -203,14 +201,10 @@
getLog().trace("testNullDeleteIgnored() Part 2 of 2 failed");
fail("Caught unexpected exception = " + e);
} finally {
- if ((em != null) && em.isOpen()) {
- if (em.getTransaction().isActive())
- em.getTransaction().rollback();
- em.close();
- }
- if ((emf != null) && emf.isOpen()) {
- emf.close();
+ if (em.getTransaction().isActive()) {
+ em.getTransaction().rollback();
}
+ cleanup(emf);
}
}
@@ -222,8 +216,8 @@
public void testNullConstraintIgnored() {
getLog().trace("testNullConstraintIgnored() started");
// create our EMF w/ props
- OpenJPAEntityManagerFactory emf = OpenJPAPersistence
- .createEntityManagerFactory(
+ OpenJPAEntityManagerFactorySPI emf = (OpenJPAEntityManagerFactorySPI)
+ OpenJPAPersistence.createEntityManagerFactory(
"null-none-mode",
"org/apache/openjpa/integration/validation/persistence.xml");
assertNotNull(emf);
@@ -247,14 +241,10 @@
getLog().trace("testNullConstraintIgnored() failed");
fail("Caught unexpected exception = " + e);
} finally {
- if ((em != null) && em.isOpen()) {
- if (em.getTransaction().isActive())
- em.getTransaction().rollback();
- em.close();
- }
- if ((emf != null) && emf.isOpen()) {
- emf.close();
+ if (em.getTransaction().isActive()) {
+ em.getTransaction().rollback();
}
+ cleanup(emf);
}
}
@@ -900,6 +890,14 @@
}
}
+ /**
+ * Helper method to remove entities and close the emf an any open em's.
+ * @param emf
+ */
+ private void cleanup(OpenJPAEntityManagerFactorySPI emf) {
+ clear(emf);
+ closeEMF(emf);
+ }
/**
* Internal convenience method for getting the OpenJPA logger