Class AnnotatedEntityHolder
Entity
instances that manage nested entity relationships annotated with
@Member
.
The AnnotatedEntityHolder
provides a way to access and update a composite object (holder) that contains one
or more nested entities. It supports collections, maps, and single-value member fields. It extracts member values
using reflection and allows updating them through generated "wither" or "setter" logic, making it possible to
reconstruct an updated parent entity when one of its children changes.
The holder is typically tied to a specific AccessibleObject
(field or method), which is analyzed and cached
to optimize repeated operations.
Responsibilities:
- Extract and cache metadata about a member location (field/method), including its type, ID property, and wither.
- Create
ImmutableEntity
instances from nested values at this member location. - Apply updates to these entities and propagate the changes back to the parent object via a wither or clone-and-set.
- Support updating collection and map-based member fields while preserving immutability semantics.
The holder is initialized and cached via getEntityHolder(Class, AccessibleObject, EntityHelper, Serializer)
,
and update logic falls back to serialization-based cloning if a wither method is not explicitly defined.
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionStream
<? extends ImmutableEntity<?>> getEntities
(Entity<?> parent) Returns the set ofImmutableEntity
instances that are defined at the member location within the specified parent entity.static AnnotatedEntityHolder
getEntityHolder
(Class<?> ownerType, AccessibleObject location, EntityHelper entityHelper, Serializer serializer) Retrieves or creates a cachedAnnotatedEntityHolder
at the given member location.updateOwner
(Object owner, Entity<?> before, Entity<?> after) Updates the parent object with the new state of a child entity.
-
Method Details
-
getEntityHolder
public static AnnotatedEntityHolder getEntityHolder(Class<?> ownerType, AccessibleObject location, EntityHelper entityHelper, Serializer serializer) Retrieves or creates a cachedAnnotatedEntityHolder
at the given member location.- Parameters:
ownerType
- the class that owns the annotated memberlocation
- the accessible field or method annotated with @MemberentityHelper
- the helper used to apply/validate/apply logic to nested entitiesserializer
- the serializer used for cloning values during updates- Returns:
- a cached or new instance of
AnnotatedEntityHolder
-
getEntities
Returns the set ofImmutableEntity
instances that are defined at the member location within the specified parent entity. This includes actual members and an "empty" fallback entity used for creating new entities or assertions to carry out before an entity is created.- Parameters:
parent
- the parent entity instance- Returns:
- a stream of nested
ImmutableEntity
instances
-
updateOwner
Updates the parent object with the new state of a child entity. Uses a wither method if available; otherwise attempts a reflective update through cloning and direct field access. If the entity has been removed (value has becomenull
), the entity is removed from the owner object if possible.Note that this method typically returns a new clone of the owner object containing the updated child entity value.
- Parameters:
owner
- the parent object containing the member fieldbefore
- the old entity (before update)after
- the new entity (after update)- Returns:
- a new updated parent object, or the original if mutation fails
-