Skip to content

Set MySqlClientBatchingBatcher as a default batcher for MySqlDataDriver #1600

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Mar 10, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/NHibernate/AdoNet/MySqlClientBatchingBatcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ protected override int CountOfStatementsInCurrentBatch

public override void AddToBatch(IExpectation expectation)
{
// MySql batcher cannot be initiated if a data reader is still open: check them.
if (CountOfStatementsInCurrentBatch == 0)
CheckReaders();

totalExpectedRowsAffected += expectation.ExpectedRowCount;
var batchUpdate = CurrentCommand;
Prepare(batchUpdate);
Expand Down
17 changes: 5 additions & 12 deletions src/NHibernate/AdoNet/MySqlClientSqlCommandSet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,24 +51,17 @@ public void Dispose()

public int ExecuteNonQuery()
{
try
if (CountOfCommands == 0)
{
if (CountOfCommands == 0)
{
return 0;
}

return doExecuteNonQuery(instance);
}
catch (Exception exception)
{
throw new HibernateException("An exception occured when executing batch queries", exception);
return 0;
}

return doExecuteNonQuery(instance);
}

public int CountOfCommands
{
get { return countOfCommands; }
}
}
}
}
4 changes: 4 additions & 0 deletions src/NHibernate/Async/AdoNet/MySqlClientBatchingBatcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ public partial class MySqlClientBatchingBatcher : AbstractBatcher
public override async Task AddToBatchAsync(IExpectation expectation, CancellationToken cancellationToken)
{
cancellationToken.ThrowIfCancellationRequested();
// MySql batcher cannot be initiated if a data reader is still open: check them.
if (CountOfStatementsInCurrentBatch == 0)
await (CheckReadersAsync(cancellationToken)).ConfigureAwait(false);

totalExpectedRowsAffected += expectation.ExpectedRowCount;
var batchUpdate = CurrentCommand;
await (PrepareAsync(batchUpdate, cancellationToken)).ConfigureAwait(false);
Expand Down
5 changes: 4 additions & 1 deletion src/NHibernate/Driver/MySqlDataDriver.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using NHibernate.AdoNet;

namespace NHibernate.Driver
{
Expand All @@ -16,7 +17,7 @@ namespace NHibernate.Driver
/// for any updates and/or documentation regarding MySQL.
/// </para>
/// </remarks>
public class MySqlDataDriver : ReflectionBasedDriver
public class MySqlDataDriver : ReflectionBasedDriver, IEmbeddedBatcherFactoryProvider
{
/// <summary>
/// Initializes a new instance of the <see cref="MySqlDataDriver"/> class.
Expand Down Expand Up @@ -95,5 +96,7 @@ public override bool SupportsMultipleQueries
// https://dev.mysql.com/doc/refman/5.7/en/datetime.html
/// <inheritdoc />
public override DateTime MinDate => new DateTime(1000, 1, 1);

System.Type IEmbeddedBatcherFactoryProvider.BatcherFactoryClass => typeof(MySqlClientBatchingBatcherFactory);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shall this be guarded by #if NETFX?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems not. It's ok then.

}
}