/// <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>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>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>Initializes the static elements of an Object.</summary> static ObjectTree() { // The table must be locked before the indices can be read into an accelerator array. ServerMarketData.ObjectTreeLock.AcquireReaderLock(System.Threading.Timeout.Infinite); // Accessor for the ObjectTree Table. ServerMarketData.ObjectTreeDataTable objectTreeTable = ServerMarketData.ObjectTree; // 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. ObjectTree.externalKeyArray = new DataView[] { objectTreeTable.KeyObjectTreeExternalId0}; // The table must be released after the array is constructed. ServerMarketData.ObjectTreeLock.ReleaseReaderLock(); }
/// <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>Finds a a ObjectTree 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 ObjectTree Table. ServerMarketData.ObjectTreeDataTable objectTreeTable = ServerMarketData.ObjectTree; // 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 = ObjectTree.GetExternalKeyIndex(configurationId, parameterId); System.Data.DataView externalKeyView = ObjectTree.externalKeyArray[externalKeyIndex]; int recordIndex = externalKeyView.Find(new object[] { externalId}); if ((recordIndex == -1)) { return int.MinValue; } return ((int)(externalKeyView[recordIndex].Row[objectTreeTable.ObjectTreeIdColumn])); }
/// <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); }