java.lang.Object
no.ntnu.principes.repository.AbstractRepository<ConfigValue,Long>
no.ntnu.principes.repository.ConfigValueRepository
- All Implemented Interfaces:
BaseRepository<ConfigValue,Long>
Repository for managing application configuration values.
Provides caching for config values and JavaFX property bindings to enable reactive UI updates.
Supports string, integer, and boolean configuration values with default fallbacks.
-
Field Summary
Fields inherited from class no.ntnu.principes.repository.AbstractRepository
dataSource, tableName -
Constructor Summary
ConstructorsConstructorDescriptionConfigValueRepository(DataSource dataSource) Creates a new ConfigValueRepository with the specified data source. -
Method Summary
Modifier and TypeMethodDescriptionvoiddeleteById(Long id) Deletes a configuration value by its ID.findAll()Retrieves all configuration values.Finds a configuration value by its ID.Finds a configuration value by its key.javafx.beans.property.ObjectProperty<ConfigValue> getValueOrDefault(String key, boolean defaultValue) Gets a boolean configuration value as a JavaFX property, with a default if not found.javafx.beans.property.ObjectProperty<ConfigValue> getValueOrDefault(String key, int defaultValue) Gets an integer configuration value as a JavaFX property, with a default if not found.javafx.beans.property.ObjectProperty<ConfigValue> getValueOrDefault(String key, String defaultValue) Gets a configuration value as a JavaFX property, with a default if not found.protected ConfigValueMaps a database result set row to a ConfigValue object.save(ConfigValue config) Saves a configuration value, updating if it exists or creating if it doesn't.voidsetConfigValue(String key, boolean value) Sets a boolean configuration value.voidsetConfigValue(String key, int value) Sets an integer configuration value.voidsetConfigValue(String key, String value) Sets a configuration value in the database and updates the cache.Methods inherited from class no.ntnu.principes.repository.AbstractRepository
executeInsert, executeUpdate, queryList, queryListRaw, queryListRaw, queryOne, queryOneRaw, queryOneRaw
-
Constructor Details
-
ConfigValueRepository
Creates a new ConfigValueRepository with the specified data source.- Parameters:
dataSource- The JDBC data source for database connections
-
-
Method Details
-
findById
Finds a configuration value by its ID.- Parameters:
id- The configuration value ID- Returns:
- An Optional containing the found config value or empty if not found
-
findAll
Retrieves all configuration values.- Returns:
- A list of all configuration values
-
save
Saves a configuration value, updating if it exists or creating if it doesn't. Uses the config key to determine if an update or insert is needed.- Parameters:
config- The configuration value to save- Returns:
- The saved configuration value with ID populated
-
deleteById
Deletes a configuration value by its ID.- Parameters:
id- The ID of the configuration value to delete
-
mapRow
Maps a database result set row to a ConfigValue object.- Specified by:
mapRowin classAbstractRepository<ConfigValue,Long> - Parameters:
rs- The result set positioned at the row to map- Returns:
- The mapped ConfigValue object
- Throws:
SQLException- If a database error occurs during mapping
-
findByKey
Finds a configuration value by its key.- Parameters:
key- The configuration key- Returns:
- An Optional containing the found config value or empty if not found
-
getValueOrDefault
public javafx.beans.property.ObjectProperty<ConfigValue> getValueOrDefault(String key, String defaultValue) Gets a configuration value as a JavaFX property, with a default if not found. Uses an in-memory cache to avoid repeated database lookups.- Parameters:
key- The configuration keydefaultValue- The default value to use if the key is not found- Returns:
- An ObjectProperty containing the config value or a new one with the default value
-
getValueOrDefault
public javafx.beans.property.ObjectProperty<ConfigValue> getValueOrDefault(String key, int defaultValue) Gets an integer configuration value as a JavaFX property, with a default if not found.- Parameters:
key- The configuration keydefaultValue- The default integer value to use if the key is not found- Returns:
- An ObjectProperty containing the config value
-
getValueOrDefault
public javafx.beans.property.ObjectProperty<ConfigValue> getValueOrDefault(String key, boolean defaultValue) Gets a boolean configuration value as a JavaFX property, with a default if not found.- Parameters:
key- The configuration keydefaultValue- The default boolean value to use if the key is not found- Returns:
- An ObjectProperty containing the config value
-
setConfigValue
Sets a configuration value in the database and updates the cache. Creates a new entry if the key doesn't exist.- Parameters:
key- The configuration keyvalue- The string value to set
-
setConfigValue
Sets an integer configuration value.- Parameters:
key- The configuration keyvalue- The integer value to set
-
setConfigValue
Sets a boolean configuration value.- Parameters:
key- The configuration keyvalue- The boolean value to set
-