Esempio n. 1
0
        public int AddOrder(Order order)
        {
            try
            {
                _db.BeginTransaction();
                // Do transacted updates here
                var poco         = _orderMapper.MapToPoco(order);
                var insertResult = _db.Insert("Orders", "Id", poco);
                var id           = Convert.ToInt32(insertResult);
                foreach (var orderedMeal in poco.OrderedMeals)
                {
                    orderedMeal.OrderId = id;
                    _db.Insert("OrderedMeals", "Id", orderedMeal);
                }

                // Commit
                _db.CompleteTransaction();
                return(id);
            }
            catch (Exception)
            {
                _db.AbortTransaction();
                throw;
            }
        }
Esempio n. 2
0
        public IDatabaseSyntax ExecuteEmbeddedScript(string resourceName)
        {
            var script = _resourceHelper.GetText(resourceName);

            _database.BeginTransaction();
            try {
                foreach (var part in Regex.Split(script, @"[\r\n]+\s*GO\s*[\r\n]+", RegexOptions.IgnoreCase))
                {
                    try {
                        using (var command = _database.CreateCommand(_database.Connection, "")) {
                            // might take quite a bit of time on a large instance
                            command.CommandTimeout = TimeSpan.FromDays(1).Seconds;
                            command.CommandText    = part;
                            command.CommandType    = CommandType.Text;
                            command.ExecuteNonQuery();
                        }
                    }
                    catch (Exception ex) {
                        throw new UmbracoMigrationException("Failed to execute script (" + ex.Message + "):\r\n" + part, ex);
                    }
                }
            }
            catch (Exception) {
                _database.AbortTransaction();
                throw;
            }
            finally {
                _database.CompleteTransaction();
            }

            return(this);
        }
Esempio n. 3
0
        private void DisposeLastScope()
        {
            // figure out completed
            var completed = _completed.HasValue && _completed.Value;

            // deal with database
            var databaseException = false;

            if (_database != null)
            {
                try
                {
                    if (completed)
                    {
                        _database.CompleteTransaction();
                    }
                    else
                    {
                        _database.AbortTransaction();
                    }
                }
                catch
                {
                    databaseException = true;
                    throw;
                }
                finally
                {
                    _database.Dispose();
                    _database = null;

                    if (databaseException)
                    {
                        RobustExit(false, true);
                    }
                }
            }

            RobustExit(completed, false);
        }