@groovy.transform.CompileStatic class DatabaseCleanupStats extends java.lang.Object
Captures statistics from a single datasource cleanup operation, including which tables were truncated and how many rows were in each table before truncation.
The datasourceName field identifies which datasource these stats belong to.
The tableRowCounts map tracks per-table row counts using a default of 0L
for unknown keys, enabling convenient += accumulation.
Individual cleanup timing can be tracked using the start() and stop() methods. These capture the start and end times for schema/datasource purging.
When debug output is enabled via the grails.testing.cleanup.debug system property,
the toFormattedReport() method produces a human-readable summary suitable for
printing to the console.
| Type | Name and description |
|---|---|
static java.lang.String |
DEBUG_PROPERTYSystem property that enables debug output of cleanup statistics to stdout. |
java.lang.String |
datasourceNameThe name of the datasource bean that was cleaned up (e.g., "dataSource"). |
boolean |
detailedStatCollectionWhether detailed debug is enabled so row level counts are collected |
long |
endTimeMillisThe end time of the cleanup operation in milliseconds since epoch. |
long |
startTimeMillisThe start time of the cleanup operation in milliseconds since epoch. |
java.util.Map<java.lang.String, java.lang.Long> |
tableRowCountsMap of table names to the number of rows that existed before truncation. |
| Constructor and description |
|---|
DatabaseCleanupStats() |
| Type Params | Return Type | Name and description |
|---|---|---|
|
void |
addTableRowCount(java.lang.String tableName, long rowCount) |
|
static java.lang.String |
formatTime(long timeMillis)Formats a timestamp in milliseconds as an ISO 8601 string. |
|
long |
getDurationMillis()Calculates the duration of the cleanup operation in milliseconds. |
|
static boolean |
isDebugEnabled()Returns true if the grails.testing.cleanup.debug system property
is set to "true". |
|
void |
start()Starts the timer for individual schema/datasource cleanup. |
|
void |
stop()Stops the timer for individual schema/datasource cleanup. |
|
java.lang.String |
toFormattedReport()Returns a human-readable formatted report of the cleanup statistics. |
| 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) |
System property that enables debug output of cleanup statistics to stdout.
Set to "true" to enable: -Dgrails.testing.cleanup.debug=true
The name of the datasource bean that was cleaned up (e.g., "dataSource").
May be null if not set by the caller.
Whether detailed debug is enabled so row level counts are collected
The end time of the cleanup operation in milliseconds since epoch. Set by calling stop() after cleaning completes.
The start time of the cleanup operation in milliseconds since epoch. Set by calling start() before cleaning begins.
Map of table names to the number of rows that existed before truncation.
Uses a default value of 0L for unknown keys, enabling += accumulation.
Formats a timestamp in milliseconds as an ISO 8601 string.
timeMillis - the timestamp in milliseconds since epochCalculates the duration of the cleanup operation in milliseconds.
Returns true if the grails.testing.cleanup.debug system property
is set to "true".
Starts the timer for individual schema/datasource cleanup. Records the current time as the start time.
Stops the timer for individual schema/datasource cleanup. Records the current time as the end time.
Returns a human-readable formatted report of the cleanup statistics.
Example output:
========================================================== Database Cleanup Stats (datasource: dataSource) Start Time: 2024-02-21T12:34:56.789Z End Time: 2024-02-21T12:34:57.123Z Duration: 334 ms ========================================================== Table Name | Row Count ---------------------------------------------------------- BOOK | 5 AUTHOR | 3 ==========================================================