예제 #1
0
        public Dictionary <TableInfo, DiscoveredTable> GetIsolationTables()
        {
            var db = IsolationDatabase.Discover(DataAccessContext.InternalDataProcessing);

            return(TablesToIsolate.ToDictionary(
                       tableInfo => tableInfo,
                       tableInfo => db.ExpectTable(PrimaryKeyCollisionIsolationMutilation.GetIsolationTableName(tableInfo))
                       ));
        }
예제 #2
0
        private void MigrateRecords(ColumnInfo deleteOn, object[] deleteValues)
        {
            var deleteOnColumnName = GetRAWColumnNameFullyQualified(deleteOn);

            using (var con = _raw.Server.GetConnection())
            {
                con.Open();

                //if we are deleting on a child table we need to look up the primary table primary key (e.g. StudyInstanceUID) we should then migrate that data instead (for all tables)
                if (!deleteOn.Equals(_primaryTablePk))
                {
                    deleteValues       = GetPrimaryKeyValuesFor(deleteOn, deleteValues, con);
                    deleteOnColumnName = GetRAWColumnNameFullyQualified(_primaryTablePk);
                }

                //pull all records that we must isolate in all joined tables
                Dictionary <TableInfo, DataTable> toPush = TablesToIsolate.ToDictionary(tableInfo => tableInfo, tableInfo => PullTable(tableInfo, con, deleteOnColumnName, deleteValues));

                //push the results to isolation
                foreach (KeyValuePair <TableInfo, DataTable> kvp in toPush)
                {
                    var toDatabase = IsolationDatabase.Discover(DataAccessContext.DataLoad);
                    var toTable    = toDatabase.ExpectTable(GetIsolationTableName(kvp.Key));

                    using (var bulkInsert = toTable.BeginBulkInsert())
                        bulkInsert.Upload(kvp.Value);
                }

                foreach (TableInfo t in TablesToIsolate.Reverse())
                {
                    DeleteRows(t, deleteOnColumnName, deleteValues, con);
                }

                con.Close();
            }
        }
예제 #3
0
        public void Check(ICheckNotifier notifier)
        {
            //if there is only one or no tables that's fine (mandatory will check for null itself)
            if (TablesToIsolate == null)
            {
                throw new Exception("No tables have been selected");
            }

            //make sure there is only one primary key per table and that it's a string
            foreach (TableInfo t in TablesToIsolate)
            {
                if (t.ColumnInfos.Count(c => c.IsPrimaryKey) != 1)
                {
                    throw new Exception("Table '" + t + "' did not have exactly 1 IsPrimaryKey column");
                }
            }

            //if there are multiple tables then we must know how to join them
            if (TablesToIsolate.Length > 1 && TablesToIsolate.Count(t => t.IsPrimaryExtractionTable) != 1)
            {
                var primaryTables = TablesToIsolate.Where(t => t.IsPrimaryExtractionTable).ToArray();

                notifier.OnCheckPerformed(
                    new CheckEventArgs(
                        $"There are {TablesToIsolate.Length} tables to operate on but {primaryTables.Length} are marked IsPrimaryExtractionTable ({string.Join(",",primaryTables.Select(t=>t.Name))}).  This should be set on a single top level table only e.g. Study",
                        CheckResult.Fail));
            }

            try
            {
                //if there are multiple tables we need to know how to join them on a 1 column to 1 basis
                BuildJoinOrder(true);
            }
            catch (Exception e)
            {
                notifier.OnCheckPerformed(new CheckEventArgs("Failed to build join order", CheckResult.Fail, e));
                return;
            }

            //This is where we put the duplicate records
            var db = IsolationDatabase.Discover(DataAccessContext.DataLoad);

            if (!db.Exists())
            {
                throw new Exception("IsolationDatabase did not exist");
            }

            //Make sure the isolation tables exist and the schema matches RAW
            foreach (var tableInfo in TablesToIsolate)
            {
                var table = db.ExpectTable(GetIsolationTableName(tableInfo));

                if (!table.Exists())
                {
                    bool fix = notifier.OnCheckPerformed(
                        new CheckEventArgs("Isolation table '" + table.GetFullyQualifiedName() + "' did not exist",
                                           CheckResult.Fail, null, "Create isolation table?"));

                    if (fix)
                    {
                        CreateIsolationTable(table, tableInfo);
                    }
                    else
                    {
                        throw new Exception("User rejected change");
                    }
                }
                else
                {
                    ValidateIsolationTableSchema(table, tableInfo, notifier);
                }
            }
        }