Skip to content

Commit ec89837

Browse files
committed
Obsolete GetOrphansAsync
1 parent a913de4 commit ec89837

File tree

7 files changed

+41
-45
lines changed

7 files changed

+41
-45
lines changed

src/NHibernate/Async/Collection/AbstractPersistentCollection.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,9 +115,20 @@ public virtual Task PreInsertAsync(ICollectionPersister persister, CancellationT
115115
}
116116
}
117117

118+
//Since 5.3
118119
/// <summary>
119120
/// Get all "orphaned" elements
120121
/// </summary>
122+
/// <param name="snapshot">The snapshot of the collection.</param>
123+
/// <param name="entityName">The persistent class whose objects
124+
/// the collection is expected to contain.</param>
125+
/// <param name="cancellationToken">A cancellation token that can be used to cancel the work</param>
126+
/// <param name="cancellationToken">A cancellation token that can be used to cancel the work</param>
127+
/// <returns>
128+
/// An <see cref="ICollection"/> that contains all of the elements
129+
/// that have been orphaned.
130+
/// </returns>
131+
[Obsolete("This method has no more usages and will be removed in a future version")]
121132
public abstract Task<ICollection> GetOrphansAsync(object snapshot, string entityName, CancellationToken cancellationToken);
122133

123134
public async Task IdentityRemoveAsync(IList list, object obj, string entityName, ISessionImplementor session, CancellationToken cancellationToken)

src/NHibernate/Async/Collection/IPersistentCollection.cs

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -98,18 +98,5 @@ public partial interface IPersistentCollection
9898
/// <param name="persister"></param>
9999
/// <param name="cancellationToken">A cancellation token that can be used to cancel the work</param>
100100
Task PreInsertAsync(ICollectionPersister persister, CancellationToken cancellationToken);
101-
102-
/// <summary>
103-
/// Get all "orphaned" elements
104-
/// </summary>
105-
/// <param name="snapshot">The snapshot of the collection.</param>
106-
/// <param name="entityName">The persistent class whose objects
107-
/// the collection is expected to contain.</param>
108-
/// <param name="cancellationToken">A cancellation token that can be used to cancel the work</param>
109-
/// <returns>
110-
/// An <see cref="ICollection"/> that contains all of the elements
111-
/// that have been orphaned.
112-
/// </returns>
113-
Task<ICollection> GetOrphansAsync(object snapshot, string entityName, CancellationToken cancellationToken);
114101
}
115102
}

src/NHibernate/Async/Collection/PersistentArrayHolder.cs

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,17 +27,20 @@ namespace NHibernate.Collection
2727
public partial class PersistentArrayHolder : AbstractPersistentCollection, ICollection
2828
{
2929

30-
public override async Task<ICollection> GetOrphansAsync(object snapshot, string entityName, CancellationToken cancellationToken)
30+
public override Task<ICollection> GetOrphansAsync(object snapshot, string entityName, CancellationToken cancellationToken)
3131
{
32-
cancellationToken.ThrowIfCancellationRequested();
33-
object[] sn = (object[]) snapshot;
34-
object[] arr = (object[]) array;
35-
List<object> result = new List<object>(sn);
36-
for (int i = 0; i < sn.Length; i++)
32+
if (cancellationToken.IsCancellationRequested)
3733
{
38-
await (IdentityRemoveAsync(result, arr[i], entityName, Session, cancellationToken)).ConfigureAwait(false);
34+
return Task.FromCanceled<ICollection>(cancellationToken);
35+
}
36+
try
37+
{
38+
return Task.FromResult<ICollection>(GetOrphans(snapshot, entityName));
39+
}
40+
catch (Exception ex)
41+
{
42+
return Task.FromException<ICollection>(ex);
3943
}
40-
return result;
4144
}
4245

4346
public override async Task<bool> EqualsSnapshotAsync(ICollectionPersister persister, CancellationToken cancellationToken)
@@ -147,4 +150,4 @@ public override async Task<bool> NeedsUpdatingAsync(object entry, int i, IType e
147150
&& await (elemType.IsDirtyAsync(array.GetValue(i), sn.GetValue(i), Session, cancellationToken)).ConfigureAwait(false);
148151
}
149152
}
150-
}
153+
}

src/NHibernate/Async/Engine/Cascade.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,7 @@ private async Task DeleteOrphansAsync(string entityName, IPersistentCollection p
285285
if (pc.WasInitialized)
286286
{
287287
CollectionEntry ce = eventSource.PersistenceContext.GetCollectionEntry(pc);
288-
orphans = ce == null ? CollectionHelper.EmptyCollection : await (ce.GetOrphansAsync(entityName, pc, cancellationToken)).ConfigureAwait(false);
288+
orphans = ce == null ? CollectionHelper.EmptyCollection : ce.GetOrphans(entityName, pc);
289289
}
290290
else
291291
{

src/NHibernate/Async/Engine/CollectionEntry.cs

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -70,18 +70,5 @@ public async Task PreFlushAsync(IPersistentCollection collection, CancellationTo
7070
reached = false;
7171
processed = false;
7272
}
73-
74-
public Task<ICollection> GetOrphansAsync(string entityName, IPersistentCollection collection, CancellationToken cancellationToken)
75-
{
76-
if (snapshot == null)
77-
{
78-
throw new AssertionFailure("no collection snapshot for orphan delete");
79-
}
80-
if (cancellationToken.IsCancellationRequested)
81-
{
82-
return Task.FromCanceled<ICollection>(cancellationToken);
83-
}
84-
return collection.GetOrphansAsync(snapshot, entityName, cancellationToken);
85-
}
8673
}
8774
}

src/NHibernate/Collection/IPersistentCollection.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -344,6 +344,21 @@ public partial interface IPersistentCollection
344344
/// that have been orphaned.
345345
/// </returns>
346346
ICollection GetOrphans(object snapshot, string entityName);
347+
348+
//Since 5.3
349+
/// <summary>
350+
/// Get all "orphaned" elements
351+
/// </summary>
352+
/// <param name="snapshot">The snapshot of the collection.</param>
353+
/// <param name="entityName">The persistent class whose objects
354+
/// the collection is expected to contain.</param>
355+
/// <param name="cancellationToken">A cancellation token that can be used to cancel the work</param>
356+
/// <returns>
357+
/// An <see cref="ICollection"/> that contains all of the elements
358+
/// that have been orphaned.
359+
/// </returns>
360+
[Obsolete("This method has no more usages and will be removed in a future version")]
361+
Task<ICollection> GetOrphansAsync(object snapshot, string entityName, CancellationToken cancellationToken);
347362
}
348363

349364
// 6.0 TODO: merge into IPersistentCollection

src/NHibernate/Collection/PersistentArrayHolder.cs

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -94,14 +94,7 @@ public override bool IsSnapshotEmpty(object snapshot)
9494

9595
public override ICollection GetOrphans(object snapshot, string entityName)
9696
{
97-
object[] sn = (object[]) snapshot;
98-
object[] arr = (object[]) array;
99-
List<object> result = new List<object>(sn);
100-
for (int i = 0; i < sn.Length; i++)
101-
{
102-
IdentityRemove(result, arr[i], entityName, Session);
103-
}
104-
return result;
97+
return GetOrphans((object[]) snapshot, (object[]) array, entityName, Session);
10598
}
10699

107100
public override bool IsWrapper(object collection)
@@ -318,4 +311,4 @@ IEnumerator IEnumerable.GetEnumerator()
318311

319312
#endregion
320313
}
321-
}
314+
}

0 commit comments

Comments
 (0)