|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.sag.osami.contextstore.storage.SerializedContextStorage
com.sag.osami.contextstore.storage.impl.AndroidStorage
public final class AndroidStorage
Context store storage implementation based on the Android SQLite API.
The table layout is according to DBConstants
. The table is stored in the database file OSAMI
.
An example query on the context store table would look like this (example fetches last context event with given origin and type):
public static ContextEvent queryLast(String type, String originID, IContextStore contextStore) { String queryGetLastItem = "SELECT * FROM contextstore WHERE type = ? AND originID = ? ORDER BY timestamp LIMIT 1"; IContextEvent[] tmp = contextStore.query(queryGetLastItem, type, originID); if (tmp.length != 0) return tmp[0]; else return null; }
Please note, that all column names (see table layout in DBConstants
) of the ContextStore table must be in the result. While it is most convenient to
use "SELECT * FROM contextstore ..."
to ensure this, it is not mandatory. The only requirement is, that the result contains at least all column
names, therefore allowing complex queries (JOINs etc.) to be performed.
Be aware, that storing of context events happens in a background thread, therefore it is not guaranteed that a context event is immediately stored after
calling SerializedContextStorage.store(ContextEvent)
.
DBConstants
Field Summary |
---|
Fields inherited from class com.sag.osami.contextstore.storage.SerializedContextStorage |
---|
serializer |
Fields inherited from interface com.sag.osami.contextstore.storage.DBConstants |
---|
COL_CTXSTORE_ID, COL_DATA, COL_DATA_CLASS, COL_ID, COL_ORIGINID, COL_TIMESTAMP, COL_TYPE, COLS, TABLE_AND_COLS, TABLE_NAME |
Constructor Summary | |
---|---|
AndroidStorage(android.content.Context context)
|
Method Summary | |
---|---|
void |
delete(java.util.List<java.lang.Long> contextIds)
Deletes several context events with given IDs. |
void |
delete(java.lang.Long contextId)
Deletes a context event with given ID. |
void |
delete(java.lang.String query,
java.lang.Object... params)
Deletes several context events defined by the query. |
protected void |
finalize()
|
ContextEvent[] |
load(boolean deserialize,
java.util.List<java.lang.Long> contextIds)
Loads several context events with the given IDs. |
ContextEvent |
load(boolean deserialize,
java.lang.Long contextId)
Loads a context event with the given ID. |
java.lang.Iterable<ContextEvent> |
loadLazy(boolean deserialize,
java.util.List<java.lang.Long> contextIds)
Lazy variant of ISerializedContextStorage.load(boolean, List) , i.e. it loads one ContextEvent at a time during iteration. |
ContextEvent[] |
query(boolean deserialize,
java.lang.String query,
java.lang.Object... params)
Queries several context events. |
java.lang.Iterable<ContextEvent> |
queryLazy(boolean deserialize,
java.lang.String query,
java.lang.Object... params)
Lazy variant of ISerializedContextStorage.query(boolean, String, Object...) , i.e. it loads one ContextEvent at a time during iteration. |
java.lang.Long |
retrieveLastID()
ContextStore uses the result of this method as the offset for its auto-incremented context event IDs. |
void |
store(boolean serialize,
ContextEvent context)
Stores a context event object persistently. |
Methods inherited from class com.sag.osami.contextstore.storage.SerializedContextStorage |
---|
load, load, loadLazy, query, queryLazy, setSerializer, store |
Methods inherited from class java.lang.Object |
---|
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public AndroidStorage(android.content.Context context)
Method Detail |
---|
public void store(boolean serialize, ContextEvent context)
ISerializedContextStorage
store
in interface ISerializedContextStorage
serialize
- whether the payload data should be serialized or not (because it is already serialized)context
- context event object to be storedpublic void delete(java.lang.Long contextId)
IContextStorage
delete
in interface IContextStorage
contextId
- ID of context event to be deleted.public void delete(java.util.List<java.lang.Long> contextIds)
IContextStorage
delete
in interface IContextStorage
contextIds
- IDs of context events to be deleted.public void delete(java.lang.String query, java.lang.Object... params)
IContextStorage
delete
in interface IContextStorage
query
- Defines the context events to be deleted.params
- Parameters for the query.IContextStorage.query(String, Object...)
public java.lang.Long retrieveLastID()
ISerializedContextStorage
retrieveLastID
in interface ISerializedContextStorage
public java.lang.Iterable<ContextEvent> queryLazy(boolean deserialize, java.lang.String query, java.lang.Object... params) throws java.lang.UnsupportedOperationException
ISerializedContextStorage
ISerializedContextStorage.query(boolean, String, Object...)
, i.e. it loads one ContextEvent at a time during iteration. This operation is optional.
queryLazy
in interface ISerializedContextStorage
java.lang.UnsupportedOperationException
- if the underlying storage implementation does not support lazy queryingISerializedContextStorage.query(boolean, String, Object...)
public ContextEvent[] query(boolean deserialize, java.lang.String query, java.lang.Object... params)
ISerializedContextStorage
query
in interface ISerializedContextStorage
deserialize
- whether the payload data should remain serialized or should be deserializedquery
- 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());
public java.lang.Iterable<ContextEvent> loadLazy(boolean deserialize, java.util.List<java.lang.Long> contextIds) throws java.lang.UnsupportedOperationException
ISerializedContextStorage
ISerializedContextStorage.load(boolean, List)
, i.e. it loads one ContextEvent at a time during iteration. This operation is optional.
loadLazy
in interface ISerializedContextStorage
java.lang.UnsupportedOperationException
- if the underlying storage implementation does not support lazy queryingISerializedContextStorage.load(boolean, List)
public ContextEvent[] load(boolean deserialize, java.util.List<java.lang.Long> contextIds)
ISerializedContextStorage
load
in interface ISerializedContextStorage
deserialize
- whether the payload data should remain serialized or should be deserializedcontextIds
- IDs of the context events
public ContextEvent load(boolean deserialize, java.lang.Long contextId)
ISerializedContextStorage
load
in interface ISerializedContextStorage
deserialize
- whether the payload data should remain serialized or should be deserializedcontextId
- ID of the context event
protected void finalize() throws java.lang.Throwable
finalize
in class java.lang.Object
java.lang.Throwable
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |