Package de.xima.fc.filter.db
Class PluginEmManager
java.lang.Object
de.xima.fc.filter.db.PluginEmManager
- All Implemented Interfaces:
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 Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidBegins a new transation, if no transaction is currently active.static voidcloseAll()voidIf theEntityManagerassociated with the current thread is open, close it.voidcommit()If a transaction is currently active, commits it.javax.persistence.EntityManagerjavax.persistence.EntityManagerbooleanisEntityDetached(Object entity) Checks whether a given entity is currently detached, ie not managed by the entity manager.booleande.xima.cmn.dao.interfaces.IBaseEntityContextThis creates a newIBaseEntityContextyou can use to read or write plugin entities.voidrollback()If a transaction is currently active, performs a rollback of that transaction.static void
-
Constructor Details
-
PluginEmManager
public PluginEmManager(javax.persistence.EntityManagerFactory factory)
-
-
Method Details
-
beginTransaction
public void beginTransaction()Description copied from interface:IPluginEmManagerBegins a new transation, if no transaction is currently active. Creates a new entity manager if noEntityManageris associated with the current thread.- Specified by:
beginTransactionin interfaceIPluginEmManager
-
closeEntityManager
public void closeEntityManager()Description copied from interface:IPluginEmManagerIf theEntityManagerassociated with the current thread is open, close it. Otherwise, does nothing.- Specified by:
closeEntityManagerin interfaceIPluginEmManager
-
commit
public void commit()Description copied from interface:IPluginEmManagerIf a transaction is currently active, commits it. Otherwise, does nothing.- Specified by:
commitin interfaceIPluginEmManager
-
getEntityManager
public javax.persistence.EntityManager getEntityManager()- Specified by:
getEntityManagerin interfaceIPluginEmManager- Returns:
- The
EntityManagerassociated with the current thread. If no entity manager exists yet, returnsnull.
-
getOrCreateEntityManager
public javax.persistence.EntityManager getOrCreateEntityManager()- Specified by:
getOrCreateEntityManagerin interfaceIPluginEmManager- Returns:
- The
EntityManagerassociated with the current thread. If no entity manager exists yet, creates a new one.
-
isEntityDetached
Description copied from interface:IPluginEmManagerChecks whether a given entity is currently detached, ie not managed by the entity manager.- Specified by:
isEntityDetachedin interfaceIPluginEmManager- Parameters:
entity- An entity to check.- Returns:
- Whether the given entity is currently managed by the entity manager.
-
isTransactionActive
public boolean isTransactionActive()- Specified by:
isTransactionActivein interfaceIPluginEmManager- Returns:
- Whether a transaction is currently active.
-
newEntityContext
public de.xima.cmn.dao.interfaces.IBaseEntityContext newEntityContext()Description copied from interface:IPluginEmManagerThis creates a newIBaseEntityContextyou can use to read or write plugin entities. Make sure you always wrap this call in atry-with statementto ensure it is properly closed. This will take care of closing the underlyingEntityManagerat 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:
newEntityContextin interfaceIPluginEmManager- Returns:
- A new
IBaseEntityContextthat can be used with the DAO API of formcycle.
-
rollback
public void rollback()Description copied from interface:IPluginEmManagerIf a transaction is currently active, performs a rollback of that transaction. Otherwise, does nothing.- Specified by:
rollbackin interfaceIPluginEmManager
-
closeAll
public static void closeAll() -
rollbackAll
public static void rollbackAll()
-