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 anEntityManager
that can be used by a plugin of typeIPluginEntities
. 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, theEntityManager
will also be closed automatically once a HTTP requests finishes. Create an instance of this class by passing it theEntityManagerFactory
instance 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 void
beginTransaction()
Begins a new transation, if no transaction is currently active.static void
closeAll()
void
closeEntityManager()
If theEntityManager
associated with the current thread is open, close it.void
commit()
If a transaction is currently active, commits it.javax.persistence.EntityManager
getEntityManager()
javax.persistence.EntityManager
getOrCreateEntityManager()
boolean
isEntityDetached(Object entity)
Checks whether a given entity is currently detached, ie not managed by the entity manager.boolean
isTransactionActive()
de.xima.cmn.dao.interfaces.IBaseEntityContext
newEntityContext()
This creates a newIBaseEntityContext
you can use to read or write plugin entities.void
rollback()
If a transaction is currently active, performs a rollback of that transaction.static void
rollbackAll()
-
-
-
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 noEntityManager
is associated with the current thread.- Specified by:
beginTransaction
in interfaceIPluginEmManager
-
closeEntityManager
public void closeEntityManager()
Description copied from interface:IPluginEmManager
If theEntityManager
associated with the current thread is open, close it. Otherwise, does nothing.- Specified by:
closeEntityManager
in interfaceIPluginEmManager
-
commit
public void commit()
Description copied from interface:IPluginEmManager
If a transaction is currently active, commits it. Otherwise, does nothing.- Specified by:
commit
in interfaceIPluginEmManager
-
getEntityManager
public javax.persistence.EntityManager getEntityManager()
- Specified by:
getEntityManager
in interfaceIPluginEmManager
- Returns:
- The
EntityManager
associated with the current thread. If no entity manager exists yet, returnsnull
.
-
getOrCreateEntityManager
public javax.persistence.EntityManager getOrCreateEntityManager()
- Specified by:
getOrCreateEntityManager
in interfaceIPluginEmManager
- 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 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:
isTransactionActive
in interfaceIPluginEmManager
- Returns:
- Whether a transaction is currently active.
-
newEntityContext
public de.xima.cmn.dao.interfaces.IBaseEntityContext newEntityContext()
Description copied from interface:IPluginEmManager
This creates a newIBaseEntityContext
you can use to read or write plugin entities. Make sure you always wrap this call in atry-with statement
to ensure it is properly closed. This will take care of closing the underlyingEntityManager
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 interfaceIPluginEmManager
- 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 interfaceIPluginEmManager
-
closeAll
public static void closeAll()
-
rollbackAll
public static void rollbackAll()
-
-