In my grails application, some of my domain classes will never be changed by Users.
However, some maintenance work is sometimes necessary, and administrator should be able to create/edit few instances from time to time (let's say twice a year).
I would like to set a read-only 2nd level cache strategy for these domain classes (static mapping = { cache usage: 'read-only' }
) AND I would like to be able to 'disable' (in very particular situations) the read-only strategy in order to udate some instances via Grails scaffolding edit view.
Is it possible? What do you advise me to do?
EDIT: The solution I am implementing is a mix of Pascal and Burt answers (see comments). Both answers are great and helpful. So I got a dilemna for choosing the accepted answer! Anyway, thank you.
It's probably possible but most likely non-trivial. I'd go with direct inserts using groovy.sql.Sql. You lose validation, but you could create instances and validate them but not call save(). Then do the SQL inserts if they're ok, e.g.
def thing = new Thing(params)
if (thing.validate()) {
new Sql(dataSource).executeInsert(
"insert into thing(name) values(?)", [params.name])
}
else {
// report validation error
}