コード例 #1
0
 public override void Generate(
     DropDatabaseOperation dropDatabaseOperation,
     IndentedStringBuilder stringBuilder)
 {
     throw new NotSupportedException(Strings.FormatMigrationOperationNotSupported(
                                         GetType(), dropDatabaseOperation.GetType()));
 }
コード例 #2
0
        public void Create_and_initialize_operation()
        {
            var dropDatabaseOperation = new DropDatabaseOperation("MyDatabase");

            Assert.Equal("MyDatabase", dropDatabaseOperation.DatabaseName);
            Assert.True(dropDatabaseOperation.IsDestructiveChange);
        }
コード例 #3
0
        public virtual void Generate(
            [NotNull] DropDatabaseOperation operation,
            [CanBeNull] IModel model,
            [NotNull] SqlBatchBuilder builder)
        {
            Check.NotNull(operation, nameof(operation));
            Check.NotNull(builder, nameof(builder));

            var dbName = _sql.DelimitIdentifier(operation.Name);

            builder
            // TODO: The following revokes connection only for the public role, what about other connecting roles?
            .Append("REVOKE CONNECT ON DATABASE ")
            .Append(dbName)
            .Append(" FROM PUBLIC")
            .EndBatch()
            // TODO: For PG <= 9.1, the column name is prodpic, not pid (see http://stackoverflow.com/questions/5408156/how-to-drop-a-postgresql-database-if-there-are-active-connections-to-it)
            .Append(
                "SELECT pg_terminate_backend(pg_stat_activity.pid) FROM pg_stat_activity WHERE pg_stat_activity.datname = '")
            .Append(dbName)
            .Append("'")
            .EndBatch()
            .Append("DROP DATABASE ")
            .Append(dbName);
        }
コード例 #4
0
        public void constructor_should_initialize_subject()
        {
            var subject = new DropDatabaseOperation(_databaseNamespace, _messageEncoderSettings);

            subject.DatabaseNamespace.Should().BeSameAs(_databaseNamespace);
            subject.MessageEncoderSettings.Should().BeSameAs(_messageEncoderSettings);
        }
コード例 #5
0
        // methods
        public Task DropAsync(TimeSpan?timeout, CancellationToken cancellationToken)
        {
            var messageEncoderSettings = GetMessageEncoderSettings();
            var operation = new DropDatabaseOperation(_databaseNamespace, messageEncoderSettings);

            return(ExecuteWriteOperation(operation, timeout, cancellationToken));
        }
コード例 #6
0
 private void ClearData(ICluster cluster)
 {
     using (var binding = new WritableServerBinding(cluster, NoCoreSession.NewHandle()))
     {
         var commandOp = new DropDatabaseOperation(_collection.DatabaseNamespace, _messageEncoderSettings);
         commandOp.Execute(binding, CancellationToken.None);
     }
 }
コード例 #7
0
 private async Task ClearData(ICluster cluster)
 {
     using (var binding = new WritableServerBinding(cluster))
     {
         var commandOp = new DropDatabaseOperation(_collection.DatabaseNamespace, _messageEncoderSettings);
         await commandOp.ExecuteAsync(binding, CancellationToken.None);
     }
 }
コード例 #8
0
        public void Generate_with_drop_database_not_supported()
        {
            var operation = new DropDatabaseOperation("Bronies");

            Assert.Equal(
                Strings.FormatMigrationOperationNotSupported(typeof(SQLiteMigrationOperationSqlGenerator), operation.GetType()),
                Assert.Throws <NotSupportedException>(() => Generate(operation)).Message);
        }
コード例 #9
0
        public virtual void Generate([NotNull] DropDatabaseOperation dropDatabaseOperation, [NotNull] IndentedStringBuilder stringBuilder, bool generateIdempotentSql)
        {
            Check.NotNull(dropDatabaseOperation, "dropDatabaseOperation");

            stringBuilder
            .Append("DROP DATABASE ")
            .Append(DelimitIdentifier(dropDatabaseOperation.DatabaseName));
        }
コード例 #10
0
 private async static Task ClearData(ICluster cluster)
 {
     using (var binding = new WritableServerBinding(cluster))
     {
         var commandOp = new DropDatabaseOperation(_database);
         await commandOp.ExecuteAsync(binding);
     }
 }
コード例 #11
0
        public virtual void Generate([NotNull] DropDatabaseOperation dropDatabaseOperation, [NotNull] SqlBatchBuilder batchBuilder)
        {
            Check.NotNull(dropDatabaseOperation, "dropDatabaseOperation");
            Check.NotNull(batchBuilder, "batchBuilder");

            batchBuilder
            .Append("DROP DATABASE ")
            .Append(DelimitIdentifier(dropDatabaseOperation.DatabaseName));
        }
コード例 #12
0
        // methods
        private void DropDatabase()
        {
            var operation = new DropDatabaseOperation(__databaseNamespace, __messageEncoderSettings);

            using (var binding = GetReadWriteBinding())
            {
                operation.Execute(binding);
            }
        }
コード例 #13
0
        // methods
        private static void DropDatabase()
        {
            var operation = new DropDatabaseOperation(__databaseNamespace, __messageEncoderSettings);

            using (var binding = GetReadWriteBinding())
            {
                operation.ExecuteAsync(binding, CancellationToken.None).GetAwaiter().GetResult();
            }
        }
コード例 #14
0
        /// <summary>
        /// Drops a database.
        /// </summary>
        /// <param name="databaseName">The name of the database to be dropped.</param>
        /// <returns>A <see cref="CommandResult"/>.</returns>
        public virtual CommandResult DropDatabase(string databaseName)
        {
            var databaseNamespace      = new DatabaseNamespace(databaseName);
            var messageEncoderSettings = GetMessageEncoderSettings();
            var operation = new DropDatabaseOperation(databaseNamespace, messageEncoderSettings);
            var response  = ExecuteWriteOperation(operation);

            return(new CommandResult(response));
        }
コード例 #15
0
        private static void DropDatabase()
        {
            var operation = new DropDatabaseOperation(__databaseNamespace.Value, __messageEncoderSettings);

            using (var session = StartSession())
                using (var binding = CreateReadWriteBinding(session))
                {
                    operation.Execute(binding, CancellationToken.None);
                }
        }
コード例 #16
0
        // public methods
        /// <inheritdoc/>
        public sealed override async Task DropDatabaseAsync(string name, CancellationToken cancellationToken = default(CancellationToken))
        {
            var messageEncoderSettings = GetMessageEncoderSettings();
            var operation = new DropDatabaseOperation(new DatabaseNamespace(name), messageEncoderSettings);

            using (var binding = new WritableServerBinding(_cluster))
            {
                await _operationExecutor.ExecuteWriteOperationAsync(binding, operation, cancellationToken).ConfigureAwait(false);
            }
        }
コード例 #17
0
        public void Dispatches_visitor()
        {
            var dropDatabaseOperation = new DropDatabaseOperation("MyDatabase");
            var mockVisitor           = new Mock <MigrationOperationSqlGenerator>(new RelationalTypeMapper());
            var builder = new Mock <IndentedStringBuilder>();

            dropDatabaseOperation.GenerateSql(mockVisitor.Object, builder.Object);

            mockVisitor.Verify(g => g.Generate(dropDatabaseOperation, builder.Object), Times.Once());
        }
コード例 #18
0
        public override void Generate([NotNull] DropDatabaseOperation dropDatabaseOperation, [NotNull] IndentedStringBuilder stringBuilder)
        {
            Check.NotNull(dropDatabaseOperation, "dropDatabaseOperation");
            Check.NotNull(stringBuilder, "stringBuilder");

            stringBuilder
            .Append("DropDatabase(")
            .Append(GenerateLiteral(dropDatabaseOperation.DatabaseName))
            .Append(")");
        }
コード例 #19
0
        public void Generate_when_drop_database_operation()
        {
            var operation = new DropDatabaseOperation("MyDatabase");

            Assert.Equal(
                @"DropDatabase(""MyDatabase"")",
                CSharpMigrationCodeGenerator.Generate(operation));

            GenerateAndValidateCode(operation);
        }
コード例 #20
0
        // public methods
        /// <inheritdoc/>
        public sealed override void DropDatabase(string name, CancellationToken cancellationToken = default(CancellationToken))
        {
            var messageEncoderSettings = GetMessageEncoderSettings();
            var operation = new DropDatabaseOperation(new DatabaseNamespace(name), messageEncoderSettings);

            using (var binding = new WritableServerBinding(_cluster))
            {
                _operationExecutor.ExecuteWriteOperation(binding, operation, cancellationToken);
            }
        }
コード例 #21
0
        public void Dispatches_visitor()
        {
            var dropDatabaseOperation = new DropDatabaseOperation("MyDatabase");
            var mockVisitor           = MigrationsTestHelpers.MockSqlGenerator();
            var builder = new Mock <SqlBatchBuilder>();

            dropDatabaseOperation.GenerateSql(mockVisitor.Object, builder.Object);

            mockVisitor.Verify(g => g.Generate(dropDatabaseOperation, builder.Object), Times.Once());
        }
コード例 #22
0
        private static void DropDatabase()
        {
            var operation = new DropDatabaseOperation(__databaseNamespace, __messageEncoderSettings);

            var session = CoreTestConfiguration.StartSession();

            using (var binding = GetReadWriteBinding(session))
            {
                operation.Execute(binding, CancellationToken.None);
            }
        }
コード例 #23
0
ファイル: MongoClient.cs プロジェクト: LJM74520/nice
        /// <inheritdoc/>
        public sealed override Task DropDatabaseAsync(IClientSessionHandle session, string name, CancellationToken cancellationToken = default(CancellationToken))
        {
            Ensure.IsNotNull(session, nameof(session));
            var messageEncoderSettings = GetMessageEncoderSettings();
            var operation = new DropDatabaseOperation(new DatabaseNamespace(name), messageEncoderSettings)
            {
                WriteConcern = _settings.WriteConcern
            };

            return(ExecuteWriteOperationAsync(session, operation, cancellationToken));
        }
コード例 #24
0
        private CommandResult DropDatabase(IClientSessionHandle session, string databaseName)
        {
            var databaseNamespace      = new DatabaseNamespace(databaseName);
            var messageEncoderSettings = GetMessageEncoderSettings();
            var operation = new DropDatabaseOperation(databaseNamespace, messageEncoderSettings)
            {
                WriteConcern = _settings.WriteConcern
            };
            var response = ExecuteWriteOperation(session, operation);

            return(new CommandResult(response));
        }
        protected override void Given()
        {
            // Ensure database exists
            var op = new BulkInsertOperation(
                new CollectionNamespace(DatabaseNamespace, "temp"),
                new [] { new InsertRequest(new BsonDocument("x", 1)) },
                MessageEncoderSettings);

            ExecuteOperation(op);

            _subject = new DropDatabaseOperation(DatabaseNamespace, MessageEncoderSettings);
        }
        protected override void Given()
        {
            // Ensure database exists
            var op = new BulkInsertOperation(
                new CollectionNamespace(DatabaseNamespace, "temp"), 
                new [] { new InsertRequest(new BsonDocument("x", 1)) },
                MessageEncoderSettings);

            ExecuteOperation(op);

            _subject = new DropDatabaseOperation(DatabaseNamespace, MessageEncoderSettings);
        }
コード例 #27
0
        public void CreateCommand_should_return_expected_result()
        {
            var subject = new DropDatabaseOperation(_databaseNamespace, _messageEncoderSettings);
            var expectedResult = new BsonDocument
            {
                { "dropDatabase", 1 }
            };

            var result = subject.CreateCommand();

            result.Should().Be(expectedResult);
        }
コード例 #28
0
        private void DropDatabase()
        {
            var operation = new DropDatabaseOperation(
                new DatabaseNamespace(__databaseName),
                new MessageEncoderSettings());

            using (var binding = new WritableServerBinding(__cluster))
            {
                operation.ExecuteAsync(binding, TimeSpan.FromSeconds(10), CancellationToken.None)
                .GetAwaiter()
                .GetResult();
            }
        }
コード例 #29
0
        public async Task ExecuteAsync_should_return_expected_result()
        {
            using (var binding = CoreTestConfiguration.GetReadWriteBinding())
            {
                EnsureDatabaseExists(binding);
                var subject = new DropDatabaseOperation(_databaseNamespace, _messageEncoderSettings);

                var result = await subject.ExecuteAsync(binding, CancellationToken.None);

                result["ok"].ToBoolean().Should().BeTrue();
                result["dropped"].ToString().Should().Be(_databaseNamespace.DatabaseName);
            }
        }
コード例 #30
0
        public virtual void Generate(
            [NotNull] DropDatabaseOperation operation,
            [CanBeNull] IModel model,
            [NotNull] SqlBatchBuilder builder)
        {
            Check.NotNull(operation, nameof(operation));
            Check.NotNull(builder, nameof(builder));

            builder
            .Append("IF SERVERPROPERTY('EngineEdition') <> 5 EXECUTE sp_executesql N'ALTER DATABASE ")
            .Append(_sql.DelimitIdentifier(operation.Name))
            .Append(" SET SINGLE_USER WITH ROLLBACK IMMEDIATE'")
            .EndBatch()
            .Append("DROP DATABASE ")
            .Append(_sql.DelimitIdentifier(operation.Name));
        }
コード例 #31
0
        public override void Generate(DropDatabaseOperation dropDatabaseOperation, SqlBatchBuilder batchBuilder)
        {
            batchBuilder
            .Append("IF SERVERPROPERTY('EngineEdition') <> 5 EXECUTE sp_executesql N")
            .Append(
                GenerateLiteral(
                    string.Concat(
                        "ALTER DATABASE ",
                        DelimitIdentifier(dropDatabaseOperation.DatabaseName),
                        " SET SINGLE_USER WITH ROLLBACK IMMEDIATE")));

            batchBuilder.EndBatch();

            base.Generate(dropDatabaseOperation, batchBuilder);

            batchBuilder.EndBatch();
        }
コード例 #32
0
        public override void Generate(DropDatabaseOperation dropDatabaseOperation, IndentedStringBuilder stringBuilder, bool generateIdempotentSql)
        {
            Check.NotNull(dropDatabaseOperation, "dropDatabaseOperation");
            Check.NotNull(stringBuilder, "stringBuilder");

            if (generateIdempotentSql)
            {
                GenerateDatabasePresenceCheck(dropDatabaseOperation.DatabaseName, negative: false, builder: stringBuilder);

                using (stringBuilder.AppendLine().Indent())
                {
                    base.Generate(dropDatabaseOperation, stringBuilder, generateIdempotentSql: false);
                }
            }
            else
            {
                base.Generate(dropDatabaseOperation, stringBuilder, generateIdempotentSql);
            }
        }
コード例 #33
0
        // methods
        private static void DropDatabase()
        {
            var operation = new DropDatabaseOperation(__databaseNamespace, __messageEncoderSettings);

            using (var binding = GetReadWriteBinding())
            {
                operation.ExecuteAsync(binding, CancellationToken.None).GetAwaiter().GetResult();
            }
        }
コード例 #34
0
        public void ExecuteAsync_should_throw_when_binding_is_null()
        {
            var subject = new DropDatabaseOperation(_databaseNamespace, _messageEncoderSettings);

            Func<Task> action = () => subject.ExecuteAsync(null, CancellationToken.None);

            action.ShouldThrow<ArgumentNullException>().And.ParamName.Should().Be("binding");
        }
コード例 #35
0
 public Task DropDatabaseAsync(IWriteBinding binding)
 {
     var operation = new DropDatabaseOperation(_collectionNamespace.DatabaseNamespace, _messageEncoderSettings);
     return operation.ExecuteAsync(binding, CancellationToken.None);
 }
コード例 #36
0
 public override void Generate(
     DropDatabaseOperation dropDatabaseOperation,
     IndentedStringBuilder stringBuilder)
 {
     throw new NotSupportedException();
 }
コード例 #37
0
ファイル: Program.cs プロジェクト: Nakro/mongo-csharp-driver
 private async static Task ClearData(ICluster cluster)
 {
     using (var binding = new WritableServerBinding(cluster))
     {
         var commandOp = new DropDatabaseOperation(_database);
         await commandOp.ExecuteAsync(binding);
     }
 }
コード例 #38
0
 public abstract void Generate([NotNull] DropDatabaseOperation dropDatabaseOperation, [NotNull] IndentedStringBuilder stringBuilder);
コード例 #39
0
ファイル: CoreApi.cs プロジェクト: RavenZZ/MDRelation
 private async Task ClearData(ICluster cluster)
 {
     using (var binding = new WritableServerBinding(cluster))
     {
         var commandOp = new DropDatabaseOperation(_collection.DatabaseNamespace, _messageEncoderSettings);
         await commandOp.ExecuteAsync(binding, CancellationToken.None);
     }
 }
コード例 #40
0
        // public methods
        /// <inheritdoc/>
        public sealed override void DropDatabase(string name, CancellationToken cancellationToken = default(CancellationToken))
        {
            var messageEncoderSettings = GetMessageEncoderSettings();
            var operation = new DropDatabaseOperation(new DatabaseNamespace(name), messageEncoderSettings)
            {
                WriteConcern = _settings.WriteConcern
            };

            using (var binding = new WritableServerBinding(_cluster))
            {
                _operationExecutor.ExecuteWriteOperation(binding, operation, cancellationToken);
            }
        }
コード例 #41
0
        /// <inheritdoc/>
        public sealed override async Task DropDatabaseAsync(string name, CancellationToken cancellationToken = default(CancellationToken))
        {
            var messageEncoderSettings = GetMessageEncoderSettings();
            var operation = new DropDatabaseOperation(new DatabaseNamespace(name), messageEncoderSettings)
            {
                WriteConcern = _settings.WriteConcern
            };

            using (var binding = new WritableServerBinding(_cluster))
            {
                await _operationExecutor.ExecuteWriteOperationAsync(binding, operation, cancellationToken).ConfigureAwait(false);
            }
        }
 public void DropDatabase(bool async)
 {
     var operation = new DropDatabaseOperation(_collectionNamespace.DatabaseNamespace, _messageEncoderSettings);
     ExecuteOperation(operation, async);
 }
コード例 #43
0
        public void MessageEncoderSettings_get_should_return_expected_result()
        {
            var subject = new DropDatabaseOperation(_databaseNamespace, _messageEncoderSettings);

            var result = subject.MessageEncoderSettings;

            result.Should().BeSameAs(_messageEncoderSettings);
        }