JdbcStore
public class JdbcStore implements BaseStore
io/agentscope/extensions/mysql/store/JdbcStore.java:74–418JDBC 存储,负责持久化与读取数据。位于 io.agentscope.extensions.mysql.store 包,实现 BaseStore。核心成员包括 builder、get、put、putIfVersion、search、delete。
JDBC-backed BaseStore. Supports MySQL, PostgreSQL, SQLite, and H2 out of the box via
JdbcStoreDialect.
Schema
`CREATE TABLE agentscope_store (
namespace_path -- VARCHAR (PG/MySQL/H2) or TEXT (SQLite), joined namespace + trailing 0x1F
item_key -- VARCHAR or TEXT, item key
value_json -- TEXT / LONGTEXT / CLOB, Jackson-serialised Map<String, Object>
version -- BIGINT, monotonically increasing per row
updated_at -- BIGINT, epoch millis of the last write
PRIMARY KEY (namespace_path, item_key)
)
`
The optional Builder#initializeSchema(true) flag runs the dialect's
CREATE TABLE IF NOT EXISTS on construction.
Namespace encoding
To preserve the prefix-search behaviour of InMemoryStore,
the namespace components are joined with the ASCII unit-separator 0x1F and stored with a
trailing separator. Searching by namespace [a, b] translates into
WHERE namespace_path LIKE 'ab%' ESCAPE '!', which matches both that exact
namespace and any deeper sub-namespace. Namespace segments that contain 0x1F are
rejected.
CAS
#putIfVersion runs a single-statement conditional UPDATE keyed on version.
The expectedVersion == 0 case (create-if-absent) issues an INSERT instead and treats a
primary-key violation as a failed CAS. Both paths are atomic without additional locking, so the
store is safe to share among multiple JVMs writing to the same database.
嵌套类摘要Nested Class Summary
| 类Class | 类型Kind | 说明Description |
|---|---|---|
Builder | 类class | `JdbcStore`的构建器。 Builder for `JdbcStore`. |
字段摘要Field Summary
| 字段Field | 类型Type | 说明Description |
|---|---|---|
DEFAULT_TABLE_NAMEstaticfinal | String | 默认 TABLE 名称字段。 Default table name used when the builder is not customised. |
方法摘要Method Summary
| 方法Method | 说明Description |
|---|---|
public static Builder builder(DataSource dataSource)static | 创建构建器用于`JdbcStore`。 Creates a builder for `JdbcStore`. |
public StoreItem get(List<String> namespace, String key) | 按条件读取数据。 Performs the get operation. |
public void put(List<String> namespace, String key, Map<String, Object> value) | 执行 `put` 方法。 Performs the put operation. |
public boolean putIfVersion(List<String> namespace, String key, Map<String, Object> value, long expectedVersion) | 执行 `putIfVersion` 方法。 Performs the put if version operation. |
public List<StoreItem> search(List<String> namespace, int limit, int offset) | 执行搜索相关操作。 Performs the search operation. |
public void delete(List<String> namespace, String key) | 删除数据。 Performs the delete operation. |
字段详情Field Detail
DEFAULT_TABLE_NAME
public static final String DEFAULT_TABLE_NAME
默认 TABLE 名称字段。声明为 public static final String DEFAULT_TABLE_NAME。
Default table name used when the builder is not customised.
io/agentscope/extensions/mysql/store/JdbcStore.java:86方法详情Method Detail
builder
public static Builder builder(DataSource dataSource)
创建构建器用于JdbcStore。
Creates a builder for JdbcStore.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
dataSource | DataSource | 数据来源(类型 `DataSource`)。The data source. |
Builderio/agentscope/extensions/mysql/store/JdbcStore.java:120–122get
public StoreItem get(List<String> namespace, String key)
按条件读取数据。
Performs the get operation.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
namespace | List<String> | 命名空间(类型 `List`)。The namespace. |
key | String | 键(类型 `String`)。The key. |
StoreItemio/agentscope/extensions/mysql/store/JdbcStore.java:139–158put
public void put(List<String> namespace, String key, Map<String, Object> value)
执行 put 方法。
Performs the put operation.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
namespace | List<String> | 命名空间(类型 `List`)。The namespace. |
key | String | 键(类型 `String`)。The key. |
value | Map<String, Object> | 值(类型 `Map`)。The value. |
io/agentscope/extensions/mysql/store/JdbcStore.java:160–175putIfVersion
public boolean putIfVersion(List<String> namespace, String key, Map<String, Object> value, long expectedVersion)
执行 putIfVersion 方法。
Performs the put if version operation.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
namespace | List<String> | 命名空间(类型 `List`)。The namespace. |
key | String | 键(类型 `String`)。The key. |
value | Map<String, Object> | 值(类型 `Map`)。The value. |
expectedVersion | long | expected 版本(类型 `long`)。The expected version. |
booleanio/agentscope/extensions/mysql/store/JdbcStore.java:177–219search
public List<StoreItem> search(List<String> namespace, int limit, int offset)
执行搜索相关操作。
Performs the search operation.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
namespace | List<String> | 命名空间(类型 `List`)。The namespace. |
limit | int | 数量上限(类型 `int`)。The limit. |
offset | int | 偏移量(类型 `int`)。The offset. |
List<StoreItem>io/agentscope/extensions/mysql/store/JdbcStore.java:221–246delete
public void delete(List<String> namespace, String key)
删除数据。
Performs the delete operation.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
namespace | List<String> | 命名空间(类型 `List`)。The namespace. |
key | String | 键(类型 `String`)。The key. |
io/agentscope/extensions/mysql/store/JdbcStore.java:248–260嵌套类详情Nested Class Detail
Builder
public static final class BuilderJdbcStore的构建器。位于 io.agentscope.extensions.mysql.store 包。核心成员包括 dialect、objectMapper、tableName、initializeSchema、build。
Builder for JdbcStore.