com.microsoft.tfs.core.util
Class MementoRepository

java.lang.Object
  extended by com.microsoft.tfs.core.util.MementoRepository

public final class MementoRepository
extends java.lang.Object

Provides persistent storage of Mementos, identified by string keys, in a PersistenceStore.

This class is convenient for sharing settings between multiple users of com.microsoft.tfs.core that may not otherwise share any standard storage (for example, Eclipse plug-in and Explorer want to share the user's custom merge tool assignments). To share settings, use the same PersistenceStore, and specify the same key from both clients. Client applications are not required to use this class to store settings, they may use a PersistenceStore directly, or store settings in another place (Eclipse workspace, etc.).

Depending on the kind of PersistenceStore supplied, key names may be restricted to prohibit some characters, or have a maximum length, or have other restrictions. See PersistenceStore for details.

Locking is used during save(String, Memento) and load(String) to prevent concurrent reads and writes from other threads as well as other processes on the same computer.

Since:
TEE-SDK-10.1
Thread-safety:
thread-safe

Constructor Summary
MementoRepository(PersistenceStore store)
          Creates a MementoRepository that stores its data inside a child store inside the given PersistenceStore.
 
Method Summary
 Memento load(java.lang.String key)
          Loads the settings Memento for the given key.
 boolean save(java.lang.String key, Memento memento)
          Saves the given Memento for the given key.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MementoRepository

public MementoRepository(PersistenceStore store)
Creates a MementoRepository that stores its data inside a child store inside the given PersistenceStore.

Parameters:
store - the PersistenceStore to use (must not be null )
Method Detail

load

public Memento load(java.lang.String key)
Loads the settings Memento for the given key. If the settings file for the given key is in use by another process, waits (potentially forever) until the file is available.

Parameters:
key - the setting key, which must be a valid PersistenceStore item name (must not be null or empty)
Returns:
the Memento for the given key, or null if no settings exist for the given key or an error happened reading the settings (check the logs for an error message)

save

public boolean save(java.lang.String key,
                    Memento memento)
Saves the given Memento for the given key. Overwrites any data already associated with the key.

Parameters:
key - the setting key, which must be a valid PersistenceStore item name (must not be null or empty)
memento - the Memento to save (must not be null)
Returns:
true if the save succeeded, false if it failed (check the logs for an error message)


© 2015 Microsoft. All rights reserved.