Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/corefx.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEgor Bogatov <egorbo@gmail.com>2019-07-15 23:47:33 +0300
committerMarek Safar <marek.safar@gmail.com>2019-07-16 01:54:34 +0300
commitdd02bebe16cf1be588b9f92c6f25facc802cffa7 (patch)
treeae0fc228152bf41681fccea9c358055cd877a2f5
parent17dd540969d8a5a0e19c99dccc31293080f735d2 (diff)
Relfect ns2.1 changes
-rw-r--r--src/System.Data.Common/src/System/Data/Common/DbCommand.cs26
-rw-r--r--src/System.Data.Common/src/System/Data/Common/DbConnection.cs62
-rw-r--r--src/System.Data.Common/src/System/Data/Common/DbDataReader.cs21
-rw-r--r--src/System.Data.Common/src/System/Data/Common/DbProviderFactory.cs35
-rw-r--r--src/System.Data.Common/src/System/Data/Common/DbTransaction.cs47
5 files changed, 187 insertions, 4 deletions
diff --git a/src/System.Data.Common/src/System/Data/Common/DbCommand.cs b/src/System.Data.Common/src/System/Data/Common/DbCommand.cs
index fc47aecb56..92ce6ab913 100644
--- a/src/System.Data.Common/src/System/Data/Common/DbCommand.cs
+++ b/src/System.Data.Common/src/System/Data/Common/DbCommand.cs
@@ -8,7 +8,7 @@ using System.Threading;
namespace System.Data.Common
{
- public abstract class DbCommand : Component, IDbCommand
+ public abstract class DbCommand : Component, IDbCommand, IAsyncDisposable
{
protected DbCommand() : base()
{
@@ -222,5 +222,29 @@ namespace System.Data.Common
public abstract object ExecuteScalar();
public abstract void Prepare();
+
+ public virtual Task PrepareAsync(CancellationToken cancellationToken = default)
+ {
+ if (cancellationToken.IsCancellationRequested)
+ {
+ return Task.FromCanceled(cancellationToken);
+ }
+
+ try
+ {
+ Prepare();
+ return Task.CompletedTask;
+ }
+ catch (Exception e)
+ {
+ return Task.FromException(e);
+ }
+ }
+
+ public virtual ValueTask DisposeAsync()
+ {
+ Dispose();
+ return default;
+ }
}
}
diff --git a/src/System.Data.Common/src/System/Data/Common/DbConnection.cs b/src/System.Data.Common/src/System/Data/Common/DbConnection.cs
index 9dba89aeff..edbbe0d03c 100644
--- a/src/System.Data.Common/src/System/Data/Common/DbConnection.cs
+++ b/src/System.Data.Common/src/System/Data/Common/DbConnection.cs
@@ -8,7 +8,7 @@ using System.Threading.Tasks;
namespace System.Data.Common
{
- public abstract partial class DbConnection : Component, IDbConnection
+ public abstract partial class DbConnection : Component, IDbConnection, IAsyncDisposable
{
#pragma warning disable 649 // ignore unassigned field warning
internal bool _suppressStateChangeForReconnection;
@@ -128,5 +128,65 @@ namespace System.Data.Common
}
}
}
+
+ protected virtual ValueTask<DbTransaction> BeginDbTransactionAsync(IsolationLevel isolationLevel, CancellationToken cancellationToken)
+ {
+ if (cancellationToken.IsCancellationRequested)
+ {
+ return new ValueTask<DbTransaction>(Task.FromCanceled<DbTransaction>(cancellationToken));
+ }
+
+ try
+ {
+ return new ValueTask<DbTransaction>(BeginDbTransaction(isolationLevel));
+ }
+ catch (Exception e)
+ {
+ return new ValueTask<DbTransaction>(Task.FromException<DbTransaction>(e));
+ }
+ }
+
+ public ValueTask<DbTransaction> BeginTransactionAsync(CancellationToken cancellationToken = default)
+ => BeginDbTransactionAsync(IsolationLevel.Unspecified, cancellationToken);
+
+ public ValueTask<DbTransaction> BeginTransactionAsync(IsolationLevel isolationLevel, CancellationToken cancellationToken = default)
+ => BeginDbTransactionAsync(isolationLevel, cancellationToken);
+
+ public virtual Task CloseAsync()
+ {
+ try
+ {
+ Close();
+ return Task.CompletedTask;
+ }
+ catch (Exception e)
+ {
+ return Task.FromException(e);
+ }
+ }
+
+ public virtual ValueTask DisposeAsync()
+ {
+ Dispose();
+ return default;
+ }
+
+ public virtual Task ChangeDatabaseAsync(string databaseName, CancellationToken cancellationToken = default)
+ {
+ if (cancellationToken.IsCancellationRequested)
+ {
+ return Task.FromCanceled(cancellationToken);
+ }
+
+ try
+ {
+ ChangeDatabase(databaseName);
+ return Task.CompletedTask;
+ }
+ catch (Exception e)
+ {
+ return Task.FromException(e);
+ }
+ }
}
}
diff --git a/src/System.Data.Common/src/System/Data/Common/DbDataReader.cs b/src/System.Data.Common/src/System/Data/Common/DbDataReader.cs
index ff30a418e5..84a2e6d26a 100644
--- a/src/System.Data.Common/src/System/Data/Common/DbDataReader.cs
+++ b/src/System.Data.Common/src/System/Data/Common/DbDataReader.cs
@@ -10,7 +10,7 @@ using System.Threading;
namespace System.Data.Common
{
- public abstract class DbDataReader : MarshalByRefObject, IDataReader, IEnumerable
+ public abstract class DbDataReader : MarshalByRefObject, IDataReader, IEnumerable, IAsyncDisposable
{
protected DbDataReader() : base() { }
@@ -247,5 +247,24 @@ namespace System.Data.Common
}
}
}
+
+ public virtual Task CloseAsync()
+ {
+ try
+ {
+ Close();
+ return Task.CompletedTask;
+ }
+ catch (Exception e)
+ {
+ return Task.FromException(e);
+ }
+ }
+
+ public virtual ValueTask DisposeAsync()
+ {
+ Dispose();
+ return default;
+ }
}
}
diff --git a/src/System.Data.Common/src/System/Data/Common/DbProviderFactory.cs b/src/System.Data.Common/src/System/Data/Common/DbProviderFactory.cs
index 0e568d7eb6..a57c2e894e 100644
--- a/src/System.Data.Common/src/System/Data/Common/DbProviderFactory.cs
+++ b/src/System.Data.Common/src/System/Data/Common/DbProviderFactory.cs
@@ -6,10 +6,45 @@ namespace System.Data.Common
{
public abstract partial class DbProviderFactory
{
+ private bool? _canCreateDataAdapter;
+ private bool? _canCreateCommandBuilder;
+
protected DbProviderFactory() { }
public virtual bool CanCreateDataSourceEnumerator => false;
+ public virtual bool CanCreateDataAdapter
+ {
+ get
+ {
+ if (!_canCreateDataAdapter.HasValue)
+ {
+ using (DbDataAdapter adapter = CreateDataAdapter())
+ {
+ _canCreateDataAdapter = adapter != null;
+ }
+ }
+
+ return _canCreateDataAdapter.Value;
+ }
+ }
+
+ public virtual bool CanCreateCommandBuilder
+ {
+ get
+ {
+ if (!_canCreateCommandBuilder.HasValue)
+ {
+ using (DbCommandBuilder builder = CreateCommandBuilder())
+ {
+ _canCreateCommandBuilder = builder != null;
+ }
+ }
+
+ return _canCreateCommandBuilder.Value;
+ }
+ }
+
public virtual DbCommand CreateCommand() => null;
public virtual DbCommandBuilder CreateCommandBuilder() => null;
diff --git a/src/System.Data.Common/src/System/Data/Common/DbTransaction.cs b/src/System.Data.Common/src/System/Data/Common/DbTransaction.cs
index 97edf2c603..7233d6d4a6 100644
--- a/src/System.Data.Common/src/System/Data/Common/DbTransaction.cs
+++ b/src/System.Data.Common/src/System/Data/Common/DbTransaction.cs
@@ -2,9 +2,12 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
+using System.Threading;
+using System.Threading.Tasks;
+
namespace System.Data.Common
{
- public abstract class DbTransaction : MarshalByRefObject, IDbTransaction
+ public abstract class DbTransaction : MarshalByRefObject, IDbTransaction, IAsyncDisposable
{
protected DbTransaction() : base() { }
@@ -23,5 +26,47 @@ namespace System.Data.Common
protected virtual void Dispose(bool disposing) { }
public abstract void Rollback();
+
+ public virtual Task CommitAsync(CancellationToken cancellationToken = default)
+ {
+ if (cancellationToken.IsCancellationRequested)
+ {
+ return Task.FromCanceled(cancellationToken);
+ }
+
+ try
+ {
+ Commit();
+ return Task.CompletedTask;
+ }
+ catch (Exception e)
+ {
+ return Task.FromException(e);
+ }
+ }
+
+ public virtual ValueTask DisposeAsync()
+ {
+ Dispose();
+ return default;
+ }
+
+ public virtual Task RollbackAsync(CancellationToken cancellationToken = default)
+ {
+ if (cancellationToken.IsCancellationRequested)
+ {
+ return Task.FromCanceled(cancellationToken);
+ }
+
+ try
+ {
+ Rollback();
+ return Task.CompletedTask;
+ }
+ catch (Exception e)
+ {
+ return Task.FromException(e);
+ }
+ }
}
}