Exemplo n.º 1
0
        protected override void Execute(UpdateStepContextWithPreconditions <UpdateDbStepType> context)
        {
            foreach (var statement in context.Step.AlternativeStatement)
            {
                _logger.LogInformation("Going to check whether statement for DbType={0} can be handled by this database", statement.DbType);

                if (!_databaseService.CanHandle(statement.DbType) && statement.DbType != "all")
                {
                    _logger.LogInformation("{0} for DbType={1} cannot be handled by this database", context, statement.DbType);

                    continue;
                }

                _transactionProvider.BeginTransaction();

                try
                {
                    foreach (var subStep in _scriptSplitter.SplitScript(statement.Value))
                    {
                        // TODO: add subcontext on script split?
                        _commandHandler.Execute(subStep);
                    }
                    _transactionProvider.CommitTransaction();
                }
                catch (Exception ex)
                {
                    // let's assume that the rollback is low chance to fail so we will not log the
                    // previous error first
                    _transactionProvider.RollbackTransaction();

                    throw new InvalidOperationException($"{context} failed with exception", ex);
                }
            }
        }
Exemplo n.º 2
0
 private IEnumerable <string> FinalizeProcessing(StringBuilder command)
 {
     if (_nextScriptSplitter == null)
     {
         yield return(command.ToString());
     }
     else
     {
         foreach (var result in _nextScriptSplitter.SplitScript(command.ToString()))
         {
             yield return(result);
         }
     }
 }
Exemplo n.º 3
0
 public IEnumerable <string> SplitScript(string script)
 {
     if (_nextScriptSplitter == null)
     {
         yield return(script);
     }
     else
     {
         foreach (var result in _nextScriptSplitter.SplitScript(script))
         {
             yield return(result);
         }
     }
 }