Database transactions and data-state flags



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


.



Relevant Pages

  • Re: Database transactions and data-state flags
    ... I use flags to indicate the state data of the object's ... When the data has been saved successfully to the database, ... Consider an Invoice object that has a LineItems ... I want to create a database transaction to ...
    (microsoft.public.vb.general.discussion)
  • Re: Database transactions and data-state flags
    ... When the data has been saved successfully to the database, the flags ... Consider an Invoice object that has a LineItems ... I want to create a database transaction ...
    (microsoft.public.vb.general.discussion)
  • Re: C++ oledb templates
    ... > support reading and writing BLOB data to and from an SQL 2000 database. ... > #define _BLOB_ENTRY_CODE_EX(nOrdinal, IID, flags, dataOffset, ... // The entire block below is needed to write to the messageContent ...
    (microsoft.public.sqlserver.server)
  • Re: C++ oledb templates
    ... > support reading and writing BLOB data to and from an SQL 2000 database. ... > #define _BLOB_ENTRY_CODE_EX(nOrdinal, IID, flags, dataOffset, ... // The entire block below is needed to write to the messageContent ...
    (microsoft.public.data.oledb)
  • Re: C++ oledb templates
    ... > support reading and writing BLOB data to and from an SQL 2000 database. ... > #define _BLOB_ENTRY_CODE_EX(nOrdinal, IID, flags, dataOffset, ... // The entire block below is needed to write to the messageContent ...
    (microsoft.public.vc.atl)

Loading