6.5 KiB
source_files, generated_at, model, schema_version, sha256
| source_files | generated_at | model | schema_version | sha256 | |||
|---|---|---|---|---|---|---|---|
|
2026-04-16T04:58:48.501962+00:00 | Qwen/Qwen3-Coder-Next-FP8 | 1 | f305fd0e552dc54c |
SettingsDB
Documentation: SettingsDB Module (Version 57)
1. Purpose
This module provides a centralized, thread-safe mechanism for managing global application settings stored in a database. It abstracts database access for reading and writing string-based settings, caching them in-memory via a singleton pattern to avoid repeated DB queries. It is part of a legacy database export module (Version57) and is intended for use during migration or export workflows where persistent global configuration is needed. The module does not support user-specific settings in the current implementation.
2. Public Interface
SettingsDB (Static Class)
A singleton-managed static class for global setting operations.
-
public static string GetGlobalValue(string id, string defaultValue)
Retrieves the global setting value forid. If not found in DB or cache, returnsdefaultValueafter initializing and caching aGlobalSetting.
Thread-safe via lock. -
public static int GetGlobalValueInt(string id, int defaultValue)
Retrieves the global setting as anint. Converts the stored string value usingint.TryParsewithCultureInfo.InvariantCulture. ReturnsdefaultValueon parse failure. -
public static bool GetGlobalValueBool(string id, bool defaultValue)
Retrieves the global setting as abool. Converts the stored string value usingbool.TryParse. ReturnsdefaultValueon parse failure. -
public static void SetGlobalValue(string id, string value)
Storesvalueas the global setting forid. Updates in-memory cache and callsSetValue()on the cachedGlobalSetting.
Note: Actual DB persistence is commented out (//StoreInDB();) inSetting.SetValue()andGlobalSetting.GetPropertyValue(). -
public static void SetGlobalValueInt(string id, int value)
Storesvalueas a string (usingCultureInfo.InvariantCulture) for global settingid. -
public static void SetGlobalValueBoolean(string id, bool value)
Storesvalueas a string ("True"/"False") for global settingid.
Setting (Abstract Base Class)
-
public string PropertyId { get; }
Read-only identifier for the setting (e.g.,"Theme"). -
public string PropertyValue { get; }
Current value of the setting (string). No length validation is performed. -
protected abstract void GetPropertyValue(string defaultValue)
Implemented by subclasses to populate_propertyValuefrom DB or fallback todefaultValue. -
public void SetValue(string value)
Updates_propertyValuein-memory. DB persistence is disabled (commented out).
GlobalSetting (Concrete Class)
-
public GlobalSetting(string id, string defaultPropertyValue)
Constructor for global settings. Hardcodes_userId = "SYSTEM". -
protected override void GetPropertyValue(string defaultValue)
Queries DB tableDbOperations.Settings.Tablefor a row matchingPropertyId = @PropertyId AND UserId = "SYSTEM".- On success: sets
_propertyValuefrom DB columnPropertyValue. - On failure (no row, exception): sets
_propertyValue = defaultValue.
DB persistence on write is disabled (commented out).
- On success: sets
3. Invariants
- Singleton enforcement:
SettingsDB.Instanceis lazily initialized and thread-safe vialock (_MyLock). - Cache consistency:
_SettingsLookupdictionary keys arePropertyIdstrings; each entry is aSettinginstance (currently onlyGlobalSettingused). - Global-only scope:
_userIdis hardcoded to"SYSTEM"inGlobalSetting; no user-specific settings are supported. - DB schema assumptions:
- Table name:
DbOperations.Settings.Table - Columns:
PropertyId,UserId,PropertyValue(allNVarChar).
- Table name:
- No persistence:
StoreInDB()calls are commented out in bothSetting.SetValue()andGlobalSetting.GetPropertyValue(). Thus,SetGlobalValue*methods only update the in-memory cache and do not write to the database. - Culture invariance: All numeric/boolean conversions use
CultureInfo.InvariantCulture.
4. Dependencies
- Internal dependencies:
DbOperations(namespace/class referenced but not provided): Used for DB access (GetCommand,CreateParam,QueryDataSet,Settings.Table,Settings.UserFields.*).System,System.Collections.Generic,System.Data(explicitly imported).
- Assumed external contracts:
DbOperations.Settings.UserFields.PropertyId,UserId,PropertyValuemust correspond to valid column names in the settings table.- Database table
DbOperations.Settings.Tablemust exist with schema matching usage.
- Depended on by: Unknown (module is in
PreviousDBVersions/Version57/...path, suggesting it is legacy/migration code).
5. Gotchas
- No DB persistence: Despite the module’s purpose, all writes are in-memory only.
StoreInDB()calls are commented out in bothSetting.SetValue()andGlobalSetting.GetPropertyValue(). This is likely intentional for export/migration workflows but is a critical behavioral constraint. - No user-specific settings: The
UserIdproperty and related logic are commented out inSetting; only"SYSTEM"is supported. - No validation:
PropertyValueaccepts arbitrary strings without length checks, despite a "max length" being noted in comments. - Thread-safety scope: Thread-safety applies only to cache access (
_SettingsLookup), not to DB operations (which are not active). - Culture sensitivity: Boolean/integer parsing uses
InvariantCulture, but string storage does not enforce formatting (e.g.,"True"vs"true").bool.TryParseis case-sensitive (only"True"/"False"work). - Exception swallowing:
GlobalSetting.GetPropertyValue()silently falls back todefaultValueon any exception, masking DB errors. - Hardcoded
"SYSTEM": The string"SYSTEM"is duplicated inGlobalSettingconstructor andGetPropertyValue; no constant or enum is used. - No cache invalidation:
SetGlobalValue*updates the cache but does not clear it on external DB changes.
None identified beyond these.