Interface EntityManager
- All Known Implementing Classes:
PojoEntityManager
,TemplateEntityManager
public interface EntityManager
Provides access to entities. Each type has its own entity manager, also, the manager is
bound to the context.
Thus get it from the
persist context
.-
Method Summary
Modifier and TypeMethodDescriptionvoid
Add anEntityFacadeListener
.void
Add anEntityListener
.create()
Create a new entity (stateEntity.State.CONCEPTION
.createEntityList
(PrimaryKey... entities) createEntityList
(Entity... entities) Creates an EntityList of persistent entities of the same EntityModel.createQuery
(Collection<PrimaryKey> keys) Create a query that returns objects with known primary keys.Create aQuery
for all entities of that type.Deletes all entities of the currentEntityModel
on which the condition applies to in a single sql statement.get
(PrimaryKey key) Get an entity by a known primary key.Get an entity by unique_id field.Get the persistence context of this entity manager.getModel()
Get the entity type's model.void
Remove anEntityFacadeListener
.void
Remove anEntityListener
.@Nullable Entity
retrieve
(PrimaryKey key) Retrieve an entity by a known primary key.@Nullable Entity
Retrieve an entity by unique_id field.
-
Method Details
-
get
Get an entity by a known primary key. If the entity with the specified key isn't present, in the database, this method throws aNotFoundException
. Useretrieve(PrimaryKey)
, if you prefer a `null` value, if the entity does not exist.- Parameters:
key
- The primary key.- Returns:
- An entity facade for the entity with the specified key
- Throws:
NotFoundException
- If the entity with the specified primary key doesn't exists.- See Also:
-
retrieve
Retrieve an entity by a known primary key. Unlikeget(PrimaryKey)
, this method returnsnull
if the entity does not exist in the database or the current user has no access to the entity.- Parameters:
key
- ThePrimaryKey
of the entity.- Returns:
- The entity or
null
, if the entity does not exist or is not accessible. - Throws:
PersistException
- If an error occurs.- See Also:
-
get
Get an entity by unique_id field. Throws if entity cannot be found.- Parameters:
uniqueId
- unique id value of entity.- Returns:
- An entity facade for the entity with the specified unique_id
- See Also:
-
retrieve
Retrieve an entity by unique_id field.- Parameters:
uniqueId
- unique id value of entity.- Returns:
- The entity or
null
, if the entity does not exist or is not accessible. - See Also:
-
createQueryForAll
Query createQueryForAll()Create aQuery
for all entities of that type.- Returns:
- A query that queries all entities.
-
createQuery
Create a query that returns objects with known primary keys. Note that the results will be returned in random order unless a sorting is applied. They will not be returned in the given keys order. UseEntityLists.orderedList(ch.tocco.nice2.persist.core.api.entity.EntityList, ch.tocco.nice2.model.entity.api.PrimaryKey[])
.- Parameters:
keys
- A collection of known primary keys.- Returns:
- The executable query.
-
createEntityList
Creates an EntityList of persistent entities of the same EntityModel.- Parameters:
entities
- Must be of same EntityModel, and persistent (not conception).- Returns:
- new EntityList of given persistent entities.
- Throws:
IllegalArgumentException
- if one entity is of another EntityModel than the first, or if not at least one entity is passed, or if one is not persistent (has no key).
-
createEntityList
-
create
Entity create()Create a new entity (stateEntity.State.CONCEPTION
. The entity won't have any primary key yet and will be written into the storage when the transaction is committed.- Returns:
- The newly created entity.
-
delete
Deletes all entities of the currentEntityModel
on which the condition applies to in a single sql statement. Does not provide cascading delete. -
getModel
EntityModel getModel()Get the entity type's model.- Returns:
- The entity type's model.
-
getContext
Context getContext()Get the persistence context of this entity manager.- Returns:
- The persistence context of this entity manager.
-
addEntityListener
Add anEntityListener
.- Parameters:
l
- TheEntityListener
to be added.
-
removeEntityListener
Remove anEntityListener
.- Parameters:
l
- TheEntityListener
to be removed.
-
addEntityFacadeListener
Add anEntityFacadeListener
.- Parameters:
l
- TheEntityFacadeListener
to be added.
-
removeEntityFacadeListener
Remove anEntityFacadeListener
.- Parameters:
l
- TheEntityFacadeListener
to be removed.
-