@groovy.transform.Trait @groovy.transform.CompileStatic trait DatabaseCleaner extends java.lang.Object
SPI interface for database-specific cleanup implementations.
Implementations are discovered via the java.util.ServiceLoader mechanism. Each implementation must declare the database type it supports via databaseType(). The type identifier must be unique across all implementations on the classpath; if two implementations declare the same type, the framework will throw an error at startup.
Implementations must be registered in
META-INF/services/org.apache.grails.testing.cleanup.core.DatabaseCleaner.
| Type Params | Return Type | Name and description |
|---|---|---|
|
abstract DatabaseCleanupStats |
cleanup(ApplicationContext applicationContext, javax.sql.DataSource dataSource)Performs the cleanup (truncation) of all tables in the given datasource. |
|
void |
cleanupCacheLayer(ApplicationContext applicationContext)Optional callback to evict the Hibernate second-level cache after database cleanup. |
|
abstract java.lang.String |
databaseType()Returns the database type that this cleaner supports (e.g., "h2", "mysql",
"postgresql"). |
|
abstract boolean |
supports(javax.sql.DataSource dataSource)Returns true if this cleaner supports the given javax.sql.DataSource.
|
| Methods inherited from class | Name |
|---|---|
class java.lang.Object |
java.lang.Object#equals(java.lang.Object), java.lang.Object#getClass(), java.lang.Object#hashCode(), java.lang.Object#notify(), java.lang.Object#notifyAll(), java.lang.Object#toString(), java.lang.Object#wait(), java.lang.Object#wait(long), java.lang.Object#wait(long, int) |
Performs the cleanup (truncation) of all tables in the given datasource.
applicationContext - the application contextdataSource - the datasource to cleanOptional callback to evict the Hibernate second-level cache after database cleanup. This is necessary for tests that rely on Hibernate's caching behavior and want to ensure a clean state after truncation. Implementations can check for the presence of Hibernate and evict the cache if applicable.
applicationContext - the application context Returns the database type that this cleaner supports (e.g., "h2", "mysql",
"postgresql"). This value is used to match cleaners to data sources at runtime and
must be unique across all DatabaseCleaner implementations on the classpath.
Returns true if this cleaner supports the given javax.sql.DataSource.
The framework calls this method to determine which cleaner to use for each datasource.
dataSource - the datasource to checktrue if this cleaner can handle the given datasource