Skip to content

Commit f817b79

Browse files
committed
Merged <map> redesign (BREAKING CHANGES)
Squashed commit of the following: commit 69550cd6ccdf491e92315a5051a2c8d60a185a03 Author: James Gregory <[email protected]> Date: Sun Aug 29 19:12:48 2010 +0100 Renamed map methods to be more logically correct, rather than matching the NH naming scheme (which doesn't make sense with <map>s all that much anyway). Key -> ForeignKey Index -> DictionaryKey Element -> DictionaryValue OneToMany and ManyToMany have remained unchanged for now. commit 53955d30b0500dbfc216312b4e47ffe15598330c Author: James Gregory <[email protected]> Date: Sun Aug 29 19:06:02 2010 +0100 Added an overload for collections derived from PersistentGenericMap commit 6d1796a4a7a9f080f935bdd44b366f68d28a8662 Author: James Gregory <[email protected]> Date: Sun Aug 29 17:12:57 2010 +0100 Created HasMany(IDictionary) with default types commit 11a34d5b5b0b6875a263cdf5591a00f1b17b297b Author: James Gregory <[email protected]> Date: Wed Aug 4 22:25:47 2010 +0100 Removed AsMap from the regular ToManyBase commit a17bd398220c3ecaa156547e01dd6af15f038e49 Author: James Gregory <[email protected]> Date: Tue Aug 3 23:56:29 2010 +0100 Added missing methods/attributes to MapBuilder MapBuilder is now complete as far as features go. commit 3ff88e6f6fceeda27f923272dec489c7a7ef4a69 Author: James Gregory <[email protected]> Date: Tue Aug 3 23:14:21 2010 +0100 Added missing methods to many-to-many builder commit 90574368a0da21ba72ffce72f3de44dff6f0ed7e Author: James Gregory <[email protected]> Date: Tue Aug 3 23:00:35 2010 +0100 Added one-to-many builder commit 6d74d43e1ca9562b0d5513c1b6e8ad37f5cf06bf Author: James Gregory <[email protected]> Date: Tue Aug 3 22:51:39 2010 +0100 Added missing composite-index attributes commit 1595bfd6e5dc27f020ec5d4b6395fa2261f7f805 Author: James Gregory <[email protected]> Date: Tue Aug 3 22:49:12 2010 +0100 Upgraded CompositeElementPart to a builder The CompositeElementPart has been upgraded to a builder, using the new mapping-in instead of mapping-out style. Along the way ManyToOnePart, and PropertyPart had to be converted to builders too. commit af36875ae944b650c99a834b08b7115e571dc372 Author: James Gregory <[email protected]> Date: Tue Aug 3 21:40:38 2010 +0100 Added missing KeyBuilder attributes commit 856e6ebc6420a5260f0bf37b10ae41e63995abcd Author: James Gregory <[email protected]> Date: Tue Aug 3 21:38:05 2010 +0100 Added missing IndexBuilder attributes commit 6b97c247c1a6a5290517158185041d4d4ebfc083 Author: James Gregory <[email protected]> Date: Tue Aug 3 21:25:16 2010 +0100 Added missing element attributes to ElementBuilder commit 34a35c62ed5231df3d8d890fc4f3a70c743217e1 Author: James Gregory <[email protected]> Date: Tue Aug 3 00:30:00 2010 +0100 Converted HasManyToMany to use MapBuilder The HasManyToMany dictionary based methods now use the MapBuilder too. Right now they're just effectively an alias until a conclusion is given for the whole many-to-many dictionary default issue. This commit effectively removes AsTernaryAssociation, AsSimpleAssociation, AsEntityMap, and AsMap, as they're no longer accessible from the dictionary HasMany chains. commit dbd45dd3db3b2cdb5d75b031eca4c896a49d8d6d Author: James Gregory <[email protected]> Date: Mon Aug 2 23:38:34 2010 +0100 Entity map support + removed IndexManyToMany New map builder now supports entity/entity maps, thus completing the possible combinations of key/value types. Refactored IndexManyToManyMapping and IndexManyToMany into one class, with a IsManyToMany property; this simplifies switching between the two from within the method chain. commit 08a955ffd6b145d99b8cdf02e0028c02e0cb5cf6 Author: James Gregory <[email protected]> Date: Mon Aug 2 20:40:51 2010 +0100 Removed all those HasMany overloads Not needed any more as it just wasn't viable - defaults are now handled through the builder. commit 09b84814e2159a1ad523380147ec4cc5565b6d20 Author: James Gregory <[email protected]> Date: Wed Jul 28 23:27:26 2010 +0100 Got composite-index support working Only the basics, no attributes yet. commit fd545a5915d1f2f778d45947a7fec03271a0b6aa Author: James Gregory <[email protected]> Date: Wed Jul 28 22:37:53 2010 +0100 Unified the builders into a single MapBuilder The default implementations (element, entity map, etc...) are decided programatically instead of using generic constraints. This actually gives us more power because we can do some proper checks against the types, instead on relying on the rather lackluster constraint system (for example: we can detect enums as element mappings). Also updated the majority of the tests that were relying on the AsMap method to initiate the <map>. This is a breaking change. The AsMap method is now not available for maps, and most of the time all the values should use reasonable defaults. commit f7a7dacdf445db84cca09e2b1b3820f92f79be38 Author: James Gregory <[email protected]> Date: Wed Jul 28 00:37:11 2010 +0100 Added composite-element support to new builders Renamed MapManyToManyBuilder to MapValueKeyBuilder as it's hard to distinguish between entity maps and composite-element maps (they're both classes). The renamed builder now has both routes on, making it a bit of a general case for anything with a value type as a key. This class might end up being even more generic, but we'll see (I'd like to try to avoid that if possible). commit 5a59385d2aaeb2507e939a4c6a65b465d7fd90cf Author: James Gregory <[email protected]> Date: Tue Jul 27 23:26:29 2010 +0100 Added key and index modifiers to the MapManyToManyBuilder Still need to add a modifier for the many-to-many element itself, that'll come soon. commit 1ddc7668fa4aa04313a2b07f26875a3a79ae1bd7 Author: James Gregory <[email protected]> Date: Tue Jul 27 20:36:34 2010 +0100 Implemented a value-type/entity map builder Refactored the HasMany methods to include value type key'd dictionaries with values of entities. These are restricted in similar ways to the element maps by explicitly specifying the value type methods as overloads. These methods default to many-to-many collections even though they're created through HasMany. This is a bit confusing, but one-to-many really doesn't make much sense to me in this situation; it creates a schema that I can't see ever being useful. If this causes confusion we should change it... commit 762d9e1d6e55bebb9ea276ef203c76741e2cf096 Author: James Gregory <[email protected]> Date: Mon Jul 26 21:44:47 2010 +0100 Added huge swath of overloads for element maps The idea is to preemptively find out that the user is trying to map a dictionary of value types; unfortunately, the only way to do that is to have hundreds of overloads for all the value types. Generic constraints don't support restricting only to value types, and even if they did you can't have two methods with the same signature only differing by constraints :( commit b5e2cee812c704a9d7a7c15185e82f27076ff0dd Author: James Gregory <[email protected]> Date: Sun Jul 25 23:26:44 2010 +0100 Got indexes working in Element Maps Default indexes are now created as part of the MapElementBuilder. Similar to ElementBuilder and ElementPart, IndexPart has now been replaced by IndexBuilder for the same reasons. commit faf4069644bda37e371a475af27579106dcc3c51 Author: James Gregory <[email protected]> Date: Sun Jul 25 23:06:39 2010 +0100 Removed ElementPart in favour of ElementBuilder ElementPart and ElementBuilder are doing the same job, except *Builder follows the "mapping in" principal over "mapping out". Removed ElementPart and updated usages to ElementBuilder. commit a0b87663ae7f5675661501479b23c1fcdd49c342 Author: James Gregory <[email protected]> Date: Sun Jul 25 22:49:44 2010 +0100 Key refactorings Started refactoring the Key support to be more complete in all cases. Now supplying a closure method to allow complete customisation of the Key, while also still providing the basic inline methods for specifying columns. HasMany(x => x.Something) .KeyUpdate() .Not.KeyNullable() .KeyColumns.Add("a") .KeyColumns.Add("b"); becomes -> HasMany(x => x.Something) .Key(k => { k.Update(); k.Not.Nullable(); k.Columns.Add("a"); k.Columns.Add("b"); }); Bit more verbose, but keeps the primary interface cleaner. commit ebb0129ca155bef71026135ea8fc750309755a9a Author: James Gregory <[email protected]> Date: Sun Jul 25 18:48:45 2010 +0100 Created KeyBuilder commit 1d2998b992bad90abc9c951062153cc0b00c8f46 Author: James Gregory <[email protected]> Date: Sun Jul 25 18:40:36 2010 +0100 Got keys working with MapElementBuilder Awaiting KeyBuilder for full customisation support commit 414d18a1df09882504a67dd7edc6af9998da7d05 Author: James Gregory <[email protected]> Date: Sun Jul 25 18:30:42 2010 +0100 Started refactoring the Map functionality The first step is to introduce more restrictive overloads to HasMany that have different return types based on their intent. Element maps are the first target, with overloads limited to value types. Created a MapElementBuilder, which ditches the baggage of ToManyBase and starts anew. So far creates the <map> and <element> correctly, still gotta support the <key> and <index>.
1 parent 78ee558 commit f817b79

File tree

129 files changed

+4807
-2087
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

129 files changed

+4807
-2087
lines changed

src/FluentNHibernate.5.1.ReSharper

Lines changed: 236 additions & 0 deletions
Large diffs are not rendered by default.

src/FluentNHibernate.Specs/Conventions/Fixtures/Child.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public ChildMap()
1414
{
1515
Id(x => x.Id);
1616
References(x => x.Parent)
17-
.Columns("one", "two");
17+
.Columns.Add("one", "two");
1818
}
1919
}
2020
}

src/FluentNHibernate.Specs/FluentInterface/ClasslikeBehaviors.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -98,10 +98,10 @@ public class ClasslikeListWithDefaultIndexBehaviour : ClasslikeListBehaviour
9898
mapping.Collections.Single().As<ListMapping>().Index.ShouldNotBeNull();
9999

100100
It should_create_a_single_column_for_the_index = () =>
101-
mapping.Collections.Single().As<ListMapping>().Index.Columns.Count().ShouldEqual(1);
101+
mapping.Collections.Single().As<ListMapping>().Index.As<IndexMapping>().Columns.Count().ShouldEqual(1);
102102

103103
It should_use_index_as_the_index_column_name = () =>
104-
mapping.Collections.Single().As<ListMapping>().Index.Columns.Single().Name.ShouldEqual("Index");
104+
mapping.Collections.Single().As<ListMapping>().Index.As<IndexMapping>().Columns.Single().Name.ShouldEqual("Index");
105105
}
106106

107107
[Behaviors]
@@ -111,10 +111,10 @@ public class ClasslikeListWithCustomIndexBehaviour : ClasslikeListBehaviour
111111
mapping.Collections.Single().As<ListMapping>().Index.ShouldNotBeNull();
112112

113113
It should_create_a_single_column_for_the_index = () =>
114-
mapping.Collections.Single().As<ListMapping>().Index.Columns.Count().ShouldEqual(1);
114+
mapping.Collections.Single().As<ListMapping>().Index.As<IndexMapping>().Columns.Count().ShouldEqual(1);
115115

116116
It should_use_specified_column_name_as_the_index_column_name = () =>
117-
mapping.Collections.Single().As<ListMapping>().Index.Columns.Single().Name.ShouldEqual("custom-column");
117+
mapping.Collections.Single().As<ListMapping>().Index.As<IndexMapping>().Columns.Single().Name.ShouldEqual("custom-column");
118118

119119
It should_use_specified_type_as_the_index_type = () =>
120120
mapping.Collections.Single().As<ListMapping>().Index.As<IndexMapping>().Type.ShouldEqual(new TypeReference(typeof(IndexTarget)));
@@ -168,10 +168,10 @@ public class ClasslikeArrayBehaviour
168168
mapping.Collections.Single().As<ArrayMapping>().Index.ShouldNotBeNull();
169169

170170
It should_create_a_single_column_for_the_index = () =>
171-
mapping.Collections.Single().As<ArrayMapping>().Index.Columns.Count().ShouldEqual(1);
171+
mapping.Collections.Single().As<ArrayMapping>().Index.As<IndexMapping>().Columns.Count().ShouldEqual(1);
172172

173173
It should_use_specified_property_as_the_index_column_name = () =>
174-
mapping.Collections.Single().As<ArrayMapping>().Index.Columns.Single().Name.ShouldEqual("Position");
174+
mapping.Collections.Single().As<ArrayMapping>().Index.As<IndexMapping>().Columns.Single().Name.ShouldEqual("Position");
175175

176176
protected static ClassMappingBase mapping;
177177
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
using System.Collections.Generic;
2+
using NHibernate.Collection.Generic;
3+
4+
namespace FluentNHibernate.Specs.FluentInterface.Fixtures
5+
{
6+
class Blog : EntityBase
7+
{
8+
public IDictionary<string, string> UrlAliases { get; set; }
9+
public IDictionary<string, string> UrlAliasesCustomCollection { get; set; }
10+
public IDictionary<string, Post> Permalinks { get; set; }
11+
public IDictionary<Post, User> Commentors { get; set; }
12+
public CommentorCollection CommentorCustomCollection { get; set; }
13+
}
14+
15+
class User : EntityBase
16+
{
17+
public string Name { get; set; }
18+
public int Age { get; set; }
19+
}
20+
21+
class Post : EntityBase
22+
{
23+
public string Name { get; set; }
24+
public int Age { get; set; }
25+
}
26+
27+
class CommentorCollection : PersistentGenericMap<Post, User>
28+
{}
29+
30+
class CustomMap<TKey, TValue> : PersistentGenericMap<TKey, TValue>
31+
{ }
32+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
namespace FluentNHibernate.Specs.FluentInterface.Fixtures
2+
{
3+
public class EntityBase
4+
{
5+
public int Id { get; set; }
6+
}
7+
}

0 commit comments

Comments
 (0)