Interface SessionStateDialect

All Known Implementing Classes:
AbstractJdbcDialect, H2Dialect, MysqlDialect, PostgresDialect, SqliteDialect

public interface SessionStateDialect
Table-domain dialect interface for the session-state table.

Stores agent state keyed by (session_id, state_key, item_index). Single states use item_index = 0; list states use one row per element.

Method names are prefixed with sessionState to avoid collision when the aggregate class implements multiple table-domain interfaces.

Secondary index: the frequent WHERE session_id = ? and session_id LIKE 'prefix%' queries require an index on session_id. Where the database supports it (MySQL), vendors inline INDEX idx_session (session_id) in the CREATE TABLE statement; the others append an idempotent CREATE INDEX IF NOT EXISTS as a second element of the sessionStateCreateTableDdls() list.

Author:
shanhongyu
  • Method Details

    • sessionStateTableName

      default String sessionStateTableName()
      Base table name (without prefix).
    • sessionStateCreateTableDdls

      List<String> sessionStateCreateTableDdls()
      DDL statements (one or more) to create the sessions table. Must be idempotent.
    • sessionStateUpsert

      BoundSql sessionStateUpsert(String sessionId, String stateKey, int itemIndex, String stateData)
      UPSERT a single state value. On conflict, updates state_data.
    • sessionStateCheckTableExists

      BoundSql sessionStateCheckTableExists(String tableName)
      Table-existence probe SQL. One bind param: the table name.
    • sessionStateInsert

      default BoundSql sessionStateInsert(String sessionId, String stateKey, int itemIndex, String stateData)
      INSERT for list items (one row per element).
    • sessionStateInsertIfAbsent

      default BoundSql sessionStateInsertIfAbsent(String sessionId, String stateKey, int itemIndex, String stateData)
      INSERT of a single state with version = 1. Used by saveIfVersion when expectedVersion == 0 (create-if-absent); on a primary-key conflict the caller falls back to sessionStateUpdateIfVersion(java.lang.String, java.lang.String, int, java.lang.String, long) with expectedVersion = 0 so that rows backfilled at version 0 still satisfy the CAS, and maps a non-zero-version mismatch to AgentStateStore.UNVERSIONED.
    • sessionStateUpdateIfVersion

      default BoundSql sessionStateUpdateIfVersion(String sessionId, String stateKey, int itemIndex, String stateData, long expectedVersion)
      Compare-and-swap UPDATE guarded by version == expectedVersion.
    • sessionStateSelect

      default BoundSql sessionStateSelect(String sessionId, String stateKey, int itemIndex)
      Single-state SELECT by item_index. Projection: state_data.
    • sessionStateSelectVersioned

      default BoundSql sessionStateSelectVersioned(String sessionId, String stateKey, int itemIndex)
      Single-state SELECT with optimistic-concurrency version. Projection: state_data, version.
    • sessionStateSelectList

      default BoundSql sessionStateSelectList(String sessionId, String stateKey)
      Ordered list SELECT. Projection: state_data.
    • sessionStateDeleteByKey

      default BoundSql sessionStateDeleteByKey(String sessionId, String stateKey)
      DELETE all items for a state key.
    • sessionStateDeleteSession

      default BoundSql sessionStateDeleteSession(String sessionId)
      DELETE an entire session.
    • sessionStateSelectMaxIndex

      default BoundSql sessionStateSelectMaxIndex(String sessionId, String stateKey)
      MAX(item_index) for change detection. Returns NULL when no rows exist.
    • sessionStateExists

      default BoundSql sessionStateExists(String sessionId)
      Session-existence probe.
    • sessionStateListSessionIds

      default BoundSql sessionStateListSessionIds(String prefixPattern)
      List distinct session IDs matching a prefix pattern.
    • sessionStateLikeEscapeChar

      default char sessionStateLikeEscapeChar()
      Escape character for LIKE patterns in sessionStateListSessionIds(java.lang.String).