/// <summary>Archives a Execution 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="executionId">The value for the ExecutionId 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 executionId) { // Accessor for the Execution Table. ServerMarketData.ExecutionDataTable executionTable = ServerMarketData.Execution; // Rule #1: Make sure the record exists before updating it. ServerMarketData.ExecutionRow executionRow = executionTable.FindByExecutionId(executionId); if ((executionRow == null)) { throw new Exception(string.Format("The Execution table does not have an element identified by {0}", executionId)); } // Rule #2: Optimistic Concurrency Check if ((executionRow.RowVersion != rowVersion)) { throw new System.Exception("This record is busy. Please try again later."); } // Archive the child records. for (int index = 0; (index < executionRow.GetNegotiationRows().Length); index = (index + 1)) { ServerMarketData.NegotiationRow childNegotiationRow = executionRow.GetNegotiationRows()[index]; Negotiation.Archive(adoTransaction, sqlTransaction, childNegotiationRow.RowVersion, childNegotiationRow.NegotiationId); } // Increment the row version rowVersion = ServerMarketData.RowVersion.Increment(); // Delete the record in the ADO database. executionRow[executionTable.RowVersionColumn] = rowVersion; adoTransaction.DataRows.Add(executionRow); executionRow.Delete(); // Archive the record in the SQL database. SqlCommand sqlCommand = new SqlCommand("update \"Execution\" set \"IsArchived\" = 1 where \"ExecutionId\"=@executionId"); sqlCommand.Connection = sqlTransaction.Connection; sqlCommand.Transaction = sqlTransaction; sqlCommand.Parameters.Add(new SqlParameter("@executionId", SqlDbType.Int, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, executionId)); 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.StatusLock); DestinationOrder.Archive(adoTransaction); Match.Archive(adoTransaction); Negotiation.Archive(adoTransaction); SourceOrder.Archive(adoTransaction); WorkingOrder.Archive(adoTransaction); }
/// <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. ServerMarketData.StatusDataTable statusTable = ServerMarketData.Status; // Rule #1: Make sure the record exists before updating it. ServerMarketData.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.GetDestinationOrderRows().Length); index = (index + 1)) { ServerMarketData.DestinationOrderRow childDestinationOrderRow = statusRow.GetDestinationOrderRows()[index]; DestinationOrder.Archive(adoTransaction, sqlTransaction, childDestinationOrderRow.RowVersion, childDestinationOrderRow.DestinationOrderId); } for (int index = 0; (index < statusRow.GetMatchRows().Length); index = (index + 1)) { ServerMarketData.MatchRow childMatchRow = statusRow.GetMatchRows()[index]; Match.Archive(adoTransaction, sqlTransaction, childMatchRow.RowVersion, childMatchRow.MatchId); } for (int index = 0; (index < statusRow.GetNegotiationRows().Length); index = (index + 1)) { ServerMarketData.NegotiationRow childNegotiationRow = statusRow.GetNegotiationRows()[index]; Negotiation.Archive(adoTransaction, sqlTransaction, childNegotiationRow.RowVersion, childNegotiationRow.NegotiationId); } for (int index = 0; (index < statusRow.GetSourceOrderRows().Length); index = (index + 1)) { ServerMarketData.SourceOrderRow childSourceOrderRow = statusRow.GetSourceOrderRows()[index]; SourceOrder.Archive(adoTransaction, sqlTransaction, childSourceOrderRow.RowVersion, childSourceOrderRow.SourceOrderId); } for (int index = 0; (index < statusRow.GetWorkingOrderRows().Length); index = (index + 1)) { ServerMarketData.WorkingOrderRow childWorkingOrderRow = statusRow.GetWorkingOrderRows()[index]; WorkingOrder.Archive(adoTransaction, sqlTransaction, childWorkingOrderRow.RowVersion, childWorkingOrderRow.WorkingOrderId); } // Increment the row version rowVersion = ServerMarketData.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 Negotiation 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 negotiationId = parameters["negotiationId"]; // Call the internal method to complete the operation. Negotiation.Archive(adoTransaction, sqlTransaction, rowVersion, negotiationId); }
/// <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.ExecutionLock); Negotiation.Archive(adoTransaction); }