by Wilfred Verkley >> Sun, 24 Jun 2001 21:18:11 GMT
If have a single reference an persistent object (a custom "session" object) thats being read from many places. This object is very often just null (because its not needed or invalid), but when its being read, i want it to automatically initialized.
A tidy way i normally do it with transient objects is to put this initialization code in a "mapping" method. If I do this with persistent objects, where do i put the begin&commitTransaction calls?
I know the normal rule in most Jade applicatiZons ive seen is to put them at the outermost level (normally in the UI layer), but it seems tedious and ineffecient to surround all references to it with a transaction when 99.9% of the time its only being read.
My current inclination is to put the transaction calls in the mapping method itself, with a "process.isInTransactionState" call to check whether we are already in a transaction or not. Is this good practice ?
mySession(set: Boolean; _value: CustomerSession io) mapping, updating;begin
if not set then
if mySession= null then
if not process.isInTransactionState then
beginTransaction;
create mySession;
commitTransaction;
else
create mySession;
endif;
endif;
_value := mySession;
endif;
end;
Cheers,
Wilfred.