Interface Entity.Builder
- Enclosing interface:
Entity
Entity instances.
When obtained via Entity.Copy.builder(), the builder is initialized with both the current and original
values from the source entity, preserving its modification state. The builder allows mutating that state
before producing a new Entity, for example by resetting modified values back to their originals
via original() and originalPrimaryKey(), or by clearing values via clear(Attribute)
and clearPrimaryKey().
Values supplied via with(Attribute, Object) and withDefaults() are applied to the
resulting entity after instantiation, so they participate in normal modification tracking (i.e. setting
a value different from the entity's original value via with(Attribute, Object) marks the entity
as modified). Primary key columns are an exception: non-generated primary key values supplied via
with(Attribute, Object) replace the column's default null directly on the entity, without
being recorded as a modification.
Instances are not thread safe and not intended to be reused after build().
Store domain = new Store();
Entities entities = domain.entities();
Entity customer = entities.entity(Customer.TYPE)
.with(Customer.FIRST_NAME, "John")
.with(Customer.LAST_NAME, "Doe")
.build();
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionbuild()Builds the Entity instance.Removes the value of the given attribute from this builder, including both the current value and any original value being tracked.Removes all primary key values from this builder, including both current values and any original values being tracked.original()Resets all modified attributes to their original values and discards the corresponding modification tracking, so the resulting entity will not beEntity.modified()for those attributes.Resets the primary key columns to their original values and discards the corresponding modification tracking.<T> Entity.BuilderSets the given attribute value, overriding any previous value supplied via this method for the same attribute.Sets the default value for all attributes which have a default value, as ifwith(Attribute, Object)had been called for each one.
-
Method Details
-
with
Sets the given attribute value, overriding any previous value supplied via this method for the same attribute. The value is applied to the entity after instantiation and participates in modification tracking, except for non-generated primary key columns, which are written directly without being recorded as a modification.- Type Parameters:
T- the value type- Parameters:
attribute- the attributevalue- the value- Returns:
- this builder instance
- Throws:
IllegalArgumentException- in caseattributeis a derived attribute
-
withDefaults
Entity.Builder withDefaults()Sets the default value for all attributes which have a default value, as ifwith(Attribute, Object)had been called for each one. Subsequentwith(Attribute, Object)calls for the same attribute override the default.- Returns:
- this builder instance
- See Also:
-
original
Entity.Builder original()Resets all modified attributes to their original values and discards the corresponding modification tracking, so the resulting entity will not beEntity.modified()for those attributes. This method is destructive: the original values are consumed from this builder, so a subsequent call has no effect. Values supplied afterwards viawith(Attribute, Object)are layered on top of the reset state and are recorded as new modifications against the restored originals.- Returns:
- this builder instance
-
clear
Removes the value of the given attribute from this builder, including both the current value and any original value being tracked. The resulting entity will beEntity.isNull(Attribute)for the attribute and unaware of any prior modification.- Parameters:
attribute- the attribute which value to remove- Returns:
- this builder instance
-
clearPrimaryKey
Entity.Builder clearPrimaryKey()Removes all primary key values from this builder, including both current values and any original values being tracked. The resulting entity will have a null primary key and no recorded modifications for those columns.- Returns:
- this builder instance
-
originalPrimaryKey
Entity.Builder originalPrimaryKey()Resets the primary key columns to their original values and discards the corresponding modification tracking. This method is destructive: the original values are consumed from this builder, so a subsequent call has no effect.- Returns:
- this builder instance
-
build
Entity build()Builds the Entity instance.- Returns:
- a new Entity instance
-