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.

    • Method Detail

      • 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 the configured 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. Not null.
        Returns:
        One or more WHERE conditions.
      • getKeyColumnsForExpiredEntryReaper

        default java.util.Collection<org.jooq.OrderField<?>> getKeyColumnsForExpiredEntryReaper()
        Returns the ORDER 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 the ORDER BY with key set seek when paged purging of expired entries is enabled.
        Parameters:
        key - The entry key. Not null.
        Returns:
        The ordered key values, null if paging is disabled.
      • getExpiredCondition

        default org.jooq.Condition getExpiredCondition​(long now)
        Returns the WHERE 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 with new 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 per Timestamp.

        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. Not null.
        Returns:
        The SQL record.
      • toInfinispanEntry

        com.nimbusds.infinispan.persistence.common.InfinispanEntry<K,​VtoInfinispanEntry​(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 be null.
        Returns:
        The Infinispan entry (key / value pair with optional metadata).