Class JdbcStore

java.lang.Object
io.agentscope.extensions.mysql.store.JdbcStore
All Implemented Interfaces:
io.agentscope.harness.agent.filesystem.remote.store.BaseStore

public class JdbcStore extends Object implements io.agentscope.harness.agent.filesystem.remote.store.BaseStore
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(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.

  • Field Details

    • DEFAULT_TABLE_NAME

      public static final String DEFAULT_TABLE_NAME
      Default table name used when the builder is not customised.
      See Also:
  • Method Details

    • builder

      public static JdbcStore.Builder builder(DataSource dataSource)
      Creates a builder for JdbcStore.
    • get

      public io.agentscope.harness.agent.filesystem.remote.store.StoreItem get(List<String> namespace, String key)
      Specified by:
      get in interface io.agentscope.harness.agent.filesystem.remote.store.BaseStore
    • put

      public void put(List<String> namespace, String key, Map<String,Object> value)
      Specified by:
      put in interface io.agentscope.harness.agent.filesystem.remote.store.BaseStore
    • putIfVersion

      public boolean putIfVersion(List<String> namespace, String key, Map<String,Object> value, long expectedVersion)
      Specified by:
      putIfVersion in interface io.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:
      search in interface io.agentscope.harness.agent.filesystem.remote.store.BaseStore
    • delete

      public void delete(List<String> namespace, String key)
      Specified by:
      delete in interface io.agentscope.harness.agent.filesystem.remote.store.BaseStore