GME  13
CoreTransactionItem.h
Go to the documentation of this file.
00001 
00002 #ifndef MGA_CORETRANSACTIONITEM_H
00003 #define MGA_CORETRANSACTIONITEM_H
00004 
00005 // --------------------------- CCoreTransactionItem
00006 
00007 // IMPORTANT: Each transaction item cares only about itself and those
00008 // of its parts which are not transaction items themselves.
00009 // Never make any modification to other transaction items during
00010 // abort, discard, commit or commit finish.
00011 
00012 // call CCoreProject::RegisterTransactionItem to get into the
00013 // latest nested transaction, be dirty when registering
00014 
00015 class ATL_NO_VTABLE CCoreTransactionItem
00016 {
00017 public:
00018         // dirty if modified in the latest transaction
00019         virtual bool IsDirty() const NOTHROW = 0;
00020 
00021         // we clear the flag at the beggining of a nested transaction
00022         // we set it at abort, or committing a nested tr and gaining focus
00023         virtual void ChangeDirty(bool dirty) NOTHROW = 0;
00024 
00025         // must be dirty, discard the latest transaction value, clear dirty
00026         virtual void AbortNestedTransaction() NOTHROW = 0;
00027 
00028         // must be dirty, discard the previous transaction value, keep dirty
00029         // called only for nested transactions when we merge the latest two values
00030         virtual void DiscardPreviousValue() NOTHROW = 0;
00031 };
00032 
00033 // --------------------------- CCoreFinalTrItem
00034 
00035 // call CCoreProject::RegisterFinalTrItem to register, call it only once
00036 // CoreObjects register to group database access of their CoreAttributes
00037 
00038 class ATL_NO_VTABLE CCoreFinalTrItem : public ISupportErrorInfo // all subclasses will inherit ISupportErrorInfoImpl, so inherit here to save a vtable entry
00039 {
00040 public:
00041         // called for final abort, clear dirty
00042         virtual void AbortFinalTransaction() NOTHROW = 0;
00043 
00044         // should do the work, may be called several times,
00045         virtual void CommitFinalTransaction() = 0;
00046 
00047         // clean up, clear dirty
00048         virtual void CommitFinalTransactionFinish(bool undo) NOTHROW = 0;
00049 };
00050 
00051 template<const IID* piid>
00052 class ATL_NO_VTABLE CCoreFinalTrItemImpl : public CCoreFinalTrItem // all subclasses will inherit ISupportErrorInfoImpl, so inherit here to save a vtable entry
00053 {
00054         // ISupportErrorInfoImpl
00055 public:
00056         STDMETHOD(InterfaceSupportsErrorInfo)(_In_ REFIID riid)
00057         {
00058                 return (InlineIsEqualGUID(riid,*piid)) ? S_OK : S_FALSE;
00059         }
00060 
00061 };
00062 
00063 // --------------------------- CCoreUndoItem
00064 
00065 // call CCoreProject::RegisterUndoItem to register,
00066 // call it only from CommitFinalTransactionFinish
00067 
00068 class ATL_NO_VTABLE CCoreUndoItem : public CCoreTransactionItem
00069         // KMS: inherit from CCoreTransactionItem so one less vtable pointer is required in subclasses
00070         // (the only subclass is CCoreDataAttribute which also implements CCoreTransactionItem)
00071 {
00072 public:
00073         // do the work here, called only once for each level
00074         // this is not a regular transaction, do not register new
00075         // transaction items and final transaction items
00076         virtual void UndoTransaction() = 0;
00077         virtual void UndoTransactionFinish() NOTHROW = 0;
00078 
00079         virtual void RedoTransaction() = 0;
00080         virtual void RedoTransactionFinish() NOTHROW = 0;
00081 
00082         // not a regular transaction, only locking attributes can register
00083         virtual void DiscardLastItem() = 0;
00084         virtual void DiscardLastItemFinish() NOTHROW = 0;
00085         virtual void DiscardLastItemCancel() NOTHROW = 0;
00086 };
00087 
00088 #endif//MGA_CORETRANSACTIONITEM_H