edu.harvard.deas.hyperenc.gui
Class DBMessageStorage

java.lang.Object
  extended by edu.harvard.deas.hyperenc.gui.MessageStorage
      extended by edu.harvard.deas.hyperenc.gui.DBMessageStorage

public class DBMessageStorage
extends MessageStorage

Stores collections of GuiMessages. Supports retrieval of all GuiMessages from a particular sender. This storage is backed by a PersistentMap, so insertions and removals of messages in this storage are synchronously written to disk, and can persist across instances of the application.

All storage in this MessageStorage is done by value; the returned GuiMessage is not necessarily the same object reference as the one that was originally stored, even if the insertion and lookup occur within the lifetime of a single VM.

Thread safety: This implementation is unconditionally thread-safe as a consequence of the thread-safety of the underlying database.

See Also:
PersistentMap

Constructor Summary
DBMessageStorage(String emailAddress)
          Equivalent to DBMessageStorage(emailAddress, null).
DBMessageStorage(String emailAddress, File envPath)
          Constructor.
 
Method Summary
 void addMessage(GuiMessage msg)
          Put message in storage.
 GuiMessage getMessage(int id)
          Get message from this storage, given its ID.
 Collection<GuiMessage> getMessagesBySender(Contact contact)
          Get all stored messages sent from a particular contact.
 GuiMessage removeMessage(int id)
          Remove a message from storage.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DBMessageStorage

public DBMessageStorage(String emailAddress)
Equivalent to DBMessageStorage(emailAddress, null).

Parameters:
emailAddress - e-mail address for which this MessageStorage is storing e-mails

DBMessageStorage

public DBMessageStorage(String emailAddress,
                        File envPath)
Constructor.

Parameters:
emailAddress - e-mail address for which this MessageStorage is storing e-mails
envPath - The path on disk of the database environment underlying the database backing this map. Must be readable and writable. If it doesn't exist, it will be created. If null, the default environment specified by PersistentMap.DEFAULT_HOME is used.
See Also:
PersistentMap, Environment
Method Detail

addMessage

public void addMessage(GuiMessage msg)
Description copied from class: MessageStorage
Put message in storage.

Specified by:
addMessage in class MessageStorage
Parameters:
msg - Message to be stored.

getMessage

public GuiMessage getMessage(int id)
Description copied from class: MessageStorage
Get message from this storage, given its ID. The ID is that given by the getID method of GuiMessage.

Specified by:
getMessage in class MessageStorage
Parameters:
id - ID of desired message.
Returns:
the message with the given ID, or null if there is no such message stored.

getMessagesBySender

public Collection<GuiMessage> getMessagesBySender(Contact contact)
Description copied from class: MessageStorage
Get all stored messages sent from a particular contact. Callers may mutate the returned Collection.

Specified by:
getMessagesBySender in class MessageStorage
Parameters:
contact - contact of desired sender
Returns:
a Collection of all incoming messages from the specified sender. If there are no messages stored from the specified sender, returns an empty Collection. Changes to the returned Collection are not reflected in this MessageStorage.

removeMessage

public GuiMessage removeMessage(int id)
Description copied from class: MessageStorage
Remove a message from storage. If there is no such message, does nothing.

Specified by:
removeMessage in class MessageStorage
Parameters:
id - ID of message to be removed.
Returns:
The message with the given ID, or null if there is no such message stored.