Module is.codion.framework.domain
Interface TransientAttributeDefinition<T>
- Type Parameters:
T- the attribute value type
- All Superinterfaces:
AttributeDefinition<T>,ValueAttributeDefinition<T>
An attribute that does not map to an underlying database column.
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 derived values:
public class Store extends DefaultDomain {
interface Customer {
EntityType TYPE = DOMAIN.entityType("store.customer");
// Database columns
Column<Integer> ID = TYPE.integerColumn("id");
Column<String> FIRST_NAME = TYPE.stringColumn("first_name");
Column<String> LAST_NAME = TYPE.stringColumn("last_name");
Column<String> EMAIL = TYPE.stringColumn("email");
// Transient attributes
Attribute<String> FULL_NAME = TYPE.stringAttribute("full_name");
Attribute<Boolean> SELECTED = TYPE.booleanAttribute("selected");
Attribute<String> TEMP_NOTES = TYPE.stringAttribute("temp_notes");
Attribute<Object> UI_STATE = TYPE.attribute("ui_state", Object.class);
}
void defineCustomer() {
Customer.TYPE.define(
// Database columns
Customer.ID.define()
.primaryKey(),
Customer.FIRST_NAME.define()
.column(),
Customer.LAST_NAME.define()
.column(),
Customer.EMAIL.define()
.column(),
// Derived transient attribute (computed from other attributes)
Customer.FULL_NAME.define()
.derived()
.from(Customer.FIRST_NAME, Customer.LAST_NAME)
.value(source -> {
String first = source.get(Customer.FIRST_NAME);
String last = source.get(Customer.LAST_NAME);
return ((first != null ? first : "") + " " +
(last != null ? last : "")).trim();
})
.caption("Full Name"),
// UI state attribute that doesn't modify entity
Customer.SELECTED.define()
.attribute()
.modifies(false) // Doesn't mark entity as modified
.defaultValue(false)
.caption("Selected"),
// Temporary notes (modifies entity by default)
Customer.TEMP_NOTES.define()
.attribute()
.caption("Temporary Notes"),
// Generic UI state storage
Customer.UI_STATE.define()
.attribute()
.modifies(false)
.caption("UI State"))
.build();
}
}
// Usage examples
Entity customer = entities.entity(Customer.TYPE)
.with(Customer.FIRST_NAME, "John")
.with(Customer.LAST_NAME, "Doe")
.with(Customer.EMAIL, "john@example.com")
.build();
// Transient attributes can be used for UI state
customer.set(Customer.SELECTED, true); // Doesn't mark entity as modified
customer.set(Customer.TEMP_NOTES, "Important customer"); // Marks entity as modified
// Derived transient values are computed automatically
String fullName = customer.get(Customer.FULL_NAME); // "John Doe"
// UI state storage
customer.set(Customer.UI_STATE, new HashMap<String, Object>());
// Transient attributes are ignored during database operations
connection.insert(customer); // Only persists database columns
// Check modification state
boolean isModified = customer.modified(); // Only true if database columns changed
- 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.ValueSupplier<T> -
Field Summary
Fields inherited from interface is.codion.framework.domain.entity.attribute.AttributeDefinition
DESCRIPTION_RESOURCE_SUFFIX, MNEMONIC_RESOURCE_SUFFIXFields inherited from interface is.codion.framework.domain.entity.attribute.ValueAttributeDefinition
DECIMAL_SEPARATOR, DEFAULT_FRACTION_DIGITS, FRACTION_DIGITS, GROUPING_SEPARATOR, NUMBER_GROUPING, ROUNDING_MODE, TRIM_STRINGS, USE_LEXICAL_STRING_COMPARATOR -
Method Summary
Methods inherited from interface is.codion.framework.domain.entity.attribute.AttributeDefinition
attribute, caption, comparator, defaultValue, description, entityType, format, hasDefaultValue, hidden, mnemonic, nullable, validate, validateMethods inherited from interface is.codion.framework.domain.entity.attribute.ValueAttributeDefinition
dateTimeFormatter, dateTimePattern, derived, format, fractionDigits, items, maximum, maximumLength, minimum, roundingMode, trim, validItem
-
Method Details
-
modifies
boolean modifies()- Returns:
- true if the value of this attribute being modified should result in a modified entity
-