grails - Converting Mutable to Immutable with Hibernate -
i'm using grails , have following domain class:
class pack { string code date publisheddate //several other properties (including collections hasmany).... def ispublished() { return publisheddate != null } def publish() { publisheddate = new date() } def canedit() { return !ispublished() } }
to sell pack first need publish , use publish method publicate pack.
after published, pack cannot changed (i.e. after published, pack need immutable instance).
my question is:
- how transform mutable object in immutable using groovy?
or
- is there way retrieve immutable instance hibernate?
another option use canedit() method combined hibernate events (beforeupdate , beforedelete). if canedit() == false can throw runtimeexception inside beforedelete or beforeupdate. solution?
obs.: think freeze method in ruby need. (http://rubylearning.com/satishtalim/mutable_and_immutable_objects.html)
you can use pack.read( id )
an instance of domain class specified id in read-only state. null returned if row specified id doesn't exist.
see http://grails.org/doc/latest/ref/domain%20classes/read.html
Comments
Post a Comment