Skip to content

Commit

Permalink
Remove unneeded savepoint API sugar (#21929)
Browse files Browse the repository at this point in the history
From DatabaseFacade and IDbContextTransactionManager

Part of #20409 (May 20)
  • Loading branch information
roji committed Aug 4, 2020
1 parent e81a99a commit 5a40adb
Show file tree
Hide file tree
Showing 5 changed files with 0 additions and 338 deletions.
36 changes: 0 additions & 36 deletions src/EFCore.InMemory/Storage/Internal/InMemoryTransactionManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -114,42 +114,6 @@ public virtual Task RollbackTransactionAsync(CancellationToken cancellationToken
return Task.CompletedTask;
}

/// <inheritdoc />
public virtual void CreateSavepoint(string name)
=> _logger.TransactionIgnoredWarning();

/// <inheritdoc />
public virtual Task CreateSavepointAsync(string name, CancellationToken cancellationToken = default)
{
_logger.TransactionIgnoredWarning();
return Task.CompletedTask;
}

/// <inheritdoc />
public virtual void RollbackToSavepoint(string name)
=> _logger.TransactionIgnoredWarning();

/// <inheritdoc />
public virtual Task RollbackToSavepointAsync(string name, CancellationToken cancellationToken = default)
{
_logger.TransactionIgnoredWarning();
return Task.CompletedTask;
}

/// <inheritdoc />
public virtual void ReleaseSavepoint(string name)
=> _logger.TransactionIgnoredWarning();

/// <inheritdoc />
public virtual Task ReleaseSavepointAsync(string name, CancellationToken cancellationToken = default)
{
_logger.TransactionIgnoredWarning();
return Task.CompletedTask;
}

/// <inheritdoc />
public virtual bool SupportsSavepoints => true;

/// <summary>
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to
/// the same compatibility standards as public APIs. It may be changed or removed without notice in
Expand Down
80 changes: 0 additions & 80 deletions src/EFCore.Relational/Storage/RelationalConnection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -531,86 +531,6 @@ public virtual Task RollbackTransactionAsync(CancellationToken cancellationToken
return CurrentTransaction.RollbackAsync(cancellationToken);
}

/// <inheritdoc />
public virtual void CreateSavepoint(string name)
{
if (CurrentTransaction == null)
{
throw new InvalidOperationException(RelationalStrings.NoActiveTransaction);
}

CurrentTransaction.CreateSavepoint(name);
}

/// <inheritdoc />
public virtual Task CreateSavepointAsync(string name, CancellationToken cancellationToken = default)
{
if (CurrentTransaction == null)
{
throw new InvalidOperationException(RelationalStrings.NoActiveTransaction);
}

return CurrentTransaction.CreateSavepointAsync(name, cancellationToken);
}

/// <inheritdoc />
public virtual void RollbackToSavepoint(string name)
{
if (CurrentTransaction == null)
{
throw new InvalidOperationException(RelationalStrings.NoActiveTransaction);
}

CurrentTransaction.RollbackToSavepoint(name);
}

/// <inheritdoc />
public virtual Task RollbackToSavepointAsync(string name, CancellationToken cancellationToken = default)
{
if (CurrentTransaction == null)
{
throw new InvalidOperationException(RelationalStrings.NoActiveTransaction);
}

return CurrentTransaction.RollbackToSavepointAsync(name, cancellationToken);
}

/// <inheritdoc />
public virtual void ReleaseSavepoint(string name)
{
if (CurrentTransaction == null)
{
throw new InvalidOperationException(RelationalStrings.NoActiveTransaction);
}

CurrentTransaction.ReleaseSavepoint(name);
}

/// <inheritdoc />
public virtual Task ReleaseSavepointAsync(string name, CancellationToken cancellationToken = default)
{
if (CurrentTransaction == null)
{
throw new InvalidOperationException(RelationalStrings.NoActiveTransaction);
}

return CurrentTransaction.ReleaseSavepointAsync(name, cancellationToken);
}

/// <inheritdoc />
public virtual bool SupportsSavepoints
{
get
{
if (CurrentTransaction == null)
{
throw new InvalidOperationException(RelationalStrings.NoActiveTransaction);
}

return CurrentTransaction.SupportsSavepoints;
}
}

/// <summary>
/// Opens the connection to the database.
/// </summary>
Expand Down
67 changes: 0 additions & 67 deletions src/EFCore/Infrastructure/DatabaseFacade.cs
Original file line number Diff line number Diff line change
Expand Up @@ -196,73 +196,6 @@ public virtual void RollbackTransaction()
public virtual Task RollbackTransactionAsync(CancellationToken cancellationToken = default)
=> Dependencies.TransactionManager.RollbackTransactionAsync(cancellationToken);

/// <summary>
/// Creates a savepoint in the transaction. This allows all commands that are executed after the savepoint
/// was established to be rolled back, restoring the transaction state to what it was at the time of the
/// savepoint.
/// </summary>
/// <param name="name"> The name of the savepoint to be created. </param>
public virtual void CreateSavepoint([NotNull] string name)
=> Dependencies.TransactionManager.CreateSavepoint(name);

/// <summary>
/// Creates a savepoint in the transaction. This allows all commands that are executed after the savepoint
/// was established to be rolled back, restoring the transaction state to what it was at the time of the
/// savepoint.
/// </summary>
/// <param name="name"> The name of the savepoint to be created. </param>
/// <param name="cancellationToken"> The cancellation token. </param>
/// <returns> A <see cref="Task" /> representing the asynchronous operation. </returns>
public virtual Task CreateSavepointAsync([NotNull] string name, CancellationToken cancellationToken = default)
=> Dependencies.TransactionManager.CreateSavepointAsync(name, cancellationToken);

/// <summary>
/// Rolls back all commands that were executed after the specified savepoint was established.
/// </summary>
/// <param name="name"> The name of the savepoint to roll back to. </param>
public virtual void RollbackToSavepoint([NotNull] string name)
=> Dependencies.TransactionManager.RollbackToSavepoint(name);

/// <summary>
/// Rolls back all commands that were executed after the specified savepoint was established.
/// </summary>
/// <param name="name"> The name of the savepoint to roll back to. </param>
/// <param name="cancellationToken"> The cancellation token. </param>
/// <returns> A <see cref="Task" /> representing the asynchronous operation. </returns>
public virtual Task RollbackToSavepointAsync([NotNull] string name, CancellationToken cancellationToken = default)
=> Dependencies.TransactionManager.RollbackToSavepointAsync(name, cancellationToken);

/// <summary>
/// Destroys a savepoint previously defined in the current transaction. This allows the system to
/// reclaim some resources before the transaction ends.
/// </summary>
/// <param name="name"> The name of the savepoint to release. </param>
public virtual void ReleaseSavepoint([NotNull] string name)
=> Dependencies.TransactionManager.ReleaseSavepoint(name);

/// <summary>
/// Destroys a savepoint previously defined in the current transaction. This allows the system to
/// reclaim some resources before the transaction ends.
/// </summary>
/// <param name="name"> The name of the savepoint to release. </param>
/// <param name="cancellationToken"> The cancellation token. </param>
/// <returns> A <see cref="Task" /> representing the asynchronous operation. </returns>
public virtual Task ReleaseSavepointAsync([NotNull] string name, CancellationToken cancellationToken = default)
=> Dependencies.TransactionManager.ReleaseSavepointAsync(name, cancellationToken);

/// <summary>
/// Gets a value that indicates whether this <see cref="DatabaseFacade"/> instance supports
/// database savepoints. If <see langword="false" />, the methods <see cref="CreateSavepointAsync"/>,
/// <see cref="RollbackToSavepointAsync"/>
/// and <see cref="ReleaseSavepointAsync"/> as well as their synchronous counterparts are expected to throw
/// <see cref="NotSupportedException"/>.
/// </summary>
/// <returns>
/// <see langword="true" /> if this <see cref="DatabaseFacade"/> instance supports database savepoints;
/// otherwise, <see langword="false" />.
/// </returns>
public virtual bool SupportsSavepoints => Dependencies.TransactionManager.SupportsSavepoints;

/// <summary>
/// Creates an instance of the configured <see cref="IExecutionStrategy" />.
/// </summary>
Expand Down
64 changes: 0 additions & 64 deletions src/EFCore/Storage/IDbContextTransactionManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,70 +70,6 @@ public interface IDbContextTransactionManager : IResettableService
/// </returns>
Task RollbackTransactionAsync(CancellationToken cancellationToken = default);

/// <summary>
/// Creates a savepoint in the transaction. This allows all commands that are executed after the savepoint
/// was established to be rolled back, restoring the transaction state to what it was at the time of the
/// savepoint.
/// </summary>
/// <param name="name"> The name of the savepoint to be created. </param>
void CreateSavepoint([NotNull] string name) => throw new NotSupportedException();

/// <summary>
/// Creates a savepoint in the transaction. This allows all commands that are executed after the savepoint
/// was established to be rolled back, restoring the transaction state to what it was at the time of the
/// savepoint.
/// </summary>
/// <param name="name"> The name of the savepoint to be created. </param>
/// <param name="cancellationToken"> The cancellation token. </param>
/// <returns> A <see cref="Task" /> representing the asynchronous operation. </returns>
Task CreateSavepointAsync([NotNull] string name, CancellationToken cancellationToken = default)
=> throw new NotSupportedException();

/// <summary>
/// Rolls back all commands that were executed after the specified savepoint was established.
/// </summary>
/// <param name="name"> The name of the savepoint to roll back to. </param>
void RollbackToSavepoint([NotNull] string name) => throw new NotSupportedException();

/// <summary>
/// Rolls back all commands that were executed after the specified savepoint was established.
/// </summary>
/// <param name="name"> The name of the savepoint to roll back to. </param>
/// <param name="cancellationToken"> The cancellation token. </param>
/// <returns> A <see cref="Task" /> representing the asynchronous operation. </returns>
Task RollbackToSavepointAsync([NotNull] string name, CancellationToken cancellationToken = default)
=> throw new NotSupportedException();

/// <summary>
/// Destroys a savepoint previously defined in the current transaction. This allows the system to
/// reclaim some resources before the transaction ends.
/// </summary>
/// <param name="name"> The name of the savepoint to release. </param>
void ReleaseSavepoint([NotNull] string name) => throw new NotSupportedException();

/// <summary>
/// Destroys a savepoint previously defined in the current transaction. This allows the system to
/// reclaim some resources before the transaction ends.
/// </summary>
/// <param name="name"> The name of the savepoint to release. </param>
/// <param name="cancellationToken"> The cancellation token. </param>
/// <returns> A <see cref="Task" /> representing the asynchronous operation. </returns>
Task ReleaseSavepointAsync([NotNull] string name, CancellationToken cancellationToken = default)
=> throw new NotSupportedException();

/// <summary>
/// Gets a value that indicates whether this <see cref="IDbContextTransactionManager"/> instance supports
/// database savepoints. If <see langword="false" />, the methods <see cref="CreateSavepointAsync"/>,
/// <see cref="RollbackToSavepointAsync"/>
/// and <see cref="ReleaseSavepointAsync"/> as well as their synchronous counterparts are expected to throw
/// <see cref="NotSupportedException"/>.
/// </summary>
/// <returns>
/// <see langword="true" /> if this <see cref="IDbContextTransactionManager"/> instance supports database savepoints;
/// otherwise, <see langword="false" />.
/// </returns>
bool SupportsSavepoints => false;

/// <summary>
/// Gets the current transaction.
/// </summary>
Expand Down
91 changes: 0 additions & 91 deletions test/EFCore.Tests/DatabaseFacadeTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -282,97 +282,6 @@ public async Task Can_roll_back_transaction_async()
Assert.Equal(1, manager.RollbackCalls);
}

[ConditionalFact]
public void Can_create_savepoint()
{
var manager = new FakeDbContextTransactionManager(new FakeDbContextTransaction());

var context = InMemoryTestHelpers.Instance.CreateContext(
new ServiceCollection().AddSingleton<IDbContextTransactionManager>(manager));

context.Database.CreateSavepoint("foo");

Assert.Equal(1, manager.CreateSavepointCalls);
}

[ConditionalFact]
public async Task Can_create_savepoint_async()
{
var manager = new FakeDbContextTransactionManager(new FakeDbContextTransaction());

var context = InMemoryTestHelpers.Instance.CreateContext(
new ServiceCollection().AddSingleton<IDbContextTransactionManager>(manager));

await context.Database.CreateSavepointAsync("foo");

Assert.Equal(1, manager.CreateSavepointCalls);
}

[ConditionalFact]
public void Can_rollback_savepoint()
{
var manager = new FakeDbContextTransactionManager(new FakeDbContextTransaction());

var context = InMemoryTestHelpers.Instance.CreateContext(
new ServiceCollection().AddSingleton<IDbContextTransactionManager>(manager));

context.Database.RollbackToSavepoint("foo");

Assert.Equal(1, manager.RollbackSavepointCalls);
}

[ConditionalFact]
public async Task Can_rollback_savepoint_async()
{
var manager = new FakeDbContextTransactionManager(new FakeDbContextTransaction());

var context = InMemoryTestHelpers.Instance.CreateContext(
new ServiceCollection().AddSingleton<IDbContextTransactionManager>(manager));

await context.Database.RollbackToSavepointAsync("foo");

Assert.Equal(1, manager.RollbackSavepointCalls);
}

[ConditionalFact]
public void Can_release_savepoint()
{
var manager = new FakeDbContextTransactionManager(new FakeDbContextTransaction());

var context = InMemoryTestHelpers.Instance.CreateContext(
new ServiceCollection().AddSingleton<IDbContextTransactionManager>(manager));

context.Database.ReleaseSavepoint("foo");

Assert.Equal(1, manager.ReleaseSavepointCalls);
}

[ConditionalFact]
public async Task Can_release_savepoint_async()
{
var manager = new FakeDbContextTransactionManager(new FakeDbContextTransaction());

var context = InMemoryTestHelpers.Instance.CreateContext(
new ServiceCollection().AddSingleton<IDbContextTransactionManager>(manager));

await context.Database.ReleaseSavepointAsync("foo");

Assert.Equal(1, manager.ReleaseSavepointCalls);
}

[ConditionalFact]
public void Can_check_if_checkpoints_are_supported()
{
var manager = new FakeDbContextTransactionManager(new FakeDbContextTransaction());

var context = InMemoryTestHelpers.Instance.CreateContext(
new ServiceCollection().AddSingleton<IDbContextTransactionManager>(manager));

_ = context.Database.SupportsSavepoints;

Assert.Equal(1, manager.SupportsSavepointsCalls);
}

[ConditionalFact]
public void Can_get_current_transaction()
{
Expand Down

0 comments on commit 5a40adb

Please sign in to comment.