public final class PluginEmManager extends Object implements IPluginEmManager
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().| Constructor and Description |
|---|
PluginEmManager(javax.persistence.EntityManagerFactory factory) |
| Modifier and Type | Method and Description |
|---|---|
void |
beginTransaction()
Begins a new transation, if no transaction is currently active.
|
static void |
closeAll() |
void |
closeEntityManager()
If the
EntityManager 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 new
IBaseEntityContext 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() |
public PluginEmManager(javax.persistence.EntityManagerFactory factory)
public void beginTransaction()
IPluginEmManagerEntityManager is associated with the current thread.beginTransaction in interface IPluginEmManagerpublic void closeEntityManager()
IPluginEmManagerEntityManager associated with the current thread is open, close it. Otherwise, does nothing.closeEntityManager in interface IPluginEmManagerpublic void commit()
IPluginEmManagercommit in interface IPluginEmManagerpublic javax.persistence.EntityManager getEntityManager()
getEntityManager in interface IPluginEmManagerEntityManager associated with the current thread. If no entity manager exists yet, returns
null.public javax.persistence.EntityManager getOrCreateEntityManager()
getOrCreateEntityManager in interface IPluginEmManagerEntityManager associated with the current thread. If no entity manager exists yet, creates a
new one.public boolean isEntityDetached(Object entity)
IPluginEmManagerisEntityDetached in interface IPluginEmManagerentity - An entity to check.public boolean isTransactionActive()
isTransactionActive in interface IPluginEmManagerpublic de.xima.cmn.dao.interfaces.IBaseEntityContext newEntityContext()
IPluginEmManagerIBaseEntityContext 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.class) {}.all(null, new QueryCriteriaManager());
}
newEntityContext in interface IPluginEmManagerIBaseEntityContext that can be used with the DAO API of FORMCYCLE.public void rollback()
IPluginEmManagerrollback in interface IPluginEmManagerpublic static void closeAll()
public static void rollbackAll()
Copyright © 2020 XIMA MEDIA GmbH. All rights reserved.