Interface EntityType<ENTITY>

Type Parameters:
ENTITY - the entity type this metadata describes
All Known Implementing Classes:
AbstractEntityType, EntityTypeProxy

public interface EntityType<ENTITY>
Describes metadata for an entity class that maps to a database table.

This interface provides methods for accessing entity metadata, such as table name, property types, and entity lifecycle methods. It also provides methods for creating entity instances and managing entity state.

Implementations of this interface are typically generated at compile time by the Doma annotation processor based on Entity annotated classes.

The implementation instance must be thread safe.

See Also:
  • Method Details

    • isImmutable

      boolean isImmutable()
      Determines whether the entity class is immutable.

      An immutable entity has all its properties set through its constructor and provides no setters to modify its state after creation. Immutable entities are typically implemented using final fields.

      Returns:
      true if the entity is immutable, false otherwise
      See Also:
    • getName

      String getName()
      Returns the name of this entity.

      The entity name typically corresponds to the simple name of the entity class, unless explicitly specified.

      Returns:
      the entity name
    • getCatalogName

      String getCatalogName()
      Returns the database catalog name for this entity.

      The catalog name is determined based on the Table.catalog() attribute if present, or may be empty if not specified.

      Returns:
      the database catalog name, or an empty string if not specified
      See Also:
    • getSchemaName

      String getSchemaName()
      Returns the database schema name for this entity.

      The schema name is determined based on the Table.schema() attribute if present, or may be empty if not specified.

      Returns:
      the database schema name, or an empty string if not specified
      See Also:
    • getTableName

      String getTableName(BiFunction<NamingType,String,String> namingFunction)
      Returns the database table name for this entity with naming convention applied.

      The table name is determined based on the Table.name() attribute if present, or derived from the entity name using the specified naming convention function.

      Parameters:
      namingFunction - the function that applies naming convention to the table name
      Returns:
      the database table name with naming convention applied
      See Also:
    • getQualifiedTableName

      String getQualifiedTableName(BiFunction<NamingType,String,String> namingFunction, Function<String,String> quoteFunction)
      Returns the fully qualified database table name for this entity.

      The qualified table name includes the catalog and schema names if specified, with both naming convention and quotation marks applied as needed.

      Parameters:
      namingFunction - the function that applies naming convention to the table name
      quoteFunction - the function that applies quotation marks to the table name
      Returns:
      the fully qualified table name (catalog.schema.table)
      See Also:
    • isQuoteRequired

      boolean isQuoteRequired()
      Determines whether quotation marks are required for catalog, schema, and table names.

      This method indicates if the catalog, schema, and table names should be quoted in SQL statements, which is typically needed for reserved words or names with special characters.

      Returns:
      true if quotation marks are required, false otherwise
      See Also:
    • getNamingType

      NamingType getNamingType()
      Returns the naming convention type used for this entity.

      The naming convention determines how entity and property names are converted to table and column names when not explicitly specified.

      Returns:
      the naming convention type, or null if not specified
      See Also:
    • getGeneratedIdPropertyType

      GeneratedIdPropertyType<ENTITY,?,?> getGeneratedIdPropertyType()
      Returns the property type for the generated identity (primary key) property.

      This method returns the property type for a primary key property that has its value automatically generated, such as an auto-increment column or a sequence-generated value.

      Returns:
      the generated identity property type, or null if none exists
      See Also:
    • getVersionPropertyType

      VersionPropertyType<ENTITY,?,?> getVersionPropertyType()
      Returns the property type for the version property used for optimistic locking.

      This method returns the property type for a version property that is automatically incremented during update operations to implement optimistic concurrency control.

      Returns:
      the version property type, or null if none exists
      See Also:
    • getTenantIdPropertyType

      TenantIdPropertyType<ENTITY,?,?> getTenantIdPropertyType()
      Returns the property type for the tenant identifier property used for multi-tenancy.

      This method returns the property type for a tenant identifier property that is used to implement multi-tenant database access, where a single database instance serves multiple logical tenants.

      Returns:
      the tenant identifier property type, or null if none exists
      See Also:
    • getIdPropertyTypes

      List<EntityPropertyType<ENTITY,?>> getIdPropertyTypes()
      Returns a list of property types for all primary key properties in this entity.

      This method returns property types for all properties annotated with Id, which mark them as primary key columns in the database table.

      Returns:
      a list of primary key property types, or an empty list if none exist
      See Also:
    • getEntityPropertyType

      EntityPropertyType<ENTITY,?> getEntityPropertyType(String __name)
      Returns the property type for a specific property by name.

      This method allows looking up a property type by its name, which is useful for dynamic property access and metadata inspection.

      Parameters:
      __name - the name of the property to look up
      Returns:
      the property type, or null if no property with the given name exists
      See Also:
    • getEntityPropertyTypes

      List<EntityPropertyType<ENTITY,?>> getEntityPropertyTypes()
      Returns a list of all property types defined for this entity.

      This method returns property types for all properties in the entity class, including regular properties, ID properties, version properties, and tenant ID properties.

      Returns:
      a list of all entity property types
      See Also:
    • getAssociationPropertyTypes

      default List<AssociationPropertyType> getAssociationPropertyTypes()
      Returns a list of association property types defined for this entity.

      This method returns property types for all properties annotated with Association, which define relationships between this entity and other entities.

      Returns:
      a list of association property types, or an empty list if no associations are defined
      See Also:
    • newEntity

      ENTITY newEntity(Map<String,Property<ENTITY,?>> __args)
      Creates a new instance of the entity class.

      This method instantiates a new entity instance using the provided property values. It is typically used by the framework to create entity instances from database query results.

      Parameters:
      __args - a map of property names to property values
      Returns:
      a new entity instance
    • getEntityClass

      Class<ENTITY> getEntityClass()
      Returns the Java Class object for this entity type.

      This method returns the Class object that represents the entity class this EntityType describes. It can be used for reflection operations or type checking.

      Returns:
      the entity class
    • saveCurrentStates

      void saveCurrentStates(ENTITY entity)
      Saves the current state of an entity for later comparison.

      This method is used to implement optimistic concurrency control and dirty property detection. It stores the current state of the entity so that it can be compared with future states to determine what has changed.

      Parameters:
      entity - the entity instance whose state should be saved
      See Also:
    • getOriginalStates

      ENTITY getOriginalStates(ENTITY entity)
      Returns the original state of an entity that was previously saved.

      This method retrieves the original state of an entity that was previously saved using saveCurrentStates(Object). It is used to implement optimistic concurrency control and dirty property detection by comparing the current state with the original state.

      Parameters:
      entity - the entity instance whose original state should be retrieved
      Returns:
      the original state of the entity, or null if no state was saved
      See Also:
    • preInsert

      void preInsert(ENTITY entity, PreInsertContext<ENTITY> context)
      Called before an entity is inserted into the database.

      This method delegates to the appropriate entity listener's preInsert method to implement pre-insert logic such as setting creation timestamps, generating IDs, or validating entity state.

      Parameters:
      entity - the entity instance about to be inserted
      context - the context containing information about the insert operation
      See Also:
    • preUpdate

      void preUpdate(ENTITY entity, PreUpdateContext<ENTITY> context)
      Called before an entity is updated in the database.

      This method delegates to the appropriate entity listener's preUpdate method to implement pre-update logic such as setting modification timestamps, validating entity state, or implementing business rules.

      Parameters:
      entity - the entity instance about to be updated
      context - the context containing information about the update operation
      See Also:
    • preDelete

      void preDelete(ENTITY entity, PreDeleteContext<ENTITY> context)
      Called before an entity is deleted from the database.

      This method delegates to the appropriate entity listener's preDelete method to implement pre-delete logic such as validating that the entity can be deleted, logging deletion attempts, or implementing business rules.

      Parameters:
      entity - the entity instance about to be deleted
      context - the context containing information about the delete operation
      See Also:
    • postInsert

      void postInsert(ENTITY entity, PostInsertContext<ENTITY> context)
      Called after an entity has been successfully inserted into the database.

      This method delegates to the appropriate entity listener's postInsert method to implement post-insert logic such as processing generated IDs, triggering related operations, or performing additional validations.

      Parameters:
      entity - the entity instance that was inserted
      context - the context containing information about the insert operation
      See Also:
    • postUpdate

      void postUpdate(ENTITY entity, PostUpdateContext<ENTITY> context)
      Called after an entity has been successfully updated in the database.

      This method delegates to the appropriate entity listener's postUpdate method to implement post-update logic such as triggering related operations, performing additional validations, or executing business logic.

      Parameters:
      entity - the entity instance that was updated
      context - the context containing information about the update operation
      See Also:
    • postDelete

      void postDelete(ENTITY entity, PostDeleteContext<ENTITY> context)
      Called after an entity has been successfully deleted from the database.

      This method delegates to the appropriate entity listener's postDelete method to implement post-delete logic such as cleaning up related resources, triggering cascading operations, or logging successful deletions.

      Parameters:
      entity - the entity instance that was deleted
      context - the context containing information about the delete operation
      See Also: