Interface PropertyDefinition<T>
- Type Parameters:
T- the attribute value type
- All Superinterfaces:
AttributeDefinition<T>, ValueAttributeDefinition<T>
Property that does not map to an underlying database column, defined via
Property.PropertyDefiner.property().
PropertyDefinition 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 properties can be set and retrieved like normal attributes
but are ignored during insert, update, and delete operations. Setting a property
value therefore does not mark the entity as modified, unless the property is configured
to, for one standing for something a custom persistence stores by other means, see
PropertyDefinition.Builder.modifies(boolean).
Properties 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 properties
Property<Boolean> SELECTED = TYPE.booleanProperty("selected");
Property<String> NOTES = TYPE.stringProperty("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, not marking the entity modified
Customer.SELECTED.as()
.property()
.defaultValue(false)
.caption("Selected"),
// Notes a custom persistence stores elsewhere
Customer.NOTES.as()
.property()
.modifies(true) // Marks the entity as modified
.caption("Notes"))
.build();
}
void customers(EntityConnection connection) {
// Transient properties 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 properties are ignored by the default persistence, which
// throws when updating an entity with only transient values modified
}
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic interfacePropertyDefinition.Builder<T, B extends PropertyDefinition.Builder<T,B>> Builds aPropertyDefinitioninstanceNested classes/interfaces inherited from interface AttributeDefinition
AttributeDefinition.DefaultValue<T> -
Field Summary
Fields inherited from interface AttributeDefinition
DECIMAL_SEPARATOR, FRACTION_DIGITS, GROUPING_SEPARATOR, LEXICAL_STRING_COMPARATOR, NUMBER_GROUPING, ROUNDING_MODEFields inherited from interface ValueAttributeDefinition
TRIM_STRINGS -
Method Summary
Methods inherited from interface AttributeDefinition
caption, comparator, dateTimeFormatter, dateTimePattern, derived, description, entityType, format, formatted, fractionDigits, hidden, mnemonic, roundingModeMethods inherited from interface ValueAttributeDefinition
defaultValue, hasDefaultValue, items, maximum, maximumLength, minimum, nullable, trim, validate, validItem
-
Method Details
-
attribute
Description copied from interface:AttributeDefinitionTheAttributethis definition is based on, should be unique within an Entity. By default, theAttribute.name()serves as column name for database columns.- Specified by:
attributein interfaceAttributeDefinition<T>- Returns:
- the attribute this definition is based on
-
modifies
boolean modifies()- Returns:
- true if the value of this attribute being modified results in a modified entity, false by default
- See Also:
-