public void Initialize() { // The packages are sorted by their dependencies, so the sql scripts will be executed in the same order. var scripts = _installedPackages.Packages .SelectMany(p => GetScripts(p)) .ToList(); foreach (var script in scripts) { _logger.Trace("Executing script " + script.Package.Id + ": " + script.Name); string sql = File.ReadAllText(script.Path, Encoding.UTF8); var sqlBatches = SqlTransactionBatch.GroupByTransaction(SqlUtility.SplitBatches(sql)); foreach (var sqlBatch in sqlBatches) { _sqlExecuter.ExecuteSql(sqlBatch, sqlBatch.UseTransacion); } } _deployPackagesLogger.Trace("Executed " + scripts.Count + " after-deploy scripts."); }
public void Batches() { var tests = new List <Tuple <string[], string> > { Tuple.Create(new[] { "a", "#a", "a", "a", "a", "#a", "#a" }, "1t, 1n, 3t, 2n"), Tuple.Create(new[] { "a" }, "1t"), Tuple.Create(new[] { "#a" }, "1n"), Tuple.Create(new string[] {}, ""), Tuple.Create(new[] { "#" }, ""), Tuple.Create(new[] { "a", "a", "a#", "a#a" }, "4t"), Tuple.Create(new[] { "#a", "#a" }, "2n"), Tuple.Create(new[] { "a", "a", "#", "a", "a" }, "2t, 2t"), Tuple.Create(new[] { "#a", "#a", "#", "#a", "#a" }, "4n"), }; foreach (var test in tests) { var batches = SqlTransactionBatch.GroupByTransaction(test.Item1.Select(sql => sql.Replace("#", SqlUtility.NoTransactionTag))); string report = TestUtility.Dump(batches, batch => batch.Count + (batch.UseTransacion ? "t" : "n")); Assert.AreEqual(test.Item2, report, "Test: " + TestUtility.Dump(test.Item1) + "."); } }
protected void ApplyChangesToDatabase( List <ConceptApplication> oldApplications, List <NewConceptApplication> newApplications, List <ConceptApplication> toBeRemoved, List <NewConceptApplication> toBeInserted) { var stopwatch = Stopwatch.StartNew(); int estimatedNumberOfQueries = (toBeRemoved.Count() + toBeInserted.Count()) * 3; var sqlScripts = new List <string>(estimatedNumberOfQueries); sqlScripts.AddRange(ApplyChangesToDatabase_Remove(toBeRemoved, oldApplications)); _performanceLogger.Write(stopwatch, "DatabaseGenerator.ApplyChangesToDatabase: Prepared SQL scripts for removing concept applications."); sqlScripts.AddRange(ApplyChangesToDatabase_Unchanged(toBeInserted, newApplications, oldApplications)); _performanceLogger.Write(stopwatch, "DatabaseGenerator.ApplyChangesToDatabase: Prepared SQL scripts for updating unchanged concept applications' metadata."); sqlScripts.AddRange(ApplyChangesToDatabase_Insert(toBeInserted, newApplications)); _performanceLogger.Write(stopwatch, "DatabaseGenerator.ApplyChangesToDatabase: Prepared SQL scripts for inserting concept applications."); foreach (var batchOfScripts in SqlTransactionBatch.GroupByTransaction(sqlScripts.Where(sql => !string.IsNullOrWhiteSpace(sql)))) { _sqlExecuter.ExecuteSql(batchOfScripts, batchOfScripts.UseTransacion); } _performanceLogger.Write(stopwatch, "DatabaseGenerator.ApplyChangesToDatabase: Executed " + sqlScripts.Count + " SQL scripts."); }