|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.modeshape.connector.store.jpa.EntityManagers
@ThreadSafe public class EntityManagers
Utility class that owns an EntityManagerFactory
instance and that provides references to EntityManager
instances while providing the ability to properly clean up all resources by closing the EntityManager and EntityManagerFactory
objects when no longer needed.
This class is instantiated by the JpaSource
and passed to the RepositoryConnection
objects, which use this
class to obtain an EntityManager. When the JPA connection object is closed
, it returns the
EntityManager to this object. Because this class maintains a count of the EntityManager references handed out, the last
EntityManager to be returned will cause the EntityManagerFactory to be closed.
This class does put the EntityManager implementations inside a HashMap, and therefore does expect that the EntityManager uses
object equality for equals
.
Method Summary | |
---|---|
void |
checkin(javax.persistence.EntityManager manager)
Return an EntityManager when it is no longer needed. |
javax.persistence.EntityManager |
checkout()
Check out an EntityManager instance. |
void |
close()
|
void |
closeNow()
For all opened EntityManager instances to be closed immediately, even if they are checked out. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Method Detail |
---|
public javax.persistence.EntityManager checkout()
checkin(EntityManager)
. In
fact, for every checkout()
call, there must be a corresponding checkin(EntityManager)
call with the
checked out EntityManager.
Note that this class may return the same EntityManager for multiple calls, but this should not matter to the caller.
public void checkin(javax.persistence.EntityManager manager)
checkout()
call. In fact, for every checkout()
call, there must be a
corresponding checkin(EntityManager)
call with the checked out EntityManager.
If this is the last reference to the EntityManager instance, it will be closed.
manager
- the entity manager; may not be null and must be the result of a prior checkout()
callpublic void close()
public void closeNow()
checkout
/checkin
pattern is always used.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |