Skip to content

Commit c78320a

Browse files
committed
Remove transient check completly
1 parent a39c14a commit c78320a

9 files changed

+8
-112
lines changed

src/NHibernate/Async/Collection/AbstractPersistentCollection.cs

Lines changed: 0 additions & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -93,41 +93,6 @@ public virtual Task ForceInitializationAsync(CancellationToken cancellationToken
9393
return Task.CompletedTask;
9494
}
9595

96-
public Task<ICollection> GetQueuedOrphansAsync(string entityName, CancellationToken cancellationToken)
97-
{
98-
if (cancellationToken.IsCancellationRequested)
99-
{
100-
return Task.FromCanceled<ICollection>(cancellationToken);
101-
}
102-
try
103-
{
104-
if (HasQueuedOperations)
105-
{
106-
List<object> additions = new List<object>(operationQueue.Count);
107-
List<object> removals = new List<object>(operationQueue.Count);
108-
for (int i = 0; i < operationQueue.Count; i++)
109-
{
110-
IDelayedOperation op = operationQueue[i];
111-
if (op.AddedInstance != null)
112-
{
113-
additions.Add(op.AddedInstance);
114-
}
115-
if (op.Orphan != null)
116-
{
117-
removals.Add(op.Orphan);
118-
}
119-
}
120-
return GetOrphansAsync(removals, additions, entityName, session, cancellationToken);
121-
}
122-
123-
return Task.FromResult<ICollection>(CollectionHelper.EmptyCollection);
124-
}
125-
catch (Exception ex)
126-
{
127-
return Task.FromException<ICollection>(ex);
128-
}
129-
}
130-
13196
/// <summary>
13297
/// Called before inserting rows, to ensure that any surrogate keys are fully generated
13398
/// </summary>
@@ -155,63 +120,6 @@ public virtual Task PreInsertAsync(ICollectionPersister persister, CancellationT
155120
/// </summary>
156121
public abstract Task<ICollection> GetOrphansAsync(object snapshot, string entityName, CancellationToken cancellationToken);
157122

158-
/// <summary>
159-
/// Given a collection of entity instances that used to
160-
/// belong to the collection, and a collection of instances
161-
/// that currently belong, return a collection of orphans
162-
/// </summary>
163-
protected virtual async Task<ICollection> GetOrphansAsync(ICollection oldElements, ICollection currentElements, string entityName, ISessionImplementor session, CancellationToken cancellationToken)
164-
{
165-
cancellationToken.ThrowIfCancellationRequested();
166-
// short-circuit(s)
167-
if (currentElements.Count == 0)
168-
{
169-
// no new elements, the old list contains only Orphans
170-
return oldElements;
171-
}
172-
if (oldElements.Count == 0)
173-
{
174-
// no old elements, so no Orphans neither
175-
return oldElements;
176-
}
177-
178-
if (currentElements.Cast<object>().SequenceEqual(oldElements.Cast<object>()))
179-
return Array.Empty<object>();
180-
181-
var persister = session.Factory.GetEntityPersister(entityName);
182-
IType idType = persister.IdentifierType;
183-
184-
var currentObjects = new HashSet<object>(idType.GetComparer());
185-
foreach (object current in currentElements)
186-
{
187-
if (current != null)
188-
{
189-
var id = persister.GetIdentifier(current);
190-
if (id != null)
191-
currentObjects.Add(id);
192-
}
193-
}
194-
195-
List<object> res = new List<object>();
196-
// oldElements may contain new elements (one case when session.Save is called on new object with list)
197-
foreach (object old in oldElements)
198-
{
199-
if (old != null)
200-
{
201-
var id = persister.GetIdentifier(old);
202-
if (id != null)
203-
{
204-
if (!currentObjects.Contains(id) && await (ForeignKeys.IsNotTransientSlowAsync(persister.EntityName, old, Session, cancellationToken)).ConfigureAwait(false))
205-
{
206-
res.Add(old);
207-
}
208-
}
209-
}
210-
}
211-
212-
return res;
213-
}
214-
215123
public async Task IdentityRemoveAsync(IList list, object obj, string entityName, ISessionImplementor session, CancellationToken cancellationToken)
216124
{
217125
cancellationToken.ThrowIfCancellationRequested();

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,7 @@ public override Task<ICollection> GetOrphansAsync(object snapshot, string entity
8484
}
8585
try
8686
{
87-
var sn = (ICollection) snapshot;
88-
return GetOrphansAsync(sn, (ICollection) _gbag, entityName, Session, cancellationToken);
87+
return Task.FromResult<ICollection>(GetOrphans(snapshot, entityName));
8988
}
9089
catch (Exception ex)
9190
{

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -163,8 +163,7 @@ public override Task<ICollection> GetOrphansAsync(object snapshot, string entity
163163
}
164164
try
165165
{
166-
var sn = (ISet<SnapshotElement>)GetSnapshot();
167-
return GetOrphansAsync(sn.Select(x => x.Value).ToArray(), (ICollection) _values, entityName, Session, cancellationToken);
166+
return Task.FromResult<ICollection>(GetOrphans(snapshot, entityName));
168167
}
169168
catch (Exception ex)
170169
{

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,7 @@ public override Task<ICollection> GetOrphansAsync(object snapshot, string entity
3838
}
3939
try
4040
{
41-
var sn = (IList<T>)snapshot;
42-
return GetOrphansAsync((ICollection)sn, (ICollection) WrappedList, entityName, Session, cancellationToken);
41+
return Task.FromResult<ICollection>(GetOrphans(snapshot, entityName));
4342
}
4443
catch (Exception ex)
4544
{

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,7 @@ public override Task<ICollection> GetOrphansAsync(object snapshot, string entity
3838
}
3939
try
4040
{
41-
var sn = (IDictionary<TKey, TValue>) snapshot;
42-
return GetOrphansAsync((ICollection)sn.Values, (ICollection)WrappedMap.Values, entityName, Session, cancellationToken);
41+
return Task.FromResult<ICollection>(GetOrphans(snapshot, entityName));
4342
}
4443
catch (Exception ex)
4544
{

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

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,7 @@ public override Task<ICollection> GetOrphansAsync(object snapshot, string entity
3939
}
4040
try
4141
{
42-
var sn = new SetSnapShot<T>((IEnumerable<T>)snapshot);
43-
44-
// TODO: Avoid duplicating shortcuts and array copy, by making base class GetOrphans() more flexible
45-
if (WrappedSet.Count == 0) return Task.FromResult<ICollection>(sn);
46-
if (((ICollection)sn).Count == 0) return Task.FromResult<ICollection>(sn);
47-
return GetOrphansAsync(sn, WrappedSet.ToArray(), entityName, Session, cancellationToken);
42+
return Task.FromResult<ICollection>(GetOrphans(snapshot, entityName));
4843
}
4944
catch (Exception ex)
5045
{

src/NHibernate/Async/Collection/IPersistentCollection.cs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,9 +92,6 @@ public partial interface IPersistentCollection
9292
/// </summary>
9393
Task<IEnumerable> GetDeletesAsync(ICollectionPersister persister, bool indexIsFormula, CancellationToken cancellationToken);
9494

95-
/// <summary> Get the "queued" orphans</summary>
96-
Task<ICollection> GetQueuedOrphansAsync(string entityName, CancellationToken cancellationToken);
97-
9895
/// <summary>
9996
/// Called before inserting rows, to ensure that any surrogate keys are fully generated
10097
/// </summary>

src/NHibernate/Async/Engine/Cascade.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,7 @@ private async Task DeleteOrphansAsync(string entityName, IPersistentCollection p
288288
}
289289
else
290290
{
291-
orphans = await (pc.GetQueuedOrphansAsync(entityName, cancellationToken)).ConfigureAwait(false);
291+
orphans = pc.GetQueuedOrphans(entityName);
292292
}
293293

294294
foreach (object orphan in orphans)

src/NHibernate/Collection/AbstractPersistentCollection.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -735,15 +735,15 @@ protected virtual ICollection GetOrphans(ICollection oldElements, ICollection cu
735735
}
736736

737737
List<object> res = new List<object>();
738-
// oldElements may contain new elements (one case when session.Save is called on new object with list)
738+
// oldElements may contain new elements (one case when session.Save is called on new object with collection filled with new objects)
739739
foreach (object old in oldElements)
740740
{
741741
if (old != null)
742742
{
743743
var id = persister.GetIdentifier(old);
744744
if (id != null)
745745
{
746-
if (!currentObjects.Contains(id) && ForeignKeys.IsNotTransientSlow(persister.EntityName, old, Session))
746+
if (!currentObjects.Contains(id))
747747
{
748748
res.Add(old);
749749
}

0 commit comments

Comments
 (0)