Skip to content

Backport Query space invalidation doesn't work for bulk actions #1959

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 2 commits into from
Jan 6, 2019
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
2 changes: 1 addition & 1 deletion appveyor.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version: 5.1.3.{build}
version: 5.1.4.{build}
image: Visual Studio 2017
environment:
matrix:
Expand Down
2 changes: 1 addition & 1 deletion build-common/NHibernate.props
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<PropertyGroup>
<VersionMajor Condition="'$(VersionMajor)' == ''">5</VersionMajor>
<VersionMinor Condition="'$(VersionMinor)' == ''">1</VersionMinor>
<VersionPatch Condition="'$(VersionPatch)' == ''">3</VersionPatch>
<VersionPatch Condition="'$(VersionPatch)' == ''">4</VersionPatch>
<VersionSuffix Condition="'$(VersionSuffix)' == ''"></VersionSuffix>

<VersionPrefix>$(VersionMajor).$(VersionMinor).$(VersionPatch)</VersionPrefix>
Expand Down
4 changes: 2 additions & 2 deletions build-common/common.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@

<!-- This is used only for build folder -->
<!-- TODO: Either remove or refactor to use NHibernate.props -->
<property name="project.version" value="5.1.3" overwrite="false" />
<property name="project.version.numeric" value="5.1.3" overwrite="false" />
<property name="project.version" value="5.1.4" overwrite="false" />
<property name="project.version.numeric" value="5.1.4" overwrite="false" />

<!-- properties used to connect to database for testing -->
<include buildfile="nhibernate-properties.xml" />
Expand Down
9 changes: 9 additions & 0 deletions releasenotes.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
Build 5.1.4
=============================

Release notes - NHibernate - Version 5.1.4

** Bug

* #1959 Backport Query space invalidation doesn't work for bulk actions

Build 5.1.3
=============================

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
using NHibernate.Cache;
using NHibernate.Cfg;
using NHibernate.Impl;
using NHibernate.Linq;
using NHibernate.Test.SecondLevelCacheTests;
using NSubstitute;
using NUnit.Framework;
Expand Down Expand Up @@ -59,6 +60,7 @@ public async Task InvalidatesEntitiesAsync()

using (var session = OpenSession())
{
//Add Item
using (var tx = session.BeginTransaction())
{
foreach (var i in Enumerable.Range(1, 10))
Expand All @@ -70,6 +72,7 @@ public async Task InvalidatesEntitiesAsync()
await (tx.CommitAsync());
}

//Update Item
using (var tx = session.BeginTransaction())
{
foreach (var i in Enumerable.Range(1, 10))
Expand All @@ -81,6 +84,7 @@ public async Task InvalidatesEntitiesAsync()
await (tx.CommitAsync());
}

//Delete Item
using (var tx = session.BeginTransaction())
{
foreach (var i in Enumerable.Range(1, 10))
Expand All @@ -91,14 +95,44 @@ public async Task InvalidatesEntitiesAsync()

await (tx.CommitAsync());
}

//Update Item using HQL
using (var tx = session.BeginTransaction())
{
await (session.CreateQuery("UPDATE Item SET Name='Test'").ExecuteUpdateAsync());

await (tx.CommitAsync());
}


//Update Item using LINQ
using (var tx = session.BeginTransaction())
{
await (session.Query<Item>()
.UpdateBuilder()
.Set(x => x.Name, "Test")
.UpdateAsync(CancellationToken.None));

await (tx.CommitAsync());
}

//Update Item using SQL
using (var tx = session.BeginTransaction())
{
await (session.CreateSQLQuery("UPDATE Item SET Name='Test'")
.ExecuteUpdateAsync());

await (tx.CommitAsync());
}
}

//Should receive one preinvalidation and one invalidation per commit
//Should receive one preinvalidation per non-DML commit
Assert.That(preInvalidations, Has.Count.EqualTo(3));
Assert.That(preInvalidations, Has.All.Count.EqualTo(1).And.Contains("Item"));

Assert.That(invalidations, Has.Count.EqualTo(3));
Assert.That(invalidations, Has.All.Count.EqualTo(1).And.Contains("Item"));
///...and one invalidation per commit
Assert.That(invalidations, Has.Count.EqualTo(6));
Assert.That(invalidations, Has.All.Contains("Item"));
}

protected override void OnTearDown()
Expand Down
40 changes: 37 additions & 3 deletions src/NHibernate.Test/SecondLevelCacheTest/InvalidationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using NHibernate.Cache;
using NHibernate.Cfg;
using NHibernate.Impl;
using NHibernate.Linq;
using NHibernate.Test.SecondLevelCacheTests;
using NSubstitute;
using NUnit.Framework;
Expand Down Expand Up @@ -47,6 +48,7 @@ public void InvalidatesEntities()

using (var session = OpenSession())
{
//Add Item
using (var tx = session.BeginTransaction())
{
foreach (var i in Enumerable.Range(1, 10))
Expand All @@ -58,6 +60,7 @@ public void InvalidatesEntities()
tx.Commit();
}

//Update Item
using (var tx = session.BeginTransaction())
{
foreach (var i in Enumerable.Range(1, 10))
Expand All @@ -69,6 +72,7 @@ public void InvalidatesEntities()
tx.Commit();
}

//Delete Item
using (var tx = session.BeginTransaction())
{
foreach (var i in Enumerable.Range(1, 10))
Expand All @@ -79,14 +83,44 @@ public void InvalidatesEntities()

tx.Commit();
}

//Update Item using HQL
using (var tx = session.BeginTransaction())
{
session.CreateQuery("UPDATE Item SET Name='Test'").ExecuteUpdate();

tx.Commit();
}


//Update Item using LINQ
using (var tx = session.BeginTransaction())
{
session.Query<Item>()
.UpdateBuilder()
.Set(x => x.Name, "Test")
.Update();

tx.Commit();
}

//Update Item using SQL
using (var tx = session.BeginTransaction())
{
session.CreateSQLQuery("UPDATE Item SET Name='Test'")
.ExecuteUpdate();

tx.Commit();
}
}

//Should receive one preinvalidation and one invalidation per commit
//Should receive one preinvalidation per non-DML commit
Assert.That(preInvalidations, Has.Count.EqualTo(3));
Assert.That(preInvalidations, Has.All.Count.EqualTo(1).And.Contains("Item"));

Assert.That(invalidations, Has.Count.EqualTo(3));
Assert.That(invalidations, Has.All.Count.EqualTo(1).And.Contains("Item"));
///...and one invalidation per commit
Assert.That(invalidations, Has.Count.EqualTo(6));
Assert.That(invalidations, Has.All.Contains("Item"));
}

protected override void OnTearDown()
Expand Down
4 changes: 0 additions & 4 deletions src/NHibernate/Async/Engine/ActionQueue.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,6 @@ private async Task InnerExecuteAsync(IExecutable executable, CancellationToken c
}
finally
{
if (executable.PropertySpaces != null)
{
executedSpaces.UnionWith(executable.PropertySpaces);
}
RegisterCleanupActions(executable);
}
}
Expand Down
8 changes: 4 additions & 4 deletions src/NHibernate/Engine/ActionQueue.cs
Original file line number Diff line number Diff line change
Expand Up @@ -185,10 +185,6 @@ private void InnerExecute(IExecutable executable)
}
finally
{
if (executable.PropertySpaces != null)
{
executedSpaces.UnionWith(executable.PropertySpaces);
}
RegisterCleanupActions(executable);
}
}
Expand All @@ -197,6 +193,10 @@ private void RegisterCleanupActions(IExecutable executable)
{
beforeTransactionProcesses.Register(executable.BeforeTransactionCompletionProcess);
afterTransactionProcesses.Register(executable.AfterTransactionCompletionProcess);
if (executable.PropertySpaces != null)
{
executedSpaces.UnionWith(executable.PropertySpaces);
}
}

/// <summary>
Expand Down