Package de.xima.fc.filter.db
Class PluginEmManager
- java.lang.Object
-
- de.xima.fc.filter.db.PluginEmManager
-
- All Implemented Interfaces:
IPluginEmManager
public final class PluginEmManager extends Object implements IPluginEmManager
A manager for anEntityManagerthat can be used by a plugin of typeIPluginEntities. It is meant to be used within the backend of formcycle, i.e. for all formcycle urls that start with/uior/portal. It takes care of creating a new entity manager when required or reusing an old one. When you use this manager, theEntityManagerwill also be closed automatically once an HTTP requests finishes. Create an instance of this class by passing it theEntityManagerFactoryinstance you received fromIPluginEntitiesParams.getEntityManagerFactory().- Author:
- XIMA MEDIA GmbH
-
-
Constructor Summary
Constructors Constructor Description PluginEmManager(javax.persistence.EntityManagerFactory factory)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidbeginTransaction()Begins a new transation, if no transaction is currently active.static voidcloseAll()voidcloseEntityManager()If theEntityManagerassociated with the current thread is open, close it.voidcommit()If a transaction is currently active, commits it.javax.persistence.EntityManagergetEntityManager()javax.persistence.EntityManagergetOrCreateEntityManager()booleanisEntityDetached(Object entity)Checks whether a given entity is currently detached, ie not managed by the entity manager.booleanisTransactionActive()de.xima.cmn.dao.interfaces.IBaseEntityContextnewEntityContext()This 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 voidrollbackAll()
-
-
-
Method Detail
-
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
public boolean isEntityDetached(Object entity)
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()
-
-