-
Notifications
You must be signed in to change notification settings - Fork 337
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add batch command API (without implementation).
Signed-off-by: Bradley Grainger <[email protected]>
- Loading branch information
Showing
5 changed files
with
238 additions
and
0 deletions.
There are no files selected for viewing
37 changes: 37 additions & 0 deletions
37
src/MySqlConnector/MySql.Data.MySqlClient/DbBatchCommandList.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
using System.Collections; | ||
using System.Collections.Generic; | ||
using System.Data.Common; | ||
|
||
namespace MySql.Data.MySqlClient | ||
{ | ||
internal sealed class DbBatchCommandList : IList<DbBatchCommand> | ||
{ | ||
public DbBatchCommandList(List<MySqlDbBatchCommand> batchCommands) => m_batchCommands = batchCommands; | ||
|
||
public void Add(DbBatchCommand item) => m_batchCommands.Add((MySqlDbBatchCommand) item); | ||
public void Clear() => m_batchCommands.Clear(); | ||
public bool Contains(DbBatchCommand item) => m_batchCommands.Contains((MySqlDbBatchCommand) item); | ||
public IEnumerator<DbBatchCommand> GetEnumerator() => m_batchCommands.GetEnumerator(); | ||
IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); | ||
public bool Remove(DbBatchCommand item) => m_batchCommands.Remove((MySqlDbBatchCommand) item); | ||
public int Count => m_batchCommands.Count; | ||
public bool IsReadOnly => false; | ||
public int IndexOf(DbBatchCommand item) => m_batchCommands.IndexOf((MySqlDbBatchCommand) item); | ||
public void Insert(int index, DbBatchCommand item) => m_batchCommands.Insert(index, (MySqlDbBatchCommand) item); | ||
public void RemoveAt(int index) => m_batchCommands.RemoveAt(index); | ||
|
||
public DbBatchCommand this[int index] | ||
{ | ||
get => m_batchCommands[index]; | ||
set => m_batchCommands[index] = (MySqlDbBatchCommand) value; | ||
} | ||
|
||
public void CopyTo(DbBatchCommand[] array, int arrayIndex) | ||
{ | ||
for (var i = 0; i < m_batchCommands.Count; i++) | ||
array[arrayIndex + i] = m_batchCommands[i]; | ||
} | ||
|
||
readonly List<MySqlDbBatchCommand> m_batchCommands; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
132 changes: 132 additions & 0 deletions
132
src/MySqlConnector/MySql.Data.MySqlClient/MySqlDbBatch.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,132 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Data.Common; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
|
||
#if NET45 || NET461 || NET471 || NETSTANDARD1_3 || NETSTANDARD2_0 || NETCOREAPP2_1 | ||
namespace System.Data.Common | ||
{ | ||
public abstract class DbBatch : IDisposable | ||
{ | ||
public IList<DbBatchCommand> BatchCommands => DbBatchCommands; | ||
protected abstract IList<DbBatchCommand> DbBatchCommands { get; } | ||
|
||
#region Execution (mirrors DbCommand) | ||
|
||
public abstract DbDataReader ExecuteReader(); | ||
public abstract Task<DbDataReader> ExecuteReaderAsync(CancellationToken cancellationToken = default); | ||
|
||
public abstract int ExecuteNonQuery(); | ||
public abstract Task<int> ExecuteNonQueryAsync(CancellationToken cancellationToken = default); | ||
|
||
public abstract object ExecuteScalar(); | ||
public abstract Task<object> ExecuteScalarAsync(CancellationToken cancellationToken = default); | ||
|
||
#endregion | ||
|
||
#region Execution properties (mirrors DbCommand) | ||
|
||
public abstract int Timeout { get; set; } | ||
|
||
// Delegates to DbConnection | ||
public DbConnection Connection { get; set; } | ||
protected abstract DbConnection DbConnection { get; set; } | ||
|
||
// Delegates to DbTransaction | ||
public DbTransaction Transaction { get; set; } | ||
protected abstract DbTransaction DbTransaction { get; set; } | ||
|
||
#endregion | ||
|
||
#region Other methods mirroring DbCommand | ||
|
||
public abstract void Prepare(); | ||
public abstract Task PrepareAsync(CancellationToken cancellationToken = default); | ||
public abstract void Cancel(); | ||
public abstract Task CancelAsync(CancellationToken cancellationToken = default); | ||
|
||
#endregion | ||
|
||
#region Standard dispose pattern | ||
|
||
public void Dispose() | ||
{ | ||
Dispose(true); | ||
GC.SuppressFinalize(this); | ||
} | ||
|
||
protected virtual void Dispose(bool disposing) { } | ||
|
||
#endregion | ||
} | ||
} | ||
#endif | ||
|
||
namespace MySql.Data.MySqlClient | ||
{ | ||
public sealed class MySqlDbBatch : DbBatch | ||
{ | ||
public MySqlDbBatch() | ||
: this(null, null) | ||
{ | ||
} | ||
|
||
public MySqlDbBatch(MySqlConnection connection = null, MySqlTransaction transaction = null) | ||
{ | ||
Connection = connection; | ||
Transaction = transaction; | ||
m_batchCommands = new List<MySqlDbBatchCommand>(); | ||
} | ||
|
||
public new MySqlConnection Connection { get; set; } | ||
public new MySqlTransaction Transaction { get; set; } | ||
|
||
protected override DbConnection DbConnection | ||
{ | ||
get => Connection; | ||
set => Connection = (MySqlConnection) value; | ||
} | ||
|
||
protected override DbTransaction DbTransaction | ||
{ | ||
get => Transaction; | ||
set => Transaction = (MySqlTransaction) value; | ||
} | ||
|
||
protected override IList<DbBatchCommand> DbBatchCommands | ||
{ | ||
get | ||
{ | ||
if (m_dbBatchCommands is null) | ||
m_dbBatchCommands = new DbBatchCommandList(m_batchCommands); | ||
return m_dbBatchCommands; | ||
} | ||
} | ||
|
||
public override DbDataReader ExecuteReader() => throw new NotImplementedException(); | ||
|
||
public override Task<DbDataReader> ExecuteReaderAsync(CancellationToken cancellationToken = default) => throw new NotImplementedException(); | ||
|
||
public override int ExecuteNonQuery() => throw new NotImplementedException(); | ||
|
||
public override Task<int> ExecuteNonQueryAsync(CancellationToken cancellationToken = default) => throw new NotImplementedException(); | ||
|
||
public override object ExecuteScalar() => throw new NotImplementedException(); | ||
|
||
public override Task<object> ExecuteScalarAsync(CancellationToken cancellationToken = default) => throw new NotImplementedException(); | ||
|
||
public override int Timeout { get; set; } | ||
|
||
public override void Prepare() => throw new NotImplementedException(); | ||
|
||
public override Task PrepareAsync(CancellationToken cancellationToken = default) => throw new NotImplementedException(); | ||
|
||
public override void Cancel() => throw new NotImplementedException(); | ||
|
||
public override Task CancelAsync(CancellationToken cancellationToken = default) => throw new NotImplementedException(); | ||
|
||
readonly List<MySqlDbBatchCommand> m_batchCommands; | ||
IList<DbBatchCommand> m_dbBatchCommands; | ||
} | ||
} |
58 changes: 58 additions & 0 deletions
58
src/MySqlConnector/MySql.Data.MySqlClient/MySqlDbBatchCommand.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Data; | ||
using System.Data.Common; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
#if NET45 || NET461 || NET471 || NETSTANDARD1_3 || NETSTANDARD2_0 || NETCOREAPP2_1 | ||
namespace System.Data.Common | ||
{ | ||
public abstract class DbBatchCommand | ||
{ | ||
public abstract string CommandText { get; set; } | ||
public abstract CommandType CommandType { get; set; } | ||
public abstract CommandBehavior CommandBehavior { get; set; } | ||
public abstract int RecordsAffected { get; set; } | ||
|
||
public DbParameterCollection Parameters => DbParameterCollection; | ||
protected abstract DbParameterCollection DbParameterCollection { get; } | ||
} | ||
} | ||
#endif | ||
|
||
namespace MySql.Data.MySqlClient | ||
{ | ||
public sealed class MySqlDbBatchCommand : DbBatchCommand | ||
{ | ||
public MySqlDbBatchCommand() | ||
: this(null) | ||
{ | ||
} | ||
|
||
public MySqlDbBatchCommand(string commandText) | ||
{ | ||
CommandText = commandText; | ||
CommandType = CommandType.Text; | ||
} | ||
|
||
public override string CommandText { get; set; } | ||
public override CommandType CommandType { get; set; } | ||
public override CommandBehavior CommandBehavior { get; set; } | ||
public override int RecordsAffected { get; set; } | ||
protected override DbParameterCollection DbParameterCollection => Parameters; | ||
|
||
public new MySqlParameterCollection Parameters | ||
{ | ||
get | ||
{ | ||
if (m_parameterCollection is null) | ||
m_parameterCollection = new MySqlParameterCollection(); | ||
return m_parameterCollection; | ||
} | ||
} | ||
|
||
MySqlParameterCollection m_parameterCollection; | ||
} | ||
} |