Exemplo n.º 1
0
        /// <summary>Inserts a OrderTree record using Metadata Parameters.</summary>
        /// <param name="parameters">Contains the metadata parameters.</param>
        public static void Archive(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.
            OrderTree.Archive(adoTransaction, sqlTransaction, rowVersion, parentId, childId);
        }
Exemplo n.º 2
0
        /// <summary>Inserts a OrderTree record using Metadata Parameters.</summary>
        /// <param name="parameters">Contains the metadata parameters.</param>
        public static void Update(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"];
            object         isDeleted      = parameters["isDeleted"].Value;

            // Call the internal method to complete the operation.
            OrderTree.Update(adoTransaction, sqlTransaction, ref rowVersion, parentId, childId, isDeleted);
            // Return values.
            parameters["rowVersion"] = rowVersion;
        }
Exemplo n.º 3
0
        /// <summary>Inserts a OrderTree record using Metadata Parameters.</summary>
        /// <param name="parameters">Contains the metadata parameters.</param>
        public static void Insert(ParameterList parameters)
        {
            // Extract the parameters from the command batch.
            AdoTransaction adoTransaction = parameters["adoTransaction"];
            SqlTransaction sqlTransaction = parameters["sqlTransaction"];
            int            parentId       = parameters["parentId"];
            int            childId        = parameters["childId"];
            object         isDeleted      = parameters["isDeleted"].Value;
            // The rowVersion is passed back to the caller in the event it's needed for additional commands in the batch.
            long rowVersion = long.MinValue;

            // Call the internal method to complete the operation.
            OrderTree.Insert(adoTransaction, sqlTransaction, ref rowVersion, parentId, childId, isDeleted);
            // Return values.
            parameters["rowVersion"] = rowVersion;
        }
Exemplo n.º 4
0
        /// <summary>Archives a Order 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="orderId">The value for the OrderId 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 orderId)
        {
            // Accessor for the Order Table.
            ServerDataModel.OrderDataTable orderTable = ServerDataModel.Order;
            // Rule #1: Make sure the record exists before updating it.
            ServerDataModel.OrderRow orderRow = orderTable.FindByOrderId(orderId);
            if ((orderRow == null))
            {
                throw new Exception(string.Format("The Order table does not have an element identified by {0}", orderId));
            }
            // Rule #2: Optimistic Concurrency Check
            if ((orderRow.RowVersion != rowVersion))
            {
                throw new System.Exception("This record is busy.  Please try again later.");
            }
            // Archive the child records.
            for (int index = 0; (index < orderRow.GetOrderTreeRowsByFKOrderOrderTreeChildId().Length); index = (index + 1))
            {
                ServerDataModel.OrderTreeRow childOrderTreeRow = orderRow.GetOrderTreeRowsByFKOrderOrderTreeChildId()[index];
                OrderTree.Archive(adoTransaction, sqlTransaction, childOrderTreeRow.RowVersion, childOrderTreeRow.ParentId, childOrderTreeRow.ChildId);
            }
            for (int index = 0; (index < orderRow.GetOrderTreeRowsByFKOrderOrderTreeParentId().Length); index = (index + 1))
            {
                ServerDataModel.OrderTreeRow childOrderTreeRow = orderRow.GetOrderTreeRowsByFKOrderOrderTreeParentId()[index];
                OrderTree.Archive(adoTransaction, sqlTransaction, childOrderTreeRow.RowVersion, childOrderTreeRow.ParentId, childOrderTreeRow.ChildId);
            }
            // Increment the row version
            rowVersion = ServerDataModel.RowVersion.Increment();
            // Delete the record in the ADO database.
            orderRow[orderTable.RowVersionColumn] = rowVersion;
            adoTransaction.DataRows.Add(orderRow);
            orderRow.Delete();
            // Archive the record in the SQL database.
            SqlCommand sqlCommand = new SqlCommand("update \"Order\" set \"IsArchived\" = 1 where \"OrderId\"=@orderId");

            sqlCommand.Connection  = sqlTransaction.Connection;
            sqlCommand.Transaction = sqlTransaction;
            sqlCommand.Parameters.Add(new SqlParameter("@orderId", SqlDbType.Int, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, orderId));
            sqlCommand.ExecuteNonQuery();
        }
Exemplo n.º 5
0
 /// <summary>Collects the table lock request(s) for an Update operation</summary>
 /// <param name="adoTransaction">A list of locks required for this operation.</param>
 public static void Archive(AdoTransaction adoTransaction)
 {
     // These table lock(s) are required for the 'Archive' operation.
     adoTransaction.LockRequests.AddWriterLock(ServerDataModel.OrderLock);
     OrderTree.Archive(adoTransaction);
 }