primaryKey
EntityDefinition.PrimaryKey primaryKey()
- Returns:
- the
EntityDefinition.PrimaryKeyinstance
An EntityDefinition contains all information about an entity's structure including:
Entity definitions are typically created using the builder pattern during domain initialization:
public class Store extends DefaultDomain {
// Define entity types
interface Customer {
EntityType TYPE = DOMAIN.entityType("store.customer");
Column<Integer> ID = TYPE.integerColumn("id");
Column<String> NAME = TYPE.stringColumn("name");
Column<String> EMAIL = TYPE.stringColumn("email");
}
// Define the entity structure
void defineCustomer() {
EntityDefinition definition = Customer.TYPE.define(
Customer.ID.define()
.primaryKey(),
Customer.NAME.define()
.column()
.caption("Name")
.nullable(false)
.maximumLength(100),
Customer.EMAIL.define()
.column()
.caption("Email")
.maximumLength(255))
.table("customer")
.caption("Customer")
.orderBy(ascending(Customer.NAME))
.smallDataset(true)
.build();
}
}
static interface static interface static interface static interface static interface static final PropertyValue<Boolean> booleancaption()columns()condition(ConditionType conditionType) ConditionString associated with the given typeentity()Entity instance based on this definitionEntity instance based on this definitionEntity instance based on this definitionexists()booleanorderBy()<T> Entity.KeyprimaryKey(T value) Entity.Key instance based on this definition, initialised with the given valuebooleanreadOnly()booleantable()type()ConditionString associated with the given typeconditionType - the condition typeConditionString associated with the given ConditionTypeIllegalArgumentException - in case no ConditionString is associated with the given ConditionType // Define custom string representation
Customer.TYPE.define(
Customer.ID.define()
.primaryKey(),
Customer.FIRST_NAME.define()
.column(),
Customer.LAST_NAME.define()
.column(),
Customer.EMAIL.define()
.column())
.formatter(customer ->
customer.get(Customer.LAST_NAME) + ", " +
customer.get(Customer.FIRST_NAME) +
" (" + customer.get(Customer.EMAIL) + ")")
.build();
// Usage
Entity customer = entities.entity(Customer.TYPE)
.with(Customer.FIRST_NAME, "John")
.with(Customer.LAST_NAME, "Doe")
.with(Customer.EMAIL, "john@example.com")
.build();
System.out.println(customer); // "Doe, John (john@example.com)"
EntityDefinition.Attributes instanceEntityDefinition.Columns instanceEntityDefinition.ForeignKeys instanceEntityDefinition.PrimaryKey instanceEntity instance based on this definitionEntity instanceEntity instance based on this definitionvalues - the initial values, an empty map in case of no valuesEntity instanceIllegalArgumentException - in case any of the value attributes are not part of the entity.Entity instance based on this definitionvalues - the initial values, an empty map in case of no valuesoriginalValues - the original values, an empty map in case of no original valuesEntity instanceIllegalArgumentException - in case any of the value attributes are not part of the entity.Entity.Key instance based on this definition, initialised with the given valueT - the key value typevalue - the key value, assuming a single value keyEntity.Key instanceIllegalStateException - in case the given primary key is a composite keyIllegalArgumentException - in case the value is not of the correct typeThe returned entity has no attribute values set and cannot be modified.
caption - the string to return when toString() is called