java.lang.Object
org.litebridge.orm.persistence.OrmTable
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 Summary
ConstructorsConstructorDescriptionOrmTable(Class<?> dtoClass, TableMetaData metaData, Map<FieldAccessor, MappedFieldTarget> fieldTargetMap, ChangeTracker changeTracker, ClassFieldAccessorCache classFieldAccessorCache) Constructs a newOrmTableinstance, initializing table metadata, field-to-column mappings, and a change tracker for managing object state. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddOneToManyReverseMapping(FieldAccessor fieldAccessor) Add a one-to-many reverse mapping for the specified field.Class<?> dtoClass()Get the DTO class associated with the table.<DTO> TrackedDto<DTO> ensureTrackedDto(DTO dto) Get the tracked version of the specified DTO, tracking its fields if not already tracked.Get a stream of field accessors for the table.@Nullable FieldAccessorfieldForColumnNameOrNull(String columnName) Get the field accessor for the specified column name, or null if not found.getColumnForFieldName(String fieldName) Get the column metadata for the specified field name.getColumnMetaData(String columnName) Get the column metadata for the specified column name.Get the context table registry.Get the DTO class interfaces.getFieldForColumnName(String columnName) Get the field accessor for the specified column name.Get the many-to-many mapping for the specified field.final List<MappedManyToMany> Get the many-to-many mappings for the table.Get the table metadata.Get the nested DTO classes.Get the one-to-many mapping for the specified field.final List<MappedOneToMany> Get the one-to-many mappings for the table.@Nullable List<FieldAccessor> Get the one-to-many reverse mappings for the table.Get the related DTO classes.<DTO> TrackedDto<DTO> getTrackedDto(DTO dto) Get the tracked version of the specified DTO.booleanisPersistedDto(Object dto) Check if the specified DTO is persisted.Get the mapped field targets.voidsetDtoClassInterfaces(Set<Class<?>> dtoClassInterfaces) Set the DTO class interfaces.voidsyncPersistedDto(Object dto) Mark the specified DTO as persisted, creating a snapshot for tracking changes.voidTrack the specified DTO's fields.
-
Constructor Details
-
OrmTable
public OrmTable(Class<?> dtoClass, TableMetaData metaData, Map<FieldAccessor, MappedFieldTarget> fieldTargetMap, ChangeTracker changeTracker, ClassFieldAccessorCache classFieldAccessorCache) Constructs a newOrmTableinstance, initializing table metadata, field-to-column mappings, and a change tracker for managing object state.- Parameters:
dtoClass- the DTO class associated with the tablemetaData- the metadata describing the table structurefieldTargetMap- a map associating field accessors with their corresponding column metadatachangeTracker- the change tracker to monitor and track modifications made to the table's dataclassFieldAccessorCache- the cache for field accessors
-
-
Method Details
-
dtoClass
Get the DTO class associated with the table.- Returns:
- the DTO class associated with the table
-
getMetaData
Get the table metadata.- Returns:
- the table metadata
-
getColumnForFieldName
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
Get the nested DTO classes.- Returns:
- the list of nested DTO classes
-
getColumnMetaData
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
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
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
Track the specified DTO's fields.- Parameters:
dto- the DTO to track
-
getFieldForColumnName
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
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
Get a stream of field accessors for the table.- Returns:
- a stream of field accessors
-
syncPersistedDto
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
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
Get the one-to-many mappings for the table.- Returns:
- the list of one-to-many mappings
-
getManyToManyMappings
Get the many-to-many mappings for the table.- Returns:
- the list of many-to-many mappings
-
getOneToManyMappingForField
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
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
Get the mapped field targets.- Returns:
- the list of field accessor and mapped field target entries
-
getContextTableRegistry
Get the context table registry.- Returns:
- the context table registry
-
addOneToManyReverseMapping
Add a one-to-many reverse mapping for the specified field.- Parameters:
fieldAccessor- the field accessor to add as a reverse mapping
-
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
Get the DTO class interfaces.- Returns:
- the set of DTO class interfaces
-
setDtoClassInterfaces
Set the DTO class interfaces.- Parameters:
dtoClassInterfaces- the set of DTO class interfaces
-
getRelatedDtoClasses
Get the related DTO classes.- Returns:
- the set of related DTO classes
-