Skip to content

Commit 59f0385

Browse files
rjpereshazzik
authored andcommitted
Added missing methods Abstract and Extents on subclass, joined-subclass and union-subclass, with unit tests
1 parent 29cb73b commit 59f0385

File tree

9 files changed

+72
-2
lines changed

9 files changed

+72
-2
lines changed

src/NHibernate.Test/MappingByCode/ExplicitlyDeclaredModelTests/JoinedSubclassMappingStrategyTests.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,5 +79,23 @@ public void WhenRegisteredAsJoinedSubclassThenIsEntity()
7979

8080
Assert.That(inspector.IsEntity(typeof(Inherited1)), Is.True);
8181
}
82+
83+
[Test]
84+
public void JoinedSubclassIsAbstract()
85+
{
86+
//NH-3527
87+
var modelMapper = new ModelMapper();
88+
modelMapper.Class<MyClass>(c => { });
89+
modelMapper.JoinedSubclass<Inherited1>(c =>
90+
{
91+
c.Abstract(true);
92+
c.Extends(typeof(MyClass));
93+
});
94+
95+
var mappings = modelMapper.CompileMappingForAllExplicitlyAddedEntities();
96+
97+
Assert.IsTrue(mappings.JoinedSubclasses[0].@abstract);
98+
Assert.IsTrue(mappings.JoinedSubclasses[0].extends == typeof(MyClass).FullName);
99+
}
82100
}
83101
}

src/NHibernate.Test/MappingByCode/ExplicitlyDeclaredModelTests/SubclassMappingStrategyTests.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,5 +79,23 @@ public void WhenRegisteredAsSubclassThenIsEntity()
7979

8080
Assert.That(inspector.IsEntity(typeof(Inherited1)), Is.True);
8181
}
82+
83+
[Test]
84+
public void SubclassIsAbstract()
85+
{
86+
//NH-3527
87+
var modelMapper = new ModelMapper();
88+
modelMapper.Class<MyClass>(c => { });
89+
modelMapper.Subclass<Inherited1>(c =>
90+
{
91+
c.Abstract(true);
92+
c.Extends(typeof(MyClass));
93+
});
94+
95+
var mappings = modelMapper.CompileMappingForAllExplicitlyAddedEntities();
96+
97+
Assert.IsTrue(mappings.SubClasses[0].@abstract);
98+
Assert.IsTrue(mappings.SubClasses[0].extends == typeof(MyClass).FullName);
99+
}
82100
}
83101
}

src/NHibernate.Test/MappingByCode/ExplicitlyDeclaredModelTests/UnionSubclassMappingStrategyTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ public void WhenRegisteredAsUnionSubclassThenIsEntity()
8181
}
8282

8383
[Test]
84-
public void SubclassIsAbstract()
84+
public void UnionSubclassIsAbstract()
8585
{
8686
//NH-3527
8787
var modelMapper = new ModelMapper();

src/NHibernate/Mapping/ByCode/IJoinedSubclassMapper.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,16 @@ public interface IJoinedSubclassAttributesMapper : IEntityAttributesMapper, IEnt
1010
void Key(Action<IKeyMapper> keyMapping);
1111
void Extends(System.Type baseType);
1212
void SchemaAction(SchemaAction action);
13-
void Filter(string filterName, Action<IFilterMapper> filterMapping);
13+
void Filter(string filterName, Action<IFilterMapper> filterMapping);
14+
void Abstract(bool isAbstract);
1415
}
1516

1617
public interface IJoinedSubclassMapper : IJoinedSubclassAttributesMapper, IPropertyContainerMapper {}
1718

1819
public interface IJoinedSubclassAttributesMapper<TEntity> : IEntityAttributesMapper, IEntitySqlsMapper where TEntity : class
1920
{
21+
void Abstract(bool isAbstract);
22+
void Extends(System.Type baseType);
2023
void Table(string tableName);
2124
void Catalog(string catalogName);
2225
void Schema(string schemaName);

src/NHibernate/Mapping/ByCode/ISubclassMapper.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ public interface ISubclassAttributesMapper : IEntityAttributesMapper, IEntitySql
77
void DiscriminatorValue(object value);
88
void Extends(System.Type baseType);
99
void Filter(string filterName, Action<IFilterMapper> filterMapping);
10+
void Abstract(bool isAbstract);
1011
}
1112

1213
public interface ISubclassMapper : ISubclassAttributesMapper, IPropertyContainerMapper
@@ -18,6 +19,8 @@ public interface ISubclassAttributesMapper<TEntity> : IEntityAttributesMapper, I
1819
{
1920
void DiscriminatorValue(object value);
2021
void Filter(string filterName, Action<IFilterMapper> filterMapping);
22+
void Extends(System.Type baseType);
23+
void Abstract(bool isAbstract);
2124
}
2225

2326
public interface ISubclassMapper<TEntity> : ISubclassAttributesMapper<TEntity>, IPropertyContainerMapper<TEntity> where TEntity : class

src/NHibernate/Mapping/ByCode/Impl/CustomizersImpl/JoinedSubclassCustomizer.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,15 @@ public void Subselect(string sql)
111111
#endregion
112112

113113
#region Implementation of IJoinedSubclassAttributesMapper<TEntity>
114+
public void Extends(System.Type baseType)
115+
{
116+
CustomizersHolder.AddCustomizer(typeof(TEntity), (IJoinedSubclassAttributesMapper m) => m.Extends(baseType));
117+
}
118+
119+
public void Abstract(bool isAbstract)
120+
{
121+
CustomizersHolder.AddCustomizer(typeof(TEntity), (IJoinedSubclassAttributesMapper m) => m.Abstract(isAbstract));
122+
}
114123

115124
public void Table(string tableName)
116125
{

src/NHibernate/Mapping/ByCode/Impl/CustomizersImpl/SubclassCustomizer.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,15 @@ public SubclassCustomizer(IModelExplicitDeclarationsHolder explicitDeclarationsH
2222
}
2323

2424
#region ISubclassMapper<TEntity> Members
25+
public void Extends(System.Type baseType)
26+
{
27+
CustomizersHolder.AddCustomizer(typeof(TEntity), (ISubclassMapper m) => m.Extends(baseType));
28+
}
29+
30+
public void Abstract(bool isAbstract)
31+
{
32+
CustomizersHolder.AddCustomizer(typeof(TEntity), (ISubclassMapper m) => m.Abstract(isAbstract));
33+
}
2534

2635
public void DiscriminatorValue(object value)
2736
{

src/NHibernate/Mapping/ByCode/Impl/JoinedSubclassMapper.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,11 @@ public void Subselect(string sql)
149149
#endregion
150150

151151
#region Implementation of IJoinedSubclassAttributesMapper
152+
public void Abstract(bool isAbstract)
153+
{
154+
classMapping.@abstract = isAbstract;
155+
classMapping.abstractSpecified = true;
156+
}
152157

153158
public void Table(string tableName)
154159
{

src/NHibernate/Mapping/ByCode/Impl/SubclassMapper.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,11 @@ public Dictionary<string, IJoinMapper> JoinMappers
3939
}
4040

4141
#region ISubclassMapper Members
42+
public void Abstract(bool isAbstract)
43+
{
44+
classMapping.@abstract = isAbstract;
45+
classMapping.abstractSpecified = true;
46+
}
4247

4348
public void DiscriminatorValue(object value)
4449
{

0 commit comments

Comments
 (0)