{"id":1219,"date":"2010-07-13T18:18:21","date_gmt":"2010-07-13T12:48:21","guid":{"rendered":"http:\/\/www.tothenew.com\/blog\/?p=1219"},"modified":"2015-07-09T15:03:06","modified_gmt":"2015-07-09T09:33:06","slug":"grails-hibernate-filter-plugin-a-life-saver","status":"publish","type":"post","link":"https:\/\/www.tothenew.com\/blog\/grails-hibernate-filter-plugin-a-life-saver\/","title":{"rendered":"Grails Hibernate Filter Plugin a Life Saver"},"content":{"rendered":"<p>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 <a title=\"iPhone Application Developers\" href=\"http:\/\/www.tothenew.com\/mobile-ios-application-development-services\">iPhone application developer<\/a> wanted to have soft delete mechanism for deleting an object. So they added new field in the database table named &#8220;deleted&#8221;.<\/p>\n<p>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.<\/p>\n<p>That&#8217;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.<\/p>\n<p>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 &#8220;life saver&#8221; plugin for Grails i.e. <a href=\"http:\/\/www.grails.org\/plugin\/hibernate-filter\">http:\/\/www.grails.org\/plugin\/hibernate-filter<\/a>. Everything is written in the plugin documentation but I would like to re-quote some of the documentation<\/p>\n<p>My class was like<\/p>\n<pre lang=\"groovy\">Class A{\r\nString name\r\nString address\r\nBoolean deleted\r\n} \r\n<\/pre>\n<p>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.<\/p>\n<pre lang=\"groovy\">Class A{\r\nString name\r\nString address\r\nBoolean deleted\r\n} \r\n\r\nstatic hibernateFilters = {\r\n        enabledFilter(condition: 'deleted=0', default: true)\r\n    }\r\n\r\n\r\n<\/pre>\n<p>in Datasource.groovy file I need to write<\/p>\n<pre lang=\"groovy\">import  org.grails.plugin.hibernate.filter.HibernateFilterDomainConfiguration\r\ndataSource {\r\n   \u2026\r\n   configClass = HibernateFilterDomainConfiguration.class\r\n}\r\n\r\n\r\n<\/pre>\n<p>and I am done without looking at how many places I have used dynamic finders or queried the database for this domain.<\/p>\n<p>I haven&#8217;t gone into the details of the plugin but it really saved a lot of work for me.<br \/>\nHope it helps<\/p>\n","protected":false},"excerpt":{"rendered":"<p>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 [&hellip;]<\/p>\n","protected":false},"author":11,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"iawp_total_views":9},"categories":[7],"tags":[308,309,307],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/1219"}],"collection":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/users\/11"}],"replies":[{"embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/comments?post=1219"}],"version-history":[{"count":0,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/1219\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/media?parent=1219"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/categories?post=1219"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/tags?post=1219"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}