/// <summary>ArchiveChildrens a AccountBase record.</summary> /// <param name="transaction">Commits or rejects a set of commands as a unit</param> /// <param name="rowVersion">the version number of this row.</param> /// <param name="accountBaseId">The value for the AccountBaseId column.</param> /// <param name="archive">true to archive the object, false to unarchive it.</param> internal static void ArchiveChildren(AdoTransaction adoTransaction, SqlTransaction sqlTransaction, long rowVersion, int accountBaseId) { // Accessor for the AccountBase Table. ServerMarketData.AccountBaseDataTable accountBaseTable = ServerMarketData.AccountBase; // This record can be used to iterate through all the children. ServerMarketData.AccountBaseRow accountBaseRow = accountBaseTable.FindByAccountBaseId(accountBaseId); // Archive the child records. for (int index = 0; (index < accountBaseRow.GetAccountRows().Length); index = (index + 1)) { ServerMarketData.AccountRow childAccountRow = accountBaseRow.GetAccountRows()[index]; Account.ArchiveChildren(adoTransaction, sqlTransaction, childAccountRow.RowVersion, childAccountRow.AccountId); } for (int index = 0; (index < accountBaseRow.GetAccountGroupRows().Length); index = (index + 1)) { ServerMarketData.AccountGroupRow childAccountGroupRow = accountBaseRow.GetAccountGroupRows()[index]; AccountGroup.ArchiveChildren(adoTransaction, sqlTransaction, childAccountGroupRow.RowVersion, childAccountGroupRow.AccountGroupId); } // Increment the row version rowVersion = ServerMarketData.RowVersion.Increment(); // Delete the record in the ADO database. accountBaseRow[accountBaseTable.RowVersionColumn] = rowVersion; adoTransaction.DataRows.Add(accountBaseRow); accountBaseRow.Delete(); // Archive the record in the SQL database. SqlCommand sqlCommand = new SqlCommand("update \"AccountBase\" set \"IsArchived\" = 1 where \"AccountBaseId\"=@accountBaseId"); sqlCommand.Connection = sqlTransaction.Connection; sqlCommand.Transaction = sqlTransaction; sqlCommand.Parameters.Add(new SqlParameter("@accountBaseId", SqlDbType.Int, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, accountBaseId)); sqlCommand.ExecuteNonQuery(); }
/// <summary>Collects the table lock request(s) for an Update operation</summary> /// <param name="adoTransaction">A list of locks required for this operation.</param> internal static void ArchiveChildren(AdoTransaction adoTransaction) { // These table lock(s) are required for the 'Archive' operation. adoTransaction.LockRequests.AddWriterLock(ServerMarketData.AccountBaseLock); Account.ArchiveChildren(adoTransaction); AccountGroup.ArchiveChildren(adoTransaction); }