Skip to content

Commit

Permalink
ADO.NET batching API (#54467)
Browse files Browse the repository at this point in the history
Closes #28633
  • Loading branch information
roji committed Jul 4, 2021
1 parent ad51267 commit 607f98c
Show file tree
Hide file tree
Showing 8 changed files with 211 additions and 0 deletions.
58 changes: 58 additions & 0 deletions src/libraries/System.Data.Common/ref/System.Data.Common.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1921,6 +1921,56 @@ public void RemoveAt(string sourceTable) { }
System.Data.ITableMapping System.Data.ITableMappingCollection.Add(string sourceTableName, string dataSetTableName) { throw null; }
System.Data.ITableMapping System.Data.ITableMappingCollection.GetByDataSetTable(string dataSetTableName) { throw null; }
}
public abstract class DbBatch : System.IDisposable, System.IAsyncDisposable
{
public System.Data.Common.DbBatchCommandCollection BatchCommands { get { throw null; } }
protected abstract System.Data.Common.DbBatchCommandCollection DbBatchCommands { get; }
public abstract int Timeout { get; set; }
public System.Data.Common.DbConnection? Connection { get; set; }
protected abstract System.Data.Common.DbConnection? DbConnection { get; set; }
public System.Data.Common.DbTransaction? Transaction { get; set; }
protected abstract System.Data.Common.DbTransaction? DbTransaction { get; set; }
public System.Data.Common.DbDataReader ExecuteReader(System.Data.CommandBehavior behavior = System.Data.CommandBehavior.Default) { throw null; }
protected abstract System.Data.Common.DbDataReader ExecuteDbDataReader(System.Data.CommandBehavior behavior);
public System.Threading.Tasks.Task<System.Data.Common.DbDataReader> ExecuteReaderAsync(System.Threading.CancellationToken cancellationToken = default) { throw null; }
public System.Threading.Tasks.Task<System.Data.Common.DbDataReader> ExecuteReaderAsync(System.Data.CommandBehavior behavior, System.Threading.CancellationToken cancellationToken = default) { throw null; }
protected abstract System.Threading.Tasks.Task<System.Data.Common.DbDataReader> ExecuteDbDataReaderAsync(System.Data.CommandBehavior behavior, System.Threading.CancellationToken cancellationToken);
public abstract int ExecuteNonQuery();
public abstract System.Threading.Tasks.Task<int> ExecuteNonQueryAsync(System.Threading.CancellationToken cancellationToken = default);
public abstract object? ExecuteScalar();
public abstract System.Threading.Tasks.Task<object?> ExecuteScalarAsync(System.Threading.CancellationToken cancellationToken = default);
public abstract void Prepare();
public abstract System.Threading.Tasks.Task PrepareAsync(System.Threading.CancellationToken cancellationToken = default);
public abstract void Cancel();
public System.Data.Common.DbBatchCommand CreateBatchCommand() { throw null; }
protected abstract System.Data.Common.DbBatchCommand CreateDbBatchCommand();
public virtual void Dispose() { throw null; }
public virtual System.Threading.Tasks.ValueTask DisposeAsync() { throw null; }
}
public abstract class DbBatchCommand
{
public abstract string CommandText { get; set; }
public abstract CommandType CommandType { get; set; }
public abstract int RecordsAffected { get; }
public DbParameterCollection Parameters { get { throw null; } }
protected abstract DbParameterCollection DbParameterCollection { get; }
}
public abstract class DbBatchCommandCollection : System.Collections.Generic.IList<DbBatchCommand>
{
public abstract System.Collections.Generic.IEnumerator<System.Data.Common.DbBatchCommand> GetEnumerator();
System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() { throw null; }
public abstract void Add(System.Data.Common.DbBatchCommand item);
public abstract void Clear();
public abstract bool Contains(System.Data.Common.DbBatchCommand item);
public abstract void CopyTo(System.Data.Common.DbBatchCommand[] array, int arrayIndex);
public abstract bool Remove(System.Data.Common.DbBatchCommand item);
public abstract int Count { get; }
public abstract bool IsReadOnly { get; }
public abstract int IndexOf(DbBatchCommand item);
public abstract void Insert(int index, DbBatchCommand item);
public abstract void RemoveAt(int index);
public abstract DbBatchCommand this[int index] { get; set; }
}
public abstract partial class DbColumn
{
protected DbColumn() { }
Expand Down Expand Up @@ -2079,6 +2129,9 @@ public virtual event System.Data.StateChangeEventHandler? StateChange { add { }
public virtual System.Threading.Tasks.Task ChangeDatabaseAsync(string databaseName, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
public abstract void Close();
public virtual System.Threading.Tasks.Task CloseAsync() { throw null; }
public virtual bool CanCreateBatch { get { throw null; } }
public System.Data.Common.DbBatch CreateBatch() { throw null; }
protected virtual System.Data.Common.DbBatch CreateDbBatch() { throw null; }
public System.Data.Common.DbCommand CreateCommand() { throw null; }
protected abstract System.Data.Common.DbCommand CreateDbCommand();
public virtual System.Threading.Tasks.ValueTask DisposeAsync() { throw null; }
Expand Down Expand Up @@ -2371,6 +2424,8 @@ protected DbException(string? message, System.Exception? innerException) { }
protected DbException(string? message, int errorCode) { }
public virtual bool IsTransient { get { throw null; } }
public virtual string? SqlState { get { throw null; } }
public System.Data.Common.DbBatchCommand? BatchCommand { get { throw null; } }
protected virtual System.Data.Common.DbBatchCommand? DbBatchCommand { get { throw null; } }
}
public static partial class DbMetaDataCollectionNames
{
Expand Down Expand Up @@ -2532,9 +2587,12 @@ public static void RegisterFactory(string providerInvariantName, [System.Diagnos
public abstract partial class DbProviderFactory
{
protected DbProviderFactory() { }
public virtual bool CanCreateBatch { get { throw null; } }
public virtual bool CanCreateCommandBuilder { get { throw null; } }
public virtual bool CanCreateDataAdapter { get { throw null; } }
public virtual bool CanCreateDataSourceEnumerator { get { throw null; } }
public virtual System.Data.Common.DbBatch CreateBatch() { throw null; }
public virtual System.Data.Common.DbBatchCommand CreateBatchCommand() { throw null; }
public virtual System.Data.Common.DbCommand? CreateCommand() { throw null; }
public virtual System.Data.Common.DbCommandBuilder? CreateCommandBuilder() { throw null; }
public virtual System.Data.Common.DbConnection? CreateConnection() { throw null; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,9 @@
<Compile Include="System\Data\Common\DataTableMappingCollection.cs" />
<Compile Include="System\Data\Common\DateTimeOffsetStorage.cs" />
<Compile Include="System\Data\Common\DateTimeStorage.cs" />
<Compile Include="System\Data\Common\DbBatch.cs" />
<Compile Include="System\Data\Common\DbBatchCommand.cs" />
<Compile Include="System\Data\Common\DbBatchCommandCollection.cs" />
<Compile Include="System\Data\Common\DbColumn.cs" />
<Compile Include="System\Data\Common\DbCommand.cs">
<SubType>Component</SubType>
Expand Down
76 changes: 76 additions & 0 deletions src/libraries/System.Data.Common/src/System/Data/Common/DbBatch.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System.Threading;
using System.Threading.Tasks;

namespace System.Data.Common
{
public abstract class DbBatch : IDisposable, IAsyncDisposable
{
public DbBatchCommandCollection BatchCommands => DbBatchCommands;

protected abstract DbBatchCommandCollection DbBatchCommands { get; }

public abstract int Timeout { get; set; }

public DbConnection? Connection
{
get => DbConnection;
set => DbConnection = value;
}

protected abstract DbConnection? DbConnection { get; set; }

public DbTransaction? Transaction
{
get => DbTransaction;
set => DbTransaction = value;
}

protected abstract DbTransaction? DbTransaction { get; set; }

public DbDataReader ExecuteReader(CommandBehavior behavior = CommandBehavior.Default)
=> ExecuteDbDataReader(behavior);

protected abstract DbDataReader ExecuteDbDataReader(CommandBehavior behavior);

public Task<DbDataReader> ExecuteReaderAsync(CancellationToken cancellationToken = default)
=> ExecuteDbDataReaderAsync(CommandBehavior.Default, cancellationToken);

public Task<DbDataReader> ExecuteReaderAsync(
CommandBehavior behavior,
CancellationToken cancellationToken = default)
=> ExecuteDbDataReaderAsync(behavior, cancellationToken);

protected abstract Task<DbDataReader> ExecuteDbDataReaderAsync(
CommandBehavior behavior,
CancellationToken cancellationToken);

public abstract int ExecuteNonQuery();

public abstract Task<int> ExecuteNonQueryAsync(CancellationToken cancellationToken = default);

public abstract object? ExecuteScalar();

public abstract Task<object?> ExecuteScalarAsync(CancellationToken cancellationToken = default);

public abstract void Prepare();

public abstract Task PrepareAsync(CancellationToken cancellationToken = default);

public abstract void Cancel();

public DbBatchCommand CreateBatchCommand() => CreateDbBatchCommand();

protected abstract DbBatchCommand CreateDbBatchCommand();

public virtual void Dispose() {}

public virtual ValueTask DisposeAsync()
{
Dispose();
return default;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System.ComponentModel;
using System.Diagnostics.CodeAnalysis;

namespace System.Data.Common
{
public abstract class DbBatchCommand
{
public abstract string CommandText { get; set; }

public abstract CommandType CommandType { get; set; }

public abstract int RecordsAffected { get; }

public DbParameterCollection Parameters => DbParameterCollection;

protected abstract DbParameterCollection DbParameterCollection { get; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System.Collections;
using System.Collections.Generic;

namespace System.Data.Common
{
public abstract class DbBatchCommandCollection : IList<DbBatchCommand>
{
public abstract IEnumerator<DbBatchCommand> GetEnumerator();

IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();

public abstract void Add(DbBatchCommand item);

public abstract void Clear();

public abstract bool Contains(DbBatchCommand item);

public abstract void CopyTo(DbBatchCommand[] array, int arrayIndex);

public abstract bool Remove(DbBatchCommand item);

public abstract int Count { get; }

public abstract bool IsReadOnly { get; }

public abstract int IndexOf(DbBatchCommand item);

public abstract void Insert(int index, DbBatchCommand item);

public abstract void RemoveAt(int index);

public abstract DbBatchCommand this[int index] { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,12 @@ public virtual Task ChangeDatabaseAsync(string databaseName, CancellationToken c
}
}

public virtual bool CanCreateBatch => false;

public DbBatch CreateBatch() => CreateDbBatch();

protected virtual DbBatch CreateDbBatch() => throw new NotSupportedException();

public DbCommand CreateCommand() => CreateDbCommand();

IDbCommand IDbConnection.CreateCommand() => CreateDbCommand();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,9 @@ protected DbException(System.Runtime.Serialization.SerializationInfo info, Syste
/// A standard SQL 5-character return code, or <see langword="null" />.
/// </returns>
public virtual string? SqlState => null;

public DbBatchCommand? BatchCommand => DbBatchCommand;

protected virtual DbBatchCommand? DbBatchCommand => null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ public abstract partial class DbProviderFactory

protected DbProviderFactory() { }

public virtual bool CanCreateBatch => false;

public virtual bool CanCreateDataSourceEnumerator => false;

public virtual bool CanCreateDataAdapter
Expand Down Expand Up @@ -47,6 +49,10 @@ public virtual bool CanCreateCommandBuilder
}
}

public virtual DbBatch CreateBatch() => throw new NotSupportedException();

public virtual DbBatchCommand CreateBatchCommand() => throw new NotSupportedException();

public virtual DbCommand? CreateCommand() => null;

public virtual DbCommandBuilder? CreateCommandBuilder() => null;
Expand Down

0 comments on commit 607f98c

Please sign in to comment.