Skip to content

Commit 9514cd2

Browse files
authored
Merge pull request #1600 from fredericDelaporte/MySqlBatcher
Set MySqlClientBatchingBatcher as a default batcher for MySqlDataDriver
2 parents 3757ff6 + 2099f0b commit 9514cd2

File tree

4 files changed

+17
-13
lines changed

4 files changed

+17
-13
lines changed

src/NHibernate/AdoNet/MySqlClientBatchingBatcher.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,10 @@ protected override int CountOfStatementsInCurrentBatch
3939

4040
public override void AddToBatch(IExpectation expectation)
4141
{
42+
// MySql batcher cannot be initiated if a data reader is still open: check them.
43+
if (CountOfStatementsInCurrentBatch == 0)
44+
CheckReaders();
45+
4246
totalExpectedRowsAffected += expectation.ExpectedRowCount;
4347
var batchUpdate = CurrentCommand;
4448
Prepare(batchUpdate);

src/NHibernate/AdoNet/MySqlClientSqlCommandSet.cs

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -51,24 +51,17 @@ public void Dispose()
5151

5252
public int ExecuteNonQuery()
5353
{
54-
try
54+
if (CountOfCommands == 0)
5555
{
56-
if (CountOfCommands == 0)
57-
{
58-
return 0;
59-
}
60-
61-
return doExecuteNonQuery(instance);
62-
}
63-
catch (Exception exception)
64-
{
65-
throw new HibernateException("An exception occured when executing batch queries", exception);
56+
return 0;
6657
}
58+
59+
return doExecuteNonQuery(instance);
6760
}
6861

6962
public int CountOfCommands
7063
{
7164
get { return countOfCommands; }
7265
}
7366
}
74-
}
67+
}

src/NHibernate/Async/AdoNet/MySqlClientBatchingBatcher.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@ public partial class MySqlClientBatchingBatcher : AbstractBatcher
2424
public override async Task AddToBatchAsync(IExpectation expectation, CancellationToken cancellationToken)
2525
{
2626
cancellationToken.ThrowIfCancellationRequested();
27+
// MySql batcher cannot be initiated if a data reader is still open: check them.
28+
if (CountOfStatementsInCurrentBatch == 0)
29+
await (CheckReadersAsync(cancellationToken)).ConfigureAwait(false);
30+
2731
totalExpectedRowsAffected += expectation.ExpectedRowCount;
2832
var batchUpdate = CurrentCommand;
2933
await (PrepareAsync(batchUpdate, cancellationToken)).ConfigureAwait(false);

src/NHibernate/Driver/MySqlDataDriver.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System;
2+
using NHibernate.AdoNet;
23

34
namespace NHibernate.Driver
45
{
@@ -16,7 +17,7 @@ namespace NHibernate.Driver
1617
/// for any updates and/or documentation regarding MySQL.
1718
/// </para>
1819
/// </remarks>
19-
public class MySqlDataDriver : ReflectionBasedDriver
20+
public class MySqlDataDriver : ReflectionBasedDriver, IEmbeddedBatcherFactoryProvider
2021
{
2122
/// <summary>
2223
/// Initializes a new instance of the <see cref="MySqlDataDriver"/> class.
@@ -95,5 +96,7 @@ public override bool SupportsMultipleQueries
9596
// https://dev.mysql.com/doc/refman/5.7/en/datetime.html
9697
/// <inheritdoc />
9798
public override DateTime MinDate => new DateTime(1000, 1, 1);
99+
100+
System.Type IEmbeddedBatcherFactoryProvider.BatcherFactoryClass => typeof(MySqlClientBatchingBatcherFactory);
98101
}
99102
}

0 commit comments

Comments
 (0)