public sealed interface EntityType
Defines an Entity type and serves as a Factory for
Attribute instances associated with this entity type.
A factory for EntityType instances.
EntityType instances are the foundation of the domain model, representing database tables or queries. They serve as factories for creating typed attributes (columns, foreign keys, derived attributes) and provide the starting point for defining entity structure.
public class Store extends DefaultDomain {
public static final DomainType DOMAIN = domainType(Store.class);
// Define entity types as interfaces for organization
public interface Customer {
EntityType TYPE = DOMAIN.entityType("store.customer");
// Define typed columns
Column<Integer> ID = TYPE.integerColumn("id");
Column<String> NAME = TYPE.stringColumn("name");
Column<String> EMAIL = TYPE.stringColumn("email");
Column<LocalDate> BIRTH_DATE = TYPE.localDateColumn("birth_date");
Column<Boolean> ACTIVE = TYPE.booleanColumn("active");
}
public interface Order {
EntityType TYPE = DOMAIN.entityType("store.order");
Column<Integer> ID = TYPE.integerColumn("id");
Column<LocalDateTime> ORDER_DATE = TYPE.localDateTimeColumn("order_date");
Column<BigDecimal> TOTAL = TYPE.bigDecimalColumn("total");
// Define foreign key to Customer
Column<Integer> CUSTOMER_ID = TYPE.integerColumn("customer_id");
ForeignKey CUSTOMER_FK = TYPE.foreignKey("customer_fk", CUSTOMER_ID, Customer.ID);
// Custom condition type for filtering
ConditionType RECENT = TYPE.conditionType("recent_orders");
}
// Constructor defines the entity structures
public Store() {
super(DOMAIN);
defineCustomer();
defineOrder();
}
}
- See Also:
-
Method Summary
Modifier and TypeMethodDescription<T> Attribute<T> attribute(String name, TypeReference<T> typeReference) Creates a newAttribute, associated with this EntityType.<T> Attribute<T> Creates a newAttribute, associated with this EntityType.bigDecimalAttribute(String name) Creates a new BigDecimal based attribute, associated with this EntityType.bigDecimalColumn(String name) Creates a new BigDecimal based column, associated with this EntityType.booleanAttribute(String name) Creates a new Boolean based attribute, associated with this EntityType.booleanColumn(String name) Creates a new Boolean based column, associated with this EntityType.Attribute<byte[]> byteArrayAttribute(String name) Creates a newAttribute, associated with this EntityType.Column<byte[]> byteArrayColumn(String name) Creates a newColumn, associated with this EntityType.characterAttribute(String name) Creates a new Character based attribute, associated with this EntityType.characterColumn(String name) Creates a new Character based column, associated with this EntityType.<T> Column<T> column(String name, TypeReference<T> typeReference) Creates a newColumn, associated with this EntityType.<T> Column<T> Creates a newColumn, associated with this EntityType.conditionType(String name) Instantiates a newConditionTypefor this entity typedefine(AttributeDefinition.Builder<?, ?>... definitionBuilders) Creates aEntityDefinition.Builderinstance based on the given attribute definition builders.define(List<? extends AttributeDefinition.Builder<?, ?>> definitionBuilders) Creates aEntityDefinition.Builderinstance based on the given attribute definition builders.doubleAttribute(String name) Creates a new Double based attribute, associated with this EntityType.doubleColumn(String name) Creates a new Double based column, associated with this EntityType.entityAttribute(String name) Creates a newAttribute, associated with this EntityType.static EntityTypeentityType(String name, DomainType domainType) Creates a new EntityType instance.static EntityTypeentityType(String name, DomainType domainType, String resourceBundleName) Creates a new EntityType instance.<A> ForeignKeyforeignKey(String name, Column<A> column, Column<A> referencedColumn) Creates a newForeignKeybased on the given attributes.<A,B> ForeignKey foreignKey(String name, Column<A> firstColumn, Column<A> firstReferencedColumn, Column<B> secondColumn, Column<B> secondReferencedColumn) Creates a newForeignKeybased on the given columns.<A,B, C> ForeignKey foreignKey(String name, Column<A> firstColumn, Column<A> firstReferencedColumn, Column<B> secondColumn, Column<B> secondReferencedColumn, Column<C> thirdColumn, Column<C> thirdReferencedColumn) Creates a newForeignKeybased on the given columns.foreignKey(String name, List<ForeignKey.Reference<?>> references) Creates a newForeignKeybased on the given references.integerAttribute(String name) Creates a new Integer based attribute, associated with this EntityType.integerColumn(String name) Creates a new Integer based column, associated with this EntityType.localDateAttribute(String name) Creates a new LocalDate based attribute, associated with this EntityType.localDateColumn(String name) Creates a new LocalDate based column, associated with this EntityType.localDateTimeAttribute(String name) Creates a new LocalDateTime based attribute, associated with this EntityType.localDateTimeColumn(String name) Creates a new LocalDateTime based column, associated with this EntityType.localTimeAttribute(String name) Creates a new LocalTime based attribute, associated with this EntityType.localTimeColumn(String name) Creates a new LocalTime based column, associated with this EntityType.longAttribute(String name) Creates a new Long based attribute, associated with this EntityType.longColumn(String name) Creates a new Long based column, associated with this EntityType.name()Creates a new OffsetDateTime based attribute, associated with this EntityType.offsetDateTimeColumn(String name) Creates a new OffsetDateTime based column, associated with this EntityType.shortAttribute(String name) Creates a new Short based attribute, associated with this EntityType.shortColumn(String name) Creates a new Short based column, associated with this EntityType.stringAttribute(String name) Creates a new String based attribute, associated with this EntityType.stringColumn(String name) Creates a new String based column, associated with this EntityType.
-
Method Details
-
domainType
DomainType domainType()- Returns:
- the domain type this entity type is associated with
-
name
String name()- Returns:
- the entity type name, unique within a domain.
-
resourceBundleName
- Returns:
- the name of the resource bundle, containing captions for this entity type, if any
-
define
EntityDefinition.Builder define(List<? extends AttributeDefinition.Builder<?, ?>> definitionBuilders) Creates aEntityDefinition.Builderinstance based on the given attribute definition builders.- Parameters:
definitionBuilders- builders for the attribute definitions comprising the entity- Returns:
- a
EntityDefinition.Builderinstance - Throws:
IllegalArgumentException- in casedefinitionBuildersis emptyIllegalArgumentException- in case of a entityType mismatch
-
define
Creates aEntityDefinition.Builderinstance based on the given attribute definition builders.EntityDefinition definition = Customer.TYPE.define( Customer.ID.define() .primaryKey(), Customer.NAME.define() .column() .caption("Customer Name") .nullable(false) .maximumLength(100), Customer.EMAIL.define() .column() .caption("Email Address") .maximumLength(255), Customer.BIRTH_DATE.define() .column() .caption("Date of Birth") .nullable(true), Customer.ACTIVE.define() .column() .caption("Active") .nullable(false) .defaultValue(true)) .table("customer") .caption("Customer") .description("Customer information") .orderBy(ascending(Customer.NAME)) .formatter(customer -> customer.get(Customer.NAME) + " (" + customer.get(Customer.EMAIL) + ")") .build();- Parameters:
definitionBuilders- builders for the attribute definitions comprising the entity- Returns:
- a
EntityDefinition.Builderinstance - Throws:
IllegalArgumentException- in casedefinitionBuildersis emptyIllegalArgumentException- in case of a entityType mismatch
-
attribute
Creates a newAttribute, associated with this EntityType.- Type Parameters:
T- the attribute type- Parameters:
name- the attribute namevalueClass- the class representing the attribute value type- Returns:
- a new
Attribute
-
attribute
Creates a newAttribute, associated with this EntityType.- Type Parameters:
T- the column type- Parameters:
name- the attribute nametypeReference- theTypeReferencerepresenting the attribute value type- Returns:
- a new
Column
-
longAttribute
Creates a new Long based attribute, associated with this EntityType.- Parameters:
name- the attribute name.- Returns:
- a new Long based attribute.
-
integerAttribute
Creates a new Integer based attribute, associated with this EntityType.- Parameters:
name- the attribute name.- Returns:
- a new Integer based attribute.
-
shortAttribute
Creates a new Short based attribute, associated with this EntityType.- Parameters:
name- the attribute name.- Returns:
- a new Short based attribute.
-
doubleAttribute
Creates a new Double based attribute, associated with this EntityType.- Parameters:
name- the attribute name.- Returns:
- a new Double based attribute.
-
bigDecimalAttribute
Creates a new BigDecimal based attribute, associated with this EntityType.- Parameters:
name- the attribute name.- Returns:
- a new BigDecimal based attribute.
-
localDateAttribute
Creates a new LocalDate based attribute, associated with this EntityType.- Parameters:
name- the attribute name.- Returns:
- a new LocalDate based attribute.
-
localTimeAttribute
Creates a new LocalTime based attribute, associated with this EntityType.- Parameters:
name- the attribute name.- Returns:
- a new LocalTime based attribute.
-
localDateTimeAttribute
Creates a new LocalDateTime based attribute, associated with this EntityType.- Parameters:
name- the attribute name.- Returns:
- a new LocalDateTime based attribute.
-
offsetDateTimeAttribute
Creates a new OffsetDateTime based attribute, associated with this EntityType.- Parameters:
name- the attribute name.- Returns:
- a new OffsetDateTime based attribute.
-
stringAttribute
Creates a new String based attribute, associated with this EntityType.- Parameters:
name- the attribute name.- Returns:
- a new String based attribute.
-
characterAttribute
Creates a new Character based attribute, associated with this EntityType.- Parameters:
name- the attribute name.- Returns:
- a new Character based attribute.
-
booleanAttribute
Creates a new Boolean based attribute, associated with this EntityType.- Parameters:
name- the attribute name.- Returns:
- a new Boolean based attribute.
-
entityAttribute
Creates a newAttribute, associated with this EntityType.- Parameters:
name- the attribute name- Returns:
- a new
Attribute
-
byteArrayAttribute
Creates a newAttribute, associated with this EntityType.- Parameters:
name- the attribute name- Returns:
- a new
Attribute
-
column
Creates a newColumn, associated with this EntityType.- Type Parameters:
T- the column type- Parameters:
name- the column namevalueClass- the class representing the column value type- Returns:
- a new
Column
-
column
Creates a newColumn, associated with this EntityType.- Type Parameters:
T- the column type- Parameters:
name- the column nametypeReference- theTypeReferencerepresenting the column value type- Returns:
- a new
Column
-
longColumn
Creates a new Long based column, associated with this EntityType.- Parameters:
name- the column name.- Returns:
- a new Long based column.
-
integerColumn
Creates a new Integer based column, associated with this EntityType.- Parameters:
name- the column name.- Returns:
- a new Integer based column.
-
shortColumn
Creates a new Short based column, associated with this EntityType.- Parameters:
name- the column name.- Returns:
- a new Short based column.
-
doubleColumn
Creates a new Double based column, associated with this EntityType.- Parameters:
name- the column name.- Returns:
- a new Double based column.
-
bigDecimalColumn
Creates a new BigDecimal based column, associated with this EntityType.- Parameters:
name- the column name.- Returns:
- a new BigDecimal based column.
-
localDateColumn
Creates a new LocalDate based column, associated with this EntityType.- Parameters:
name- the column name.- Returns:
- a new LocalDate based column.
-
localTimeColumn
Creates a new LocalTime based column, associated with this EntityType.- Parameters:
name- the column name.- Returns:
- a new LocalTime based column.
-
localDateTimeColumn
Creates a new LocalDateTime based column, associated with this EntityType.- Parameters:
name- the column name.- Returns:
- a new LocalDateTime based column.
-
offsetDateTimeColumn
Creates a new OffsetDateTime based column, associated with this EntityType.- Parameters:
name- the column name.- Returns:
- a new OffsetDateTime based column.
-
stringColumn
Creates a new String based column, associated with this EntityType.- Parameters:
name- the column name.- Returns:
- a new String based column.
-
characterColumn
Creates a new Character based column, associated with this EntityType.- Parameters:
name- the column name.- Returns:
- a new Character based column.
-
booleanColumn
Creates a new Boolean based column, associated with this EntityType.- Parameters:
name- the column name.- Returns:
- a new Boolean based column.
-
byteArrayColumn
Creates a newColumn, associated with this EntityType.- Parameters:
name- the column name- Returns:
- a new
Column
-
foreignKey
Creates a newForeignKeybased on the given attributes.// Single column foreign key interface Order { EntityType TYPE = DOMAIN.entityType("store.order"); Column<Integer> ID = TYPE.integerColumn("id"); Column<Integer> CUSTOMER_ID = TYPE.integerColumn("customer_id"); // Define foreign key to Customer entity ForeignKey CUSTOMER_FK = TYPE.foreignKey("customer_fk", CUSTOMER_ID, Customer.ID); } // Usage in entity definition Order.TYPE.define( Order.ID.define() .primaryKey(), Order.CUSTOMER_ID.define() .column(), Order.CUSTOMER_FK.define() .foreignKey() .caption("Customer")) .build();- Type Parameters:
A- the attribute type- Parameters:
name- the attribute namecolumn- the columnreferencedColumn- the referenced column- Returns:
- a new
ForeignKey
-
foreignKey
<A,B> ForeignKey foreignKey(String name, Column<A> firstColumn, Column<A> firstReferencedColumn, Column<B> secondColumn, Column<B> secondReferencedColumn) Creates a newForeignKeybased on the given columns.// Composite foreign key (two columns) interface OrderLine { EntityType TYPE = DOMAIN.entityType("store.order_line"); // Composite primary key columns Column<Integer> ORDER_ID = TYPE.integerColumn("order_id"); Column<Integer> LINE_NUMBER = TYPE.integerColumn("line_number"); // Foreign key columns to ProductPrice (which has composite key) Column<Integer> PRODUCT_ID = TYPE.integerColumn("product_id"); Column<LocalDate> PRICE_DATE = TYPE.localDateColumn("price_date"); // Composite foreign key ForeignKey PRODUCT_PRICE_FK = TYPE.foreignKey("product_price_fk", PRODUCT_ID, ProductPrice.PRODUCT_ID, PRICE_DATE, ProductPrice.EFFECTIVE_DATE); }- Type Parameters:
A- the first column typeB- the second column type- Parameters:
name- the column namefirstColumn- the first columnfirstReferencedColumn- the first referenced columnsecondColumn- the second columnsecondReferencedColumn- the second referenced column- Returns:
- a new
ForeignKey
-
foreignKey
<A,B, ForeignKey foreignKeyC> (String name, Column<A> firstColumn, Column<A> firstReferencedColumn, Column<B> secondColumn, Column<B> secondReferencedColumn, Column<C> thirdColumn, Column<C> thirdReferencedColumn) Creates a newForeignKeybased on the given columns.- Type Parameters:
A- the first column typeB- the second column typeC- the third column type- Parameters:
name- the column namefirstColumn- the first columnfirstReferencedColumn- the first referenced columnsecondColumn- the second columnsecondReferencedColumn- the third referenced columnthirdColumn- the second columnthirdReferencedColumn- the third referenced column- Returns:
- a new
ForeignKey
-
foreignKey
Creates a newForeignKeybased on the given references.- Parameters:
name- the attribute namereferences- the references- Returns:
- a new
ForeignKey - See Also:
-
conditionType
Instantiates a newConditionTypefor this entity type- Parameters:
name- the name- Returns:
- a new condition type
-
entityType
Creates a new EntityType instance.- Parameters:
name- the entity type namedomainType- the domainType to associate this entity type with- Returns:
- a
EntityTypeinstance with the given name
-
entityType
Creates a new EntityType instance.- Parameters:
name- the entity type namedomainType- the domainType to associate this entity type withresourceBundleName- the name of a resource bundle to use for captions- Returns:
- a
EntityTypeinstance with the given name - Throws:
NullPointerException- in caseresourceBundleNameis null
-