/// <summary>Inserts a BlockOrder record using Metadata Parameters.</summary> /// <param name="parameters">Contains the metadata parameters.</param> public static void Insert(ParameterList parameters) { // Extract the parameters from the command batch. AdoTransaction adoTransaction = parameters["adoTransaction"]; SqlTransaction sqlTransaction = parameters["sqlTransaction"]; int blotterId = parameters["blotterId"]; object accountId = parameters["accountId"].Value; int securityId = parameters["securityId"]; int settlementId = parameters["settlementId"]; object brokerId = parameters["brokerId"].Value; int statusCode = parameters["statusCode"]; int transactionTypeCode = parameters["transactionTypeCode"]; object timeInForceCode = parameters["timeInForceCode"].Value; object orderTypeCode = parameters["orderTypeCode"].Value; object conditionCode = parameters["conditionCode"].Value; object isDeleted = parameters["isDeleted"].Value; object isAgency = parameters["isAgency"].Value; object quantityExecuted = parameters["quantityExecuted"].Value; object quantityOrdered = parameters["quantityOrdered"].Value; object price1 = parameters["price1"].Value; object price2 = parameters["price2"].Value; System.DateTime createdTime = parameters["createdTime"]; int createdUserId = parameters["createdUserId"]; System.DateTime modifiedTime = parameters["modifiedTime"]; int modifiedUserId = parameters["modifiedUserId"]; // The rowVersion is passed back to the caller in the event it's needed for additional commands in the batch. long rowVersion = long.MinValue; // Call the internal method to complete the operation. int blockOrderId = BlockOrder.Insert(adoTransaction, sqlTransaction, ref rowVersion, blotterId, accountId, securityId, settlementId, brokerId, statusCode, transactionTypeCode, timeInForceCode, orderTypeCode, conditionCode, isDeleted, isAgency, quantityExecuted, quantityOrdered, price1, price2, createdTime, createdUserId, modifiedTime, modifiedUserId); // Return values. parameters["rowVersion"] = rowVersion; parameters.Return = blockOrderId; }
/// <summary>Archives a Status 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="statusCode">The value for the StatusCode 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 statusCode) { // Accessor for the Status Table. ServerDataModel.StatusDataTable statusTable = ServerDataModel.Status; // Rule #1: Make sure the record exists before updating it. ServerDataModel.StatusRow statusRow = statusTable.FindByStatusCode(statusCode); if ((statusRow == null)) { throw new Exception(string.Format("The Status table does not have an element identified by {0}", statusCode)); } // Rule #2: Optimistic Concurrency Check if ((statusRow.RowVersion != rowVersion)) { throw new System.Exception("This record is busy. Please try again later."); } // Archive the child records. for (int index = 0; (index < statusRow.GetBlockOrderRows().Length); index = (index + 1)) { ServerDataModel.BlockOrderRow childBlockOrderRow = statusRow.GetBlockOrderRows()[index]; BlockOrder.Archive(adoTransaction, sqlTransaction, childBlockOrderRow.RowVersion, childBlockOrderRow.BlockOrderId); } // Increment the row version rowVersion = ServerDataModel.RowVersion.Increment(); // Delete the record in the ADO database. statusRow[statusTable.RowVersionColumn] = rowVersion; adoTransaction.DataRows.Add(statusRow); statusRow.Delete(); // Archive the record in the SQL database. SqlCommand sqlCommand = new SqlCommand("update \"Status\" set \"IsArchived\" = 1 where \"StatusCode\"=@statusCode"); sqlCommand.Connection = sqlTransaction.Connection; sqlCommand.Transaction = sqlTransaction; sqlCommand.Parameters.Add(new SqlParameter("@statusCode", SqlDbType.Int, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, statusCode)); sqlCommand.ExecuteNonQuery(); }
/// <summary>Inserts a BlockOrder record using Metadata Parameters.</summary> /// <param name="parameters">Contains the metadata parameters.</param> public static void Update(ParameterList parameters) { // Extract the parameters from the command batch. AdoTransaction adoTransaction = parameters["adoTransaction"]; SqlTransaction sqlTransaction = parameters["sqlTransaction"]; long rowVersion = parameters["rowVersion"]; int blockOrderId = parameters["blockOrderId"]; object blotterId = parameters["blotterId"].Value; object accountId = parameters["accountId"].Value; object securityId = parameters["securityId"].Value; object settlementId = parameters["settlementId"].Value; object brokerId = parameters["brokerId"].Value; object statusCode = parameters["statusCode"].Value; object transactionTypeCode = parameters["transactionTypeCode"].Value; object timeInForceCode = parameters["timeInForceCode"].Value; object orderTypeCode = parameters["orderTypeCode"].Value; object conditionCode = parameters["conditionCode"].Value; object isDeleted = parameters["isDeleted"].Value; object isAgency = parameters["isAgency"].Value; object quantityExecuted = parameters["quantityExecuted"].Value; object quantityOrdered = parameters["quantityOrdered"].Value; object price1 = parameters["price1"].Value; object price2 = parameters["price2"].Value; object createdTime = parameters["createdTime"].Value; object createdUserId = parameters["createdUserId"].Value; object modifiedTime = parameters["modifiedTime"].Value; object modifiedUserId = parameters["modifiedUserId"].Value; // Call the internal method to complete the operation. BlockOrder.Update(adoTransaction, sqlTransaction, ref rowVersion, blockOrderId, blotterId, accountId, securityId, settlementId, brokerId, statusCode, transactionTypeCode, timeInForceCode, orderTypeCode, conditionCode, isDeleted, isAgency, quantityExecuted, quantityOrdered, price1, price2, createdTime, createdUserId, modifiedTime, modifiedUserId); // Return values. parameters["rowVersion"] = rowVersion; }
/// <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.Add(new TableWriterRequest(ServerDataModel.Blotter)); Account.ArchiveChildren(adoTransaction); BlotterMap.Archive(adoTransaction); BlockOrder.Archive(adoTransaction); }
/// <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.TransactionType)); Allocation.Archive(adoTransaction); BlockOrder.Archive(adoTransaction); ProposedOrder.Archive(adoTransaction); }
/// <summary>Inserts a BlockOrder record using Metadata Parameters.</summary> /// <param name="parameters">Contains the metadata parameters.</param> public static void Archive(ParameterList parameters) { // Extract the parameters from the command batch. AdoTransaction adoTransaction = parameters["adoTransaction"]; SqlTransaction sqlTransaction = parameters["sqlTransaction"]; long rowVersion = parameters["rowVersion"]; int blockOrderId = parameters["blockOrderId"]; // Call the internal method to complete the operation. BlockOrder.Archive(adoTransaction, sqlTransaction, rowVersion, blockOrderId); }
/// <summary>Deletes a TransactionType 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="transactionTypeCode">The value for the TransactionTypeCode 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 transactionTypeCode) { // Accessor for the TransactionType Table. ServerDataModel.TransactionTypeDataTable transactionTypeTable = ServerDataModel.TransactionType; // Rule #1: Make sure the record exists before updating it. ServerDataModel.TransactionTypeRow transactionTypeRow = transactionTypeTable.FindByTransactionTypeCode(transactionTypeCode); if ((transactionTypeRow == null)) { throw new Exception(string.Format("The TransactionType table does not have an element identified by {0}", transactionTypeCode)); } // Rule #2: Optimistic Concurrency Check if ((transactionTypeRow.RowVersion != rowVersion)) { throw new System.Exception("This record is busy. Please try again later."); } // Delete the child records. for (int index = 0; (index < transactionTypeRow.GetAllocationRows().Length); index = (index + 1)) { ServerDataModel.AllocationRow childAllocationRow = transactionTypeRow.GetAllocationRows()[index]; Allocation.Delete(adoTransaction, sqlTransaction, childAllocationRow.RowVersion, childAllocationRow.AllocationId); } for (int index = 0; (index < transactionTypeRow.GetBlockOrderRows().Length); index = (index + 1)) { ServerDataModel.BlockOrderRow childBlockOrderRow = transactionTypeRow.GetBlockOrderRows()[index]; BlockOrder.Delete(adoTransaction, sqlTransaction, childBlockOrderRow.RowVersion, childBlockOrderRow.BlockOrderId); } for (int index = 0; (index < transactionTypeRow.GetOrderRows().Length); index = (index + 1)) { ServerDataModel.OrderRow childOrderRow = transactionTypeRow.GetOrderRows()[index]; Order.Delete(adoTransaction, sqlTransaction, childOrderRow.RowVersion, childOrderRow.OrderId); } for (int index = 0; (index < transactionTypeRow.GetProposedOrderRows().Length); index = (index + 1)) { ServerDataModel.ProposedOrderRow childProposedOrderRow = transactionTypeRow.GetProposedOrderRows()[index]; ProposedOrder.Delete(adoTransaction, sqlTransaction, childProposedOrderRow.RowVersion, childProposedOrderRow.ProposedOrderId); } // Increment the row version rowVersion = ServerDataModel.RowVersion.Increment(); // Delete the record in the ADO database. transactionTypeRow[transactionTypeTable.RowVersionColumn] = rowVersion; adoTransaction.DataRows.Add(transactionTypeRow); transactionTypeRow.Delete(); // Delete the record in the SQL database. SqlCommand sqlCommand = new SqlCommand("update \"TransactionType\" set \"IsDeleted\" = 1 where \"TransactionTypeCode\"=@transac" + "tionTypeCode"); sqlCommand.Connection = sqlTransaction.Connection; sqlCommand.Transaction = sqlTransaction; sqlCommand.Parameters.Add(new SqlParameter("@transactionTypeCode", SqlDbType.Int, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, transactionTypeCode)); 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.Add(new TableWriterRequest(ServerDataModel.Security)); Account.ArchiveChildren(adoTransaction); Allocation.Archive(adoTransaction); BlockOrder.Archive(adoTransaction); BlotterMap.Archive(adoTransaction); Debt.ArchiveChildren(adoTransaction); Currency.ArchiveChildren(adoTransaction); Equity.ArchiveChildren(adoTransaction); Position.Archive(adoTransaction); PositionTarget.Archive(adoTransaction); Price.Archive(adoTransaction); ProposedOrder.Archive(adoTransaction); TaxLot.Archive(adoTransaction); Violation.Archive(adoTransaction); }
/// <summary>ArchiveChildrens a Blotter 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="blotterId">The value for the BlotterId 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 blotterId) { // Accessor for the Blotter Table. ServerDataModel.BlotterDataTable blotterTable = ServerDataModel.Blotter; // This record can be used to iterate through all the children. ServerDataModel.BlotterRow blotterRow = blotterTable.FindByBlotterId(blotterId); // Archive the child records. for (int index = 0; (index < blotterRow.GetAccountRows().Length); index = (index + 1)) { ServerDataModel.AccountRow childAccountRow = blotterRow.GetAccountRows()[index]; Account.ArchiveChildren(adoTransaction, sqlTransaction, childAccountRow.RowVersion, childAccountRow.AccountId); } for (int index = 0; (index < blotterRow.GetBlotterMapRows().Length); index = (index + 1)) { ServerDataModel.BlotterMapRow childBlotterMapRow = blotterRow.GetBlotterMapRows()[index]; BlotterMap.Archive(adoTransaction, sqlTransaction, childBlotterMapRow.RowVersion, childBlotterMapRow.BlotterMapId); } for (int index = 0; (index < blotterRow.GetBlockOrderRows().Length); index = (index + 1)) { ServerDataModel.BlockOrderRow childBlockOrderRow = blotterRow.GetBlockOrderRows()[index]; BlockOrder.Archive(adoTransaction, sqlTransaction, childBlockOrderRow.RowVersion, childBlockOrderRow.BlockOrderId); } // Increment the row version rowVersion = ServerDataModel.RowVersion.Increment(); // Delete the record in the ADO database. blotterRow[blotterTable.RowVersionColumn] = rowVersion; adoTransaction.DataRows.Add(blotterRow); blotterRow.Delete(); // Archive the record in the SQL database. SqlCommand sqlCommand = new SqlCommand("update \"Blotter\" set \"IsArchived\" = 1 where \"BlotterId\"=@blotterId"); sqlCommand.Connection = sqlTransaction.Connection; sqlCommand.Transaction = sqlTransaction; sqlCommand.Parameters.Add(new SqlParameter("@blotterId", SqlDbType.Int, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, blotterId)); sqlCommand.ExecuteNonQuery(); }
/// <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 Delete(AdoTransaction adoTransaction) { // These table lock(s) are required for the 'Delete' operation. adoTransaction.LockRequests.Add(new TableWriterRequest(ServerDataModel.Status)); BlockOrder.Archive(adoTransaction); }