Skip to content

Commit 9ac4809

Browse files
Merge pull request #1959 from fredericDelaporte/QuerySpaceDml
Backport Query space invalidation doesn't work for bulk actions
2 parents 190fe3c + 5a09c7f commit 9ac4809

File tree

8 files changed

+91
-18
lines changed

8 files changed

+91
-18
lines changed

appveyor.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
version: 5.1.3.{build}
1+
version: 5.1.4.{build}
22
image: Visual Studio 2017
33
environment:
44
matrix:

build-common/NHibernate.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<PropertyGroup>
33
<VersionMajor Condition="'$(VersionMajor)' == ''">5</VersionMajor>
44
<VersionMinor Condition="'$(VersionMinor)' == ''">1</VersionMinor>
5-
<VersionPatch Condition="'$(VersionPatch)' == ''">3</VersionPatch>
5+
<VersionPatch Condition="'$(VersionPatch)' == ''">4</VersionPatch>
66
<VersionSuffix Condition="'$(VersionSuffix)' == ''"></VersionSuffix>
77

88
<VersionPrefix>$(VersionMajor).$(VersionMinor).$(VersionPatch)</VersionPrefix>

build-common/common.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313

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

1919
<!-- properties used to connect to database for testing -->
2020
<include buildfile="nhibernate-properties.xml" />

releasenotes.txt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1+
Build 5.1.4
2+
=============================
3+
4+
Release notes - NHibernate - Version 5.1.4
5+
6+
** Bug
7+
8+
* #1959 Backport Query space invalidation doesn't work for bulk actions
9+
110
Build 5.1.3
211
=============================
312

src/NHibernate.Test/Async/SecondLevelCacheTest/InvalidationTests.cs

Lines changed: 37 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
using NHibernate.Cache;
1616
using NHibernate.Cfg;
1717
using NHibernate.Impl;
18+
using NHibernate.Linq;
1819
using NHibernate.Test.SecondLevelCacheTests;
1920
using NSubstitute;
2021
using NUnit.Framework;
@@ -59,6 +60,7 @@ public async Task InvalidatesEntitiesAsync()
5960

6061
using (var session = OpenSession())
6162
{
63+
//Add Item
6264
using (var tx = session.BeginTransaction())
6365
{
6466
foreach (var i in Enumerable.Range(1, 10))
@@ -70,6 +72,7 @@ public async Task InvalidatesEntitiesAsync()
7072
await (tx.CommitAsync());
7173
}
7274

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

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

9296
await (tx.CommitAsync());
9397
}
98+
99+
//Update Item using HQL
100+
using (var tx = session.BeginTransaction())
101+
{
102+
await (session.CreateQuery("UPDATE Item SET Name='Test'").ExecuteUpdateAsync());
103+
104+
await (tx.CommitAsync());
105+
}
106+
107+
108+
//Update Item using LINQ
109+
using (var tx = session.BeginTransaction())
110+
{
111+
await (session.Query<Item>()
112+
.UpdateBuilder()
113+
.Set(x => x.Name, "Test")
114+
.UpdateAsync(CancellationToken.None));
115+
116+
await (tx.CommitAsync());
117+
}
118+
119+
//Update Item using SQL
120+
using (var tx = session.BeginTransaction())
121+
{
122+
await (session.CreateSQLQuery("UPDATE Item SET Name='Test'")
123+
.ExecuteUpdateAsync());
124+
125+
await (tx.CommitAsync());
126+
}
94127
}
95128

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

100-
Assert.That(invalidations, Has.Count.EqualTo(3));
101-
Assert.That(invalidations, Has.All.Count.EqualTo(1).And.Contains("Item"));
133+
///...and one invalidation per commit
134+
Assert.That(invalidations, Has.Count.EqualTo(6));
135+
Assert.That(invalidations, Has.All.Contains("Item"));
102136
}
103137

104138
protected override void OnTearDown()

src/NHibernate.Test/SecondLevelCacheTest/InvalidationTests.cs

Lines changed: 37 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using NHibernate.Cache;
66
using NHibernate.Cfg;
77
using NHibernate.Impl;
8+
using NHibernate.Linq;
89
using NHibernate.Test.SecondLevelCacheTests;
910
using NSubstitute;
1011
using NUnit.Framework;
@@ -47,6 +48,7 @@ public void InvalidatesEntities()
4748

4849
using (var session = OpenSession())
4950
{
51+
//Add Item
5052
using (var tx = session.BeginTransaction())
5153
{
5254
foreach (var i in Enumerable.Range(1, 10))
@@ -58,6 +60,7 @@ public void InvalidatesEntities()
5860
tx.Commit();
5961
}
6062

63+
//Update Item
6164
using (var tx = session.BeginTransaction())
6265
{
6366
foreach (var i in Enumerable.Range(1, 10))
@@ -69,6 +72,7 @@ public void InvalidatesEntities()
6972
tx.Commit();
7073
}
7174

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

8084
tx.Commit();
8185
}
86+
87+
//Update Item using HQL
88+
using (var tx = session.BeginTransaction())
89+
{
90+
session.CreateQuery("UPDATE Item SET Name='Test'").ExecuteUpdate();
91+
92+
tx.Commit();
93+
}
94+
95+
96+
//Update Item using LINQ
97+
using (var tx = session.BeginTransaction())
98+
{
99+
session.Query<Item>()
100+
.UpdateBuilder()
101+
.Set(x => x.Name, "Test")
102+
.Update();
103+
104+
tx.Commit();
105+
}
106+
107+
//Update Item using SQL
108+
using (var tx = session.BeginTransaction())
109+
{
110+
session.CreateSQLQuery("UPDATE Item SET Name='Test'")
111+
.ExecuteUpdate();
112+
113+
tx.Commit();
114+
}
82115
}
83116

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

88-
Assert.That(invalidations, Has.Count.EqualTo(3));
89-
Assert.That(invalidations, Has.All.Count.EqualTo(1).And.Contains("Item"));
121+
///...and one invalidation per commit
122+
Assert.That(invalidations, Has.Count.EqualTo(6));
123+
Assert.That(invalidations, Has.All.Contains("Item"));
90124
}
91125

92126
protected override void OnTearDown()

src/NHibernate/Async/Engine/ActionQueue.cs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -82,10 +82,6 @@ private async Task InnerExecuteAsync(IExecutable executable, CancellationToken c
8282
}
8383
finally
8484
{
85-
if (executable.PropertySpaces != null)
86-
{
87-
executedSpaces.UnionWith(executable.PropertySpaces);
88-
}
8985
RegisterCleanupActions(executable);
9086
}
9187
}

src/NHibernate/Engine/ActionQueue.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -185,10 +185,6 @@ private void InnerExecute(IExecutable executable)
185185
}
186186
finally
187187
{
188-
if (executable.PropertySpaces != null)
189-
{
190-
executedSpaces.UnionWith(executable.PropertySpaces);
191-
}
192188
RegisterCleanupActions(executable);
193189
}
194190
}
@@ -197,6 +193,10 @@ private void RegisterCleanupActions(IExecutable executable)
197193
{
198194
beforeTransactionProcesses.Register(executable.BeforeTransactionCompletionProcess);
199195
afterTransactionProcesses.Register(executable.AfterTransactionCompletionProcess);
196+
if (executable.PropertySpaces != null)
197+
{
198+
executedSpaces.UnionWith(executable.PropertySpaces);
199+
}
200200
}
201201

202202
/// <summary>

0 commit comments

Comments
 (0)