The project I am currently working on is also accessible from the iPhone. In the last few months so many changes have been done on the web application (developed in groovy/grails). Now the client wants the same thing on iPhone as well. He has a separate development team for iPhone application. The iPhone application developer wanted to have soft delete mechanism for deleting an object. So they added new field in the database table named “deleted”.
Now we have to remove all such records from our every query in the project which have deleted true. So there were 6-7 domains which now have this mechanism of soft deletion.
That’s how our life became hell, we were unsure about what to do next, is it good to modify all the queries in the project which would be a lot of work.
I was also reading Hibernate books these days and found a very good thing in Hibernate about filters. So now I just need to look for how the filters work in Grails. In few seconds I found my “life saver” plugin for Grails i.e. http://www.grails.org/plugin/hibernate-filter. Everything is written in the plugin documentation but I would like to re-quote some of the documentation
My class was like
Class A{ String name String address Boolean deleted }
After installing the plugin I just need to add a line in the domain and a property in datasource file and it will filter all the data with the condition that I put in filter. So my domain would become like this.
Class A{ String name String address Boolean deleted } static hibernateFilters = { enabledFilter(condition: 'deleted=0', default: true) }
in Datasource.groovy file I need to write
import org.grails.plugin.hibernate.filter.HibernateFilterDomainConfiguration dataSource { … configClass = HibernateFilterDomainConfiguration.class }
and I am done without looking at how many places I have used dynamic finders or queried the database for this domain.
I haven’t gone into the details of the plugin but it really saved a lot of work for me.
## Uday Pratap Singh ##
uday@intelligrape.com
http://www.IntelliGrape.com/
http://in.linkedin.com/in/meudaypratap
