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 an ORM table to the registry.voidAdds a table to the registry, but do not associate it with a root DTO class.booleancontainsOrmTable(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 OrmTablegetOrmTable(Class<?> dtoClass) Retrieves theOrmTableassociated with the specified DTO class.@Nullable OrmTablegetOrmTable(String table) Retrieves theOrmTableassociated with the specified table name.@Nullable OrmTablegetOrmTable(@Nullable Table table) Retrieves theOrmTableassociated with the specified table.@Nullable OrmTablegetOrmTableInContext(Class<?> dtoClass, Class<?> contextClass) Retrieves anOrmTableassociated with the specified DTO class within a given context class.getOrmTableInContextOrThrow(Class<?> dtoClass, Class<?> contextClass) Retrieves theOrmTableassociated with the specified DTO class within the context of a given context class.getOrmTableOrThrow(Class<?> dtoClass) Retrieves theOrmTableassociated with the specified DTO class, or throws an exception if no table is mapped to the class.getOrmTableOrThrow(String table) Retrieves theOrmTableassociated with the specified table name, throwing an exception if not found.getOrmTableOrThrow(Table table) Retrieves theOrmTableassociated with the specified SPI table, throwing an exception if not found.
-
Constructor Details
-
TableRegistry
public TableRegistry()
-
-
Method Details
-
getOrmTable
Retrieves theOrmTableassociated with the specified DTO class. -
getOrmTableOrThrow
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
-
getOrmTableInContext
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
-
getOrmTableInContextOrThrow
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
-
getOrmTable
Retrieves theOrmTableassociated with the specified table name.- Parameters:
table- the table name in the format "schema.table" or unqualified "table"- Returns:
- the
OrmTableassociated with the specified table name, ornullif not found
-
getOrmTableOrThrow
Retrieves theOrmTableassociated with the specified table name, throwing an exception if not found.- Parameters:
table- the table name, optionally schema-qualified- Returns:
- the associated
OrmTable - Throws:
NullPointerException- if the table is not found
-
getOrmTable
Retrieves theOrmTableassociated with the specified table.- Parameters:
table- the table- Returns:
- the
OrmTableassociated with the specified table, ornullif not found
-
getOrmTableOrThrow
Retrieves theOrmTableassociated with the specified SPI table, throwing an exception if not found.- Parameters:
table- the SPI table- Returns:
- the associated
OrmTable - Throws:
NullPointerException- if the table is not found
-
containsOrmTable
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 an ORM table to the registry.- Parameters:
dtoClass- the DTO class for which the table is to be associatedormTable- the ORM table to register
-
addTable
Adds a table to the registry, but do not associate it with a root DTO class.The resulting ORM table will only be able to be queried by name from this registry.
- Parameters:
ormTable- the table to register
-
getOrCreateSpiTable
Returns the SPI table for the specified table name.- Parameters:
table- the table name- Returns:
- the SPI table
-