/// <summary>Inserts a ObjectTree record.</summary> /// <param name="transaction">Commits or rejects a set of commands as a unit</param> /// <param name="childId">The value for the ChildId column.</param> /// <param name="parentId">The value for the ParentId column.</param> /// <param name="externalId0">The value for the ExternalId0 column.</param> public static int Insert(AdoTransaction adoTransaction, SqlTransaction sqlTransaction, ref long rowVersion, int childId, int parentId, object externalId0) { // Accessor for the ObjectTree Table. ServerMarketData.ObjectTreeDataTable objectTreeTable = ServerMarketData.ObjectTree; // Apply Defaults if ((externalId0 == null)) { externalId0 = System.DBNull.Value; } // Increment the row version rowVersion = ServerMarketData.RowVersion.Increment(); // Insert the record into the ADO database. ServerMarketData.ObjectTreeRow objectTreeRow = objectTreeTable.NewObjectTreeRow(); objectTreeRow[objectTreeTable.RowVersionColumn] = rowVersion; objectTreeRow[objectTreeTable.ChildIdColumn] = childId; objectTreeRow[objectTreeTable.ParentIdColumn] = parentId; objectTreeRow[objectTreeTable.ExternalId0Column] = externalId0; objectTreeTable.AddObjectTreeRow(objectTreeRow); adoTransaction.DataRows.Add(objectTreeRow); // Insert the record into the SQL database. SqlCommand sqlCommand = new SqlCommand("insert \"ObjectTree\" (\"rowVersion\",\"ObjectTreeId\",\"ChildId\",\"ParentId\",\"ExternalId" + "0\") values (@rowVersion,@objectTreeId,@childId,@parentId,@externalId0)"); 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("@objectTreeId", SqlDbType.Int, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, objectTreeRow[objectTreeTable.ObjectTreeIdColumn])); sqlCommand.Parameters.Add(new SqlParameter("@childId", SqlDbType.Int, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, childId)); sqlCommand.Parameters.Add(new SqlParameter("@parentId", SqlDbType.Int, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, parentId)); sqlCommand.Parameters.Add(new SqlParameter("@externalId0", SqlDbType.NVarChar, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, externalId0)); sqlCommand.ExecuteNonQuery(); // Return Statements return(objectTreeRow.ObjectTreeId); }
/// <summary>Archives a ObjectTree 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="objectTreeId">The value for the ObjectTreeId 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 objectTreeId) { // Accessor for the ObjectTree Table. ServerMarketData.ObjectTreeDataTable objectTreeTable = ServerMarketData.ObjectTree; // Rule #1: Make sure the record exists before updating it. ServerMarketData.ObjectTreeRow objectTreeRow = objectTreeTable.FindByObjectTreeId(objectTreeId); if ((objectTreeRow == null)) { throw new Exception(string.Format("The ObjectTree table does not have an element identified by {0}", objectTreeId)); } // Rule #2: Optimistic Concurrency Check if ((objectTreeRow.RowVersion != rowVersion)) { throw new System.Exception("This record is busy. Please try again later."); } // Archive the child records. // Increment the row version rowVersion = ServerMarketData.RowVersion.Increment(); // Delete the record in the ADO database. objectTreeRow[objectTreeTable.RowVersionColumn] = rowVersion; adoTransaction.DataRows.Add(objectTreeRow); objectTreeRow.Delete(); // Archive the record in the SQL database. SqlCommand sqlCommand = new SqlCommand("update \"ObjectTree\" set \"IsArchived\" = 1 where \"ObjectTreeId\"=@objectTreeId"); sqlCommand.Connection = sqlTransaction.Connection; sqlCommand.Transaction = sqlTransaction; sqlCommand.Parameters.Add(new SqlParameter("@objectTreeId", SqlDbType.Int, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, objectTreeId)); sqlCommand.ExecuteNonQuery(); }
/// <summary>Updates a ObjectTree 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 ObjectTree Table. ServerMarketData.ObjectTreeDataTable objectTreeTable = ServerMarketData.ObjectTree; // Extract the parameters from the command batch. AdoTransaction adoTransaction = parameters["adoTransaction"]; SqlTransaction sqlTransaction = parameters["sqlTransaction"]; object configurationId = parameters["configurationId"].Value; string externalObjectTreeId = ((string)(parameters["objectTreeId"])); object externalChildId = parameters["childId"].Value; object externalParentId = parameters["parentId"].Value; // The row versioning is largely disabled for external operations. long rowVersion = long.MinValue; // Resolve External Identifiers int objectTreeId = ObjectTree.FindRequiredKey(configurationId, "objectTreeId", externalObjectTreeId); object childId = Object.FindOptionalKey(configurationId, "childId", externalChildId); object parentId = Object.FindOptionalKey(configurationId, "parentId", externalParentId); // 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.ObjectTreeRow objectTreeRow = objectTreeTable.FindByObjectTreeId(objectTreeId); rowVersion = ((long)(objectTreeRow[objectTreeTable.RowVersionColumn])); // Call the internal method to complete the operation. MarkThree.Guardian.Core.ObjectTree.Update(adoTransaction, sqlTransaction, ref rowVersion, objectTreeId, childId, parentId, null); // Return values. parameters["rowVersion"] = rowVersion; }
/// <summary>Updates a ObjectTree 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="objectTreeId">The value for the ObjectTreeId column.</param> /// <param name="childId">The value for the ChildId column.</param> /// <param name="parentId">The value for the ParentId column.</param> /// <param name="externalId0">The value for the ExternalId0 column.</param> public static void Update(AdoTransaction adoTransaction, SqlTransaction sqlTransaction, ref long rowVersion, int objectTreeId, object childId, object parentId, object externalId0) { // Accessor for the ObjectTree Table. ServerMarketData.ObjectTreeDataTable objectTreeTable = ServerMarketData.ObjectTree; // Rule #1: Make sure the record exists before updating it. ServerMarketData.ObjectTreeRow objectTreeRow = objectTreeTable.FindByObjectTreeId(objectTreeId); if ((objectTreeRow == null)) { throw new Exception(string.Format("The ObjectTree table does not have an element identified by {0}", objectTreeId)); } // Rule #2: Optimistic Concurrency Check if ((objectTreeRow.RowVersion != rowVersion)) { throw new System.Exception("This record is busy. Please try again later."); } // Apply Defaults if ((childId == null)) { childId = objectTreeRow[objectTreeTable.ChildIdColumn]; } if ((parentId == null)) { parentId = objectTreeRow[objectTreeTable.ParentIdColumn]; } if ((externalId0 == null)) { externalId0 = objectTreeRow[objectTreeTable.ExternalId0Column]; } // Increment the row version rowVersion = ServerMarketData.RowVersion.Increment(); // Update the record in the ADO database. objectTreeRow[objectTreeTable.RowVersionColumn] = rowVersion; objectTreeRow[objectTreeTable.ChildIdColumn] = childId; objectTreeRow[objectTreeTable.ParentIdColumn] = parentId; objectTreeRow[objectTreeTable.ExternalId0Column] = externalId0; adoTransaction.DataRows.Add(objectTreeRow); // Update the record in the SQL database. SqlCommand sqlCommand = new SqlCommand("update \"ObjectTree\" set \"RowVersion\"=@rowVersion,\"ChildId\"=@childId,\"ParentId\"=@p" + "arentId,\"ExternalId0\"=@externalId0 where \"ObjectTreeId\"=@objectTreeId"); 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("@objectTreeId", SqlDbType.Int, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, objectTreeId)); sqlCommand.Parameters.Add(new SqlParameter("@childId", SqlDbType.Int, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, childId)); sqlCommand.Parameters.Add(new SqlParameter("@parentId", SqlDbType.Int, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, parentId)); sqlCommand.Parameters.Add(new SqlParameter("@externalId0", SqlDbType.NVarChar, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, externalId0)); // Update the record in the SQL database. sqlCommand.ExecuteNonQuery(); }
/// <summary>Loads a ObjectTree 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 ObjectTree Table. ServerMarketData.ObjectTreeDataTable objectTreeTable = ServerMarketData.ObjectTree; // Extract the parameters from the command batch. AdoTransaction adoTransaction = parameters["adoTransaction"]; SqlTransaction sqlTransaction = parameters["sqlTransaction"]; object configurationId = parameters["configurationId"].Value; object externalObjectTreeId = parameters["objectTreeId"].Value; string externalChildId = parameters["childId"]; string externalParentId = parameters["parentId"]; object externalId0 = parameters["externalId0"].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 objectTreeId = ObjectTree.FindKey(configurationId, "objectTreeId", externalObjectTreeId); int childId = Object.FindRequiredKey(configurationId, "childId", externalChildId); int parentId = Object.FindRequiredKey(configurationId, "parentId", externalParentId); // 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 ((objectTreeId == 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 = ObjectTree.GetExternalKeyIndex(configurationId, "objectTreeId"); object[] externalIdArray = new object[1]; externalIdArray[externalKeyIndex] = externalObjectTreeId; externalId0 = externalIdArray[0]; // Call the internal method to complete the operation. MarkThree.Guardian.Core.ObjectTree.Insert(adoTransaction, sqlTransaction, ref rowVersion, childId, parentId, externalId0); } 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.ObjectTreeRow objectTreeRow = objectTreeTable.FindByObjectTreeId(objectTreeId); rowVersion = ((long)(objectTreeRow[objectTreeTable.RowVersionColumn])); // Call the internal method to complete the operation. MarkThree.Guardian.Core.ObjectTree.Update(adoTransaction, sqlTransaction, ref rowVersion, objectTreeId, childId, parentId, externalId0); } // Return values. parameters["rowVersion"] = rowVersion; }
/// <summary>Archives a ObjectTree 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 ObjectTree Table. ServerMarketData.ObjectTreeDataTable objectTreeTable = ServerMarketData.ObjectTree; // Extract the parameters from the command batch. AdoTransaction adoTransaction = parameters["adoTransaction"]; SqlTransaction sqlTransaction = parameters["sqlTransaction"]; object configurationId = parameters["configurationId"].Value; string externalObjectTreeId = parameters["objectTreeId"]; // 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 objectTreeId = ObjectTree.FindRequiredKey(configurationId, "objectTreeId", externalObjectTreeId); // 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.ObjectTreeRow objectTreeRow = objectTreeTable.FindByObjectTreeId(objectTreeId); rowVersion = ((long)(objectTreeRow[objectTreeTable.RowVersionColumn])); // Call the internal method to complete the operation. MarkThree.Guardian.Core.ObjectTree.Archive(adoTransaction, sqlTransaction, rowVersion, objectTreeId); }
/// <summary>Archives a Object 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="objectId">The value for the ObjectId 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 objectId) { // Accessor for the Object Table. ServerMarketData.ObjectDataTable objectTable = ServerMarketData.Object; // Rule #1: Make sure the record exists before updating it. ServerMarketData.ObjectRow objectRow = objectTable.FindByObjectId(objectId); if ((objectRow == null)) { throw new Exception(string.Format("The Object table does not have an element identified by {0}", objectId)); } // Rule #2: Optimistic Concurrency Check if ((objectRow.RowVersion != rowVersion)) { throw new System.Exception("This record is busy. Please try again later."); } // Archive the child records. for (int index = 0; (index < objectRow.GetAccountBaseRows().Length); index = (index + 1)) { ServerMarketData.AccountBaseRow childAccountBaseRow = objectRow.GetAccountBaseRows()[index]; AccountBase.ArchiveChildren(adoTransaction, sqlTransaction, childAccountBaseRow.RowVersion, childAccountBaseRow.AccountBaseId); } for (int index = 0; (index < objectRow.GetBlotterRows().Length); index = (index + 1)) { ServerMarketData.BlotterRow childBlotterRow = objectRow.GetBlotterRows()[index]; Blotter.ArchiveChildren(adoTransaction, sqlTransaction, childBlotterRow.RowVersion, childBlotterRow.BlotterId); } for (int index = 0; (index < objectRow.GetFolderRows().Length); index = (index + 1)) { ServerMarketData.FolderRow childFolderRow = objectRow.GetFolderRows()[index]; Folder.ArchiveChildren(adoTransaction, sqlTransaction, childFolderRow.RowVersion, childFolderRow.FolderId); } for (int index = 0; (index < objectRow.GetIssuerRows().Length); index = (index + 1)) { ServerMarketData.IssuerRow childIssuerRow = objectRow.GetIssuerRows()[index]; Issuer.ArchiveChildren(adoTransaction, sqlTransaction, childIssuerRow.RowVersion, childIssuerRow.IssuerId); } for (int index = 0; (index < objectRow.GetObjectTreeRowsByObjectObjectTreeChildId().Length); index = (index + 1)) { ServerMarketData.ObjectTreeRow childObjectTreeRow = objectRow.GetObjectTreeRowsByObjectObjectTreeChildId()[index]; ObjectTree.Archive(adoTransaction, sqlTransaction, childObjectTreeRow.RowVersion, childObjectTreeRow.ObjectTreeId); } for (int index = 0; (index < objectRow.GetObjectTreeRowsByObjectObjectTreeParentId().Length); index = (index + 1)) { ServerMarketData.ObjectTreeRow childObjectTreeRow = objectRow.GetObjectTreeRowsByObjectObjectTreeParentId()[index]; ObjectTree.Archive(adoTransaction, sqlTransaction, childObjectTreeRow.RowVersion, childObjectTreeRow.ObjectTreeId); } for (int index = 0; (index < objectRow.GetSecurityRows().Length); index = (index + 1)) { ServerMarketData.SecurityRow childSecurityRow = objectRow.GetSecurityRows()[index]; Security.ArchiveChildren(adoTransaction, sqlTransaction, childSecurityRow.RowVersion, childSecurityRow.SecurityId); } for (int index = 0; (index < objectRow.GetUserRows().Length); index = (index + 1)) { ServerMarketData.UserRow childUserRow = objectRow.GetUserRows()[index]; User.ArchiveChildren(adoTransaction, sqlTransaction, childUserRow.RowVersion, childUserRow.UserId); } // Increment the row version rowVersion = ServerMarketData.RowVersion.Increment(); // Delete the record in the ADO database. objectRow[objectTable.RowVersionColumn] = rowVersion; adoTransaction.DataRows.Add(objectRow); objectRow.Delete(); // Archive the record in the SQL database. SqlCommand sqlCommand = new SqlCommand("update \"Object\" set \"IsArchived\" = 1 where \"ObjectId\"=@objectId"); sqlCommand.Connection = sqlTransaction.Connection; sqlCommand.Transaction = sqlTransaction; sqlCommand.Parameters.Add(new SqlParameter("@objectId", SqlDbType.Int, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, objectId)); sqlCommand.ExecuteNonQuery(); }