JdbcAgentStateStore
public class JdbcAgentStateStore implements AgentStateStore
io/agentscope/extensions/jdbc/state/JdbcAgentStateStore.java:49–614JDBC 智能体状态存储,负责持久化与读取数据。位于 io.agentscope.extensions.jdbc.state 包,实现 AgentStateStore。核心成员包括 save、supportsVersioning、getVersioned、saveIfVersion、get、getList。
Database-agnostic session state store backed by SessionStateDialect.
Implements AgentStateStore with zero inline SQL — every statement is sourced
from the dialect via BoundSql.
构造器摘要Constructor Summary
| 构造器Constructor | 说明Description |
|---|---|
public JdbcAgentStateStore(DataSource dataSource, SessionStateDialect dialect) | 初始化 `JdbcAgentStateStore` 实例。 Creates a store with auto-schema creation disabled. |
public JdbcAgentStateStore(DataSource dataSource, SessionStateDialect dialect, boolean createIfNotExist) | 初始化 `JdbcAgentStateStore` 实例。 Creates a store with optional auto-schema creation. |
方法摘要Method Summary
构造器详情Constructor Detail
JdbcAgentStateStore
public JdbcAgentStateStore(DataSource dataSource, SessionStateDialect dialect)
初始化 JdbcAgentStateStore 实例。
Creates a store with auto-schema creation disabled.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
dataSource | DataSource | JDBC 数据来源。the JDBC data source |
dialect | SessionStateDialect | dialect(类型 `SessionStateDialect`)。the session-state dialect |
io/agentscope/extensions/jdbc/state/JdbcAgentStateStore.java:65–67JdbcAgentStateStore
public JdbcAgentStateStore(DataSource dataSource, SessionStateDialect dialect, boolean createIfNotExist)
初始化 JdbcAgentStateStore 实例。
Creates a store with optional auto-schema creation.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
dataSource | DataSource | JDBC 数据来源。the JDBC data source |
dialect | SessionStateDialect | dialect(类型 `SessionStateDialect`)。the session-state dialect |
createIfNotExist | boolean | 创建 If 不 Exist(类型 `boolean`)。when true, auto-creates the sessions table |
io/agentscope/extensions/jdbc/state/JdbcAgentStateStore.java:76–85方法详情Method Detail
save
public void save(String userId, String sessionId, String key, State value)
保存数据到持久化存储。
Saves a single value unconditionally.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
userId | String | 用户标识(类型 `String`)。The user id. |
sessionId | String | 会话标识(类型 `String`)。The session id. |
key | String | 键(类型 `String`)。The key. |
value | State | 值(类型 `State`)。The value. |
io/agentscope/extensions/jdbc/state/JdbcAgentStateStore.java:129–144save
public void save(String userId, String sessionId, String key, List<? extends State> values)
保存数据到持久化存储。
Performs the save operation.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
userId | String | 用户标识(类型 `String`)。The user id. |
sessionId | String | 会话标识(类型 `String`)。The session id. |
key | String | 键(类型 `String`)。The key. |
values | List<? extends State> | 值(类型 `List`)。The values. |
io/agentscope/extensions/jdbc/state/JdbcAgentStateStore.java:146–197supportsVersioning
public boolean supportsVersioning()
返回 supportsVersioning 结果。
Returns the supports versioning.
booleanio/agentscope/extensions/jdbc/state/JdbcAgentStateStore.java:199–202getVersioned
public T extends State VersionedState<T> getVersioned(String userId, String sessionId, String key, Class<T> type)
获取 getVersioned。
Returns the versioned.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
userId | String | 用户标识(类型 `String`)。The user id. |
sessionId | String | 会话标识(类型 `String`)。The session id. |
key | String | 键(类型 `String`)。The key. |
type | Class<T> | 类型(类型 `Class`)。The type. |
VersionedState<T>io/agentscope/extensions/jdbc/state/JdbcAgentStateStore.java:204–226saveIfVersion
public long saveIfVersion(String userId, String sessionId, String key, State value, long expectedVersion)
保存If 版本。
Writes and obtains the assigned version in one database transaction.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
userId | String | 用户标识(类型 `String`)。The user id. |
sessionId | String | 会话标识(类型 `String`)。The session id. |
key | String | 键(类型 `String`)。The key. |
value | State | 值(类型 `State`)。The value. |
expectedVersion | long | expected 版本(类型 `long`)。The expected version. |
longio/agentscope/extensions/jdbc/state/JdbcAgentStateStore.java:246–297get
public T extends State Optional<T> get(String userId, String sessionId, String key, Class<T> type)
按条件读取数据。
Performs the get operation.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
userId | String | 用户标识(类型 `String`)。The user id. |
sessionId | String | 会话标识(类型 `String`)。The session id. |
key | String | 键(类型 `String`)。The key. |
type | Class<T> | 类型(类型 `Class`)。The type. |
Optional<T>io/agentscope/extensions/jdbc/state/JdbcAgentStateStore.java:320–341getList
public T extends State List<T> getList(String userId, String sessionId, String key, Class<T> itemType)
获取列表。
Returns the list.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
userId | String | 用户标识(类型 `String`)。The user id. |
sessionId | String | 会话标识(类型 `String`)。The session id. |
key | String | 键(类型 `String`)。The key. |
itemType | Class<T> | 条目类型(类型 `Class`)。The item type. |
List<T>io/agentscope/extensions/jdbc/state/JdbcAgentStateStore.java:343–366exists
public boolean exists(String userId, String sessionId)
判断数据是否存在。
Performs the exists operation.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
userId | String | 用户标识(类型 `String`)。The user id. |
sessionId | String | 会话标识(类型 `String`)。The session id. |
booleanio/agentscope/extensions/jdbc/state/JdbcAgentStateStore.java:368–383delete
public void delete(String userId, String sessionId)
删除数据。
Performs the delete operation.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
userId | String | 用户标识(类型 `String`)。The user id. |
sessionId | String | 会话标识(类型 `String`)。The session id. |
io/agentscope/extensions/jdbc/state/JdbcAgentStateStore.java:385–403listSessionIds
public Set<String> listSessionIds(String userId)
列出 listSessionIds。
Lists the session ids.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
userId | String | 用户标识(类型 `String`)。The user id. |
Set<String>io/agentscope/extensions/jdbc/state/JdbcAgentStateStore.java:405–428