Skip to content

Commit b720934

Browse files
committed
Merge pull request nhibernate#230 from whut/MappingByCodeAdditions
NH-3558 - Table check and enhanced id generators in Mapping By Code
2 parents 531161a + c9a37eb commit b720934

File tree

5 files changed

+82
-0
lines changed

5 files changed

+82
-0
lines changed

src/NHibernate.Test/MappingByCode/MappersTests/IdMapperTest.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,21 @@ public void CanSetGeneratorAssigned()
9898
hbmId.generator.@class.Should().Be.EqualTo("assigned");
9999
}
100100

101+
[Test]
102+
public void CanSetGeneratorEnhancedSequence()
103+
{
104+
var hbmId = new HbmId();
105+
new IdMapper(hbmId).Generator(Generators.EnhancedSequence);
106+
hbmId.generator.@class.Should().Be.EqualTo("enhanced-sequence");
107+
}
108+
109+
[Test]
110+
public void CanSetGeneratorEnhancedTable()
111+
{
112+
var hbmId = new HbmId();
113+
new IdMapper(hbmId).Generator(Generators.EnhancedTable);
114+
hbmId.generator.@class.Should().Be.EqualTo("enhanced-table");
115+
}
101116
private class BaseEntity
102117
{
103118
private int id;

src/NHibernate/Mapping/ByCode/Generators.cs

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ static Generators()
1515
Sequence = new SequenceGeneratorDef();
1616
Identity = new IdentityGeneratorDef();
1717
Assigned = new AssignedGeneratorDef();
18+
EnhancedSequence = new EnhancedSequenceGeneratorDef();
19+
EnhancedTable = new EnhancedTableGeneratorDef();
1820
}
1921

2022
public static IGeneratorDef Assigned { get; private set; }
@@ -24,6 +26,8 @@ static Generators()
2426
public static IGeneratorDef GuidComb { get; private set; }
2527
public static IGeneratorDef Sequence { get; private set; }
2628
public static IGeneratorDef Identity { get; private set; }
29+
public static IGeneratorDef EnhancedSequence { get; private set; }
30+
public static IGeneratorDef EnhancedTable { get; private set; }
2731

2832
public static IGeneratorDef Foreign<TEntity>(Expression<Func<TEntity, object>> property)
2933
{
@@ -257,4 +261,56 @@ public bool SupportedAsCollectionElementId
257261
}
258262
#endregion
259263
}
264+
265+
public class EnhancedSequenceGeneratorDef : IGeneratorDef
266+
{
267+
#region Implementation of IGeneratorDef
268+
269+
public string Class
270+
{
271+
get { return "enhanced-sequence"; }
272+
}
273+
274+
public object Params
275+
{
276+
get { return null; }
277+
}
278+
279+
public System.Type DefaultReturnType
280+
{
281+
get { return typeof(int); }
282+
}
283+
284+
public bool SupportedAsCollectionElementId
285+
{
286+
get { return true; }
287+
}
288+
#endregion
289+
}
290+
291+
public class EnhancedTableGeneratorDef : IGeneratorDef
292+
{
293+
#region Implementation of IGeneratorDef
294+
295+
public string Class
296+
{
297+
get { return "enhanced-table"; }
298+
}
299+
300+
public object Params
301+
{
302+
get { return null; }
303+
}
304+
305+
public System.Type DefaultReturnType
306+
{
307+
get { return typeof(int); }
308+
}
309+
310+
public bool SupportedAsCollectionElementId
311+
{
312+
get { return true; }
313+
}
314+
#endregion
315+
}
260316
}

src/NHibernate/Mapping/ByCode/IClassMapper.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ public interface IClassAttributesMapper : IEntityAttributesMapper, IEntitySqlsMa
1515
void Discriminator(Action<IDiscriminatorMapper> discriminatorMapping);
1616
void DiscriminatorValue(object value);
1717
void Table(string tableName);
18+
void Check(string check);
1819
void Catalog(string catalogName);
1920
void Schema(string schemaName);
2021
void Mutable(bool isMutable);

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,11 @@ public void Table(string tableName)
166166
classMapping.table = tableName;
167167
}
168168

169+
public void Check(string check)
170+
{
171+
classMapping.check = check;
172+
}
173+
169174
public void Catalog(string catalogName)
170175
{
171176
classMapping.catalog = catalogName;

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,11 @@ public void Table(string tableName)
101101
CustomizersHolder.AddCustomizer(typeof(TEntity), (IClassMapper m) => m.Table(tableName));
102102
}
103103

104+
public void Check(string tableName)
105+
{
106+
CustomizersHolder.AddCustomizer(typeof(TEntity), (IClassMapper m) => m.Check(tableName));
107+
}
108+
104109
public void Catalog(string catalogName)
105110
{
106111
CustomizersHolder.AddCustomizer(typeof(TEntity), (IClassMapper m) => m.Catalog(catalogName));

0 commit comments

Comments
 (0)