|
From: <fab...@us...> - 2011-05-30 22:28:10
|
Revision: 5893
http://nhibernate.svn.sourceforge.net/nhibernate/?rev=5893&view=rev
Author: fabiomaulo
Date: 2011-05-30 22:28:04 +0000 (Mon, 30 May 2011)
Log Message:
-----------
Support Unique and NotNullable for IKeyMapper
Modified Paths:
--------------
trunk/nhibernate/src/NHibernate/Mapping/ByCode/IKeyMapper.cs
trunk/nhibernate/src/NHibernate/Mapping/ByCode/Impl/CustomizersImpl/CollectionKeyCustomizer.cs
trunk/nhibernate/src/NHibernate/Mapping/ByCode/Impl/CustomizersImpl/JoinKeyCustomizer.cs
trunk/nhibernate/src/NHibernate/Mapping/ByCode/Impl/CustomizersImpl/JoinedSubclassKeyCustomizer.cs
trunk/nhibernate/src/NHibernate/Mapping/ByCode/Impl/KeyMapper.cs
Added Paths:
-----------
trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH941/
trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH941/Fixture.cs
Modified: trunk/nhibernate/src/NHibernate/Mapping/ByCode/IKeyMapper.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/Mapping/ByCode/IKeyMapper.cs 2011-05-30 19:32:23 UTC (rev 5892)
+++ trunk/nhibernate/src/NHibernate/Mapping/ByCode/IKeyMapper.cs 2011-05-30 22:28:04 UTC (rev 5893)
@@ -15,6 +15,8 @@
void OnDelete(OnDeleteAction deleteAction);
void PropertyRef(MemberInfo property);
void Update(bool consideredInUpdateQuery);
+ void NotNullable(bool notnull);
+ void Unique(bool unique);
/// <summary>
/// Set the Foreing-Key name
@@ -33,5 +35,7 @@
void PropertyRef<TProperty>(Expression<Func<TEntity, TProperty>> propertyGetter);
void Update(bool consideredInUpdateQuery);
void ForeignKey(string foreingKeyName);
+ void NotNullable(bool notnull);
+ void Unique(bool unique);
}
}
\ No newline at end of file
Modified: trunk/nhibernate/src/NHibernate/Mapping/ByCode/Impl/CustomizersImpl/CollectionKeyCustomizer.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/Mapping/ByCode/Impl/CustomizersImpl/CollectionKeyCustomizer.cs 2011-05-30 19:32:23 UTC (rev 5892)
+++ trunk/nhibernate/src/NHibernate/Mapping/ByCode/Impl/CustomizersImpl/CollectionKeyCustomizer.cs 2011-05-30 22:28:04 UTC (rev 5893)
@@ -55,6 +55,16 @@
CustomizersHolder.AddCustomizer(propertyPath, (ICollectionPropertiesMapper m) => m.Key(x => x.ForeignKey(foreingKeyName)));
}
+ public void NotNullable(bool notnull)
+ {
+ CustomizersHolder.AddCustomizer(propertyPath, (ICollectionPropertiesMapper m) => m.Key(x => x.NotNullable(notnull)));
+ }
+
+ public void Unique(bool unique)
+ {
+ // Do nothing (a collection with the key as unique... no thanks!)
+ }
+
#endregion
}
}
\ No newline at end of file
Modified: trunk/nhibernate/src/NHibernate/Mapping/ByCode/Impl/CustomizersImpl/JoinKeyCustomizer.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/Mapping/ByCode/Impl/CustomizersImpl/JoinKeyCustomizer.cs 2011-05-30 19:32:23 UTC (rev 5892)
+++ trunk/nhibernate/src/NHibernate/Mapping/ByCode/Impl/CustomizersImpl/JoinKeyCustomizer.cs 2011-05-30 22:28:04 UTC (rev 5893)
@@ -52,6 +52,16 @@
CustomizersHolder.AddCustomizer(typeof(TEntity), (IJoinAttributesMapper m) => m.Key(x => x.ForeignKey(foreingKeyName)));
}
+ public void NotNullable(bool notnull)
+ {
+ CustomizersHolder.AddCustomizer(typeof(TEntity), (IJoinAttributesMapper m) => m.Key(x => x.NotNullable(notnull)));
+ }
+
+ public void Unique(bool unique)
+ {
+ CustomizersHolder.AddCustomizer(typeof(TEntity), (IJoinAttributesMapper m) => m.Key(x => x.Unique(unique)));
+ }
+
#endregion
}
}
\ No newline at end of file
Modified: trunk/nhibernate/src/NHibernate/Mapping/ByCode/Impl/CustomizersImpl/JoinedSubclassKeyCustomizer.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/Mapping/ByCode/Impl/CustomizersImpl/JoinedSubclassKeyCustomizer.cs 2011-05-30 19:32:23 UTC (rev 5892)
+++ trunk/nhibernate/src/NHibernate/Mapping/ByCode/Impl/CustomizersImpl/JoinedSubclassKeyCustomizer.cs 2011-05-30 22:28:04 UTC (rev 5893)
@@ -52,6 +52,16 @@
CustomizersHolder.AddCustomizer(typeof (TEntity), (IJoinedSubclassAttributesMapper m) => m.Key(x => x.ForeignKey(foreingKeyName)));
}
+ public void NotNullable(bool notnull)
+ {
+ CustomizersHolder.AddCustomizer(typeof(TEntity), (IJoinedSubclassAttributesMapper m) => m.Key(x => x.NotNullable(notnull)));
+ }
+
+ public void Unique(bool unique)
+ {
+ CustomizersHolder.AddCustomizer(typeof(TEntity), (IJoinedSubclassAttributesMapper m) => m.Key(x => x.Unique(unique)));
+ }
+
#endregion
}
}
\ No newline at end of file
Modified: trunk/nhibernate/src/NHibernate/Mapping/ByCode/Impl/KeyMapper.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/Mapping/ByCode/Impl/KeyMapper.cs 2011-05-30 19:32:23 UTC (rev 5892)
+++ trunk/nhibernate/src/NHibernate/Mapping/ByCode/Impl/KeyMapper.cs 2011-05-30 22:28:04 UTC (rev 5893)
@@ -50,8 +50,8 @@
else
{
mapping.column1 = !DefaultColumnName(ownerEntityType).Equals(hbm.name) ? hbm.name : null;
- mapping.notnull = hbm.notnull;
- mapping.unique = hbm.unique;
+ NotNullable(hbm.notnull);
+ Unique(hbm.unique);
}
}
@@ -109,6 +109,16 @@
mapping.updateSpecified = true;
}
+ public void NotNullable(bool notnull)
+ {
+ mapping.notnull = mapping.notnullSpecified = notnull;
+ }
+
+ public void Unique(bool unique)
+ {
+ mapping.unique = mapping.uniqueSpecified = unique;
+ }
+
public void ForeignKey(string foreingKeyName)
{
if (foreingKeyName == null)
Added: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH941/Fixture.cs
===================================================================
--- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH941/Fixture.cs (rev 0)
+++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH941/Fixture.cs 2011-05-30 22:28:04 UTC (rev 5893)
@@ -0,0 +1,62 @@
+using System.Collections.Generic;
+using NHibernate.Cfg.MappingSchema;
+using NHibernate.Mapping.ByCode;
+using NUnit.Framework;
+
+namespace NHibernate.Test.NHSpecificTest.NH941
+{
+ public class MyClass
+ {
+ public virtual int Id { get; set; }
+ public virtual ICollection<Related> Relateds { get; set; }
+ }
+
+ public class Related
+ {
+ public virtual int Id { get; set; }
+ }
+
+ public class Fixture : TestCaseMappingByCode
+ {
+ protected override HbmMapping GetMappings()
+ {
+ var mapper = new ModelMapper();
+ mapper.Class<MyClass>(rc =>
+ {
+ rc.Id(x => x.Id, map => map.Generator(Generators.HighLow));
+ rc.Bag(x => x.Relateds, map =>
+ {
+ map.Key(km => km.Column(cm => cm.NotNullable(true)));
+ map.Cascade(Mapping.ByCode.Cascade.All);
+ }, rel => rel.OneToMany());
+ });
+ mapper.Class<Related>(rc => rc.Id(x => x.Id, map => map.Generator(Generators.HighLow)));
+ HbmMapping mappings = mapper.CompileMappingForAllExplicitAddedEntities();
+ return mappings;
+ }
+
+ [Test]
+ public void WhenSaveOneThenShouldSaveMany()
+ {
+ using (ISession session = OpenSession())
+ {
+ using (ITransaction tx = session.BeginTransaction())
+ {
+ var one = new MyClass();
+ one.Relateds = new List<Related> {new Related(), new Related()};
+ session.Persist(one);
+ tx.Commit();
+ }
+ }
+ using (ISession session = OpenSession())
+ {
+ using (ITransaction tx = session.BeginTransaction())
+ {
+ session.CreateQuery("delete from Related").ExecuteUpdate();
+ session.CreateQuery("delete from MyClass").ExecuteUpdate();
+ tx.Commit();
+ }
+ }
+ }
+ }
+}
\ No newline at end of file
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|