/// <summary>Archives a Exchange 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="exchangeId">The value for the ExchangeId column.</param> /// <param name="archive">true to archive the object, false to unarchive it.</param> public static void Archive(AdoTransaction adoTransaction, SqlTransaction sqlTransaction, long rowVersion, int exchangeId) { // Accessor for the Exchange Table. ServerMarketData.ExchangeDataTable exchangeTable = ServerMarketData.Exchange; // Rule #1: Make sure the record exists before updating it. ServerMarketData.ExchangeRow exchangeRow = exchangeTable.FindByExchangeId(exchangeId); if ((exchangeRow == null)) { throw new Exception(string.Format("The Exchange table does not have an element identified by {0}", exchangeId)); } // Rule #2: Optimistic Concurrency Check if ((exchangeRow.RowVersion != rowVersion)) { throw new System.Exception("This record is busy. Please try again later."); } // Archive the child records. for (int index = 0; (index < exchangeRow.GetEquityRows().Length); index = (index + 1)) { ServerMarketData.EquityRow childEquityRow = exchangeRow.GetEquityRows()[index]; Equity.ArchiveChildren(adoTransaction, sqlTransaction, childEquityRow.RowVersion, childEquityRow.EquityId); } // Increment the row version rowVersion = ServerMarketData.RowVersion.Increment(); // Delete the record in the ADO database. exchangeRow[exchangeTable.RowVersionColumn] = rowVersion; adoTransaction.DataRows.Add(exchangeRow); exchangeRow.Delete(); // Archive the record in the SQL database. SqlCommand sqlCommand = new SqlCommand("update \"Exchange\" set \"IsArchived\" = 1 where \"ExchangeId\"=@exchangeId"); sqlCommand.Connection = sqlTransaction.Connection; sqlCommand.Transaction = sqlTransaction; sqlCommand.Parameters.Add(new SqlParameter("@exchangeId", SqlDbType.Int, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, exchangeId)); 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.SecurityLock); AccountBase.ArchiveChildren(adoTransaction); Allocation.Archive(adoTransaction); Currency.ArchiveChildren(adoTransaction); Debt.ArchiveChildren(adoTransaction); Equity.ArchiveChildren(adoTransaction); Position.Archive(adoTransaction); Price.Archive(adoTransaction); SourceOrder.Archive(adoTransaction); TaxLot.Archive(adoTransaction); WorkingOrder.Archive(adoTransaction); }
/// <summary>ArchiveChildrens a Security 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="securityId">The value for the SecurityId 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 securityId) { // Accessor for the Security Table. ServerMarketData.SecurityDataTable securityTable = ServerMarketData.Security; // This record can be used to iterate through all the children. ServerMarketData.SecurityRow securityRow = securityTable.FindBySecurityId(securityId); // Archive the child records. for (int index = 0; (index < securityRow.GetAccountBaseRows().Length); index = (index + 1)) { ServerMarketData.AccountBaseRow childAccountBaseRow = securityRow.GetAccountBaseRows()[index]; AccountBase.ArchiveChildren(adoTransaction, sqlTransaction, childAccountBaseRow.RowVersion, childAccountBaseRow.AccountBaseId); } for (int index = 0; (index < securityRow.GetAllocationRowsBySecurityAllocationSecurityId().Length); index = (index + 1)) { ServerMarketData.AllocationRow childAllocationRow = securityRow.GetAllocationRowsBySecurityAllocationSecurityId()[index]; Allocation.Archive(adoTransaction, sqlTransaction, childAllocationRow.RowVersion, childAllocationRow.AllocationId); } for (int index = 0; (index < securityRow.GetAllocationRowsBySecurityAllocationSettlementId().Length); index = (index + 1)) { ServerMarketData.AllocationRow childAllocationRow = securityRow.GetAllocationRowsBySecurityAllocationSettlementId()[index]; Allocation.Archive(adoTransaction, sqlTransaction, childAllocationRow.RowVersion, childAllocationRow.AllocationId); } for (int index = 0; (index < securityRow.GetCurrencyRows().Length); index = (index + 1)) { ServerMarketData.CurrencyRow childCurrencyRow = securityRow.GetCurrencyRows()[index]; Currency.ArchiveChildren(adoTransaction, sqlTransaction, childCurrencyRow.RowVersion, childCurrencyRow.CurrencyId); } for (int index = 0; (index < securityRow.GetDebtRowsBySecurityDebtDebtId().Length); index = (index + 1)) { ServerMarketData.DebtRow childDebtRow = securityRow.GetDebtRowsBySecurityDebtDebtId()[index]; Debt.ArchiveChildren(adoTransaction, sqlTransaction, childDebtRow.RowVersion, childDebtRow.DebtId); } for (int index = 0; (index < securityRow.GetDebtRowsBySecurityDebtSettlementId().Length); index = (index + 1)) { ServerMarketData.DebtRow childDebtRow = securityRow.GetDebtRowsBySecurityDebtSettlementId()[index]; Debt.ArchiveChildren(adoTransaction, sqlTransaction, childDebtRow.RowVersion, childDebtRow.DebtId); } for (int index = 0; (index < securityRow.GetEquityRowsBySecurityEquityEquityId().Length); index = (index + 1)) { ServerMarketData.EquityRow childEquityRow = securityRow.GetEquityRowsBySecurityEquityEquityId()[index]; Equity.ArchiveChildren(adoTransaction, sqlTransaction, childEquityRow.RowVersion, childEquityRow.EquityId); } for (int index = 0; (index < securityRow.GetEquityRowsBySecurityEquitySettlementId().Length); index = (index + 1)) { ServerMarketData.EquityRow childEquityRow = securityRow.GetEquityRowsBySecurityEquitySettlementId()[index]; Equity.ArchiveChildren(adoTransaction, sqlTransaction, childEquityRow.RowVersion, childEquityRow.EquityId); } for (int index = 0; (index < securityRow.GetPositionRows().Length); index = (index + 1)) { ServerMarketData.PositionRow childPositionRow = securityRow.GetPositionRows()[index]; Position.Archive(adoTransaction, sqlTransaction, childPositionRow.RowVersion, childPositionRow.AccountId, childPositionRow.SecurityId, childPositionRow.PositionTypeCode); } for (int index = 0; (index < securityRow.GetPriceRows().Length); index = (index + 1)) { ServerMarketData.PriceRow childPriceRow = securityRow.GetPriceRows()[index]; Price.Archive(adoTransaction, sqlTransaction, childPriceRow.RowVersion, childPriceRow.SecurityId); } for (int index = 0; (index < securityRow.GetSourceOrderRowsBySecuritySourceOrderSecurityId().Length); index = (index + 1)) { ServerMarketData.SourceOrderRow childSourceOrderRow = securityRow.GetSourceOrderRowsBySecuritySourceOrderSecurityId()[index]; SourceOrder.Archive(adoTransaction, sqlTransaction, childSourceOrderRow.RowVersion, childSourceOrderRow.SourceOrderId); } for (int index = 0; (index < securityRow.GetSourceOrderRowsBySecuritySourceOrderSettlementId().Length); index = (index + 1)) { ServerMarketData.SourceOrderRow childSourceOrderRow = securityRow.GetSourceOrderRowsBySecuritySourceOrderSettlementId()[index]; SourceOrder.Archive(adoTransaction, sqlTransaction, childSourceOrderRow.RowVersion, childSourceOrderRow.SourceOrderId); } for (int index = 0; (index < securityRow.GetTaxLotRows().Length); index = (index + 1)) { ServerMarketData.TaxLotRow childTaxLotRow = securityRow.GetTaxLotRows()[index]; TaxLot.Archive(adoTransaction, sqlTransaction, childTaxLotRow.RowVersion, childTaxLotRow.TaxLotId); } for (int index = 0; (index < securityRow.GetWorkingOrderRowsBySecurityWorkingOrderSecurityId().Length); index = (index + 1)) { ServerMarketData.WorkingOrderRow childWorkingOrderRow = securityRow.GetWorkingOrderRowsBySecurityWorkingOrderSecurityId()[index]; WorkingOrder.Archive(adoTransaction, sqlTransaction, childWorkingOrderRow.RowVersion, childWorkingOrderRow.WorkingOrderId); } for (int index = 0; (index < securityRow.GetWorkingOrderRowsBySecurityWorkingOrderSettlementId().Length); index = (index + 1)) { ServerMarketData.WorkingOrderRow childWorkingOrderRow = securityRow.GetWorkingOrderRowsBySecurityWorkingOrderSettlementId()[index]; WorkingOrder.Archive(adoTransaction, sqlTransaction, childWorkingOrderRow.RowVersion, childWorkingOrderRow.WorkingOrderId); } // Increment the row version rowVersion = ServerMarketData.RowVersion.Increment(); // Delete the record in the ADO database. securityRow[securityTable.RowVersionColumn] = rowVersion; adoTransaction.DataRows.Add(securityRow); securityRow.Delete(); // Archive the record in the SQL database. SqlCommand sqlCommand = new SqlCommand("update \"Security\" set \"IsArchived\" = 1 where \"SecurityId\"=@securityId"); sqlCommand.Connection = sqlTransaction.Connection; sqlCommand.Transaction = sqlTransaction; sqlCommand.Parameters.Add(new SqlParameter("@securityId", SqlDbType.Int, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, securityId)); 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> public static void Archive(AdoTransaction adoTransaction) { // These table lock(s) are required for the 'Archive' operation. adoTransaction.LockRequests.AddWriterLock(ServerMarketData.ExchangeLock); Equity.ArchiveChildren(adoTransaction); }