Skip to content

Commit b03c343

Browse files
committed
Merge branch 'rjperes-NH-2930'
2 parents dbfd3e3 + 59f0385 commit b03c343

16 files changed

+138
-2
lines changed

src/NHibernate.Test/MappingByCode/ExplicitMappingTests/BasicMappingOfSimpleClass.cs

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
using NHibernate.Mapping.ByCode;
77
using NUnit.Framework;
88

9-
namespace NHibernate.Test.MappingByCode.ExpliticMappingTests
9+
namespace NHibernate.Test.MappingByCode.ExplicitMappingTests
1010
{
1111
public class BasicMappingOfSimpleClass
1212
{
@@ -16,6 +16,25 @@ public class MyClass
1616
public string Something { get; set; }
1717
}
1818

19+
[Test]
20+
public void AbstractClass()
21+
{
22+
//NH-3527
23+
var mapper = new ModelMapper();
24+
mapper.Class<MyClass>(ca =>
25+
{
26+
ca.Abstract(true);
27+
ca.Id(x => x.Id, map =>
28+
{
29+
map.Column("MyClassId");
30+
map.Generator(Generators.HighLow, gmap => gmap.Params(new { max_low = 100 }));
31+
});
32+
ca.Property(x => x.Something, map => map.Length(150));
33+
});
34+
var hbmMapping = mapper.CompileMappingFor(new[] { typeof(MyClass) });
35+
Assert.AreEqual(hbmMapping.RootClasses[0].@abstract, true);
36+
}
37+
1938
[Test]
2039
public void MapClassWithIdAndProperty()
2140
{

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: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,5 +79,23 @@ public void WhenRegisteredAsUnionSubclassThenIsEntity()
7979

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

src/NHibernate/Mapping/ByCode/IClassMapper.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ public interface IClassAttributesMapper : IEntityAttributesMapper, IEntitySqlsMa
1313
void ComponentAsId(MemberInfo idProperty, Action<IComponentAsIdMapper> idMapper);
1414
void ComposedId(Action<IComposedIdMapper> idPropertiesMapping);
1515

16+
void Abstract(bool isAbstract);
1617
void Discriminator(Action<IDiscriminatorMapper> discriminatorMapping);
1718
void DiscriminatorValue(object value);
1819
void Table(string tableName);
@@ -53,6 +54,7 @@ public interface IClassAttributesMapper<TEntity> : IEntityAttributesMapper, IEnt
5354

5455
void ComposedId(Action<IComposedIdMapper<TEntity>> idPropertiesMapping);
5556

57+
void Abstract(bool isAbstract);
5658
void Discriminator(Action<IDiscriminatorMapper> discriminatorMapping);
5759
void DiscriminatorValue(object value);
5860
void Table(string tableName);

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/IUnionSubclassMapper.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ public interface IUnionSubclassAttributesMapper : IEntityAttributesMapper, IEnti
66
void Catalog(string catalogName);
77
void Schema(string schemaName);
88
void Extends(System.Type baseType);
9+
void Abstract(bool isAbstract);
910
}
1011

1112
public interface IUnionSubclassMapper : IUnionSubclassAttributesMapper, IPropertyContainerMapper {}
@@ -15,6 +16,8 @@ public interface IUnionSubclassAttributesMapper<TEntity> : IEntityAttributesMapp
1516
void Table(string tableName);
1617
void Catalog(string catalogName);
1718
void Schema(string schemaName);
19+
void Extends(System.Type baseType);
20+
void Abstract(bool isAbstract);
1821
}
1922

2023
public interface IUnionSubclassMapper<TEntity> : IUnionSubclassAttributesMapper<TEntity>, IPropertyContainerMapper<TEntity> where TEntity : class {}

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,12 @@ public Dictionary<string, IJoinMapper> JoinMappers
5959
}
6060

6161
#region Implementation of IClassMapper
62+
public void Abstract(bool isAbstract)
63+
{
64+
classMapping.@abstract = isAbstract;
65+
classMapping.abstractSpecified = true;
66+
}
67+
6268
public void OptimisticLock(OptimisticLockMode mode)
6369
{
6470
classMapping.optimisticlock = (HbmOptimisticLockMode)Enum.Parse(typeof(OptimisticLockMode), mode.ToString());

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@ private Dictionary<string, IJoinMapper<TEntity>> JoinCustomizers
2929
}
3030

3131
#region Implementation of IClassAttributesMapper<TEntity>
32+
public void Abstract(bool isAbstract)
33+
{
34+
CustomizersHolder.AddCustomizer(typeof(TEntity), (IClassMapper m) => m.Abstract(isAbstract));
35+
}
3236

3337
public void OptimisticLock(OptimisticLockMode mode)
3438
{

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/CustomizersImpl/UnionSubclassCustomizer.cs

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

9999
#region Implementation of IUnionSubclassAttributesMapper<TEntity>
100+
public void Extends(System.Type baseType)
101+
{
102+
CustomizersHolder.AddCustomizer(typeof(TEntity), (IUnionSubclassAttributesMapper m) => m.Extends(baseType));
103+
}
104+
105+
public void Abstract(bool isAbstract)
106+
{
107+
CustomizersHolder.AddCustomizer(typeof(TEntity), (IUnionSubclassAttributesMapper m) => m.Abstract(isAbstract));
108+
}
100109

101110
public void Table(string tableName)
102111
{

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
{

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

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

152152
#region Implementation of IUnionSubclassAttributesMapper
153+
public void Abstract(bool isAbstract)
154+
{
155+
classMapping.@abstract = isAbstract;
156+
classMapping.abstractSpecified = true;
157+
}
153158

154159
public void Table(string tableName)
155160
{

0 commit comments

Comments
 (0)