Class JdbcAgentStateStore
java.lang.Object
io.agentscope.extensions.jdbc.state.JdbcAgentStateStore
- All Implemented Interfaces:
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
-
Field Summary
Fields inherited from interface io.agentscope.core.state.AgentStateStore
UNVERSIONED -
Constructor Summary
ConstructorsConstructorDescriptionJdbcAgentStateStore(DataSource dataSource, SessionStateDialect dialect) Creates a store with auto-schema creation disabled.JdbcAgentStateStore(DataSource dataSource, SessionStateDialect dialect, boolean createIfNotExist) Creates a store with optional auto-schema creation. -
Method Summary
Modifier and TypeMethodDescriptionvoidboolean<T extends io.agentscope.core.state.State>
Optional<T><T extends io.agentscope.core.state.State>
List<T><T extends io.agentscope.core.state.State>
io.agentscope.core.state.VersionedState<T>getVersioned(String userId, String sessionId, String key, Class<T> type) listSessionIds(String userId) voidSaves a single value unconditionally.voidsave(String userId, String sessionId, String key, List<? extends io.agentscope.core.state.State> values) longsaveIfVersion(String userId, String sessionId, String key, io.agentscope.core.state.State value, long expectedVersion) Writes and obtains the assigned version in one database transaction.booleanMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface io.agentscope.core.state.AgentStateStore
close, delete
-
Constructor Details
-
JdbcAgentStateStore
Creates a store with auto-schema creation disabled.- Parameters:
dataSource- the JDBC data sourcedialect- 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 sourcedialect- the session-state dialectcreateIfNotExist- when true, auto-creates the sessions table
-
-
Method Details
-
save
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 andsaveIfVersion(java.lang.String, java.lang.String, java.lang.String, io.agentscope.core.state.State, long).- Specified by:
savein interfaceio.agentscope.core.state.AgentStateStore
-
save
public void save(String userId, String sessionId, String key, List<? extends io.agentscope.core.state.State> values) - Specified by:
savein interfaceio.agentscope.core.state.AgentStateStore
-
supportsVersioning
public boolean supportsVersioning()- Specified by:
supportsVersioningin interfaceio.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:
getVersionedin interfaceio.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 tosave(String, String, String, State), including for unconditional writes, so the version is captured before the write lock is released.- Specified by:
saveIfVersionin interfaceio.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:
getin interfaceio.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:
getListin interfaceio.agentscope.core.state.AgentStateStore
-
exists
- Specified by:
existsin interfaceio.agentscope.core.state.AgentStateStore
-
delete
- Specified by:
deletein interfaceio.agentscope.core.state.AgentStateStore
-
listSessionIds
- Specified by:
listSessionIdsin interfaceio.agentscope.core.state.AgentStateStore
-