From: <fab...@us...> - 2011-04-27 21:49:18
|
Revision: 5777 http://nhibernate.svn.sourceforge.net/nhibernate/?rev=5777&view=rev Author: fabiomaulo Date: 2011-04-27 21:49:11 +0000 (Wed, 27 Apr 2011) Log Message: ----------- Impl DynamicComponentCustomizer to set dynamic-component attributes Modified Paths: -------------- trunk/nhibernate/src/NHibernate/Mapping/ByCode/IDynamicComponentAttributesMapper.cs trunk/nhibernate/src/NHibernate/Mapping/ByCode/Impl/CustomizersImpl/DynamicComponentCustomizer.cs trunk/nhibernate/src/NHibernate/Mapping/ByCode/Impl/DynamicComponentMapper.cs trunk/nhibernate/src/NHibernate.Test/MappingByCode/ExpliticMappingTests/DynamicComponentMappingTests.cs Modified: trunk/nhibernate/src/NHibernate/Mapping/ByCode/IDynamicComponentAttributesMapper.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Mapping/ByCode/IDynamicComponentAttributesMapper.cs 2011-04-27 20:51:43 UTC (rev 5776) +++ trunk/nhibernate/src/NHibernate/Mapping/ByCode/IDynamicComponentAttributesMapper.cs 2011-04-27 21:49:11 UTC (rev 5777) @@ -4,6 +4,7 @@ { void Update(bool consideredInUpdateQuery); void Insert(bool consideredInInsertQuery); + void Unique(bool unique); } public interface IDynamicComponentMapper : IDynamicComponentAttributesMapper, IPropertyContainerMapper { } @@ -12,6 +13,7 @@ { void Update(bool consideredInUpdateQuery); void Insert(bool consideredInInsertQuery); + void Unique(bool unique); } public interface IDynamicComponentMapper<TComponent> : IDynamicComponentAttributesMapper<TComponent>, IPropertyContainerMapper<TComponent> where TComponent : class { } Modified: trunk/nhibernate/src/NHibernate/Mapping/ByCode/Impl/CustomizersImpl/DynamicComponentCustomizer.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Mapping/ByCode/Impl/CustomizersImpl/DynamicComponentCustomizer.cs 2011-04-27 20:51:43 UTC (rev 5776) +++ trunk/nhibernate/src/NHibernate/Mapping/ByCode/Impl/CustomizersImpl/DynamicComponentCustomizer.cs 2011-04-27 21:49:11 UTC (rev 5777) @@ -22,29 +22,34 @@ public void Access(Accessor accessor) { - throw new NotImplementedException(); + CustomizersHolder.AddCustomizer(PropertyPath, (IDynamicComponentAttributesMapper m) => m.Access(accessor)); } public void Access(System.Type accessorType) { - throw new NotImplementedException(); + CustomizersHolder.AddCustomizer(PropertyPath, (IDynamicComponentAttributesMapper m) => m.Access(accessorType)); } public void OptimisticLock(bool takeInConsiderationForOptimisticLock) { - throw new NotImplementedException(); + CustomizersHolder.AddCustomizer(PropertyPath, (IDynamicComponentAttributesMapper m) => m.OptimisticLock(takeInConsiderationForOptimisticLock)); } public void Update(bool consideredInUpdateQuery) { - throw new NotImplementedException(); + CustomizersHolder.AddCustomizer(PropertyPath, (IDynamicComponentAttributesMapper m) => m.Update(consideredInUpdateQuery)); } public void Insert(bool consideredInInsertQuery) { - throw new NotImplementedException(); + CustomizersHolder.AddCustomizer(PropertyPath, (IDynamicComponentAttributesMapper m) => m.Insert(consideredInInsertQuery)); } + public void Unique(bool unique) + { + CustomizersHolder.AddCustomizer(PropertyPath, (IDynamicComponentAttributesMapper m) => m.Unique(unique)); + } + #endregion } } \ No newline at end of file Modified: trunk/nhibernate/src/NHibernate/Mapping/ByCode/Impl/DynamicComponentMapper.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Mapping/ByCode/Impl/DynamicComponentMapper.cs 2011-04-27 20:51:43 UTC (rev 5776) +++ trunk/nhibernate/src/NHibernate/Mapping/ByCode/Impl/DynamicComponentMapper.cs 2011-04-27 21:49:11 UTC (rev 5777) @@ -163,5 +163,10 @@ { component.insert = consideredInInsertQuery; } + + public void Unique(bool unique) + { + component.unique = unique; + } } } \ No newline at end of file Modified: trunk/nhibernate/src/NHibernate.Test/MappingByCode/ExpliticMappingTests/DynamicComponentMappingTests.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Test/MappingByCode/ExpliticMappingTests/DynamicComponentMappingTests.cs 2011-04-27 20:51:43 UTC (rev 5776) +++ trunk/nhibernate/src/NHibernate.Test/MappingByCode/ExpliticMappingTests/DynamicComponentMappingTests.cs 2011-04-27 21:49:11 UTC (rev 5777) @@ -13,7 +13,12 @@ private class Person { public int Id { get; set; } - public IDictionary Info { get; set; } + private IDictionary info; + public IDictionary Info + { + get { return info; } + set { info = value; } + } } [Test] @@ -48,5 +53,32 @@ var hbmDynamicComponent = hbmClass.Properties.OfType<HbmDynamicComponent>().Single(); hbmDynamicComponent.Properties.OfType<HbmProperty>().Select(x => x.type1).All(x=> x.Satisfy(value=> !string.IsNullOrEmpty(value))); } + + [Test] + public void WhenMapDynCompoAttributesThenMapAttributes() + { + var mapper = new ModelMapper(); + mapper.Class<Person>(map => + { + map.Id(x => x.Id, idmap => { }); + map.Component(x => x.Info, new { MyInt = 5}, z => + { + z.Access(Accessor.Field); + z.Insert(false); + z.Update(false); + z.Unique(true); + z.OptimisticLock(false); + }); + }); + + var hbmMapping = mapper.CompileMappingFor(new[] { typeof(Person) }); + var hbmClass = hbmMapping.RootClasses[0]; + var hbmDynamicComponent = hbmClass.Properties.OfType<HbmDynamicComponent>().SingleOrDefault(); + hbmDynamicComponent.access.Should().Contain("field"); + hbmDynamicComponent.insert.Should().Be.False(); + hbmDynamicComponent.update.Should().Be.False(); + hbmDynamicComponent.optimisticlock.Should().Be.False(); + hbmDynamicComponent.unique.Should().Be.True(); + } } } \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |