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 }); }
protected override void LoadInternal(IEnumerable <SqlTableWithRecords> records, JsonOperationContext context) { using (var writer = new RelationalDatabaseWriter(this, Database)) { foreach (var table in records) { var stats = writer.Write(table, null, CancellationToken); LogStats(stats, table); } writer.Commit(); } }
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 }); }
protected override int LoadInternal(IEnumerable <SqlTableWithRecords> records, DocumentsOperationContext context) { var count = 0; using (var writer = new RelationalDatabaseWriter(this, Database)) { foreach (var table in records) { var stats = writer.Write(table, null, CancellationToken); LogStats(stats, table); count += stats.DeletedRecordsCount + stats.InsertedRecordsCount; } writer.Commit(); } return(count); }