AbstractJdbcDialect
public abstract class AbstractJdbcDialect implements StoreDialect, SessionStateDialect, SnapshotDialect, SandboxLockStrategy
io/agentscope/extensions/jdbc/dialect/AbstractJdbcDialect.java:64–368抽象 JDBC Dialect,在多次调用之间保存和恢复会话与记忆数据。位于 io.agentscope.extensions.jdbc.dialect 包,实现 StoreDialect、SessionStateDialect、SnapshotDialect、SandboxLockStrategy。核心成员包括 storeTableName、sessionStateTableName、snapshotTableName、createTableDdls、bindDataSource、getDataSource。
Aggregate dialect abstract class — implements all table-domain interfaces and the
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
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 (java.util.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.
方法摘要Method Summary
| 方法Method | 说明Description |
|---|---|
public final String storeTableName()final | 返回 `storeTableName` 结果。 Returns the store table name. |
public final String sessionStateTableName()final | 返回 `sessionStateTableName` 结果。 Returns the session state table name. |
public final String snapshotTableName()final | 返回 `snapshotTableName` 结果。 Returns the snapshot table name. |
protected List<String> createTableDdls() | 创建 `createTableDdls`。 Collects create-schema DDL for all table-domain interfaces, executed by the builder
in a single connection during `build()`. |
public void bindDataSource(DataSource dataSource) | 设置该参数。 Binds the DataSource used for lock acquisition. |
protected DataSource getDataSource() | 获取数据来源。 Returns the bound DataSource (for vendor lock implementations). |
public static void closeConnection(Connection con)static | 关闭连接。 Closes a JDBC connection quietly, returning it to the pool when pooled. |
public static void closeStatement(Statement stmt)static | 关闭 `closeStatement`。 Closes a JDBC statement quietly. |
public static void closeResultSet(ResultSet rs)static | 关闭结果设置。 Closes a JDBC result set quietly. |
public abstract boolean supports(DatabaseMetaData metaData) throws SQLExceptionabstract | 设置支持。 Whether this dialect supports the target database. |
public int getOrder() | 获取顺序。 Detection priority (lower wins). |
protected String lockTableName() | 返回 `lockTableName` 结果。 Lock table name, derived from the table prefix. |
public SandboxLease tryEnter(String lockName, int timeoutSeconds) throws InterruptedException | 执行 `tryEnter` 方法。 Performs the try enter operation. |
public static AbstractJdbcDialectBuilder from(DataSource dataSource)static | 创建并返回实例。 Entry point for auto-detection. |
方法详情Method Detail
storeTableName
public final String storeTableName()
返回 storeTableName 结果。
Returns the store table name.
Stringio/agentscope/extensions/jdbc/dialect/AbstractJdbcDialect.java:92–96sessionStateTableName
public final String sessionStateTableName()
返回 sessionStateTableName 结果。
Returns the session state table name.
Stringio/agentscope/extensions/jdbc/dialect/AbstractJdbcDialect.java:98–103snapshotTableName
public final String snapshotTableName()
返回 snapshotTableName 结果。
Returns the snapshot table name.
Stringio/agentscope/extensions/jdbc/dialect/AbstractJdbcDialect.java:105–110createTableDdls
protected List<String> createTableDdls()
创建 createTableDdls。
Collects create-schema DDL for all table-domain interfaces, executed by the builder in a single connection during build().
List<String>io/agentscope/extensions/jdbc/dialect/AbstractJdbcDialect.java:124–130bindDataSource
public void bindDataSource(DataSource dataSource)
设置该参数。
Binds the DataSource used for lock acquisition.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
dataSource | DataSource | 数据来源(类型 `DataSource`)。The data source. |
io/agentscope/extensions/jdbc/dialect/AbstractJdbcDialect.java:160–170getDataSource
protected DataSource getDataSource()
获取数据来源。
Returns the bound DataSource (for vendor lock implementations).
DataSourceio/agentscope/extensions/jdbc/dialect/AbstractJdbcDialect.java:173–180closeConnection
public static void closeConnection(Connection con)
关闭连接。
Closes a JDBC connection quietly, returning it to the pool when pooled.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
con | Connection | con(类型 `Connection`)。The con. |
io/agentscope/extensions/jdbc/dialect/AbstractJdbcDialect.java:187–197closeStatement
public static void closeStatement(Statement stmt)
关闭 closeStatement。
Closes a JDBC statement quietly.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
stmt | Statement | stmt(类型 `Statement`)。The stmt. |
io/agentscope/extensions/jdbc/dialect/AbstractJdbcDialect.java:200–210closeResultSet
public static void closeResultSet(ResultSet rs)
关闭结果设置。
Closes a JDBC result set quietly.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
rs | ResultSet | rs(类型 `ResultSet`)。The rs. |
io/agentscope/extensions/jdbc/dialect/AbstractJdbcDialect.java:213–223supports
public abstract boolean supports(DatabaseMetaData metaData) throws SQLException
设置支持。
Whether this dialect supports the target database.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
metaData | DatabaseMetaData | 元数据(类型 `DatabaseMetaData`)。JDBC metadata (connection stays open) |
booleanSQLException可能抛出 `SQLException`。Thrown when the operation cannot be completed.
io/agentscope/extensions/jdbc/dialect/AbstractJdbcDialect.java:236getOrder
public int getOrder()
获取顺序。
Detection priority (lower wins).
intio/agentscope/extensions/jdbc/dialect/AbstractJdbcDialect.java:241–243lockTableName
protected String lockTableName()
返回 lockTableName 结果。
Lock table name, derived from the table prefix.
Stringio/agentscope/extensions/jdbc/dialect/AbstractJdbcDialect.java:253–255tryEnter
public SandboxLease tryEnter(String lockName, int timeoutSeconds) throws InterruptedException
执行 tryEnter 方法。
Performs the try enter operation.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
lockName | String | 锁名称(类型 `String`)。The lock name. |
timeoutSeconds | int | 超时秒(类型 `int`)。The timeout seconds. |
SandboxLeaseInterruptedException可能抛出 `InterruptedException`。Thrown when the operation cannot be completed.
io/agentscope/extensions/jdbc/dialect/AbstractJdbcDialect.java:257–294from
public static AbstractJdbcDialectBuilder from(DataSource dataSource)
创建并返回实例。
Entry point for auto-detection.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
dataSource | DataSource | 数据来源(类型 `DataSource`)。The data source. |
AbstractJdbcDialectBuilderio/agentscope/extensions/jdbc/dialect/AbstractJdbcDialect.java:362–367继承成员Inherited Members
SessionStateDialectsessionStateCreateTableDdls, sessionStateUpsert, sessionStateCheckTableExists, sessionStateInsert, sessionStateInsertIfAbsent, sessionStateUpdateIfVersion, sessionStateSelect, sessionStateSelectVersioned, sessionStateSelectList, sessionStateDeleteByKey, sessionStateDeleteSession, sessionStateSelectMaxIndex, sessionStateExists, sessionStateListSessionIds, sessionStateLikeEscapeChar