Class JdbcStore
- All Implemented Interfaces:
io.agentscope.harness.agent.filesystem.remote.store.BaseStore
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(java.util.List<java.lang.String>, java.lang.String, java.util.Map<java.lang.String, java.lang.Object>, long) 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
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringDefault table name used when the builder is not customised. -
Method Summary
Modifier and TypeMethodDescriptionstatic JdbcStore.Builderbuilder(DataSource dataSource) Creates a builder forJdbcStore.voidio.agentscope.harness.agent.filesystem.remote.store.StoreItemvoidbooleanList<io.agentscope.harness.agent.filesystem.remote.store.StoreItem>
-
Field Details
-
DEFAULT_TABLE_NAME
Default table name used when the builder is not customised.- See Also:
-
-
Method Details
-
builder
Creates a builder forJdbcStore. -
get
public io.agentscope.harness.agent.filesystem.remote.store.StoreItem get(List<String> namespace, String key) - Specified by:
getin interfaceio.agentscope.harness.agent.filesystem.remote.store.BaseStore
-
put
- Specified by:
putin interfaceio.agentscope.harness.agent.filesystem.remote.store.BaseStore
-
putIfVersion
public boolean putIfVersion(List<String> namespace, String key, Map<String, Object> value, long expectedVersion) - Specified by:
putIfVersionin interfaceio.agentscope.harness.agent.filesystem.remote.store.BaseStore
-
search
public List<io.agentscope.harness.agent.filesystem.remote.store.StoreItem> search(List<String> namespace, int limit, int offset) - Specified by:
searchin interfaceio.agentscope.harness.agent.filesystem.remote.store.BaseStore
-
delete
- Specified by:
deletein interfaceio.agentscope.harness.agent.filesystem.remote.store.BaseStore
-