This plugin allows you to do a logical deletion of the domain classes. The main intention of the plugin is to handle cases when certain entities cannot be physically removed from the database.
Most of the work is done using AST transformations. For the desired class a new boolean property is added: deleted. The GORM method delete is modified to avoid the physical removal and just change the value of the deleted property. In addition to the AST transformations, an Hibernate filter is added to make the exclusion of the deleted entities transparent.
To provide logical deletion to a domain class you just need to add the @LogicalDelete annotation to it.
@LogicalDelete
class User {
String lastName
String firstName
String nickName
...
}
To make a logical removal you just need to use the GORM method delete.
user.delete()
If you want to force a physical deletion to an annotated class, you have to add the physical parameter in true to the delete method:
user.delete(physical: true)
If you want to use the logically deleted elements, you can use the withDeleted method to execute a closure that includes the deleted items:
user.withDeleted {
def deletedUserList = User.list()
}