void CRUDependenceGraph::MergePipelinedTasks(const CRUTaskList &pplTaskList)
{
	if (TRUE == pplTaskList.IsEmpty())
	{
		return;
	}

	CRURefreshTask *pTopTask = (CRURefreshTask*) pScheduledTask_;
	CRURefreshTask *pNewTopTask;

	CRUMVList &mvList = pTopTask->GetMVList();

	DSListPosition pos = pplTaskList.GetHeadPosition();
	while (NULL != pos)
	{
		// The next task to merge ...
		pNewTopTask = (CRURefreshTask*)(pplTaskList.GetNext(pos));
		CRUMV &topMV = pNewTopTask->GetRootMV();
		mvList.AddTail(&topMV);

		// Inherit the connectivity of the newly merged task
		InheritTopTaskConnectivity(pNewTopTask);
		RemoveFromAvailableList(pNewTopTask);

		pTopTask = pNewTopTask;
	}
}
void CRURefreshTaskExecutor::FinalMetadataUpdate()
{
	CRURefreshTask *pParentTask = GetRefreshTask();
	RUASSERT (NULL != pParentTask);


	TInt32 currDuration = 0;
        TInt64 ts = CalculateTimeStamp();

	if (TRUE == pParentTask->NeedToExecuteInternalRefresh())
	{
		currDuration = GetTimerDuration();
	}
	
	CRUMV *pPrevMV, *pCurrMV = NULL;
	CRUMVList &mvList = pParentTask->GetMVList();
	DSListPosition pos = mvList.GetHeadPosition();

	while (NULL != pos)
	{
		pPrevMV = pCurrMV;
		pCurrMV = mvList.GetNext(pos);

		// Update the MV's REFRESHED_AT timestamp
		pCurrMV->SetTimestamp(ts);

                // publish the refresh event to the PUBLISH table
           NABoolean isRecomputePublish = (IsRecompute() == TRUE);
           pCurrMV->PublishMVRefresh(isRecomputePublish);
   
	   if (CDDObject::eON_STATEMENT != pCurrMV->GetRefreshType())
           {
		if (NULL == pPrevMV)
		{
			// This is the Root MV (the first in the list)
			if (CDDObject::eON_REQUEST == pCurrMV->GetRefreshType())
			{
				// For every table T used by MV, 
				// set MV.EPOCH[T]<--T.CURRENT_EPOCH.
				UpdateRootMVCurrentEpochVector();
			}
			
			UpdateRootMVStatistics(currDuration);
		}
		else
		{
			UpdateNonRootMVStatistics(pCurrMV, pPrevMV, currDuration);
		}
	   }
		
		pCurrMV->SaveMetadata();
	}

        if (CDDObject::eON_STATEMENT != GetRootMV().GetRefreshType())
        {
	IncrementTopMvCurrentEpoch();
        }
}