Class AbstractPostgresKeyValueStore<T,S>
- java.lang.Object
-
- org.opennms.features.distributed.kvstore.api.AbstractKeyValueStore<T>
-
- org.opennms.features.distributed.kvstore.api.AbstractAsyncKeyValueStore<T>
-
- org.opennms.features.distributed.kvstore.pgshared.AbstractPostgresKeyValueStore<T,S>
-
- Type Parameters:
T
- the type this store persistsS
- the SQL type this store persists if the value type must be wrapped with an SQL type
- All Implemented Interfaces:
KeyValueStore<T>
- Direct Known Subclasses:
PostgresBlobStore
,PostgresJsonStore
public abstract class AbstractPostgresKeyValueStore<T,S> extends AbstractAsyncKeyValueStore<T>
AKeyValueStore
backed by Postgres.Postgres key value stores should implement this class with concrete types.
-
-
Constructor Summary
Constructors Constructor Description AbstractPostgresKeyValueStore(javax.sql.DataSource dataSource)
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description void
delete(java.lang.String key, java.lang.String context)
java.util.Map<java.lang.String,T>
enumerateContext(java.lang.String context)
java.util.Optional<T>
get(java.lang.String key, java.lang.String context)
java.util.Optional<java.util.Optional<T>>
getIfStale(java.lang.String key, java.lang.String context, long timestamp)
java.util.OptionalLong
getLastUpdated(java.lang.String key, java.lang.String context)
java.lang.String
getName()
protected abstract java.lang.String
getPkConstraintName()
protected S
getSQLTypeFromValueType(T value)
Sub classes should override this method to provide handling for converting from type T to a JDBC type if type T is not a native JDBC type.protected abstract java.lang.String
getTableName()
protected java.lang.String
getValueStatementPlaceholder()
Sub classes should override this to add additional specificity to the SQL placeholder in the prepared statements if necessary.protected abstract T
getValueTypeFromSQLType(java.sql.ResultSet resultSet, java.lang.String columnName)
Sub classes must override this method to provide handling for converting from the JDBC result to type T.long
put(java.lang.String key, T value, java.lang.String context, java.lang.Integer ttlInSeconds)
Put a value with a suggested time-to-live after which the value should be expired and removed from the store.void
truncateContext(java.lang.String context)
A default truncate implementation.-
Methods inherited from class org.opennms.features.distributed.kvstore.api.AbstractAsyncKeyValueStore
deleteAsync, enumerateContextAsync, getAsync, getIfStaleAsync, getLastUpdatedAsync, putAsync, truncateContextAsync
-
Methods inherited from class org.opennms.features.distributed.kvstore.api.AbstractKeyValueStore
put, putAsync
-
-
-
-
Method Detail
-
put
public long put(java.lang.String key, T value, java.lang.String context, java.lang.Integer ttlInSeconds)
Description copied from interface:KeyValueStore
Put a value with a suggested time-to-live after which the value should be expired and removed from the store.Records are expired on a best effort basis and depending on the implementation it is possible to get an expired record.
context
- a context used to differentiate between keys with the same name (forms a compound key)ttlInSeconds
- the time to live in seconds for this key or no ttl if null- Returns:
- the timestamp the value was persisted with
-
get
public java.util.Optional<T> get(java.lang.String key, java.lang.String context)
context
- a context used to differentiate between keys with the same name (forms a compound key)- Returns:
- an optional containing the value if present or empty if the key did not exist
-
getIfStale
public java.util.Optional<java.util.Optional<T>> getIfStale(java.lang.String key, java.lang.String context, long timestamp)
context
- a context used to differentiate between keys with the same name (forms a compound key)timestamp
- the timestamp of the last known state such that if an record with a more recent timestamp is found the provided timestamp will be considered stale and the new record will be returned- Returns:
- an optional that will be empty if the key was not found or will contain another optional that will be empty if not stale or contain the value if stale
-
getLastUpdated
public java.util.OptionalLong getLastUpdated(java.lang.String key, java.lang.String context)
context
- a context used to differentiate between keys with the same name (forms a compound key)- Returns:
- an optional containing the timestamp the key's value was last updated or empty if the key did not exist
-
enumerateContext
public java.util.Map<java.lang.String,T> enumerateContext(java.lang.String context)
- Parameters:
context
- a context used to differentiate between keys with the same name (forms a compound key)- Returns:
- a map of all the records matching the given context where the map's key is the record's key and the map's value is the records value
-
delete
public void delete(java.lang.String key, java.lang.String context)
context
- a context used to differentiate between keys with the same name (forms a compound key)
-
truncateContext
public void truncateContext(java.lang.String context)
Description copied from class:AbstractKeyValueStore
A default truncate implementation.- Specified by:
truncateContext
in interfaceKeyValueStore<T>
- Overrides:
truncateContext
in classAbstractKeyValueStore<T>
- Parameters:
context
- a context used to differentiate between keys with the same name (forms a compound key)
-
getSQLTypeFromValueType
protected S getSQLTypeFromValueType(T value)
Sub classes should override this method to provide handling for converting from type T to a JDBC type if type T is not a native JDBC type.
-
getValueTypeFromSQLType
protected abstract T getValueTypeFromSQLType(java.sql.ResultSet resultSet, java.lang.String columnName) throws java.sql.SQLException
Sub classes must override this method to provide handling for converting from the JDBC result to type T.- Throws:
java.sql.SQLException
-
getValueStatementPlaceholder
protected java.lang.String getValueStatementPlaceholder()
Sub classes should override this to add additional specificity to the SQL placeholder in the prepared statements if necessary.
-
getTableName
protected abstract java.lang.String getTableName()
- Returns:
- the name of the table for this store
-
getPkConstraintName
protected abstract java.lang.String getPkConstraintName()
- Returns:
- the name of the primary key constraint for the table this store persists to
-
getName
public java.lang.String getName()
- Returns:
- the name of the backing implementation
-
-