I'm looking at some grails gorm code in my current project and I'm wondering what are some pros and cons of the following HQL approach:
UploadUpsell.executeUpdate("update UploadUpsell set processedStatus=:newStatus, processedDate=:processedDate where processedDate is null and period=:period",
[newStatus: EXPIRED_UPSELL_STATUS, processedDate: new Date(), period: flow.period])
I would have gone for a more idiomatic approach along the lines
UploadUpsell.findAllByPeriodAndProcessedDate(flow.period, null).each { UploadUpsell uploadUpsell ->
uploadUpsell.with {
processedStatus = EXPIRED_UPSELL_STATUS
processedDate = new Date()
save()
}
}
I believe that my approach would be more testable and is more readable but I'm wondering if my thinking is just dogmatic
HQL statements are not supported by grails mocking framework as far as I know.