/// <summary>Inserts a ObjectTree record using Metadata Parameters.</summary> /// <param name="parameters">Contains the metadata parameters.</param> public static void Delete(ParameterList parameters) { // Extract the parameters from the command batch. AdoTransaction adoTransaction = parameters["adoTransaction"]; SqlTransaction sqlTransaction = parameters["sqlTransaction"]; long rowVersion = parameters["rowVersion"]; int parentId = parameters["parentId"]; int childId = parameters["childId"]; // Call the internal method to complete the operation. ObjectTree.Delete(adoTransaction, sqlTransaction, rowVersion, parentId, childId); }
/// <summary>Deletes 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 Delete(AdoTransaction adoTransaction, SqlTransaction sqlTransaction, long rowVersion, int objectId) { // Accessor for the Object Table. ServerDataModel.ObjectDataTable objectTable = ServerDataModel.Object; // Rule #1: Make sure the record exists before updating it. ServerDataModel.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."); } // Delete the child records. for (int index = 0; (index < objectRow.GetFolderRows().Length); index = (index + 1)) { ServerDataModel.FolderRow childFolderRow = objectRow.GetFolderRows()[index]; Folder.DeleteChildren(adoTransaction, sqlTransaction, childFolderRow.RowVersion, childFolderRow.FolderId); } for (int index = 0; (index < objectRow.GetAccountRows().Length); index = (index + 1)) { ServerDataModel.AccountRow childAccountRow = objectRow.GetAccountRows()[index]; Account.DeleteChildren(adoTransaction, sqlTransaction, childAccountRow.RowVersion, childAccountRow.AccountId); } for (int index = 0; (index < objectRow.GetBlotterRows().Length); index = (index + 1)) { ServerDataModel.BlotterRow childBlotterRow = objectRow.GetBlotterRows()[index]; Blotter.DeleteChildren(adoTransaction, sqlTransaction, childBlotterRow.RowVersion, childBlotterRow.BlotterId); } for (int index = 0; (index < objectRow.GetBrokerRows().Length); index = (index + 1)) { ServerDataModel.BrokerRow childBrokerRow = objectRow.GetBrokerRows()[index]; Broker.DeleteChildren(adoTransaction, sqlTransaction, childBrokerRow.RowVersion, childBrokerRow.BrokerId); } for (int index = 0; (index < objectRow.GetIssuerRows().Length); index = (index + 1)) { ServerDataModel.IssuerRow childIssuerRow = objectRow.GetIssuerRows()[index]; Issuer.DeleteChildren(adoTransaction, sqlTransaction, childIssuerRow.RowVersion, childIssuerRow.IssuerId); } for (int index = 0; (index < objectRow.GetUserRows().Length); index = (index + 1)) { ServerDataModel.UserRow childUserRow = objectRow.GetUserRows()[index]; User.DeleteChildren(adoTransaction, sqlTransaction, childUserRow.RowVersion, childUserRow.UserId); } for (int index = 0; (index < objectRow.GetModelRows().Length); index = (index + 1)) { ServerDataModel.ModelRow childModelRow = objectRow.GetModelRows()[index]; Model.DeleteChildren(adoTransaction, sqlTransaction, childModelRow.RowVersion, childModelRow.ModelId); } for (int index = 0; (index < objectRow.GetObjectTreeRowsByFKObjectObjectTreeChildId().Length); index = (index + 1)) { ServerDataModel.ObjectTreeRow childObjectTreeRow = objectRow.GetObjectTreeRowsByFKObjectObjectTreeChildId()[index]; ObjectTree.Delete(adoTransaction, sqlTransaction, childObjectTreeRow.RowVersion, childObjectTreeRow.ParentId, childObjectTreeRow.ChildId); } for (int index = 0; (index < objectRow.GetObjectTreeRowsByFKObjectObjectTreeParentId().Length); index = (index + 1)) { ServerDataModel.ObjectTreeRow childObjectTreeRow = objectRow.GetObjectTreeRowsByFKObjectObjectTreeParentId()[index]; ObjectTree.Delete(adoTransaction, sqlTransaction, childObjectTreeRow.RowVersion, childObjectTreeRow.ParentId, childObjectTreeRow.ChildId); } for (int index = 0; (index < objectRow.GetSchemeRows().Length); index = (index + 1)) { ServerDataModel.SchemeRow childSchemeRow = objectRow.GetSchemeRows()[index]; Scheme.DeleteChildren(adoTransaction, sqlTransaction, childSchemeRow.RowVersion, childSchemeRow.SchemeId); } for (int index = 0; (index < objectRow.GetSectorRows().Length); index = (index + 1)) { ServerDataModel.SectorRow childSectorRow = objectRow.GetSectorRows()[index]; Sector.DeleteChildren(adoTransaction, sqlTransaction, childSectorRow.RowVersion, childSectorRow.SectorId); } for (int index = 0; (index < objectRow.GetSecurityRows().Length); index = (index + 1)) { ServerDataModel.SecurityRow childSecurityRow = objectRow.GetSecurityRows()[index]; Security.DeleteChildren(adoTransaction, sqlTransaction, childSecurityRow.RowVersion, childSecurityRow.SecurityId); } // Increment the row version rowVersion = ServerDataModel.RowVersion.Increment(); // Delete the record in the ADO database. objectRow[objectTable.RowVersionColumn] = rowVersion; adoTransaction.DataRows.Add(objectRow); objectRow.Delete(); // Delete the record in the SQL database. SqlCommand sqlCommand = new SqlCommand("update \"Object\" set \"IsDeleted\" = 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(); }