Skip to content

nanlabs/logical-delete

Repository files navigation

Logical Delete

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.

How it works:

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.

How to use:

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()
}

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published