Class OrmTable

java.lang.Object
org.litebridge.orm.persistence.OrmTable

public class OrmTable extends Object
A table known by/registered with the ORM, facilitating the relationship between Java objects (DTOs) and database table schema.

This class maintains metadata and mappings between object field accessors and database expressions. It tracks changes made to objects and their associated database states for ORM operations.

  • Constructor Details

    • OrmTable

      public OrmTable(Class<?> dtoClass, TableMetaData metaData, Map<FieldAccessor,MappedFieldTarget> fieldTargetMap, ChangeTracker changeTracker, ClassFieldAccessorCache classFieldAccessorCache)
      Constructs a new OrmTable instance, initializing table metadata, field-to-column mappings, and a change tracker for managing object state.
      Parameters:
      dtoClass - the DTO class associated with the table
      metaData - the metadata describing the table structure
      fieldTargetMap - a map associating field accessors with their corresponding column metadata
      changeTracker - the change tracker to monitor and track modifications made to the table's data
      classFieldAccessorCache - the cache for field accessors
  • Method Details

    • dtoClass

      public Class<?> dtoClass()
      Get the DTO class associated with the table.
      Returns:
      the DTO class associated with the table
    • getMetaData

      public TableMetaData getMetaData()
      Get the table metadata.
      Returns:
      the table metadata
    • getColumnForFieldName

      public ColumnMetaData getColumnForFieldName(String fieldName)
      Get the column metadata for the specified field name.
      Parameters:
      fieldName - the field name to retrieve the column metadata for
      Returns:
      the column metadata for the specified field name, or null if not found
    • getNestedDtoClasses

      public List<Class<?>> getNestedDtoClasses()
      Get the nested DTO classes.
      Returns:
      the list of nested DTO classes
    • getColumnMetaData

      public ColumnMetaData getColumnMetaData(String columnName)
      Get the column metadata for the specified column name.
      Parameters:
      columnName - the column name to retrieve the metadata for
      Returns:
      the column metadata for the specified column name, or null if not found
    • getTrackedDto

      public <DTO> TrackedDto<DTO> getTrackedDto(DTO dto)
      Get the tracked version of the specified DTO.
      Type Parameters:
      DTO - the type of the DTO
      Parameters:
      dto - the DTO to retrieve the tracked version for
      Returns:
      the tracked version of the specified DTO
      Throws:
      IllegalArgumentException - if the specified DTO is not tracked
    • ensureTrackedDto

      public <DTO> TrackedDto<DTO> ensureTrackedDto(DTO dto)
      Get the tracked version of the specified DTO, tracking its fields if not already tracked.
      Type Parameters:
      DTO - the type of the DTO
      Parameters:
      dto - the DTO to retrieve the tracked version for
      Returns:
      the tracked version of the specified DTO
    • trackDto

      public void trackDto(Object dto)
      Track the specified DTO's fields.
      Parameters:
      dto - the DTO to track
    • getFieldForColumnName

      public FieldAccessor getFieldForColumnName(String columnName)
      Get the field accessor for the specified column name.
      Parameters:
      columnName - the column name to retrieve the field accessor for
      Returns:
      the field accessor for the specified column name, or null if not found
      Throws:
      IllegalArgumentException - if the specified column name is null or empty
    • fieldForColumnNameOrNull

      public @Nullable FieldAccessor fieldForColumnNameOrNull(String columnName)
      Get the field accessor for the specified column name, or null if not found.
      Parameters:
      columnName - the column name to retrieve the field accessor for
      Returns:
      the field accessor for the specified column name, or null if not found
    • fieldAcessorStream

      public Stream<FieldAccessor> fieldAcessorStream()
      Get a stream of field accessors for the table.
      Returns:
      a stream of field accessors
    • syncPersistedDto

      public void syncPersistedDto(Object dto)
      Mark the specified DTO as persisted, creating a snapshot for tracking changes.
      Parameters:
      dto - the DTO to mark as persisted
      Throws:
      IllegalArgumentException - if the specified DTO is null
    • isPersistedDto

      public boolean isPersistedDto(Object dto)
      Check if the specified DTO is persisted.
      Parameters:
      dto - the DTO to check
      Returns:
      true if the specified DTO is persisted, false otherwise
      Throws:
      IllegalArgumentException - if the specified DTO is null
    • getOneToManyMappings

      public final List<MappedOneToMany> getOneToManyMappings()
      Get the one-to-many mappings for the table.
      Returns:
      the list of one-to-many mappings
    • getManyToManyMappings

      public final List<MappedManyToMany> getManyToManyMappings()
      Get the many-to-many mappings for the table.
      Returns:
      the list of many-to-many mappings
    • getOneToManyMappingForField

      public Optional<MappedOneToMany> getOneToManyMappingForField(FieldAccessor field)
      Get the one-to-many mapping for the specified field.
      Parameters:
      field - the field accessor to retrieve the mapping for
      Returns:
      the one-to-many mapping for the specified field, or empty if not found
    • getManyToManyMappingForField

      public Optional<MappedManyToMany> getManyToManyMappingForField(FieldAccessor field)
      Get the many-to-many mapping for the specified field.
      Parameters:
      field - the field accessor to retrieve the mapping for
      Returns:
      the many-to-many mapping for the specified field, or empty if not found
    • mappedFieldTargets

      public List<Map.Entry<FieldAccessor,MappedFieldTarget>> mappedFieldTargets()
      Get the mapped field targets.
      Returns:
      the list of field accessor and mapped field target entries
    • getContextTableRegistry

      public TableRegistry getContextTableRegistry()
      Get the context table registry.
      Returns:
      the context table registry
    • addOneToManyReverseMapping

      public void addOneToManyReverseMapping(FieldAccessor fieldAccessor)
      Add a one-to-many reverse mapping for the specified field.
      Parameters:
      fieldAccessor - the field accessor to add as a reverse mapping
    • getOneToManyReverseMappings

      public @Nullable List<FieldAccessor> getOneToManyReverseMappings()
      Get the one-to-many reverse mappings for the table.
      Returns:
      the list of one-to-many reverse mappings, or null if none
    • getDtoClassInterfaces

      public Set<Class<?>> getDtoClassInterfaces()
      Get the DTO class interfaces.
      Returns:
      the set of DTO class interfaces
    • setDtoClassInterfaces

      public void setDtoClassInterfaces(Set<Class<?>> dtoClassInterfaces)
      Set the DTO class interfaces.
      Parameters:
      dtoClassInterfaces - the set of DTO class interfaces
    • getRelatedDtoClasses

      public Set<Class<?>> getRelatedDtoClasses()
      Get the related DTO classes.
      Returns:
      the set of related DTO classes