OrmTable). This registry allows for efficient management, querying, and consistency of ORM
table mappings within Litebridge.
This class provides methods to:
- Add and register OrmTable instances associated with DTO classes.
- Retrieve OrmTable instances based on DTO class, schema, or table names.
- Check for the existence of tables mapped to specific DTO classes.
- Retrieve or create lightweight SPI table representations for database interactions.
Instances of this class are immutable with respect to their internal maps, ensuring thread safety and consistent state across multiple threads.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidAdds a table to the registry.booleancontainsTable(Class<?> dtoClass) Checks if a table associated with the specified DTO class exists in the registry.getOrCreateSpiTable(String table) Returns the SPI table for the specified table name.@Nullable OrmTableRetrieves theOrmTableassociated with the specified DTO class.@Nullable OrmTableRetrieves theOrmTableassociated with the specified table name.@Nullable OrmTableRetrieves theOrmTableassociated with the specified schema and table name.@Nullable OrmTableRetrieves theOrmTableassociated with the specified table.getTableInContext(Class<?> dtoClass, Class<?> contextClass) Retrieves anOrmTableassociated with the specified DTO class within a given context class.getTableInContextOrThrow(Class<?> dtoClass, Class<?> contextClass) Retrieves theOrmTableassociated with the specified DTO class within the context of a given context class.getTableOrThrow(Class<?> dtoClass) Retrieves theOrmTableassociated with the specified DTO class, or throws an exception if no table is mapped to the class.Returns a stream of all registered tables.
-
Constructor Details
-
TableRegistry
public TableRegistry()
-
-
Method Details
-
getTable
Retrieves theOrmTableassociated with the specified DTO class. -
getTableOrThrow
Retrieves theOrmTableassociated with the specified DTO class, or throws an exception if no table is mapped to the class.- Parameters:
dtoClass- the DTO class for which the correspondingOrmTableis to be retrieved; must not be null- Returns:
- the
OrmTableassociated with the specified DTO class - Throws:
IllegalArgumentException- if no table is mapped to the class
-
getTableInContext
Retrieves anOrmTableassociated with the specified DTO class within a given context class.This method first retrieves the
OrmTablefor the context class. If the context's table exists, it attempts to retrieve theOrmTablefor the DTO class from the context table's registry. If no context table exists or the registry does not contain the table, the method will return an emptyOptional.- Parameters:
dtoClass- the DTO class for which the correspondingOrmTableis to be retrieved; must not be nullcontextClass- the class representing the context within which theOrmTableis being resolved; must not be null- Returns:
- an
Optionalcontaining theOrmTableassociated with the specified DTO class in the context of the given context class, or an emptyOptionalif no such table is found
-
getTableInContextOrThrow
Retrieves theOrmTableassociated with the specified DTO class within the context of a given context class.This method first resolves the
OrmTablefor the context class and then fetches theOrmTablefor the DTO class from the context table's registry. If no table is mapped to either class, an exception is thrown.- Parameters:
dtoClass- the DTO class for which the correspondingOrmTableis to be retrieved; must not be nullcontextClass- the class representing the context within which theOrmTableis to be resolved; must not be null- Returns:
- the
OrmTableassociated with the specified DTO class in the context of the given context class - Throws:
IllegalArgumentException- if noOrmTableis mapped to the context class or the DTO class
-
getTable
Retrieves theOrmTableassociated with the specified table name.- Parameters:
table- the table name in the format "schema.table"- Returns:
- the
OrmTableassociated with the specified table name, ornullif not found
-
getTable
Retrieves theOrmTableassociated with the specified schema and table name.- Parameters:
schema- the schema nametable- the table name- Returns:
- the
OrmTableassociated with the specified schema and table name, ornullif not found
-
getTable
Retrieves theOrmTableassociated with the specified table.- Parameters:
table- the table- Returns:
- the
OrmTableassociated with the specified table, ornullif not found
-
containsTable
Checks if a table associated with the specified DTO class exists in the registry.- Parameters:
dtoClass- the DTO class for which the presence of an associated table is to be checked; must not be null- Returns:
trueif a table is mapped to the specified DTO class,falseotherwise
-
addTable
Adds a table to the registry.- Parameters:
dtoClass- the DTO class for which the table is to be associatedtable- the table to register
-
tableStream
Returns a stream of all registered tables.- Returns:
- a stream of all registered tables
-
getOrCreateSpiTable
Returns the SPI table for the specified table name.- Parameters:
table- the table name- Returns:
- the SPI table
-