/// <summary>Updates a Order record using Metadata Parameters.</summary> /// <param name="transaction">Contains the parameters and exceptions for this command.</param> public static void Update(ParameterList parameters) { // Accessor for the Order Table. ServerDataModel.OrderDataTable orderTable = ServerDataModel.Order; // Extract the parameters from the command batch. AdoTransaction adoTransaction = parameters["adoTransaction"]; SqlTransaction sqlTransaction = parameters["sqlTransaction"]; object configurationId = parameters["configurationId"].Value; int orderId = ((string)(parameters["orderId"])); object blockOrderId = parameters["blockOrderId"].Value; object externalAccountId = parameters["accountId"].Value; object externalSecurityId = parameters["securityId"].Value; object externalSettlementId = parameters["settlementId"].Value; object brokerId = parameters["brokerId"].Value; object positionTypeCode = parameters["positionTypeCode"].Value; object externalTransactionTypeCode = parameters["transactionTypeCode"].Value; object externalTimeInForceCode = parameters["timeInForceCode"].Value; object externalOrderTypeCode = parameters["orderTypeCode"].Value; object conditionCode = parameters["conditionCode"].Value; object isDeleted = parameters["isDeleted"].Value; object isAgency = parameters["isAgency"].Value; object quantity = parameters["quantity"].Value; object price1 = parameters["price1"].Value; object price2 = parameters["price2"].Value; object note = parameters["note"].Value; object createdTime = parameters["createdTime"].Value; object createdUserId = parameters["createdUserId"].Value; object modifiedTime = parameters["modifiedTime"].Value; object modifiedUserId = parameters["modifiedUserId"].Value; // The row versioning is largely disabled for external operations. long rowVersion = long.MinValue; // Resolve External Identifiers object accountId = Account.FindOptionalKey(configurationId, "accountId", externalAccountId); object securityId = Security.FindOptionalKey(configurationId, "securityId", externalSecurityId); object settlementId = Security.FindOptionalKey(configurationId, "settlementId", externalSettlementId); object transactionTypeCode = TransactionType.FindOptionalKey(configurationId, "transactionTypeCode", externalTransactionTypeCode); object timeInForceCode = TimeInForce.FindOptionalKey(configurationId, "timeInForceCode", externalTimeInForceCode); object orderTypeCode = OrderType.FindOptionalKey(configurationId, "orderTypeCode", externalOrderTypeCode); // While the optimistic concurrency checking is disabled for the external methods, the internal methods // still need to perform the check. This ncurrency checking logic by finding the current row version to be // will bypass the coused when the internal method is called. ServerDataModel.OrderRow orderRow = orderTable.FindByOrderId(orderId); rowVersion = ((long)(orderRow[orderTable.RowVersionColumn])); // Call the internal method to complete the operation. MarkThree.Quasar.Core.Order.Update(adoTransaction, sqlTransaction, ref rowVersion, orderId, blockOrderId, accountId, securityId, settlementId, brokerId, positionTypeCode, transactionTypeCode, timeInForceCode, orderTypeCode, conditionCode, isDeleted, isAgency, quantity, price1, price2, note, createdTime, createdUserId, modifiedTime, modifiedUserId); // Return values. parameters["rowVersion"] = rowVersion; }
/// <summary>Archives a Order 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="orderId">The value for the OrderId 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 orderId) { // Accessor for the Order Table. ServerDataModel.OrderDataTable orderTable = ServerDataModel.Order; // Rule #1: Make sure the record exists before updating it. ServerDataModel.OrderRow orderRow = orderTable.FindByOrderId(orderId); if ((orderRow == null)) { throw new Exception(string.Format("The Order table does not have an element identified by {0}", orderId)); } // Rule #2: Optimistic Concurrency Check if ((orderRow.RowVersion != rowVersion)) { throw new System.Exception("This record is busy. Please try again later."); } // Archive the child records. for (int index = 0; (index < orderRow.GetOrderTreeRowsByFKOrderOrderTreeChildId().Length); index = (index + 1)) { ServerDataModel.OrderTreeRow childOrderTreeRow = orderRow.GetOrderTreeRowsByFKOrderOrderTreeChildId()[index]; OrderTree.Archive(adoTransaction, sqlTransaction, childOrderTreeRow.RowVersion, childOrderTreeRow.ParentId, childOrderTreeRow.ChildId); } for (int index = 0; (index < orderRow.GetOrderTreeRowsByFKOrderOrderTreeParentId().Length); index = (index + 1)) { ServerDataModel.OrderTreeRow childOrderTreeRow = orderRow.GetOrderTreeRowsByFKOrderOrderTreeParentId()[index]; OrderTree.Archive(adoTransaction, sqlTransaction, childOrderTreeRow.RowVersion, childOrderTreeRow.ParentId, childOrderTreeRow.ChildId); } // Increment the row version rowVersion = ServerDataModel.RowVersion.Increment(); // Delete the record in the ADO database. orderRow[orderTable.RowVersionColumn] = rowVersion; adoTransaction.DataRows.Add(orderRow); orderRow.Delete(); // Archive the record in the SQL database. SqlCommand sqlCommand = new SqlCommand("update \"Order\" set \"IsArchived\" = 1 where \"OrderId\"=@orderId"); sqlCommand.Connection = sqlTransaction.Connection; sqlCommand.Transaction = sqlTransaction; sqlCommand.Parameters.Add(new SqlParameter("@orderId", SqlDbType.Int, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, orderId)); sqlCommand.ExecuteNonQuery(); }
/// <summary>Archives a Order record using Metadata Parameters.</summary> /// <param name="transaction">Contains the parameters and exceptions for this command.</param> public static void Archive(ParameterList parameters) { // Accessor for the Order Table. ServerDataModel.OrderDataTable orderTable = ServerDataModel.Order; // Extract the parameters from the command batch. AdoTransaction adoTransaction = parameters["adoTransaction"]; SqlTransaction sqlTransaction = parameters["sqlTransaction"]; object configurationId = parameters["configurationId"].Value; string externalOrderId = parameters["orderId"]; // The row versioning is largely disabled for external operations. long rowVersion = long.MinValue; // Find the internal identifier using the primar key elements. // identifier is used to determine if a record exists with the same key. int orderId = Order.FindRequiredKey(configurationId, "orderId", externalOrderId); // While the optimistic concurrency checking is disabled for the external methods, the internal methods // still need to perform the check. This ncurrency checking logic by finding the current row version to be // will bypass the coused when the internal method is called. ServerDataModel.OrderRow orderRow = orderTable.FindByOrderId(orderId); rowVersion = ((long)(orderRow[orderTable.RowVersionColumn])); // Call the internal method to complete the operation. MarkThree.Quasar.Core.Order.Archive(adoTransaction, sqlTransaction, rowVersion, orderId); }
/// <summary>Updates a Order record.</summary> /// <param name="transaction">Commits or rejects a set of commands as a unit</param> /// <param name="rowVersion">The version number of the row</param> /// <param name="orderId">The value for the OrderId column.</param> /// <param name="blockOrderId">The value for the BlockOrderId column.</param> /// <param name="accountId">The value for the AccountId column.</param> /// <param name="securityId">The value for the SecurityId column.</param> /// <param name="settlementId">The value for the SettlementId column.</param> /// <param name="brokerId">The value for the BrokerId column.</param> /// <param name="positionTypeCode">The value for the PositionTypeCode column.</param> /// <param name="transactionTypeCode">The value for the TransactionTypeCode column.</param> /// <param name="timeInForceCode">The value for the TimeInForceCode column.</param> /// <param name="orderTypeCode">The value for the OrderTypeCode column.</param> /// <param name="conditionCode">The value for the ConditionCode column.</param> /// <param name="isDeleted">The value for the IsDeleted column.</param> /// <param name="isAgency">The value for the IsAgency column.</param> /// <param name="quantity">The value for the Quantity column.</param> /// <param name="price1">The value for the Price1 column.</param> /// <param name="price2">The value for the Price2 column.</param> /// <param name="note">The value for the Note column.</param> /// <param name="createdTime">The value for the CreatedTime column.</param> /// <param name="createdUserId">The value for the CreatedUserId column.</param> /// <param name="modifiedTime">The value for the ModifiedTime column.</param> /// <param name="modifiedUserId">The value for the ModifiedUserId column.</param> public static void Update( AdoTransaction adoTransaction, SqlTransaction sqlTransaction, ref long rowVersion, int orderId, object blockOrderId, object accountId, object securityId, object settlementId, object brokerId, object positionTypeCode, object transactionTypeCode, object timeInForceCode, object orderTypeCode, object conditionCode, object isDeleted, object isAgency, object quantity, object price1, object price2, object note, object createdTime, object createdUserId, object modifiedTime, object modifiedUserId) { // Accessor for the Order Table. ServerDataModel.OrderDataTable orderTable = ServerDataModel.Order; // Rule #1: Make sure the record exists before updating it. ServerDataModel.OrderRow orderRow = orderTable.FindByOrderId(orderId); if ((orderRow == null)) { throw new Exception(string.Format("The Order table does not have an element identified by {0}", orderId)); } // Rule #2: Optimistic Concurrency Check if ((orderRow.RowVersion != rowVersion)) { throw new System.Exception("This record is busy. Please try again later."); } // Apply Defaults if ((blockOrderId == null)) { blockOrderId = orderRow[orderTable.BlockOrderIdColumn]; } if ((accountId == null)) { accountId = orderRow[orderTable.AccountIdColumn]; } if ((securityId == null)) { securityId = orderRow[orderTable.SecurityIdColumn]; } if ((settlementId == null)) { settlementId = orderRow[orderTable.SettlementIdColumn]; } if ((brokerId == null)) { brokerId = orderRow[orderTable.BrokerIdColumn]; } if ((positionTypeCode == null)) { positionTypeCode = orderRow[orderTable.PositionTypeCodeColumn]; } if ((transactionTypeCode == null)) { transactionTypeCode = orderRow[orderTable.TransactionTypeCodeColumn]; } if ((timeInForceCode == null)) { timeInForceCode = orderRow[orderTable.TimeInForceCodeColumn]; } if ((orderTypeCode == null)) { orderTypeCode = orderRow[orderTable.OrderTypeCodeColumn]; } if ((conditionCode == null)) { conditionCode = orderRow[orderTable.ConditionCodeColumn]; } if ((isDeleted == null)) { isDeleted = orderRow[orderTable.IsDeletedColumn]; } if ((isAgency == null)) { isAgency = orderRow[orderTable.IsAgencyColumn]; } if ((quantity == null)) { quantity = orderRow[orderTable.QuantityColumn]; } if ((price1 == null)) { price1 = orderRow[orderTable.Price1Column]; } if ((price2 == null)) { price2 = orderRow[orderTable.Price2Column]; } if ((note == null)) { note = orderRow[orderTable.NoteColumn]; } if ((createdTime == null)) { createdTime = orderRow[orderTable.CreatedTimeColumn]; } if ((createdUserId == null)) { createdUserId = orderRow[orderTable.CreatedUserIdColumn]; } if ((modifiedTime == null)) { modifiedTime = orderRow[orderTable.ModifiedTimeColumn]; } if ((modifiedUserId == null)) { modifiedUserId = orderRow[orderTable.ModifiedUserIdColumn]; } // Increment the row version rowVersion = ServerDataModel.RowVersion.Increment(); // Update the record in the ADO database. orderRow[orderTable.RowVersionColumn] = rowVersion; orderRow[orderTable.BlockOrderIdColumn] = blockOrderId; orderRow[orderTable.AccountIdColumn] = accountId; orderRow[orderTable.SecurityIdColumn] = securityId; orderRow[orderTable.SettlementIdColumn] = settlementId; orderRow[orderTable.BrokerIdColumn] = brokerId; orderRow[orderTable.PositionTypeCodeColumn] = positionTypeCode; orderRow[orderTable.TransactionTypeCodeColumn] = transactionTypeCode; orderRow[orderTable.TimeInForceCodeColumn] = timeInForceCode; orderRow[orderTable.OrderTypeCodeColumn] = orderTypeCode; orderRow[orderTable.ConditionCodeColumn] = conditionCode; orderRow[orderTable.IsDeletedColumn] = isDeleted; orderRow[orderTable.IsAgencyColumn] = isAgency; orderRow[orderTable.QuantityColumn] = quantity; orderRow[orderTable.Price1Column] = price1; orderRow[orderTable.Price2Column] = price2; orderRow[orderTable.NoteColumn] = note; orderRow[orderTable.CreatedTimeColumn] = createdTime; orderRow[orderTable.CreatedUserIdColumn] = createdUserId; orderRow[orderTable.ModifiedTimeColumn] = modifiedTime; orderRow[orderTable.ModifiedUserIdColumn] = modifiedUserId; adoTransaction.DataRows.Add(orderRow); // Update the record in the SQL database. SqlCommand sqlCommand = new SqlCommand(@"update ""Order"" set ""RowVersion""=@rowVersion,""BlockOrderId""=@blockOrderId,""AccountId""=@accountId,""SecurityId""=@securityId,""SettlementId""=@settlementId,""BrokerId""=@brokerId,""PositionTypeCode""=@positionTypeCode,""TransactionTypeCode""=@transactionTypeCode,""TimeInForceCode""=@timeInForceCode,""OrderTypeCode""=@orderTypeCode,""ConditionCode""=@conditionCode,""IsDeleted""=@isDeleted,""IsAgency""=@isAgency,""Quantity""=@quantity,""Price1""=@price1,""Price2""=@price2,""Note""=@note,""CreatedTime""=@createdTime,""CreatedUserId""=@createdUserId,""ModifiedTime""=@modifiedTime,""ModifiedUserId""=@modifiedUserId where ""OrderId""=@orderId"); sqlCommand.Connection = sqlTransaction.Connection; sqlCommand.Transaction = sqlTransaction; sqlCommand.Parameters.Add(new SqlParameter("@rowVersion", SqlDbType.BigInt, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, rowVersion)); sqlCommand.Parameters.Add(new SqlParameter("@orderId", SqlDbType.Int, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, orderId)); sqlCommand.Parameters.Add(new SqlParameter("@blockOrderId", SqlDbType.Int, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, blockOrderId)); sqlCommand.Parameters.Add(new SqlParameter("@accountId", SqlDbType.Int, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, accountId)); sqlCommand.Parameters.Add(new SqlParameter("@securityId", SqlDbType.Int, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, securityId)); sqlCommand.Parameters.Add(new SqlParameter("@settlementId", SqlDbType.Int, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, settlementId)); sqlCommand.Parameters.Add(new SqlParameter("@brokerId", SqlDbType.Int, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, brokerId)); sqlCommand.Parameters.Add(new SqlParameter("@positionTypeCode", SqlDbType.Int, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, positionTypeCode)); sqlCommand.Parameters.Add(new SqlParameter("@transactionTypeCode", SqlDbType.Int, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, transactionTypeCode)); sqlCommand.Parameters.Add(new SqlParameter("@timeInForceCode", SqlDbType.Int, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, timeInForceCode)); sqlCommand.Parameters.Add(new SqlParameter("@orderTypeCode", SqlDbType.Int, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, orderTypeCode)); sqlCommand.Parameters.Add(new SqlParameter("@conditionCode", SqlDbType.Int, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, conditionCode)); sqlCommand.Parameters.Add(new SqlParameter("@isDeleted", SqlDbType.Bit, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, isDeleted)); sqlCommand.Parameters.Add(new SqlParameter("@isAgency", SqlDbType.Bit, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, isAgency)); sqlCommand.Parameters.Add(new SqlParameter("@quantity", SqlDbType.Decimal, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, quantity)); sqlCommand.Parameters.Add(new SqlParameter("@price1", SqlDbType.Decimal, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, price1)); sqlCommand.Parameters.Add(new SqlParameter("@price2", SqlDbType.Decimal, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, price2)); sqlCommand.Parameters.Add(new SqlParameter("@note", SqlDbType.NVarChar, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, note)); sqlCommand.Parameters.Add(new SqlParameter("@createdTime", SqlDbType.DateTime, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, createdTime)); sqlCommand.Parameters.Add(new SqlParameter("@createdUserId", SqlDbType.Int, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, createdUserId)); sqlCommand.Parameters.Add(new SqlParameter("@modifiedTime", SqlDbType.DateTime, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, modifiedTime)); sqlCommand.Parameters.Add(new SqlParameter("@modifiedUserId", SqlDbType.Int, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, modifiedUserId)); // Update the record in the SQL database. sqlCommand.ExecuteNonQuery(); }
/// <summary>Inserts a Order record.</summary> /// <param name="transaction">Commits or rejects a set of commands as a unit</param> /// <param name="blockOrderId">The value for the BlockOrderId column.</param> /// <param name="accountId">The value for the AccountId column.</param> /// <param name="securityId">The value for the SecurityId column.</param> /// <param name="settlementId">The value for the SettlementId column.</param> /// <param name="brokerId">The value for the BrokerId column.</param> /// <param name="positionTypeCode">The value for the PositionTypeCode column.</param> /// <param name="transactionTypeCode">The value for the TransactionTypeCode column.</param> /// <param name="timeInForceCode">The value for the TimeInForceCode column.</param> /// <param name="orderTypeCode">The value for the OrderTypeCode column.</param> /// <param name="conditionCode">The value for the ConditionCode column.</param> /// <param name="isDeleted">The value for the IsDeleted column.</param> /// <param name="isAgency">The value for the IsAgency column.</param> /// <param name="quantity">The value for the Quantity column.</param> /// <param name="price1">The value for the Price1 column.</param> /// <param name="price2">The value for the Price2 column.</param> /// <param name="note">The value for the Note column.</param> /// <param name="createdTime">The value for the CreatedTime column.</param> /// <param name="createdUserId">The value for the CreatedUserId column.</param> /// <param name="modifiedTime">The value for the ModifiedTime column.</param> /// <param name="modifiedUserId">The value for the ModifiedUserId column.</param> public static int Insert( AdoTransaction adoTransaction, SqlTransaction sqlTransaction, ref long rowVersion, int blockOrderId, int accountId, int securityId, int settlementId, object brokerId, int positionTypeCode, int transactionTypeCode, int timeInForceCode, int orderTypeCode, object conditionCode, object isDeleted, object isAgency, decimal quantity, object price1, object price2, object note, System.DateTime createdTime, int createdUserId, System.DateTime modifiedTime, int modifiedUserId) { // Accessor for the Order Table. ServerDataModel.OrderDataTable orderTable = ServerDataModel.Order; // Apply Defaults if ((brokerId == null)) { brokerId = System.DBNull.Value; } if ((conditionCode == null)) { conditionCode = System.DBNull.Value; } if ((isDeleted == null)) { isDeleted = false; } if ((isAgency == null)) { isAgency = false; } if ((price1 == null)) { price1 = System.DBNull.Value; } if ((price2 == null)) { price2 = System.DBNull.Value; } if ((note == null)) { note = System.DBNull.Value; } // Increment the row version rowVersion = ServerDataModel.RowVersion.Increment(); // The table must be locked for a short time to insert the record. This lock is to prevent other threads from // modifying the table during this short operation, it cannot be considered part of the locks used for transactional // integrity. ServerDataModel.OrderRow orderRow = null; lock (ServerDataModel.Order) { // Insert the record into the ADO database. orderRow = orderTable.NewOrderRow(); orderRow[orderTable.RowVersionColumn] = rowVersion; orderRow[orderTable.BlockOrderIdColumn] = blockOrderId; orderRow[orderTable.AccountIdColumn] = accountId; orderRow[orderTable.SecurityIdColumn] = securityId; orderRow[orderTable.SettlementIdColumn] = settlementId; orderRow[orderTable.BrokerIdColumn] = brokerId; orderRow[orderTable.PositionTypeCodeColumn] = positionTypeCode; orderRow[orderTable.TransactionTypeCodeColumn] = transactionTypeCode; orderRow[orderTable.TimeInForceCodeColumn] = timeInForceCode; orderRow[orderTable.OrderTypeCodeColumn] = orderTypeCode; orderRow[orderTable.ConditionCodeColumn] = conditionCode; orderRow[orderTable.IsDeletedColumn] = isDeleted; orderRow[orderTable.IsAgencyColumn] = isAgency; orderRow[orderTable.QuantityColumn] = quantity; orderRow[orderTable.Price1Column] = price1; orderRow[orderTable.Price2Column] = price2; orderRow[orderTable.NoteColumn] = note; orderRow[orderTable.CreatedTimeColumn] = createdTime; orderRow[orderTable.CreatedUserIdColumn] = createdUserId; orderRow[orderTable.ModifiedTimeColumn] = modifiedTime; orderRow[orderTable.ModifiedUserIdColumn] = modifiedUserId; orderTable.AddOrderRow(orderRow); } // New rows can't be locked ahed of time because they don't exist. Once the record is created and added to the table, // it is locked and then added retroactively to the transaction. adoTransaction.LockRequests.Add(new RowWriterRequest(orderRow, true)); // This will add the row to the transaction. adoTransaction.DataRows.Add(orderRow); // Insert the record into the SQL database. SqlCommand sqlCommand = new SqlCommand(@"insert ""Order"" (""rowVersion"",""OrderId"",""BlockOrderId"",""AccountId"",""SecurityId"",""SettlementId"",""BrokerId"",""PositionTypeCode"",""TransactionTypeCode"",""TimeInForceCode"",""OrderTypeCode"",""ConditionCode"",""IsDeleted"",""IsAgency"",""Quantity"",""Price1"",""Price2"",""Note"",""CreatedTime"",""CreatedUserId"",""ModifiedTime"",""ModifiedUserId"") values (@rowVersion,@orderId,@blockOrderId,@accountId,@securityId,@settlementId,@brokerId,@positionTypeCode,@transactionTypeCode,@timeInForceCode,@orderTypeCode,@conditionCode,@isDeleted,@isAgency,@quantity,@price1,@price2,@note,@createdTime,@createdUserId,@modifiedTime,@modifiedUserId)"); sqlCommand.Connection = sqlTransaction.Connection; sqlCommand.Transaction = sqlTransaction; sqlCommand.Parameters.Add(new SqlParameter("@rowVersion", SqlDbType.BigInt, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, rowVersion)); sqlCommand.Parameters.Add(new SqlParameter("@orderId", SqlDbType.Int, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, orderRow[orderTable.OrderIdColumn])); sqlCommand.Parameters.Add(new SqlParameter("@blockOrderId", SqlDbType.Int, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, blockOrderId)); sqlCommand.Parameters.Add(new SqlParameter("@accountId", SqlDbType.Int, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, accountId)); sqlCommand.Parameters.Add(new SqlParameter("@securityId", SqlDbType.Int, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, securityId)); sqlCommand.Parameters.Add(new SqlParameter("@settlementId", SqlDbType.Int, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, settlementId)); sqlCommand.Parameters.Add(new SqlParameter("@brokerId", SqlDbType.Int, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, brokerId)); sqlCommand.Parameters.Add(new SqlParameter("@positionTypeCode", SqlDbType.Int, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, positionTypeCode)); sqlCommand.Parameters.Add(new SqlParameter("@transactionTypeCode", SqlDbType.Int, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, transactionTypeCode)); sqlCommand.Parameters.Add(new SqlParameter("@timeInForceCode", SqlDbType.Int, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, timeInForceCode)); sqlCommand.Parameters.Add(new SqlParameter("@orderTypeCode", SqlDbType.Int, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, orderTypeCode)); sqlCommand.Parameters.Add(new SqlParameter("@conditionCode", SqlDbType.Int, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, conditionCode)); sqlCommand.Parameters.Add(new SqlParameter("@isDeleted", SqlDbType.Bit, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, isDeleted)); sqlCommand.Parameters.Add(new SqlParameter("@isAgency", SqlDbType.Bit, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, isAgency)); sqlCommand.Parameters.Add(new SqlParameter("@quantity", SqlDbType.Decimal, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, quantity)); sqlCommand.Parameters.Add(new SqlParameter("@price1", SqlDbType.Decimal, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, price1)); sqlCommand.Parameters.Add(new SqlParameter("@price2", SqlDbType.Decimal, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, price2)); sqlCommand.Parameters.Add(new SqlParameter("@note", SqlDbType.NVarChar, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, note)); sqlCommand.Parameters.Add(new SqlParameter("@createdTime", SqlDbType.DateTime, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, createdTime)); sqlCommand.Parameters.Add(new SqlParameter("@createdUserId", SqlDbType.Int, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, createdUserId)); sqlCommand.Parameters.Add(new SqlParameter("@modifiedTime", SqlDbType.DateTime, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, modifiedTime)); sqlCommand.Parameters.Add(new SqlParameter("@modifiedUserId", SqlDbType.Int, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, modifiedUserId)); sqlCommand.ExecuteNonQuery(); // Return Statements return(orderRow.OrderId); }
/// <summary>Inserts a Order record.</summary> /// <param name="transaction">Commits or rejects a set of commands as a unit</param> /// <param name="blockOrderId">The value for the BlockOrderId column.</param> /// <param name="accountId">The value for the AccountId column.</param> /// <param name="securityId">The value for the SecurityId column.</param> /// <param name="settlementId">The value for the SettlementId column.</param> /// <param name="brokerId">The value for the BrokerId column.</param> /// <param name="positionTypeCode">The value for the PositionTypeCode column.</param> /// <param name="transactionTypeCode">The value for the TransactionTypeCode column.</param> /// <param name="timeInForceCode">The value for the TimeInForceCode column.</param> /// <param name="orderTypeCode">The value for the OrderTypeCode column.</param> /// <param name="conditionCode">The value for the ConditionCode column.</param> /// <param name="isDeleted">The value for the IsDeleted column.</param> /// <param name="isAgency">The value for the IsAgency column.</param> /// <param name="quantity">The value for the Quantity column.</param> /// <param name="price1">The value for the Price1 column.</param> /// <param name="price2">The value for the Price2 column.</param> /// <param name="note">The value for the Note column.</param> /// <param name="createdTime">The value for the CreatedTime column.</param> /// <param name="createdUserId">The value for the CreatedUserId column.</param> /// <param name="modifiedTime">The value for the ModifiedTime column.</param> /// <param name="modifiedUserId">The value for the ModifiedUserId column.</param> public static int Insert( AdoTransaction adoTransaction, SqlTransaction sqlTransaction, ref long rowVersion, int blockOrderId, int accountId, int securityId, int settlementId, object brokerId, int positionTypeCode, int transactionTypeCode, int timeInForceCode, int orderTypeCode, object conditionCode, object isDeleted, object isAgency, decimal quantity, object price1, object price2, object note, System.DateTime createdTime, int createdUserId, System.DateTime modifiedTime, int modifiedUserId) { // Accessor for the Order Table. ServerDataModel.OrderDataTable orderTable = ServerDataModel.Order; // Apply Defaults if ((brokerId == null)) { brokerId = System.DBNull.Value; } if ((conditionCode == null)) { conditionCode = System.DBNull.Value; } if ((isDeleted == null)) { isDeleted = false; } if ((isAgency == null)) { isAgency = false; } if ((price1 == null)) { price1 = System.DBNull.Value; } if ((price2 == null)) { price2 = System.DBNull.Value; } if ((note == null)) { note = System.DBNull.Value; } // Increment the row version rowVersion = ServerDataModel.RowVersion.Increment(); // Insert the record into the ADO database. ServerDataModel.OrderRow orderRow = orderTable.NewOrderRow(); orderRow[orderTable.RowVersionColumn] = rowVersion; orderRow[orderTable.BlockOrderIdColumn] = blockOrderId; orderRow[orderTable.AccountIdColumn] = accountId; orderRow[orderTable.SecurityIdColumn] = securityId; orderRow[orderTable.SettlementIdColumn] = settlementId; orderRow[orderTable.BrokerIdColumn] = brokerId; orderRow[orderTable.PositionTypeCodeColumn] = positionTypeCode; orderRow[orderTable.TransactionTypeCodeColumn] = transactionTypeCode; orderRow[orderTable.TimeInForceCodeColumn] = timeInForceCode; orderRow[orderTable.OrderTypeCodeColumn] = orderTypeCode; orderRow[orderTable.ConditionCodeColumn] = conditionCode; orderRow[orderTable.IsDeletedColumn] = isDeleted; orderRow[orderTable.IsAgencyColumn] = isAgency; orderRow[orderTable.QuantityColumn] = quantity; orderRow[orderTable.Price1Column] = price1; orderRow[orderTable.Price2Column] = price2; orderRow[orderTable.NoteColumn] = note; orderRow[orderTable.CreatedTimeColumn] = createdTime; orderRow[orderTable.CreatedUserIdColumn] = createdUserId; orderRow[orderTable.ModifiedTimeColumn] = modifiedTime; orderRow[orderTable.ModifiedUserIdColumn] = modifiedUserId; orderTable.AddOrderRow(orderRow); adoTransaction.DataRows.Add(orderRow); // Insert the record into the SQL database. SqlCommand sqlCommand = new SqlCommand(@"insert ""Order"" (""rowVersion"",""OrderId"",""BlockOrderId"",""AccountId"",""SecurityId"",""SettlementId"",""BrokerId"",""PositionTypeCode"",""TransactionTypeCode"",""TimeInForceCode"",""OrderTypeCode"",""ConditionCode"",""IsDeleted"",""IsAgency"",""Quantity"",""Price1"",""Price2"",""Note"",""CreatedTime"",""CreatedUserId"",""ModifiedTime"",""ModifiedUserId"") values (@rowVersion,@orderId,@blockOrderId,@accountId,@securityId,@settlementId,@brokerId,@positionTypeCode,@transactionTypeCode,@timeInForceCode,@orderTypeCode,@conditionCode,@isDeleted,@isAgency,@quantity,@price1,@price2,@note,@createdTime,@createdUserId,@modifiedTime,@modifiedUserId)"); sqlCommand.Connection = sqlTransaction.Connection; sqlCommand.Transaction = sqlTransaction; sqlCommand.Parameters.Add(new SqlParameter("@rowVersion", SqlDbType.BigInt, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, rowVersion)); sqlCommand.Parameters.Add(new SqlParameter("@orderId", SqlDbType.Int, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, orderRow[orderTable.OrderIdColumn])); sqlCommand.Parameters.Add(new SqlParameter("@blockOrderId", SqlDbType.Int, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, blockOrderId)); sqlCommand.Parameters.Add(new SqlParameter("@accountId", SqlDbType.Int, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, accountId)); sqlCommand.Parameters.Add(new SqlParameter("@securityId", SqlDbType.Int, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, securityId)); sqlCommand.Parameters.Add(new SqlParameter("@settlementId", SqlDbType.Int, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, settlementId)); sqlCommand.Parameters.Add(new SqlParameter("@brokerId", SqlDbType.Int, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, brokerId)); sqlCommand.Parameters.Add(new SqlParameter("@positionTypeCode", SqlDbType.Int, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, positionTypeCode)); sqlCommand.Parameters.Add(new SqlParameter("@transactionTypeCode", SqlDbType.Int, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, transactionTypeCode)); sqlCommand.Parameters.Add(new SqlParameter("@timeInForceCode", SqlDbType.Int, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, timeInForceCode)); sqlCommand.Parameters.Add(new SqlParameter("@orderTypeCode", SqlDbType.Int, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, orderTypeCode)); sqlCommand.Parameters.Add(new SqlParameter("@conditionCode", SqlDbType.Int, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, conditionCode)); sqlCommand.Parameters.Add(new SqlParameter("@isDeleted", SqlDbType.Bit, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, isDeleted)); sqlCommand.Parameters.Add(new SqlParameter("@isAgency", SqlDbType.Bit, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, isAgency)); sqlCommand.Parameters.Add(new SqlParameter("@quantity", SqlDbType.Decimal, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, quantity)); sqlCommand.Parameters.Add(new SqlParameter("@price1", SqlDbType.Decimal, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, price1)); sqlCommand.Parameters.Add(new SqlParameter("@price2", SqlDbType.Decimal, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, price2)); sqlCommand.Parameters.Add(new SqlParameter("@note", SqlDbType.NVarChar, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, note)); sqlCommand.Parameters.Add(new SqlParameter("@createdTime", SqlDbType.DateTime, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, createdTime)); sqlCommand.Parameters.Add(new SqlParameter("@createdUserId", SqlDbType.Int, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, createdUserId)); sqlCommand.Parameters.Add(new SqlParameter("@modifiedTime", SqlDbType.DateTime, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, modifiedTime)); sqlCommand.Parameters.Add(new SqlParameter("@modifiedUserId", SqlDbType.Int, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, modifiedUserId)); sqlCommand.ExecuteNonQuery(); // Return Statements return(orderRow.OrderId); }
/// <summary>Loads a Order record using Metadata Parameters.</summary> /// <param name="transaction">Contains the parameters and exceptions for this command.</param> public static void Load(ParameterList parameters) { // Accessor for the Order Table. ServerDataModel.OrderDataTable orderTable = ServerDataModel.Order; // Extract the parameters from the command batch. AdoTransaction adoTransaction = parameters["adoTransaction"]; SqlTransaction sqlTransaction = parameters["sqlTransaction"]; object configurationId = parameters["configurationId"].Value; object externalOrderId = parameters["orderId"].Value; string externalBlockOrderId = parameters["blockOrderId"]; string externalAccountId = parameters["accountId"]; string externalSecurityId = parameters["securityId"]; string externalSettlementId = parameters["settlementId"]; object brokerId = parameters["brokerId"].Value; int positionTypeCode = parameters["positionTypeCode"]; string externalTransactionTypeCode = parameters["transactionTypeCode"]; string externalTimeInForceCode = parameters["timeInForceCode"]; string externalOrderTypeCode = parameters["orderTypeCode"]; object conditionCode = parameters["conditionCode"].Value; object isDeleted = parameters["isDeleted"].Value; object isAgency = parameters["isAgency"].Value; decimal quantity = parameters["quantity"]; object price1 = parameters["price1"].Value; object price2 = parameters["price2"].Value; object note = parameters["note"].Value; System.DateTime createdTime = parameters["createdTime"]; int createdUserId = parameters["createdUserId"]; System.DateTime modifiedTime = parameters["modifiedTime"]; int modifiedUserId = parameters["modifiedUserId"]; // The row versioning is largely disabled for external operations. The value is returned to the caller in the // event it's needed for operations within the batch. long rowVersion = long.MinValue; // Resolve External Identifiers int accountId = Account.FindRequiredKey(configurationId, "accountId", externalAccountId); int securityId = Security.FindRequiredKey(configurationId, "securityId", externalSecurityId); int settlementId = Security.FindRequiredKey(configurationId, "settlementId", externalSettlementId); int transactionTypeCode = TransactionType.FindRequiredKey(configurationId, "transactionTypeCode", externalTransactionTypeCode); int timeInForceCode = TimeInForce.FindRequiredKey(configurationId, "timeInForceCode", externalTimeInForceCode); int orderTypeCode = OrderType.FindRequiredKey(configurationId, "orderTypeCode", externalOrderTypeCode); // The load operation will create a record if it doesn't exist, or update an existing record. The external // identifier is used to determine if a record exists with the same key. if ((orderId == int.MinValue)) { // Populate the 'externalId' varaibles so that the external identifier can be used to find the row when an // external method is called with the same 'configurationId' parameter. int externalKeyIndex = Order.GetExternalKeyIndex(configurationId, "orderId"); object[] externalIdArray = new object[0]; externalIdArray[externalKeyIndex] = externalOrderId; // Call the internal method to complete the operation. MarkThree.Quasar.Core.Order.Insert(adoTransaction, sqlTransaction, ref rowVersion, blockOrderId, accountId, securityId, settlementId, brokerId, positionTypeCode, transactionTypeCode, timeInForceCode, orderTypeCode, conditionCode, isDeleted, isAgency, quantity, price1, price2, note, createdTime, createdUserId, modifiedTime, modifiedUserId); } else { // While the optimistic concurrency checking is disabled for the external methods, the internal methods // still need to perform the check. This ncurrency checking logic by finding the current row version to be // will bypass the coused when the internal method is called. ServerDataModel.OrderRow orderRow = orderTable.FindByOrderId(orderId); rowVersion = ((long)(orderRow[orderTable.RowVersionColumn])); // Call the internal method to complete the operation. MarkThree.Quasar.Core.Order.Update(adoTransaction, sqlTransaction, ref rowVersion, orderId, blockOrderId, accountId, securityId, settlementId, brokerId, positionTypeCode, transactionTypeCode, timeInForceCode, orderTypeCode, conditionCode, isDeleted, isAgency, quantity, price1, price2, note, createdTime, createdUserId, modifiedTime, modifiedUserId); } // Return values. parameters["rowVersion"] = rowVersion; }