named isInsideTransaction() should be used in named closeTx()
Prevent connection leaks: do not create new EntityManager if transaction is not active.

These newly-created EMs are not bound to thread and thus never closed.
This is also how play 1.2.x used to work: no transaction - cannot read from DB.
use JPA.DEFAULT constant, as a few lines above
simplify code: use ThreadLocal's initialValue() to greatly reduce number of null checks
use more efficient iterations and remove unused some code
Merge branch 'fix-transactions' into 1.3.x-codeborne