Interface TransientAttributeDefinition<T>
- Type Parameters:
T- the attribute value type
- All Superinterfaces:
AttributeDefinition<T>,ValueAttributeDefinition<T>
TransientAttributeDefinition extends ValueAttributeDefinition for attributes
used for temporary data, UI state, calculated values, or any other data that should
not be persisted to the database. They are initialized to null when entities are
loaded and ignored during DML operations.
The value of transient attributes can be set and retrieved like normal attributes but are ignored during insert, update, and delete operations. By default, setting a transient value marks the entity as modified, but trying to update an entity with only transient values modified will result in an error.
Transient attributes are useful for UI state, temporary calculations and values the record carries without storing. They are editable fields wherever the framework builds components from attribute definitions, which is what makes them the way a form holds something the table does not store:
interface Customer {
EntityType TYPE = DOMAIN.entityType("chinook.customer");
// Database columns
Column<Long> ID = TYPE.longColumn("id");
Column<String> FIRSTNAME = TYPE.stringColumn("firstname");
Column<String> LASTNAME = TYPE.stringColumn("lastname");
// Transient attributes
Attribute<Boolean> SELECTED = TYPE.booleanAttribute("selected");
Attribute<String> NOTES = TYPE.stringAttribute("notes");
}
EntityDefinition customer() {
return Customer.TYPE.as()
.attributes(
// Database columns
Customer.ID.as()
.primaryKey(),
Customer.FIRSTNAME.as()
.column()
.caption("First name"),
Customer.LASTNAME.as()
.column()
.caption("Last name"),
// UI state attribute that doesn't modify entity
Customer.SELECTED.as()
.attribute()
.modifies(false) // Doesn't mark entity as modified
.defaultValue(false)
.caption("Selected"),
// Temporary notes (modifies entity by default)
Customer.NOTES.as()
.attribute()
.caption("Notes"))
.build();
}
void customers(EntityConnection connection) {
// Transient attributes are initialized to null when entities are loaded
Entity customer = connection.selectSingle(Customer.ID.equalTo(1L));
customer.set(Customer.SELECTED, true);
customer.modified(); // false, SELECTED doesn't modify the entity
customer.set(Customer.NOTES, "Important customer");
customer.modified(); // true, NOTES modifies the entity
// Transient attributes are ignored during database operations,
// updating an entity with only transient values modified results in an error
}
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic interfaceBuilds a transient AttributeDefinition instanceNested classes/interfaces inherited from interface is.codion.framework.domain.entity.attribute.AttributeDefinition
AttributeDefinition.DefaultValue<T> -
Field Summary
Fields inherited from interface is.codion.framework.domain.entity.attribute.AttributeDefinition
DECIMAL_SEPARATOR, DESCRIPTION_RESOURCE_SUFFIX, FRACTION_DIGITS, GROUPING_SEPARATOR, LEXICAL_STRING_COMPARATOR, MNEMONIC_RESOURCE_SUFFIX, NUMBER_GROUPING, ROUNDING_MODEFields inherited from interface is.codion.framework.domain.entity.attribute.ValueAttributeDefinition
TRIM_STRINGS -
Method Summary
Methods inherited from interface is.codion.framework.domain.entity.attribute.AttributeDefinition
attribute, caption, comparator, dateTimeFormatter, dateTimePattern, derived, description, entityType, format, format, fractionDigits, hidden, mnemonic, roundingModeMethods inherited from interface is.codion.framework.domain.entity.attribute.ValueAttributeDefinition
defaultValue, hasDefaultValue, items, maximum, maximumLength, minimum, nullable, trim, validate, validItem
-
Method Details
-
modifies
boolean modifies()- Returns:
- true if the value of this attribute being modified should result in a modified entity
-