PostgresBaseStore
public class PostgresBaseStore implements BaseStore
io/agentscope/extensions/postgresql/store/PostgresBaseStore.java:73–449Postgres 基类存储,负责持久化与读取数据。位于 io.agentscope.extensions.postgresql.store 包,实现 BaseStore。核心成员包括 builder、get、put、putIfVersion、search、delete。
PostgreSQL-backed BaseStore.
Schema
`CREATE TABLE agentscope_store (
namespace_path VARCHAR(2048) NOT NULL,
item_key VARCHAR(255) NOT NULL,
value_json TEXT NOT NULL,
version BIGINT NOT NULL,
updated_at BIGINT NOT NULL,
PRIMARY KEY (namespace_path, item_key)
)
`
The optional Builder#initializeSchema(true) flag runs
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 uses a single-statement conditional UPDATE keyed on
version. The expectedVersion == 0 case issues an INSERT and treats a
primary-key conflict 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 | `PostgresBaseStore`的构建器。 Builder for `PostgresBaseStore`. |
字段摘要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 | 创建构建器用于`PostgresBaseStore`。 Creates a builder for `PostgresBaseStore`. |
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/postgresql/store/PostgresBaseStore.java:85方法详情Method Detail
builder
public static Builder builder(DataSource dataSource)
创建构建器用于PostgresBaseStore。
Creates a builder for PostgresBaseStore.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
dataSource | DataSource | 数据来源(类型 `DataSource`)。The data source. |
Builderio/agentscope/extensions/postgresql/store/PostgresBaseStore.java:171–173get
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/postgresql/store/PostgresBaseStore.java:197–216put
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/postgresql/store/PostgresBaseStore.java:218–233putIfVersion
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/postgresql/store/PostgresBaseStore.java:235–275search
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/postgresql/store/PostgresBaseStore.java:277–302delete
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/postgresql/store/PostgresBaseStore.java:304–316嵌套类详情Nested Class Detail
Builder
public static final class BuilderPostgresBaseStore的构建器。位于 io.agentscope.extensions.postgresql.store 包。核心成员包括 objectMapper、schemaName、tableName、initializeSchema、build。
Builder for PostgresBaseStore.