/// <summary>Inserts a TaxLot 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 accountId = parameters["accountId"]; decimal cost = parameters["cost"]; object externalId0 = parameters["externalId0"].Value; object externalId1 = parameters["externalId1"].Value; object externalId2 = parameters["externalId2"].Value; object externalId3 = parameters["externalId3"].Value; object localCost = parameters["localCost"].Value; int positionTypeCode = parameters["positionTypeCode"]; decimal quantity = parameters["quantity"]; int securityId = parameters["securityId"]; object settlementDate = parameters["settlementDate"].Value; object tradeDate = parameters["tradeDate"].Value; object userData0 = parameters["userData0"].Value; object userData1 = parameters["userData1"].Value; object userData2 = parameters["userData2"].Value; object userData3 = parameters["userData3"].Value; object userData4 = parameters["userData4"].Value; object userData5 = parameters["userData5"].Value; object userData6 = parameters["userData6"].Value; object userData7 = parameters["userData7"].Value; // 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 taxLotId = TaxLot.Insert(adoTransaction, sqlTransaction, ref rowVersion, accountId, cost, externalId0, externalId1, externalId2, externalId3, localCost, positionTypeCode, quantity, securityId, settlementDate, tradeDate, userData0, userData1, userData2, userData3, userData4, userData5, userData6, userData7); // Return values. parameters["rowVersion"] = rowVersion; parameters.Return = taxLotId; }
/// <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.PositionTypeLock); Position.Archive(adoTransaction); TaxLot.Archive(adoTransaction); }
/// <summary>Inserts a TaxLot 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"]; object accountId = parameters["accountId"].Value; object cost = parameters["cost"].Value; object externalId0 = parameters["externalId0"].Value; object externalId1 = parameters["externalId1"].Value; object externalId2 = parameters["externalId2"].Value; object externalId3 = parameters["externalId3"].Value; object localCost = parameters["localCost"].Value; object positionTypeCode = parameters["positionTypeCode"].Value; object quantity = parameters["quantity"].Value; object securityId = parameters["securityId"].Value; object settlementDate = parameters["settlementDate"].Value; int taxLotId = parameters["taxLotId"]; object tradeDate = parameters["tradeDate"].Value; object userData0 = parameters["userData0"].Value; object userData1 = parameters["userData1"].Value; object userData2 = parameters["userData2"].Value; object userData3 = parameters["userData3"].Value; object userData4 = parameters["userData4"].Value; object userData5 = parameters["userData5"].Value; object userData6 = parameters["userData6"].Value; object userData7 = parameters["userData7"].Value; // Call the internal method to complete the operation. TaxLot.Update(adoTransaction, sqlTransaction, ref rowVersion, accountId, cost, externalId0, externalId1, externalId2, externalId3, localCost, positionTypeCode, quantity, securityId, settlementDate, taxLotId, tradeDate, userData0, userData1, userData2, userData3, userData4, userData5, userData6, userData7); // 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 new static void ArchiveChildren(AdoTransaction adoTransaction) { // These table lock(s) are required for the 'Archive' operation. adoTransaction.LockRequests.AddWriterLock(ServerMarketData.AccountLock); Allocation.Archive(adoTransaction); Position.Archive(adoTransaction); TaxLot.Archive(adoTransaction); }
/// <summary>Inserts a TaxLot 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 taxLotId = parameters["taxLotId"]; // Call the internal method to complete the operation. TaxLot.Archive(adoTransaction, sqlTransaction, rowVersion, taxLotId); }
/// <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>Archives 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 Archive(AdoTransaction adoTransaction, SqlTransaction sqlTransaction, long rowVersion, int positionTypeCode) { // Accessor for the PositionType Table. ServerMarketData.PositionTypeDataTable positionTypeTable = ServerMarketData.PositionType; // Rule #1: Make sure the record exists before updating it. ServerMarketData.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."); } // Archive the child records. for (int index = 0; (index < positionTypeRow.GetPositionRows().Length); index = (index + 1)) { ServerMarketData.PositionRow childPositionRow = positionTypeRow.GetPositionRows()[index]; Position.Archive(adoTransaction, sqlTransaction, childPositionRow.RowVersion, childPositionRow.AccountId, childPositionRow.SecurityId, childPositionRow.PositionTypeCode); } for (int index = 0; (index < positionTypeRow.GetTaxLotRows().Length); index = (index + 1)) { ServerMarketData.TaxLotRow childTaxLotRow = positionTypeRow.GetTaxLotRows()[index]; TaxLot.Archive(adoTransaction, sqlTransaction, childTaxLotRow.RowVersion, childTaxLotRow.TaxLotId); } // Increment the row version rowVersion = ServerMarketData.RowVersion.Increment(); // Delete the record in the ADO database. positionTypeRow[positionTypeTable.RowVersionColumn] = rowVersion; adoTransaction.DataRows.Add(positionTypeRow); positionTypeRow.Delete(); // Archive the record in the SQL database. SqlCommand sqlCommand = new SqlCommand("update \"PositionType\" set \"IsArchived\" = 1 where \"PositionTypeCode\"=@positionType" + "Code"); 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>ArchiveChildrens a Account 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="accountId">The value for the AccountId column.</param> /// <param name="archive">true to archive the object, false to unarchive it.</param> internal new static void ArchiveChildren(AdoTransaction adoTransaction, SqlTransaction sqlTransaction, long rowVersion, int accountId) { // Accessor for the Account Table. ServerMarketData.AccountDataTable accountTable = ServerMarketData.Account; // This record can be used to iterate through all the children. ServerMarketData.AccountRow accountRow = accountTable.FindByAccountId(accountId); // Archive the child records. for (int index = 0; (index < accountRow.GetAllocationRows().Length); index = (index + 1)) { ServerMarketData.AllocationRow childAllocationRow = accountRow.GetAllocationRows()[index]; Allocation.Archive(adoTransaction, sqlTransaction, childAllocationRow.RowVersion, childAllocationRow.AllocationId); } for (int index = 0; (index < accountRow.GetPositionRows().Length); index = (index + 1)) { ServerMarketData.PositionRow childPositionRow = accountRow.GetPositionRows()[index]; Position.Archive(adoTransaction, sqlTransaction, childPositionRow.RowVersion, childPositionRow.AccountId, childPositionRow.SecurityId, childPositionRow.PositionTypeCode); } for (int index = 0; (index < accountRow.GetTaxLotRows().Length); index = (index + 1)) { ServerMarketData.TaxLotRow childTaxLotRow = accountRow.GetTaxLotRows()[index]; TaxLot.Archive(adoTransaction, sqlTransaction, childTaxLotRow.RowVersion, childTaxLotRow.TaxLotId); } // Increment the row version rowVersion = ServerMarketData.RowVersion.Increment(); // Delete the record in the ADO database. accountRow[accountTable.RowVersionColumn] = rowVersion; adoTransaction.DataRows.Add(accountRow); accountRow.Delete(); // Archive the record in the SQL database. SqlCommand sqlCommand = new SqlCommand("update \"Account\" set \"IsArchived\" = 1 where \"AccountId\"=@accountId"); sqlCommand.Connection = sqlTransaction.Connection; sqlCommand.Transaction = sqlTransaction; sqlCommand.Parameters.Add(new SqlParameter("@accountId", SqlDbType.Int, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, accountId)); 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. 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(); }