Exemplo n.º 1
0
        /// <summary>
        /// Deletes any rows in tiCurrent that are out-of-date (with respect to live) and childless, then updates remaining out-of-date rows with the values from staging.
        /// Out-of-date remaining rows will only be present if they have children which are to be inserted. Any other children will have been deleted in an earlier pass through the recursion (since it starts at the leaves and works upwards).
        /// </summary>
        /// <param name="tiCurrent"></param>
        /// <param name="joinPathToTimeTable">Chain of JoinInfos back to the TimePeriodicity table so we can join to it and recover the effective date of a particular row</param>
        /// <param name="childJoins"></param>
        private void ProcessTable(ITableInfo tiCurrent, List <JoinInfo> joinPathToTimeTable, List <JoinInfo> childJoins)
        {
            var columnSetsToMigrate = _migrationConfiguration.CreateMigrationColumnSetFromTableInfos(new[] { tiCurrent }.ToList(), null, new BackfillMigrationFieldProcessor());
            var columnSet           = columnSetsToMigrate.Single();
            var queryHelper         = new ReverseMigrationQueryHelper(columnSet);
            var mcsQueryHelper      = new MigrationColumnSetQueryHelper(columnSet);

            // Any DELETEs needed?
            DeleteEntriesHavingNoChildren(tiCurrent, joinPathToTimeTable, childJoins, mcsQueryHelper);

            // Update any out-of-date rows that have survived the delete, so they don't overwrite live with stale data. They will only survive the delete if they have children due for insertion into live.
            UpdateOldParentsThatHaveNewChildren(tiCurrent, joinPathToTimeTable, queryHelper, mcsQueryHelper);
        }
Exemplo n.º 2
0
        private void UpdateOldParentsThatHaveNewChildren(ITableInfo tiCurrent, List <JoinInfo> joinPathToTimeTable, ReverseMigrationQueryHelper queryHelper, MigrationColumnSetQueryHelper mcsQueryHelper)
        {
            var update = string.Format(@"WITH 
{0}
UPDATE CurrentTable
SET {1}
FROM 
LiveDataForUpdating LEFT JOIN {2} AS CurrentTable {3}",
                                       GetLiveDataToUpdateStaging(tiCurrent, joinPathToTimeTable),
                                       queryHelper.BuildUpdateClauseForRow("LiveDataForUpdating", "CurrentTable"),
                                       "[" + _dbInfo.GetRuntimeName() + "]..[" + tiCurrent.GetRuntimeName() + "]",
                                       mcsQueryHelper.BuildJoinClause("LiveDataForUpdating", "CurrentTable"));

            using (var connection = (SqlConnection)_dbInfo.Server.GetConnection())
            {
                connection.Open();
                var cmd = new SqlCommand(update, connection);
                cmd.ExecuteNonQuery();
            }
        }