Package ai.specformula.spring
Class TrackingDataSource
java.lang.Object
ai.specformula.spring.TrackingDataSource
- All Implemented Interfaces:
Wrapper,CommonDataSource,DataSource
JDBC DataSource 追蹤代理,本身即為
DataSource。
透過 JDK 動態代理攔截 getConnection() 回傳的 Connection / Statement, 解析 SQL 中的
INSERT INTO 並記錄被寫入的 table。 清理時只清理 dirty tables,大幅減少 disposeWorld 時間。
由 TestcontainerFactory 建立時自動包裝;
SpecFormulaBridge.setDataSource(String, DataSource)
會以 instanceof TrackingDataSource 判斷是否啟用 dirty table tracking。
-
Method Summary
Modifier and TypeMethodDescriptionvoid清除 dirty table 記錄(每個 scenario 結束後呼叫)。getConnection(String username, String password) 取得被 INSERT 過的 table 名稱集合。int取得原始 DataSource。booleanisWrapperFor(Class<?> iface) voidsetLoginTimeout(int seconds) voidsetLogWriter(PrintWriter out) <T> Tstatic TrackingDataSourcewrap(DataSource ds) 包裝 DataSource,回傳 TrackingDataSource 實例。Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface javax.sql.CommonDataSource
createShardingKeyBuilderMethods inherited from interface javax.sql.DataSource
createConnectionBuilder
-
Method Details
-
wrap
包裝 DataSource,回傳 TrackingDataSource 實例。 -
getOriginal
取得原始 DataSource。 -
getDirtyTables
取得被 INSERT 過的 table 名稱集合。 -
clearDirtyTables
public void clearDirtyTables()清除 dirty table 記錄(每個 scenario 結束後呼叫)。 -
getConnection
- Specified by:
getConnectionin interfaceDataSource- Throws:
SQLException
-
getConnection
- Specified by:
getConnectionin interfaceDataSource- Throws:
SQLException
-
getLogWriter
- Specified by:
getLogWriterin interfaceCommonDataSource- Specified by:
getLogWriterin interfaceDataSource- Throws:
SQLException
-
setLogWriter
- Specified by:
setLogWriterin interfaceCommonDataSource- Specified by:
setLogWriterin interfaceDataSource- Throws:
SQLException
-
setLoginTimeout
- Specified by:
setLoginTimeoutin interfaceCommonDataSource- Specified by:
setLoginTimeoutin interfaceDataSource- Throws:
SQLException
-
getLoginTimeout
- Specified by:
getLoginTimeoutin interfaceCommonDataSource- Specified by:
getLoginTimeoutin interfaceDataSource- Throws:
SQLException
-
getParentLogger
- Specified by:
getParentLoggerin interfaceCommonDataSource- Throws:
SQLFeatureNotSupportedException
-
unwrap
- Specified by:
unwrapin interfaceWrapper- Throws:
SQLException
-
isWrapperFor
- Specified by:
isWrapperForin interfaceWrapper- Throws:
SQLException
-