java.lang.Object
no.ntnu.principes.service.DatabaseManager
Central manager for database repositories.
Provides a singleton registry for accessing repository instances.
Lazily initializes repositories when requested and allows configuring the data source.
-
Method Summary
Modifier and TypeMethodDescriptionstatic DatabaseManagerGets the singleton instance of the DatabaseManager.<T> TgetRepository(Class<T> repositoryClass) Gets a repository instance by its class type.voiduseDataSource(DataSource dataSource) Sets a custom data source for all repositories.
-
Method Details
-
useDataSource
Sets a custom data source for all repositories. Reinitializes all repositories to use the new data source.- Parameters:
dataSource- The data source to use for database connections- Throws:
IllegalArgumentException- if the data source is null
-
getInstance
Gets the singleton instance of the DatabaseManager. Thread-safe implementation using the holder pattern.- Returns:
- The DatabaseManager instance
-
getRepository
Gets a repository instance by its class type. Lazily initializes the default data source if none has been set.- Type Parameters:
T- The repository type- Parameters:
repositoryClass- The class of the repository to get- Returns:
- The repository instance
- Throws:
IllegalArgumentException- if the requested repository type is not registered
-