Interface SQLRecordTransformer<K,V>
-
public interface SQLRecordTransformer<K,V>
Interface for transforming between Infinispan entries (key / value pair and metadata) and a corresponding SQL record. Implementations must be thread-safe.To specify an entry transformer for a given Infinispan cache that is backed by an SQL store, provide its class name to the
store configuration
.
-
-
Nested Class Summary
Nested Classes Modifier and Type Interface Description static interface
SQLRecordTransformer.InitParameters
SQL transformer initialisation parameters.
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description java.lang.String
getCreateTableStatement()
Returns the SQL statement to create a table for the entries.default org.jooq.Condition
getExpiredCondition(long now)
Returns theWHERE
condition to select expired entries.default java.util.Collection<org.jooq.OrderField<?>>
getKeyColumnsForExpiredEntryReaper()
Returns theORDER BY
key columns for paged purging of expired entries.default java.util.List<java.lang.Object>
getKeyValuesForExpiredEntryReaper(K key)
Returns the ordered key values for theORDER BY
with key set seek whenpaged purging of expired entries
is enabled.java.lang.String
getTableName()
Returns the associated SQL table name.void
init(SQLRecordTransformer.InitParameters initParams)
Initialises the SQL transformer.java.util.Collection<org.jooq.Condition>
resolveSelectionConditions(K key)
Resolves the SQL selection conditions for the specified Infinispan entry key.com.nimbusds.infinispan.persistence.common.InfinispanEntry<K,V>
toInfinispanEntry(RetrievedSQLRecord sqlRecord)
Transforms the specified SQL record to an Infinispan entry (key / value / metadata triple).SQLRecord
toSQLRecord(com.nimbusds.infinispan.persistence.common.InfinispanEntry<K,V> infinispanEntry)
Transforms the specified Infinispan entry (key / value pair with optional metadata) to an SQL record ready to be written.
-
-
-
Method Detail
-
init
void init(SQLRecordTransformer.InitParameters initParams)
Initialises the SQL transformer.- Parameters:
initParams
- The initialisation parameters.
-
getCreateTableStatement
java.lang.String getCreateTableStatement()
Returns the SQL statement to create a table for the entries. Typically required at SQL store startup if the underlying table doesn't exist yet. The statement must be aware of the SQL dialect of theconfigured
database.- Returns:
- The SQL create table statement.
-
getTableName
java.lang.String getTableName()
Returns the associated SQL table name.- Returns:
- The table name.
-
resolveSelectionConditions
java.util.Collection<org.jooq.Condition> resolveSelectionConditions(K key)
Resolves the SQL selection conditions for the specified Infinispan entry key.- Parameters:
key
- The Infinispan entry key. Notnull
.- Returns:
- One or more WHERE conditions.
-
getKeyColumnsForExpiredEntryReaper
default java.util.Collection<org.jooq.OrderField<?>> getKeyColumnsForExpiredEntryReaper()
Returns theORDER BY
key columns for paged purging of expired entries.- Returns:
- The key columns,
null
prevents paging.
-
getKeyValuesForExpiredEntryReaper
default java.util.List<java.lang.Object> getKeyValuesForExpiredEntryReaper(K key)
Returns the ordered key values for theORDER BY
with key set seek whenpaged purging of expired entries
is enabled.- Parameters:
key
- The entry key. Notnull
.- Returns:
- The ordered key values,
null
if paging is disabled.
-
getExpiredCondition
default org.jooq.Condition getExpiredCondition(long now)
Returns theWHERE
condition to select expired entries.Use
new Timestamp(System.currentTimeMillis())
in the SQL query to determine the current timestamp, as this will guarantee it matches the timezone of the timestamps in the stored record (also created withnew Timestamp()
).Do not use
DSL.currentTimestamp()
, because the MySQL and Microsoft SQL Server function returns the current UTC time, not the current local time as perTimestamp
.- Parameters:
now
- The current system time, in milliseconds since the Unix epoch.- Returns:
- The expired condition,
null
if not available.
-
toSQLRecord
SQLRecord toSQLRecord(com.nimbusds.infinispan.persistence.common.InfinispanEntry<K,V> infinispanEntry)
Transforms the specified Infinispan entry (key / value pair with optional metadata) to an SQL record ready to be written.Example:
Infinispan entry:
- Key: cae7t
- Value: Java POJO with fields
uid=cae7t
,givenName=Alice
,surname=Adams
and[email protected]
. - Metadata: Specifies the entry expiration and other properties.
Resulting SQL record:
uid: cae7t (key) surname: Adams given_name: Alice email: [email protected]
- Parameters:
infinispanEntry
- The Infinispan entry. Notnull
.- Returns:
- The SQL record.
-
toInfinispanEntry
com.nimbusds.infinispan.persistence.common.InfinispanEntry<K,V> toInfinispanEntry(RetrievedSQLRecord sqlRecord)
Transforms the specified SQL record to an Infinispan entry (key / value / metadata triple).Example:
SQL record:
uid: cae7t surname: Adams given_name: Alice email: [email protected]
Resulting Infinispan entry:
- Key: cae7t
- Value: Java POJO with fields
uid=cae7t
,givenName=Alice
,surname=Adams
and[email protected]
. - Metadata: Default metadata (no expiration, etc).
- Parameters:
sqlRecord
- The SQL record. Must not benull
.- Returns:
- The Infinispan entry (key / value pair with optional metadata).
-
-