Skip to content

PreferenceData

PreferenceData is the sole data-access class in SAIF.Framework.Preferences. It reads and writes rows in USER_PREFERENCE directly via inline Oracle SQL executed through SqlHelper.ResultSetQuery and SqlHelper.ScalarQuery<T>, bypassing the framework's standard clsBusinessBase/IBusinessCriteria business-object pattern.

Purpose

  • Provide the read (GetPreferences, GetPreferencesForUser) and write (SavePreferences) surface for per-user application/page preference blobs stored in USER_PREFERENCE.

Context

  • Namespace: SAIF.Framework.Preferences
  • Assembly/package: SAIF.Framework.Preferences

Public members

Member Signature Purpose
PreferenceData(IDataPortalInfo dpi) public PreferenceData(IDataPortalInfo dpi) Constructs the data-access object with a caller-supplied IDataPortalInfo, stored in the private DPI field and used for query execution context and audit-user resolution.
GetPreferences public string GetPreferences(string appName, string pageName, string userId) Retrieves the stored PREFERENCE_TEXT for one application/user/page combination (see SQL-002); returns string.Empty if no row matches.
GetPreferencesForUser public List<Preference> GetPreferencesForUser(string userId) Retrieves all preference rows for a user, building and returning a Preference object per row, with PreferenceItems deserialized from JSON (see SQL-003).
SavePreferences public bool SavePreferences(string appName, string pageName, string userId, string preferenceText) Single write entry point; dispatches to DeletePref, UpdatePref, or InsertPref depending on preferenceText and existing-row state. Always returns true.
InsertPref (private) private int InsertPref(string appName, string pageName, string userId, string preferenceText) Inserts a new USER_PREFERENCE row with a sequence-generated key (see SQL-001, SQL-004).
UpdatePref (private) private int UpdatePref(string appName, string pageName, string userId, string preferenceText) Updates an existing row's PREFERENCE_TEXT and audit columns, guarded against no-op writes (see SQL-005).
DeletePref (private) private int DeletePref(string appName, string pageName, string userId) Deletes a matching USER_PREFERENCE row (see SQL-006).
DoesPrefExist (private) private bool DoesPrefExist(string appName, string pageName, string userId) Returns whether a matching row already exists, via a scalar Count(*) check (see SQL-007).

Behavioral notes

  • User IDs are lower-cased before being bound to :userid in every method — see BR-001.
  • SavePreferences routes to DeletePref when preferenceText is empty or whitespace-only — see BR-002.
  • Preference identity is scoped by application name, user ID, and an optional page name across all read/write/delete methods — see BR-003.
  • UpdatePref skips the write when the stored value is unchanged (PREFERENCE_TEXT <> :prefs) — see BR-004.
  • Preference text is trimmed before being persisted in InsertPref/UpdatePref — see BR-005.
  • GetPreferencesForUser deserializes the JSON-encoded PREFERENCE_TEXT payload into Preference.PreferenceItems — see BR-006.
  • This class does not implement IBusinessCriteria and has no nested Criteria class or CreateSQL/RetrieveSQL/InsertSQL/UpdateSQL/DeleteSQL properties, unlike most BOF business-object classes.*

Constraints and usage notes

  • Callers must supply a valid IDataPortalInfo at construction time; this class resolves no connection or configuration context of its own.
  • All internal write methods (InsertPref, UpdatePref, DeletePref) execute via SqlHelper.ScalarQuery<int> and return a rows-affected/status integer that SavePreferences does not directly propagate to its own bool return value.*
  • No authentication, authorization, or segregation-of-duties checks are performed on userId; it is used purely as a data key.

Note: Statements marked with * were inferred from code structure, naming conventions, or contextual evidence where direct confirmation was not available in source artifacts.

Sources

  • SAIF.Framework.Preferences\PreferenceData.cs