Class EntityTasks
java.lang.Object
ch.tocco.nice2.persist.core.api.exec.tasks2.EntityTasks
Utility tasks usually working on
Entity
s.-
Method Summary
Modifier and TypeMethodDescriptionstatic OptionalTask
<Entity, Entity> addToRelation
(Relation relation) Sets the task entity to the relation.static OptionalTask
<String, Entity> Creates a new entity using the entity model given as argument.static NoArgPersistTask
<Entity> createEntity
(String entityName) creates a entity of the given typestatic OptionalTask
<Entity, Void> Deletes the given Entitystatic OptionalTask
<Entity, Entity> Fill all required but null values with an empty value.static OptionalTask
<Entity, EntityId> Return the entity-id of a given entity.static NoArgPersistTask
<EntityModel> getEntityModel
(String entityName) get theEntityModel
for an entity namestatic <V> OptionalTask
<Entity, V> getFieldValue
(String name, Class<V> type) Return the value of a field from an entity.static OptionalTask
<Entity, Boolean> hasRelation
(String relationName) Return `true` if the given entity has a relation with name `relationName`.static PersistTask
<Entity, Boolean> checks if the entity has the stateEntity.State.PHANTOM
static <V> PersistTask
<Entity, Boolean> isFieldNull
(String name, Class<V> type) checks if the value of the field with the given name is nullstatic OptionalTask
<Entity, Boolean> isRelationEmpty
(String relationName) Resolves and returns true if it is empty, false otherwisestatic OptionalTask
<Entity, Boolean> isStatus
(Entity.State state) Checks if the given entity has state `state`.static OptionalTask
<EntityEvent, Entity> static <E extends EntityFacadeEvent>
OptionalTask<E, Entity> static OptionalTask
<EntityId, Entity> loadById()
static PersistTask
<Long, Entity> loadByLongPk
(String entityModel) static OptionalTask
<PrimaryKey, Entity> static PersistTaskIterable
<Iterable<PrimaryKey>, Entity> load all entities from a given list of primary keys in a single querystatic OptionalTask
<SimpleEntityId, Entity> static PersistTask
<String, Entity> loadByStringPk
(String entityModel) static OptionalTask
<String, Entity> loadByUniqueId
(String entityModel) static OptionalTask
<Long, PrimaryKey> static OptionalTask
<String, PrimaryKey> pkFromString
(String entityModel) static OptionalTask
<Entity, Entity> removeFromRelation
(Relation relation) removes the task entity from a relationstatic OptionalTask
<Relation, Relation> removeRelation
(Entity target) removes the target entity from a relationstatic OptionalTask
<Entity, Entity> resolveAndRemoveRelation
(String relationName, Entity entityToSet) Resolves and removes the given entity from the relationstatic OptionalTask
<Entity, Entity> resolveAndSetLookup
(String lookupName, String uniqueId) Resolves and sets the lookup relation to a unique id.static OptionalTask
<Entity, Entity> resolveAndSetRelation
(String relationName, Entity entityToSet) Resolves and sets the relation to given entitystatic <T> OptionalTask
<Entity, Entity> resolveAndSetRelation
(String relationName, PersistTask<T, Entity> task, T argument) Resolves and sets the relation to the task result.static PersistTaskIterable
<Entity, Entity> resolveQuery
(Path relationPath) Resolves a path against the given entity.static PersistTaskIterable
<Entity, Entity> resolveQuery
(String relationPath) Resolves a path against the given entity.static OptionalTask
<Entity, EntityList> resolveQueryToList
(Path relationPath) Resolve a path against a given entity and return the result as a list of entities.static OptionalTask
<Entity, EntityList> resolveQueryToList
(String relationPath) Resolve a relation path against the given entity.static OptionalTask
<Entity, Relation> resolveRelation
(String relation) Resolves from the entity to a relation.static <V> OptionalTask
<Entity, Entity> setFieldValue
(String name, V value) Set the value on the entity and return the entity.static <V> OptionalTask
<Entity, Entity> setFieldValueByTask
(String fieldName, PersistTask<Entity, V> task) Executes a task and sets the result in the given field if the given task returns null the field won't get touched.static OptionalTask
<Relation, Entity> setLookupRelation
(String model, String uniqueId) Loads the entity with the given unique_id and sets it usingsetRelation(Entity)
.static OptionalTask
<Relation, Relation> setRelation
(Entity target) Sets the target entity to the relation.
-
Method Details
-
createEntity
Creates a new entity using the entity model given as argument. -
loadById
-
loadBySimpleId
-
loadByUniqueId
-
loadByPk
-
loadByPks
load all entities from a given list of primary keys in a single query- Parameters:
model
- the model to load- Returns:
- an iterable task that returns entitites
-
pkFromString
-
pkFromLong
-
loadByEvent
-
loadByFacadeEvent
-
loadByLongPk
-
loadByStringPk
-
getFieldValue
Return the value of a field from an entity. -
setFieldValue
Set the value on the entity and return the entity.- Parameters:
name
- the field to set the value invalue
- the value to set- Returns:
- the entity the value was set on
-
setFieldValueByTask
public static <V> OptionalTask<Entity,Entity> setFieldValueByTask(String fieldName, PersistTask<Entity, V> task) Executes a task and sets the result in the given field if the given task returns null the field won't get touched.- Returns:
- the input
Entity
-
isFieldNull
checks if the value of the field with the given name is null- Parameters:
name
- the name of the fieldtype
- the type of the field- Returns:
- true if the field is null, false otherwise
-
isStatus
Checks if the given entity has state `state`. -
isEntityDeleted
checks if the entity has the stateEntity.State.PHANTOM
- Returns:
- true if the entity is in state
Entity.State.PHANTOM
-
fillEmptyValues
Fill all required but null values with an empty value. -
hasRelation
Return `true` if the given entity has a relation with name `relationName`. -
isRelationEmpty
Resolves and returns true if it is empty, false otherwise -
resolveRelation
Resolves from the entity to a relation. -
resolveQueryToList
Resolve a relation path against the given entity. Note, unlikeEntity.resolve(String)
this also works with paths like "relA.relB" (the path must end in a relation). -
resolveQueryToList
Resolve a path against a given entity and return the result as a list of entities. -
resolveQuery
Resolves a path against the given entity. The result is converted into a iterable of entities. Note, unlikeEntity.resolve(String)
this also works with paths like "relA.relB" (the path must end in a relation). -
resolveQuery
Resolves a path against the given entity. The result is converted into a iterable of entities. Note, unlikeEntity.resolve(String)
this also works with paths like "relA.relB" (the path must end in a relation). -
setRelation
Sets the target entity to the relation. If the relation is to-1 `set` is used, and if it is to-many `add` is used. -
addToRelation
Sets the task entity to the relation. If the relation is to-1 `set` is used, and if it is to-many `add` is used.- Parameters:
relation
- relation to add to
-
removeRelation
removes the target entity from a relation- Parameters:
target
- the entity to remove
-
removeFromRelation
removes the task entity from a relation- Parameters:
relation
- the relation to remove from
-
resolveAndSetRelation
public static <T> OptionalTask<Entity,Entity> resolveAndSetRelation(String relationName, PersistTask<T, Entity> task, T argument) Resolves and sets the relation to the task result. if the given task returns null the relation won't get touched.- Returns:
- the input
Entity
-
resolveAndSetLookup
Resolves and sets the lookup relation to a unique id.- Returns:
- the input
Entity
-
resolveAndSetRelation
public static OptionalTask<Entity,Entity> resolveAndSetRelation(String relationName, Entity entityToSet) Resolves and sets the relation to given entity- Returns:
- the input
Entity
-
resolveAndRemoveRelation
public static OptionalTask<Entity,Entity> resolveAndRemoveRelation(String relationName, Entity entityToSet) Resolves and removes the given entity from the relation- Returns:
- the input
Entity
-
setLookupRelation
Loads the entity with the given unique_id and sets it usingsetRelation(Entity)
. AnIllegalStateException
will be thrown if no entity with the given unique_id exists.- Parameters:
model
- the model of the lookup entityuniqueId
- the unique_id of the entity to set- Returns:
- the source entity of the relation
-
getEntityId
Return the entity-id of a given entity. The primary must exist. -
deleteEntity
Deletes the given Entity -
createEntity
creates a entity of the given type- Parameters:
entityName
- the entity name to create- Returns:
- the created entity
-
getEntityModel
get theEntityModel
for an entity name- Parameters:
entityName
- the entity name to get the model for- Returns:
- the entity model
-