Class Entities
java.lang.Object
ch.tocco.nice2.persist.core.api.entity.Entities
Static methods for dealing with
entities.-
Nested Class Summary
Nested Classes -
Method Summary
Modifier and TypeMethodDescriptionstatic voidclearFields(Entity entity) Set every field to null or empty value except keys if possible.static voidcopyFields(Entity sourceEntity, Entity targetEntity) Copies the field values of the source to the target.static voidcopyFields(Entity sourceEntity, Entity targetEntity, @Nullable List<String> excludedFields) static voidcopyRelationReference(Entity sourceEntity, Entity targetEntity, String relationName) Copies the relation reference from source onto target entity.static voidcopyRelations(Entity sourceEntity, Entity targetEntity) Copy relations (relation references) from source entity to target entity.static voidcopyRelations(Entity sourceEntity, Entity targetEntity, Set<String> excludedRelationNames) Copy relations (relation references) from source entity to target entity.static EntitycreateCopy(Entity sourceEntity) Same ascreateCopy(Entity, EntityManager).static EntitycreateCopy(Entity sourceEntity, EntityManager eManager) Creates a new entity based on the given one without storing it (State=CONCEPTION).static EntitycreateCopy(Entity sourceEntity, EntityManager eManager, @Nullable List<String> excludedFields) static voiddeleteEntities(EntityList listWithEntitiesToDelete) Deletes all entities in supplied entity liststatic EntitynullCounterEntity(Entity entity) Wraps the entity so that it forgets all values of counter fields.static EntitynullKeyEntity(Entity entity) Wraps the entity so that it forgets all about its existing Primary Key.static EntityListresolvePathToEntityList(Entity entity, String pathString) Deprecated.static EntityListresolvePathToEntityListWithoutLastStep(Entity entity, Path path, QueryBuilderFactory queryBuilderFactory) Resolve a path without it's last step to an entity list.static @Nullable TypedValue<?> resolvePathToFieldValue(Entity entity, String pathString) Deprecated.static EntityListresolvePathWithCondition(EntityList baseEntities, String path, @Nullable String condition, QueryBuilderFactory queryBuilderFactory, Context context) Resolve a path applying a condition to the "last step"static EntityresolvePathWithoutLastStep(Entity entity, Path path) Deprecated.static @Nullable EntityresolvePathWithoutLastStepOrNull(Entity entity, Path path) Deprecated.static Entities.ReversePathreversePath(EntityModel entityModel, Path path) Reverse a pathstatic Entities.ReversePathreversePathWithoutLastStep(EntityModel entityModel, Path path) Reverse a path without the last stepstatic EntityunmodifiableEntity(Entity entity) Wraps the entity to be unmodifiable.static EntitywrapForCopy(Entity entity) Wraps the entity so that primary key and counter info is nullified, and makes it unmodifiable.
-
Method Details
-
unmodifiableEntity
Wraps the entity to be unmodifiable. -
nullKeyEntity
Wraps the entity so that it forgets all about its existing Primary Key. -
nullCounterEntity
Wraps the entity so that it forgets all values of counter fields. -
createCopy
Creates a new entity based on the given one without storing it (State=CONCEPTION).Info: Fields part of the Primary key are ignored as well as fields of type counter.
Limits: Relations are not copied. Obviously. Such a method would have to store everything. Does not call fillNonNullable(), you may or may not have to do that, probably depends on the source if it was complete or not.
- Parameters:
sourceEntity- The source of data, won't be modified.- Returns:
- The newly in-memory created entity in conception state.
-
createCopy
Same ascreateCopy(Entity, EntityManager). Uses theEntityManagerof the given entity.- See Also:
-
createCopy
public static Entity createCopy(Entity sourceEntity, EntityManager eManager, @Nullable @Nullable List<String> excludedFields) -
wrapForCopy
Wraps the entity so that primary key and counter info is nullified, and makes it unmodifiable.- Parameters:
entity- The source entity, won't be modified.- Returns:
- The wrapper containing the source.
-
copyFields
Copies the field values of the source to the target.WARNING: All values are copied over, including pk fields!
Limits: Relations are not copied. Obviously. Such a method would have to store everything. Does not call fillNonNullable(), you may or may not have to do that, probably depends on the source if it was complete or not.
- Parameters:
sourceEntity- The source of data, won't be modified.targetEntity- The entity where all field values will be overridden.
-
copyFields
-
clearFields
Set every field to null or empty value except keys if possible. -
copyRelations
Copy relations (relation references) from source entity to target entity.- Parameters:
sourceEntity- The entity to copy the relation references from.targetEntity- The entity to copy the relation references to.
-
copyRelations
public static void copyRelations(Entity sourceEntity, Entity targetEntity, Set<String> excludedRelationNames) Copy relations (relation references) from source entity to target entity.- Parameters:
sourceEntity- The entity to copy the relation references from.targetEntity- The entity to copy the relation references to.excludedRelationNames- The relations to ignore and skip.
-
copyRelationReference
public static void copyRelationReference(Entity sourceEntity, Entity targetEntity, String relationName) Copies the relation reference from source onto target entity.This method relates the same entity, it does not create a copy of the linked entity.
-
resolvePathToFieldValue
@Deprecated @Nullable public static @Nullable TypedValue<?> resolvePathToFieldValue(Entity entity, String pathString) throws NoEntityToLoadException Deprecated.Resolve a path of relations to a single field value. All relations on the path may only be n:1 relations.- Parameters:
entity- the starting entitypathString- a string containing an arbitrary path to follow from the starting entity- Returns:
- the field value corresponding to the specified path
- Throws:
NoEntityToLoadException
-
resolvePathToEntityList
@Deprecated public static EntityList resolvePathToEntityList(Entity entity, String pathString) throws NoEntityToLoadException Deprecated.Resolve a path of relations to an entity list. All relations on the path may only be n:1 relations except for the last relation which can be either 1:n or n:1- Parameters:
entity- the starting entitypathString- a string containing an arbitrary path to follow from the starting entity- Returns:
- the entity list corresponding to the specified relation path
- Throws:
NoEntityToLoadException
-
resolvePathWithoutLastStep
@Deprecated public static Entity resolvePathWithoutLastStep(Entity entity, Path path) throws NoEntityToLoadException Deprecated.Resolve a path of relations (without the last step) to an entity all relations on the path may only be n:1 relations.- Parameters:
entity- the starting entitypath- the path object to follow- Returns:
- the entity corresponding to the path without the last step
- Throws:
NoEntityToLoadException
-
resolvePathWithoutLastStepOrNull
@Nullable @Deprecated public static @Nullable Entity resolvePathWithoutLastStepOrNull(Entity entity, Path path) Deprecated.Resolve a path of relations (without the last step) to an entity all relations on the path may only be n:0..1 relations. return null if there was no entity found- Parameters:
entity- the starting entitypath- the path object to follow- Returns:
- the entity corresponding to the path without the last step
-
resolvePathToEntityListWithoutLastStep
public static EntityList resolvePathToEntityListWithoutLastStep(Entity entity, Path path, QueryBuilderFactory queryBuilderFactory) Resolve a path without it's last step to an entity list. This method is capable of traversing all types of relations (1:n, n:n, n:1), similar to a path in a query e.g. find X where relY.relZ.pk == 1- Parameters:
entity- the starting point entitypath- a pathqueryBuilderFactory- queryBuilderFactory- Returns:
- the resolved entity list
-
reversePathWithoutLastStep
Reverse a path without the last step- Parameters:
entityModel- the starting point entity modelpath- the path to reverse- Returns:
- a path string representing the opposite direction of the provided path
-
reversePath
Reverse a path- Parameters:
entityModel- the starting point entity modelpath- the path to reverse- Returns:
- a path string representing the opposite direction of the provided path
-
resolvePathWithCondition
public static EntityList resolvePathWithCondition(EntityList baseEntities, String path, @Nullable @Nullable String condition, QueryBuilderFactory queryBuilderFactory, Context context) Resolve a path applying a condition to the "last step"- Parameters:
baseEntities- a base entity list to resolve the path onpath- a path string ending in a relation (not a field)condition- a condition for the target entity of the provided pathqueryBuilderFactory- queryBuilderFactory- Returns:
- an EntityList containing entities that are found behind this path satisfying the provided condition
-
deleteEntities
Deletes all entities in supplied entity list- Parameters:
listWithEntitiesToDelete- the
-
resolvePathWithoutLastStep(Entity, Path)