void CRUUnAuditRefreshTaskExecutor::Recompute()
{
	// ?????
	// Temporary - Should be removed when read commited from unaudited table is implemented
	if (FALSE == IsTransactionOpen())
	{
		BeginTransaction(); 
	}
	
	CDMPreparedStatement *pStat = PrepareRecomputeMV();

	// ?????
	// Temporary - Should be removed when read commited from unaudited table is implemented
	CommitTransaction();
	BeginTransaction();

	ExecuteRecomputeMV(pStat);

	// ?????
	// Temporary - Should be removed when read commited from unaudited table is implemented
	CommitTransaction();

	TESTPOINT2(CRUGlobals::TESTPOINT104, GetRootMVName());

	if (TRUE == isPopindex_)
	{
		SetState(EX_POPINDEX);
	}
	else
	{
		SetState(EX_EPILOGUE);
	}
}
void CRUAuditRefreshTaskExecutor::Recompute()
{
	// TEMPORARY: Commented out until the privilege-skipping lock 
	// is implemented 
	
	// LockMV();

	if (FALSE == IsTransactionOpen())
	{
		BeginTransaction(); 
	}

	// Decouple prepare and execute to separate transactions.
	CDMPreparedStatement *pStat = PrepareRecomputeMV();
	CommitTransaction();
	BeginTransaction();
	ExecuteRecomputeMV(pStat);

	if (TRUE == isDeleteMultiTxnContext_)
	{
		// Delete all rows from the context log table 
		auditRefreshTEDynamicContainer_.
			DirectExecStatement(DELETE_MULT_TXN_CTX_TBL);
	}

        if (TRUE == isPopindex_)
	{
		CommitTransaction();
		SetState(EX_POPINDEX);
	}
        else
        {
		SetState(EX_REMOTE_END);
        }
}
Exemplo n.º 3
0
/* static */ bool
WheelTransaction::WillHandleDefaultAction(WidgetWheelEvent* aWheelEvent,
                                          nsWeakFrame& aTargetWeakFrame)
{
  nsIFrame* lastTargetFrame = GetTargetFrame();
  if (!lastTargetFrame) {
    BeginTransaction(aTargetWeakFrame.GetFrame(), aWheelEvent);
  } else if (lastTargetFrame != aTargetWeakFrame.GetFrame()) {
    EndTransaction();
    BeginTransaction(aTargetWeakFrame.GetFrame(), aWheelEvent);
  } else {
    UpdateTransaction(aWheelEvent);
  }

  // When the wheel event will not be handled with any frames,
  // UpdateTransaction() fires MozMouseScrollFailed event which is for
  // automated testing.  In the event handler, the target frame might be
  // destroyed.  Then, the caller shouldn't try to handle the default action.
  if (!aTargetWeakFrame.IsAlive()) {
    EndTransaction();
    return false;
  }

  return true;
}
void CRUUnAuditRefreshTaskExecutor::Refresh()
{
	try 
	{
		// ?????
		// Temporary - Should be removed when read commited from unaudited table is implemented
		BeginTransaction(); 

		ApplyIRCompilerDefaults();

		if(TRUE == IsSingleDeltaRefresh())
		{
			CDMPreparedStatement *pStat = PrepareSingleDeltaRefresh();

			// ?????
			// Temporary - Should be removed when read commited from unaudited table is implemented
			CommitTransaction();
			BeginTransaction();

			ExecuteSingleDeltaRefresh(pStat);
		}
		else
		{
			StmtList *stmts = PrepareMultiDeltasRefresh();

			// ?????
			// Temporary - Should be removed when read commited from unaudited table is implemented
			CommitTransaction();
			BeginTransaction();

			ExecuteMultiDeltasRefresh(stmts);
		}

		ResetIRCompilerDefaults();

		ExecuteShowExplain();

		// ?????
		// Temporary - Should be removed when read commited from unaudited table is implemented
		CommitTransaction();

		TESTPOINT2(CRUGlobals::TESTPOINT106, GetRootMVName());
		
		SetState(EX_EPILOGUE);
	}
	catch (CRUSimpleRefreshTaskExecutor::NeedRecomputeException)
	{
		SetState(EX_RECOMPUTE);
		SetRecompute(TRUE);
	}
}
Exemplo n.º 5
0
/** 
 * @brief Lock the line of the Handle table with inode & devid defined in p_info
 * 
 * @param p_conn
 *        Database connection
 * @param p_info 
 *        Information about the file
 * 
 * @return ERR_FSAL_POSIXDB_NOERR if no error,
 *         another error code else.
 */
fsal_posixdb_status_t fsal_posixdb_lockHandleForUpdate(fsal_posixdb_conn * p_conn,      /* IN */
                                                       fsal_posixdb_fileinfo_t *
                                                       p_info /* IN */ )
{
  PGresult *p_res;
  char devid_str[MAX_DEVICEIDSTR_SIZE];
  char inode_str[MAX_INODESTR_SIZE];
  const char *paramValues[2];

  CheckConn(p_conn);

  BeginTransaction(p_conn, p_res);

  snprintf(devid_str, MAX_DEVICEIDSTR_SIZE, "%lli", (long long int)p_info->devid);
  snprintf(inode_str, MAX_INODESTR_SIZE, "%lli", (long long int)p_info->inode);
  paramValues[0] = devid_str;
  paramValues[1] = inode_str;
  p_res = PQexecPrepared(p_conn, "lookupHandleByInodeFU", 2, paramValues, NULL, NULL, 0);
  CheckResult(p_res);
  PQclear(p_res);

  /* Do not end the transaction, because it will be closed by the next call to a posixdb function */

  ReturnCodeDB(ERR_FSAL_POSIXDB_NOERR, 0);
}
void CRUUnAuditRefreshTaskExecutor::Epilogue()
{
	EndTimer();

	BeginTransaction();

	if (TRUE == GetRefreshTask()->NeedToExecuteInternalRefresh())
	{
		if (CDDObject::eON_STATEMENT == GetRootMVType())
		{
			EpilogueHandleOnStatementMV();
		}
		
		// Set the MV(s)/indexes back available
		ResetObjectsAvailable();

	}

	FinalMetadataUpdate();
	
	CommitTransaction();

	TESTPOINT2(CRUGlobals::TESTPOINT107, GetRootMVName());
	
	LogClosureMessage();

	SetState(EX_COMPLETE);
}
void CRUUnAuditRefreshTaskExecutor::PopulateIndexes()
{
	RUASSERT(TRUE == isPopindex_);

	if (0 == numOfIndexes_)
	{
		return;
	}

	// ?????
	// Temporary - Should be removed when read commited from unaudited table is implemented
	BeginTransaction();

#ifdef _DEBUG
	CDSString msg(
		"\nPopulating the secondary indexes of materialized view " 
		+ GetRootMVName() + "...\n");

	CRUGlobals::GetInstance()->
		LogDebugMessage(CRUGlobals::DUMP_POPINDEX,"",msg);
#endif

	ExecuteIndexStatmenents(*pUnAuditPopIndexdynamicContainer_, IDS_RU_POPINDEX_FAILED);

	// ?????
	// Temporary - Should be removed when read commited from unaudited table is implemented
	CommitTransaction();

	TESTPOINT2(CRUGlobals::TESTPOINT105, GetRootMVName());

	SetState(EX_EPILOGUE);
}
void CRUUnAuditRefreshTaskExecutor::Prologue()
{
	TESTPOINT2(CRUGlobals::TESTPOINT101, GetRootMVName());

	BeginTransaction();
	if (CDDObject::eON_STATEMENT == GetRootMVType())
	{
		PrologueHandleOnStatementMV();
	}
	// Set the MV non-available etc ...
	SetObjectsUnavailable();
	CommitTransaction();

	TESTPOINT2(CRUGlobals::TESTPOINT102, GetRootMVName());

	if (TRUE == isPurgedata_) 
	{
		SetState(EX_PURGE_DATA);
	}
	else if (TRUE == IsRecompute())
	{
		SetState(EX_RECOMPUTE);
	}
	else
	{
		SetState(EX_REFRESH);
	}
}
void CRULogCleanupTaskExecutor::CleanLogFirstN(SQL_STATEMENT statement)
{
	// Compilation Stage
	CDMPreparedStatement *pStat = 
          logCleanupTEDynamicContainer_.GetPreparedStatement(statement);

	while (TRUE)
	{
		BeginTransaction();

		ExecuteStatement(*pStat,
				 IDS_RU_LOG_CLEANUP_FAILED,
				 NULL, /* error argument */
				 TRUE /* Obtain row count */);

		CommitTransaction();

		TESTPOINT(CRUGlobals::TESTPOINT160); 

		if (pStat->GetRowsAffected() < 
			CRULogCleanupSQLComposer::MAX_ROW_TO_DELETE_IN_SINGLE_TXN)
		{
			break;
		}
	}
}
void CRUTableSyncTaskExecutor::Epilogue()
{
	CRUTableSyncTask *pParentTask = (CRUTableSyncTask *)GetParentTask();

	RUASSERT(NULL != pParentTask);

	CRUTbl &tbl = pParentTask->GetTable();

	if (TRUE == tbl.IsIncEpochNeeded())
	{
		if (TRUE == tbl.IsLongLockNeeded())
		{
			BeginTransaction();
			tbl.ExecuteReadProtectedOpen();
			CommitTransaction();
		}

		if (TRUE == tbl.IsLogRPOpenPending())
		{
			// The above condition is false only in case of 
			// a non involved incremental mv.We do not need to lock the logs 
			// because we rely on the ddl locks
			tbl.ReleaseLogReadProtectedOpen();
		}
	}
	SetState(EX_COMPLETE);

}
void CRUAuditRefreshTaskExecutor::Prologue()
{
	RUASSERT(FALSE == IsTransactionOpen());	    

        BeginTransaction();
        if (CDDObject::eON_STATEMENT == GetRootMVType())
	{
		PrologueHandleOnStatementMV();
	}
			
	SetObjectsUnavailable();		        	      
        CommitTransaction();

        TESTPOINT2(CRUGlobals::TESTPOINT102, GetRootMVName());

	if (TRUE == isPurgedata_) 
	{	
		// purgedata is done in main process           
		SetState(EX_PURGE_DATA);
	}
	else 
	{
		// refresh, recompute, and popindex done in remote process
		SetState(EX_REMOTE_START);
	}	
}
Exemplo n.º 12
0
void
ClientLayerManager::EndTransaction(DrawPaintedLayerCallback aCallback,
                                   void* aCallbackData,
                                   EndTransactionFlags aFlags)
{
  if (!mForwarder->IPCOpen()) {
    mInTransaction = false;
    return;
  }

  if (mWidget) {
    mWidget->PrepareWindowEffects();
  }
  EndTransactionInternal(aCallback, aCallbackData, aFlags);
  ForwardTransaction(!(aFlags & END_NO_REMOTE_COMPOSITE));

  if (mRepeatTransaction) {
    mRepeatTransaction = false;
    mIsRepeatTransaction = true;
    if (BeginTransaction()) {
      ClientLayerManager::EndTransaction(aCallback, aCallbackData, aFlags);
    }
    mIsRepeatTransaction = false;
  } else {
    MakeSnapshotIfRequired();
  }

  mInTransaction = false;
  mTransactionStart = TimeStamp();
}
Exemplo n.º 13
0
void
ClientLayerManager::EndTransaction(DrawPaintedLayerCallback aCallback,
                                   void* aCallbackData,
                                   EndTransactionFlags aFlags)
{
  if (mWidget) {
    mWidget->PrepareWindowEffects();
  }
  EndTransactionInternal(aCallback, aCallbackData, aFlags);
  ForwardTransaction(!(aFlags & END_NO_REMOTE_COMPOSITE));

  if (mRepeatTransaction) {
    mRepeatTransaction = false;
    mIsRepeatTransaction = true;
    BeginTransaction();
    ClientLayerManager::EndTransaction(aCallback, aCallbackData, aFlags);
    mIsRepeatTransaction = false;
  } else {
    MakeSnapshotIfRequired();
  }

  for (size_t i = 0; i < mTexturePools.Length(); i++) {
    mTexturePools[i]->ReturnDeferredClients();
  }

  mInTransaction = false;
  mTransactionStart = TimeStamp();
}
NS_IMETHODIMP
nsTransactionManager::BeginBatch()
{
  nsresult result;

  // We can batch independent transactions together by simply pushing
  // a dummy transaction item on the do stack. This dummy transaction item
  // will be popped off the do stack, and then pushed on the undo stack
  // in EndBatch().

  bool doInterrupt = false;

  result = WillBeginBatchNotify(&doInterrupt);

  if (NS_FAILED(result)) {
    return result;
  }

  if (doInterrupt) {
    return NS_OK;
  }

  result = BeginTransaction(0);
  
  nsresult result2 = DidBeginBatchNotify(result);

  if (NS_SUCCEEDED(result))
    result = result2;

  return result;
}
NS_IMETHODIMP
nsTransactionManager::DoTransaction(nsITransaction *aTransaction)
{
  nsresult result;

  NS_ENSURE_TRUE(aTransaction, NS_ERROR_NULL_POINTER);

  bool doInterrupt = false;

  result = WillDoNotify(aTransaction, &doInterrupt);

  if (NS_FAILED(result)) {
    return result;
  }

  if (doInterrupt) {
    return NS_OK;
  }

  result = BeginTransaction(aTransaction);

  if (NS_FAILED(result)) {
    DidDoNotify(aTransaction, result);
    return result;
  }

  result = EndTransaction();

  nsresult result2 = DidDoNotify(aTransaction, result);

  if (NS_SUCCEEDED(result))
    result = result2;

  return result;
}
Exemplo n.º 16
0
fsal_posixdb_status_t fsal_posixdb_delete(fsal_posixdb_conn * p_conn,   /* IN */
                                          posixfsal_handle_t * p_parent_directory_handle,       /* IN */
                                          fsal_name_t * p_filename,     /* IN */
                                          fsal_posixdb_fileinfo_t *
                                          p_object_info /* IN */ )
{
  result_handle_t res;
  fsal_posixdb_status_t st;
  char query[2048];

    /*******************
     * 1/ sanity check *
     *******************/

  if(!p_conn || !p_parent_directory_handle || !p_filename)
    ReturnCodeDB(ERR_FSAL_POSIXDB_FAULT, 0);

  BeginTransaction(p_conn);

    /*******************************
     * 2/ we check the file exists *
     *******************************/

  snprintf(query, 2048, "SELECT Parent.handleid, Parent.handlets, "
           "Handle.deviceid, Handle.inode, Handle.nlink, Handle.ctime, Handle.ftype "
           "FROM Parent INNER JOIN Handle ON Parent.handleid = Handle.handleid "
           "AND Parent.handlets=Handle.handlets "
           "WHERE handleidparent=%llu AND handletsparent=%u AND name='%s' "
           "FOR UPDATE", p_parent_directory_handle->data.id,
           p_parent_directory_handle->data.ts, p_filename->name);

  st = db_exec_sql(p_conn, query, &res);
  if(FSAL_POSIXDB_IS_ERROR(st))
    goto rollback;

  if(mysql_num_rows(res) != 1)
    {
      /* parent entry not found */
      mysql_free_result(res);
      RollbackTransaction(p_conn);
      ReturnCodeDB(ERR_FSAL_POSIXDB_NOENT, 0);
    }
  mysql_free_result(res);

    /***********************************************
     * 3/ Get information about the file to delete *
     ***********************************************/

  st = fsal_posixdb_internal_delete(p_conn, p_parent_directory_handle->data.id,
                                    p_parent_directory_handle->data.ts,
                                    p_filename->name, p_object_info);
  if(FSAL_POSIXDB_IS_ERROR(st))
    goto rollback;

  return EndTransaction(p_conn);

 rollback:
  RollbackTransaction(p_conn);
  return st;
}
Exemplo n.º 17
0
/** 
 * @brief Lock the line of the Handle table with inode & devid defined in p_info
 * 
 * @param p_conn
 *        Database connection
 * @param p_info 
 *        Information about the file
 * 
 * @return ERR_FSAL_POSIXDB_NOERR if no error,
 *         another error code else.
 */
fsal_posixdb_status_t fsal_posixdb_lockHandleForUpdate(fsal_posixdb_conn * p_conn,      /* IN */
                                                       fsal_posixdb_fileinfo_t *
                                                       p_info /* IN */ )
{
  result_handle_t res;
  fsal_posixdb_status_t st;
  char query[2048];

  BeginTransaction(p_conn);

  snprintf(query, 2048, "SELECT handleid, handlets, nlink, ctime, ftype "
           "FROM Handle WHERE deviceid=%llu AND inode=%llu "
           "FOR UPDATE", (unsigned long long)p_info->devid, (unsigned long long)p_info->inode);

  st = db_exec_sql(p_conn, query, &res);
  if(FSAL_POSIXDB_IS_ERROR(st))
    {
      RollbackTransaction(p_conn);
      return st;
    }

  mysql_free_result(res);

  /* Do not end the transaction, because it will be closed by the next call to a posixdb function */

  ReturnCodeDB(ERR_FSAL_POSIXDB_NOERR, 0);
}
void CRUAuditRefreshTaskExecutor::Epilogue()
{
	RUASSERT(FALSE == IsTransactionOpen());

        EndTimer();

        BeginTransaction();

	// if this is the first refresh, the MV status can be
        // changed to initialized
	if( TRUE == GetRefreshTask()->NeedToExecuteInternalRefresh() )
	{
        	if (CDDObject::eON_STATEMENT == GetRootMVType())
		{
			EpilogueHandleOnStatementMV();
		}		
		ResetObjectsAvailable();	
	}		

	FinalMetadataUpdate();

	CommitTransaction();

	TESTPOINT2(CRUGlobals::TESTPOINT131, GetRootMVName());
	
	LogClosureMessage();

	SetState(EX_COMPLETE);
}
Exemplo n.º 19
0
CAutoTrans::CAutoTrans(CDB_Connection& connection)
: m_Abort(true)
, m_Conn(connection)
, m_TranCount(0)
{
    BeginTransaction();
    m_TranCount = GetTranCount();
}
void CRUEmpCheckTaskExecutor::
PerformEmptinessCheck()
{
	pEmpCheck_->PrepareSQL();

	BeginTransaction();
	pEmpCheck_->PerformCheck();		
	CommitTransaction(); // Although no write operations were performed...
}
void CRUAuditRefreshTaskExecutor::Refresh()
{
	RUASSERT(TRUE == IsTransactionOpen());

	// Simulate a system error at this point!
	TESTPOINT_SEVERE(CRUGlobals::SEVERE_REFRESH_CRASH);

	try 
	{		
		ApplyIRCompilerDefaults();

		if(TRUE == IsSingleDeltaRefresh())
		{
			CDMPreparedStatement *pStat = PrepareSingleDeltaRefresh();

			CommitTransaction();
			BeginTransaction();

			ExecuteSingleDeltaRefresh(pStat);
		}
		else
		{
			StmtList *stmts = PrepareMultiDeltasRefresh();

			CommitTransaction();
			BeginTransaction();

			ExecuteMultiDeltasRefresh(stmts);
		}

		ResetIRCompilerDefaults();

		ExecuteShowExplain();

		SetState(EX_REMOTE_END);
	}
	catch (CRUSimpleRefreshTaskExecutor::NeedRecomputeException)
	{
		// If a min/max value was deleted an exception will be thrown and
		// then we need to recompute the mv
		SetState(EX_RECOMPUTE);
		SetRecompute(TRUE);
	}
}
void CRUAuditRefreshTaskExecutor::PopulateIndexes()
{
	RUASSERT(TRUE == isPopindex_);

	if (0 == numOfIndexes_)
	{
		return;
	}

        // toggle audit flag OFF for indices to do the
        // side tree insert
        BeginTransaction();
        ToggleIndicesAudit(FALSE);        
        CommitTransaction();
        

	// ?????
	// Temporary - Should be removed when read commited from unaudited table is implemented
	BeginTransaction();

#ifdef _DEBUG
	CDSString msg(
		"\nPopulating the secondary indexes of materialized view " 
		+ GetRootMVName() + "...\n");

	CRUGlobals::GetInstance()->
		LogDebugMessage(CRUGlobals::DUMP_POPINDEX,"",msg);
#endif

	ExecuteIndexStatmenents(*pAuditPopIndexdynamicContainer_, IDS_RU_POPINDEX_FAILED);
        
        CommitTransaction();

	TESTPOINT2(CRUGlobals::TESTPOINT105, GetRootMVName());

        // toggle the audit flag for the indices back on
        BeginTransaction();
        ToggleIndicesAudit(TRUE);
        // transaction gets committed in EX_REMOTE_END...

	SetState(EX_REMOTE_END);
}
Exemplo n.º 23
0
bool MySqlConnection::ExecuteTransaction(MySqlTransaction* transaction)
{
	std::list<SQLElementData> const& queries = transaction->m_queries;
	if (queries.empty())
	{
		TRACE_LOG("MySqlConnection::ExecuteTransaction:quries is empty\n");
		return true;
	}

	if (!BeginTransaction())
	{
		TRACE_LOG("MySqlConnection::ExecuteTransaction:BeginTransaction\n");
        return false;
	}

	std::list<SQLElementData>::const_iterator itr;
	for (itr = queries.begin(); itr != queries.end(); ++itr)
	{
		SQLElementData const& data = *itr;
		switch (itr->type)
		{
			case SQL_ELEMENT_PREPARED:
            {
                PreparedStmt* stmt = data.element.stmt;
                if (!Execute(stmt))
                {
                    WARNING_LOG("Transaction aborted. %u queries not executed.\n", static_cast<uint32>(queries.size()));
                    RollbackTransaction();
                    return false;
                }
            }
            break;
			case SQL_ELEMENT_RAW:
            {
                const char* sql = data.element.query;
                if (!Execute(sql))
                {
                    WARNING_LOG("Transaction aborted. %u queries not executed.\n", static_cast<uint32>(queries.size()));
                    RollbackTransaction();
                    return false;
                }
            }
            break;
		}
	}

	// we might encounter errors during certain queries, and depending on the kind of error
	// we might want to restart the transaction. So to prevent data loss, we only clean up when it's all done.
	// This is done in calling functions DatabaseWorkerPool<T>::DirectCommitTransaction and TransactionTask::Execute,
	// and not while iterating over every element.

	CommitTransaction();
	return true;
}
void FResizeSection::OnBeginDrag(const FVector2D& LocalMousePos, TSharedPtr<FTrackNode> SequencerNode)
{
	if( Section.IsValid() )
	{
		BeginTransaction( *Section, NSLOCTEXT("Sequencer", "DragSectionEdgeTransaction", "Resize section") );

		DraggedKeyHandles.Empty();

		Section->GetKeyHandles(DraggedKeyHandles);
	}
}
Exemplo n.º 25
0
void FSCSEditorViewportClient::TrackingStarted( const struct FInputEventState& InInputState, bool bIsDraggingWidget, bool bNudge )
{
	if( !bIsManipulating && bIsDraggingWidget )
	{
		// Suspend component modification during each delta step to avoid recording unnecessary overhead into the transaction buffer
		GEditor->DisableDeltaModification(true);

		// Begin transaction
		BeginTransaction( NSLOCTEXT("UnrealEd", "ModifyComponents", "Modify Component(s)") );
		bIsManipulating = true;
	}
}
Exemplo n.º 26
0
FReply FCanvasSlotExtension::HandleAnchorBeginDrag(const FGeometry& Geometry, const FPointerEvent& Event, EAnchorWidget::Type AnchorType)
{
	BeginTransaction(LOCTEXT("MoveAnchor", "Move Anchor"));

	bMovingAnchor = true;
	MouseDownPosition = Event.GetScreenSpacePosition();

	UCanvasPanelSlot* PreviewCanvasSlot = Cast<UCanvasPanelSlot>(SelectionCache[0].GetPreview()->Slot);
	BeginAnchors = PreviewCanvasSlot->LayoutData.Anchors;

	return FReply::Handled().CaptureMouse(AnchorWidgets[(int32)AnchorType].ToSharedRef());
}
void FSingleTileEditorViewportClient::TrackingStarted(const struct FInputEventState& InInputState, bool bIsDragging, bool bNudge)
{
	//@TODO: Should push this into FEditorViewportClient
	// Begin transacting.  Give the current editor mode an opportunity to do the transacting.
	const bool bTrackingHandledExternally = ModeTools->StartTracking(this, Viewport);

	if (!bManipulating && bIsDragging && !bTrackingHandledExternally)
	{
		BeginTransaction(LOCTEXT("ModificationInViewport", "Modification in Viewport"));
		bManipulating = true;
		bManipulationDirtiedSomething = false;
	}
}
Exemplo n.º 28
0
int MySQLConnection::ExecuteTransaction(SQLTransaction& transaction)
{
    std::list<SQLElementData> const& queries = transaction->m_queries;
    if (queries.empty())
        return -1;

    BeginTransaction();

    std::list<SQLElementData>::const_iterator itr;
    for (itr = queries.begin(); itr != queries.end(); ++itr)
    {
        SQLElementData const& data = *itr;
        switch (itr->type)
        {
            case SQL_ELEMENT_PREPARED:
            {
                PreparedStatement* stmt = data.element.stmt;
                ASSERT(stmt);
                if (!Execute(stmt))
                {
                    TC_LOG_WARN("sql.sql", "Transaction aborted. %u queries not executed.", (uint32)queries.size());
                    int errorCode = GetLastError();
                    RollbackTransaction();
                    return errorCode;
                }
            }
            break;
            case SQL_ELEMENT_RAW:
            {
                const char* sql = data.element.query;
                ASSERT(sql);
                if (!Execute(sql))
                {
                    TC_LOG_WARN("sql.sql", "Transaction aborted. %u queries not executed.", (uint32)queries.size());
                    int errorCode = GetLastError();
                    RollbackTransaction();
                    return errorCode;
                }
            }
            break;
        }
    }

    // we might encounter errors during certain queries, and depending on the kind of error
    // we might want to restart the transaction. So to prevent data loss, we only clean up when it's all done.
    // This is done in calling functions DatabaseWorkerPool<T>::DirectCommitTransaction and TransactionTask::Execute,
    // and not while iterating over every element.

    CommitTransaction();
    return 0;
}
void MySqlFactoryDal::CleanupOldRecords(nlib::DateTime olderThanDate, nlib::DateTime olderThanAlertDate)
{
	nlib::DateTime currTime = nlib::CurrentUniversalTime();

	const char *pszQry[] ={
		"DELETE FROM CommandParameters WHERE CommandID IN (SELECT C.CommandID from Commands C WHERE C.TimePosted < \"%s\");",	// +24*7
		"DELETE FROM Commands WHERE TimePosted < \"%s\";",	// +24*7
		"DELETE FROM CommandParameters WHERE CommandID IN (SELECT C.CommandID from Commands C WHERE C.TimePosted < \"%s\" AND (C.CommandStatus = 2 OR C.CommandStatus = 3));",
		"DELETE FROM Commands WHERE TimePosted < \"%s\" AND (CommandStatus = 2 OR CommandStatus = 3);",
		"DELETE FROM DeviceReadingsHistory WHERE ReadingTime < \"%s\";",
		//there is other approach
		//"DELETE FROM DeviceHistory WHERE Timestamp < \"%s\";",
		"DELETE FROM DeviceHealthHistory WHERE Timestamp < \"%s\";",
		"DELETE FROM NeighborHealthHistory WHERE Timestamp < \"%s\";",
		"DELETE FROM AlertNotifications WHERE AlertTime < \"%s\";",
		"DELETE FROM DeviceChannelsHistory WHERE Timestamp < \"%s\";",
		"DELETE FROM ISACSConfirmDataBuffer WHERE Timestamp < \"%s\";",
		"DELETE FROM Firmwares WHERE UploadStatus = 5 AND UploadDate < \"%s\";"
	};

	LOG("DEBUG CleanupOldRecords START [%s] [%s]", nlib::ToString(olderThanDate).c_str(), nlib::ToString(currTime - nlib::util::hours(24*7)).c_str());
	for( int i = 0; i< sizeof(pszQry) / sizeof(pszQry[0]); ++i)
	{	char szQry[ 1024 ];
		snprintf( szQry, sizeof(szQry), pszQry[i], (i>=2)
			? nlib::ToString(olderThanDate).c_str() 
			: (nlib::ToString(currTime - nlib::util::hours(24*7)).c_str()) );
		szQry[ sizeof(szQry)-1 ] = 0;
		std::string obQry( szQry );
		MySQLCommand command(connection, obQry);
		try
		{
			BeginTransaction();
			command.ExecuteNonQuery();
			CommitTransaction();
		}
		catch(std::exception& ex)
		{
			LOG_ERROR("CATCH(exception): CleanupOldRecords failed at step=" << i << " error=" << ex.what());
			RollbackTransaction();
		}
		catch(...)
		{
			LOG_ERROR("CATCH(...): CleanupOldRecords failed at step=" << i );
			RollbackTransaction();
		}
	}
	LOG_STR("DEBUG CleanupOldRecords END");

}
Exemplo n.º 30
0
FReply FGridSlotExtension::HandleShiftColumn(int32 ShiftAmount)
{
	BeginTransaction(LOCTEXT("MoveWidget", "Move Widget"));

	for ( FWidgetReference& Selection : SelectionCache )
	{
		ShiftColumn(Selection.GetPreview(), ShiftAmount);
		ShiftColumn(Selection.GetTemplate(), ShiftAmount);
	}

	EndTransaction();

	FBlueprintEditorUtils::MarkBlueprintAsModified(Blueprint);

	return FReply::Handled();
}