From: <fab...@us...> - 2011-04-02 20:48:19
|
Revision: 5582 http://nhibernate.svn.sourceforge.net/nhibernate/?rev=5582&view=rev Author: fabiomaulo Date: 2011-04-02 20:48:13 +0000 (Sat, 02 Apr 2011) Log Message: ----------- Subclass-Join Sequence registration fix Modified Paths: -------------- trunk/nhibernate/src/NHibernate/Mapping/ByCode/ExplicitlyDeclaredModel.cs trunk/nhibernate/src/NHibernate.Test/MappingByCode/ExplicitlyDeclaredModelTests/SubclassSequenceRegistrationTests.cs trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj Added Paths: ----------- trunk/nhibernate/src/NHibernate.Test/MappingByCode/ExplicitlyDeclaredModelTests/SubclassJoinSequenceRegistrationTests.cs Modified: trunk/nhibernate/src/NHibernate/Mapping/ByCode/ExplicitlyDeclaredModel.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Mapping/ByCode/ExplicitlyDeclaredModel.cs 2011-04-02 20:40:33 UTC (rev 5581) +++ trunk/nhibernate/src/NHibernate/Mapping/ByCode/ExplicitlyDeclaredModel.cs 2011-04-02 20:48:13 UTC (rev 5582) @@ -227,6 +227,11 @@ public void AddAsTablePerClassHierarchyJoinEntity(System.Type type) { + AddAsTablePerClassHierarchyJoinEntity(type, false); + } + + public void AddAsTablePerClassHierarchyJoinEntity(System.Type type, bool rootEntityMustExists) + { if (IsComponent(type)) { throw new MappingException(string.Format("Abiguous mapping of {0}. It was registered as entity and as component", type.FullName)); @@ -243,8 +248,16 @@ throw new MappingException(string.Format("Abiguous mapping of {0}. It was registered with more than one class-hierarchy strategy", type.FullName)); } tablePerClassHierarchyEntities.Add(rootEntity); + tablePerClassHierarchyJoinEntities.Add(type); } - tablePerClassHierarchyJoinEntities.Add(type); + else + { + if (rootEntityMustExists) + { + throw new MappingException(string.Format("The root entity for {0} was never registered", type.FullName)); + } + EnlistTypeRegistration(type, t => AddAsTablePerClassHierarchyJoinEntity(t, true)); + } } public void AddAsTablePerConcreteClassEntity(System.Type type) @@ -395,6 +408,7 @@ public bool IsTablePerClassHierarchyJoin(System.Type type) { + ExecuteDelayedTypeRegistration(type); return tablePerClassHierarchyJoinEntities.Contains(type); } Added: trunk/nhibernate/src/NHibernate.Test/MappingByCode/ExplicitlyDeclaredModelTests/SubclassJoinSequenceRegistrationTests.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Test/MappingByCode/ExplicitlyDeclaredModelTests/SubclassJoinSequenceRegistrationTests.cs (rev 0) +++ trunk/nhibernate/src/NHibernate.Test/MappingByCode/ExplicitlyDeclaredModelTests/SubclassJoinSequenceRegistrationTests.cs 2011-04-02 20:48:13 UTC (rev 5582) @@ -0,0 +1,37 @@ +using NHibernate.Mapping.ByCode; +using NUnit.Framework; +using SharpTestsEx; + +namespace NHibernate.Test.MappingByCode.ExplicitlyDeclaredModelTests +{ + public class SubclassJoinSequenceRegistrationTests + { + private class MyClass + { + + } + private class Inherited1 : MyClass + { + + } + + [Test] + public void WhenRegisterSubclassJoinBeforeRootThenIsRegistered() + { + var inspector = new ExplicitlyDeclaredModel(); + inspector.AddAsTablePerClassHierarchyJoinEntity(typeof(Inherited1)); + + inspector.AddAsRootEntity(typeof(MyClass)); + inspector.IsTablePerClassHierarchyJoin(typeof(Inherited1)).Should().Be.True(); + } + + [Test] + public void WhenRegisterSubclassWithNoRootThenThrows() + { + var inspector = new ExplicitlyDeclaredModel(); + inspector.AddAsTablePerClassHierarchyJoinEntity(typeof(Inherited1)); + + inspector.Executing(x => x.IsTablePerClassHierarchyJoin(typeof(Inherited1))).Throws<MappingException>(); + } + } +} \ No newline at end of file Modified: trunk/nhibernate/src/NHibernate.Test/MappingByCode/ExplicitlyDeclaredModelTests/SubclassSequenceRegistrationTests.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Test/MappingByCode/ExplicitlyDeclaredModelTests/SubclassSequenceRegistrationTests.cs 2011-04-02 20:40:33 UTC (rev 5581) +++ trunk/nhibernate/src/NHibernate.Test/MappingByCode/ExplicitlyDeclaredModelTests/SubclassSequenceRegistrationTests.cs 2011-04-02 20:48:13 UTC (rev 5582) @@ -31,7 +31,7 @@ var inspector = new ExplicitlyDeclaredModel(); inspector.AddAsTablePerClassHierarchyEntity(typeof(Inherited1)); - inspector.Executing(x => x.IsTablePerClass(typeof(Inherited1))).Throws<MappingException>(); + inspector.Executing(x => x.IsTablePerClassHierarchy(typeof(Inherited1))).Throws<MappingException>(); } } } \ No newline at end of file Modified: trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2011-04-02 20:40:33 UTC (rev 5581) +++ trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2011-04-02 20:48:13 UTC (rev 5582) @@ -513,6 +513,7 @@ <Compile Include="MappingByCode\ExplicitlyDeclaredModelTests\JoinedSubclassSequenceRegistrationTests.cs" /> <Compile Include="MappingByCode\ExplicitlyDeclaredModelTests\RootClassMappingStrategyTests.cs" /> <Compile Include="MappingByCode\ExplicitlyDeclaredModelTests\SubclassJoinMappingStrategyTests.cs" /> + <Compile Include="MappingByCode\ExplicitlyDeclaredModelTests\SubclassJoinSequenceRegistrationTests.cs" /> <Compile Include="MappingByCode\ExplicitlyDeclaredModelTests\SubclassMappingStrategyTests.cs" /> <Compile Include="MappingByCode\ExplicitlyDeclaredModelTests\SubclassSequenceRegistrationTests.cs" /> <Compile Include="MappingByCode\ExplicitlyDeclaredModelTests\UnionSubclassMappingStrategyTests.cs" /> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |