T
- the type this store persistsS
- the SQL type this store persists if the value type must be wrapped with an SQL typepublic abstract class AbstractPostgresKeyValueStore<T,S> extends AbstractAsyncKeyValueStore<T>
KeyValueStore
backed by Postgres.
Postgres key value stores should implement this class with concrete types.
Constructor and Description |
---|
AbstractPostgresKeyValueStore(DataSource dataSource) |
Modifier and Type | Method and Description |
---|---|
void |
delete(String key,
String context) |
Map<String,T> |
enumerateContext(String context) |
Optional<T> |
get(String key,
String context) |
Optional<Optional<T>> |
getIfStale(String key,
String context,
long timestamp) |
OptionalLong |
getLastUpdated(String key,
String context) |
String |
getName() |
protected abstract 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 String |
getTableName() |
protected 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(ResultSet resultSet,
String columnName)
Sub classes must override this method to provide handling for converting from the JDBC result to type T.
|
long |
put(String key,
T value,
String context,
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(String context)
A default truncate implementation.
|
deleteAsync, enumerateContextAsync, getAsync, getIfStaleAsync, getLastUpdatedAsync, putAsync, truncateContextAsync
put, putAsync
public AbstractPostgresKeyValueStore(DataSource dataSource)
public long put(String key, T value, String context, Integer ttlInSeconds)
KeyValueStore
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 nullpublic Optional<T> get(String key, String context)
context
- a context used to differentiate between keys with the same name (forms a compound key)public Optional<Optional<T>> getIfStale(String key, 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 returnedpublic OptionalLong getLastUpdated(String key, String context)
context
- a context used to differentiate between keys with the same name (forms a compound key)public Map<String,T> enumerateContext(String context)
context
- a context used to differentiate between keys with the same name (forms a compound key)public void delete(String key, String context)
context
- a context used to differentiate between keys with the same name (forms a compound key)public void truncateContext(String context)
AbstractKeyValueStore
truncateContext
in interface KeyValueStore<T>
truncateContext
in class AbstractKeyValueStore<T>
context
- a context used to differentiate between keys with the same name (forms a compound key)protected S getSQLTypeFromValueType(T value)
protected abstract T getValueTypeFromSQLType(ResultSet resultSet, String columnName) throws SQLException
SQLException
protected String getValueStatementPlaceholder()
protected abstract String getTableName()
protected abstract String getPkConstraintName()
public String getName()
Copyright © 2020. All rights reserved.