public SqlEtlTestScriptResult RunTest(DocumentsOperationContext context, IEnumerable <SqlTableWithRecords> toWrite, bool performRolledBackTransaction) { var summaries = new List <TableQuerySummary>(); if (performRolledBackTransaction) { try { using (var writer = new RelationalDatabaseWriter(this, Database)) { foreach (var records in toWrite) { var commands = new List <DbCommand>(); writer.Write(records, commands, CancellationToken); summaries.Add(TableQuerySummary.GenerateSummaryFromCommands(records.TableName, commands)); } writer.Rollback(); } } catch (Exception e) { Statistics.RecordLoadError(e.ToString(), documentId: null, count: 1); } } else { var simulatedWriter = new RelationalDatabaseWriterSimulator(Configuration); foreach (var records in toWrite) { var commands = simulatedWriter.SimulateExecuteCommandText(records, CancellationToken).Select(x => new TableQuerySummary.CommandData { CommandText = x }).ToArray(); summaries.Add(new TableQuerySummary { TableName = records.TableName, Commands = commands }); } } return(new SqlEtlTestScriptResult { TransformationErrors = Statistics.TransformationErrorsInCurrentBatch.Errors.ToList(), LoadErrors = Statistics.LastLoadErrorsInCurrentBatch.Errors.ToList(), SlowSqlWarnings = Statistics.LastSlowSqlWarningsInCurrentBatch.Statements.ToList(), Summary = summaries }); }
public SqlEtlSimulationResult Simulate(SimulateSqlEtl simulateSqlEtl, DocumentsOperationContext context, IEnumerable <SqlTableWithRecords> toWrite) { var summaries = new List <TableQuerySummary>(); if (simulateSqlEtl.PerformRolledBackTransaction) { using (var writer = new RelationalDatabaseWriter(this, Database)) { foreach (var records in toWrite) { var commands = new List <DbCommand>(); writer.Write(records, commands, CancellationToken); summaries.Add(TableQuerySummary.GenerateSummaryFromCommands(records.TableName, commands)); } writer.Rollback(); } } else { var simulatedwriter = new RelationalDatabaseWriterSimulator(Configuration); foreach (var records in toWrite) { var commands = simulatedwriter.SimulateExecuteCommandText(records, CancellationToken).Select(x => new TableQuerySummary.CommandData { CommandText = x }).ToArray(); summaries.Add(new TableQuerySummary { TableName = records.TableName, Commands = commands }); } } return(new SqlEtlSimulationResult { LastAlert = Statistics.LastAlert, Summary = summaries }); }