/// <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. ServerDataModel.SecurityDataTable securityTable = ServerDataModel.Security; // This record can be used to iterate through all the children. ServerDataModel.SecurityRow securityRow = securityTable.FindBySecurityId(securityId); // Archive the child records. for (int index = 0; (index < securityRow.GetAccountRows().Length); index = (index + 1)) { ServerDataModel.AccountRow childAccountRow = securityRow.GetAccountRows()[index]; Account.ArchiveChildren(adoTransaction, sqlTransaction, childAccountRow.RowVersion, childAccountRow.AccountId); } for (int index = 0; (index < securityRow.GetAllocationRowsByFKSecurityAllocationSecurityId().Length); index = (index + 1)) { ServerDataModel.AllocationRow childAllocationRow = securityRow.GetAllocationRowsByFKSecurityAllocationSecurityId()[index]; Allocation.Archive(adoTransaction, sqlTransaction, childAllocationRow.RowVersion, childAllocationRow.AllocationId); } for (int index = 0; (index < securityRow.GetAllocationRowsByFKSecurityAllocationSettlementId().Length); index = (index + 1)) { ServerDataModel.AllocationRow childAllocationRow = securityRow.GetAllocationRowsByFKSecurityAllocationSettlementId()[index]; Allocation.Archive(adoTransaction, sqlTransaction, childAllocationRow.RowVersion, childAllocationRow.AllocationId); } for (int index = 0; (index < securityRow.GetBlockOrderRowsByFKSecurityBlockOrderSecurityId().Length); index = (index + 1)) { ServerDataModel.BlockOrderRow childBlockOrderRow = securityRow.GetBlockOrderRowsByFKSecurityBlockOrderSecurityId()[index]; BlockOrder.Archive(adoTransaction, sqlTransaction, childBlockOrderRow.RowVersion, childBlockOrderRow.BlockOrderId); } for (int index = 0; (index < securityRow.GetBlockOrderRowsByFKSecurityBlockOrderSettlementId().Length); index = (index + 1)) { ServerDataModel.BlockOrderRow childBlockOrderRow = securityRow.GetBlockOrderRowsByFKSecurityBlockOrderSettlementId()[index]; BlockOrder.Archive(adoTransaction, sqlTransaction, childBlockOrderRow.RowVersion, childBlockOrderRow.BlockOrderId); } for (int index = 0; (index < securityRow.GetBlotterMapRows().Length); index = (index + 1)) { ServerDataModel.BlotterMapRow childBlotterMapRow = securityRow.GetBlotterMapRows()[index]; BlotterMap.Archive(adoTransaction, sqlTransaction, childBlotterMapRow.RowVersion, childBlotterMapRow.BlotterMapId); } for (int index = 0; (index < securityRow.GetDebtRowsByFKSecurityDebtDebtId().Length); index = (index + 1)) { ServerDataModel.DebtRow childDebtRow = securityRow.GetDebtRowsByFKSecurityDebtDebtId()[index]; Debt.ArchiveChildren(adoTransaction, sqlTransaction, childDebtRow.RowVersion, childDebtRow.DebtId); } for (int index = 0; (index < securityRow.GetDebtRowsByFKSecurityDebtSettlementId().Length); index = (index + 1)) { ServerDataModel.DebtRow childDebtRow = securityRow.GetDebtRowsByFKSecurityDebtSettlementId()[index]; Debt.ArchiveChildren(adoTransaction, sqlTransaction, childDebtRow.RowVersion, childDebtRow.DebtId); } for (int index = 0; (index < securityRow.GetCurrencyRows().Length); index = (index + 1)) { ServerDataModel.CurrencyRow childCurrencyRow = securityRow.GetCurrencyRows()[index]; Currency.ArchiveChildren(adoTransaction, sqlTransaction, childCurrencyRow.RowVersion, childCurrencyRow.CurrencyId); } for (int index = 0; (index < securityRow.GetEquityRowsByFKSecurityEquityEquityId().Length); index = (index + 1)) { ServerDataModel.EquityRow childEquityRow = securityRow.GetEquityRowsByFKSecurityEquityEquityId()[index]; Equity.ArchiveChildren(adoTransaction, sqlTransaction, childEquityRow.RowVersion, childEquityRow.EquityId); } for (int index = 0; (index < securityRow.GetEquityRowsByFKSecurityEquitySettlementId().Length); index = (index + 1)) { ServerDataModel.EquityRow childEquityRow = securityRow.GetEquityRowsByFKSecurityEquitySettlementId()[index]; Equity.ArchiveChildren(adoTransaction, sqlTransaction, childEquityRow.RowVersion, childEquityRow.EquityId); } for (int index = 0; (index < securityRow.GetOrderRowsByFKSecurityOrderSecurityId().Length); index = (index + 1)) { ServerDataModel.OrderRow childOrderRow = securityRow.GetOrderRowsByFKSecurityOrderSecurityId()[index]; Order.Archive(adoTransaction, sqlTransaction, childOrderRow.RowVersion, childOrderRow.OrderId); } for (int index = 0; (index < securityRow.GetOrderRowsByFKSecurityOrderSettlementId().Length); index = (index + 1)) { ServerDataModel.OrderRow childOrderRow = securityRow.GetOrderRowsByFKSecurityOrderSettlementId()[index]; Order.Archive(adoTransaction, sqlTransaction, childOrderRow.RowVersion, childOrderRow.OrderId); } for (int index = 0; (index < securityRow.GetPositionRows().Length); index = (index + 1)) { ServerDataModel.PositionRow childPositionRow = securityRow.GetPositionRows()[index]; Position.Archive(adoTransaction, sqlTransaction, childPositionRow.RowVersion, childPositionRow.AccountId, childPositionRow.SecurityId, childPositionRow.PositionTypeCode); } for (int index = 0; (index < securityRow.GetPositionTargetRows().Length); index = (index + 1)) { ServerDataModel.PositionTargetRow childPositionTargetRow = securityRow.GetPositionTargetRows()[index]; PositionTarget.Archive(adoTransaction, sqlTransaction, childPositionTargetRow.RowVersion, childPositionTargetRow.ModelId, childPositionTargetRow.SecurityId, childPositionTargetRow.PositionTypeCode); } for (int index = 0; (index < securityRow.GetPriceRows().Length); index = (index + 1)) { ServerDataModel.PriceRow childPriceRow = securityRow.GetPriceRows()[index]; Price.Archive(adoTransaction, sqlTransaction, childPriceRow.RowVersion, childPriceRow.SecurityId, childPriceRow.CurrencyId); } for (int index = 0; (index < securityRow.GetProposedOrderRowsByFKSecurityProposedOrderSecurityId().Length); index = (index + 1)) { ServerDataModel.ProposedOrderRow childProposedOrderRow = securityRow.GetProposedOrderRowsByFKSecurityProposedOrderSecurityId()[index]; ProposedOrder.Archive(adoTransaction, sqlTransaction, childProposedOrderRow.RowVersion, childProposedOrderRow.ProposedOrderId); } for (int index = 0; (index < securityRow.GetProposedOrderRowsByFKSecurityProposedOrderSettlementId().Length); index = (index + 1)) { ServerDataModel.ProposedOrderRow childProposedOrderRow = securityRow.GetProposedOrderRowsByFKSecurityProposedOrderSettlementId()[index]; ProposedOrder.Archive(adoTransaction, sqlTransaction, childProposedOrderRow.RowVersion, childProposedOrderRow.ProposedOrderId); } for (int index = 0; (index < securityRow.GetTaxLotRows().Length); index = (index + 1)) { ServerDataModel.TaxLotRow childTaxLotRow = securityRow.GetTaxLotRows()[index]; TaxLot.Archive(adoTransaction, sqlTransaction, childTaxLotRow.RowVersion, childTaxLotRow.TaxLotId); } for (int index = 0; (index < securityRow.GetViolationRows().Length); index = (index + 1)) { ServerDataModel.ViolationRow childViolationRow = securityRow.GetViolationRows()[index]; Violation.Archive(adoTransaction, sqlTransaction, childViolationRow.RowVersion, childViolationRow.ViolationId); } // Increment the row version rowVersion = ServerDataModel.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.Add(new TableWriterRequest(ServerDataModel.Exchange)); Equity.ArchiveChildren(adoTransaction); }