com.sag.osami.contextstore.storage
Class SerializedContextStorage

java.lang.Object
  extended by com.sag.osami.contextstore.storage.SerializedContextStorage
All Implemented Interfaces:
IContextStorage, ISerializedContextStorage
Direct Known Subclasses:
AndroidStorage, JDBCStorage

public abstract class SerializedContextStorage
extends java.lang.Object
implements ISerializedContextStorage

This convenience implementation of an ISerializedContextStorage provides trivial implementations for the public API methods which hide the (de)serialization-flags (i.e. all methods from IContextStorage), as well as a trivial setter method for the serialization handler. All public API implementations simply call the corresponding (de)serialization-aware method, passing the appropriate flag.

Although it helps avoiding redundant, trivial code, it is not required to inherit from this class when implementing an own ContextStore storage.


Field Summary
protected  ISerializationHandler serializer
          Reference to the serialization handler.
 
Constructor Summary
SerializedContextStorage()
           
 
Method Summary
 ContextEvent[] load(java.util.List<java.lang.Long> contextIds)
          Loads several context events with the given IDs.
 ContextEvent load(java.lang.Long contextId)
          Loads a context event with the given ID.
 java.lang.Iterable<ContextEvent> loadLazy(java.util.List<java.lang.Long> contextIds)
          Lazy variant of IContextStorage.load(List), i.e. it loads one ContextEvent at a time during iteration.
 ContextEvent[] query(java.lang.String query, java.lang.Object... params)
          Queries several context events.
 java.lang.Iterable<ContextEvent> queryLazy(java.lang.String query, java.lang.Object... params)
          Lazy variant of IContextStorage.query(String, Object...), i.e. it loads one ContextEvent at a time during iteration.
 void setSerializer(ISerializationHandler serializer)
          Grants access to the payload data serialization handler.
 void store(ContextEvent context)
          Stores a context event object persistently.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface com.sag.osami.contextstore.storage.ISerializedContextStorage
load, load, loadLazy, query, queryLazy, retrieveLastID, store
 
Methods inherited from interface com.sag.osami.api.context.IContextStorage
delete, delete, delete
 

Field Detail

serializer

protected ISerializationHandler serializer
Reference to the serialization handler.

Constructor Detail

SerializedContextStorage

public SerializedContextStorage()
Method Detail

setSerializer

public void setSerializer(ISerializationHandler serializer)
Description copied from interface: ISerializedContextStorage
Grants access to the payload data serialization handler.

Specified by:
setSerializer in interface ISerializedContextStorage
Parameters:
serializer - payload data serialization handler

store

public void store(ContextEvent context)
Description copied from interface: IContextStorage
Stores a context event object persistently.

Specified by:
store in interface IContextStorage
Parameters:
context - context event object to be stored.

load

public ContextEvent load(java.lang.Long contextId)
Description copied from interface: IContextStorage
Loads a context event with the given ID.

Specified by:
load in interface IContextStorage
Parameters:
contextId - ID of the context event
Returns:
loaded context event (or null, if there is no context event with given ID)

load

public ContextEvent[] load(java.util.List<java.lang.Long> contextIds)
Description copied from interface: IContextStorage
Loads several context events with the given IDs. The order within the result is unspecified.

Specified by:
load in interface IContextStorage
Parameters:
contextIds - IDs of the context events.
Returns:
loaded context events (or a zero-length array, if there are no context events with given IDs)

loadLazy

public java.lang.Iterable<ContextEvent> loadLazy(java.util.List<java.lang.Long> contextIds)
                                          throws java.lang.UnsupportedOperationException
Description copied from interface: IContextStorage
Lazy variant of IContextStorage.load(List), i.e. it loads one ContextEvent at a time during iteration. This operation is optional.

Specified by:
loadLazy in interface IContextStorage
Parameters:
contextIds - IDs of the context events.
Throws:
java.lang.UnsupportedOperationException - if the underlying storage implementation does not support lazy querying
See Also:
IContextStorage.load(List)

query

public ContextEvent[] query(java.lang.String query,
                            java.lang.Object... params)
Description copied from interface: IContextStorage
Queries several context events.

Specified by:
query in interface IContextStorage
Parameters:
query - Its language/format depends on the actual storage management class.
params - Should be used for parameter binding à la JDBC: query("SELECT * FROM contextstore WHERE type = ? AND timestamp >= ?", "someType", someDate.getTime());
Returns:
queried context events (or a zero-length array, if there are no according context events)

queryLazy

public java.lang.Iterable<ContextEvent> queryLazy(java.lang.String query,
                                                  java.lang.Object... params)
                                           throws java.lang.UnsupportedOperationException
Description copied from interface: IContextStorage
Lazy variant of IContextStorage.query(String, Object...), i.e. it loads one ContextEvent at a time during iteration. This operation is optional.

Specified by:
queryLazy in interface IContextStorage
Parameters:
query - The context event query.
params - Parameters for the query.
Throws:
java.lang.UnsupportedOperationException - if the underlying storage implementation does not support lazy querying
See Also:
IContextStorage.query(String, Object...)