From 01effc3019eebb6c950b954e6e702e79ac00d013 Mon Sep 17 00:00:00 2001 From: maca88 Date: Sun, 29 Sep 2019 17:09:46 +0100 Subject: [PATCH] Upgrade AsyncGenerator to 0.17.1 (#2182) * Use .NET Core for async generation * Add packages.csproj for AsyncGenerator to avoid using nuget --- ReleaseProcedure.txt | 4 +- ShowBuildMenu.bat | 7 +- ShowBuildMenu.sh | 25 ++--- Tools/.gitignore | 11 ++- Tools/actual_msbuild.cmd | 2 +- Tools/packages.config | 13 --- Tools/packages.csproj | 20 ++++ build-common/common.xml | 8 +- default.build | 32 +++--- doc/documentation.build | 2 +- src/AsyncGenerator.yml | 13 ++- src/NHibernate.Test/Ado/BatcherFixture.cs | 10 +- .../Async/Ado/BatcherFixture.cs | 7 +- .../Async/NHSpecificTest/GH1547/Fixture.cs | 6 +- .../NH2898/BinaryFormatterCache.cs | 4 +- .../SchemaValidator/SchemaValidateFixture.cs | 4 +- .../DriverTest/ReflectionBasedDriverTest.cs | 10 +- src/NHibernate.Test/Linq/MathFTests.cs | 6 +- src/NHibernate.Test/NetFxOnlyAttribute.cs | 20 ++++ .../SchemaValidator/SchemaValidateFixture.cs | 4 +- .../UtilityTest/ReflectHelperFixture.cs | 4 +- .../AdoNet/SqlClientBatchingBatcher.cs | 75 +++++++++++++- .../Async/AdoNet/SqlClientBatchingBatcher.cs | 98 ------------------- 23 files changed, 192 insertions(+), 193 deletions(-) delete mode 100644 Tools/packages.config create mode 100644 Tools/packages.csproj create mode 100644 src/NHibernate.Test/NetFxOnlyAttribute.cs delete mode 100644 src/NHibernate/Async/AdoNet/SqlClientBatchingBatcher.cs diff --git a/ReleaseProcedure.txt b/ReleaseProcedure.txt index 753cce5c66a..82ebcc510db 100644 --- a/ReleaseProcedure.txt +++ b/ReleaseProcedure.txt @@ -4,11 +4,11 @@ These are the tasks typically needed to create an official NHibernate release. that is about to happen (as these will show in the milestone). * Create a draft release in Github with GitReleaseManager. If you have used - the NHibernate build menu, it should be available in Tools\gitreleasemanage.x.x.x\ + the NHibernate build menu, it should be available in Tools\gitreleasemanager\x.x.x\ (change x.x.x by its current version in tools). By example: -Tools\gitreleasemanager.0.7.0\tools\GitReleaseManager.exe create -o nhibernate -r nhibernate-core -m 5.1 -u username -p password +Tools\gitreleasemanager\0.7.0\tools\GitReleaseManager.exe create -o nhibernate -r nhibernate-core -m 5.1 -u username -p password (Adjust the -m milestone parameter above, and add "-c branchname" if releasing another branch than master) diff --git a/ShowBuildMenu.bat b/ShowBuildMenu.bat index 9e4dd3d18a6..4bbb640c761 100644 --- a/ShowBuildMenu.bat +++ b/ShowBuildMenu.bat @@ -1,12 +1,16 @@ @echo off pushd %~dp0 +for /f "tokens=* USEBACKQ delims= " %%i in (`findstr /c:"NUnit.Console" "Tools\packages.csproj"`) do set NUNIT_VERSION=%%i +set NUNIT_VERSION=%NUNIT_VERSION:~51% +set NUNIT_VERSION=%NUNIT_VERSION:" />=% + set NANT="%~dp0Tools\nant\bin\NAnt.exe" -t:net-4.0 set BUILD_TOOL_PATH=%~dp0Tools\BuildTool\bin\BuildTool.dll set BUILDTOOL=dotnet %BUILD_TOOL_PATH% set AVAILABLE_CONFIGURATIONS=%~dp0available-test-configurations set CURRENT_CONFIGURATION=%~dp0current-test-configuration -set NUNIT="%~dp0Tools\NUnit.ConsoleRunner.3.10.0\tools\nunit3-console.exe" +set NUNIT="%~dp0Tools\NUnit.ConsoleRunner\%NUNIT_VERSION%\tools\nunit3-console.exe" if not exist %BUILD_TOOL_PATH% ( pushd %~dp0Tools\BuildTool @@ -184,6 +188,7 @@ SET NUNITPLATFORM= goto test-run :test-run +%NANT% common.tools-restore start "nunit3-console" cmd /K %NUNIT% %NUNITPLATFORM% --agents=1 NHibernate.nunit goto main-menu diff --git a/ShowBuildMenu.sh b/ShowBuildMenu.sh index b3e00d4c37a..9d98d5473c8 100755 --- a/ShowBuildMenu.sh +++ b/ShowBuildMenu.sh @@ -12,6 +12,7 @@ LIB_FILES2="" CURRENT_CONFIGURATION="./current-test-configuration" OPTION=0 async_generator_path="" +async_generator_version="" if [ ! -f $BUILD_TOOL_PATH ] then @@ -177,11 +178,11 @@ testRun(){ } generateAsync(){ - dotnet msbuild /t:Restore ./src/NHibernate.sln + dotnet restore ./src/NHibernate.sln getAsyncGeneratorPath cd src - mono ../"$async_generator_path" + dotnet ../"$async_generator_path" cd .. mainMenu @@ -195,27 +196,15 @@ getAsyncGeneratorPath(){ cd Tools - if [ ! -f nuget.exe ] - then - wget https://dist.nuget.org/win-x86-commandline/latest/nuget.exe - fi - - async_generator_path="CSharpAsyncGenerator.CommandLine.$(cat packages.config | grep id=\"CSharpAsyncGenerator.CommandLine | cut -d\" -f4)/tools" + async_generator_version="$(cat packages.csproj | grep Include=\"CSharpAsyncGenerator.CommandLine | cut -d\" -f4)" + async_generator_path="csharpasyncgenerator.commandline/$async_generator_version/tools" if [ ! -d $async_generator_path ] then - mono nuget.exe install + dotnet restore "./packages.csproj" --packages . fi - if [ ! -f $async_generator_path/SQLitePCLRaw.core.dll ] - then - # This "hidden" dependency causes a failure under some Mono setup, add it explicitly - mono nuget.exe install SQLitePCLRaw.core -Version 1.0.0 - cp SQLitePCLRaw.core.1.0.0/lib/net45/SQLitePCLRaw.core.dll $async_generator_path/ - fi - - async_generator_path="Tools/$async_generator_path/AsyncGenerator.CommandLine.exe" - + async_generator_path="Tools/$async_generator_path/netcoreapp2.1/AsyncGenerator.CommandLine.dll" cd .. } diff --git a/Tools/.gitignore b/Tools/.gitignore index 1128a77fed4..f57f34e8809 100644 --- a/Tools/.gitignore +++ b/Tools/.gitignore @@ -1,6 +1,7 @@ nuget.exe -NUnit.* -vswhere.* -CSharpAsyncGenerator.CommandLine.* -gitreleasemanager.* -SQLitePCLRaw.core.* +nunit.* +vswhere/ +csharpasyncgenerator.commandline/ +gitreleasemanager/ +obj/ +microsoft.* diff --git a/Tools/actual_msbuild.cmd b/Tools/actual_msbuild.cmd index 7db65390fe3..7596a39ba5b 100644 --- a/Tools/actual_msbuild.cmd +++ b/Tools/actual_msbuild.cmd @@ -1,6 +1,6 @@ @echo off -for /f "usebackq tokens=*" %%i in (`%~dp0\vswhere.2.1.4\tools\vswhere -latest -products * -requires Microsoft.Component.MSBuild -property installationPath`) do ( +for /f "usebackq tokens=*" %%i in (`%~dp0\vswhere\2.1.4\tools\vswhere -latest -products * -requires Microsoft.Component.MSBuild -property installationPath`) do ( set InstallDir=%%i ) diff --git a/Tools/packages.config b/Tools/packages.config deleted file mode 100644 index d58f2d2e51b..00000000000 --- a/Tools/packages.config +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - - - - - diff --git a/Tools/packages.csproj b/Tools/packages.csproj new file mode 100644 index 00000000000..23590a90970 --- /dev/null +++ b/Tools/packages.csproj @@ -0,0 +1,20 @@ + + + + netcoreapp2.1 + + + + + + + + + + + + + + + + diff --git a/build-common/common.xml b/build-common/common.xml index 26e5302a66d..70c8c685303 100644 --- a/build-common/common.xml +++ b/build-common/common.xml @@ -39,10 +39,10 @@ /> - - - - + + + + diff --git a/default.build b/default.build index 51399f2fc4c..a65ecd04d78 100644 --- a/default.build +++ b/default.build @@ -46,7 +46,7 @@ - + @@ -54,24 +54,24 @@ - + - + file="${tools.dir}/packages.csproj" + xpath="/Project/ItemGroup/PackageReference[@Include = '${tool.id}']/@Version" + property="tool.version" /> + - - - + + + - - + + + + @@ -150,9 +150,9 @@ - - - + + + diff --git a/doc/documentation.build b/doc/documentation.build index 86104ac767b..52cf503cd6d 100644 --- a/doc/documentation.build +++ b/doc/documentation.build @@ -9,7 +9,7 @@ - + diff --git a/src/AsyncGenerator.yml b/src/AsyncGenerator.yml index a4d096948b0..6dbd545a149 100644 --- a/src/AsyncGenerator.yml +++ b/src/AsyncGenerator.yml @@ -1,8 +1,10 @@ projects: - filePath: NHibernate/NHibernate.csproj - targetFramework: net461 + targetFramework: netcoreapp2.0 concurrentRun: true applyChanges: true + suppressDiagnosticFailures: + - pattern: ^.*(Hql\.g).*$ analyzation: methodConversion: - conversion: Ignore @@ -166,17 +168,21 @@ - type: AsyncGenerator.Core.Plugins.EmptyRegionRemover assemblyName: AsyncGenerator.Core - filePath: NHibernate.DomainModel/NHibernate.DomainModel.csproj - targetFramework: net461 + targetFramework: netcoreapp2.0 concurrentRun: true applyChanges: true + suppressDiagnosticFailures: + - pattern: ^.*(Hql\.g).*$ analyzation: scanMethodBody: true scanForMissingAsyncMembers: - all: true - filePath: NHibernate.Test/NHibernate.Test.csproj - targetFramework: net461 + targetFramework: netcoreapp2.0 concurrentRun: true applyChanges: true + suppressDiagnosticFailures: + - pattern: ^.*(Hql\.g).*$ analyzation: methodConversion: - conversion: Copy @@ -198,6 +204,7 @@ rule: IsTestCase - conversion: Ignore anyBaseTypeRule: IsTestCase + executionPhase: PostProviders ignoreDocuments: - filePathEndsWith: Linq/MathTests.cs - filePathEndsWith: Linq/ExpressionSessionLeakTest.cs diff --git a/src/NHibernate.Test/Ado/BatcherFixture.cs b/src/NHibernate.Test/Ado/BatcherFixture.cs index e9f80c182b7..16574a18e0d 100644 --- a/src/NHibernate.Test/Ado/BatcherFixture.cs +++ b/src/NHibernate.Test/Ado/BatcherFixture.cs @@ -90,13 +90,14 @@ public void OneRoundTripUpdate() Cleanup(); } -#if NETFX - [Test, Ignore("Not fixed yet.")] + [Test, Ignore("Not fixed yet."), NetFxOnly] [Description("SqlClient: The batcher should run all different INSERT queries in only one roundtrip.")] public void SqlClientOneRoundTripForUpdateAndInsert() { +#if NETFX if (Sfi.Settings.BatcherFactory is SqlClientBatchingBatcherFactory == false) Assert.Ignore("This test is for SqlClientBatchingBatcher only"); +#endif FillDb(); @@ -129,12 +130,14 @@ public void SqlClientOneRoundTripForUpdateAndInsert() Cleanup(); } - [Test] + [Test, NetFxOnly] [Description("SqlClient: The batcher log output should be formatted")] public void BatchedoutputShouldBeFormatted() { +#if NETFX if (Sfi.Settings.BatcherFactory is SqlClientBatchingBatcherFactory == false) Assert.Ignore("This test is for SqlClientBatchingBatcher only"); +#endif using (var sqlLog = new SqlLogSpy()) { @@ -145,7 +148,6 @@ public void BatchedoutputShouldBeFormatted() Cleanup(); } -#endif [Test] [Description("The batcher should run all DELETE queries in only one roundtrip.")] diff --git a/src/NHibernate.Test/Async/Ado/BatcherFixture.cs b/src/NHibernate.Test/Async/Ado/BatcherFixture.cs index a21e4c918e0..de08b5410d3 100644 --- a/src/NHibernate.Test/Async/Ado/BatcherFixture.cs +++ b/src/NHibernate.Test/Async/Ado/BatcherFixture.cs @@ -102,14 +102,14 @@ public async Task OneRoundTripUpdateAsync() await (CleanupAsync()); } - #if NETFX - - [Test] + [Test, NetFxOnly] [Description("SqlClient: The batcher log output should be formatted")] public async Task BatchedoutputShouldBeFormattedAsync() { +#if NETFX if (Sfi.Settings.BatcherFactory is SqlClientBatchingBatcherFactory == false) Assert.Ignore("This test is for SqlClientBatchingBatcher only"); +#endif using (var sqlLog = new SqlLogSpy()) { @@ -120,7 +120,6 @@ public async Task BatchedoutputShouldBeFormattedAsync() await (CleanupAsync()); } -#endif [Test] [Description("The batcher should run all DELETE queries in only one roundtrip.")] diff --git a/src/NHibernate.Test/Async/NHSpecificTest/GH1547/Fixture.cs b/src/NHibernate.Test/Async/NHSpecificTest/GH1547/Fixture.cs index f55778a975f..a9b6818c04f 100644 --- a/src/NHibernate.Test/Async/NHSpecificTest/GH1547/Fixture.cs +++ b/src/NHibernate.Test/Async/NHSpecificTest/GH1547/Fixture.cs @@ -103,12 +103,12 @@ public async Task LinqWithListParameterPerfAsync() { var query = queryFactory(session); // Warm up. - await (RunBenchmarkUnitAsync(cache, query)); + await (RunBenchmarkUnitAsync(cache, query, cancellationToken)); for (var j = 0; j < 1000; j++) { sw.Restart(); - await (RunBenchmarkUnitAsync(cache, query)); + await (RunBenchmarkUnitAsync(cache, query, cancellationToken)); sw.Stop(); timings.Add(sw.Elapsed.TotalMilliseconds); } @@ -122,7 +122,7 @@ public async Task LinqWithListParameterPerfAsync() $"{test} average time: {avg}ms (s {Math.Sqrt(timings.Sum(t => Math.Pow(t - avg, 2)) / (timings.Count - 1))}ms)"); } - private static Task RunBenchmarkUnitAsync(SoftLimitMRUCache cache, IQueryable query) + private static Task RunBenchmarkUnitAsync(SoftLimitMRUCache cache, IQueryable query, CancellationToken cancellationToken = default(CancellationToken)) { try { diff --git a/src/NHibernate.Test/Async/NHSpecificTest/NH2898/BinaryFormatterCache.cs b/src/NHibernate.Test/Async/NHSpecificTest/NH2898/BinaryFormatterCache.cs index 5fbc3ca0ef7..ef42a49d254 100644 --- a/src/NHibernate.Test/Async/NHSpecificTest/NH2898/BinaryFormatterCache.cs +++ b/src/NHibernate.Test/Async/NHSpecificTest/NH2898/BinaryFormatterCache.cs @@ -34,7 +34,7 @@ public override Task GetAsync(object key, CancellationToken cancellation var fmt = new BinaryFormatter { #if !NETFX - SurrogateSelector = new SerializationHelper.SurrogateSelector() + SurrogateSelector = new SerializationHelper.SurrogateSelector() #endif }; using (var stream = new MemoryStream(entry)) @@ -55,7 +55,7 @@ public override Task PutAsync(object key, object value, CancellationToken cancel var fmt = new BinaryFormatter { #if !NETFX - SurrogateSelector = new SerializationHelper.SurrogateSelector() + SurrogateSelector = new SerializationHelper.SurrogateSelector() #endif }; using (var stream = new MemoryStream()) diff --git a/src/NHibernate.Test/Async/Tools/hbm2ddl/SchemaValidator/SchemaValidateFixture.cs b/src/NHibernate.Test/Async/Tools/hbm2ddl/SchemaValidator/SchemaValidateFixture.cs index a4950e994ba..a8809777bba 100644 --- a/src/NHibernate.Test/Async/Tools/hbm2ddl/SchemaValidator/SchemaValidateFixture.cs +++ b/src/NHibernate.Test/Async/Tools/hbm2ddl/SchemaValidator/SchemaValidateFixture.cs @@ -52,8 +52,7 @@ public async Task ShouldVerifySameTableAsync() await (validator.ValidateAsync()); } -#if NETFX - [Test, SetCulture("tr-TR"), SetUICulture("tr-TR")] + [Test, SetCulture("tr-TR"), SetUICulture("tr-TR"), NetFxOnly] public async Task ShouldVerifySameTableTurkishAsync() { //NH-3063 @@ -81,7 +80,6 @@ public async Task ShouldVerifySameTableTurkishAsync() await (export.DropAsync(true, true)); } } -#endif [Test] public void ShouldNotVerifyModifiedTableAsync() diff --git a/src/NHibernate.Test/DriverTest/ReflectionBasedDriverTest.cs b/src/NHibernate.Test/DriverTest/ReflectionBasedDriverTest.cs index 89a017a1b25..9f57e6c0ac2 100644 --- a/src/NHibernate.Test/DriverTest/ReflectionBasedDriverTest.cs +++ b/src/NHibernate.Test/DriverTest/ReflectionBasedDriverTest.cs @@ -64,20 +64,19 @@ public override string NamedPrefix } } -#if NETFX - [Test] + [Test, NetFxOnly] public void WhenCreatedWithGoodDbProviderThenNotThrows() { Assert.That(() => new MyDriverWithWrongClassesAndGoodDbProviderFactory(), Throws.Nothing); } - [Test] + [Test, NetFxOnly] public void WhenCreatedWithNullAssemblyAndGoodDbProviderThenNotThrows() { Assert.That(() => new MyDriverWithWrongClassesAndGoodDbProviderFactory(null), Throws.Nothing); } - [Test] + [Test, NetFxOnly] public void WhenCreatedWithDbFactoryThenCanReturnConnection() { var provider = new MyDriverWithWrongClassesAndGoodDbProviderFactory(); @@ -87,7 +86,7 @@ public void WhenCreatedWithDbFactoryThenCanReturnConnection() } } - [Test] + [Test, NetFxOnly] public void WhenCreatedWithDbFactoryThenCanReturnCommand() { var provider = new MyDriverWithWrongClassesAndGoodDbProviderFactory(); @@ -96,7 +95,6 @@ public void WhenCreatedWithDbFactoryThenCanReturnCommand() Assert.That(command, Is.Not.Null); } } -#endif [Test] public void WhenCreatedWithNoDbProviderThenNotThrows() diff --git a/src/NHibernate.Test/Linq/MathFTests.cs b/src/NHibernate.Test/Linq/MathFTests.cs index 40a3e759f0d..8dd21f8de24 100644 --- a/src/NHibernate.Test/Linq/MathFTests.cs +++ b/src/NHibernate.Test/Linq/MathFTests.cs @@ -7,7 +7,9 @@ namespace NHibernate.Test.Linq { - [TestFixture] + // [TestFixture] is omitted on purpose: it is not required by NUnit. It is used by the async generator + // to generated async tests. Async tests cannot works for this fixture due to using a non NHibernate + // queryable which will not be supported by NHibernate ToListAsync. public class MathFTests : LinqTestCase { private IQueryable _orderLines; @@ -135,4 +137,4 @@ private void Test(Expression> selector) } } } -#endif \ No newline at end of file +#endif diff --git a/src/NHibernate.Test/NetFxOnlyAttribute.cs b/src/NHibernate.Test/NetFxOnlyAttribute.cs new file mode 100644 index 00000000000..2c4bbed82f6 --- /dev/null +++ b/src/NHibernate.Test/NetFxOnlyAttribute.cs @@ -0,0 +1,20 @@ +using System; +using NUnit.Framework; +using NUnit.Framework.Interfaces; + +namespace NHibernate.Test +{ + public class NetFxOnlyAttribute : Attribute, ITestAction + { + public ActionTargets Targets => ActionTargets.Default; + + public void AfterTest(ITest test) { } + + public void BeforeTest(ITest test) + { +#if !NETFX + Assert.Ignore("This test is only for NETFX."); +#endif + } + } +} diff --git a/src/NHibernate.Test/Tools/hbm2ddl/SchemaValidator/SchemaValidateFixture.cs b/src/NHibernate.Test/Tools/hbm2ddl/SchemaValidator/SchemaValidateFixture.cs index 57e056f0dab..ba8686986b4 100644 --- a/src/NHibernate.Test/Tools/hbm2ddl/SchemaValidator/SchemaValidateFixture.cs +++ b/src/NHibernate.Test/Tools/hbm2ddl/SchemaValidator/SchemaValidateFixture.cs @@ -41,8 +41,7 @@ public void ShouldVerifySameTable() validator.Validate(); } -#if NETFX - [Test, SetCulture("tr-TR"), SetUICulture("tr-TR")] + [Test, SetCulture("tr-TR"), SetUICulture("tr-TR"), NetFxOnly] public void ShouldVerifySameTableTurkish() { //NH-3063 @@ -70,7 +69,6 @@ public void ShouldVerifySameTableTurkish() export.Drop(true, true); } } -#endif [Test] public void ShouldNotVerifyModifiedTable() diff --git a/src/NHibernate.Test/UtilityTest/ReflectHelperFixture.cs b/src/NHibernate.Test/UtilityTest/ReflectHelperFixture.cs index 86aec92ae2e..2f7979afaf0 100644 --- a/src/NHibernate.Test/UtilityTest/ReflectHelperFixture.cs +++ b/src/NHibernate.Test/UtilityTest/ReflectHelperFixture.cs @@ -82,8 +82,7 @@ public void NoTypeFoundReturnsNull() Assert.IsNull(noType); } -#if NETFX - [Test] + [Test, NetFxOnly] public void TypeFoundInNotLoadedAssembly() { System.Type httpRequest = ReflectHelper.TypeFromAssembly("System.Web.HttpRequest", "System.Web", false); @@ -92,7 +91,6 @@ public void TypeFoundInNotLoadedAssembly() System.Type sameType = ReflectHelper.TypeFromAssembly("System.Web.HttpRequest", "System.Web", false); Assert.AreEqual(httpRequest, sameType, "should be the exact same Type"); } -#endif [Test] public void SystemTypes() diff --git a/src/NHibernate/AdoNet/SqlClientBatchingBatcher.cs b/src/NHibernate/AdoNet/SqlClientBatchingBatcher.cs index 61eef67666b..88fd9980ca0 100644 --- a/src/NHibernate/AdoNet/SqlClientBatchingBatcher.cs +++ b/src/NHibernate/AdoNet/SqlClientBatchingBatcher.cs @@ -2,13 +2,15 @@ using System; using System.Data.Common; using System.Text; +using System.Threading; +using System.Threading.Tasks; using NHibernate.AdoNet.Util; using NHibernate.Driver; using NHibernate.Exceptions; namespace NHibernate.AdoNet { - public partial class SqlClientBatchingBatcher : AbstractBatcher + public class SqlClientBatchingBatcher : AbstractBatcher { private int _batchSize; private int _totalExpectedRowsAffected; @@ -70,6 +72,47 @@ public override void AddToBatch(IExpectation expectation) } } + public override Task AddToBatchAsync(IExpectation expectation, CancellationToken cancellationToken) + { + if (cancellationToken.IsCancellationRequested) + { + return Task.FromCanceled(cancellationToken); + } + try + { + _totalExpectedRowsAffected += expectation.ExpectedRowCount; + var batchUpdate = CurrentCommand; + Driver.AdjustCommand(batchUpdate); + string lineWithParameters = null; + var sqlStatementLogger = Factory.Settings.SqlStatementLogger; + if (sqlStatementLogger.IsDebugEnabled || Log.IsDebugEnabled()) + { + lineWithParameters = sqlStatementLogger.GetCommandLineWithParameters(batchUpdate); + var formatStyle = sqlStatementLogger.DetermineActualStyle(FormatStyle.Basic); + lineWithParameters = formatStyle.Formatter.Format(lineWithParameters); + _currentBatchCommandsLog.Append("command ") + .Append(_currentBatch.CountOfCommands) + .Append(":") + .AppendLine(lineWithParameters); + } + if (Log.IsDebugEnabled()) + { + Log.Debug("Adding to batch:{0}", lineWithParameters); + } + _currentBatch.Append((System.Data.SqlClient.SqlCommand) batchUpdate); + + if (_currentBatch.CountOfCommands >= _batchSize) + { + return ExecuteBatchWithTimingAsync(batchUpdate, cancellationToken); + } + return Task.CompletedTask; + } + catch (Exception ex) + { + return Task.FromException(ex); + } + } + protected override void DoExecuteBatch(DbCommand ps) { try @@ -99,6 +142,36 @@ protected override void DoExecuteBatch(DbCommand ps) } } + protected override async Task DoExecuteBatchAsync(DbCommand ps, CancellationToken cancellationToken) + { + cancellationToken.ThrowIfCancellationRequested(); + try + { + Log.Debug("Executing batch"); + await (CheckReadersAsync(cancellationToken)).ConfigureAwait(false); + await (PrepareAsync(_currentBatch.BatchCommand, cancellationToken)).ConfigureAwait(false); + if (Factory.Settings.SqlStatementLogger.IsDebugEnabled) + { + Factory.Settings.SqlStatementLogger.LogBatchCommand(_currentBatchCommandsLog.ToString()); + } + int rowsAffected; + try + { + rowsAffected = _currentBatch.ExecuteNonQuery(); + } + catch (DbException e) + { + throw ADOExceptionHelper.Convert(Factory.SQLExceptionConverter, e, "could not execute batch command."); + } + + Expectations.VerifyOutcomeBatched(_totalExpectedRowsAffected, rowsAffected, ps); + } + finally + { + ClearCurrentBatch(); + } + } + private SqlClientSqlCommandSet CreateConfiguredBatch() { var result = new SqlClientSqlCommandSet(); diff --git a/src/NHibernate/Async/AdoNet/SqlClientBatchingBatcher.cs b/src/NHibernate/Async/AdoNet/SqlClientBatchingBatcher.cs deleted file mode 100644 index c0128ec26ce..00000000000 --- a/src/NHibernate/Async/AdoNet/SqlClientBatchingBatcher.cs +++ /dev/null @@ -1,98 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by AsyncGenerator. -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - - -#if NETFX -using System; -using System.Data.Common; -using System.Text; -using NHibernate.AdoNet.Util; -using NHibernate.Driver; -using NHibernate.Exceptions; - -namespace NHibernate.AdoNet -{ - using System.Threading.Tasks; - using System.Threading; - public partial class SqlClientBatchingBatcher : AbstractBatcher - { - - public override Task AddToBatchAsync(IExpectation expectation, CancellationToken cancellationToken) - { - if (cancellationToken.IsCancellationRequested) - { - return Task.FromCanceled(cancellationToken); - } - try - { - _totalExpectedRowsAffected += expectation.ExpectedRowCount; - var batchUpdate = CurrentCommand; - Driver.AdjustCommand(batchUpdate); - string lineWithParameters = null; - var sqlStatementLogger = Factory.Settings.SqlStatementLogger; - if (sqlStatementLogger.IsDebugEnabled || Log.IsDebugEnabled()) - { - lineWithParameters = sqlStatementLogger.GetCommandLineWithParameters(batchUpdate); - var formatStyle = sqlStatementLogger.DetermineActualStyle(FormatStyle.Basic); - lineWithParameters = formatStyle.Formatter.Format(lineWithParameters); - _currentBatchCommandsLog.Append("command ") - .Append(_currentBatch.CountOfCommands) - .Append(":") - .AppendLine(lineWithParameters); - } - if (Log.IsDebugEnabled()) - { - Log.Debug("Adding to batch:{0}", lineWithParameters); - } - _currentBatch.Append((System.Data.SqlClient.SqlCommand)batchUpdate); - - if (_currentBatch.CountOfCommands >= _batchSize) - { - return ExecuteBatchWithTimingAsync(batchUpdate, cancellationToken); - } - return Task.CompletedTask; - } - catch (Exception ex) - { - return Task.FromException(ex); - } - } - - protected override async Task DoExecuteBatchAsync(DbCommand ps, CancellationToken cancellationToken) - { - cancellationToken.ThrowIfCancellationRequested(); - try - { - Log.Debug("Executing batch"); - await (CheckReadersAsync(cancellationToken)).ConfigureAwait(false); - await (PrepareAsync(_currentBatch.BatchCommand, cancellationToken)).ConfigureAwait(false); - if (Factory.Settings.SqlStatementLogger.IsDebugEnabled) - { - Factory.Settings.SqlStatementLogger.LogBatchCommand(_currentBatchCommandsLog.ToString()); - } - int rowsAffected; - try - { - rowsAffected = _currentBatch.ExecuteNonQuery(); - } - catch (DbException e) - { - throw ADOExceptionHelper.Convert(Factory.SQLExceptionConverter, e, "could not execute batch command."); - } - - Expectations.VerifyOutcomeBatched(_totalExpectedRowsAffected, rowsAffected, ps); - } - finally - { - ClearCurrentBatch(); - } - } - } -} -#endif