/// <summary>Archives a Folder 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="folderId">The value for the FolderId column.</param> /// <param name="archive">true to archive the object, false to unarchive it.</param> public new static void Archive(AdoTransaction adoTransaction, SqlTransaction sqlTransaction, long rowVersion, int folderId) { // Accessor for the Folder Table. ServerMarketData.FolderDataTable folderTable = ServerMarketData.Folder; // Rule #1: Make sure the record exists before updating it. ServerMarketData.FolderRow folderRow = folderTable.FindByFolderId(folderId); if ((folderRow == null)) { throw new Exception(string.Format("The Folder table does not have an element identified by {0}", folderId)); } // Rule #2: Optimistic Concurrency Check if ((folderRow.RowVersion != rowVersion)) { throw new System.Exception("This record is busy. Please try again later."); } // Delete the base class record. Note that optimistic concurrency is only used // by the top level type in the hierarchy, it is bypassed after you pass the first test. long baseRowVersion = folderRow.ObjectRow.RowVersion; Object.Archive(adoTransaction, sqlTransaction, baseRowVersion, folderId); }
/// <summary>Archives a Folder record using Metadata Parameters.</summary> /// <param name="transaction">Contains the parameters and exceptions for this command.</param> public new static void Archive(ParameterList parameters) { // Accessor for the Folder Table. ServerMarketData.FolderDataTable folderTable = ServerMarketData.Folder; // Extract the parameters from the command batch. AdoTransaction adoTransaction = parameters["adoTransaction"]; SqlTransaction sqlTransaction = parameters["sqlTransaction"]; object configurationId = parameters["configurationId"].Value; string externalFolderId = parameters["folderId"]; // 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; // Find the internal identifier using the primary key elements. // identifier is used to determine if a record exists with the same key. int folderId = Folder.FindRequiredKey(configurationId, "folderId", externalFolderId); // This disables the concurrency checking logic by finding the current row version and passing it to the // internal method. ServerMarketData.FolderRow folderRow = folderTable.FindByFolderId(folderId); rowVersion = ((long)(folderRow[folderTable.RowVersionColumn])); // Call the internal method to complete the operation. MarkThree.Guardian.Core.Folder.Archive(adoTransaction, sqlTransaction, rowVersion, folderId); }
/// <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(); }