Skip to content

Commit 4f195c4

Browse files
committed
Remove breaking changes
1 parent 4b40405 commit 4f195c4

File tree

10 files changed

+58
-14
lines changed

10 files changed

+58
-14
lines changed

src/NHibernate.Test/NHSpecificTest/SetFixture.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -348,8 +348,6 @@ public object NotFoundObject
348348
get { throw new NotImplementedException(); }
349349
}
350350

351-
public int BatchSize { get; } = 0;
352-
353351
public ISessionFactoryImplementor Factory
354352
{
355353
get { return null; }

src/NHibernate/Collection/AbstractPersistentCollection.cs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ public virtual bool RowUpdatePossible
233233
}
234234

235235
/// <summary></summary>
236-
public virtual ISessionImplementor Session
236+
protected virtual ISessionImplementor Session
237237
{
238238
get { return session; }
239239
}
@@ -868,5 +868,13 @@ public abstract object ReadFrom(DbDataReader reader, ICollectionPersister role,
868868
*/
869869

870870
#endregion
871+
872+
/// <summary>
873+
/// Get the session associated with the collection.
874+
/// </summary>
875+
public ISessionImplementor GetCurrentSession()
876+
{
877+
return session;
878+
}
871879
}
872880
}

src/NHibernate/Collection/IPersistentCollection.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
using System;
12
using System.Collections;
23
using System.Data.Common;
34
using NHibernate.Collection.Generic;
@@ -337,4 +338,21 @@ public partial interface IPersistentCollection
337338
/// </returns>
338339
ICollection GetOrphans(object snapshot, string entityName);
339340
}
341+
342+
public static class PersistentCollectionExtensions
343+
{
344+
/// <summary>
345+
/// Get the session associated with the collection.
346+
/// </summary>
347+
//6.0 TODO: Merge into IPersistentCollection interface. Consider converting to a property.
348+
public static ISessionImplementor GetCurrentSession(this IPersistentCollection collection)
349+
{
350+
if (collection is AbstractPersistentCollection apc)
351+
{
352+
return apc.GetCurrentSession();
353+
}
354+
355+
throw new InvalidOperationException("Only collections of AbstractPersistentCollection are supported.");
356+
}
357+
}
340358
}

src/NHibernate/Engine/CollectionEntry.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -302,9 +302,9 @@ public void PostInitialize(IPersistentCollection collection)
302302
{
303303
snapshot = LoadedPersister.IsMutable ? collection.GetSnapshot(LoadedPersister) : null;
304304
collection.SetSnapshot(loadedKey, role, snapshot);
305-
if (LoadedPersister.BatchSize > 1)
305+
if (LoadedPersister.GetBatchSize() > 1)
306306
{
307-
((AbstractPersistentCollection) collection).Session.PersistenceContext.BatchFetchQueue.RemoveBatchLoadableCollection(this);
307+
collection.GetCurrentSession().PersistenceContext.BatchFetchQueue.RemoveBatchLoadableCollection(this);
308308
}
309309
}
310310

src/NHibernate/Engine/StatefulPersistenceContext.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -835,7 +835,7 @@ public void AddUninitializedCollection(ICollectionPersister persister, IPersiste
835835
{
836836
CollectionEntry ce = new CollectionEntry(collection, persister, id, flushing);
837837
AddCollection(collection, ce, id);
838-
if (persister.BatchSize > 1)
838+
if (persister.GetBatchSize() > 1)
839839
{
840840
batchFetchQueue.AddBatchLoadableCollection(collection, ce);
841841
}

src/NHibernate/Event/Default/EvictVisitor.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using NHibernate.Collection;
33
using NHibernate.Engine;
44
using NHibernate.Impl;
5+
using NHibernate.Persister.Collection;
56
using NHibernate.Type;
67

78
namespace NHibernate.Event.Default
@@ -53,7 +54,7 @@ private void EvictCollection(IPersistentCollection collection)
5354
Session.PersistenceContext.CollectionEntries.Remove(collection);
5455
if (log.IsDebugEnabled())
5556
log.Debug("evicting collection: {0}", MessageHelper.CollectionInfoString(ce.LoadedPersister, collection, ce.LoadedKey, Session));
56-
if (ce.LoadedPersister?.BatchSize > 1)
57+
if (ce.LoadedPersister?.GetBatchSize() > 1)
5758
{
5859
Session.PersistenceContext.BatchFetchQueue.RemoveBatchLoadableCollection(ce);
5960
}

src/NHibernate/Persister/Collection/AbstractCollectionPersister.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2043,9 +2043,12 @@ public string[] RootTableKeyColumnNames
20432043
get { return new string[] {IdentifierColumnName}; }
20442044
}
20452045

2046-
public int BatchSize
2046+
/// <summary>
2047+
/// Get the batch size of a collection persister.
2048+
/// </summary>
2049+
public int GetBatchSize()
20472050
{
2048-
get { return batchSize; }
2051+
return batchSize;
20492052
}
20502053

20512054
public SqlString GetSelectByUniqueKeyString(string propertyName)

src/NHibernate/Persister/Collection/BasicCollectionPersister.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ private string ManyToManySelectFragment(IJoinable rhs, string rhsAlias, string l
281281
/// </summary>
282282
protected override ICollectionInitializer CreateCollectionInitializer(IDictionary<string, IFilter> enabledFilters)
283283
{
284-
return BatchingCollectionInitializer.CreateBatchingCollectionInitializer(this, BatchSize, Factory, enabledFilters);
284+
return BatchingCollectionInitializer.CreateBatchingCollectionInitializer(this, batchSize, Factory, enabledFilters);
285285
}
286286

287287
public override SqlString FromJoinFragment(string alias, bool innerJoin, bool includeSubclasses)
@@ -322,4 +322,4 @@ protected override SqlCommandInfo GenerateIdentityInsertRowString()
322322

323323
#endregion
324324
}
325-
}
325+
}

src/NHibernate/Persister/Collection/ICollectionPersister.cs

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
using System;
12
using System.Collections.Generic;
23
using System.Data.Common;
34
using NHibernate.Cache;
@@ -282,7 +283,22 @@ public partial interface ICollectionPersister
282283
/// A place-holder to inform that the data-reader was empty.
283284
/// </summary>
284285
object NotFoundObject { get; }
286+
}
287+
288+
public static class CollectionPersisterExtensions
289+
{
290+
/// <summary>
291+
/// Get the batch size of a collection persister.
292+
/// </summary>
293+
//6.0 TODO: Merge into ICollectionPersister and convert to a property.
294+
public static int GetBatchSize(this ICollectionPersister persister)
295+
{
296+
if (persister is AbstractCollectionPersister acp)
297+
{
298+
return acp.GetBatchSize();
299+
}
285300

286-
int BatchSize { get; }
301+
throw new InvalidOperationException("Only persisters of AbstractCollectionPersister are supported.");
302+
}
287303
}
288304
}

src/NHibernate/Persister/Collection/OneToManyPersister.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -343,7 +343,7 @@ protected override SelectFragment GenerateSelectFragment(string alias, string co
343343
/// </summary>
344344
protected override ICollectionInitializer CreateCollectionInitializer(IDictionary<string, IFilter> enabledFilters)
345345
{
346-
return BatchingCollectionInitializer.CreateBatchingOneToManyInitializer(this, BatchSize, Factory, enabledFilters);
346+
return BatchingCollectionInitializer.CreateBatchingOneToManyInitializer(this, batchSize, Factory, enabledFilters);
347347
}
348348

349349
public override SqlString FromJoinFragment(string alias, bool innerJoin, bool includeSubclasses)
@@ -413,4 +413,4 @@ protected override SqlCommandInfo GenerateIdentityInsertRowString()
413413

414414
#endregion
415415
}
416-
}
416+
}

0 commit comments

Comments
 (0)