public class JpaPersistenceContextManager extends Object implements PersistenceContextManager
JpaPersistenceContext
objects, and the underlying persistence context (EntityManager
)
instances for a persistent KieSession
and other infrastructure classes that use persistence in KIE projects.
(For reference in the following documentation: the EntityManager
is the class used to represent a persistence context)
There are 2 issues to take into account when looking at or modifying the code here: KieSession
KieSession
by multiple threads. In other words, when multiple threads call operations on a Singleton persistent
KieSession
.ThreadLocal
instances for two things:EntityManager
instance.Modifier and Type | Field and Description |
---|---|
protected org.kie.api.runtime.Environment |
env |
protected ThreadLocal<javax.persistence.EntityManager> |
localInternalCmdScopedEntityManager |
Constructor and Description |
---|
JpaPersistenceContextManager(org.kie.api.runtime.Environment env) |
Modifier and Type | Method and Description |
---|---|
void |
beginCommandScopedEntityManager()
This method should be called at the beginning of a
CommandExecutor.execute(org.kie.api.command.Command) method,
when the given CommandService instance is responsible for handling persistence. |
void |
dispose()
Executes the necessary actions in order to clean up and dispose of the internal fields of this instance.
|
void |
endCommandScopedEntityManager()
This method should only called in the
Synchronization.afterCompletion(int) method. |
PersistenceContext |
getApplicationScopedPersistenceContext() |
PersistenceContext |
getCommandScopedPersistenceContext() |
protected javax.persistence.EntityManager |
getInternalCommandScopedEntityManager()
Getter / Setter methods for the Command Scoped
EntityManager |
protected void |
setInternalCommandScopedEntityManager(javax.persistence.EntityManager entityManager) |
protected final org.kie.api.runtime.Environment env
protected final ThreadLocal<javax.persistence.EntityManager> localInternalCmdScopedEntityManager
public JpaPersistenceContextManager(org.kie.api.runtime.Environment env)
public PersistenceContext getApplicationScopedPersistenceContext()
getApplicationScopedPersistenceContext
in interface PersistenceContextManager
PersistenceContext
instance containing the Application Scoped EntityManager
.public PersistenceContext getCommandScopedPersistenceContext()
getCommandScopedPersistenceContext
in interface PersistenceContextManager
PersistenceContext
instance containing the Command Scoped EntityManager
.public void beginCommandScopedEntityManager()
PersistenceContextManager
CommandExecutor.execute(org.kie.api.command.Command)
method,
when the given CommandService
instance is responsible for handling persistence.
See the SingleSessionCommandService
class.
The first responsibility of this method is to make sure that the Command Scoped EntityManager
(CSEM) joins
the ongoing transaction.
When the CSEM is internally managed, this method is also responsible for creating a new CSEM for use during execution
of the Command
or operation being executed by the KieSession
.beginCommandScopedEntityManager
in interface PersistenceContextManager
public void endCommandScopedEntityManager()
PersistenceContextManager
Synchronization.afterCompletion(int)
method.
It is responsible for cleaning up the Command Scoped EntityManager
(CSEM) instance, but only when
the CSEM is an internal one, and not one supplied (and managed) by the user.
If the CSEM is (internally) managed, then this method will take the necessary actions in order to make sure that a
new CSEM can be generated at the beginning of the next operation or command on the persistent KieSession
.
if the CSEM is supplied (and managed) by the user, this method will do nothing with the CSEM.endCommandScopedEntityManager
in interface PersistenceContextManager
public void dispose()
PersistenceContextManager
dispose
in interface PersistenceContextManager
protected javax.persistence.EntityManager getInternalCommandScopedEntityManager()
EntityManager
protected void setInternalCommandScopedEntityManager(javax.persistence.EntityManager entityManager)
Copyright © 2001-2014 JBoss by Red Hat. All Rights Reserved.