In my last blog, we discussed how to hook into GORM API to add some common custom functionality. We will refer the same problem that we discussed in my last blog. Here is the problem statement: In my grails plugin I was needed to add some fields that were common to a set of domains. For eg: for some domains we wanted to store fields like...
In my grails plugin I was needed to add some fields that were common to a set of domains. For eg: for some domains we wanted to store fields like createdBy and lastUpdatedBy to keep track of users who created and last updated each record in that domain. Grails framework provides timestamping using which we can keep track of the time a...
It's a common practice to add fields to Grails domain's hasMany block while in database a foreign key relationship is maintained for every such entry. In other words, for each foreign key, we have a column in parent table (or domain) and a reference column in other table. I was adding a field into hasMany block recently when I got this...
In grails app, there might come scenarios where one need to create a non-persistent domain rather than creating a command obejct or POJO / POGO. GORM comes with a handy static property mapWith which has default value GORM (which associates any domain with gorm persistence layer). To make a domain non persistent set mapWith="none". For...
I recently had a situation where I had the exact same criteria in multiple domains. I found a way to DRY them using Closure.delegate. I wanted to share that in this post. Just including the relevant details the domains that I had were like the following. [code language="groovy"]class Subscription { static belongsTo = [topic:...
In the previous blog Grails performance optimization - Unique constraint we have optimized Grails unique constraint. Now in this blog we will check another use case and will optimize unique constraint according to it. Suppose we have two domains having the following structure: [code] class Address { String addressLine1 String...
Grails unique constraint is very powerful way to check duplicate keys in any DBMS, but it has some impact on application performance. Lets check it by one example: Suppose we have one domain having the following structure: [code] class User { String firstName String lastName String emailId static constraints = { ...
Day 3 started sharp at 7:30 with the breakfast and then the sessions started from 8:30 AM and continued till 6:00 PM. The day was jam packed with varying sessions on Groovy, Grails, performance optimisation and the "Groovy puzzlers show" (Yes, it was a show ;) ). The highlights of the day were: # Microservice Architecture With...
I am working on a Grails application with MySQL database. I had a use case in which I had to implement alphanumeric sorting using Criteria Query on Grails. By alphanumeric sorting I mean if there is a class Employee with field empId then on doing : [plain] Employee e1 = new Employee(empId:'emp10').save() Employee e2 = new...
The groovy world is abuzz about the latest release from the Grails Stable, Grails 2.0, which packs a lot more punch than its predecessors, which by themselves were productivity enhancers and wonderful to develop our web applications with. The new version brings with itself a lot of changes compared to the previous releases and...
Recently, I used bitwise Anding in my grails project. I am sharing the approach that we followed by means of an example. Suppose we have a domain class Person which can have multiple attributes like Smart, Intelligent, Talkative etc. What sort of relationship comes to our mind when we see this? I believe the obvious answer would...
We are using the grails asynchronous mail plugin in our project and noticed that the sent mails never gets deleted from the database. This was an issue because we were sending out a lot of mails and all of them had PDF attachments of about 500 KB to 1 MB each. A sure recipe for disaster because our DB was growing exponentially. To take...