java.lang.Object
org.litebridgedb.orm.persistence.PersistenceFacade
The PersistenceFacade class provides an abstraction layer for managing the persistence
of Data Transfer Objects (DTOs) within a database system. It simplifies interactions
with the database, supporting operations such as saving, inserting, and updating
records while ensuring consistency with the underlying ORM table definitions.
This class relies on a TableRegistry for mapping DTOs to their corresponding ORM tables and a DatabaseProvider for executing database statements. It encapsulates complex operations, including statement preparation, dependency resolution, primary key updates, and transaction management.
-
Constructor Summary
ConstructorsConstructorDescriptionPersistenceFacade(TableRegistry tableRegistry, TransactionalDatabaseProvider databaseProvider, ChangeTracker changeTracker) -
Method Summary
Modifier and TypeMethodDescriptionvoidvoidInserts the specified Data Transfer Object (DTO) into the database.<DTO> voidsave(DTO dto) Saves the given Data Transfer Object (DTO) to the database.<DTO> voidsave(Collection<DTO> dtos) Saves a collection of Data Transfer Objects (DTOs) to the database.voidUpdates the specified Data Transfer Object (DTO) in the corresponding database table.
-
Constructor Details
-
PersistenceFacade
public PersistenceFacade(TableRegistry tableRegistry, TransactionalDatabaseProvider databaseProvider, ChangeTracker changeTracker)
-
-
Method Details
-
save
Saves a collection of Data Transfer Objects (DTOs) to the database. Each DTO in the collection is processed sequentially, and the save operation determines whether to insert or update the DTO based on its current state. If the operation generates primary keys (e.g., in the case of an insert), those keys are updated in the respective DTOs.- Parameters:
dtos- the collection of Data Transfer Objects to be saved in the database. Each DTO must correspond to a registered ORM table.- Throws:
SQLException- if a database access error occurs during any of the save operations.
-
save
Saves the given Data Transfer Object (DTO) to the database. This method determines whether the DTO should be inserted or updated based on its current state. If the operation generates primary keys (e.g., in the case of an insert), those keys are updated in the DTO.- Parameters:
dto- the Data Transfer Object to be saved in the database. It must correspond to a registered ORM table.- Throws:
SQLException- if a database access error occurs during the save operation.
-
insert
Inserts the specified Data Transfer Object (DTO) into the database. This method constructs an SQL insert statement based on the provided DTO and executes it. If the insertion generates primary keys, those keys will be updated in the corresponding fields of the DTO.- Parameters:
dto- the Data Transfer Object to be inserted into the database. It must correspond to a registered ORM table.- Throws:
SQLException- if a database access error occurs during the insertion process.
-
update
Updates the specified Data Transfer Object (DTO) in the corresponding database table. This method constructs an SQL update statement based on the provided DTO and executes it. The update operation modifies rows in the database that match the DTO's conditions, such as its primary key or other specified filters.- Parameters:
dto- the Data Transfer Object to be updated in the database. It must correspond to a registered ORM table and include valid fields or conditions to perform the update.- Throws:
SQLException- if a database access error occurs during the update process.
-
delete
- Throws:
SQLException
-