コード例 #1
0
 /// <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.
     ServerDataModel.ObjectTreeDataTable objectTreeTable = ServerDataModel.ObjectTree;
     // Extract the parameters from the command batch.
     AdoTransaction adoTransaction = parameters["adoTransaction"];
     SqlTransaction sqlTransaction = parameters["sqlTransaction"];
     object configurationId = parameters["configurationId"].Value;
     string externalParentId = parameters["parentId"];
     string externalChildId = parameters["childId"];
     // The row versioning is largely disabled for external operations.
     long rowVersion = long.MinValue;
     // Resolve External Identifiers
     int parentId = Object.FindRequiredKey(configurationId, "parentId", externalParentId);
     int childId = Object.FindRequiredKey(configurationId, "childId", externalChildId);
     // Find the record using the unique identifier.  If it doesn't exist, it will be inserted, if it does exist,
     // it will be updated.
     ServerDataModel.ObjectTreeRow objectTreeRow = objectTreeTable.FindByParentIdChildId(parentId, childId);
     if ((objectTreeRow == null))
     {
         // Call the internal 'Insert' method to complete the operation.
         MarkThree.Quasar.Core.ObjectTree.Insert(adoTransaction, sqlTransaction, ref rowVersion, parentId, childId);
     }
     else
     {
         // This will bypass the optimistic concurrency checking required by the internal method.
         rowVersion = ((long)(objectTreeRow[objectTreeTable.RowVersionColumn]));
     }
     // Return values
     parameters["rowVersion"] = rowVersion;
 }
コード例 #2
0
ファイル: ObjectTree.cs プロジェクト: DonaldAirey/quasar
        /// <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="parentId">The value for the ParentId column.</param>
        /// <param name="childId">The value for the ChildId 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 parentId, int childId)
        {
            // Accessor for the ObjectTree Table.
            ServerDataModel.ObjectTreeDataTable objectTreeTable = ServerDataModel.ObjectTree;
            // Rule #1: Make sure the record exists before updating it.
            ServerDataModel.ObjectTreeRow objectTreeRow = objectTreeTable.FindByParentIdChildId(parentId, childId);
            if ((objectTreeRow == null))
            {
                throw new Exception(string.Format("The ObjectTree table does not have an element identified by {0}{0}", parentId, childId));
            }
            // 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 = ServerDataModel.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 \"ParentId\"=@parentId and \"ChildId\"" +
                                                   "=@childId");

            sqlCommand.Connection  = sqlTransaction.Connection;
            sqlCommand.Transaction = sqlTransaction;
            sqlCommand.Parameters.Add(new SqlParameter("@parentId", SqlDbType.Int, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, parentId));
            sqlCommand.Parameters.Add(new SqlParameter("@childId", SqlDbType.Int, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, childId));
            sqlCommand.ExecuteNonQuery();
        }
コード例 #3
0
 /// <summary>Deletes a ObjectTree record using Metadata Parameters.</summary>
 /// <param name="transaction">Contains the parameters and exceptions for this command.</param>
 public static void Delete(ParameterList parameters)
 {
     // Accessor for the ObjectTree Table.
     ServerDataModel.ObjectTreeDataTable objectTreeTable = ServerDataModel.ObjectTree;
     // Extract the parameters from the command batch.
     AdoTransaction adoTransaction = parameters["adoTransaction"];
     SqlTransaction sqlTransaction = parameters["sqlTransaction"];
     object configurationId = parameters["configurationId"].Value;
     string externalParentId = parameters["parentId"];
     string externalChildId = parameters["childId"];
     // Resolve External Identifiers
     int parentId = Object.FindRequiredKey(configurationId, "parentId", externalParentId);
     int childId = Object.FindRequiredKey(configurationId, "childId", externalChildId);
     // The row versioning is largely disabled for external operations.
     long rowVersion = long.MinValue;
     // 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.
     ServerDataModel.ObjectTreeRow objectTreeRow = objectTreeTable.FindByParentIdChildId(parentId, childId);
     rowVersion = ((long)(objectTreeRow[objectTreeTable.RowVersionColumn]));
     // Call the internal method to complete the operation.
     MarkThree.Quasar.Core.ObjectTree.Delete(adoTransaction, sqlTransaction, rowVersion, parentId, childId);
 }