- All Implemented Interfaces:
SelectApi
Litebridge is responsible for managing database interactions, including mapping Data Transfer Objects (DTOs) to tables, registering tables, change tracking, and executing query operations.
It provides a mechanism to translate between DTOs and database tables, facilitating CRUD operations while maintaining consistency and integrity.
Litebridge ensures thread safety by using immutable internal structures and
leveraging the DatabaseProvider and PersistenceFacade for
database interactions, ensuring that operations are performed safely and
efficiently.
This extends LitebridgeCore and provides additional methods for
performing MERGE INTO operations if the database provider supports merge operations.
- See Also:
-
Field Summary
Fields inherited from class org.litebridge.orm.LitebridgeCore
persistenceFacade -
Constructor Summary
ConstructorsModifierConstructorDescriptionLitebridge(DatabaseProvider databaseProvider, DataSource dataSource) Constructs a Litebridge instance with the specified database provider and data source.Litebridge(DatabaseProvider databaseProvider, DataSource dataSource, @Nullable LitebridgeConfig litebridgeConfig) Constructs a Litebridge instance with the specified database provider, data source, and configuration.Litebridge(DatabaseProvider databaseProvider, DataSource dataSource, @Nullable LitebridgeConfig litebridgeConfig, MethodHandles.Lookup lookup) Constructs a Litebridge instance with the specified database provider, data source, configuration, and lookup.Litebridge(DatabaseProvider databaseProvider, TransactionManager transactionManager) Constructs a Litebridge instance with the specified database provider and transaction manager.Litebridge(DatabaseProvider databaseProvider, TransactionManager transactionManager, MethodHandles.Lookup lookup) Constructs a Litebridge instance with the specified database provider, transaction manager, and lookup.Litebridge(DatabaseProvider databaseProvider, TransactionManager transactionManager, @Nullable LitebridgeConfig litebridgeConfig, MethodHandles.Lookup lookup) Constructs a Litebridge instance with the specified database provider, transaction manager, configuration, and lookup.Litebridge(DatabaseProvider databaseProvider, TransactionManager transactionManager, LitebridgeConfig litebridgeConfig) Constructs a Litebridge instance with the specified database provider, transaction manager, and configuration.protectedLitebridge(LitebridgeCore other) Copy constructor. -
Method Summary
Modifier and TypeMethodDescriptionvoidMerges/upserts the specified entity/mapped DTO into the database.<DTO> UpdateResultmergeInto(Class<DTO> dtoClass, Class<?> contextDtoClass, Function<DtoMergeUsingStep<DTO>, MergeTerminal> merge) Performs aMERGE INTOoperation targeting the specified mapped DTO type.<DTO> UpdateResultmergeInto(Class<DTO> dtoClass, Function<DtoMergeUsingStep<DTO>, MergeTerminal> merge) Performs aMERGE INTOoperation targeting the specified mapped DTO type.mergeInto(String tableName, Function<SqlMergeUsingStep, MergeTerminal> merge) Performs aMERGE INTOoperation targeting the specified database table.Methods inherited from class org.litebridge.orm.LitebridgeCore
createDtoLitebridgeContext, createLitebridgeContext, createSqlLitebridgeContext, databaseProvider, delete, delete, delete, delete, delete, entityDtoMapper, insert, insert, insert, inspect, mappingPlanCache, nativeSql, register, register, register, save, saveAll, saveAll, saveAll, select, select, select, select, select, select, select, select, select, tableRegistry, toDto, toDtos, track, transaction, update, update, update, withDatabase, withDatabase
-
Constructor Details
-
Litebridge
Constructs a Litebridge instance with the specified database provider and data source.- Parameters:
databaseProvider- the database providerdataSource- the data source
-
Litebridge
public Litebridge(DatabaseProvider databaseProvider, DataSource dataSource, @Nullable LitebridgeConfig litebridgeConfig) Constructs a Litebridge instance with the specified database provider, data source, and configuration.- Parameters:
databaseProvider- the database providerdataSource- the data sourcelitebridgeConfig- the configuration, ornull
-
Litebridge
public Litebridge(DatabaseProvider databaseProvider, DataSource dataSource, @Nullable LitebridgeConfig litebridgeConfig, MethodHandles.Lookup lookup) Constructs a Litebridge instance with the specified database provider, data source, configuration, and lookup.- Parameters:
databaseProvider- the database providerdataSource- the data sourcelitebridgeConfig- the configuration, ornulllookup- the method handles lookup
-
Litebridge
Constructs a Litebridge instance with the specified database provider and transaction manager.- Parameters:
databaseProvider- the database providertransactionManager- the transaction manager
-
Litebridge
public Litebridge(DatabaseProvider databaseProvider, TransactionManager transactionManager, LitebridgeConfig litebridgeConfig) Constructs a Litebridge instance with the specified database provider, transaction manager, and configuration.- Parameters:
databaseProvider- the database providertransactionManager- the transaction managerlitebridgeConfig- the configuration
-
Litebridge
public Litebridge(DatabaseProvider databaseProvider, TransactionManager transactionManager, MethodHandles.Lookup lookup) Constructs a Litebridge instance with the specified database provider, transaction manager, and lookup.- Parameters:
databaseProvider- the database providertransactionManager- the transaction managerlookup- the method handles lookup
-
Litebridge
public Litebridge(DatabaseProvider databaseProvider, TransactionManager transactionManager, @Nullable LitebridgeConfig litebridgeConfig, MethodHandles.Lookup lookup) Constructs a Litebridge instance with the specified database provider, transaction manager, configuration, and lookup.- Parameters:
databaseProvider- the database providertransactionManager- the transaction managerlitebridgeConfig- the configuration, ornulllookup- the method handles lookup
-
Litebridge
Copy constructor.- Parameters:
other- Instance to copy.
-
-
Method Details
-
merge
Merges/upserts the specified entity/mapped DTO into the database.This method constructs an SQL `MERGE INTO` statement based on the provided DTO and executes it.
- Parameters:
dto- the entity/mapped DTO to be merged into the database. It must correspond to a registered ORM table.
-
mergeInto
Performs aMERGE INTOoperation targeting the specified database table.- Parameters:
tableName- the name of the table into which to merge datamerge- a function that takes an instance ofSqlMergeUsingStepand returns aMergeTerminal, specifying the conditions and actions for merging records- Returns:
- the result of the merge operation
-
mergeInto
public <DTO> UpdateResult mergeInto(Class<DTO> dtoClass, Function<DtoMergeUsingStep<DTO>, MergeTerminal> merge) Performs aMERGE INTOoperation targeting the specified mapped DTO type.- Type Parameters:
DTO- the type of the DTO- Parameters:
dtoClass- the target class of the DTO/entity to mergemerge- a function that takes an instance ofDtoMergeUsingStepand returns aMergeTerminal, specifying the conditions and actions for merging records- Returns:
- the result of the merge operation
-
mergeInto
public <DTO> UpdateResult mergeInto(Class<DTO> dtoClass, Class<?> contextDtoClass, Function<DtoMergeUsingStep<DTO>, MergeTerminal> merge) Performs aMERGE INTOoperation targeting the specified mapped DTO type.- Type Parameters:
DTO- the type of the DTO- Parameters:
dtoClass- the target class of the DTO/entity to mergecontextDtoClass- The context DTO class for determining the table mapping.merge- a function that takes an instance ofDtoMergeUsingStepand returns aMergeTerminal, specifying the conditions and actions for merging records- Returns:
- the result of the merge operation
-