Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
languagejava
interface PreferenceStore
{
    // see below for the Updater and Recoverer interfaces
    void Collection<PreferenceRecords> openopenAndLoad(PreferenceStoreUpdater updater, PreferenceStoreRecoverer recoverer);

    // safely persist all state and close all resources
    void close();

    // adds preferences to the store
    void create(Collection<PreferenceRecord> preferences);

    // updates existing preferences. throws an exception if preference with given id is not already in the store
    void update(Collection<PreferenceRecord> preferences);

    // updates existing preferences. if a preference with given id is not already in the store it will be added
    void updateOrCreate(Collection<PreferenceRecord> preferences);

    // remove preferences from the store. throws an exception if preference with given id is not already in the store
    void delete(Collection<PreferenceRecord> preferences);
}

interface PreferenceRecord
{
    UUID getId();
	Map<String, Object> getAttributes();
}

...

  • we want to ability to update individual preferences. This may include updating, creating and deleting preferences. This might require multiple passes.
  • Since the update step might arbitrarily modify the preferences the store needs to be informed about the changes so that the update can be persisted.
  • preferences need to ability to reference each other. One way to achieve this is that separate instantiation and dependency resolutionThis is done by storing UUIDs. The objects using the preferences are responsible for resolving those references.

The first to points are the responsibility of the PreferenceStoreUpdater while the second should be performed by the PreferenceStoreRecoverer.While not part of this specification the recoverer should probably go through these

stepsThe recoverer is responsible for

  1. Convert PreferenceRecord to Preference
  2. Attach Preference to AbstractConfiguredObject
  3. Convert generic attributes to a type specific PreferenceValue
  4. Cross link to other preferencesAttach Preference to AbstractConfiguredObject
Code Block
languagejava

interface PreferenceStoreUpdater
{
    Collection<PreferenceRecord> updatePreferences(String currentVersion, Collection<PreferenceRecord> preferences);
}

interface PreferenceStoreRecoverer
{
	void recoverPreferences(Collection<PreferenceRecord> preferences    String getLatestVersion();
}

Persistence

Preferences are considered immutable. All changes to preferences should go through a UserPreferences facade which is responsible for updating the store.

...