As you're dealing with domain objects, GORM supports the registration of events as methods that get fired when certain events occurs such as deletes, insertsand updates:
beforeInsert - Executed before an object is initially persisted to the database
beforeUpdate - Executed before an object is updated
beforeDelete - Executed before an object is deleted
beforeValidate - Executed before an object is validated
afterInsert - Executed after an object is persisted to the database
afterUpdate - Executed after an object has been updated
afterDelete - Executed after an object has been deleted
onLoad - Executed when an object is loaded from the database
Then, you can add updateCalculations()
in your domain object like that:
static constraints = {
machine blank:false
cicleValue nullable:false
}
def beforeUpdate() { updateCalculations() }
As a general good design practice, it's better to keep logic implementation out from domains object and Grails allows to inject services into domains (POGO).