/// <summary>Archives a Price 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="currencyId">The value for the CurrencyId 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 securityId, int currencyId) { // Accessor for the Price Table. ServerDataModel.PriceDataTable priceTable = ServerDataModel.Price; // Rule #1: Make sure the record exists before updating it. ServerDataModel.PriceRow priceRow = priceTable.FindBySecurityIdCurrencyId(securityId, currencyId); if ((priceRow == null)) { throw new Exception(string.Format("The Price table does not have an element identified by {0}{0}", securityId, currencyId)); } // Rule #2: Optimistic Concurrency Check if ((priceRow.RowVersion != rowVersion)) { throw new System.Exception("This record is busy. Please try again later."); } // Archive the child records. // Increment the row version rowVersion = ServerDataModel.RowVersion.Increment(); // Delete the record in the ADO database. priceRow[priceTable.RowVersionColumn] = rowVersion; adoTransaction.DataRows.Add(priceRow); priceRow.Delete(); // Archive the record in the SQL database. SqlCommand sqlCommand = new SqlCommand("update \"Price\" set \"IsArchived\" = 1 where \"SecurityId\"=@securityId and \"CurrencyI" + "d\"=@currencyId"); 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.Parameters.Add(new SqlParameter("@currencyId", SqlDbType.Int, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, currencyId)); sqlCommand.ExecuteNonQuery(); }
/// <summary>Updates a Price 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 Price Table. ServerDataModel.PriceDataTable priceTable = ServerDataModel.Price; // Extract the parameters from the command batch. AdoTransaction adoTransaction = parameters["adoTransaction"]; SqlTransaction sqlTransaction = parameters["sqlTransaction"]; object configurationId = parameters["configurationId"].Value; string externalSecurityId = parameters["securityId"]; string externalCurrencyId = parameters["currencyId"]; object closePrice = parameters["closePrice"].Value; object priceChange = parameters["priceChange"].Value; object lastPrice = parameters["lastPrice"].Value; object lastSize = parameters["lastSize"].Value; object bidPrice = parameters["bidPrice"].Value; object bidSize = parameters["bidSize"].Value; object askPrice = parameters["askPrice"].Value; object askSize = parameters["askSize"].Value; // The row versioning is largely disabled for external operations. long rowVersion = long.MinValue; // Resolve External Identifiers int securityId = Security.FindRequiredKey(configurationId, "securityId", externalSecurityId); int currencyId = Currency.FindRequiredKey(configurationId, "currencyId", externalCurrencyId); // This will bypass the internal optimistic concurrency checking by providing the current rowVersion to the // internal method. ServerDataModel.PriceRow priceRow = priceTable.FindBySecurityIdCurrencyId(securityId, currencyId); rowVersion = ((long)(priceRow[priceTable.RowVersionColumn])); // Call the internal method to complete the operation. MarkThree.Quasar.Core.Price.Update(adoTransaction, sqlTransaction, ref rowVersion, securityId, currencyId, closePrice, priceChange, lastPrice, lastSize, bidPrice, bidSize, askPrice, askSize); // Return values. parameters["rowVersion"] = rowVersion; }
/// <summary>Archives a Price 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 Price Table. ServerDataModel.PriceDataTable priceTable = ServerDataModel.Price; // Extract the parameters from the command batch. AdoTransaction adoTransaction = parameters["adoTransaction"]; SqlTransaction sqlTransaction = parameters["sqlTransaction"]; object configurationId = parameters["configurationId"].Value; string externalSecurityId = parameters["securityId"]; string externalCurrencyId = parameters["currencyId"]; // Resolve External Identifiers int securityId = Security.FindRequiredKey(configurationId, "securityId", externalSecurityId); int currencyId = Currency.FindRequiredKey(configurationId, "currencyId", externalCurrencyId); // The row versioning is largely disabled for external operations. long rowVersion = long.MinValue; // 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.PriceRow priceRow = priceTable.FindBySecurityIdCurrencyId(securityId, currencyId); rowVersion = ((long)(priceRow[priceTable.RowVersionColumn])); // Call the internal method to complete the operation. MarkThree.Quasar.Core.Price.Archive(adoTransaction, sqlTransaction, rowVersion, securityId, currencyId); }
/// <summary>Inserts a Price record.</summary> /// <param name="transaction">Commits or rejects a set of commands as a unit</param> /// <param name="securityId">The value for the SecurityId column.</param> /// <param name="currencyId">The value for the CurrencyId column.</param> /// <param name="closePrice">The value for the ClosePrice column.</param> /// <param name="priceChange">The value for the PriceChange column.</param> /// <param name="lastPrice">The value for the LastPrice column.</param> /// <param name="lastSize">The value for the LastSize column.</param> /// <param name="bidPrice">The value for the BidPrice column.</param> /// <param name="bidSize">The value for the BidSize column.</param> /// <param name="askPrice">The value for the AskPrice column.</param> /// <param name="askSize">The value for the AskSize column.</param> public static void Insert(AdoTransaction adoTransaction, SqlTransaction sqlTransaction, ref long rowVersion, int securityId, int currencyId, object closePrice, object priceChange, object lastPrice, object lastSize, object bidPrice, object bidSize, object askPrice, object askSize) { // Accessor for the Price Table. ServerDataModel.PriceDataTable priceTable = ServerDataModel.Price; // Apply Defaults if ((closePrice == null)) { closePrice = 0.0m; } if ((priceChange == null)) { priceChange = 0.0m; } if ((lastPrice == null)) { lastPrice = 0.0m; } if ((lastSize == null)) { lastSize = 0.0m; } if ((bidPrice == null)) { bidPrice = 0.0m; } if ((bidSize == null)) { bidSize = 0.0m; } if ((askPrice == null)) { askPrice = 0.0m; } if ((askSize == null)) { askSize = 0.0m; } // Increment the row version rowVersion = ServerDataModel.RowVersion.Increment(); // Insert the record into the ADO database. ServerDataModel.PriceRow priceRow = priceTable.NewPriceRow(); priceRow[priceTable.RowVersionColumn] = rowVersion; priceRow[priceTable.SecurityIdColumn] = securityId; priceRow[priceTable.CurrencyIdColumn] = currencyId; priceRow[priceTable.ClosePriceColumn] = closePrice; priceRow[priceTable.PriceChangeColumn] = priceChange; priceRow[priceTable.LastPriceColumn] = lastPrice; priceRow[priceTable.LastSizeColumn] = lastSize; priceRow[priceTable.BidPriceColumn] = bidPrice; priceRow[priceTable.BidSizeColumn] = bidSize; priceRow[priceTable.AskPriceColumn] = askPrice; priceRow[priceTable.AskSizeColumn] = askSize; priceTable.AddPriceRow(priceRow); adoTransaction.DataRows.Add(priceRow); // Insert the record into the SQL database. SqlCommand sqlCommand = new SqlCommand("insert \"Price\" (\"rowVersion\",\"SecurityId\",\"CurrencyId\",\"ClosePrice\",\"LastPrice\",\"" + "LastSize\",\"BidPrice\",\"BidSize\",\"AskPrice\",\"AskSize\") values (@rowVersion,@securi" + "tyId,@currencyId,@closePrice,@lastPrice,@lastSize,@bidPrice,@bidSize,@askPrice,@" + "askSize)"); 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("@securityId", SqlDbType.Int, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, securityId)); sqlCommand.Parameters.Add(new SqlParameter("@currencyId", SqlDbType.Int, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, currencyId)); sqlCommand.Parameters.Add(new SqlParameter("@closePrice", SqlDbType.Decimal, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, closePrice)); sqlCommand.Parameters.Add(new SqlParameter("@lastPrice", SqlDbType.Decimal, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, lastPrice)); sqlCommand.Parameters.Add(new SqlParameter("@lastSize", SqlDbType.Decimal, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, lastSize)); sqlCommand.Parameters.Add(new SqlParameter("@bidPrice", SqlDbType.Decimal, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, bidPrice)); sqlCommand.Parameters.Add(new SqlParameter("@bidSize", SqlDbType.Decimal, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, bidSize)); sqlCommand.Parameters.Add(new SqlParameter("@askPrice", SqlDbType.Decimal, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, askPrice)); sqlCommand.Parameters.Add(new SqlParameter("@askSize", SqlDbType.Decimal, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, askSize)); sqlCommand.ExecuteNonQuery(); }
/// <summary>Updates a Price 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="securityId">The value for the SecurityId column.</param> /// <param name="currencyId">The value for the CurrencyId column.</param> /// <param name="closePrice">The value for the ClosePrice column.</param> /// <param name="priceChange">The value for the PriceChange column.</param> /// <param name="lastPrice">The value for the LastPrice column.</param> /// <param name="lastSize">The value for the LastSize column.</param> /// <param name="bidPrice">The value for the BidPrice column.</param> /// <param name="bidSize">The value for the BidSize column.</param> /// <param name="askPrice">The value for the AskPrice column.</param> /// <param name="askSize">The value for the AskSize column.</param> public static void Update(AdoTransaction adoTransaction, SqlTransaction sqlTransaction, ref long rowVersion, int securityId, int currencyId, object closePrice, object priceChange, object lastPrice, object lastSize, object bidPrice, object bidSize, object askPrice, object askSize) { // Accessor for the Price Table. ServerDataModel.PriceDataTable priceTable = ServerDataModel.Price; // Rule #1: Make sure the record exists before updating it. ServerDataModel.PriceRow priceRow = priceTable.FindBySecurityIdCurrencyId(securityId, currencyId); if ((priceRow == null)) { throw new Exception(string.Format("The Price table does not have an element identified by {0}{0}", securityId, currencyId)); } // Rule #2: Optimistic Concurrency Check if ((priceRow.RowVersion != rowVersion)) { throw new System.Exception("This record is busy. Please try again later."); } // Apply Defaults if ((closePrice == null)) { closePrice = priceRow[priceTable.ClosePriceColumn]; } if ((priceChange == null)) { priceChange = priceRow[priceTable.PriceChangeColumn]; } if ((lastPrice == null)) { lastPrice = priceRow[priceTable.LastPriceColumn]; } if ((lastSize == null)) { lastSize = priceRow[priceTable.LastSizeColumn]; } if ((bidPrice == null)) { bidPrice = priceRow[priceTable.BidPriceColumn]; } if ((bidSize == null)) { bidSize = priceRow[priceTable.BidSizeColumn]; } if ((askPrice == null)) { askPrice = priceRow[priceTable.AskPriceColumn]; } if ((askSize == null)) { askSize = priceRow[priceTable.AskSizeColumn]; } // Increment the row version rowVersion = ServerDataModel.RowVersion.Increment(); // Update the record in the ADO database. priceRow[priceTable.RowVersionColumn] = rowVersion; priceRow[priceTable.ClosePriceColumn] = closePrice; priceRow[priceTable.PriceChangeColumn] = priceChange; priceRow[priceTable.LastPriceColumn] = lastPrice; priceRow[priceTable.LastSizeColumn] = lastSize; priceRow[priceTable.BidPriceColumn] = bidPrice; priceRow[priceTable.BidSizeColumn] = bidSize; priceRow[priceTable.AskPriceColumn] = askPrice; priceRow[priceTable.AskSizeColumn] = askSize; adoTransaction.DataRows.Add(priceRow); // Update the record in the SQL database. SqlCommand sqlCommand = new SqlCommand("update \"Price\" set \"RowVersion\"=@rowVersion,\"ClosePrice\"=@closePrice,\"LastPrice\"=" + "@lastPrice,\"LastSize\"=@lastSize,\"BidPrice\"=@bidPrice,\"BidSize\"=@bidSize,\"AskPric" + "e\"=@askPrice,\"AskSize\"=@askSize where \"SecurityId\"=@securityId and \"CurrencyId\"=" + "@currencyId"); 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("@securityId", SqlDbType.Int, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, securityId)); sqlCommand.Parameters.Add(new SqlParameter("@currencyId", SqlDbType.Int, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, currencyId)); sqlCommand.Parameters.Add(new SqlParameter("@closePrice", SqlDbType.Decimal, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, closePrice)); sqlCommand.Parameters.Add(new SqlParameter("@lastPrice", SqlDbType.Decimal, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, lastPrice)); sqlCommand.Parameters.Add(new SqlParameter("@lastSize", SqlDbType.Decimal, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, lastSize)); sqlCommand.Parameters.Add(new SqlParameter("@bidPrice", SqlDbType.Decimal, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, bidPrice)); sqlCommand.Parameters.Add(new SqlParameter("@bidSize", SqlDbType.Decimal, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, bidSize)); sqlCommand.Parameters.Add(new SqlParameter("@askPrice", SqlDbType.Decimal, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, askPrice)); sqlCommand.Parameters.Add(new SqlParameter("@askSize", SqlDbType.Decimal, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, askSize)); // Update the record in the SQL database. sqlCommand.ExecuteNonQuery(); }