Database transactions and data-state flags
- From: "Craig Buchanan" <someone@xxxxxxxxxxxxx>
- Date: Wed, 1 Nov 2006 09:58:30 -0600
I am attempting to create an API layer for my application. The UI interacts
with the API, the API interacts with the database.
Essentially, each object is responsible for its persistence. At this point,
I use flags (IsNew or IsDirty) to indicate the state data of the object's
data. When the data has been saved successfully to the database, the flags
are switched off. This works fine for a simple object.
If, however, I have an object that has collections, the state management
becomes more complex. Consider an Invoice object that has a LineItems
collection of LineItem objects. I want to create a database transaction to
ensure that the hierarchy is save successfully as a whole. It seems that I
need to follow this logic:
* create a transaction
* save the Invoice, if necessary
* iterate the LineItems collection, save the LineItem, if necessary
* commit the transaction
* reset the Invoice's flags
* iterated the LineItems collection, reset each LineItem's flags
I don't want to reset the LineItem's flags during the database update
process; if the transaction fails, the flags' settings wouldn't match the
data's true state.
Does this seem reasonable? Is there an alternate approach to this that
avoids flags?
Thanks for your thoughts.
Craig Buchanan
.
- Follow-Ups:
- Re: Database transactions and data-state flags
- From: Ralph
- Re: Database transactions and data-state flags
- From: Jan Hyde
- Re: Database transactions and data-state flags
- Prev by Date: Distribution woes
- Next by Date: Re: Distribution woes
- Previous by thread: Distribution woes
- Next by thread: Re: Database transactions and data-state flags
- Index(es):
Relevant Pages
|
Loading