Save preference¶
This operation is the library's only write entry point. It never inserts, updates, or deletes directly; instead it inspects the supplied text, treats blank content as a delete request, and otherwise chooses update versus insert by checking whether the scoped preference row already exists.
| Field | Value |
|---|---|
| Operation ID | OP-PREF-003 |
| Trigger | Caller invokes PreferenceData.SavePreferences(appName, pageName, userId, preferenceText). |
| Inputs | appName, pageName, userId, preferenceText |
| Outputs | true after the delegated write path completes, or an exception if preprocessing/delegated execution fails |
| Primary components | PreferenceData.SavePreferences, PreferenceData.DeletePref, PreferenceData.DoesPrefExist, PreferenceData.UpdatePref, PreferenceData.InsertPref |
| Entry point | SAIF.Framework.Preferences\PreferenceData.cs |
Steps¶
- Evaluate
preferenceText.Trim()and pass the result tostring.IsNullOrEmpty(...)to decide whether the caller supplied usable content (BR-002). - On failure: if
preferenceTextisnull, the immediateTrim()call throwsNullReferenceException; this method does not guard that case locally. - If the trimmed text is empty, dispatch to Delete preference row, which applies the scoped delete against USER_PREFERENCE using SQL-006 and the scope rules BR-001, BR-003.
- The delete path returns
trueeven when no row matches the delete criteria. - If the trimmed text is not empty, call Check preference existence to count rows in USER_PREFERENCE via SQL-007 under BR-001 and BR-003.
- If the helper returns
true, continue to step 4. - If the helper returns
false, continue to step 5. - When a scoped row already exists, call Update preference row, which updates USER_PREFERENCE through SQL-005 and enforces BR-001, BR-003, BR-004, and BR-005.
- Because the update SQL contains the no-op guard from BR-004, unchanged text can lead to zero rows updated while this operation still returns
true. - When no scoped row exists, call Insert preference row, which allocates identity with SQL-001, inserts the row with SQL-004, and enforces BR-001, BR-003, and BR-005 against USER_PREFERENCE.
- Return
trueto the caller after the selected delete/update/insert helper completes. - On failure: exceptions raised by the delegated helper methods are not caught here and propagate to the caller.
Process flow¶
The following diagram visualizes this operation's control flow.
flowchart TD
Start([Caller invokes SavePreferences]) --> Trim[Trim preferenceText]
Trim --> Empty{Trimmed text empty?}
Empty -->|Yes| Delete[Delete preference row]
Empty -->|No| Exists[Check preference existence]
Exists -->|Yes| Update[Update preference row]
Exists -->|No| Insert[Insert preference row]
Delete --> EndOk([Return true])
Update --> EndOk
Insert --> EndOk
Failure and edge-case behavior¶
preferenceTextisnull:Trim()throws before delete/update/insert routing begins.- Blank or whitespace-only text always routes to delete; this method never persists an empty
PREFERENCE_TEXTvalue. - The return value is a plain
true/exception signal — it does not distinguish between insert, update, delete, or a no-op update/delete outcome.
Related documentation¶
Sources¶
- SAIF.Framework.Preferences\PreferenceData.cs