Class PostgresBaseStore

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

public class PostgresBaseStore extends Object implements io.agentscope.harness.agent.filesystem.remote.store.BaseStore
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(java.util.List<java.lang.String>, java.lang.String, java.util.Map<java.lang.String, java.lang.Object>, long) 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.

  • 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 PostgresBaseStore.Builder builder(DataSource dataSource)
      Creates a builder for PostgresBaseStore.
    • 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