Beispiel #1
0
        private PersistedVersioning GetPersistedVersioning(IDbConnection connection, IDbTransaction transaction, IDbCommandExecutor executor)
        {
            if (_persistedVersioning == null)
            {
                var history = new History(_versioningTableName, _configuration.ProviderInfo.Metadata);
                if (!_versioningTableExists.Value)
                {
                    Debug.Assert(connection != null, "At this point, an upgrade of the versioning table is requested. This always takes part of a running migration step and therefore already has an associated connection (and possibly a transaction).");

                    // execute the boostrap migration to create the versioning table
                    var step = new BootstrapMigrationStep(new BootstrapMigration(_versioningTableName), null);
                    step.Execute(_configuration.ProviderInfo, connection, transaction, MigrationDirection.Up, executor);
                    _versioningTableExists = new Lazy <bool>(() => true); // now, the versioning table exists
                }
                else
                {
                    // load the existing entries from the versioning table
                    IDbConnection c = connection ?? _configuration.OpenConnection();
                    try
                    {
                        history.Load(c, transaction);
                    }
                    finally
                    {
                        if (connection == null) // we had to open a connection ourselves
                        {
                            c.Dispose();
                        }
                    }
                }
                _persistedVersioning = new PersistedVersioning(history);
            }
            Debug.Assert(_persistedVersioning != null);
            return(_persistedVersioning);
        }
Beispiel #2
0
        public void Execute(IRuntimeConfiguration configuration, IVersioning versioning)
        {
            if (versioning == null)
            {
                throw new ArgumentNullException("versioning");
            }

            DateTime start = DateTime.Now;

            long   timestamp = GetTimestamp();
            string tag       = GetTag();

            using (IDbConnection connection = configuration.OpenConnection())
            {
                Debug.Assert(connection.State == ConnectionState.Open);

                using (IDbTransaction transaction = configuration.ConnectionInfo.SupportsTransactions ? connection.BeginTransaction() : null)
                {
                    IDbCommandExecutor executor;
                    using ((executor = configuration.SqlDispatcher.CreateExecutor(string.Format(CultureInfo.InvariantCulture, "Migration.{0}.{1}", Metadata.ModuleName, timestamp))) as IDisposable)
                    {
                        try
                        {
                            Execute(configuration.ProviderInfo, connection, transaction, Metadata.Direction, executor);
                        }
                        catch
                        {
                            Log.Error("An non-recoverable error occurred in migration '{0}'{1}{2} while executing {3}.",
                                      timestamp,
                                      Metadata.ModuleName != MigrationExportAttribute.DefaultModuleName ? " in module '" + Metadata.ModuleName + "'" : string.Empty,
                                      tag,
                                      Metadata.Direction);
                            throw;
                        }

                        // update versioning
                        versioning.Update(Metadata, connection, transaction, executor);
                    }

                    if (transaction != null)
                    {
                        transaction.Commit();
                    }
                }
            }

            Log.Verbose(LogCategory.Performance, "Migration of module '{0}' to {1}{2} took {3}s",
                        Metadata.ModuleName,
                        timestamp,
                        tag,
                        (DateTime.Now - start).TotalSeconds);
        }
Beispiel #3
0
        public void Execute(IRuntimeConfiguration configuration, IVersioning versioning)
        {
            if (versioning == null) throw new ArgumentNullException("versioning");

            DateTime start = DateTime.Now;

            long timestamp = GetTimestamp();
            string tag = GetTag();
            using (IDbConnection connection = configuration.OpenConnection())
            {
                Debug.Assert(connection.State == ConnectionState.Open);

                using (IDbTransaction transaction = configuration.ConnectionInfo.SupportsTransactions ? connection.BeginTransaction() : null)
                {
                    IDbCommandExecutor executor;
                    using ((executor = configuration.SqlDispatcher.CreateExecutor(string.Format(CultureInfo.InvariantCulture, "Migration.{0}.{1}", Metadata.ModuleName, timestamp))) as IDisposable)
                    {
                        try
                        {
                            Execute(configuration.ProviderInfo, connection, transaction, Metadata.Direction, executor);
                        }
                        catch
                        {
                            Log.Error("An non-recoverable error occurred in migration '{0}'{1}{2} while executing {3}.",
                                timestamp,
                                Metadata.ModuleName != MigrationExportAttribute.DefaultModuleName ? " in module '" + Metadata.ModuleName + "'" : string.Empty,
                                tag,
                                Metadata.Direction);
                            throw;
                        }

                        // update versioning
                        versioning.Update(Metadata, connection, transaction, executor);
                    }

                    if (transaction != null)
                    {
                        transaction.Commit();
                    }
                }
            }

            Log.Verbose(LogCategory.Performance, "Migration of module '{0}' to {1}{2} took {3}s",
                Metadata.ModuleName,
                timestamp,
                tag,
                (DateTime.Now - start).TotalSeconds);
        }
Beispiel #4
0
        internal Versioning(IRuntimeConfiguration configuration, TableName versioningTableName)
        {
            _configuration = configuration;
            _versioningTableName = versioningTableName;

            _versioningTableExists = new Lazy<bool>(() =>
            {
                int exists;
                using (IDbConnection connection = configuration.OpenConnection())
                {
                    IDbCommand command = connection.CreateCommand();
                    command.CommandTimeout = 0; // do not timeout; the client is responsible for not causing lock-outs
                    command.CommandText = configuration.ProviderInfo.Provider.ExistsTable(connection.Database, _versioningTableName);
                    Log.Verbose(LogCategory.Sql, command.CommandText);
                    exists = Convert.ToInt32(command.ExecuteScalar(), CultureInfo.InvariantCulture);
                }
                return exists != 0;
            });
        }
Beispiel #5
0
        internal Versioning(IRuntimeConfiguration configuration, TableName versioningTableName)
        {
            _configuration       = configuration;
            _versioningTableName = versioningTableName;

            _versioningTableExists = new Lazy <bool>(() =>
            {
                int exists;
                using (IDbConnection connection = configuration.OpenConnection())
                {
                    IDbCommand command     = connection.CreateCommand();
                    command.CommandTimeout = 0; // do not timeout; the client is responsible for not causing lock-outs
                    command.CommandText    = configuration.ProviderInfo.Provider.ExistsTable(connection.Database, _versioningTableName);
                    Log.Verbose(LogCategory.Sql, command.CommandText);
                    exists = Convert.ToInt32(command.ExecuteScalar(), CultureInfo.InvariantCulture);
                }
                return(exists != 0);
            });
        }