Skip to content

Commit e076763

Browse files
committed
NH-3345 - Remove support for non generic id-bags
1 parent 63ce5ab commit e076763

File tree

7 files changed

+55
-104
lines changed

7 files changed

+55
-104
lines changed

src/NHibernate/Bytecode/ICollectionTypeFactory.cs

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -57,20 +57,6 @@ public interface ICollectionTypeFactory
5757
/// </returns>
5858
CollectionType List<T>(string role, string propertyRef, bool embedded);
5959

60-
/// <summary>
61-
/// Creates a new <see cref="CollectionType"/> for an <see cref="IList"/>
62-
/// with id-bag semantics.
63-
/// </summary>
64-
/// <param name="role">The role the collection is in.</param>
65-
/// <param name="propertyRef">The name of the property in the
66-
/// owner object containing the collection ID, or <see langword="null" /> if it is
67-
/// the primary key.</param>
68-
/// <param name="embedded">Is embedded in XML (not supported yet)</param>
69-
/// <returns>
70-
/// A <see cref="IdentifierBagType"/> for the specified role.
71-
/// </returns>
72-
CollectionType IdBag(string role, string propertyRef, bool embedded);
73-
7460
/// <summary>
7561
/// Creates a new <see cref="CollectionType"/> for an
7662
/// <see cref="System.Collections.Generic.IList{T}"/> with identifier

src/NHibernate/Mapping/IdentifierBag.cs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,23 @@ namespace NHibernate.Mapping
1010
[Serializable]
1111
public class IdentifierBag : IdentifierCollection
1212
{
13-
public IdentifierBag(PersistentClass owner) : base(owner)
13+
public IdentifierBag(PersistentClass owner)
14+
: base(owner)
1415
{
1516
}
1617

1718
public override CollectionType DefaultCollectionType
1819
{
1920
get
2021
{
22+
System.Type elementType = typeof(object);
2123
if (IsGeneric)
2224
{
2325
CheckGenericArgumentsLength(1);
24-
return TypeFactory.GenericIdBag(Role, ReferencedPropertyName, GenericArguments[0]);
26+
elementType = GenericArguments[0];
2527
}
26-
return TypeFactory.IdBag(Role, ReferencedPropertyName, Embedded);
28+
29+
return TypeFactory.GenericIdBag(Role, ReferencedPropertyName, elementType);
2730
}
2831
}
2932
}

src/NHibernate/NHibernate.csproj

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -665,7 +665,6 @@
665665
<Compile Include="Type\GuidType.cs" />
666666
<Compile Include="Type\IAbstractComponentType.cs" />
667667
<Compile Include="Type\IAssociationType.cs" />
668-
<Compile Include="Type\IdentifierBagType.cs" />
669668
<Compile Include="Type\IDiscriminatorType.cs" />
670669
<Compile Include="Type\IIdentifierType.cs" />
671670
<Compile Include="Type\ILiteralType.cs" />

src/NHibernate/Type/DefaultCollectionTypeFactory.cs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,6 @@ public virtual CollectionType List<T>(string role, string propertyRef, bool embe
2121
return new GenericListType<T>(role, propertyRef);
2222
}
2323

24-
public virtual CollectionType IdBag(string role, string propertyRef, bool embedded)
25-
{
26-
return new IdentifierBagType(role, propertyRef, embedded);
27-
}
28-
2924
public virtual CollectionType IdBag<T>(string role, string propertyRef, bool embedded)
3025
{
3126
return new GenericIdentifierBagType<T>(role, propertyRef);

src/NHibernate/Type/GenericIdentifierBagType.cs

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,32 +7,80 @@
77

88
namespace NHibernate.Type
99
{
10+
/// <summary>
11+
/// An <see cref="IType"/> that maps an <see cref="IList{T}"/> collection
12+
/// using bag semantics with an identifier to the database.
13+
/// </summary>
1014
[Serializable]
11-
public class GenericIdentifierBagType<T> : IdentifierBagType
15+
public class GenericIdentifierBagType<T> : CollectionType
1216
{
17+
/// <summary>
18+
/// Initializes a new instance of a <see cref="CollectionType"/> class for
19+
/// a specific role.
20+
/// </summary>
21+
/// <param name="role">The role the persistent collection is in.</param>
22+
/// <param name="propertyRef">The name of the property in the
23+
/// owner object containing the collection ID, or <see langword="null" /> if it is
24+
/// the primary key.</param>
1325
public GenericIdentifierBagType(string role, string propertyRef)
1426
: base(role, propertyRef, false)
1527
{
1628
}
1729

30+
/// <summary>
31+
/// Instantiates a new <see cref="IPersistentCollection"/> for the identifier bag.
32+
/// </summary>
33+
/// <param name="session">The current <see cref="ISessionImplementor"/> for the identifier bag.</param>
34+
/// <param name="persister"></param>
35+
/// <param name="key"></param>
36+
/// <returns></returns>
1837
public override IPersistentCollection Instantiate(ISessionImplementor session, ICollectionPersister persister, object key)
1938
{
2039
return new PersistentIdentifierBag<T>(session);
2140
}
2241

42+
/// <summary>
43+
/// Wraps an <see cref="IList{T}"/> in a <see cref="PersistentIdentifierBag{T}"/>.
44+
/// </summary>
45+
/// <param name="session">The <see cref="ISessionImplementor"/> for the collection to be a part of.</param>
46+
/// <param name="collection">The unwrapped <see cref="IList{T}"/>.</param>
47+
/// <returns>
48+
/// An <see cref="PersistentIdentifierBag{T}"/> that wraps the non NHibernate <see cref="IList{T}"/>.
49+
/// </returns>
2350
public override IPersistentCollection Wrap(ISessionImplementor session, object collection)
2451
{
2552
return new PersistentIdentifierBag<T>(session, (ICollection<T>) collection);
2653
}
2754

55+
/// <summary></summary>
2856
public override System.Type ReturnedClass
2957
{
3058
get { return typeof(IList<T>); }
3159
}
3260

61+
/// <summary>
62+
/// Instantiate an empty instance of the "underlying" collection (not a wrapper),
63+
/// but with the given anticipated size (i.e. accounting for initial capacity
64+
/// and perhaps load factor).
65+
/// </summary>
66+
/// <param name="anticipatedSize">
67+
/// The anticipated size of the instantiated collection after we are done populating it.
68+
/// </param>
69+
/// <returns> A newly instantiated collection to be wrapped. </returns>
3370
public override object Instantiate(int anticipatedSize)
3471
{
3572
return anticipatedSize <= 0 ? new List<T>() : new List<T>(anticipatedSize + 1);
3673
}
74+
75+
76+
protected override void Clear(object collection)
77+
{
78+
((IList<T>)collection).Clear();
79+
}
80+
81+
protected override void Add(object collection, object element)
82+
{
83+
((IList<T>)collection).Add((T)element);
84+
}
3785
}
3886
}

src/NHibernate/Type/IdentifierBagType.cs

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

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 IdBag(string role, string propertyRef, bool embedded)
758-
{
759-
return Instance.CollectionTypeFactory.IdBag(role, propertyRef, embedded);
760-
}
761-
762757
public static CollectionType Map(string role, string propertyRef, bool embedded)
763758
{
764759
return Instance.CollectionTypeFactory.Map(role, propertyRef, embedded);

0 commit comments

Comments
 (0)