|
From: <fab...@us...> - 2011-04-02 20:40:41
|
Revision: 5581
http://nhibernate.svn.sourceforge.net/nhibernate/?rev=5581&view=rev
Author: fabiomaulo
Date: 2011-04-02 20:40:33 +0000 (Sat, 02 Apr 2011)
Log Message:
-----------
Subclass Sequence registration fix
Modified Paths:
--------------
trunk/nhibernate/src/NHibernate/Mapping/ByCode/ExplicitlyDeclaredModel.cs
trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj
Added Paths:
-----------
trunk/nhibernate/src/NHibernate.Test/MappingByCode/ExplicitlyDeclaredModelTests/SubclassSequenceRegistrationTests.cs
Modified: trunk/nhibernate/src/NHibernate/Mapping/ByCode/ExplicitlyDeclaredModel.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/Mapping/ByCode/ExplicitlyDeclaredModel.cs 2011-04-02 20:32:31 UTC (rev 5580)
+++ trunk/nhibernate/src/NHibernate/Mapping/ByCode/ExplicitlyDeclaredModel.cs 2011-04-02 20:40:33 UTC (rev 5581)
@@ -193,6 +193,11 @@
public void AddAsTablePerClassHierarchyEntity(System.Type type)
{
+ AddAsTablePerClassHierarchyEntity(type, false);
+ }
+
+ public void AddAsTablePerClassHierarchyEntity(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));
@@ -210,6 +215,14 @@
}
tablePerClassHierarchyEntities.Add(rootEntity);
}
+ else
+ {
+ if (rootEntityMustExists)
+ {
+ throw new MappingException(string.Format("The root entity for {0} was never registered", type.FullName));
+ }
+ EnlistTypeRegistration(type, t => AddAsTablePerClassHierarchyEntity(t, true));
+ }
}
public void AddAsTablePerClassHierarchyJoinEntity(System.Type type)
@@ -376,6 +389,7 @@
public bool IsTablePerClassHierarchy(System.Type type)
{
+ ExecuteDelayedTypeRegistration(type);
return IsMappedFor(tablePerClassHierarchyEntities, type);
}
Added: trunk/nhibernate/src/NHibernate.Test/MappingByCode/ExplicitlyDeclaredModelTests/SubclassSequenceRegistrationTests.cs
===================================================================
--- trunk/nhibernate/src/NHibernate.Test/MappingByCode/ExplicitlyDeclaredModelTests/SubclassSequenceRegistrationTests.cs (rev 0)
+++ trunk/nhibernate/src/NHibernate.Test/MappingByCode/ExplicitlyDeclaredModelTests/SubclassSequenceRegistrationTests.cs 2011-04-02 20:40:33 UTC (rev 5581)
@@ -0,0 +1,37 @@
+using NHibernate.Mapping.ByCode;
+using NUnit.Framework;
+using SharpTestsEx;
+
+namespace NHibernate.Test.MappingByCode.ExplicitlyDeclaredModelTests
+{
+ public class SubclassSequenceRegistrationTests
+ {
+ private class MyClass
+ {
+
+ }
+ private class Inherited1 : MyClass
+ {
+
+ }
+
+ [Test]
+ public void WhenRegisterSubclassBeforeRootThenIsRegistered()
+ {
+ var inspector = new ExplicitlyDeclaredModel();
+ inspector.AddAsTablePerClassHierarchyEntity(typeof(Inherited1));
+
+ inspector.AddAsRootEntity(typeof(MyClass));
+ inspector.IsTablePerClassHierarchy(typeof(Inherited1)).Should().Be.True();
+ }
+
+ [Test]
+ public void WhenRegisterSubclassWithNoRootThenThrows()
+ {
+ var inspector = new ExplicitlyDeclaredModel();
+ inspector.AddAsTablePerClassHierarchyEntity(typeof(Inherited1));
+
+ inspector.Executing(x => x.IsTablePerClass(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:32:31 UTC (rev 5580)
+++ trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2011-04-02 20:40:33 UTC (rev 5581)
@@ -514,6 +514,7 @@
<Compile Include="MappingByCode\ExplicitlyDeclaredModelTests\RootClassMappingStrategyTests.cs" />
<Compile Include="MappingByCode\ExplicitlyDeclaredModelTests\SubclassJoinMappingStrategyTests.cs" />
<Compile Include="MappingByCode\ExplicitlyDeclaredModelTests\SubclassMappingStrategyTests.cs" />
+ <Compile Include="MappingByCode\ExplicitlyDeclaredModelTests\SubclassSequenceRegistrationTests.cs" />
<Compile Include="MappingByCode\ExplicitlyDeclaredModelTests\UnionSubclassMappingStrategyTests.cs" />
<Compile Include="MappingByCode\MappingOfPrivateMembersOnRootEntity.cs" />
<Compile Include="NHSpecificTest\AccessAndCorrectPropertyName\Fixture.cs" />
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|