Drools :: Persistence :: JPA 6.2.0.CR4

org.drools.persistence.jpa
Class JpaPersistenceContextManager

java.lang.Object
  extended by org.drools.persistence.jpa.AbstractPersistenceContextManager
      extended by org.drools.persistence.jpa.JpaPersistenceContextManager
All Implemented Interfaces:
PersistenceContextManager

public class JpaPersistenceContextManager
extends AbstractPersistenceContextManager
implements PersistenceContextManager

This class manages 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:
  1. One of the features made available here is the ability for the user to supply their own (Command Scoped) persistence context for use by the KieSession
  2. However, significant race-conditions arise when a Command Scoped persistence context is used in one persistent KieSession by multiple threads. In other words, when multiple threads call operations on a Singleton persistent KieSession.
This class uses ThreadLocal instances for two things:
  1. The internal Command Scoped EntityManager instance.


Field Summary
 
Fields inherited from class org.drools.persistence.jpa.AbstractPersistenceContextManager
appScopedEntityManager, cmdScopedEntityManager, emf, env, internalAppScopedEntityManagerFlag, internalCmdScopedEntityManagerFlag, txm
 
Constructor Summary
JpaPersistenceContextManager(org.kie.api.runtime.Environment env)
           
 
Method Summary
 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.
 PersistenceContext getApplicationScopedPersistenceContext()
           
 PersistenceContext getCommandScopedPersistenceContext()
           
 
Methods inherited from class org.drools.persistence.jpa.AbstractPersistenceContextManager
dispose, endCommandScopedEntityManager, getApplicationScopedEntityManager, getCommandScopedEntityManager, getInternalCommandScopedEntityManager
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.drools.persistence.PersistenceContextManager
dispose, endCommandScopedEntityManager
 

Constructor Detail

JpaPersistenceContextManager

public JpaPersistenceContextManager(org.kie.api.runtime.Environment env)
Method Detail

getApplicationScopedPersistenceContext

public PersistenceContext getApplicationScopedPersistenceContext()
Specified by:
getApplicationScopedPersistenceContext in interface PersistenceContextManager
Returns:
a PersistenceContext instance containing the Application Scoped EntityManager.

getCommandScopedPersistenceContext

public PersistenceContext getCommandScopedPersistenceContext()
Specified by:
getCommandScopedPersistenceContext in interface PersistenceContextManager
Returns:
a PersistenceContext instance containing the Command Scoped EntityManager.

beginCommandScopedEntityManager

public void beginCommandScopedEntityManager()
Description copied from interface: PersistenceContextManager
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. 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.

Specified by:
beginCommandScopedEntityManager in interface PersistenceContextManager

Drools :: Persistence :: JPA 6.2.0.CR4

Copyright © 2001-2015 JBoss by Red Hat. All Rights Reserved.