/// <summary>Updates a VolumeCategory 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 VolumeCategory Table. ServerMarketData.VolumeCategoryDataTable volumeCategoryTable = ServerMarketData.VolumeCategory; // Extract the parameters from the command batch. AdoTransaction adoTransaction = parameters["adoTransaction"]; SqlTransaction sqlTransaction = parameters["sqlTransaction"]; object configurationId = parameters["configurationId"].Value; object description = parameters["description"].Value; object highVolumeRange = parameters["highVolumeRange"].Value; object lowVolumeRange = parameters["lowVolumeRange"].Value; object mnemonic = parameters["mnemonic"].Value; string externalVolumeCategoryId = ((string)(parameters["volumeCategoryId"])); // The row versioning is largely disabled for external operations. long rowVersion = long.MinValue; // Resolve External Identifiers int volumeCategoryId = VolumeCategory.FindRequiredKey(configurationId, "volumeCategoryId", externalVolumeCategoryId); // 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. ServerMarketData.VolumeCategoryRow volumeCategoryRow = volumeCategoryTable.FindByVolumeCategoryId(volumeCategoryId); rowVersion = ((long)(volumeCategoryRow[volumeCategoryTable.RowVersionColumn])); // Call the internal method to complete the operation. MarkThree.Guardian.Core.VolumeCategory.Update(adoTransaction, sqlTransaction, ref rowVersion, description, null, highVolumeRange, lowVolumeRange, mnemonic, volumeCategoryId); // Return values. parameters["rowVersion"] = rowVersion; }
/// <summary>Initializes the static elements of an Object.</summary> static VolumeCategory() { // The table must be locked before the indices can be read into an accelerator array. ServerMarketData.VolumeCategoryLock.AcquireReaderLock(System.Threading.Timeout.Infinite); // Accessor for the VolumeCategory Table. ServerMarketData.VolumeCategoryDataTable volumeCategoryTable = ServerMarketData.VolumeCategory; // This does an indirect lookup operation using the views created for the ExternalId columns. Take the index of the user // identifier column calcualted above and use it to find a record containing the external identifier. VolumeCategory.externalKeyArray = new DataView[] { volumeCategoryTable.KeyVolumeCategoryExternalId0}; // The table must be released after the array is constructed. ServerMarketData.VolumeCategoryLock.ReleaseReaderLock(); }
/// <summary>Inserts a VolumeCategory record.</summary> /// <param name="transaction">Commits or rejects a set of commands as a unit</param> /// <param name="description">The value for the Description column.</param> /// <param name="externalId0">The value for the ExternalId0 column.</param> /// <param name="highVolumeRange">The value for the HighVolumeRange column.</param> /// <param name="lowVolumeRange">The value for the LowVolumeRange column.</param> /// <param name="mnemonic">The value for the Mnemonic column.</param> public static int Insert(AdoTransaction adoTransaction, SqlTransaction sqlTransaction, ref long rowVersion, object description, object externalId0, object highVolumeRange, decimal lowVolumeRange, string mnemonic) { // Accessor for the VolumeCategory Table. ServerMarketData.VolumeCategoryDataTable volumeCategoryTable = ServerMarketData.VolumeCategory; // Apply Defaults if ((description == null)) { description = System.DBNull.Value; } if ((externalId0 == null)) { externalId0 = System.DBNull.Value; } if ((highVolumeRange == null)) { highVolumeRange = System.DBNull.Value; } // Increment the row version rowVersion = ServerMarketData.RowVersion.Increment(); // Insert the record into the ADO database. ServerMarketData.VolumeCategoryRow volumeCategoryRow = volumeCategoryTable.NewVolumeCategoryRow(); volumeCategoryRow[volumeCategoryTable.RowVersionColumn] = rowVersion; volumeCategoryRow[volumeCategoryTable.DescriptionColumn] = description; volumeCategoryRow[volumeCategoryTable.ExternalId0Column] = externalId0; volumeCategoryRow[volumeCategoryTable.HighVolumeRangeColumn] = highVolumeRange; volumeCategoryRow[volumeCategoryTable.LowVolumeRangeColumn] = lowVolumeRange; volumeCategoryRow[volumeCategoryTable.MnemonicColumn] = mnemonic; volumeCategoryTable.AddVolumeCategoryRow(volumeCategoryRow); adoTransaction.DataRows.Add(volumeCategoryRow); // Insert the record into the SQL database. SqlCommand sqlCommand = new SqlCommand("insert \"VolumeCategory\" (\"rowVersion\",\"Description\",\"ExternalId0\",\"HighVolumeRang" + "e\",\"LowVolumeRange\",\"Mnemonic\",\"VolumeCategoryId\") values (@rowVersion,@descript" + "ion,@externalId0,@highVolumeRange,@lowVolumeRange,@mnemonic,@volumeCategoryId)"); 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("@description", SqlDbType.NVarChar, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, description)); sqlCommand.Parameters.Add(new SqlParameter("@externalId0", SqlDbType.NVarChar, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, externalId0)); sqlCommand.Parameters.Add(new SqlParameter("@highVolumeRange", SqlDbType.Decimal, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, highVolumeRange)); sqlCommand.Parameters.Add(new SqlParameter("@lowVolumeRange", SqlDbType.Decimal, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, lowVolumeRange)); sqlCommand.Parameters.Add(new SqlParameter("@mnemonic", SqlDbType.NVarChar, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, mnemonic)); sqlCommand.Parameters.Add(new SqlParameter("@volumeCategoryId", SqlDbType.Int, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, volumeCategoryRow[volumeCategoryTable.VolumeCategoryIdColumn])); sqlCommand.ExecuteNonQuery(); // Return Statements return(volumeCategoryRow.VolumeCategoryId); }
/// <summary>Loads a VolumeCategory 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 VolumeCategory Table. ServerMarketData.VolumeCategoryDataTable volumeCategoryTable = ServerMarketData.VolumeCategory; // Extract the parameters from the command batch. AdoTransaction adoTransaction = parameters["adoTransaction"]; SqlTransaction sqlTransaction = parameters["sqlTransaction"]; object configurationId = parameters["configurationId"].Value; object description = parameters["description"].Value; object externalId0 = parameters["externalId0"].Value; object highVolumeRange = parameters["highVolumeRange"].Value; decimal lowVolumeRange = parameters["lowVolumeRange"]; string mnemonic = parameters["mnemonic"]; object externalVolumeCategoryId = parameters["volumeCategoryId"].Value; // 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 volumeCategoryId = VolumeCategory.FindKey(configurationId, "volumeCategoryId", externalVolumeCategoryId); // 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 ((volumeCategoryId == 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 = VolumeCategory.GetExternalKeyIndex(configurationId, "volumeCategoryId"); object[] externalIdArray = new object[1]; externalIdArray[externalKeyIndex] = externalVolumeCategoryId; externalId0 = externalIdArray[0]; // Call the internal method to complete the operation. MarkThree.Guardian.Core.VolumeCategory.Insert(adoTransaction, sqlTransaction, ref rowVersion, description, externalId0, highVolumeRange, lowVolumeRange, mnemonic); } 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. ServerMarketData.VolumeCategoryRow volumeCategoryRow = volumeCategoryTable.FindByVolumeCategoryId(volumeCategoryId); rowVersion = ((long)(volumeCategoryRow[volumeCategoryTable.RowVersionColumn])); // Call the internal method to complete the operation. MarkThree.Guardian.Core.VolumeCategory.Update(adoTransaction, sqlTransaction, ref rowVersion, description, externalId0, highVolumeRange, lowVolumeRange, mnemonic, volumeCategoryId); } // Return values. parameters["rowVersion"] = rowVersion; }
/// <summary>Archives a VolumeCategory 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="volumeCategoryId">The value for the VolumeCategoryId 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 volumeCategoryId) { // Accessor for the VolumeCategory Table. ServerMarketData.VolumeCategoryDataTable volumeCategoryTable = ServerMarketData.VolumeCategory; // Rule #1: Make sure the record exists before updating it. ServerMarketData.VolumeCategoryRow volumeCategoryRow = volumeCategoryTable.FindByVolumeCategoryId(volumeCategoryId); if ((volumeCategoryRow == null)) { throw new Exception(string.Format("The VolumeCategory table does not have an element identified by {0}", volumeCategoryId)); } // Rule #2: Optimistic Concurrency Check if ((volumeCategoryRow.RowVersion != rowVersion)) { throw new System.Exception("This record is busy. Please try again later."); } // Archive the child records. for (int index = 0; (index < volumeCategoryRow.GetSecurityRows().Length); index = (index + 1)) { ServerMarketData.SecurityRow childSecurityRow = volumeCategoryRow.GetSecurityRows()[index]; Security.ArchiveChildren(adoTransaction, sqlTransaction, childSecurityRow.RowVersion, childSecurityRow.SecurityId); } for (int index = 0; (index < volumeCategoryRow.GetTraderVolumeSettingRows().Length); index = (index + 1)) { ServerMarketData.TraderVolumeSettingRow childTraderVolumeSettingRow = volumeCategoryRow.GetTraderVolumeSettingRows()[index]; TraderVolumeSetting.Archive(adoTransaction, sqlTransaction, childTraderVolumeSettingRow.RowVersion, childTraderVolumeSettingRow.TraderVolumeSettingId); } // Increment the row version rowVersion = ServerMarketData.RowVersion.Increment(); // Delete the record in the ADO database. volumeCategoryRow[volumeCategoryTable.RowVersionColumn] = rowVersion; adoTransaction.DataRows.Add(volumeCategoryRow); volumeCategoryRow.Delete(); // Archive the record in the SQL database. SqlCommand sqlCommand = new SqlCommand("update \"VolumeCategory\" set \"IsArchived\" = 1 where \"VolumeCategoryId\"=@volumeCate" + "goryId"); sqlCommand.Connection = sqlTransaction.Connection; sqlCommand.Transaction = sqlTransaction; sqlCommand.Parameters.Add(new SqlParameter("@volumeCategoryId", SqlDbType.Int, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, volumeCategoryId)); sqlCommand.ExecuteNonQuery(); }
/// <summary>Finds a a VolumeCategory record using a configuration and an external identifier.</summary> /// <param name="configurationId">Specified which mappings (user id columns) to use when looking up external identifiers.</param> /// <param name="parameterId">The name of the parameter as specified in the configuration table.</param> /// <param name="externalId">The external (user supplied) identifier for the record.</param> public static int FindKey(object configurationId, string parameterId, object externalId) { // A missing key will never match a column. if ((externalId == null)) { return int.MinValue; } // Accessor for the VolumeCategory Table. ServerMarketData.VolumeCategoryDataTable volumeCategoryTable = ServerMarketData.VolumeCategory; // Look for the record using the external identifier. The configuration selected the key to use, which effectively // selected the external id column to use for the search. If a record is found in the view, a translation still needs // to be made back to the original table before an index to the record can be returned to the caller. int externalKeyIndex = VolumeCategory.GetExternalKeyIndex(configurationId, parameterId); System.Data.DataView externalKeyView = VolumeCategory.externalKeyArray[externalKeyIndex]; int recordIndex = externalKeyView.Find(new object[] { externalId}); if ((recordIndex == -1)) { return int.MinValue; } return ((int)(externalKeyView[recordIndex].Row[volumeCategoryTable.VolumeCategoryIdColumn])); }
/// <summary>Archives a VolumeCategory 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 VolumeCategory Table. ServerMarketData.VolumeCategoryDataTable volumeCategoryTable = ServerMarketData.VolumeCategory; // Extract the parameters from the command batch. AdoTransaction adoTransaction = parameters["adoTransaction"]; SqlTransaction sqlTransaction = parameters["sqlTransaction"]; object configurationId = parameters["configurationId"].Value; string externalVolumeCategoryId = parameters["volumeCategoryId"]; // 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 volumeCategoryId = VolumeCategory.FindRequiredKey(configurationId, "volumeCategoryId", externalVolumeCategoryId); // 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. ServerMarketData.VolumeCategoryRow volumeCategoryRow = volumeCategoryTable.FindByVolumeCategoryId(volumeCategoryId); rowVersion = ((long)(volumeCategoryRow[volumeCategoryTable.RowVersionColumn])); // Call the internal method to complete the operation. MarkThree.Guardian.Core.VolumeCategory.Archive(adoTransaction, sqlTransaction, rowVersion, volumeCategoryId); }
/// <summary>Updates a VolumeCategory 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="description">The value for the Description column.</param> /// <param name="externalId0">The value for the ExternalId0 column.</param> /// <param name="highVolumeRange">The value for the HighVolumeRange column.</param> /// <param name="lowVolumeRange">The value for the LowVolumeRange column.</param> /// <param name="mnemonic">The value for the Mnemonic column.</param> /// <param name="volumeCategoryId">The value for the VolumeCategoryId column.</param> public static void Update(AdoTransaction adoTransaction, SqlTransaction sqlTransaction, ref long rowVersion, object description, object externalId0, object highVolumeRange, object lowVolumeRange, object mnemonic, int volumeCategoryId) { // Accessor for the VolumeCategory Table. ServerMarketData.VolumeCategoryDataTable volumeCategoryTable = ServerMarketData.VolumeCategory; // Rule #1: Make sure the record exists before updating it. ServerMarketData.VolumeCategoryRow volumeCategoryRow = volumeCategoryTable.FindByVolumeCategoryId(volumeCategoryId); if ((volumeCategoryRow == null)) { throw new Exception(string.Format("The VolumeCategory table does not have an element identified by {0}", volumeCategoryId)); } // Rule #2: Optimistic Concurrency Check if ((volumeCategoryRow.RowVersion != rowVersion)) { throw new System.Exception("This record is busy. Please try again later."); } // Apply Defaults if ((description == null)) { description = volumeCategoryRow[volumeCategoryTable.DescriptionColumn]; } if ((externalId0 == null)) { externalId0 = volumeCategoryRow[volumeCategoryTable.ExternalId0Column]; } if ((highVolumeRange == null)) { highVolumeRange = volumeCategoryRow[volumeCategoryTable.HighVolumeRangeColumn]; } if ((lowVolumeRange == null)) { lowVolumeRange = volumeCategoryRow[volumeCategoryTable.LowVolumeRangeColumn]; } if ((mnemonic == null)) { mnemonic = volumeCategoryRow[volumeCategoryTable.MnemonicColumn]; } // Increment the row version rowVersion = ServerMarketData.RowVersion.Increment(); // Update the record in the ADO database. volumeCategoryRow[volumeCategoryTable.RowVersionColumn] = rowVersion; volumeCategoryRow[volumeCategoryTable.DescriptionColumn] = description; volumeCategoryRow[volumeCategoryTable.ExternalId0Column] = externalId0; volumeCategoryRow[volumeCategoryTable.HighVolumeRangeColumn] = highVolumeRange; volumeCategoryRow[volumeCategoryTable.LowVolumeRangeColumn] = lowVolumeRange; volumeCategoryRow[volumeCategoryTable.MnemonicColumn] = mnemonic; adoTransaction.DataRows.Add(volumeCategoryRow); // Update the record in the SQL database. SqlCommand sqlCommand = new SqlCommand("update \"VolumeCategory\" set \"RowVersion\"=@rowVersion,\"Description\"=@description,\"" + "ExternalId0\"=@externalId0,\"HighVolumeRange\"=@highVolumeRange,\"LowVolumeRange\"=@l" + "owVolumeRange,\"Mnemonic\"=@mnemonic where \"VolumeCategoryId\"=@volumeCategoryId"); 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("@description", SqlDbType.NVarChar, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, description)); sqlCommand.Parameters.Add(new SqlParameter("@externalId0", SqlDbType.NVarChar, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, externalId0)); sqlCommand.Parameters.Add(new SqlParameter("@highVolumeRange", SqlDbType.Decimal, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, highVolumeRange)); sqlCommand.Parameters.Add(new SqlParameter("@lowVolumeRange", SqlDbType.Decimal, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, lowVolumeRange)); sqlCommand.Parameters.Add(new SqlParameter("@mnemonic", SqlDbType.NVarChar, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, mnemonic)); sqlCommand.Parameters.Add(new SqlParameter("@volumeCategoryId", SqlDbType.Int, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, volumeCategoryId)); // Update the record in the SQL database. sqlCommand.ExecuteNonQuery(); }