/// <summary> /// Generate the data. /// </summary> /// <remarks> /// 1. Add columns @DF1 and @DF2 to the table. /// @DF1 is a primary key. /// @DF2 contains the same values as @DF1, but scrambled. /// 2. For each primary key relationship, update the fk by binding @DF2 of the parent table to the @DF1 of the referenced table. /// 3. Drop the primary keys. /// </remarks> public ISql Generate() { ISql sql = null; _Owner._Logger.LogInformation(Messages.LOG_INF_STARTED, nameof(Generate)); try { sql = _Owner._SqlFactory.CreateTemporaryDatabase(DEFAULT_DATABASENAME); var tablePrescriptions = _Owner._Project.Prescriptor.TablePrescriptions .AsParallel() .WithDegreeOfParallelism(2); var tableDescriptions = tablePrescriptions.Select(t => t.TableDescription); var foreignKeyDescriptions = tableDescriptions.SelectMany(tableDescription => tableDescription.ForeignKeyDescriptions); tablePrescriptions.ForAll(_ => CreateTable(sql, _)); tablePrescriptions.ForAll(_ => FillTable(sql, _)); tableDescriptions.ForAll(_ => FillAuxiliaryColumns(sql, _)); foreignKeyDescriptions.ForAll(_ => UpdateForeignKeys(sql, _)); DropAuxiliaryColumns(sql); return(sql); } catch (Exception exception) { _Owner._Logger.LogError(exception, Messages.LOG_ERR_FAILED, nameof(Generate)); sql?.Dispose(); throw; } finally { _Owner._Logger.LogInformation(Messages.LOG_INF_FINISHED, nameof(Generate)); } }