Class PluginEmManager

  • All Implemented Interfaces:
    IPluginEmManager

    public final class PluginEmManager
    extends Object
    implements IPluginEmManager
    A manager for an EntityManager that can be used by a plugin of type IPluginEntities. It is meant to be used within the backend of FORMCYCLE, ie for all FORMCYCLE urls that start with /ui or /portal. It takes care of creating a new entity manager when required or reusing an old one. When you use this manager, the EntityManager will also be closed automatically once a HTTP requests finishes. Create an instance of this class by passing it the EntityManagerFactory instance you received from IPluginEntitiesParams.getEntityManagerFactory().
    Author:
    XIMA MEDIA GmbH
    • Constructor Detail

      • PluginEmManager

        public PluginEmManager​(javax.persistence.EntityManagerFactory factory)
    • Method Detail

      • beginTransaction

        public void beginTransaction()
        Description copied from interface: IPluginEmManager
        Begins a new transation, if no transaction is currently active. Creates a new entity manager if no EntityManager is associated with the current thread.
        Specified by:
        beginTransaction in interface IPluginEmManager
      • closeEntityManager

        public void closeEntityManager()
        Description copied from interface: IPluginEmManager
        If the EntityManager associated with the current thread is open, close it. Otherwise, does nothing.
        Specified by:
        closeEntityManager in interface IPluginEmManager
      • commit

        public void commit()
        Description copied from interface: IPluginEmManager
        If a transaction is currently active, commits it. Otherwise, does nothing.
        Specified by:
        commit in interface IPluginEmManager
      • getEntityManager

        public javax.persistence.EntityManager getEntityManager()
        Specified by:
        getEntityManager in interface IPluginEmManager
        Returns:
        The EntityManager associated with the current thread. If no entity manager exists yet, returns null.
      • getOrCreateEntityManager

        public javax.persistence.EntityManager getOrCreateEntityManager()
        Specified by:
        getOrCreateEntityManager in interface IPluginEmManager
        Returns:
        The EntityManager associated with the current thread. If no entity manager exists yet, creates a new one.
      • isEntityDetached

        public boolean isEntityDetached​(Object entity)
        Description copied from interface: IPluginEmManager
        Checks whether a given entity is currently detached, ie not managed by the entity manager.
        Specified by:
        isEntityDetached in interface IPluginEmManager
        Parameters:
        entity - An entity to check.
        Returns:
        Whether the given entity is currently managed by the entity manager.
      • isTransactionActive

        public boolean isTransactionActive()
        Specified by:
        isTransactionActive in interface IPluginEmManager
        Returns:
        Whether a transaction is currently active.
      • newEntityContext

        public de.xima.cmn.dao.interfaces.IBaseEntityContext newEntityContext()
        Description copied from interface: IPluginEmManager
        This creates a new IBaseEntityContext you can use to read or write plugin entities. Make sure you always wrap this call in a try-with statement to ensure it is properly closed. This will take care of closing the underlying EntityManager at the appropriate time. Note that when you are within a backend context (eg a backend configuration menu or a portal page), the underlying entity manager is created only once for each HTTP request and reused during the request.

        You should use this method as follows:

         try (final IBaseEntityContext ec = pluginEmManager.newEntityContext()) {
           // use entity context with some DAO
           // this fetches all existing MyEntity
           new AbstractDao<MyEntity, Long, IBaseEntityContext>(MyEntity.class) {}.all(null, new QueryCriteriaManager());
         }
         
        Specified by:
        newEntityContext in interface IPluginEmManager
        Returns:
        A new IBaseEntityContext that can be used with the DAO API of FORMCYCLE.
      • rollback

        public void rollback()
        Description copied from interface: IPluginEmManager
        If a transaction is currently active, performs a rollback of that transaction. Otherwise, does nothing.
        Specified by:
        rollback in interface IPluginEmManager
      • closeAll

        public static void closeAll()
      • rollbackAll

        public static void rollbackAll()