Data Guard Plugin
Data Guard Plugin rejects dangerous write and table operations according to user-defined policies.
Enable DataGuard
DataGuardPlugin checks Kronos write and table operations before execution. Enable it during application startup when the application should reject full-table write operations and destructive table operations by default.
kotlin
import com.kotlinorm.plugins.DataGuardPlugin
DataGuardPlugin.enable()Disable it when the same process needs to run without DataGuard checks.
disable
DataGuardPlugin.disable()DataGuard reads table and condition information from Kronos DSL and table operation APIs. Guard raw SQL at the boundary where your application creates and executes that SQL.
Block full-table delete
With the default policy, a delete without by or where is rejected.
kotlin
DataGuardPlugin.enable()
User()
.delete()
.execute()The operation stops before it reaches the data source.
result
UnsupportedOperationException: Delete operation is not allowed.Add an explicit condition for a delete that targets known rows.
with where
User()
.delete()
.where { it.id == 1 }
.execute()Block full-table update
With the default policy, an update that has no generated WHERE clause is rejected.
kotlin
DataGuardPlugin.enable()
User()
.update()
.set { it.status = "LOCKED" }
.execute()The operation stops with the update guard message.
result
UnsupportedOperationException: Update operation is not allowed.Allow a planned full-table update for one table by adding an updateAll allow rule.
allow table
DataGuardPlugin.enable {
updateAll {
allow {
tableName = "user_archive"
}
}
}
UserArchive()
.update()
.set { it.status = "EXPIRED" }
.execute()Allow a maintenance delete
Use deleteAll when a planned maintenance job intentionally deletes every row from a known table.
allow table
DataGuardPlugin.enable {
deleteAll {
allow {
tableName = "tmp_import_error"
}
}
}
TmpImportError()
.delete()
.execute()The allow rule applies only to tmp_import_error. Other full-table deletes are still rejected.
other table
UnsupportedOperationException: Delete operation is not allowed.Allow temporary table DDL
truncate, drop, and alter rules protect table operations. The % wildcard matches any sequence of characters in databaseName or tableName.
tmp tables
import com.kotlinorm.Kronos
DataGuardPlugin.enable {
truncate {
allow {
tableName = "tmp_%"
}
}
drop {
allow {
tableName = "tmp_%"
}
}
alter {
allow {
tableName = "tmp_%"
}
}
}
val wrapper = Kronos.dataSource()
wrapper.table.truncateTable("tmp_session")
wrapper.table.dropTable("tmp_session")
wrapper.table.syncTable(TmpSession())A table outside the temporary-table rule is rejected.
result
UnsupportedOperationException: Drop operation is not allowed.Match one database
Set databaseName when the rule should apply only to the current database reported by the active data source.
database rule
DataGuardPlugin.enable {
deleteAll {
allow {
databaseName = "kronos"
tableName = "tmp_%"
}
}
}When the same table name is used from another database, the rule does not match.
result
UnsupportedOperationException: Delete operation is not allowed.Deny sensitive tables
Use allowAll() to allow an operation by default, then add deny { ... } rules for sensitive tables.
drop
import com.kotlinorm.Kronos
DataGuardPlugin.enable {
drop {
allowAll()
deny {
tableName = "sensitive_%"
}
}
}
val wrapper = Kronos.dataSource()
wrapper.table.dropTable("archive_2026")
wrapper.table.dropTable("sensitive_user")The first drop is allowed. The second drop is rejected by the deny rule.
result
UnsupportedOperationException: Drop operation is not allowed.For explicit delete and update conditions, see 📚Delete Records and 📚Update Records.