Interface EntityType


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 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

      Optional<String> 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 a EntityDefinition.Builder instance based on the given attribute definition builders.
      Parameters:
      definitionBuilders - builders for the attribute definitions comprising the entity
      Returns:
      a EntityDefinition.Builder instance
      Throws:
      IllegalArgumentException - in case definitionBuilders is empty
      IllegalArgumentException - in case of a entityType mismatch
    • define

      EntityDefinition.Builder define(AttributeDefinition.Builder<?,?>... definitionBuilders)
      Creates a EntityDefinition.Builder instance 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.Builder instance
      Throws:
      IllegalArgumentException - in case definitionBuilders is empty
      IllegalArgumentException - in case of a entityType mismatch
    • attribute

      <T> Attribute<T> attribute(String name, Class<T> valueClass)
      Creates a new Attribute, associated with this EntityType.
      Type Parameters:
      T - the attribute type
      Parameters:
      name - the attribute name
      valueClass - the class representing the attribute value type
      Returns:
      a new Attribute
    • attribute

      <T> Attribute<T> attribute(String name, TypeReference<T> typeReference)
      Creates a new Attribute, associated with this EntityType.
      Type Parameters:
      T - the column type
      Parameters:
      name - the attribute name
      typeReference - the TypeReference representing the attribute value type
      Returns:
      a new Column
    • longAttribute

      Attribute<Long> longAttribute(String name)
      Creates a new Long based attribute, associated with this EntityType.
      Parameters:
      name - the attribute name.
      Returns:
      a new Long based attribute.
    • integerAttribute

      Attribute<Integer> integerAttribute(String name)
      Creates a new Integer based attribute, associated with this EntityType.
      Parameters:
      name - the attribute name.
      Returns:
      a new Integer based attribute.
    • shortAttribute

      Attribute<Short> shortAttribute(String name)
      Creates a new Short based attribute, associated with this EntityType.
      Parameters:
      name - the attribute name.
      Returns:
      a new Short based attribute.
    • doubleAttribute

      Attribute<Double> doubleAttribute(String name)
      Creates a new Double based attribute, associated with this EntityType.
      Parameters:
      name - the attribute name.
      Returns:
      a new Double based attribute.
    • bigDecimalAttribute

      Attribute<BigDecimal> bigDecimalAttribute(String name)
      Creates a new BigDecimal based attribute, associated with this EntityType.
      Parameters:
      name - the attribute name.
      Returns:
      a new BigDecimal based attribute.
    • localDateAttribute

      Attribute<LocalDate> localDateAttribute(String name)
      Creates a new LocalDate based attribute, associated with this EntityType.
      Parameters:
      name - the attribute name.
      Returns:
      a new LocalDate based attribute.
    • localTimeAttribute

      Attribute<LocalTime> localTimeAttribute(String name)
      Creates a new LocalTime based attribute, associated with this EntityType.
      Parameters:
      name - the attribute name.
      Returns:
      a new LocalTime based attribute.
    • localDateTimeAttribute

      Attribute<LocalDateTime> localDateTimeAttribute(String name)
      Creates a new LocalDateTime based attribute, associated with this EntityType.
      Parameters:
      name - the attribute name.
      Returns:
      a new LocalDateTime based attribute.
    • offsetDateTimeAttribute

      Attribute<OffsetDateTime> offsetDateTimeAttribute(String name)
      Creates a new OffsetDateTime based attribute, associated with this EntityType.
      Parameters:
      name - the attribute name.
      Returns:
      a new OffsetDateTime based attribute.
    • stringAttribute

      Attribute<String> stringAttribute(String name)
      Creates a new String based attribute, associated with this EntityType.
      Parameters:
      name - the attribute name.
      Returns:
      a new String based attribute.
    • characterAttribute

      Attribute<Character> characterAttribute(String name)
      Creates a new Character based attribute, associated with this EntityType.
      Parameters:
      name - the attribute name.
      Returns:
      a new Character based attribute.
    • booleanAttribute

      Attribute<Boolean> booleanAttribute(String name)
      Creates a new Boolean based attribute, associated with this EntityType.
      Parameters:
      name - the attribute name.
      Returns:
      a new Boolean based attribute.
    • entityAttribute

      Attribute<Entity> entityAttribute(String name)
      Creates a new Attribute, associated with this EntityType.
      Parameters:
      name - the attribute name
      Returns:
      a new Attribute
    • byteArrayAttribute

      Attribute<byte[]> byteArrayAttribute(String name)
      Creates a new Attribute, associated with this EntityType.
      Parameters:
      name - the attribute name
      Returns:
      a new Attribute
    • column

      <T> Column<T> column(String name, Class<T> valueClass)
      Creates a new Column, associated with this EntityType.
      Type Parameters:
      T - the column type
      Parameters:
      name - the column name
      valueClass - the class representing the column value type
      Returns:
      a new Column
    • column

      <T> Column<T> column(String name, TypeReference<T> typeReference)
      Creates a new Column, associated with this EntityType.
      Type Parameters:
      T - the column type
      Parameters:
      name - the column name
      typeReference - the TypeReference representing the column value type
      Returns:
      a new Column
    • longColumn

      Column<Long> longColumn(String name)
      Creates a new Long based column, associated with this EntityType.
      Parameters:
      name - the column name.
      Returns:
      a new Long based column.
    • integerColumn

      Column<Integer> integerColumn(String name)
      Creates a new Integer based column, associated with this EntityType.
      Parameters:
      name - the column name.
      Returns:
      a new Integer based column.
    • shortColumn

      Column<Short> shortColumn(String name)
      Creates a new Short based column, associated with this EntityType.
      Parameters:
      name - the column name.
      Returns:
      a new Short based column.
    • doubleColumn

      Column<Double> doubleColumn(String name)
      Creates a new Double based column, associated with this EntityType.
      Parameters:
      name - the column name.
      Returns:
      a new Double based column.
    • bigDecimalColumn

      Column<BigDecimal> bigDecimalColumn(String name)
      Creates a new BigDecimal based column, associated with this EntityType.
      Parameters:
      name - the column name.
      Returns:
      a new BigDecimal based column.
    • localDateColumn

      Column<LocalDate> localDateColumn(String name)
      Creates a new LocalDate based column, associated with this EntityType.
      Parameters:
      name - the column name.
      Returns:
      a new LocalDate based column.
    • localTimeColumn

      Column<LocalTime> localTimeColumn(String name)
      Creates a new LocalTime based column, associated with this EntityType.
      Parameters:
      name - the column name.
      Returns:
      a new LocalTime based column.
    • localDateTimeColumn

      Column<LocalDateTime> localDateTimeColumn(String name)
      Creates a new LocalDateTime based column, associated with this EntityType.
      Parameters:
      name - the column name.
      Returns:
      a new LocalDateTime based column.
    • offsetDateTimeColumn

      Column<OffsetDateTime> offsetDateTimeColumn(String name)
      Creates a new OffsetDateTime based column, associated with this EntityType.
      Parameters:
      name - the column name.
      Returns:
      a new OffsetDateTime based column.
    • stringColumn

      Column<String> stringColumn(String name)
      Creates a new String based column, associated with this EntityType.
      Parameters:
      name - the column name.
      Returns:
      a new String based column.
    • characterColumn

      Column<Character> characterColumn(String name)
      Creates a new Character based column, associated with this EntityType.
      Parameters:
      name - the column name.
      Returns:
      a new Character based column.
    • booleanColumn

      Column<Boolean> booleanColumn(String name)
      Creates a new Boolean based column, associated with this EntityType.
      Parameters:
      name - the column name.
      Returns:
      a new Boolean based column.
    • byteArrayColumn

      Column<byte[]> byteArrayColumn(String name)
      Creates a new Column, associated with this EntityType.
      Parameters:
      name - the column name
      Returns:
      a new Column
    • foreignKey

      <A> ForeignKey foreignKey(String name, Column<A> column, Column<A> referencedColumn)
      Creates a new ForeignKey based 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 name
      column - the column
      referencedColumn - 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 new ForeignKey based 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 type
      B - the second column type
      Parameters:
      name - the column name
      firstColumn - the first column
      firstReferencedColumn - the first referenced column
      secondColumn - the second column
      secondReferencedColumn - the second referenced column
      Returns:
      a new ForeignKey
    • foreignKey

      <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 new ForeignKey based on the given columns.
      Type Parameters:
      A - the first column type
      B - the second column type
      C - the third column type
      Parameters:
      name - the column name
      firstColumn - the first column
      firstReferencedColumn - the first referenced column
      secondColumn - the second column
      secondReferencedColumn - the third referenced column
      thirdColumn - the second column
      thirdReferencedColumn - the third referenced column
      Returns:
      a new ForeignKey
    • foreignKey

      ForeignKey foreignKey(String name, List<ForeignKey.Reference<?>> references)
      Creates a new ForeignKey based on the given references.
      Parameters:
      name - the attribute name
      references - the references
      Returns:
      a new ForeignKey
      See Also:
    • conditionType

      ConditionType conditionType(String name)
      Instantiates a new ConditionType for this entity type
      Parameters:
      name - the name
      Returns:
      a new condition type
    • entityType

      static EntityType entityType(String name, DomainType domainType)
      Creates a new EntityType instance.
      Parameters:
      name - the entity type name
      domainType - the domainType to associate this entity type with
      Returns:
      a EntityType instance with the given name
    • entityType

      static EntityType entityType(String name, DomainType domainType, String resourceBundleName)
      Creates a new EntityType instance.
      Parameters:
      name - the entity type name
      domainType - the domainType to associate this entity type with
      resourceBundleName - the name of a resource bundle to use for captions
      Returns:
      a EntityType instance with the given name
      Throws:
      NullPointerException - in case resourceBundleName is null