Class PostgresDialect

java.lang.Object
io.agentscope.extensions.jdbc.dialect.AbstractJdbcDialect
io.agentscope.extensions.jdbc.dialect.vendor.PostgresDialect
All Implemented Interfaces:
SandboxLockStrategy, SessionStateDialect, SnapshotDialect, StoreDialect

public class PostgresDialect extends AbstractJdbcDialect
PostgreSQL dialect — the ANSI baseline.

Business SQL inherits ANSI defaults from the table-domain interfaces. Only create-table DDL and UPSERT syntax (which use PostgreSQL-specific ON CONFLICT and types like TEXT/BYTEA) are overridden.

Author:
shanhongyu
  • Constructor Details

    • PostgresDialect

      public PostgresDialect()
  • Method Details

    • storeCreateTableDdls

      public List<String> storeCreateTableDdls()
      Description copied from interface: StoreDialect
      DDL statements (one or more) to create the KV store table. Must be idempotent.
    • storeUpsert

      public BoundSql storeUpsert(String namespacePath, String key, String json, long timestamp)
      Description copied from interface: StoreDialect
      UPSERT: insert new row with version=1 or update existing row with version+1.
    • sessionStateCreateTableDdls

      public List<String> sessionStateCreateTableDdls()
      Description copied from interface: SessionStateDialect
      DDL statements (one or more) to create the sessions table. Must be idempotent.
    • sessionStateUpsert

      public BoundSql sessionStateUpsert(String sessionId, String stateKey, int itemIndex, String stateData)
      Description copied from interface: SessionStateDialect
      UPSERT a single state value. On conflict, updates state_data.
    • sessionStateCheckTableExists

      public BoundSql sessionStateCheckTableExists(String tableName)
      Description copied from interface: SessionStateDialect
      Table-existence probe SQL. One bind param: the table name.
    • snapshotCreateTableDdls

      public List<String> snapshotCreateTableDdls()
      Description copied from interface: SnapshotDialect
      DDL statements (one or more) to create the snapshots table. Must be idempotent.
    • snapshotUpsert

      public BoundSql snapshotUpsert(String snapshotId, InputStream data)
      Description copied from interface: SnapshotDialect
      Idempotent UPSERT for uploading a snapshot.

      The data param is bound as a binary stream via PreparedStatement.setBinaryStream(int, InputStream) by the client, so snapshots of arbitrary size are streamed straight to the database without loading the whole archive into heap memory.

    • tryEnter

      public io.agentscope.harness.agent.sandbox.SandboxLease tryEnter(String lockName, int timeoutSeconds) throws InterruptedException
      Description copied from interface: SandboxLockStrategy
      Acquires the named lock, blocking until available or timeout expires.
      Specified by:
      tryEnter in interface SandboxLockStrategy
      Overrides:
      tryEnter in class AbstractJdbcDialect
      Parameters:
      lockName - a unique, validated lock name
      timeoutSeconds - maximum wait in seconds
      Returns:
      a lease that releases the lock when closed
      Throws:
      InterruptedException - if the calling thread is interrupted
    • supports

      public boolean supports(DatabaseMetaData metaData) throws SQLException
      Description copied from class: AbstractJdbcDialect
      Whether this dialect supports the target database.
      Specified by:
      supports in class AbstractJdbcDialect
      Parameters:
      metaData - JDBC metadata (connection stays open)
      Returns:
      true if this dialect handles the database
      Throws:
      SQLException - if metadata reading fails