示例#1
0
        public void Synchronize(ICheckNotifier notifier)
        {
            //there are no columns going to dump (because constructor didnt give us a server)
            if (_externalDatabaseServer == null)
            {
                return;
            }

            IdentifierDumperSynchronizer synchronizer = new IdentifierDumperSynchronizer(this, _externalDatabaseServer);

            synchronizer.Synchronize(notifier);
        }
示例#2
0
        public void Check(ICheckNotifier notifier)
        {
            var columnsToDump = TableInfo.PreLoadDiscardedColumns;
            var duplicates    = columnsToDump.GroupBy(k => k.GetRuntimeName()).Where(c => c.Count() > 1).ToArray();

            foreach (var duplicate in duplicates)
            {
                notifier.OnCheckPerformed(
                    new CheckEventArgs(
                        "There are " + duplicate.Count() + " PreLoadDiscardedColumns called '" + duplicate.Key + "' for TableInfo '" +
                        TableInfo + "'", CheckResult.Fail));
            }

            //columns that exist in live but are supposedly dropped during load
            var liveColumns = TableInfo.ColumnInfos.ToArray();


            foreach (var preLoadDiscardedColumn in columnsToDump)
            {
                var match = liveColumns.FirstOrDefault(c => c.GetRuntimeName().Equals(preLoadDiscardedColumn.GetRuntimeName()));

                if (match != null)
                {
                    if (preLoadDiscardedColumn.Destination != DiscardedColumnDestination.Dilute)
                    {
                        notifier.OnCheckPerformed(new CheckEventArgs("TableInfo " + TableInfo + " declares both a PreLoadDiscardedColumn '" + preLoadDiscardedColumn + "' and a ColumnInfo with the same name", CheckResult.Fail));
                        return;
                    }

                    if (match.IsPrimaryKey && preLoadDiscardedColumn.Destination == DiscardedColumnDestination.Dilute)
                    {
                        notifier.OnCheckPerformed(new CheckEventArgs("TableInfo " + TableInfo + " declares a PreLoadDiscardedColumn '" + preLoadDiscardedColumn + "' but there is a matching ColumnInfo of the same name which IsPrimaryKey", CheckResult.Fail));
                        return;
                    }
                }
            }

            if (!HasAtLeastOneColumnToStoreInDump)
            {
                notifier.OnCheckPerformed(new CheckEventArgs("No columns require dumping from TableInfo " + _tableInfo + " so checking is not needed", CheckResult.Success, null));
                return;
            }

            var tables = _dumpDatabase.DiscoverTables(false);

            bool stagingTableFound = tables.Any(t => t.GetRuntimeName().Equals(GetStagingRuntimeName()));

            ConfirmDependencies(_dumpDatabase, notifier);

            //detect ongoing loads/dirty cleanup
            if (stagingTableFound)
            {
                bool shouldDrop = notifier.OnCheckPerformed(new CheckEventArgs("STAGING table found " + GetStagingRuntimeName() + " in ANO database",
                                                                               CheckResult.Fail, null, "Drop table " + GetStagingRuntimeName()));

                if (shouldDrop)
                {
                    DropStaging();
                }
            }
            else
            {
                notifier.OnCheckPerformed(new CheckEventArgs("Confirmed absence of Table  " + GetStagingRuntimeName() + "(this will be created during load)", CheckResult.Success, null));
            }

            //confirm that there is a ColumnInfo for every Dilute column
            var columnInfos = _tableInfo.ColumnInfos.ToArray();

            foreach (var dilutedColumn in ColumnsToRouteToSomewhereElse.Where(c => c.Destination == DiscardedColumnDestination.Dilute))
            {
                if (!columnInfos.Any(c => c.GetRuntimeName().Equals(dilutedColumn.RuntimeColumnName)))
                {
                    notifier.OnCheckPerformed(new CheckEventArgs("PreLoadDiscardedColumn called " + dilutedColumn.GetRuntimeName() +
                                                                 " is marked for Dilution but does not appear in the TableInfo object's ColumnInfo collection.  Diluted columns must appear both in the LIVE database (in diluted state) and in IdentifierDump (in pristene state) which means that for every PreLoadDiscardedColumn which has the destination Dilution, there must be a ColumnInfo with the same name in LIVE", CheckResult.Fail, null));
                }
            }

            //if there are any columns due to be stored in the Identifier dump
            if (ColumnsToRouteToSomewhereElse.Any(c => c.GoesIntoIdentifierDump()))
            {
                //see if table exists
                IdentifierDumperSynchronizer synchronizer = new IdentifierDumperSynchronizer(this, _externalDatabaseServer);
                synchronizer.Synchronize(notifier);

                //make sure there is a backup trigger enabled on the Identifier dump so that we version updates
                TriggerChecks triggerChecker = new TriggerChecks(_dumpDatabase.ExpectTable(GetRuntimeName()));  // primary keys - ignoring transforms for ANO
                triggerChecker.Check(notifier);
            }
        }