Skip to content

Commit be0796e

Browse files
committed
WIP Move cache check from IEntityPersister.IsTransient to ForeignKeys.IsTransientSlow
1 parent ad676cc commit be0796e

File tree

65 files changed

+205
-2622
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

65 files changed

+205
-2622
lines changed

src/NHibernate.DomainModel/Async/CustomPersister.cs

Lines changed: 0 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -34,44 +34,6 @@ public partial class CustomPersister : IEntityPersister
3434

3535
#region IOptimisticCacheSource Members
3636

37-
public Task<int[]> FindDirtyAsync(object[] currentState, object[] previousState, object entity, ISessionImplementor session, CancellationToken cancellationToken)
38-
{
39-
try
40-
{
41-
if (!Equals(currentState[0], previousState[0]))
42-
{
43-
return Task.FromResult<int[]>(new int[] { 0 });
44-
}
45-
else
46-
{
47-
return Task.FromResult<int[]>(null);
48-
}
49-
}
50-
catch (Exception ex)
51-
{
52-
return Task.FromException<int[]>(ex);
53-
}
54-
}
55-
56-
public Task<int[]> FindModifiedAsync(object[] old, object[] current, object entity, ISessionImplementor session, CancellationToken cancellationToken)
57-
{
58-
try
59-
{
60-
if (!Equals(old[0], current[0]))
61-
{
62-
return Task.FromResult<int[]>(new int[] { 0 });
63-
}
64-
else
65-
{
66-
return Task.FromResult<int[]>(null);
67-
}
68-
}
69-
catch (Exception ex)
70-
{
71-
return Task.FromException<int[]>(ex);
72-
}
73-
}
74-
7537
public Task<object[]> GetNaturalIdentifierSnapshotAsync(object id, ISessionImplementor session, CancellationToken cancellationToken)
7638
{
7739
return Task.FromResult<object[]>(null);
@@ -165,18 +127,6 @@ public Task<object> ForceVersionIncrementAsync(object id, object currentVersion,
165127
return Task.FromResult<object>(null);
166128
}
167129

168-
public Task<bool?> IsTransientAsync(object obj, ISessionImplementor session, CancellationToken cancellationToken)
169-
{
170-
try
171-
{
172-
return Task.FromResult<bool?>(((Custom) obj).Id == null);
173-
}
174-
catch (Exception ex)
175-
{
176-
return Task.FromException<bool?>(ex);
177-
}
178-
}
179-
180130
public Task ProcessInsertGeneratedPropertiesAsync(object id, object entity, object[] state, ISessionImplementor session, CancellationToken cancellationToken)
181131
{
182132
return Task.CompletedTask;

src/NHibernate.Test/Async/NHSpecificTest/GH1486/Fixture.cs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
namespace NHibernate.Test.NHSpecificTest.GH1486
1717
{
1818
using System.Threading.Tasks;
19-
using System.Threading;
2019
[TestFixture]
2120
public class FixtureAsync : BugTestCase
2221
{
@@ -142,12 +141,12 @@ public async Task TestDirectCallToIsModifiedAsync()
142141

143142
var checkable = new [] { true, true, true };
144143
Assert.That(
145-
() => componentType.IsModifiedAsync(new object[] { "", "", "" }, person.Address, checkable, sessionImplementor, CancellationToken.None),
144+
() => componentType.IsModified(new object[] { "", "", "" }, person.Address, checkable, sessionImplementor),
146145
Throws.Nothing,
147146
"Checking component against an array snapshot failed");
148-
var isModified = await (componentType.IsModifiedAsync(person.Address, person.Address, checkable, sessionImplementor, CancellationToken.None));
147+
var isModified = componentType.IsModified(person.Address, person.Address, checkable, sessionImplementor);
149148
Assert.That(isModified, Is.False, "Checking same component failed");
150-
isModified = await (componentType.IsModifiedAsync(new Address("1", "A", "B"), person.Address, checkable, sessionImplementor, CancellationToken.None));
149+
isModified = componentType.IsModified(new Address("1", "A", "B"), person.Address, checkable, sessionImplementor);
151150
Assert.That(isModified, Is.False, "Checking equal component failed");
152151
}
153152
await (transaction.RollbackAsync());

src/NHibernate.Test/Async/NHSpecificTest/GH1496/AuditEventListener.cs

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,20 +18,28 @@ namespace NHibernate.Test.NHSpecificTest.GH1496
1818
public partial class AuditEventListener : IPostUpdateEventListener
1919
{
2020

21-
public async Task OnPostUpdateAsync(PostUpdateEvent @event, CancellationToken cancellationToken)
21+
public Task OnPostUpdateAsync(PostUpdateEvent @event, CancellationToken cancellationToken)
2222
{
23-
if (isActive == false)
24-
{ return; }
25-
26-
var modifiedItems = await (@event.Persister.FindModifiedAsync(@event.OldState, @event.State, @event.Entity, @event.Session, cancellationToken));
27-
foreach (int index in modifiedItems)
23+
try
2824
{
29-
ModifiedItems.Add(new Item
25+
if (isActive == false)
26+
{ return Task.CompletedTask; }
27+
28+
var modifiedItems = @event.Persister.FindModified(@event.OldState, @event.State, @event.Entity, @event.Session);
29+
foreach (int index in modifiedItems)
30+
{
31+
ModifiedItems.Add(new Item
3032
{
3133
Index = index,
3234
OldState = @event.OldState[index],
3335
State = @event.State[index]
3436
});
37+
}
38+
return Task.CompletedTask;
39+
}
40+
catch (System.Exception ex)
41+
{
42+
return Task.FromException<object>(ex);
3543
}
3644
}
3745
}

src/NHibernate.Test/Async/TypesTest/Int64TypeFixture.cs

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -41,21 +41,6 @@ public async Task SeedAsync()
4141
Assert.IsTrue(await (type.SeedAsync(null, CancellationToken.None)) is Int64, "seed should be int64");
4242
}
4343

44-
[Test]
45-
public async Task NullableWrapperDirtyAsync()
46-
{
47-
Int64Type type = NHibernateUtil.Int64;
48-
49-
long? nullLong = null;
50-
long? valueLong = 5;
51-
long? fiveAgain = 5;
52-
using (ISession s = OpenSession())
53-
{
54-
Assert.IsTrue(await (type.IsDirtyAsync(nullLong, valueLong, (ISessionImplementor)s, CancellationToken.None)), "should be dirty - null to '5'");
55-
Assert.IsFalse(await (type.IsDirtyAsync(valueLong, fiveAgain, (ISessionImplementor)s, CancellationToken.None)), "should not be dirty - 5 to 5");
56-
}
57-
}
58-
5944
protected override string[] Mappings => Array.Empty<string>();
6045
}
6146
}

src/NHibernate/Async/Collection/AbstractPersistentCollection.cs

Lines changed: 4 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -185,15 +185,15 @@ protected virtual async Task<ICollection> GetOrphansAsync(ICollection oldElement
185185
{
186186
if (current != null && await (ForeignKeys.IsNotTransientSlowAsync(entityName, current, session, cancellationToken)).ConfigureAwait(false))
187187
{
188-
object currentId = await (ForeignKeys.GetEntityIdentifierIfNotUnsavedAsync(entityName, current, session, cancellationToken)).ConfigureAwait(false);
188+
object currentId = ForeignKeys.GetEntityIdentifierIfNotUnsaved(entityName, current, session);
189189
currentIds.Add(new TypedValue(idType, currentId, false));
190190
}
191191
}
192192

193193
// iterate over the *old* list
194194
foreach (object old in oldElements)
195195
{
196-
object oldId = await (ForeignKeys.GetEntityIdentifierIfNotUnsavedAsync(entityName, old, session, cancellationToken)).ConfigureAwait(false);
196+
object oldId = ForeignKeys.GetEntityIdentifierIfNotUnsaved(entityName, old, session);
197197
if (!currentIds.Contains(new TypedValue(idType, oldId, false)))
198198
{
199199
res.Add(old);
@@ -210,15 +210,15 @@ public async Task IdentityRemoveAsync(IList list, object obj, string entityName,
210210
{
211211
IType idType = session.Factory.GetEntityPersister(entityName).IdentifierType;
212212

213-
object idOfCurrent = await (ForeignKeys.GetEntityIdentifierIfNotUnsavedAsync(entityName, obj, session, cancellationToken)).ConfigureAwait(false);
213+
object idOfCurrent = ForeignKeys.GetEntityIdentifierIfNotUnsaved(entityName, obj, session);
214214
List<object> toRemove = new List<object>(list.Count);
215215
foreach (object current in list)
216216
{
217217
if (current == null)
218218
{
219219
continue;
220220
}
221-
object idOfOld = await (ForeignKeys.GetEntityIdentifierIfNotUnsavedAsync(entityName, current, session, cancellationToken)).ConfigureAwait(false);
221+
object idOfOld = ForeignKeys.GetEntityIdentifierIfNotUnsaved(entityName, current, session);
222222
if (idType.IsEqual(idOfCurrent, idOfOld, session.Factory))
223223
{
224224
toRemove.Add(current);
@@ -239,13 +239,6 @@ public async Task IdentityRemoveAsync(IList list, object obj, string entityName,
239239
/// <returns></returns>
240240
public abstract Task<object> DisassembleAsync(ICollectionPersister persister, CancellationToken cancellationToken);
241241

242-
/// <summary>
243-
/// Get all the elements that need deleting
244-
/// </summary>
245-
public abstract Task<IEnumerable> GetDeletesAsync(ICollectionPersister persister, bool indexIsFormula, CancellationToken cancellationToken);
246-
247-
public abstract Task<bool> EqualsSnapshotAsync(ICollectionPersister persister, CancellationToken cancellationToken);
248-
249242
/// <summary>
250243
/// Read the state of the collection from a disassembled cached value.
251244
/// </summary>
@@ -255,16 +248,6 @@ public async Task IdentityRemoveAsync(IList list, object obj, string entityName,
255248
/// <param name="cancellationToken">A cancellation token that can be used to cancel the work</param>
256249
public abstract Task InitializeFromCacheAsync(ICollectionPersister persister, object disassembled, object owner, CancellationToken cancellationToken);
257250

258-
/// <summary>
259-
/// Do we need to update this element?
260-
/// </summary>
261-
/// <param name="entry"></param>
262-
/// <param name="i"></param>
263-
/// <param name="elemType"></param>
264-
/// <param name="cancellationToken">A cancellation token that can be used to cancel the work</param>
265-
/// <returns></returns>
266-
public abstract Task<bool> NeedsUpdatingAsync(object entry, int i, IType elemType, CancellationToken cancellationToken);
267-
268251
/// <summary>
269252
/// Reads the row from the <see cref="DbDataReader"/>.
270253
/// </summary>
@@ -276,15 +259,5 @@ public async Task IdentityRemoveAsync(IList list, object obj, string entityName,
276259
/// <returns>The object that was contained in the row.</returns>
277260
public abstract Task<object> ReadFromAsync(DbDataReader reader, ICollectionPersister role, ICollectionAliases descriptor,
278261
object owner, CancellationToken cancellationToken);
279-
280-
/// <summary>
281-
/// Do we need to insert this element?
282-
/// </summary>
283-
/// <param name="entry"></param>
284-
/// <param name="i"></param>
285-
/// <param name="elemType"></param>
286-
/// <param name="cancellationToken">A cancellation token that can be used to cancel the work</param>
287-
/// <returns></returns>
288-
public abstract Task<bool> NeedsInsertingAsync(object entry, int i, IType elemType, CancellationToken cancellationToken);
289262
}
290263
}

src/NHibernate/Async/Collection/Generic/PersistentGenericBag.cs

Lines changed: 0 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -44,38 +44,6 @@ public override async Task<object> DisassembleAsync(ICollectionPersister persist
4444
return result;
4545
}
4646

47-
public override Task<bool> EqualsSnapshotAsync(ICollectionPersister persister, CancellationToken cancellationToken)
48-
{
49-
if (cancellationToken.IsCancellationRequested)
50-
{
51-
return Task.FromCanceled<bool>(cancellationToken);
52-
}
53-
try
54-
{
55-
return Task.FromResult<bool>(EqualsSnapshot(persister));
56-
}
57-
catch (Exception ex)
58-
{
59-
return Task.FromException<bool>(ex);
60-
}
61-
}
62-
63-
public override Task<IEnumerable> GetDeletesAsync(ICollectionPersister persister, bool indexIsFormula, CancellationToken cancellationToken)
64-
{
65-
if (cancellationToken.IsCancellationRequested)
66-
{
67-
return Task.FromCanceled<IEnumerable>(cancellationToken);
68-
}
69-
try
70-
{
71-
return Task.FromResult<IEnumerable>(GetDeletes(persister, indexIsFormula));
72-
}
73-
catch (Exception ex)
74-
{
75-
return Task.FromException<IEnumerable>(ex);
76-
}
77-
}
78-
7947
public override Task<ICollection> GetOrphansAsync(object snapshot, string entityName, CancellationToken cancellationToken)
8048
{
8149
if (cancellationToken.IsCancellationRequested)
@@ -116,38 +84,6 @@ public override async Task InitializeFromCacheAsync(ICollectionPersister persist
11684
}
11785
}
11886

119-
public override Task<bool> NeedsInsertingAsync(object entry, int i, IType elemType, CancellationToken cancellationToken)
120-
{
121-
if (cancellationToken.IsCancellationRequested)
122-
{
123-
return Task.FromCanceled<bool>(cancellationToken);
124-
}
125-
try
126-
{
127-
return Task.FromResult<bool>(NeedsInserting(entry, i, elemType));
128-
}
129-
catch (Exception ex)
130-
{
131-
return Task.FromException<bool>(ex);
132-
}
133-
}
134-
135-
public override Task<bool> NeedsUpdatingAsync(object entry, int i, IType elemType, CancellationToken cancellationToken)
136-
{
137-
if (cancellationToken.IsCancellationRequested)
138-
{
139-
return Task.FromCanceled<bool>(cancellationToken);
140-
}
141-
try
142-
{
143-
return Task.FromResult<bool>(NeedsUpdating(entry, i, elemType));
144-
}
145-
catch (Exception ex)
146-
{
147-
return Task.FromException<bool>(ex);
148-
}
149-
}
150-
15187
public override async Task<object> ReadFromAsync(DbDataReader reader, ICollectionPersister role, ICollectionAliases descriptor, object owner, CancellationToken cancellationToken)
15288
{
15389
cancellationToken.ThrowIfCancellationRequested();

src/NHibernate/Async/Collection/Generic/PersistentGenericIdentifierBag.cs

Lines changed: 0 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -66,80 +66,6 @@ public override async Task<object> DisassembleAsync(ICollectionPersister persist
6666
return result;
6767
}
6868

69-
public override async Task<bool> EqualsSnapshotAsync(ICollectionPersister persister, CancellationToken cancellationToken)
70-
{
71-
cancellationToken.ThrowIfCancellationRequested();
72-
IType elementType = persister.ElementType;
73-
var snap = (ISet<SnapshotElement>)GetSnapshot();
74-
if (snap.Count != _values.Count)
75-
{
76-
return false;
77-
}
78-
for (int i = 0; i < _values.Count; i++)
79-
{
80-
object val = _values[i];
81-
object id = GetIdentifier(i);
82-
object old = snap.Where(x => Equals(x.Id, id)).Select(x => x.Value).FirstOrDefault();
83-
if (await (elementType.IsDirtyAsync(old, val, Session, cancellationToken)).ConfigureAwait(false))
84-
{
85-
return false;
86-
}
87-
}
88-
89-
return true;
90-
}
91-
92-
public override Task<IEnumerable> GetDeletesAsync(ICollectionPersister persister, bool indexIsFormula, CancellationToken cancellationToken)
93-
{
94-
if (cancellationToken.IsCancellationRequested)
95-
{
96-
return Task.FromCanceled<IEnumerable>(cancellationToken);
97-
}
98-
try
99-
{
100-
return Task.FromResult<IEnumerable>(GetDeletes(persister, indexIsFormula));
101-
}
102-
catch (Exception ex)
103-
{
104-
return Task.FromException<IEnumerable>(ex);
105-
}
106-
}
107-
108-
public override Task<bool> NeedsInsertingAsync(object entry, int i, IType elemType, CancellationToken cancellationToken)
109-
{
110-
if (cancellationToken.IsCancellationRequested)
111-
{
112-
return Task.FromCanceled<bool>(cancellationToken);
113-
}
114-
try
115-
{
116-
return Task.FromResult<bool>(NeedsInserting(entry, i, elemType));
117-
}
118-
catch (Exception ex)
119-
{
120-
return Task.FromException<bool>(ex);
121-
}
122-
}
123-
124-
public override async Task<bool> NeedsUpdatingAsync(object entry, int i, IType elemType, CancellationToken cancellationToken)
125-
{
126-
cancellationToken.ThrowIfCancellationRequested();
127-
if (entry == null)
128-
{
129-
return false;
130-
}
131-
var snap = (ISet<SnapshotElement>)GetSnapshot();
132-
133-
object id = GetIdentifier(i);
134-
if (id == null)
135-
{
136-
return false;
137-
}
138-
139-
object old = snap.Where(x => Equals(x.Id, id)).Select(x => x.Value).FirstOrDefault();
140-
return old != null && await (elemType.IsDirtyAsync(old, entry, Session, cancellationToken)).ConfigureAwait(false);
141-
}
142-
14369
public override async Task<object> ReadFromAsync(DbDataReader reader, ICollectionPersister persister, ICollectionAliases descriptor, object owner, CancellationToken cancellationToken)
14470
{
14571
cancellationToken.ThrowIfCancellationRequested();

0 commit comments

Comments
 (0)