Question about dbo transaction exception safety
Added by Saif Rehman almost 12 years ago
Hi,
I'm curious, if after modifying or removing(from backend) a ptr object, commit() fails due to a backend error(maybe lost connection or whatever). Would the ptr keep the modified values or return to it's original state after rollback occurs as strong exception safety should.
If not, shouldn't it be implemented. It seems quite possible with mutator class.
Another question. What is the best way to clone a ptr so that it points to another part of the memory containing the same values of the dbo?
Replies (3)
RE: Question about dbo transaction exception safety - Added by Koen Deforche almost 12 years ago
Hey,
I guess this is indeed not explained well.
When a transaction fails, Wt::Dbo will keep the 'state' of all unsaved objects. Thus they all remain 'dirty' and all keep their modified (unsaved/transient) state.
It's easy for you to discard all changes in case of an exception: session.rereadAll()
Regards,
koen
RE: Question about dbo transaction exception safety - Added by Saif Rehman almost 12 years ago
Then that would mean if reread() also fails(due to connection loss) the exception would become fatal becuase the procedures(or widgets) that require checking the ptr would cause unexpected behavior. I guess either the session would have to be destroyed(restarted).
Is the ptr rollback method not a viable option?
Thanks for replying Koen :)
RE: Question about dbo transaction exception safety - Added by Koen Deforche almost 12 years ago
Hey Saif,
But reread() cannot fail. It doesn't actually reread since Dbo only lazily reads data from the database: it simply discards the current values.
If the actual dereference (later) fails, then that is part of a new transaction.
Regards,
koen