Beispiel #1
0
        private void CheckConflicts(IEnumerable <TransactionObjectState> namespaceJournals)
        {
            AssertNoDirtySelect();

            // Check there isn't a namespace clash with database objects.
            // We need to create a list of all create and drop activity in the
            // Composite from when the transaction started.
            var allDroppedObs = new List <ObjectName>();
            var allCreatedObs = new List <ObjectName>();

            foreach (var nsJournal in namespaceJournals)
            {
                if (nsJournal.CommitId >= CommitId)
                {
                    allDroppedObs.AddRange(nsJournal.DroppedObjects);
                    allCreatedObs.AddRange(nsJournal.CreatedObjects);
                }
            }

            // The list of all dropped objects since this transaction
            // began.
            bool       conflict5    = false;
            ObjectName conflictName = null;
            string     conflictDesc = "";

            foreach (ObjectName droppedOb in allDroppedObs)
            {
                if (ObjectsDropped.Contains(droppedOb))
                {
                    conflict5    = true;
                    conflictName = droppedOb;
                    conflictDesc = "dropped";
                }
            }
            // The list of all created objects since this transaction
            // began.
            foreach (ObjectName createdOb in allCreatedObs)
            {
                if (ObjectsCreated.Contains(createdOb))
                {
                    conflict5    = true;
                    conflictName = createdOb;
                    conflictDesc = "created";
                }
            }
            if (conflict5)
            {
                // Namespace conflict...
                throw new ObjectDuplicatedConflictException(conflictName, conflictDesc);
            }

            // For each journal,
            foreach (TableEventRegistry changeJournal in ChangedTables)
            {
                // The table the change was made to.
                int tableId = changeJournal.TableId;
                // Get the master table with this table id.
                TableSource master = Composite.GetTableSource(tableId);

                // True if the state contains a committed resource with the given name
                bool committedResource = Composite.ContainsVisibleResource(tableId);

                // Check this table is still in the committed tables list.
                if (!CreatedTables.Contains(tableId) && !committedResource)
                {
                    // This table is no longer a committed table, so rollback
                    throw new NonCommittedConflictException(master.TableName);
                }

                // Since this journal was created, check to see if any changes to the
                // tables have been committed since.
                // This will return all journals on the table with the same commit_id
                // or greater.
                var journalsSince = master.FindChangesSinceCmmit(CommitId);

                // For each journal, determine if there's any clashes.
                foreach (TableEventRegistry tableJournal in journalsSince)
                {
                    // This will thrown an exception if a commit classes.
                    changeJournal.TestCommitClash(master.TableInfo, tableJournal);
                }
            }

            // Look at the transaction journal, if a table is dropped that has
            // journal entries since the last commit then we have an exception
            // case.
            foreach (int tableId in DroppedTables)
            {
                // Get the master table with this table id.
                TableSource master = Composite.GetTableSource(tableId);
                // Any journal entries made to this dropped table?
                if (master.FindChangesSinceCmmit(CommitId).Any())
                {
                    // Oops, yes, rollback!
                    throw new DroppedModifiedObjectConflictException(master.TableName);
                }
            }
        }