Class EntityContextFactory


  • public class EntityContextFactory
    extends Object
    • Constructor Detail

      • EntityContextFactory

        public EntityContextFactory()
    • Method Detail

      • newAnonymousEntityContext

        public static IEntityContext newAnonymousEntityContext()
      • newSystemEntityContext

        public static IEntityContext newSystemEntityContext()
      • joinedSystemEntityContext

        public static IEntityContext joinedSystemEntityContext​(javax.persistence.EntityManager em)
        Creates an entity context for the system user over an entity manager that belongs to somebody else, so legacy DAOs can write into a transaction they did not open. The returned context never commits, rolls back or closes anything, that stays the business of whoever opened the transaction, and closing it does nothing.
        Parameters:
        em - The entity manager to join. Must be open.
        Returns:
        An entity context over the given entity manager.
        Throws:
        IllegalArgumentException - if the entity manager is null.
        IllegalStateException - if the entity manager is closed.
        Since:
        8.5.6
      • reusedEntityContext

        public static IEntityContext reusedEntityContext​(IEntityContext toReuse)
        Wraps an IEntityContext and prevents it from being closed. Useful when you want to reuse another entity context, but still use the try-with-resources syntax.
        Parameters:
        toReuse - The entity context to reuse.
        Returns:
        A wrapper that prevents the entity context from being closed.
        Since:
        8.3.0