/// <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 DeleteChildren(AdoTransaction adoTransaction) { // These table lock(s) are required for the 'Delete' operation. adoTransaction.LockRequests.Add(new TableWriterRequest(ServerDataModel.Model)); Account.DeleteChildren(adoTransaction); PositionTarget.Delete(adoTransaction); SectorTarget.Delete(adoTransaction); }
/// <summary>Inserts a PositionTarget record using Metadata Parameters.</summary> /// <param name="parameters">Contains the metadata parameters.</param> public static void Delete(ParameterList parameters) { // Extract the parameters from the command batch. AdoTransaction adoTransaction = parameters["adoTransaction"]; SqlTransaction sqlTransaction = parameters["sqlTransaction"]; long rowVersion = parameters["rowVersion"]; int modelId = parameters["modelId"]; int securityId = parameters["securityId"]; int positionTypeCode = parameters["positionTypeCode"]; // Call the internal method to complete the operation. PositionTarget.Delete(adoTransaction, sqlTransaction, rowVersion, modelId, securityId, positionTypeCode); }
/// <summary>Deletes a PositionType 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="positionTypeCode">The value for the PositionTypeCode column.</param> /// <param name="archive">true to archive the object, false to unarchive it.</param> public static void Delete(AdoTransaction adoTransaction, SqlTransaction sqlTransaction, long rowVersion, int positionTypeCode) { // Accessor for the PositionType Table. ServerDataModel.PositionTypeDataTable positionTypeTable = ServerDataModel.PositionType; // Rule #1: Make sure the record exists before updating it. ServerDataModel.PositionTypeRow positionTypeRow = positionTypeTable.FindByPositionTypeCode(positionTypeCode); if ((positionTypeRow == null)) { throw new Exception(string.Format("The PositionType table does not have an element identified by {0}", positionTypeCode)); } // Rule #2: Optimistic Concurrency Check if ((positionTypeRow.RowVersion != rowVersion)) { throw new System.Exception("This record is busy. Please try again later."); } // Delete the child records. for (int index = 0; (index < positionTypeRow.GetPositionRows().Length); index = (index + 1)) { ServerDataModel.PositionRow childPositionRow = positionTypeRow.GetPositionRows()[index]; Position.Delete(adoTransaction, sqlTransaction, childPositionRow.RowVersion, childPositionRow.AccountId, childPositionRow.SecurityId, childPositionRow.PositionTypeCode); } for (int index = 0; (index < positionTypeRow.GetPositionTargetRows().Length); index = (index + 1)) { ServerDataModel.PositionTargetRow childPositionTargetRow = positionTypeRow.GetPositionTargetRows()[index]; PositionTarget.Delete(adoTransaction, sqlTransaction, childPositionTargetRow.RowVersion, childPositionTargetRow.ModelId, childPositionTargetRow.SecurityId, childPositionTargetRow.PositionTypeCode); } for (int index = 0; (index < positionTypeRow.GetTaxLotRows().Length); index = (index + 1)) { ServerDataModel.TaxLotRow childTaxLotRow = positionTypeRow.GetTaxLotRows()[index]; TaxLot.Delete(adoTransaction, sqlTransaction, childTaxLotRow.RowVersion, childTaxLotRow.TaxLotId); } for (int index = 0; (index < positionTypeRow.GetViolationRows().Length); index = (index + 1)) { ServerDataModel.ViolationRow childViolationRow = positionTypeRow.GetViolationRows()[index]; Violation.Delete(adoTransaction, sqlTransaction, childViolationRow.RowVersion, childViolationRow.ViolationId); } // Increment the row version rowVersion = ServerDataModel.RowVersion.Increment(); // Delete the record in the ADO database. positionTypeRow[positionTypeTable.RowVersionColumn] = rowVersion; adoTransaction.DataRows.Add(positionTypeRow); positionTypeRow.Delete(); // Delete the record in the SQL database. SqlCommand sqlCommand = new SqlCommand("update \"PositionType\" set \"IsDeleted\" = 1 where \"PositionTypeCode\"=@positionTypeC" + "ode"); sqlCommand.Connection = sqlTransaction.Connection; sqlCommand.Transaction = sqlTransaction; sqlCommand.Parameters.Add(new SqlParameter("@positionTypeCode", SqlDbType.Int, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, positionTypeCode)); 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 DeleteChildren(AdoTransaction adoTransaction) { // These table lock(s) are required for the 'Delete' operation. adoTransaction.LockRequests.Add(new TableWriterRequest(ServerDataModel.Security)); Account.DeleteChildren(adoTransaction); Allocation.Delete(adoTransaction); BlockOrder.Delete(adoTransaction); BlotterMap.Delete(adoTransaction); Debt.DeleteChildren(adoTransaction); Currency.DeleteChildren(adoTransaction); Equity.DeleteChildren(adoTransaction); Position.Delete(adoTransaction); PositionTarget.Delete(adoTransaction); Price.Delete(adoTransaction); ProposedOrder.Delete(adoTransaction); TaxLot.Delete(adoTransaction); Violation.Delete(adoTransaction); }
/// <summary>DeleteChildrens a Model 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="modelId">The value for the ModelId column.</param> /// <param name="archive">true to archive the object, false to unarchive it.</param> internal static void DeleteChildren(AdoTransaction adoTransaction, SqlTransaction sqlTransaction, long rowVersion, int modelId) { // Accessor for the Model Table. ServerDataModel.ModelDataTable modelTable = ServerDataModel.Model; // This record can be used to iterate through all the children. ServerDataModel.ModelRow modelRow = modelTable.FindByModelId(modelId); // Delete the child records. for (int index = 0; (index < modelRow.GetAccountRows().Length); index = (index + 1)) { ServerDataModel.AccountRow childAccountRow = modelRow.GetAccountRows()[index]; Account.DeleteChildren(adoTransaction, sqlTransaction, childAccountRow.RowVersion, childAccountRow.AccountId); } for (int index = 0; (index < modelRow.GetPositionTargetRows().Length); index = (index + 1)) { ServerDataModel.PositionTargetRow childPositionTargetRow = modelRow.GetPositionTargetRows()[index]; PositionTarget.Delete(adoTransaction, sqlTransaction, childPositionTargetRow.RowVersion, childPositionTargetRow.ModelId, childPositionTargetRow.SecurityId, childPositionTargetRow.PositionTypeCode); } for (int index = 0; (index < modelRow.GetSectorTargetRows().Length); index = (index + 1)) { ServerDataModel.SectorTargetRow childSectorTargetRow = modelRow.GetSectorTargetRows()[index]; SectorTarget.Delete(adoTransaction, sqlTransaction, childSectorTargetRow.RowVersion, childSectorTargetRow.ModelId, childSectorTargetRow.SectorId); } // Increment the row version rowVersion = ServerDataModel.RowVersion.Increment(); // Delete the record in the ADO database. modelRow[modelTable.RowVersionColumn] = rowVersion; adoTransaction.DataRows.Add(modelRow); modelRow.Delete(); // Delete the record in the SQL database. SqlCommand sqlCommand = new SqlCommand("update \"Model\" set \"IsDeleted\" = 1 where \"ModelId\"=@modelId"); sqlCommand.Connection = sqlTransaction.Connection; sqlCommand.Transaction = sqlTransaction; sqlCommand.Parameters.Add(new SqlParameter("@modelId", SqlDbType.Int, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, modelId)); sqlCommand.ExecuteNonQuery(); }
/// <summary>DeleteChildrens 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 DeleteChildren(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); // Delete the child records. for (int index = 0; (index < securityRow.GetAccountRows().Length); index = (index + 1)) { ServerDataModel.AccountRow childAccountRow = securityRow.GetAccountRows()[index]; Account.DeleteChildren(adoTransaction, sqlTransaction, childAccountRow.RowVersion, childAccountRow.AccountId); } for (int index = 0; (index < securityRow.GetAllocationRowsByFKSecurityAllocationSecurityId().Length); index = (index + 1)) { ServerDataModel.AllocationRow childAllocationRow = securityRow.GetAllocationRowsByFKSecurityAllocationSecurityId()[index]; Allocation.Delete(adoTransaction, sqlTransaction, childAllocationRow.RowVersion, childAllocationRow.AllocationId); } for (int index = 0; (index < securityRow.GetAllocationRowsByFKSecurityAllocationSettlementId().Length); index = (index + 1)) { ServerDataModel.AllocationRow childAllocationRow = securityRow.GetAllocationRowsByFKSecurityAllocationSettlementId()[index]; Allocation.Delete(adoTransaction, sqlTransaction, childAllocationRow.RowVersion, childAllocationRow.AllocationId); } for (int index = 0; (index < securityRow.GetBlockOrderRowsByFKSecurityBlockOrderSecurityId().Length); index = (index + 1)) { ServerDataModel.BlockOrderRow childBlockOrderRow = securityRow.GetBlockOrderRowsByFKSecurityBlockOrderSecurityId()[index]; BlockOrder.Delete(adoTransaction, sqlTransaction, childBlockOrderRow.RowVersion, childBlockOrderRow.BlockOrderId); } for (int index = 0; (index < securityRow.GetBlockOrderRowsByFKSecurityBlockOrderSettlementId().Length); index = (index + 1)) { ServerDataModel.BlockOrderRow childBlockOrderRow = securityRow.GetBlockOrderRowsByFKSecurityBlockOrderSettlementId()[index]; BlockOrder.Delete(adoTransaction, sqlTransaction, childBlockOrderRow.RowVersion, childBlockOrderRow.BlockOrderId); } for (int index = 0; (index < securityRow.GetBlotterMapRows().Length); index = (index + 1)) { ServerDataModel.BlotterMapRow childBlotterMapRow = securityRow.GetBlotterMapRows()[index]; BlotterMap.Delete(adoTransaction, sqlTransaction, childBlotterMapRow.RowVersion, childBlotterMapRow.BlotterMapId); } for (int index = 0; (index < securityRow.GetDebtRowsByFKSecurityDebtDebtId().Length); index = (index + 1)) { ServerDataModel.DebtRow childDebtRow = securityRow.GetDebtRowsByFKSecurityDebtDebtId()[index]; Debt.DeleteChildren(adoTransaction, sqlTransaction, childDebtRow.RowVersion, childDebtRow.DebtId); } for (int index = 0; (index < securityRow.GetDebtRowsByFKSecurityDebtSettlementId().Length); index = (index + 1)) { ServerDataModel.DebtRow childDebtRow = securityRow.GetDebtRowsByFKSecurityDebtSettlementId()[index]; Debt.DeleteChildren(adoTransaction, sqlTransaction, childDebtRow.RowVersion, childDebtRow.DebtId); } for (int index = 0; (index < securityRow.GetCurrencyRows().Length); index = (index + 1)) { ServerDataModel.CurrencyRow childCurrencyRow = securityRow.GetCurrencyRows()[index]; Currency.DeleteChildren(adoTransaction, sqlTransaction, childCurrencyRow.RowVersion, childCurrencyRow.CurrencyId); } for (int index = 0; (index < securityRow.GetEquityRowsByFKSecurityEquityEquityId().Length); index = (index + 1)) { ServerDataModel.EquityRow childEquityRow = securityRow.GetEquityRowsByFKSecurityEquityEquityId()[index]; Equity.DeleteChildren(adoTransaction, sqlTransaction, childEquityRow.RowVersion, childEquityRow.EquityId); } for (int index = 0; (index < securityRow.GetEquityRowsByFKSecurityEquitySettlementId().Length); index = (index + 1)) { ServerDataModel.EquityRow childEquityRow = securityRow.GetEquityRowsByFKSecurityEquitySettlementId()[index]; Equity.DeleteChildren(adoTransaction, sqlTransaction, childEquityRow.RowVersion, childEquityRow.EquityId); } for (int index = 0; (index < securityRow.GetOrderRowsByFKSecurityOrderSecurityId().Length); index = (index + 1)) { ServerDataModel.OrderRow childOrderRow = securityRow.GetOrderRowsByFKSecurityOrderSecurityId()[index]; Order.Delete(adoTransaction, sqlTransaction, childOrderRow.RowVersion, childOrderRow.OrderId); } for (int index = 0; (index < securityRow.GetOrderRowsByFKSecurityOrderSettlementId().Length); index = (index + 1)) { ServerDataModel.OrderRow childOrderRow = securityRow.GetOrderRowsByFKSecurityOrderSettlementId()[index]; Order.Delete(adoTransaction, sqlTransaction, childOrderRow.RowVersion, childOrderRow.OrderId); } for (int index = 0; (index < securityRow.GetPositionRows().Length); index = (index + 1)) { ServerDataModel.PositionRow childPositionRow = securityRow.GetPositionRows()[index]; Position.Delete(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.Delete(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.Delete(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.Delete(adoTransaction, sqlTransaction, childProposedOrderRow.RowVersion, childProposedOrderRow.ProposedOrderId); } for (int index = 0; (index < securityRow.GetProposedOrderRowsByFKSecurityProposedOrderSettlementId().Length); index = (index + 1)) { ServerDataModel.ProposedOrderRow childProposedOrderRow = securityRow.GetProposedOrderRowsByFKSecurityProposedOrderSettlementId()[index]; ProposedOrder.Delete(adoTransaction, sqlTransaction, childProposedOrderRow.RowVersion, childProposedOrderRow.ProposedOrderId); } for (int index = 0; (index < securityRow.GetTaxLotRows().Length); index = (index + 1)) { ServerDataModel.TaxLotRow childTaxLotRow = securityRow.GetTaxLotRows()[index]; TaxLot.Delete(adoTransaction, sqlTransaction, childTaxLotRow.RowVersion, childTaxLotRow.TaxLotId); } for (int index = 0; (index < securityRow.GetViolationRows().Length); index = (index + 1)) { ServerDataModel.ViolationRow childViolationRow = securityRow.GetViolationRows()[index]; Violation.Delete(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(); // Delete the record in the SQL database. SqlCommand sqlCommand = new SqlCommand("update \"Security\" set \"IsDeleted\" = 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(); }