Logical Delete Plugin

1 vote
Dependency:
compile ":logical-delete:0.1"

 Documentation  Source  Issues

Summary

Allows you to do a logical deletion of domain classes

Installation

grails install-plugin logical-delete

Description

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)