Skip to content

Commit bbc0980

Browse files
committed
NH-3345 - Remove support for non generic bags
1 parent 0dd4062 commit bbc0980

File tree

10 files changed

+22
-125
lines changed

10 files changed

+22
-125
lines changed

src/NHibernate/Bytecode/ICollectionTypeFactory.cs

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -23,20 +23,6 @@ public interface ICollectionTypeFactory
2323
/// </returns>
2424
CollectionType Array(string role, string propertyRef, bool embedded, System.Type elementClass);
2525

26-
/// <summary>
27-
/// Creates a new <see cref="CollectionType"/> for an <see cref="IList"/>
28-
/// with bag semantics.
29-
/// </summary>
30-
/// <param name="role">The role the collection is in.</param>
31-
/// <param name="propertyRef">The name of the property in the
32-
/// owner object containing the collection ID, or <see langword="null" /> if it is
33-
/// the primary key.</param>
34-
/// <param name="embedded">Is embedded in XML (not supported yet)</param>
35-
/// <returns>
36-
/// A <see cref="BagType"/> for the specified role.
37-
/// </returns>
38-
CollectionType Bag(string role, string propertyRef, bool embedded);
39-
4026
/// <summary>
4127
/// Creates a new <see cref="CollectionType"/> for an
4228
/// <see cref="System.Collections.Generic.IList{T}"/> with bag semantics.

src/NHibernate/Collection/Generic/PersistentGenericBag.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
using System;
22
using System.Collections;
33
using System.Collections.Generic;
4-
using System.Diagnostics;
4+
using System.Diagnostics;
5+
using System.Linq;
56
using NHibernate.DebugHelpers;
67
using NHibernate.Engine;
78
using NHibernate.Persister.Collection;
@@ -37,7 +38,8 @@ public class PersistentGenericBag<T> : PersistentBag, IList<T>
3738
public PersistentGenericBag() {}
3839
public PersistentGenericBag(ISessionImplementor session) : base(session) {}
3940

40-
public PersistentGenericBag(ISessionImplementor session, IEnumerable<T> coll) : base(session, coll as ICollection)
41+
public PersistentGenericBag(ISessionImplementor session, IEnumerable<T> coll)
42+
: base(session, coll.Cast<object>())
4143
{
4244
gbag = coll as IList<T>;
4345
if (gbag == null)

src/NHibernate/Collection/PersistentBag.cs

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,13 @@
55
using System.Diagnostics;
66
using NHibernate.DebugHelpers;
77
using NHibernate.Engine;
8-
using NHibernate.Loader;
8+
using NHibernate.Loader;
9+
using NHibernate.Mapping;
910
using NHibernate.Persister.Collection;
1011
using NHibernate.Type;
11-
using NHibernate.Util;
12-
12+
using NHibernate.Util;
13+
using Array = System.Array;
14+
1315
namespace NHibernate.Collection
1416
{
1517
/// <summary>
@@ -26,17 +28,13 @@ public class PersistentBag : AbstractPersistentCollection, IList
2628

2729
public PersistentBag() {} // needed for serialization
2830

29-
public PersistentBag(ISessionImplementor session) : base(session) {}
30-
31-
public PersistentBag(ISessionImplementor session, ICollection coll) : base(session)
31+
public PersistentBag(ISessionImplementor session) : base(session) {}
32+
33+
public PersistentBag(ISessionImplementor session, IEnumerable<object> coll)
34+
: base(session)
3235
{
33-
bag = coll as IList;
34-
35-
if (bag == null)
36-
{
37-
bag = new ArrayList(coll);
38-
}
39-
36+
bag = coll as IList ?? new List<object>(coll);
37+
4038
SetInitialized();
4139
IsDirectlyAccessible = true;
4240
}
@@ -62,7 +60,7 @@ public override IEnumerable Entries(ICollectionPersister persister)
6260
}
6361

6462
public override object ReadFrom(IDataReader reader, ICollectionPersister role, ICollectionAliases descriptor,
65-
object owner)
63+
object owner)
6664
{
6765
// note that if we load this collection from a cartesian product
6866
// the multiplicity would be broken ... so use an idbag instead

src/NHibernate/Loader/BasicLoader.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,8 @@ protected override void PostInstantiate()
6868

6969
private static bool IsBag(ICollectionPersister collectionPersister)
7070
{
71-
return collectionPersister.CollectionType is BagType;
71+
var type = collectionPersister.CollectionType.GetType();
72+
return type.IsGenericType && type.GetGenericTypeDefinition() == typeof (GenericBagType<>);
7273
}
7374

7475
/// <summary>

src/NHibernate/Mapping/Bag.cs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,13 @@ public override CollectionType DefaultCollectionType
2525
{
2626
get
2727
{
28+
System.Type elementType = typeof (object);
2829
if (IsGeneric)
2930
{
3031
CheckGenericArgumentsLength(1);
31-
return TypeFactory.GenericBag(Role, ReferencedPropertyName, GenericArguments[0]);
32-
}
33-
else
34-
{
35-
return TypeFactory.Bag(Role, ReferencedPropertyName, Embedded);
32+
elementType = GenericArguments[0];
3633
}
34+
return TypeFactory.GenericBag(Role, ReferencedPropertyName, elementType);
3735
}
3836
}
3937

src/NHibernate/NHibernate.csproj

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -646,7 +646,6 @@
646646
<Compile Include="Type\AbstractType.cs" />
647647
<Compile Include="Type\AnsiStringType.cs" />
648648
<Compile Include="Type\ArrayType.cs" />
649-
<Compile Include="Type\BagType.cs" />
650649
<Compile Include="Type\BinaryBlobType.cs" />
651650
<Compile Include="Type\BinaryType.cs" />
652651
<Compile Include="Type\BooleanType.cs" />

src/NHibernate/Type/BagType.cs

Lines changed: 0 additions & 77 deletions
This file was deleted.

src/NHibernate/Type/DefaultCollectionTypeFactory.cs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,6 @@ public virtual CollectionType Array(string role, string propertyRef, bool embedd
1111
return new ArrayType(role, propertyRef, elementClass, embedded);
1212
}
1313

14-
public virtual CollectionType Bag(string role, string propertyRef, bool embedded)
15-
{
16-
return new BagType(role, propertyRef, embedded);
17-
}
18-
1914
public virtual CollectionType Bag<T>(string role, string propertyRef, bool embedded)
2015
{
2116
return new GenericBagType<T>(role, propertyRef);

src/NHibernate/Type/GenericBagType.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ namespace NHibernate.Type
1212
/// to the database using bag semantics.
1313
/// </summary>
1414
[Serializable]
15-
public class GenericBagType<T> : BagType
15+
public class GenericBagType<T> : CollectionType
1616
{
1717
/// <summary>
1818
/// Initializes a new instance of a <see cref="GenericBagType{T}"/> class for

src/NHibernate/Type/TypeFactory.cs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -754,11 +754,6 @@ public static CollectionType Array(string role, string propertyRef, bool embedde
754754
return Instance.CollectionTypeFactory.Array(role, propertyRef, embedded, elementClass);
755755
}
756756

757-
public static CollectionType Bag(string role, string propertyRef, bool embedded)
758-
{
759-
return Instance.CollectionTypeFactory.Bag(role, propertyRef, embedded);
760-
}
761-
762757
public static CollectionType IdBag(string role, string propertyRef, bool embedded)
763758
{
764759
return Instance.CollectionTypeFactory.IdBag(role, propertyRef, embedded);

0 commit comments

Comments
 (0)