Class AbstractJdbcDialect
- All Implemented Interfaces:
SandboxLockStrategy,SessionStateDialect,SnapshotDialect,StoreDialect
- Direct Known Subclasses:
H2Dialect,MysqlDialect,PostgresDialect,SqliteDialect
SandboxLockStrategy contract.
Holds a unified table prefix and per-table name overrides. Vendor classes
extend this class and override only the methods where their SQL diverges from
ANSI defaults. Lock behavior is also overridable: the default tryEnter(java.lang.String, int)
uses a portable table-based lock; vendor dialects with native advisory locks
(e.g. MySQL GET_LOCK, PostgreSQL pg_try_advisory_lock) override
tryEnter.
Table-name resolution priority: per-table override > prefix + base.
The final resolution methods lock the logic in the base class; vendor
dialects inherit them and read the assembled names.
Fields are mutable at assembly time (set by AbstractJdbcDialectBuilder)
and effectively read-only after build() returns.
Auto-detection
from(DataSource) returns a AbstractJdbcDialectBuilder that uses JDK
SPI (ServiceLoader) to discover all dialect implementations on the
classpath. Dialects are sorted by getOrder() (ascending) then by inheritance
depth (child before parent). The first dialect whose supports(DatabaseMetaData)
returns true wins.
- Author:
- shanhongyu
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidbindDataSource(DataSource dataSource) Binds the DataSource used for lock acquisition.static voidCloses a JDBC connection quietly, returning it to the pool when pooled.static voidCloses a JDBC result set quietly.static voidcloseStatement(Statement stmt) Closes a JDBC statement quietly.Collects create-schema DDL for all table-domain interfaces, executed by the builder in a single connection duringbuild().static AbstractJdbcDialectBuilderfrom(DataSource dataSource) Entry point for auto-detection.protected DataSourceReturns the bound DataSource (for vendor lock implementations).intgetOrder()Detection priority (lower wins).protected StringLock table name, derived from the table prefix.final StringBase table name (without prefix).final StringBase table name (without prefix).final StringBase table name (without prefix).abstract booleansupports(DatabaseMetaData metaData) Whether this dialect supports the target database.io.agentscope.harness.agent.sandbox.SandboxLeaseAcquires the named lock, blocking until available or timeout expires.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface io.agentscope.extensions.jdbc.dialect.table.SessionStateDialect
sessionStateCheckTableExists, sessionStateCreateTableDdls, sessionStateDeleteByKey, sessionStateDeleteSession, sessionStateExists, sessionStateInsert, sessionStateInsertIfAbsent, sessionStateLikeEscapeChar, sessionStateListSessionIds, sessionStateSelect, sessionStateSelectList, sessionStateSelectMaxIndex, sessionStateSelectVersioned, sessionStateUpdateIfVersion, sessionStateUpsertMethods inherited from interface io.agentscope.extensions.jdbc.dialect.table.SnapshotDialect
snapshotCreateTableDdls, snapshotExists, snapshotSelect, snapshotUpsertMethods inherited from interface io.agentscope.extensions.jdbc.dialect.table.StoreDialect
storeCasUpdate, storeCreateTableDdls, storeDelete, storeInsert, storeLikeEscapeChar, storeSearch, storeSelect, storeUpsert
-
Constructor Details
-
AbstractJdbcDialect
public AbstractJdbcDialect()
-
-
Method Details
-
storeTableName
Description copied from interface:StoreDialectBase table name (without prefix).- Specified by:
storeTableNamein interfaceStoreDialect
-
sessionStateTableName
Description copied from interface:SessionStateDialectBase table name (without prefix).- Specified by:
sessionStateTableNamein interfaceSessionStateDialect
-
snapshotTableName
Description copied from interface:SnapshotDialectBase table name (without prefix).- Specified by:
snapshotTableNamein interfaceSnapshotDialect
-
createTableDdls
Collects create-schema DDL for all table-domain interfaces, executed by the builder in a single connection duringbuild(). Each table-domain method may return one or more statements (e.g.CREATE TABLEplus a secondaryCREATE INDEX), so no vendor is constrained to a single SQL statement per table.- Returns:
- all DDL statements, in store → sessions → snapshots order
-
bindDataSource
Binds the DataSource used for lock acquisition. Called by the builder andJdbcDistributedStore; not intended for direct application use.If a different DataSource was already bound (e.g. the one the dialect was built with), the replacement is logged so callers notice a mismatched
JdbcDistributedStore.create(dataSource, dialect). -
getDataSource
Returns the bound DataSource (for vendor lock implementations). -
closeConnection
Closes a JDBC connection quietly, returning it to the pool when pooled. Null-safe; a close failure is logged at debug level rather than propagated. Intended for vendor dialects that acquire a dedicated lock connection in theirtryEnterimplementation. -
closeStatement
Closes a JDBC statement quietly. Null-safe; failures are logged, not propagated. -
closeResultSet
Closes a JDBC result set quietly. Null-safe; failures are logged, not propagated. -
supports
Whether this dialect supports the target database.- Parameters:
metaData- JDBC metadata (connection stays open)- Returns:
- true if this dialect handles the database
- Throws:
SQLException- if metadata reading fails
-
getOrder
public int getOrder()Detection priority (lower wins). Default 100. -
lockTableName
Lock table name, derived from the table prefix. -
tryEnter
public io.agentscope.harness.agent.sandbox.SandboxLease tryEnter(String lockName, int timeoutSeconds) throws InterruptedException Description copied from interface:SandboxLockStrategyAcquires the named lock, blocking until available or timeout expires.- Specified by:
tryEnterin interfaceSandboxLockStrategy- Parameters:
lockName- a unique, validated lock nametimeoutSeconds- maximum wait in seconds- Returns:
- a lease that releases the lock when closed
- Throws:
InterruptedException- if the calling thread is interrupted
-
from
Entry point for auto-detection. Returns a builder for chainable configuration.
-