Class JdbcAgentStateStore

java.lang.Object
io.agentscope.extensions.jdbc.state.JdbcAgentStateStore
All Implemented Interfaces:
io.agentscope.core.state.AgentStateStore

public class JdbcAgentStateStore extends Object implements io.agentscope.core.state.AgentStateStore
Database-agnostic session state store backed by SessionStateDialect.

Implements AgentStateStore with zero inline SQL — every statement is sourced from the dialect via BoundSql.

Author:
shanhongyu
  • Constructor Details

    • JdbcAgentStateStore

      public JdbcAgentStateStore(DataSource dataSource, SessionStateDialect dialect)
      Creates a store with auto-schema creation disabled.
      Parameters:
      dataSource - the JDBC data source
      dialect - the session-state dialect
    • JdbcAgentStateStore

      public JdbcAgentStateStore(DataSource dataSource, SessionStateDialect dialect, boolean createIfNotExist)
      Creates a store with optional auto-schema creation.
      Parameters:
      dataSource - the JDBC data source
      dialect - the session-state dialect
      createIfNotExist - when true, auto-creates the sessions table
  • Method Details

    • save

      public void save(String userId, String sessionId, String key, io.agentscope.core.state.State value)
      Saves a single value unconditionally. Versioned writes use the same SQL helper but do not invoke this public method; subclasses intercepting writes should override both this method and saveIfVersion(java.lang.String, java.lang.String, java.lang.String, io.agentscope.core.state.State, long).
      Specified by:
      save in interface io.agentscope.core.state.AgentStateStore
    • save

      public void save(String userId, String sessionId, String key, List<? extends io.agentscope.core.state.State> values)
      Specified by:
      save in interface io.agentscope.core.state.AgentStateStore
    • supportsVersioning

      public boolean supportsVersioning()
      Specified by:
      supportsVersioning in interface io.agentscope.core.state.AgentStateStore
    • getVersioned

      public <T extends io.agentscope.core.state.State> io.agentscope.core.state.VersionedState<T> getVersioned(String userId, String sessionId, String key, Class<T> type)
      Specified by:
      getVersioned in interface io.agentscope.core.state.AgentStateStore
    • saveIfVersion

      public long saveIfVersion(String userId, String sessionId, String key, io.agentscope.core.state.State value, long expectedVersion)
      Writes and obtains the assigned version in one database transaction. This method does not delegate to save(String, String, String, State), including for unconditional writes, so the version is captured before the write lock is released.
      Specified by:
      saveIfVersion in interface io.agentscope.core.state.AgentStateStore
    • get

      public <T extends io.agentscope.core.state.State> Optional<T> get(String userId, String sessionId, String key, Class<T> type)
      Specified by:
      get in interface io.agentscope.core.state.AgentStateStore
    • getList

      public <T extends io.agentscope.core.state.State> List<T> getList(String userId, String sessionId, String key, Class<T> itemType)
      Specified by:
      getList in interface io.agentscope.core.state.AgentStateStore
    • exists

      public boolean exists(String userId, String sessionId)
      Specified by:
      exists in interface io.agentscope.core.state.AgentStateStore
    • delete

      public void delete(String userId, String sessionId)
      Specified by:
      delete in interface io.agentscope.core.state.AgentStateStore
    • listSessionIds

      public Set<String> listSessionIds(String userId)
      Specified by:
      listSessionIds in interface io.agentscope.core.state.AgentStateStore