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()
IPluginEmManager
EntityManager
is associated with the current thread.beginTransaction
in interface IPluginEmManager
public void closeEntityManager()
IPluginEmManager
EntityManager
associated with the current thread is open, close it. Otherwise, does nothing.closeEntityManager
in interface IPluginEmManager
public void commit()
IPluginEmManager
commit
in interface IPluginEmManager
public javax.persistence.EntityManager getEntityManager()
getEntityManager
in interface IPluginEmManager
EntityManager
associated with the current thread. If no entity manager exists yet, returns
null
.public javax.persistence.EntityManager getOrCreateEntityManager()
getOrCreateEntityManager
in interface IPluginEmManager
EntityManager
associated with the current thread. If no entity manager exists yet, creates a
new one.public boolean isEntityDetached(Object entity)
IPluginEmManager
isEntityDetached
in interface IPluginEmManager
entity
- An entity to check.public boolean isTransactionActive()
isTransactionActive
in interface IPluginEmManager
public de.xima.cmn.dao.interfaces.IBaseEntityContext newEntityContext()
IPluginEmManager
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.class) {}.all(null, new QueryCriteriaManager()); }
newEntityContext
in interface IPluginEmManager
IBaseEntityContext
that can be used with the DAO API of FORMCYCLE.public void rollback()
IPluginEmManager
rollback
in interface IPluginEmManager
public static void closeAll()
public static void rollbackAll()
Copyright © 2020 XIMA MEDIA GmbH. All rights reserved.