Class JpaPersistenceContextManager

  • All Implemented Interfaces:
    org.drools.persistence.api.PersistenceContextManager

    public class JpaPersistenceContextManager
    extends AbstractPersistenceContextManager
    implements org.drools.persistence.api.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.
    • Constructor Detail

      • JpaPersistenceContextManager

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

      • getApplicationScopedPersistenceContext

        public org.drools.persistence.api.PersistenceContext getApplicationScopedPersistenceContext()
        Specified by:
        getApplicationScopedPersistenceContext in interface org.drools.persistence.api.PersistenceContextManager
      • getCommandScopedPersistenceContext

        public org.drools.persistence.api.PersistenceContext getCommandScopedPersistenceContext()
        Specified by:
        getCommandScopedPersistenceContext in interface org.drools.persistence.api.PersistenceContextManager
      • beginCommandScopedEntityManager

        public void beginCommandScopedEntityManager()
        Specified by:
        beginCommandScopedEntityManager in interface org.drools.persistence.api.PersistenceContextManager