|
||||||||||
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.JDBCStorage
public final class JDBCStorage
Context storage implementation based on JDBC. It is database-agnostic by using a IJDBCDialect
interface which provides all database-specific SQL
statements. By default, DerbyDialect
is used.
It is configurable using the ContextStoreBuilder
. Following properties can be configured:
jdbc:mydb://...
, this dialect class
will be used:
com.sag.osami.contextstore.storage.jdbc.MydbDialect
The table layout is according to DBConstants
.
An example query on the context store table, when using Derby, 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 FETCH ONLY LAST ROW"; 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.
OSGi notice: To conveniently use other dialects than Derby in an OSGi environment, deploy the according fragment bundle (MySQL, PostgreSQL and SQLite
are available) and further deploy a configuration file in another fragment bundle (with the ContextStore bundle as its host). Another way is to register your
own IJDBCDialect
implementation as an OSGi service before the ContextStore initialization.
IJDBCDialect
,
ContextStoreBuilder
,
DBConstants
Field Summary | |
---|---|
static java.lang.String |
CONFIG_AUTODROP
|
static java.lang.String |
CONFIG_PASSWORD
|
static java.lang.String |
CONFIG_URL
|
static java.lang.String |
CONFIG_USERNAME
|
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 | |
---|---|
JDBCStorage(IJDBCDialect dialect,
java.util.Properties jdbcProps)
Creates a JDBC-based storage with the given dialect, taking the JDBC URL etc. from the given properties |
|
JDBCStorage(IJDBCDialect dialect,
java.lang.String jdbcUrl,
boolean autodrop)
Creates a JDBC-based storage with the given dialect |
|
JDBCStorage(IJDBCDialect dialect,
java.lang.String jdbcUrl,
java.lang.String jdbcUsername,
java.lang.String jdbcPassword,
boolean autodrop)
Creates a JDBC-based storage with the given dialect |
|
JDBCStorage(java.util.Properties jdbcProps)
Creates a JDBC-based storage, taking the JDBC URL etc. from the given properties, auto-detecting the dialect based on the JDBC URL |
|
JDBCStorage(java.lang.String jdbcUrl,
boolean autodrop)
Creates a JDBC-based storage, auto-detecting the dialect based on the JDBC URL |
|
JDBCStorage(java.lang.String jdbcUrl,
java.lang.String jdbcUsername,
java.lang.String jdbcPassword,
boolean autodrop)
Creates a JDBC-based storage, auto-detecting the dialect based on the JDBC URL |
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. |
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, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final java.lang.String CONFIG_URL
public static final java.lang.String CONFIG_AUTODROP
public static final java.lang.String CONFIG_USERNAME
public static final java.lang.String CONFIG_PASSWORD
Constructor Detail |
---|
public JDBCStorage(IJDBCDialect dialect, java.util.Properties jdbcProps)
dialect
- the JDBC dialect to be usedjdbcProps
- the configuration propertiespublic JDBCStorage(java.util.Properties jdbcProps)
jdbcProps
- the configuration propertiespublic JDBCStorage(java.lang.String jdbcUrl, boolean autodrop)
jdbcUrl
- the JDBC URLautodrop
- whether the context store table should be auto-droppedpublic JDBCStorage(java.lang.String jdbcUrl, java.lang.String jdbcUsername, java.lang.String jdbcPassword, boolean autodrop)
jdbcUrl
- the JDBC URLjdbcUsername
- the JDBC usernamejdbcPassword
- the JDBC passwordautodrop
- whether the context store table should be auto-droppedpublic JDBCStorage(IJDBCDialect dialect, java.lang.String jdbcUrl, boolean autodrop)
dialect
- the JDBC dialect to be usedjdbcUrl
- the JDBC URLautodrop
- whether the context store table should be auto-droppedpublic JDBCStorage(IJDBCDialect dialect, java.lang.String jdbcUrl, java.lang.String jdbcUsername, java.lang.String jdbcPassword, boolean autodrop)
dialect
- the JDBC dialect to be usedjdbcUrl
- the JDBC URLjdbcUsername
- the JDBC usernamejdbcPassword
- the JDBC passwordautodrop
- whether the context store table should be auto-droppedMethod 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.Iterable<ContextEvent> queryLazy(boolean deserialize, java.lang.String query, java.lang.Object... params)
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
ISerializedContextStorage.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)
ISerializedContextStorage
ISerializedContextStorage.load(boolean, List)
, i.e. it loads one ContextEvent at a time during iteration. This operation is optional.
loadLazy
in interface ISerializedContextStorage
ISerializedContextStorage.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
public java.lang.Long retrieveLastID()
ISerializedContextStorage
retrieveLastID
in interface ISerializedContextStorage
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |