Back to index

lightning-sunbird  0.9+nobinonly
Public Member Functions | Public Attributes | Private Member Functions
AggregateTransaction Class Reference
Inheritance diagram for AggregateTransaction:
Inheritance graph
[legend]
Collaboration diagram for AggregateTransaction:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 AggregateTransaction (nsITransactionManager *aTXMgr, PRInt32 aMaxLevel, PRInt32 aNumChildrenPerNode, PRInt32 aFlags=NONE_FLAG)
virtual ~AggregateTransaction ()
NS_IMETHOD DoTransaction ()
NS_IMETHOD UndoTransaction ()
NS_IMETHOD RedoTransaction ()
NS_IMETHOD GetIsTransient (PRBool *aIsTransient)
NS_IMETHOD Merge (nsITransaction *aTransaction, PRBool *aDidMerge)
void doTransaction ()
 Executes the transaction.
void undoTransaction ()
 Restores the state to what it was before the transaction was executed.
void redoTransaction ()
 Executes the transaction again.
boolean merge (in nsITransaction aTransaction)
 Attempts to merge a transaction into "this" transaction.

Public Attributes

nsITransactionManagermTXMgr
PRInt32 mLevel
PRInt32 mNumber
PRInt32 mErrorFlags
PRInt32 mMaxLevel
PRInt32 mNumChildrenPerNode
PRInt32 mVal
PRInt32 mFlags
readonly attribute boolean isTransient
 The transaction's transient state.

Private Member Functions

 AggregateTransaction (nsITransactionManager *aTXMgr, PRInt32 aLevel, PRInt32 aNumber, PRInt32 aMaxLevel, PRInt32 aNumChildrenPerNode, PRInt32 aFlags)

Detailed Description

Definition at line 579 of file TestTXMgr.cpp.


Constructor & Destructor Documentation

AggregateTransaction::AggregateTransaction ( nsITransactionManager aTXMgr,
PRInt32  aLevel,
PRInt32  aNumber,
PRInt32  aMaxLevel,
PRInt32  aNumChildrenPerNode,
PRInt32  aFlags 
) [inline, private]

Definition at line 583 of file TestTXMgr.cpp.

  {
    mLevel              = aLevel;
    mNumber             = aNumber;
    mTXMgr              = aTXMgr;
    mFlags              = aFlags & (~ALL_ERROR_FLAGS);
    mErrorFlags         = aFlags & ALL_ERROR_FLAGS;
    mTXMgr              = aTXMgr;
    mMaxLevel           = aMaxLevel;
    mNumChildrenPerNode = aNumChildrenPerNode;
  }

Here is the caller graph for this function:

AggregateTransaction::AggregateTransaction ( nsITransactionManager aTXMgr,
PRInt32  aMaxLevel,
PRInt32  aNumChildrenPerNode,
PRInt32  aFlags = NONE_FLAG 
) [inline]

Definition at line 609 of file TestTXMgr.cpp.

  {
    mLevel              = 1;
    mNumber             = 1;
    mFlags              = aFlags & (~ALL_ERROR_FLAGS);
    mErrorFlags         = aFlags & ALL_ERROR_FLAGS;
    mTXMgr              = aTXMgr;
    mMaxLevel           = aMaxLevel;
    mNumChildrenPerNode = aNumChildrenPerNode;
  }
virtual AggregateTransaction::~AggregateTransaction ( ) [inline, virtual]

Definition at line 622 of file TestTXMgr.cpp.

  {
    // printf("~AggregateTransaction(0x%.8x) - %3d (%3d)\n", this, mLevel, mVal);
  }

Member Function Documentation

Executes the transaction.

Reimplemented from SimpleTransaction.

Definition at line 627 of file TestTXMgr.cpp.

  {
    if (mLevel >= mMaxLevel) {
      // Only leaf nodes can throw errors!
      mFlags |= mErrorFlags;
    }

    nsresult result = SimpleTransaction::DoTransaction();

    if (NS_FAILED(result)) {
      // printf("ERROR: QueryInterface() failed for transaction level %d. (%d)\n",
      //       mLevel, result);
      return result;
    }

    if (mLevel >= mMaxLevel)
      return NS_OK;

    if (mFlags & BATCH_FLAG) {
      result = mTXMgr->BeginBatch();
      if (NS_FAILED(result)) {
        return result;
      }
    }

    PRInt32 cLevel = mLevel + 1;

    for (int i = 1; i <= mNumChildrenPerNode; i++) {
      PRInt32 flags = mErrorFlags & THROWS_DO_ERROR_FLAG;

      if ((mErrorFlags & THROWS_REDO_ERROR_FLAG) && i == mNumChildrenPerNode) {
        // Make the rightmost leaf transaction throw the error!
        flags = THROWS_REDO_ERROR_FLAG;
        mErrorFlags = mErrorFlags & (~THROWS_REDO_ERROR_FLAG);
      }
      else if ((mErrorFlags & THROWS_UNDO_ERROR_FLAG)
               && i == 1) {
        // Make the leftmost leaf transaction throw the error!
        flags = THROWS_UNDO_ERROR_FLAG;
        mErrorFlags = mErrorFlags & (~THROWS_UNDO_ERROR_FLAG);
      }

      flags |= mFlags & BATCH_FLAG;

      AggregateTransaction *tximpl =
              new AggregateTransaction(mTXMgr, cLevel, i, mMaxLevel,
                                       mNumChildrenPerNode, flags);

      if (!tximpl) {
        printf("ERROR: Failed to allocate AggregateTransaction %d, level %d. (%d)\n",
               i, mLevel, result);

        if (mFlags & BATCH_FLAG)
          mTXMgr->EndBatch();

        return NS_ERROR_OUT_OF_MEMORY;
      }

      nsITransaction *tx = 0;
      result = tximpl->QueryInterface(NS_GET_IID(nsITransaction), (void **)&tx);
      if (NS_FAILED(result)) {
        printf("ERROR: QueryInterface() failed for transaction %d, level %d. (%d)\n",
               i, mLevel, result);

        if (mFlags & BATCH_FLAG)
          mTXMgr->EndBatch();

        return result;
      }

      result = mTXMgr->DoTransaction(tx);

      if (NS_FAILED(result)) {
        // printf("ERROR: Failed to execute transaction %d, level %d. (%d)\n",
        //        i, mLevel, result);
        tx->Release();

        if (mFlags & BATCH_FLAG)
          mTXMgr->EndBatch();

        return result;
      }

      tx->Release();
    }

    if (mFlags & BATCH_FLAG)
      mTXMgr->EndBatch();

    return result;
  }

Here is the call graph for this function:

NS_IMETHOD SimpleTransaction::GetIsTransient ( PRBool aIsTransient) [inline, inherited]

Definition at line 562 of file TestTXMgr.cpp.

  {
    if (aIsTransient)
      *aIsTransient = (mFlags & TRANSIENT_FLAG) ? PR_TRUE : PR_FALSE;

    return NS_OK;
  }
boolean nsITransaction::merge ( in nsITransaction  aTransaction) [inherited]

Attempts to merge a transaction into "this" transaction.

Both transactions must be in their undo state, doTransaction() methods already called. The transaction manager calls this method to coalesce a new transaction with the transaction on the top of the undo stack. This method returns a boolean value that indicates the merge result. A true value indicates that the transactions were merged successfully, a false value if the merge was not possible or failed. If true, the transaction manager will Release() the new transacton instead of pushing it on the undo stack.

Parameters:
aTransactionthe previously executed transaction to merge.
NS_IMETHOD SimpleTransaction::Merge ( nsITransaction aTransaction,
PRBool aDidMerge 
) [inline, inherited]

Definition at line 570 of file TestTXMgr.cpp.

  {
    if (aDidMerge)
      *aDidMerge = (mFlags & MERGE_FLAG) ? PR_TRUE : PR_FALSE;

    return NS_OK;
  }

Executes the transaction again.

Can only be called on a transaction that was previously undone.

In most cases, the redoTransaction() method will actually call the doTransaction() method to execute the transaction again.

Definition at line 539 of file TestTXMgr.cpp.

  {
    //
    // Make sure RedoTransaction() is called in the order we expect!
    // Notice that we don't check to see if we go past the end of the array.
    // This is done on purpose since we want to crash if the order array is out
    // of date.
    //
    if (sRedoOrderArr && mVal != sRedoOrderArr[sRedoCount]) {
      printf("ERROR: ~SimpleTransaction expected %d got %d.\n",
             mVal, sRedoOrderArr[sRedoCount]);
      exit(NS_ERROR_FAILURE);
    }

    ++sRedoCount;

#ifdef ENABLE_DEBUG_PRINTFS
    printf("\nSimpleTransaction.Redo: %d - 0x%.8x\n", mVal, (PRInt32)this);
#endif // ENABLE_DEBUG_PRINTFS

    return (mFlags & THROWS_REDO_ERROR_FLAG) ? NS_ERROR_FAILURE : NS_OK;
  }

Here is the call graph for this function:

Restores the state to what it was before the transaction was executed.

Definition at line 516 of file TestTXMgr.cpp.

  {
    //
    // Make sure UndoTransaction() is called in the order we expect!
    // Notice that we don't check to see if we go past the end of the array.
    // This is done on purpose since we want to crash if the order array is out
    // of date.
    //
    if (sUndoOrderArr && mVal != sUndoOrderArr[sUndoCount]) {
      printf("ERROR: ~SimpleTransaction expected %d got %d.\n",
             mVal, sUndoOrderArr[sUndoCount]);
      exit(NS_ERROR_FAILURE);
    }

    ++sUndoCount;

#ifdef ENABLE_DEBUG_PRINTFS
    printf("\nSimpleTransaction.Undo: %d - 0x%.8x\n", mVal, (PRInt32)this);
#endif // ENABLE_DEBUG_PRINTFS

    return (mFlags & THROWS_UNDO_ERROR_FLAG) ? NS_ERROR_FAILURE : NS_OK;
  }

Here is the call graph for this function:


Member Data Documentation

The transaction's transient state.

This attribute is checked by the transaction manager after the transaction's Execute() method is called. If the transient state is false, a reference to the transaction is held by the transaction manager so that the transactions' undoTransaction() and redoTransaction() methods can be called. If the transient state is true, the transaction manager returns immediately after the transaction's doTransaction() method is called, no references to the transaction are maintained. Transient transactions cannot be undone or redone by the transaction manager.

Definition at line 79 of file nsITransaction.idl.

Definition at line 604 of file TestTXMgr.cpp.

Definition at line 464 of file TestTXMgr.cpp.

Definition at line 602 of file TestTXMgr.cpp.

Definition at line 606 of file TestTXMgr.cpp.

Definition at line 603 of file TestTXMgr.cpp.

Definition at line 607 of file TestTXMgr.cpp.

Definition at line 600 of file TestTXMgr.cpp.

Definition at line 463 of file TestTXMgr.cpp.


The documentation for this class was generated from the following file: