From 946a2daf9e8a2f3786e04d04689bd88daeeffc7f Mon Sep 17 00:00:00 2001 From: Shay Rojansky Date: Wed, 22 Apr 2020 15:43:49 +0200 Subject: [PATCH] Move more implementation up with default interface implementations --- .../Storage/RelationalTransaction.cs | 26 ------------------- .../Storage/Internal/SqlServerTransaction.cs | 12 ++++----- .../Storage/Internal/SqliteTransaction.cs | 16 ++++++------ src/EFCore/Storage/IDbContextTransaction.cs | 4 +-- 4 files changed, 16 insertions(+), 42 deletions(-) diff --git a/src/EFCore.Relational/Storage/RelationalTransaction.cs b/src/EFCore.Relational/Storage/RelationalTransaction.cs index 91d1f87fd2c..a23632a5d1f 100644 --- a/src/EFCore.Relational/Storage/RelationalTransaction.cs +++ b/src/EFCore.Relational/Storage/RelationalTransaction.cs @@ -270,32 +270,6 @@ await Logger.TransactionErrorAsync( await ClearTransactionAsync(cancellationToken); } - /// - public virtual void Save(string savepointName) - => throw new NotSupportedException(); - - /// - public virtual Task SaveAsync(string savepointName, CancellationToken cancellationToken = default) - => throw new NotSupportedException(); - - /// - public virtual void Rollback(string savepointName) - => throw new NotSupportedException(); - - /// - public virtual Task RollbackAsync(string savepointName, CancellationToken cancellationToken = default) - => throw new NotSupportedException(); - - /// - public virtual void Release(string savepointName) { } - - /// - public virtual Task ReleaseAsync(string savepointName, CancellationToken cancellationToken = default) - => Task.CompletedTask; - - /// - public virtual bool AreSavepointsSupported => false; - /// /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources. /// diff --git a/src/EFCore.SqlServer/Storage/Internal/SqlServerTransaction.cs b/src/EFCore.SqlServer/Storage/Internal/SqlServerTransaction.cs index 9285afc8ab2..231178d20a4 100644 --- a/src/EFCore.SqlServer/Storage/Internal/SqlServerTransaction.cs +++ b/src/EFCore.SqlServer/Storage/Internal/SqlServerTransaction.cs @@ -11,7 +11,7 @@ namespace Microsoft.EntityFrameworkCore.SqlServer.Storage.Internal { - public class SqlServerTransaction : RelationalTransaction + public class SqlServerTransaction : RelationalTransaction, IDbContextTransaction { private readonly DbTransaction _dbTransaction; @@ -31,7 +31,7 @@ public SqlServerTransaction( => _dbTransaction = transaction; /// - public override void Save(string savepointName) + public void Save(string savepointName) { using var command = Connection.DbConnection.CreateCommand(); command.Transaction = _dbTransaction; @@ -40,7 +40,7 @@ public override void Save(string savepointName) } /// - public override async Task SaveAsync(string savepointName, CancellationToken cancellationToken = default) + public async Task SaveAsync(string savepointName, CancellationToken cancellationToken = default) { using var command = Connection.DbConnection.CreateCommand(); command.Transaction = _dbTransaction; @@ -49,7 +49,7 @@ public override async Task SaveAsync(string savepointName, CancellationToken can } /// - public override void Rollback(string savepointName) + public void Rollback(string savepointName) { using var command = Connection.DbConnection.CreateCommand(); command.Transaction = _dbTransaction; @@ -58,7 +58,7 @@ public override void Rollback(string savepointName) } /// - public override async Task RollbackAsync(string savepointName, CancellationToken cancellationToken = default) + public async Task RollbackAsync(string savepointName, CancellationToken cancellationToken = default) { using var command = Connection.DbConnection.CreateCommand(); command.Transaction = _dbTransaction; @@ -67,6 +67,6 @@ public override async Task RollbackAsync(string savepointName, CancellationToken } /// - public override bool AreSavepointsSupported => true; + public bool AreSavepointsSupported => true; } } diff --git a/src/EFCore.Sqlite.Core/Storage/Internal/SqliteTransaction.cs b/src/EFCore.Sqlite.Core/Storage/Internal/SqliteTransaction.cs index 44917cbbcb7..b5aadb56e54 100644 --- a/src/EFCore.Sqlite.Core/Storage/Internal/SqliteTransaction.cs +++ b/src/EFCore.Sqlite.Core/Storage/Internal/SqliteTransaction.cs @@ -11,7 +11,7 @@ namespace Microsoft.EntityFrameworkCore.Sqlite.Storage.Internal { - public class SqliteTransaction : RelationalTransaction + public class SqliteTransaction : RelationalTransaction, IDbContextTransaction { private readonly DbTransaction _dbTransaction; @@ -31,7 +31,7 @@ public SqliteTransaction( => _dbTransaction = transaction; /// - public override void Save(string savepointName) + public void Save(string savepointName) { using var command = Connection.DbConnection.CreateCommand(); command.Transaction = _dbTransaction; @@ -40,7 +40,7 @@ public override void Save(string savepointName) } /// - public override async Task SaveAsync(string savepointName, CancellationToken cancellationToken = default) + public async Task SaveAsync(string savepointName, CancellationToken cancellationToken = default) { using var command = Connection.DbConnection.CreateCommand(); command.Transaction = _dbTransaction; @@ -49,7 +49,7 @@ public override async Task SaveAsync(string savepointName, CancellationToken can } /// - public override void Rollback(string savepointName) + public void Rollback(string savepointName) { using var command = Connection.DbConnection.CreateCommand(); command.Transaction = _dbTransaction; @@ -58,7 +58,7 @@ public override void Rollback(string savepointName) } /// - public override async Task RollbackAsync(string savepointName, CancellationToken cancellationToken = default) + public async Task RollbackAsync(string savepointName, CancellationToken cancellationToken = default) { using var command = Connection.DbConnection.CreateCommand(); command.Transaction = _dbTransaction; @@ -67,7 +67,7 @@ public override async Task RollbackAsync(string savepointName, CancellationToken } /// - public override void Release(string savepointName) + public void Release(string savepointName) { using var command = Connection.DbConnection.CreateCommand(); command.Transaction = _dbTransaction; @@ -76,7 +76,7 @@ public override void Release(string savepointName) } /// - public override async Task ReleaseAsync(string savepointName, CancellationToken cancellationToken = default) + public async Task ReleaseAsync(string savepointName, CancellationToken cancellationToken = default) { using var command = Connection.DbConnection.CreateCommand(); command.Transaction = _dbTransaction; @@ -85,6 +85,6 @@ public override async Task ReleaseAsync(string savepointName, CancellationToken } /// - public override bool AreSavepointsSupported => true; + public bool AreSavepointsSupported => true; } } diff --git a/src/EFCore/Storage/IDbContextTransaction.cs b/src/EFCore/Storage/IDbContextTransaction.cs index 3ce006e2349..78bffe008cf 100644 --- a/src/EFCore/Storage/IDbContextTransaction.cs +++ b/src/EFCore/Storage/IDbContextTransaction.cs @@ -88,7 +88,7 @@ Task RollbackAsync([NotNull] string savepointName, CancellationToken cancellatio /// reclaim some resources before the transaction ends. /// /// The name of the savepoint to release. - void Release([NotNull] string savepointName) => throw new NotSupportedException(); + void Release([NotNull] string savepointName) { } /// /// Destroys a savepoint previously defined in the current transaction. This allows the system to @@ -98,7 +98,7 @@ Task RollbackAsync([NotNull] string savepointName, CancellationToken cancellatio /// The cancellation token. /// A representing the asynchronous operation. Task ReleaseAsync([NotNull] string savepointName, CancellationToken cancellationToken = default) - => throw new NotSupportedException(); + => Task.CompletedTask; /// /// Gets a value that indicates whether this instance supports