solomax commented on code in PR #218:
URL: https://github.com/apache/openjpa/pull/218#discussion_r4266394023


##########
openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/AbstractCriteriaTestCase.java:
##########
@@ -69,10 +69,73 @@ public DBDictionary getDictionary() {
 
     @Override
     public void tearDown() throws Exception {
-        dict = null;
-        super.tearDown();
+        releaseResources();
     }
 
+    /**
+     * Releases everything {@code setUp()} opened: the EntityManager, the 
audited SQL and the
+     * shared EntityManagerFactory, in that order and each step in its own 
{@code finally}, so
+     * that a failure releasing one resource cannot leave the next one open - 
an exception out
+     * of {@code em.close()} must not skip {@code emf.close()} and leak the 
whole connection
+     * pool. Every step is null-safe, because {@link #runBare()} calls {@code 
tearDown()} even
+     * when {@code setUp()} failed part way through, and the method is 
idempotent
+     * (OPENJPA-3016).
+     * <p>
+     * All three criteria base classes delegate here, so the guarantee {@link 
#runBare()}
+     * relies on holds for each of them.
+     */
+    protected final void releaseResources() throws Exception {
+        try {

Review Comment:
   maybe this "cascade" can be breaked into several private methods to improve 
readability?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to