Class OrmTable

java.lang.Object
org.litebridgedb.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 columns. 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
  • 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()
    • getColumn

      public ColumnMetaData getColumn(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)
    • fieldAcessorStream

      public Stream<FieldAccessor> fieldAcessorStream()
    • 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()
    • getManyToManyMappings

      public final List<MappedManyToMany> getManyToManyMappings()
    • getOneToManyMappingForField

      public Optional<MappedOneToMany> getOneToManyMappingForField(FieldAccessor field)
    • getManyToManyMappingForField

      public Optional<MappedManyToMany> getManyToManyMappingForField(FieldAccessor field)
    • mappedFieldTargets

      public List<Map.Entry<FieldAccessor,MappedFieldTarget>> mappedFieldTargets()
    • getContextTableRegistry

      public TableRegistry getContextTableRegistry()
    • addOneToManyReverseMapping

      public void addOneToManyReverseMapping(FieldAccessor fieldAccessor)
    • getOneToManyReverseMappings

      public @Nullable List<FieldAccessor> getOneToManyReverseMappings()