You can subscribe to this list here.
2004 |
Jan
|
Feb
|
Mar
|
Apr
(248) |
May
(82) |
Jun
(90) |
Jul
(177) |
Aug
(253) |
Sep
(157) |
Oct
(151) |
Nov
(143) |
Dec
(278) |
---|---|---|---|---|---|---|---|---|---|---|---|---|
2005 |
Jan
(152) |
Feb
(107) |
Mar
(177) |
Apr
(133) |
May
(259) |
Jun
(81) |
Jul
(119) |
Aug
(306) |
Sep
(416) |
Oct
(240) |
Nov
(329) |
Dec
(206) |
2006 |
Jan
(466) |
Feb
(382) |
Mar
(153) |
Apr
(162) |
May
(133) |
Jun
(21) |
Jul
(18) |
Aug
(37) |
Sep
(97) |
Oct
(114) |
Nov
(110) |
Dec
(28) |
2007 |
Jan
(74) |
Feb
(65) |
Mar
(49) |
Apr
(76) |
May
(43) |
Jun
(15) |
Jul
(68) |
Aug
(55) |
Sep
(63) |
Oct
(59) |
Nov
(70) |
Dec
(66) |
2008 |
Jan
(71) |
Feb
(60) |
Mar
(120) |
Apr
(31) |
May
(48) |
Jun
(81) |
Jul
(107) |
Aug
(51) |
Sep
(80) |
Oct
(83) |
Nov
(83) |
Dec
(79) |
2009 |
Jan
(83) |
Feb
(110) |
Mar
(97) |
Apr
(91) |
May
(291) |
Jun
(250) |
Jul
(197) |
Aug
(58) |
Sep
(54) |
Oct
(122) |
Nov
(68) |
Dec
(34) |
2010 |
Jan
(50) |
Feb
(17) |
Mar
(63) |
Apr
(61) |
May
(84) |
Jun
(81) |
Jul
(138) |
Aug
(144) |
Sep
(78) |
Oct
(26) |
Nov
(30) |
Dec
(61) |
2011 |
Jan
(33) |
Feb
(35) |
Mar
(166) |
Apr
(221) |
May
(109) |
Jun
(76) |
Jul
(27) |
Aug
(37) |
Sep
(1) |
Oct
(4) |
Nov
(2) |
Dec
(1) |
2012 |
Jan
|
Feb
|
Mar
(2) |
Apr
(2) |
May
|
Jun
|
Jul
(1) |
Aug
|
Sep
(1) |
Oct
|
Nov
(1) |
Dec
|
2013 |
Jan
|
Feb
(1) |
Mar
|
Apr
|
May
|
Jun
|
Jul
(1) |
Aug
(1) |
Sep
(3) |
Oct
(2) |
Nov
|
Dec
(1) |
2014 |
Jan
(1) |
Feb
(1) |
Mar
(3) |
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
From: <fab...@us...> - 2011-04-06 21:06:36
|
Revision: 5628 http://nhibernate.svn.sourceforge.net/nhibernate/?rev=5628&view=rev Author: fabiomaulo Date: 2011-04-06 21:06:29 +0000 (Wed, 06 Apr 2011) Log Message: ----------- Fixed test to be only dyn-proxy test Modified Paths: -------------- trunk/nhibernate/src/NHibernate.Test/DynamicProxyTests/ProxiedMembers/Fixture.cs trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj Added Paths: ----------- trunk/nhibernate/src/NHibernate.Test/DynamicProxyTests/PassThroughInterceptor.cs Removed Paths: ------------- trunk/nhibernate/src/NHibernate.Test/DynamicProxyTests/ProxiedMembers/ClassWithVarietyOfMembers.cs trunk/nhibernate/src/NHibernate.Test/DynamicProxyTests/ProxiedMembers/Mapping.hbm.xml Added: trunk/nhibernate/src/NHibernate.Test/DynamicProxyTests/PassThroughInterceptor.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Test/DynamicProxyTests/PassThroughInterceptor.cs (rev 0) +++ trunk/nhibernate/src/NHibernate.Test/DynamicProxyTests/PassThroughInterceptor.cs 2011-04-06 21:06:29 UTC (rev 5628) @@ -0,0 +1,20 @@ +using System; +using NHibernate.Proxy.DynamicProxy; + +namespace NHibernate.Test.DynamicProxyTests +{ + public class PassThroughInterceptor : NHibernate.Proxy.DynamicProxy.IInterceptor + { + private readonly object targetInstance; + + public PassThroughInterceptor(object targetInstance) + { + this.targetInstance = targetInstance; + } + + public object Intercept(InvocationInfo info) + { + return info.TargetMethod.Invoke(targetInstance, info.Arguments); + } + } +} \ No newline at end of file Deleted: trunk/nhibernate/src/NHibernate.Test/DynamicProxyTests/ProxiedMembers/ClassWithVarietyOfMembers.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Test/DynamicProxyTests/ProxiedMembers/ClassWithVarietyOfMembers.cs 2011-04-06 18:11:14 UTC (rev 5627) +++ trunk/nhibernate/src/NHibernate.Test/DynamicProxyTests/ProxiedMembers/ClassWithVarietyOfMembers.cs 2011-04-06 21:06:29 UTC (rev 5628) @@ -1,20 +0,0 @@ -using System; - -namespace NHibernate.Test.DynamicProxyTests.ProxiedMembers -{ - public class ClassWithVarietyOfMembers - { - public virtual int Id { get; set; } - public virtual string Data { get; set; } - - public virtual void Method1(out int x) - { - x = 3; - } - - public virtual void Method2(ref int x) - { - x++; - } - } -} \ No newline at end of file Modified: trunk/nhibernate/src/NHibernate.Test/DynamicProxyTests/ProxiedMembers/Fixture.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Test/DynamicProxyTests/ProxiedMembers/Fixture.cs 2011-04-06 18:11:14 UTC (rev 5627) +++ trunk/nhibernate/src/NHibernate.Test/DynamicProxyTests/ProxiedMembers/Fixture.cs 2011-04-06 21:06:29 UTC (rev 5628) @@ -1,50 +1,38 @@ -using System; -using System.Collections; -using System.IO; -using System.Runtime.Serialization; -using System.Runtime.Serialization.Formatters.Binary; +using NHibernate.Proxy.DynamicProxy; using NUnit.Framework; +using SharpTestsEx; namespace NHibernate.Test.DynamicProxyTests.ProxiedMembers { - [TestFixture] - public class Fixture : TestCase + public class ClassWithVarietyOfMembers { - protected override IList Mappings + public virtual void Method1(out int x) { - get { return new[] { "DynamicProxyTests.ProxiedMembers.Mapping.hbm.xml" }; } + x = 3; } - protected override string MappingsAssembly + public virtual void Method2(ref int x) { - get { return "NHibernate.Test"; } + x++; } + } + public class Fixture + { [Test] - [Ignore] + [Ignore] public void Proxy() { - ISession s = OpenSession(); - ClassWithVarietyOfMembers c = new ClassWithVarietyOfMembers {Id = 1, Data = "some data"}; - s.Save(c); - s.Flush(); - s.Close(); + var factory = new ProxyFactory(); + var c = (ClassWithVarietyOfMembers)factory.CreateProxy(typeof(ClassWithVarietyOfMembers), new PassThroughInterceptor(new ClassWithVarietyOfMembers()), null); - s = OpenSession(); - c = (ClassWithVarietyOfMembers)s.Load(typeof(ClassWithVarietyOfMembers), c.Id); - Assert.IsFalse(NHibernateUtil.IsInitialized(c)); + int x; + c.Method1(out x); + x.Should().Be(3); - int x; - c.Method1(out x); - Assert.AreEqual(3, x); - - x = 4; - c.Method2(ref x); - Assert.AreEqual(5, x); - - s.Delete(c); - s.Flush(); - s.Close(); + x = 4; + c.Method2(ref x); + x.Should().Be(5); } } } \ No newline at end of file Deleted: trunk/nhibernate/src/NHibernate.Test/DynamicProxyTests/ProxiedMembers/Mapping.hbm.xml =================================================================== --- trunk/nhibernate/src/NHibernate.Test/DynamicProxyTests/ProxiedMembers/Mapping.hbm.xml 2011-04-06 18:11:14 UTC (rev 5627) +++ trunk/nhibernate/src/NHibernate.Test/DynamicProxyTests/ProxiedMembers/Mapping.hbm.xml 2011-04-06 21:06:29 UTC (rev 5628) @@ -1,11 +0,0 @@ -<?xml version="1.0" encoding="utf-8" ?> -<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" - assembly="NHibernate.Test" - namespace="NHibernate.Test.DynamicProxyTests.ProxiedMembers"> - <class name="ClassWithVarietyOfMembers"> - <id name="Id"> - <generator class="assigned" /> - </id> - <property name="Data" /> - </class> -</hibernate-mapping> \ No newline at end of file Modified: trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2011-04-06 18:11:14 UTC (rev 5627) +++ trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2011-04-06 21:06:29 UTC (rev 5628) @@ -222,7 +222,7 @@ <Compile Include="DynamicProxyTests\InterfaceProxySerializationTests\ProxyFixture.cs" /> <Compile Include="DynamicProxyTests\InterfaceWithEqualsGethashcodeTests.cs" /> <Compile Include="DynamicProxyTests\LazyFieldInterceptorSerializable.cs" /> - <Compile Include="DynamicProxyTests\ProxiedMembers\ClassWithVarietyOfMembers.cs" /> + <Compile Include="DynamicProxyTests\PassThroughInterceptor.cs" /> <Compile Include="DynamicProxyTests\ProxiedMembers\Fixture.cs" /> <Compile Include="EngineTest\CallableParserFixture.cs" /> <Compile Include="EngineTest\NativeSQLQueryNonScalarReturnTest.cs" /> @@ -2548,7 +2548,6 @@ <EmbeddedResource Include="NHSpecificTest\NH1291AnonExample\Mappings.hbm.xml" /> </ItemGroup> <ItemGroup> - <EmbeddedResource Include="DynamicProxyTests\ProxiedMembers\Mapping.hbm.xml" /> <EmbeddedResource Include="NHSpecificTest\SqlConverterAndMultiQuery\Mappings.hbm.xml" /> <EmbeddedResource Include="NHSpecificTest\NH2489\Mappings.hbm.xml" /> <EmbeddedResource Include="NHSpecificTest\NH2603\Mappings.hbm.xml" /> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fab...@us...> - 2011-04-06 18:11:21
|
Revision: 5627 http://nhibernate.svn.sourceforge.net/nhibernate/?rev=5627&view=rev Author: fabiomaulo Date: 2011-04-06 18:11:14 +0000 (Wed, 06 Apr 2011) Log Message: ----------- Facility to get mappings for declared entities Modified Paths: -------------- trunk/nhibernate/src/NHibernate/Mapping/ByCode/Impl/CustomizersHolder.cs trunk/nhibernate/src/NHibernate/Mapping/ByCode/Impl/ICustomizersHolder.cs trunk/nhibernate/src/NHibernate/Mapping/ByCode/ModelMapper.cs trunk/nhibernate/src/NHibernate.Test/MappingByCode/ExpliticMappingTests/BasicMappingOfSimpleClass.cs trunk/nhibernate/src/NHibernate.Test/MappingByCode/ExpliticMappingTests/ConformistMappingRegistrationTests/ClassMappingRegistrationTest.cs Modified: trunk/nhibernate/src/NHibernate/Mapping/ByCode/Impl/CustomizersHolder.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Mapping/ByCode/Impl/CustomizersHolder.cs 2011-04-06 17:49:34 UTC (rev 5626) +++ trunk/nhibernate/src/NHibernate/Mapping/ByCode/Impl/CustomizersHolder.cs 2011-04-06 18:11:14 UTC (rev 5627) @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Linq; namespace NHibernate.Mapping.ByCode.Impl { @@ -183,6 +184,11 @@ AddCustomizer(mapKeyElementCustomizers, member, mapKeyElementCustomizer); } + public IEnumerable<System.Type> GetAllCustomizedEntities() + { + return rootClassCustomizers.Keys.Concat(subclassCustomizers.Keys).Concat(joinedClassCustomizers.Keys).Concat(unionClassCustomizers.Keys); + } + public void InvokeCustomizers(System.Type type, IClassMapper mapper) { InvokeCustomizers(rootClassCustomizers, type, mapper); Modified: trunk/nhibernate/src/NHibernate/Mapping/ByCode/Impl/ICustomizersHolder.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Mapping/ByCode/Impl/ICustomizersHolder.cs 2011-04-06 17:49:34 UTC (rev 5626) +++ trunk/nhibernate/src/NHibernate/Mapping/ByCode/Impl/ICustomizersHolder.cs 2011-04-06 18:11:14 UTC (rev 5627) @@ -1,4 +1,5 @@ using System; +using System.Collections.Generic; namespace NHibernate.Mapping.ByCode.Impl { @@ -72,5 +73,7 @@ void AddCustomizer(PropertyPath member, Action<IMapKeyMapper> mapKeyElementCustomizer); #endregion + + IEnumerable<System.Type> GetAllCustomizedEntities(); } } \ No newline at end of file Modified: trunk/nhibernate/src/NHibernate/Mapping/ByCode/ModelMapper.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Mapping/ByCode/ModelMapper.cs 2011-04-06 17:49:34 UTC (rev 5626) +++ trunk/nhibernate/src/NHibernate/Mapping/ByCode/ModelMapper.cs 2011-04-06 18:11:14 UTC (rev 5627) @@ -1650,5 +1650,15 @@ AddMapping(type); } } + + public HbmMapping CompileMappingForAllExplicitAddedEntities() + { + return CompileMappingFor(customizerHolder.GetAllCustomizedEntities()); + } + + public IEnumerable<HbmMapping> CompileMappingForEachExplicitAddedEntity() + { + return CompileMappingForEach(customizerHolder.GetAllCustomizedEntities()); + } } } \ No newline at end of file Modified: trunk/nhibernate/src/NHibernate.Test/MappingByCode/ExpliticMappingTests/BasicMappingOfSimpleClass.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Test/MappingByCode/ExpliticMappingTests/BasicMappingOfSimpleClass.cs 2011-04-06 17:49:34 UTC (rev 5626) +++ trunk/nhibernate/src/NHibernate.Test/MappingByCode/ExpliticMappingTests/BasicMappingOfSimpleClass.cs 2011-04-06 18:11:14 UTC (rev 5627) @@ -73,7 +73,7 @@ }); ca.Property(x => x.Something, map => map.Length(150)); }); - var hbmMapping = mapper.CompileMappingFor(new[] { typeof(MyClass) }); + var hbmMapping = mapper.CompileMappingForAllExplicitAddedEntities(); ModelIsWellFormed(hbmMapping); } Modified: trunk/nhibernate/src/NHibernate.Test/MappingByCode/ExpliticMappingTests/ConformistMappingRegistrationTests/ClassMappingRegistrationTest.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Test/MappingByCode/ExpliticMappingTests/ConformistMappingRegistrationTests/ClassMappingRegistrationTest.cs 2011-04-06 17:49:34 UTC (rev 5626) +++ trunk/nhibernate/src/NHibernate.Test/MappingByCode/ExpliticMappingTests/ConformistMappingRegistrationTests/ClassMappingRegistrationTest.cs 2011-04-06 18:11:14 UTC (rev 5627) @@ -58,6 +58,16 @@ ModelIsWellFormed(hbmMapping); } + [Test] + public void WhenRegisterClassMappingThroughTypeThenGetMapping() + { + var mapper = new ModelMapper(); + mapper.AddMapping(typeof(MyClassMap)); + var hbmMapping = mapper.CompileMappingForAllExplicitAddedEntities(); + + ModelIsWellFormed(hbmMapping); + } + private void ModelIsWellFormed(HbmMapping hbmMapping) { var hbmClass = hbmMapping.RootClasses[0]; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fab...@us...> - 2011-04-06 17:49:41
|
Revision: 5626 http://nhibernate.svn.sourceforge.net/nhibernate/?rev=5626&view=rev Author: fabiomaulo Date: 2011-04-06 17:49:34 +0000 (Wed, 06 Apr 2011) Log Message: ----------- Add Conformist mappings Modified Paths: -------------- trunk/nhibernate/src/NHibernate/Mapping/ByCode/ModelMapper.cs trunk/nhibernate/src/NHibernate.Test/MappingByCode/ExpliticMappingTests/ConformistMappingRegistrationTests/ClassMappingRegistrationTest.cs Modified: trunk/nhibernate/src/NHibernate/Mapping/ByCode/ModelMapper.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Mapping/ByCode/ModelMapper.cs 2011-04-06 17:38:08 UTC (rev 5625) +++ trunk/nhibernate/src/NHibernate/Mapping/ByCode/ModelMapper.cs 2011-04-06 17:49:34 UTC (rev 5626) @@ -1638,5 +1638,17 @@ thisCustomizerHolder.Merge(otherCustomizerHolder); explicitDeclarationsHolder.Merge(mapping.ExplicitDeclarationsHolder); } + + public void AddMappings(IEnumerable<System.Type> types) + { + if (types == null) + { + throw new ArgumentNullException("types"); + } + foreach (var type in types) + { + AddMapping(type); + } + } } } \ No newline at end of file Modified: trunk/nhibernate/src/NHibernate.Test/MappingByCode/ExpliticMappingTests/ConformistMappingRegistrationTests/ClassMappingRegistrationTest.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Test/MappingByCode/ExpliticMappingTests/ConformistMappingRegistrationTests/ClassMappingRegistrationTest.cs 2011-04-06 17:38:08 UTC (rev 5625) +++ trunk/nhibernate/src/NHibernate.Test/MappingByCode/ExpliticMappingTests/ConformistMappingRegistrationTests/ClassMappingRegistrationTest.cs 2011-04-06 17:49:34 UTC (rev 5626) @@ -35,19 +35,7 @@ mapper.AddMapping<MyClassMap>(); var hbmMapping = mapper.CompileMappingFor(new[] { typeof(MyClass) }); - var hbmClass = hbmMapping.RootClasses[0]; - hbmClass.Should().Not.Be.Null(); - var hbmId = hbmClass.Id; - hbmId.Should().Not.Be.Null(); - hbmId.name.Should().Be("Id"); - var hbmGenerator = hbmId.generator; - hbmGenerator.Should().Not.Be.Null(); - hbmGenerator.@class.Should().Be("hilo"); - hbmGenerator.param[0].name.Should().Be("max_low"); - hbmGenerator.param[0].GetText().Should().Be("100"); - var hbmProperty = hbmClass.Properties.OfType<HbmProperty>().Single(); - hbmProperty.name.Should().Be("Something"); - hbmProperty.length.Should().Be("150"); + ModelIsWellFormed(hbmMapping); } [Test] @@ -57,6 +45,21 @@ mapper.AddMapping(typeof(MyClassMap)); var hbmMapping = mapper.CompileMappingFor(new[] { typeof(MyClass) }); + ModelIsWellFormed(hbmMapping); + } + + [Test] + public void WhenRegisterClassMappingThroughCollectionOfTypeThenMapTheClass() + { + var mapper = new ModelMapper(); + mapper.AddMappings(new []{typeof(MyClassMap)}); + var hbmMapping = mapper.CompileMappingFor(new[] { typeof(MyClass) }); + + ModelIsWellFormed(hbmMapping); + } + + private void ModelIsWellFormed(HbmMapping hbmMapping) + { var hbmClass = hbmMapping.RootClasses[0]; hbmClass.Should().Not.Be.Null(); var hbmId = hbmClass.Id; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fab...@us...> - 2011-04-06 17:38:15
|
Revision: 5625 http://nhibernate.svn.sourceforge.net/nhibernate/?rev=5625&view=rev Author: fabiomaulo Date: 2011-04-06 17:38:08 +0000 (Wed, 06 Apr 2011) Log Message: ----------- Add Conformist mapping without use strongly typed method Modified Paths: -------------- trunk/nhibernate/src/NHibernate/Mapping/ByCode/ModelMapper.cs trunk/nhibernate/src/NHibernate.Test/MappingByCode/ExpliticMappingTests/ConformistMappingRegistrationTests/ClassMappingRegistrationTest.cs trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj Added Paths: ----------- trunk/nhibernate/src/NHibernate.Test/MappingByCode/ExpliticMappingTests/ConformistMappingRegistrationTests/ModelMapperAddMappingByTypeTests.cs Modified: trunk/nhibernate/src/NHibernate/Mapping/ByCode/ModelMapper.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Mapping/ByCode/ModelMapper.cs 2011-04-06 17:05:20 UTC (rev 5624) +++ trunk/nhibernate/src/NHibernate/Mapping/ByCode/ModelMapper.cs 2011-04-06 17:38:08 UTC (rev 5625) @@ -1607,5 +1607,36 @@ thisCustomizerHolder.Merge(otherCustomizerHolder); explicitDeclarationsHolder.Merge(mapping.ExplicitDeclarationsHolder); } + + public void AddMapping(System.Type type) + { + object mappingInstance; + try + { + mappingInstance = Activator.CreateInstance(type); + } + catch (Exception e) + { + throw new MappingException("Unable to instantiate mapping class (see InnerException): " + type, e); + } + + var mapping = mappingInstance as IConformistHoldersProvider; + if(mapping == null) + { + throw new ArgumentOutOfRangeException("type", "The mapping class must be an implementation of IConformistHoldersProvider."); + } + var thisCustomizerHolder = customizerHolder as CustomizersHolder; + if (thisCustomizerHolder == null) + { + throw new NotSupportedException("To merge 'conformist' mappings, the instance of ICustomizersHolder, provided in the ModelMapper constructor, have to be a CustomizersHolder instance."); + } + var otherCustomizerHolder = mapping.CustomizersHolder as CustomizersHolder; + if (otherCustomizerHolder == null) + { + throw new NotSupportedException("The mapping class have to provide a CustomizersHolder instance."); + } + thisCustomizerHolder.Merge(otherCustomizerHolder); + explicitDeclarationsHolder.Merge(mapping.ExplicitDeclarationsHolder); + } } } \ No newline at end of file Modified: trunk/nhibernate/src/NHibernate.Test/MappingByCode/ExpliticMappingTests/ConformistMappingRegistrationTests/ClassMappingRegistrationTest.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Test/MappingByCode/ExpliticMappingTests/ConformistMappingRegistrationTests/ClassMappingRegistrationTest.cs 2011-04-06 17:05:20 UTC (rev 5624) +++ trunk/nhibernate/src/NHibernate.Test/MappingByCode/ExpliticMappingTests/ConformistMappingRegistrationTests/ClassMappingRegistrationTest.cs 2011-04-06 17:38:08 UTC (rev 5625) @@ -49,5 +49,27 @@ hbmProperty.name.Should().Be("Something"); hbmProperty.length.Should().Be("150"); } + + [Test] + public void WhenRegisterClassMappingThroughTypeThenMapTheClass() + { + var mapper = new ModelMapper(); + mapper.AddMapping(typeof(MyClassMap)); + var hbmMapping = mapper.CompileMappingFor(new[] { typeof(MyClass) }); + + var hbmClass = hbmMapping.RootClasses[0]; + hbmClass.Should().Not.Be.Null(); + var hbmId = hbmClass.Id; + hbmId.Should().Not.Be.Null(); + hbmId.name.Should().Be("Id"); + var hbmGenerator = hbmId.generator; + hbmGenerator.Should().Not.Be.Null(); + hbmGenerator.@class.Should().Be("hilo"); + hbmGenerator.param[0].name.Should().Be("max_low"); + hbmGenerator.param[0].GetText().Should().Be("100"); + var hbmProperty = hbmClass.Properties.OfType<HbmProperty>().Single(); + hbmProperty.name.Should().Be("Something"); + hbmProperty.length.Should().Be("150"); + } } } \ No newline at end of file Added: trunk/nhibernate/src/NHibernate.Test/MappingByCode/ExpliticMappingTests/ConformistMappingRegistrationTests/ModelMapperAddMappingByTypeTests.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Test/MappingByCode/ExpliticMappingTests/ConformistMappingRegistrationTests/ModelMapperAddMappingByTypeTests.cs (rev 0) +++ trunk/nhibernate/src/NHibernate.Test/MappingByCode/ExpliticMappingTests/ConformistMappingRegistrationTests/ModelMapperAddMappingByTypeTests.cs 2011-04-06 17:38:08 UTC (rev 5625) @@ -0,0 +1,31 @@ +using System; +using NUnit.Framework; +using NHibernate.Mapping.ByCode; +using SharpTestsEx; + +namespace NHibernate.Test.MappingByCode.ExpliticMappingTests.ConformistMappingRegistrationTests +{ + public class ModelMapperAddMappingByTypeTests + { + public class WithOutPublicParameterLessCtor + { + public WithOutPublicParameterLessCtor(string something) + { + } + } + + [Test] + public void WhenRegisterClassMappingThroughTypeThenCheckIConformistHoldersProvider() + { + var mapper = new ModelMapper(); + mapper.Executing(x => x.AddMapping(typeof(object))).Throws<ArgumentOutOfRangeException>().And.ValueOf.Message.Should().Contain("IConformistHoldersProvider"); + } + + [Test] + public void WhenRegisterClassMappingThroughTypeThenCheckParameterLessCtor() + { + var mapper = new ModelMapper(); + mapper.Executing(x => x.AddMapping(typeof(WithOutPublicParameterLessCtor))).Throws<MappingException>(); + } + } +} \ No newline at end of file Modified: trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2011-04-06 17:05:20 UTC (rev 5624) +++ trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2011-04-06 17:38:08 UTC (rev 5625) @@ -521,6 +521,7 @@ <Compile Include="MappingByCode\ExplicitlyDeclaredModelTests\SubclassSequenceRegistrationTests.cs" /> <Compile Include="MappingByCode\ExplicitlyDeclaredModelTests\UnionSubclassMappingStrategyTests.cs" /> <Compile Include="MappingByCode\ExplicitlyDeclaredModelTests\UnionSubclassSequenceRegistrationTests.cs" /> + <Compile Include="MappingByCode\ExpliticMappingTests\ConformistMappingRegistrationTests\ModelMapperAddMappingByTypeTests.cs" /> <Compile Include="MappingByCode\ExpliticMappingTests\IdBagMappingTest.cs" /> <Compile Include="MappingByCode\ExpliticMappingTests\MappingOfPrivateMembersOnRootEntity.cs" /> <Compile Include="MappingByCode\ExpliticMappingTests\NaturalIdTests.cs" /> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fab...@us...> - 2011-04-06 17:05:26
|
Revision: 5624 http://nhibernate.svn.sourceforge.net/nhibernate/?rev=5624&view=rev Author: fabiomaulo Date: 2011-04-06 17:05:20 +0000 (Wed, 06 Apr 2011) Log Message: ----------- Conformist mapping for root-class Modified Paths: -------------- trunk/nhibernate/src/NHibernate/Mapping/ByCode/ModelMapper.cs trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj Added Paths: ----------- trunk/nhibernate/src/NHibernate.Test/MappingByCode/ExpliticMappingTests/ConformistMappingRegistrationTests/ trunk/nhibernate/src/NHibernate.Test/MappingByCode/ExpliticMappingTests/ConformistMappingRegistrationTests/ClassMappingRegistrationTest.cs Modified: trunk/nhibernate/src/NHibernate/Mapping/ByCode/ModelMapper.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Mapping/ByCode/ModelMapper.cs 2011-04-06 16:07:13 UTC (rev 5623) +++ trunk/nhibernate/src/NHibernate/Mapping/ByCode/ModelMapper.cs 2011-04-06 17:05:20 UTC (rev 5624) @@ -1590,5 +1590,22 @@ } #endregion + + public void AddMapping<T>() where T: IConformistHoldersProvider, new() + { + var mapping = new T(); + var thisCustomizerHolder = customizerHolder as CustomizersHolder; + if (thisCustomizerHolder == null) + { + throw new NotSupportedException("To merge 'conformist' mappings, the instance of ICustomizersHolder, provided in the ModelMapper constructor, have to be a CustomizersHolder instance."); + } + var otherCustomizerHolder = mapping.CustomizersHolder as CustomizersHolder; + if(otherCustomizerHolder == null) + { + throw new NotSupportedException("The mapping class have to provide a CustomizersHolder instance."); + } + thisCustomizerHolder.Merge(otherCustomizerHolder); + explicitDeclarationsHolder.Merge(mapping.ExplicitDeclarationsHolder); + } } } \ No newline at end of file Added: trunk/nhibernate/src/NHibernate.Test/MappingByCode/ExpliticMappingTests/ConformistMappingRegistrationTests/ClassMappingRegistrationTest.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Test/MappingByCode/ExpliticMappingTests/ConformistMappingRegistrationTests/ClassMappingRegistrationTest.cs (rev 0) +++ trunk/nhibernate/src/NHibernate.Test/MappingByCode/ExpliticMappingTests/ConformistMappingRegistrationTests/ClassMappingRegistrationTest.cs 2011-04-06 17:05:20 UTC (rev 5624) @@ -0,0 +1,53 @@ +using System.Linq; +using NHibernate.Cfg.MappingSchema; +using NUnit.Framework; +using NHibernate.Mapping.ByCode; +using NHibernate.Mapping.ByCode.Conformist; +using SharpTestsEx; + +namespace NHibernate.Test.MappingByCode.ExpliticMappingTests.ConformistMappingRegistrationTests +{ + public class ClassMappingRegistrationTest + { + public class MyClass + { + public int Id { get; set; } + public string Something { get; set; } + } + + private class MyClassMap: ClassMapping<MyClass> + { + public MyClassMap() + { + Id(x => x.Id, map => + { + map.Column("MyClassId"); + map.Generator(Generators.HighLow, gmap => gmap.Params(new { max_low = 100 })); + }); + Property(x => x.Something, map => map.Length(150)); + } + } + + [Test] + public void WhenRegisterClassMappingThenMapTheClass() + { + var mapper = new ModelMapper(); + mapper.AddMapping<MyClassMap>(); + var hbmMapping = mapper.CompileMappingFor(new[] { typeof(MyClass) }); + + var hbmClass = hbmMapping.RootClasses[0]; + hbmClass.Should().Not.Be.Null(); + var hbmId = hbmClass.Id; + hbmId.Should().Not.Be.Null(); + hbmId.name.Should().Be("Id"); + var hbmGenerator = hbmId.generator; + hbmGenerator.Should().Not.Be.Null(); + hbmGenerator.@class.Should().Be("hilo"); + hbmGenerator.param[0].name.Should().Be("max_low"); + hbmGenerator.param[0].GetText().Should().Be("100"); + var hbmProperty = hbmClass.Properties.OfType<HbmProperty>().Single(); + hbmProperty.name.Should().Be("Something"); + hbmProperty.length.Should().Be("150"); + } + } +} \ No newline at end of file Modified: trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2011-04-06 16:07:13 UTC (rev 5623) +++ trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2011-04-06 17:05:20 UTC (rev 5624) @@ -508,6 +508,7 @@ <Compile Include="Linq\ByMethod\SumTests.cs" /> <Compile Include="Logging\Log4NetLoggerTest.cs" /> <Compile Include="Logging\LoggerProviderTest.cs" /> + <Compile Include="MappingByCode\ExpliticMappingTests\ConformistMappingRegistrationTests\ClassMappingRegistrationTest.cs" /> <Compile Include="MappingByCode\CustomizerHolderMergeTest.cs" /> <Compile Include="MappingByCode\ExplicitlyDeclaredModelTests\SplitPropertiesRegistrationTests.cs" /> <Compile Include="MappingByCode\ExpliticMappingTests\BasicMappingOfSimpleClass.cs" /> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fab...@us...> - 2011-04-06 16:07:20
|
Revision: 5623 http://nhibernate.svn.sourceforge.net/nhibernate/?rev=5623&view=rev Author: fabiomaulo Date: 2011-04-06 16:07:13 +0000 (Wed, 06 Apr 2011) Log Message: ----------- Added classes for Conformist mapping Modified Paths: -------------- trunk/nhibernate/src/NHibernate/Mapping/ByCode/Impl/CustomizersImpl/ClassCustomizer.cs trunk/nhibernate/src/NHibernate/Mapping/ByCode/Impl/CustomizersImpl/PropertyContainerCustomizer.cs trunk/nhibernate/src/NHibernate/NHibernate.csproj trunk/nhibernate/src/NHibernate.Test/MappingByCode/ModelExplicitDeclarationsHolderMergeTest.cs Added Paths: ----------- trunk/nhibernate/src/NHibernate/Mapping/ByCode/Conformist/ trunk/nhibernate/src/NHibernate/Mapping/ByCode/Conformist/ClassMapping.cs trunk/nhibernate/src/NHibernate/Mapping/ByCode/Conformist/ComponentMapping.cs trunk/nhibernate/src/NHibernate/Mapping/ByCode/Conformist/JoinedSubclassMapping.cs trunk/nhibernate/src/NHibernate/Mapping/ByCode/Conformist/SubclassMapping.cs trunk/nhibernate/src/NHibernate/Mapping/ByCode/Conformist/UnionSubclassMapping.cs trunk/nhibernate/src/NHibernate/Mapping/ByCode/IConformistHoldersProvider.cs trunk/nhibernate/src/NHibernate/Mapping/ByCode/Impl/ExplicitDeclarationsHolder.cs Added: trunk/nhibernate/src/NHibernate/Mapping/ByCode/Conformist/ClassMapping.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Mapping/ByCode/Conformist/ClassMapping.cs (rev 0) +++ trunk/nhibernate/src/NHibernate/Mapping/ByCode/Conformist/ClassMapping.cs 2011-04-06 16:07:13 UTC (rev 5623) @@ -0,0 +1,10 @@ +using NHibernate.Mapping.ByCode.Impl; +using NHibernate.Mapping.ByCode.Impl.CustomizersImpl; + +namespace NHibernate.Mapping.ByCode.Conformist +{ + public class ClassMapping<T> : ClassCustomizer<T> where T : class + { + public ClassMapping() : base(new ExplicitDeclarationsHolder(), new CustomizersHolder()) { } + } +} \ No newline at end of file Added: trunk/nhibernate/src/NHibernate/Mapping/ByCode/Conformist/ComponentMapping.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Mapping/ByCode/Conformist/ComponentMapping.cs (rev 0) +++ trunk/nhibernate/src/NHibernate/Mapping/ByCode/Conformist/ComponentMapping.cs 2011-04-06 16:07:13 UTC (rev 5623) @@ -0,0 +1,10 @@ +using NHibernate.Mapping.ByCode.Impl; +using NHibernate.Mapping.ByCode.Impl.CustomizersImpl; + +namespace NHibernate.Mapping.ByCode.Conformist +{ + public class ComponentMapping<T> : ComponentCustomizer<T> where T : class + { + public ComponentMapping() : base(new ExplicitDeclarationsHolder(), new CustomizersHolder()) { } + } +} \ No newline at end of file Added: trunk/nhibernate/src/NHibernate/Mapping/ByCode/Conformist/JoinedSubclassMapping.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Mapping/ByCode/Conformist/JoinedSubclassMapping.cs (rev 0) +++ trunk/nhibernate/src/NHibernate/Mapping/ByCode/Conformist/JoinedSubclassMapping.cs 2011-04-06 16:07:13 UTC (rev 5623) @@ -0,0 +1,10 @@ +using NHibernate.Mapping.ByCode.Impl; +using NHibernate.Mapping.ByCode.Impl.CustomizersImpl; + +namespace NHibernate.Mapping.ByCode.Conformist +{ + public class JoinedSubclassMapping<T> : JoinedSubclassCustomizer<T> where T : class + { + public JoinedSubclassMapping() : base(new ExplicitDeclarationsHolder(), new CustomizersHolder()) { } + } +} \ No newline at end of file Added: trunk/nhibernate/src/NHibernate/Mapping/ByCode/Conformist/SubclassMapping.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Mapping/ByCode/Conformist/SubclassMapping.cs (rev 0) +++ trunk/nhibernate/src/NHibernate/Mapping/ByCode/Conformist/SubclassMapping.cs 2011-04-06 16:07:13 UTC (rev 5623) @@ -0,0 +1,10 @@ +using NHibernate.Mapping.ByCode.Impl; +using NHibernate.Mapping.ByCode.Impl.CustomizersImpl; + +namespace NHibernate.Mapping.ByCode.Conformist +{ + public class SubclassMapping<T> : SubclassCustomizer<T> where T : class + { + public SubclassMapping() : base(new ExplicitDeclarationsHolder(), new CustomizersHolder()) { } + } +} \ No newline at end of file Added: trunk/nhibernate/src/NHibernate/Mapping/ByCode/Conformist/UnionSubclassMapping.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Mapping/ByCode/Conformist/UnionSubclassMapping.cs (rev 0) +++ trunk/nhibernate/src/NHibernate/Mapping/ByCode/Conformist/UnionSubclassMapping.cs 2011-04-06 16:07:13 UTC (rev 5623) @@ -0,0 +1,10 @@ +using NHibernate.Mapping.ByCode.Impl; +using NHibernate.Mapping.ByCode.Impl.CustomizersImpl; + +namespace NHibernate.Mapping.ByCode.Conformist +{ + public class UnionSubclassMapping<T> : UnionSubclassCustomizer<T> where T : class + { + public UnionSubclassMapping() : base(new ExplicitDeclarationsHolder(), new CustomizersHolder()) { } + } +} \ No newline at end of file Added: trunk/nhibernate/src/NHibernate/Mapping/ByCode/IConformistHoldersProvider.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Mapping/ByCode/IConformistHoldersProvider.cs (rev 0) +++ trunk/nhibernate/src/NHibernate/Mapping/ByCode/IConformistHoldersProvider.cs 2011-04-06 16:07:13 UTC (rev 5623) @@ -0,0 +1,10 @@ +using NHibernate.Mapping.ByCode.Impl; + +namespace NHibernate.Mapping.ByCode +{ + public interface IConformistHoldersProvider + { + ICustomizersHolder CustomizersHolder { get; } + IModelExplicitDeclarationsHolder ExplicitDeclarationsHolder { get; } + } +} \ No newline at end of file Modified: trunk/nhibernate/src/NHibernate/Mapping/ByCode/Impl/CustomizersImpl/ClassCustomizer.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Mapping/ByCode/Impl/CustomizersImpl/ClassCustomizer.cs 2011-04-06 15:13:35 UTC (rev 5622) +++ trunk/nhibernate/src/NHibernate/Mapping/ByCode/Impl/CustomizersImpl/ClassCustomizer.cs 2011-04-06 16:07:13 UTC (rev 5623) @@ -6,7 +6,7 @@ namespace NHibernate.Mapping.ByCode.Impl.CustomizersImpl { - public class ClassCustomizer<TEntity> : PropertyContainerCustomizer<TEntity>, IClassMapper<TEntity> where TEntity : class + public class ClassCustomizer<TEntity> : PropertyContainerCustomizer<TEntity>, IClassMapper<TEntity>, IConformistHoldersProvider where TEntity : class { private Dictionary<string, IJoinMapper<TEntity>> joinCustomizers; @@ -201,5 +201,15 @@ } #endregion + + ICustomizersHolder IConformistHoldersProvider.CustomizersHolder + { + get { return CustomizersHolder; } + } + + IModelExplicitDeclarationsHolder IConformistHoldersProvider.ExplicitDeclarationsHolder + { + get { return ExplicitDeclarationsHolder; } + } } } \ No newline at end of file Modified: trunk/nhibernate/src/NHibernate/Mapping/ByCode/Impl/CustomizersImpl/PropertyContainerCustomizer.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Mapping/ByCode/Impl/CustomizersImpl/PropertyContainerCustomizer.cs 2011-04-06 15:13:35 UTC (rev 5622) +++ trunk/nhibernate/src/NHibernate/Mapping/ByCode/Impl/CustomizersImpl/PropertyContainerCustomizer.cs 2011-04-06 16:07:13 UTC (rev 5623) @@ -20,9 +20,10 @@ PropertyPath = propertyPath; } - protected ICustomizersHolder CustomizersHolder { get; private set; } - protected PropertyPath PropertyPath { get; private set; } - protected IModelExplicitDeclarationsHolder ExplicitDeclarationsHolder + protected internal ICustomizersHolder CustomizersHolder { get; private set; } + protected internal PropertyPath PropertyPath { get; private set; } + + protected internal IModelExplicitDeclarationsHolder ExplicitDeclarationsHolder { get { return explicitDeclarationsHolder; } } Added: trunk/nhibernate/src/NHibernate/Mapping/ByCode/Impl/ExplicitDeclarationsHolder.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Mapping/ByCode/Impl/ExplicitDeclarationsHolder.cs (rev 0) +++ trunk/nhibernate/src/NHibernate/Mapping/ByCode/Impl/ExplicitDeclarationsHolder.cs 2011-04-06 16:07:13 UTC (rev 5623) @@ -0,0 +1,255 @@ +using System.Collections.Generic; +using System.Linq; +using System.Reflection; + +namespace NHibernate.Mapping.ByCode.Impl +{ + public class ExplicitDeclarationsHolder : IModelExplicitDeclarationsHolder + { + private readonly HashSet<MemberInfo> any = new HashSet<MemberInfo>(); + private readonly HashSet<MemberInfo> arrays = new HashSet<MemberInfo>(); + private readonly HashSet<MemberInfo> bags = new HashSet<MemberInfo>(); + private readonly HashSet<System.Type> components = new HashSet<System.Type>(); + private readonly HashSet<MemberInfo> dictionaries = new HashSet<MemberInfo>(); + private readonly HashSet<MemberInfo> idBags = new HashSet<MemberInfo>(); + private readonly HashSet<MemberInfo> lists = new HashSet<MemberInfo>(); + private readonly HashSet<MemberInfo> manyToManyRelations = new HashSet<MemberInfo>(); + private readonly HashSet<MemberInfo> manyToOneRelations = new HashSet<MemberInfo>(); + private readonly HashSet<MemberInfo> naturalIds = new HashSet<MemberInfo>(); + private readonly HashSet<MemberInfo> oneToManyRelations = new HashSet<MemberInfo>(); + private readonly HashSet<MemberInfo> oneToOneRelations = new HashSet<MemberInfo>(); + private readonly HashSet<MemberInfo> poids = new HashSet<MemberInfo>(); + private readonly HashSet<MemberInfo> properties = new HashSet<MemberInfo>(); + private readonly HashSet<System.Type> rootEntities = new HashSet<System.Type>(); + private readonly HashSet<MemberInfo> sets = new HashSet<MemberInfo>(); + private readonly HashSet<SplitDefinition> splitDefinitions = new HashSet<SplitDefinition>(); + private readonly HashSet<System.Type> tablePerClassEntities = new HashSet<System.Type>(); + private readonly HashSet<System.Type> tablePerClassHierarchyEntities = new HashSet<System.Type>(); + private readonly HashSet<System.Type> tablePerConcreteClassEntities = new HashSet<System.Type>(); + private readonly HashSet<MemberInfo> versionProperties = new HashSet<MemberInfo>(); + + #region IModelExplicitDeclarationsHolder Members + + public IEnumerable<System.Type> RootEntities + { + get { return rootEntities; } + } + + public IEnumerable<System.Type> Components + { + get { return components; } + } + + public IEnumerable<System.Type> TablePerClassEntities + { + get { return tablePerClassEntities; } + } + + public IEnumerable<System.Type> TablePerClassHierarchyEntities + { + get { return tablePerClassHierarchyEntities; } + } + + public IEnumerable<System.Type> TablePerConcreteClassEntities + { + get { return tablePerConcreteClassEntities; } + } + + public IEnumerable<MemberInfo> OneToOneRelations + { + get { return oneToOneRelations; } + } + + public IEnumerable<MemberInfo> ManyToOneRelations + { + get { return manyToOneRelations; } + } + + public IEnumerable<MemberInfo> ManyToManyRelations + { + get { return manyToManyRelations; } + } + + public IEnumerable<MemberInfo> OneToManyRelations + { + get { return oneToManyRelations; } + } + + public IEnumerable<MemberInfo> Any + { + get { return any; } + } + + public IEnumerable<MemberInfo> Poids + { + get { return poids; } + } + + public IEnumerable<MemberInfo> VersionProperties + { + get { return versionProperties; } + } + + public IEnumerable<MemberInfo> NaturalIds + { + get { return naturalIds; } + } + + public IEnumerable<MemberInfo> Sets + { + get { return sets; } + } + + public IEnumerable<MemberInfo> Bags + { + get { return bags; } + } + + public IEnumerable<MemberInfo> IdBags + { + get { return idBags; } + } + + public IEnumerable<MemberInfo> Lists + { + get { return lists; } + } + + public IEnumerable<MemberInfo> Arrays + { + get { return arrays; } + } + + public IEnumerable<MemberInfo> Dictionaries + { + get { return dictionaries; } + } + + public IEnumerable<MemberInfo> Properties + { + get { return properties; } + } + + public IEnumerable<SplitDefinition> SplitDefinitions + { + get { return splitDefinitions; } + } + + public IEnumerable<string> GetSplitGroupsFor(System.Type type) + { + return Enumerable.Empty<string>(); + } + + public string GetSplitGroupFor(MemberInfo member) + { + return null; + } + + public void AddAsRootEntity(System.Type type) + { + rootEntities.Add(type); + } + + public void AddAsComponent(System.Type type) + { + components.Add(type); + } + + public void AddAsTablePerClassEntity(System.Type type) + { + tablePerClassEntities.Add(type); + } + + public void AddAsTablePerClassHierarchyEntity(System.Type type) + { + tablePerClassHierarchyEntities.Add(type); + } + + public void AddAsTablePerConcreteClassEntity(System.Type type) + { + tablePerConcreteClassEntities.Add(type); + } + + public void AddAsOneToOneRelation(MemberInfo member) + { + oneToOneRelations.Add(member); + } + + public void AddAsManyToOneRelation(MemberInfo member) + { + manyToOneRelations.Add(member); + } + + public void AddAsManyToManyRelation(MemberInfo member) + { + manyToManyRelations.Add(member); + } + + public void AddAsOneToManyRelation(MemberInfo member) + { + oneToManyRelations.Add(member); + } + + public void AddAsAny(MemberInfo member) + { + any.Add(member); + } + + public void AddAsPoid(MemberInfo member) + { + poids.Add(member); + } + + public void AddAsVersionProperty(MemberInfo member) + { + versionProperties.Add(member); + } + + public void AddAsNaturalId(MemberInfo member) + { + naturalIds.Add(member); + } + + public void AddAsSet(MemberInfo member) + { + sets.Add(member); + } + + public void AddAsBag(MemberInfo member) + { + bags.Add(member); + } + + public void AddAsIdBag(MemberInfo member) + { + idBags.Add(member); + } + + public void AddAsList(MemberInfo member) + { + lists.Add(member); + } + + public void AddAsArray(MemberInfo member) + { + arrays.Add(member); + } + + public void AddAsMap(MemberInfo member) + { + dictionaries.Add(member); + } + + public void AddAsProperty(MemberInfo member) + { + properties.Add(member); + } + + public void AddAsPropertySplit(System.Type propertyContainer, string splitGroupId, MemberInfo member) + { + splitDefinitions.Add(new SplitDefinition(propertyContainer, splitGroupId, member)); + } + + #endregion + } +} \ No newline at end of file Modified: trunk/nhibernate/src/NHibernate/NHibernate.csproj =================================================================== --- trunk/nhibernate/src/NHibernate/NHibernate.csproj 2011-04-06 15:13:35 UTC (rev 5622) +++ trunk/nhibernate/src/NHibernate/NHibernate.csproj 2011-04-06 16:07:13 UTC (rev 5623) @@ -280,6 +280,11 @@ <Compile Include="Mapping\ByCode\CascadeExtensions.cs" /> <Compile Include="Mapping\ByCode\CollectionFetchMode.cs" /> <Compile Include="Mapping\ByCode\CollectionLazy.cs" /> + <Compile Include="Mapping\ByCode\Conformist\ClassMapping.cs" /> + <Compile Include="Mapping\ByCode\Conformist\ComponentMapping.cs" /> + <Compile Include="Mapping\ByCode\Conformist\JoinedSubclassMapping.cs" /> + <Compile Include="Mapping\ByCode\Conformist\SubclassMapping.cs" /> + <Compile Include="Mapping\ByCode\Conformist\UnionSubclassMapping.cs" /> <Compile Include="Mapping\ByCode\ExplicitlyDeclaredModel.cs" /> <Compile Include="Mapping\ByCode\FakeModelExplicitDeclarationsHolder.cs" /> <Compile Include="Mapping\ByCode\FetchKind.cs" /> @@ -299,6 +304,7 @@ <Compile Include="Mapping\ByCode\IComponentMapKeyMapper.cs" /> <Compile Include="Mapping\ByCode\IComponentMapper.cs" /> <Compile Include="Mapping\ByCode\IComponentParentMapper.cs" /> + <Compile Include="Mapping\ByCode\IConformistHoldersProvider.cs" /> <Compile Include="Mapping\ByCode\IDiscriminatorMapper.cs" /> <Compile Include="Mapping\ByCode\IElementMapper.cs" /> <Compile Include="Mapping\ByCode\IEntityAttributesMapper.cs" /> @@ -369,6 +375,7 @@ <Compile Include="Mapping\ByCode\Impl\DefaultCandidatePersistentMembersProvider.cs" /> <Compile Include="Mapping\ByCode\Impl\DiscriminatorMapper.cs" /> <Compile Include="Mapping\ByCode\Impl\ElementMapper.cs" /> + <Compile Include="Mapping\ByCode\Impl\ExplicitDeclarationsHolder.cs" /> <Compile Include="Mapping\ByCode\Impl\FilterMapper.cs" /> <Compile Include="Mapping\ByCode\Impl\GeneratorMapper.cs" /> <Compile Include="Mapping\ByCode\Generators.cs" /> Modified: trunk/nhibernate/src/NHibernate.Test/MappingByCode/ModelExplicitDeclarationsHolderMergeTest.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Test/MappingByCode/ModelExplicitDeclarationsHolderMergeTest.cs 2011-04-06 15:13:35 UTC (rev 5622) +++ trunk/nhibernate/src/NHibernate.Test/MappingByCode/ModelExplicitDeclarationsHolderMergeTest.cs 2011-04-06 16:07:13 UTC (rev 5623) @@ -1,7 +1,6 @@ -using System.Collections.Generic; -using System.Linq; using System.Reflection; using NHibernate.Mapping.ByCode; +using NHibernate.Mapping.ByCode.Impl; using NUnit.Framework; using SharpTestsEx; @@ -14,15 +13,15 @@ [Test] public void WhenMergeNullsThenNotThrows() { - Executing.This(() => ((EmptyHolder) null).Merge(new EmptyHolder())).Should().NotThrow(); - Executing.This(() => (new EmptyHolder()).Merge(null)).Should().NotThrow(); + Executing.This(() => ((ExplicitDeclarationsHolder) null).Merge(new ExplicitDeclarationsHolder())).Should().NotThrow(); + Executing.This(() => (new ExplicitDeclarationsHolder()).Merge(null)).Should().NotThrow(); } [Test] public void MergeSplitDefinitions() { - var destination = new EmptyHolder(); - var source = new EmptyHolder(); + var destination = new ExplicitDeclarationsHolder(); + var source = new ExplicitDeclarationsHolder(); source.AddAsPropertySplit(typeof (MyClass), "foo", property); destination.Merge(source); @@ -32,8 +31,8 @@ [Test] public void MergeProperties() { - var destination = new EmptyHolder(); - var source = new EmptyHolder(); + var destination = new ExplicitDeclarationsHolder(); + var source = new ExplicitDeclarationsHolder(); source.AddAsProperty(property); destination.Merge(source); @@ -43,8 +42,8 @@ [Test] public void MergeDictionaries() { - var destination = new EmptyHolder(); - var source = new EmptyHolder(); + var destination = new ExplicitDeclarationsHolder(); + var source = new ExplicitDeclarationsHolder(); source.AddAsMap(property); destination.Merge(source); @@ -54,8 +53,8 @@ [Test] public void MergeArrays() { - var destination = new EmptyHolder(); - var source = new EmptyHolder(); + var destination = new ExplicitDeclarationsHolder(); + var source = new ExplicitDeclarationsHolder(); source.AddAsArray(property); destination.Merge(source); @@ -65,8 +64,8 @@ [Test] public void MergeLists() { - var destination = new EmptyHolder(); - var source = new EmptyHolder(); + var destination = new ExplicitDeclarationsHolder(); + var source = new ExplicitDeclarationsHolder(); source.AddAsList(property); destination.Merge(source); @@ -76,8 +75,8 @@ [Test] public void MergeIdBags() { - var destination = new EmptyHolder(); - var source = new EmptyHolder(); + var destination = new ExplicitDeclarationsHolder(); + var source = new ExplicitDeclarationsHolder(); source.AddAsIdBag(property); destination.Merge(source); @@ -87,8 +86,8 @@ [Test] public void MergeBags() { - var destination = new EmptyHolder(); - var source = new EmptyHolder(); + var destination = new ExplicitDeclarationsHolder(); + var source = new ExplicitDeclarationsHolder(); source.AddAsBag(property); destination.Merge(source); @@ -98,8 +97,8 @@ [Test] public void MergeSets() { - var destination = new EmptyHolder(); - var source = new EmptyHolder(); + var destination = new ExplicitDeclarationsHolder(); + var source = new ExplicitDeclarationsHolder(); source.AddAsSet(property); destination.Merge(source); @@ -109,8 +108,8 @@ [Test] public void MergeNaturalIds() { - var destination = new EmptyHolder(); - var source = new EmptyHolder(); + var destination = new ExplicitDeclarationsHolder(); + var source = new ExplicitDeclarationsHolder(); source.AddAsNaturalId(property); destination.Merge(source); @@ -120,8 +119,8 @@ [Test] public void MergeVersionProperties() { - var destination = new EmptyHolder(); - var source = new EmptyHolder(); + var destination = new ExplicitDeclarationsHolder(); + var source = new ExplicitDeclarationsHolder(); source.AddAsVersionProperty(property); destination.Merge(source); @@ -131,8 +130,8 @@ [Test] public void MergePoids() { - var destination = new EmptyHolder(); - var source = new EmptyHolder(); + var destination = new ExplicitDeclarationsHolder(); + var source = new ExplicitDeclarationsHolder(); source.AddAsPoid(property); destination.Merge(source); @@ -142,8 +141,8 @@ [Test] public void MergeAny() { - var destination = new EmptyHolder(); - var source = new EmptyHolder(); + var destination = new ExplicitDeclarationsHolder(); + var source = new ExplicitDeclarationsHolder(); source.AddAsAny(property); destination.Merge(source); @@ -153,8 +152,8 @@ [Test] public void MergeOneToManyRelations() { - var destination = new EmptyHolder(); - var source = new EmptyHolder(); + var destination = new ExplicitDeclarationsHolder(); + var source = new ExplicitDeclarationsHolder(); source.AddAsOneToManyRelation(property); destination.Merge(source); @@ -164,8 +163,8 @@ [Test] public void MergeManyToManyRelations() { - var destination = new EmptyHolder(); - var source = new EmptyHolder(); + var destination = new ExplicitDeclarationsHolder(); + var source = new ExplicitDeclarationsHolder(); source.AddAsManyToManyRelation(property); destination.Merge(source); @@ -175,8 +174,8 @@ [Test] public void MergeManyToOneRelations() { - var destination = new EmptyHolder(); - var source = new EmptyHolder(); + var destination = new ExplicitDeclarationsHolder(); + var source = new ExplicitDeclarationsHolder(); source.AddAsManyToOneRelation(property); destination.Merge(source); @@ -186,8 +185,8 @@ [Test] public void MergeOneToOneRelations() { - var destination = new EmptyHolder(); - var source = new EmptyHolder(); + var destination = new ExplicitDeclarationsHolder(); + var source = new ExplicitDeclarationsHolder(); source.AddAsOneToOneRelation(property); destination.Merge(source); @@ -197,8 +196,8 @@ [Test] public void MergeTablePerConcreteClassEntities() { - var destination = new EmptyHolder(); - var source = new EmptyHolder(); + var destination = new ExplicitDeclarationsHolder(); + var source = new ExplicitDeclarationsHolder(); source.AddAsTablePerConcreteClassEntity(typeof (MyClass)); destination.Merge(source); @@ -208,8 +207,8 @@ [Test] public void MergeTablePerClassHierarchyEntities() { - var destination = new EmptyHolder(); - var source = new EmptyHolder(); + var destination = new ExplicitDeclarationsHolder(); + var source = new ExplicitDeclarationsHolder(); source.AddAsTablePerClassHierarchyEntity(typeof (MyClass)); destination.Merge(source); @@ -219,8 +218,8 @@ [Test] public void MergeTablePerClassEntities() { - var destination = new EmptyHolder(); - var source = new EmptyHolder(); + var destination = new ExplicitDeclarationsHolder(); + var source = new ExplicitDeclarationsHolder(); source.AddAsTablePerClassEntity(typeof (MyClass)); destination.Merge(source); @@ -230,8 +229,8 @@ [Test] public void MergeComponents() { - var destination = new EmptyHolder(); - var source = new EmptyHolder(); + var destination = new ExplicitDeclarationsHolder(); + var source = new ExplicitDeclarationsHolder(); source.AddAsComponent(typeof (MyClass)); destination.Merge(source); @@ -241,267 +240,14 @@ [Test] public void MergeRootEntities() { - var destination = new EmptyHolder(); - var source = new EmptyHolder(); + var destination = new ExplicitDeclarationsHolder(); + var source = new ExplicitDeclarationsHolder(); source.AddAsRootEntity(typeof (MyClass)); destination.Merge(source); destination.RootEntities.Should().Have.Count.EqualTo(1); } - #region Nested type: EmptyHolder - - public class EmptyHolder : IModelExplicitDeclarationsHolder - { - private readonly HashSet<MemberInfo> any = new HashSet<MemberInfo>(); - private readonly HashSet<MemberInfo> arrays = new HashSet<MemberInfo>(); - private readonly HashSet<MemberInfo> bags = new HashSet<MemberInfo>(); - private readonly HashSet<System.Type> components = new HashSet<System.Type>(); - private readonly HashSet<MemberInfo> dictionaries = new HashSet<MemberInfo>(); - private readonly HashSet<MemberInfo> idBags = new HashSet<MemberInfo>(); - private readonly HashSet<MemberInfo> lists = new HashSet<MemberInfo>(); - private readonly HashSet<MemberInfo> manyToManyRelations = new HashSet<MemberInfo>(); - private readonly HashSet<MemberInfo> manyToOneRelations = new HashSet<MemberInfo>(); - private readonly HashSet<MemberInfo> naturalIds = new HashSet<MemberInfo>(); - private readonly HashSet<MemberInfo> oneToManyRelations = new HashSet<MemberInfo>(); - private readonly HashSet<MemberInfo> oneToOneRelations = new HashSet<MemberInfo>(); - private readonly HashSet<MemberInfo> poids = new HashSet<MemberInfo>(); - private readonly HashSet<MemberInfo> properties = new HashSet<MemberInfo>(); - private readonly HashSet<System.Type> rootEntities = new HashSet<System.Type>(); - private readonly HashSet<MemberInfo> sets = new HashSet<MemberInfo>(); - private readonly HashSet<SplitDefinition> splitDefinitions = new HashSet<SplitDefinition>(); - private readonly HashSet<System.Type> tablePerClassEntities = new HashSet<System.Type>(); - private readonly HashSet<System.Type> tablePerClassHierarchyEntities = new HashSet<System.Type>(); - private readonly HashSet<System.Type> tablePerConcreteClassEntities = new HashSet<System.Type>(); - private readonly HashSet<MemberInfo> versionProperties = new HashSet<MemberInfo>(); - - #region IModelExplicitDeclarationsHolder Members - - public IEnumerable<System.Type> RootEntities - { - get { return rootEntities; } - } - - public IEnumerable<System.Type> Components - { - get { return components; } - } - - public IEnumerable<System.Type> TablePerClassEntities - { - get { return tablePerClassEntities; } - } - - public IEnumerable<System.Type> TablePerClassHierarchyEntities - { - get { return tablePerClassHierarchyEntities; } - } - - public IEnumerable<System.Type> TablePerConcreteClassEntities - { - get { return tablePerConcreteClassEntities; } - } - - public IEnumerable<MemberInfo> OneToOneRelations - { - get { return oneToOneRelations; } - } - - public IEnumerable<MemberInfo> ManyToOneRelations - { - get { return manyToOneRelations; } - } - - public IEnumerable<MemberInfo> ManyToManyRelations - { - get { return manyToManyRelations; } - } - - public IEnumerable<MemberInfo> OneToManyRelations - { - get { return oneToManyRelations; } - } - - public IEnumerable<MemberInfo> Any - { - get { return any; } - } - - public IEnumerable<MemberInfo> Poids - { - get { return poids; } - } - - public IEnumerable<MemberInfo> VersionProperties - { - get { return versionProperties; } - } - - public IEnumerable<MemberInfo> NaturalIds - { - get { return naturalIds; } - } - - public IEnumerable<MemberInfo> Sets - { - get { return sets; } - } - - public IEnumerable<MemberInfo> Bags - { - get { return bags; } - } - - public IEnumerable<MemberInfo> IdBags - { - get { return idBags; } - } - - public IEnumerable<MemberInfo> Lists - { - get { return lists; } - } - - public IEnumerable<MemberInfo> Arrays - { - get { return arrays; } - } - - public IEnumerable<MemberInfo> Dictionaries - { - get { return dictionaries; } - } - - public IEnumerable<MemberInfo> Properties - { - get { return properties; } - } - - public IEnumerable<SplitDefinition> SplitDefinitions - { - get { return splitDefinitions; } - } - - public IEnumerable<string> GetSplitGroupsFor(System.Type type) - { - return Enumerable.Empty<string>(); - } - - public string GetSplitGroupFor(MemberInfo member) - { - return null; - } - - public void AddAsRootEntity(System.Type type) - { - rootEntities.Add(type); - } - - public void AddAsComponent(System.Type type) - { - components.Add(type); - } - - public void AddAsTablePerClassEntity(System.Type type) - { - tablePerClassEntities.Add(type); - } - - public void AddAsTablePerClassHierarchyEntity(System.Type type) - { - tablePerClassHierarchyEntities.Add(type); - } - - public void AddAsTablePerConcreteClassEntity(System.Type type) - { - tablePerConcreteClassEntities.Add(type); - } - - public void AddAsOneToOneRelation(MemberInfo member) - { - oneToOneRelations.Add(member); - } - - public void AddAsManyToOneRelation(MemberInfo member) - { - manyToOneRelations.Add(member); - } - - public void AddAsManyToManyRelation(MemberInfo member) - { - manyToManyRelations.Add(member); - } - - public void AddAsOneToManyRelation(MemberInfo member) - { - oneToManyRelations.Add(member); - } - - public void AddAsAny(MemberInfo member) - { - any.Add(member); - } - - public void AddAsPoid(MemberInfo member) - { - poids.Add(member); - } - - public void AddAsVersionProperty(MemberInfo member) - { - versionProperties.Add(member); - } - - public void AddAsNaturalId(MemberInfo member) - { - naturalIds.Add(member); - } - - public void AddAsSet(MemberInfo member) - { - sets.Add(member); - } - - public void AddAsBag(MemberInfo member) - { - bags.Add(member); - } - - public void AddAsIdBag(MemberInfo member) - { - idBags.Add(member); - } - - public void AddAsList(MemberInfo member) - { - lists.Add(member); - } - - public void AddAsArray(MemberInfo member) - { - arrays.Add(member); - } - - public void AddAsMap(MemberInfo member) - { - dictionaries.Add(member); - } - - public void AddAsProperty(MemberInfo member) - { - properties.Add(member); - } - - public void AddAsPropertySplit(System.Type propertyContainer, string splitGroupId, MemberInfo member) - { - splitDefinitions.Add(new SplitDefinition(propertyContainer, splitGroupId, member)); - } - - #endregion - } - - #endregion - #region Nested type: MyClass private class MyClass This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pa...@us...> - 2011-04-06 15:13:41
|
Revision: 5622 http://nhibernate.svn.sourceforge.net/nhibernate/?rev=5622&view=rev Author: patearl Date: 2011-04-06 15:13:35 +0000 (Wed, 06 Apr 2011) Log Message: ----------- Linq: Use GetSessionImplementation() instead of casting to ISessionImplementor. Modified Paths: -------------- trunk/nhibernate/src/NHibernate/Linq/LinqExtensionMethods.cs Modified: trunk/nhibernate/src/NHibernate/Linq/LinqExtensionMethods.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Linq/LinqExtensionMethods.cs 2011-04-06 15:10:54 UTC (rev 5621) +++ trunk/nhibernate/src/NHibernate/Linq/LinqExtensionMethods.cs 2011-04-06 15:13:35 UTC (rev 5622) @@ -11,12 +11,12 @@ { public static IQueryable<T> Query<T>(this ISession session) { - return new NhQueryable<T>(session as ISessionImplementor); + return new NhQueryable<T>(session.GetSessionImplementation()); } public static IQueryable<T> Query<T>(this IStatelessSession session) { - return new NhQueryable<T>(session as ISessionImplementor); + return new NhQueryable<T>(session.GetSessionImplementation()); } public static IQueryable<T> Cacheable<T>(this IQueryable<T> query) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fab...@us...> - 2011-04-06 15:11:01
|
Revision: 5621 http://nhibernate.svn.sourceforge.net/nhibernate/?rev=5621&view=rev Author: fabiomaulo Date: 2011-04-06 15:10:54 +0000 (Wed, 06 Apr 2011) Log Message: ----------- Merge IModelExplicitDeclarationsHolder Modified Paths: -------------- trunk/nhibernate/src/NHibernate/Mapping/ByCode/ExplicitlyDeclaredModel.cs trunk/nhibernate/src/NHibernate/Mapping/ByCode/FakeModelExplicitDeclarationsHolder.cs trunk/nhibernate/src/NHibernate/Mapping/ByCode/IModelExplicitDeclarationsHolder.cs trunk/nhibernate/src/NHibernate/NHibernate.csproj trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj Added Paths: ----------- trunk/nhibernate/src/NHibernate/Mapping/ByCode/ModelExplicitDeclarationsHolderExtensions.cs trunk/nhibernate/src/NHibernate.Test/MappingByCode/ModelExplicitDeclarationsHolderMergeTest.cs Modified: trunk/nhibernate/src/NHibernate/Mapping/ByCode/ExplicitlyDeclaredModel.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Mapping/ByCode/ExplicitlyDeclaredModel.cs 2011-04-06 13:41:56 UTC (rev 5620) +++ trunk/nhibernate/src/NHibernate/Mapping/ByCode/ExplicitlyDeclaredModel.cs 2011-04-06 15:10:54 UTC (rev 5621) @@ -31,6 +31,7 @@ private readonly Dictionary<System.Type, Action<System.Type>> delayedEntityRegistrations = new Dictionary<System.Type, Action<System.Type>>(); private readonly Dictionary<System.Type, HashSet<string>> typeSplitGroups = new Dictionary<System.Type, HashSet<string>>(); private readonly Dictionary<MemberInfo, string> memberSplitGroup = new Dictionary<MemberInfo, string>(); + private readonly HashSet<SplitDefinition> splitDefinitions = new HashSet<SplitDefinition>(); #region IModelExplicitDeclarationsHolder Members @@ -134,6 +135,11 @@ get { return properties; } } + public IEnumerable<SplitDefinition> SplitDefinitions + { + get { return splitDefinitions; } + } + public IEnumerable<string> GetSplitGroupsFor(System.Type type) { HashSet<string> splitsGroupsIds; @@ -378,6 +384,8 @@ AddTypeSplits(propertyContainer, splitGroupId); memberSplitGroup[memberKey] = splitGroupId; } + + splitDefinitions.Add(new SplitDefinition(propertyContainer, splitGroup, member)); } private void AddTypeSplits(System.Type propertyContainer, string splitGroupId) Modified: trunk/nhibernate/src/NHibernate/Mapping/ByCode/FakeModelExplicitDeclarationsHolder.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Mapping/ByCode/FakeModelExplicitDeclarationsHolder.cs 2011-04-06 13:41:56 UTC (rev 5620) +++ trunk/nhibernate/src/NHibernate/Mapping/ByCode/FakeModelExplicitDeclarationsHolder.cs 2011-04-06 15:10:54 UTC (rev 5621) @@ -28,6 +28,7 @@ private readonly IEnumerable<System.Type> tablePerClassHierarchyJoinEntities = Enumerable.Empty<System.Type>(); private readonly IEnumerable<System.Type> tablePerConcreteClassEntities = Enumerable.Empty<System.Type>(); private readonly IEnumerable<MemberInfo> versionProperties = Enumerable.Empty<MemberInfo>(); + private readonly IEnumerable<SplitDefinition> splitDefinitions = Enumerable.Empty<SplitDefinition>(); #region IModelExplicitDeclarationsHolder Members @@ -136,6 +137,11 @@ get { return properties; } } + public IEnumerable<SplitDefinition> SplitDefinitions + { + get { return splitDefinitions; } + } + public IEnumerable<string> GetSplitGroupsFor(System.Type type) { return Enumerable.Empty<string>(); Modified: trunk/nhibernate/src/NHibernate/Mapping/ByCode/IModelExplicitDeclarationsHolder.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Mapping/ByCode/IModelExplicitDeclarationsHolder.cs 2011-04-06 13:41:56 UTC (rev 5620) +++ trunk/nhibernate/src/NHibernate/Mapping/ByCode/IModelExplicitDeclarationsHolder.cs 2011-04-06 15:10:54 UTC (rev 5621) @@ -3,6 +3,20 @@ namespace NHibernate.Mapping.ByCode { + public class SplitDefinition + { + public SplitDefinition(System.Type @on, string groupId, MemberInfo member) + { + On = on; + GroupId = groupId; + Member = member; + } + + public System.Type On { get; private set; } + public string GroupId { get; private set; } + public MemberInfo Member { get; private set; } + } + public interface IModelExplicitDeclarationsHolder { IEnumerable<System.Type> RootEntities { get; } @@ -28,6 +42,8 @@ IEnumerable<MemberInfo> Arrays { get; } IEnumerable<MemberInfo> Dictionaries { get; } IEnumerable<MemberInfo> Properties { get; } + IEnumerable<SplitDefinition> SplitDefinitions { get; } + IEnumerable<string> GetSplitGroupsFor(System.Type type); string GetSplitGroupFor(MemberInfo member); Added: trunk/nhibernate/src/NHibernate/Mapping/ByCode/ModelExplicitDeclarationsHolderExtensions.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Mapping/ByCode/ModelExplicitDeclarationsHolderExtensions.cs (rev 0) +++ trunk/nhibernate/src/NHibernate/Mapping/ByCode/ModelExplicitDeclarationsHolderExtensions.cs 2011-04-06 15:10:54 UTC (rev 5621) @@ -0,0 +1,43 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Reflection; + +namespace NHibernate.Mapping.ByCode +{ + public static class ModelExplicitDeclarationsHolderExtensions + { + public static void Merge(this IModelExplicitDeclarationsHolder destination, IModelExplicitDeclarationsHolder source) + { + if (destination == null || source == null) + { + return; + } + + System.Array.ForEach(source.RootEntities.ToArray(), destination.AddAsRootEntity); + System.Array.ForEach(source.Components.ToArray(), destination.AddAsComponent); + System.Array.ForEach(source.TablePerClassEntities.ToArray(), destination.AddAsTablePerClassEntity); + System.Array.ForEach(source.TablePerClassHierarchyEntities.ToArray(), destination.AddAsTablePerClassHierarchyEntity); + System.Array.ForEach(source.TablePerConcreteClassEntities.ToArray(), destination.AddAsTablePerConcreteClassEntity); + + System.Array.ForEach(source.OneToOneRelations.ToArray(), destination.AddAsOneToOneRelation); + System.Array.ForEach(source.ManyToOneRelations.ToArray(), destination.AddAsManyToOneRelation); + System.Array.ForEach(source.ManyToManyRelations.ToArray(), destination.AddAsManyToManyRelation); + System.Array.ForEach(source.OneToManyRelations.ToArray(), destination.AddAsOneToManyRelation); + System.Array.ForEach(source.Any.ToArray(), destination.AddAsAny); + + System.Array.ForEach(source.Poids.ToArray(), destination.AddAsPoid); + System.Array.ForEach(source.VersionProperties.ToArray(), destination.AddAsVersionProperty); + System.Array.ForEach(source.NaturalIds.ToArray(), destination.AddAsNaturalId); + + System.Array.ForEach(source.Sets.ToArray(), destination.AddAsSet); + System.Array.ForEach(source.Bags.ToArray(), destination.AddAsBag); + System.Array.ForEach(source.IdBags.ToArray(), destination.AddAsIdBag); + System.Array.ForEach(source.Lists.ToArray(), destination.AddAsList); + System.Array.ForEach(source.Arrays.ToArray(), destination.AddAsArray); + System.Array.ForEach(source.Dictionaries.ToArray(), destination.AddAsMap); + System.Array.ForEach(source.Properties.ToArray(), destination.AddAsProperty); + System.Array.ForEach(source.SplitDefinitions.ToArray(), x => destination.AddAsPropertySplit(x.On, x.GroupId, x.Member)); + } + } +} \ No newline at end of file Modified: trunk/nhibernate/src/NHibernate/NHibernate.csproj =================================================================== --- trunk/nhibernate/src/NHibernate/NHibernate.csproj 2011-04-06 13:41:56 UTC (rev 5620) +++ trunk/nhibernate/src/NHibernate/NHibernate.csproj 2011-04-06 15:10:54 UTC (rev 5621) @@ -413,6 +413,7 @@ <Compile Include="Mapping\ByCode\IUnionSubclassMapper.cs" /> <Compile Include="Mapping\ByCode\IVersionMapper.cs" /> <Compile Include="Mapping\ByCode\Lazy.cs" /> + <Compile Include="Mapping\ByCode\ModelExplicitDeclarationsHolderExtensions.cs" /> <Compile Include="Mapping\ByCode\ModelMapper.cs" /> <Compile Include="Mapping\ByCode\MappingsExtensions.cs" /> <Compile Include="Mapping\ByCode\NotFoundMode.cs" /> Added: trunk/nhibernate/src/NHibernate.Test/MappingByCode/ModelExplicitDeclarationsHolderMergeTest.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Test/MappingByCode/ModelExplicitDeclarationsHolderMergeTest.cs (rev 0) +++ trunk/nhibernate/src/NHibernate.Test/MappingByCode/ModelExplicitDeclarationsHolderMergeTest.cs 2011-04-06 15:10:54 UTC (rev 5621) @@ -0,0 +1,514 @@ +using System.Collections.Generic; +using System.Linq; +using System.Reflection; +using NHibernate.Mapping.ByCode; +using NUnit.Framework; +using SharpTestsEx; + +namespace NHibernate.Test.MappingByCode +{ + public class ModelExplicitDeclarationsHolderMergeTest + { + private readonly MemberInfo property = typeof (MyClass).GetProperty("Bar"); + + [Test] + public void WhenMergeNullsThenNotThrows() + { + Executing.This(() => ((EmptyHolder) null).Merge(new EmptyHolder())).Should().NotThrow(); + Executing.This(() => (new EmptyHolder()).Merge(null)).Should().NotThrow(); + } + + [Test] + public void MergeSplitDefinitions() + { + var destination = new EmptyHolder(); + var source = new EmptyHolder(); + source.AddAsPropertySplit(typeof (MyClass), "foo", property); + + destination.Merge(source); + destination.SplitDefinitions.Should().Have.Count.EqualTo(1); + } + + [Test] + public void MergeProperties() + { + var destination = new EmptyHolder(); + var source = new EmptyHolder(); + source.AddAsProperty(property); + + destination.Merge(source); + destination.Properties.Should().Have.Count.EqualTo(1); + } + + [Test] + public void MergeDictionaries() + { + var destination = new EmptyHolder(); + var source = new EmptyHolder(); + source.AddAsMap(property); + + destination.Merge(source); + destination.Dictionaries.Should().Have.Count.EqualTo(1); + } + + [Test] + public void MergeArrays() + { + var destination = new EmptyHolder(); + var source = new EmptyHolder(); + source.AddAsArray(property); + + destination.Merge(source); + destination.Arrays.Should().Have.Count.EqualTo(1); + } + + [Test] + public void MergeLists() + { + var destination = new EmptyHolder(); + var source = new EmptyHolder(); + source.AddAsList(property); + + destination.Merge(source); + destination.Lists.Should().Have.Count.EqualTo(1); + } + + [Test] + public void MergeIdBags() + { + var destination = new EmptyHolder(); + var source = new EmptyHolder(); + source.AddAsIdBag(property); + + destination.Merge(source); + destination.IdBags.Should().Have.Count.EqualTo(1); + } + + [Test] + public void MergeBags() + { + var destination = new EmptyHolder(); + var source = new EmptyHolder(); + source.AddAsBag(property); + + destination.Merge(source); + destination.Bags.Should().Have.Count.EqualTo(1); + } + + [Test] + public void MergeSets() + { + var destination = new EmptyHolder(); + var source = new EmptyHolder(); + source.AddAsSet(property); + + destination.Merge(source); + destination.Sets.Should().Have.Count.EqualTo(1); + } + + [Test] + public void MergeNaturalIds() + { + var destination = new EmptyHolder(); + var source = new EmptyHolder(); + source.AddAsNaturalId(property); + + destination.Merge(source); + destination.NaturalIds.Should().Have.Count.EqualTo(1); + } + + [Test] + public void MergeVersionProperties() + { + var destination = new EmptyHolder(); + var source = new EmptyHolder(); + source.AddAsVersionProperty(property); + + destination.Merge(source); + destination.VersionProperties.Should().Have.Count.EqualTo(1); + } + + [Test] + public void MergePoids() + { + var destination = new EmptyHolder(); + var source = new EmptyHolder(); + source.AddAsPoid(property); + + destination.Merge(source); + destination.Poids.Should().Have.Count.EqualTo(1); + } + + [Test] + public void MergeAny() + { + var destination = new EmptyHolder(); + var source = new EmptyHolder(); + source.AddAsAny(property); + + destination.Merge(source); + destination.Any.Should().Have.Count.EqualTo(1); + } + + [Test] + public void MergeOneToManyRelations() + { + var destination = new EmptyHolder(); + var source = new EmptyHolder(); + source.AddAsOneToManyRelation(property); + + destination.Merge(source); + destination.OneToManyRelations.Should().Have.Count.EqualTo(1); + } + + [Test] + public void MergeManyToManyRelations() + { + var destination = new EmptyHolder(); + var source = new EmptyHolder(); + source.AddAsManyToManyRelation(property); + + destination.Merge(source); + destination.ManyToManyRelations.Should().Have.Count.EqualTo(1); + } + + [Test] + public void MergeManyToOneRelations() + { + var destination = new EmptyHolder(); + var source = new EmptyHolder(); + source.AddAsManyToOneRelation(property); + + destination.Merge(source); + destination.ManyToOneRelations.Should().Have.Count.EqualTo(1); + } + + [Test] + public void MergeOneToOneRelations() + { + var destination = new EmptyHolder(); + var source = new EmptyHolder(); + source.AddAsOneToOneRelation(property); + + destination.Merge(source); + destination.OneToOneRelations.Should().Have.Count.EqualTo(1); + } + + [Test] + public void MergeTablePerConcreteClassEntities() + { + var destination = new EmptyHolder(); + var source = new EmptyHolder(); + source.AddAsTablePerConcreteClassEntity(typeof (MyClass)); + + destination.Merge(source); + destination.TablePerConcreteClassEntities.Should().Have.Count.EqualTo(1); + } + + [Test] + public void MergeTablePerClassHierarchyEntities() + { + var destination = new EmptyHolder(); + var source = new EmptyHolder(); + source.AddAsTablePerClassHierarchyEntity(typeof (MyClass)); + + destination.Merge(source); + destination.TablePerClassHierarchyEntities.Should().Have.Count.EqualTo(1); + } + + [Test] + public void MergeTablePerClassEntities() + { + var destination = new EmptyHolder(); + var source = new EmptyHolder(); + source.AddAsTablePerClassEntity(typeof (MyClass)); + + destination.Merge(source); + destination.TablePerClassEntities.Should().Have.Count.EqualTo(1); + } + + [Test] + public void MergeComponents() + { + var destination = new EmptyHolder(); + var source = new EmptyHolder(); + source.AddAsComponent(typeof (MyClass)); + + destination.Merge(source); + destination.Components.Should().Have.Count.EqualTo(1); + } + + [Test] + public void MergeRootEntities() + { + var destination = new EmptyHolder(); + var source = new EmptyHolder(); + source.AddAsRootEntity(typeof (MyClass)); + + destination.Merge(source); + destination.RootEntities.Should().Have.Count.EqualTo(1); + } + + #region Nested type: EmptyHolder + + public class EmptyHolder : IModelExplicitDeclarationsHolder + { + private readonly HashSet<MemberInfo> any = new HashSet<MemberInfo>(); + private readonly HashSet<MemberInfo> arrays = new HashSet<MemberInfo>(); + private readonly HashSet<MemberInfo> bags = new HashSet<MemberInfo>(); + private readonly HashSet<System.Type> components = new HashSet<System.Type>(); + private readonly HashSet<MemberInfo> dictionaries = new HashSet<MemberInfo>(); + private readonly HashSet<MemberInfo> idBags = new HashSet<MemberInfo>(); + private readonly HashSet<MemberInfo> lists = new HashSet<MemberInfo>(); + private readonly HashSet<MemberInfo> manyToManyRelations = new HashSet<MemberInfo>(); + private readonly HashSet<MemberInfo> manyToOneRelations = new HashSet<MemberInfo>(); + private readonly HashSet<MemberInfo> naturalIds = new HashSet<MemberInfo>(); + private readonly HashSet<MemberInfo> oneToManyRelations = new HashSet<MemberInfo>(); + private readonly HashSet<MemberInfo> oneToOneRelations = new HashSet<MemberInfo>(); + private readonly HashSet<MemberInfo> poids = new HashSet<MemberInfo>(); + private readonly HashSet<MemberInfo> properties = new HashSet<MemberInfo>(); + private readonly HashSet<System.Type> rootEntities = new HashSet<System.Type>(); + private readonly HashSet<MemberInfo> sets = new HashSet<MemberInfo>(); + private readonly HashSet<SplitDefinition> splitDefinitions = new HashSet<SplitDefinition>(); + private readonly HashSet<System.Type> tablePerClassEntities = new HashSet<System.Type>(); + private readonly HashSet<System.Type> tablePerClassHierarchyEntities = new HashSet<System.Type>(); + private readonly HashSet<System.Type> tablePerConcreteClassEntities = new HashSet<System.Type>(); + private readonly HashSet<MemberInfo> versionProperties = new HashSet<MemberInfo>(); + + #region IModelExplicitDeclarationsHolder Members + + public IEnumerable<System.Type> RootEntities + { + get { return rootEntities; } + } + + public IEnumerable<System.Type> Components + { + get { return components; } + } + + public IEnumerable<System.Type> TablePerClassEntities + { + get { return tablePerClassEntities; } + } + + public IEnumerable<System.Type> TablePerClassHierarchyEntities + { + get { return tablePerClassHierarchyEntities; } + } + + public IEnumerable<System.Type> TablePerConcreteClassEntities + { + get { return tablePerConcreteClassEntities; } + } + + public IEnumerable<MemberInfo> OneToOneRelations + { + get { return oneToOneRelations; } + } + + public IEnumerable<MemberInfo> ManyToOneRelations + { + get { return manyToOneRelations; } + } + + public IEnumerable<MemberInfo> ManyToManyRelations + { + get { return manyToManyRelations; } + } + + public IEnumerable<MemberInfo> OneToManyRelations + { + get { return oneToManyRelations; } + } + + public IEnumerable<MemberInfo> Any + { + get { return any; } + } + + public IEnumerable<MemberInfo> Poids + { + get { return poids; } + } + + public IEnumerable<MemberInfo> VersionProperties + { + get { return versionProperties; } + } + + public IEnumerable<MemberInfo> NaturalIds + { + get { return naturalIds; } + } + + public IEnumerable<MemberInfo> Sets + { + get { return sets; } + } + + public IEnumerable<MemberInfo> Bags + { + get { return bags; } + } + + public IEnumerable<MemberInfo> IdBags + { + get { return idBags; } + } + + public IEnumerable<MemberInfo> Lists + { + get { return lists; } + } + + public IEnumerable<MemberInfo> Arrays + { + get { return arrays; } + } + + public IEnumerable<MemberInfo> Dictionaries + { + get { return dictionaries; } + } + + public IEnumerable<MemberInfo> Properties + { + get { return properties; } + } + + public IEnumerable<SplitDefinition> SplitDefinitions + { + get { return splitDefinitions; } + } + + public IEnumerable<string> GetSplitGroupsFor(System.Type type) + { + return Enumerable.Empty<string>(); + } + + public string GetSplitGroupFor(MemberInfo member) + { + return null; + } + + public void AddAsRootEntity(System.Type type) + { + rootEntities.Add(type); + } + + public void AddAsComponent(System.Type type) + { + components.Add(type); + } + + public void AddAsTablePerClassEntity(System.Type type) + { + tablePerClassEntities.Add(type); + } + + public void AddAsTablePerClassHierarchyEntity(System.Type type) + { + tablePerClassHierarchyEntities.Add(type); + } + + public void AddAsTablePerConcreteClassEntity(System.Type type) + { + tablePerConcreteClassEntities.Add(type); + } + + public void AddAsOneToOneRelation(MemberInfo member) + { + oneToOneRelations.Add(member); + } + + public void AddAsManyToOneRelation(MemberInfo member) + { + manyToOneRelations.Add(member); + } + + public void AddAsManyToManyRelation(MemberInfo member) + { + manyToManyRelations.Add(member); + } + + public void AddAsOneToManyRelation(MemberInfo member) + { + oneToManyRelations.Add(member); + } + + public void AddAsAny(MemberInfo member) + { + any.Add(member); + } + + public void AddAsPoid(MemberInfo member) + { + poids.Add(member); + } + + public void AddAsVersionProperty(MemberInfo member) + { + versionProperties.Add(member); + } + + public void AddAsNaturalId(MemberInfo member) + { + naturalIds.Add(member); + } + + public void AddAsSet(MemberInfo member) + { + sets.Add(member); + } + + public void AddAsBag(MemberInfo member) + { + bags.Add(member); + } + + public void AddAsIdBag(MemberInfo member) + { + idBags.Add(member); + } + + public void AddAsList(MemberInfo member) + { + lists.Add(member); + } + + public void AddAsArray(MemberInfo member) + { + arrays.Add(member); + } + + public void AddAsMap(MemberInfo member) + { + dictionaries.Add(member); + } + + public void AddAsProperty(MemberInfo member) + { + properties.Add(member); + } + + public void AddAsPropertySplit(System.Type propertyContainer, string splitGroupId, MemberInfo member) + { + splitDefinitions.Add(new SplitDefinition(propertyContainer, splitGroupId, member)); + } + + #endregion + } + + #endregion + + #region Nested type: MyClass + + private class MyClass + { + public string Bar { get; set; } + } + + #endregion + } +} \ No newline at end of file Modified: trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2011-04-06 13:41:56 UTC (rev 5620) +++ trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2011-04-06 15:10:54 UTC (rev 5621) @@ -535,6 +535,7 @@ <Compile Include="MappingByCode\MappersTests\IdBagMapperTest.cs" /> <Compile Include="MappingByCode\MappersTests\JoinMapperTests.cs" /> <Compile Include="MappingByCode\MappersTests\SubclassMapperWithJoinPropertiesTest.cs" /> + <Compile Include="MappingByCode\ModelExplicitDeclarationsHolderMergeTest.cs" /> <Compile Include="MappingByCode\NatureDemo\Naturalness\Address.cs" /> <Compile Include="MappingByCode\NatureDemo\Naturalness\Animal.cs" /> <Compile Include="MappingByCode\NatureDemo\Naturalness\Classification.cs" /> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fab...@us...> - 2011-04-06 13:42:02
|
Revision: 5620 http://nhibernate.svn.sourceforge.net/nhibernate/?rev=5620&view=rev Author: fabiomaulo Date: 2011-04-06 13:41:56 +0000 (Wed, 06 Apr 2011) Log Message: ----------- Merge with null Modified Paths: -------------- trunk/nhibernate/src/NHibernate/Mapping/ByCode/Impl/CustomizersHolder.cs trunk/nhibernate/src/NHibernate.Test/MappingByCode/CustomizerHolderMergeTest.cs Modified: trunk/nhibernate/src/NHibernate/Mapping/ByCode/Impl/CustomizersHolder.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Mapping/ByCode/Impl/CustomizersHolder.cs 2011-04-06 12:43:42 UTC (rev 5619) +++ trunk/nhibernate/src/NHibernate/Mapping/ByCode/Impl/CustomizersHolder.cs 2011-04-06 13:41:56 UTC (rev 5620) @@ -295,6 +295,10 @@ public void Merge(CustomizersHolder source) { + if (source == null) + { + return; + } MergeDictionary(rootClassCustomizers, source.rootClassCustomizers); MergeDictionary(subclassCustomizers, source.subclassCustomizers); MergeDictionary(joinedClassCustomizers, source.joinedClassCustomizers); Modified: trunk/nhibernate/src/NHibernate.Test/MappingByCode/CustomizerHolderMergeTest.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Test/MappingByCode/CustomizerHolderMergeTest.cs 2011-04-06 12:43:42 UTC (rev 5619) +++ trunk/nhibernate/src/NHibernate.Test/MappingByCode/CustomizerHolderMergeTest.cs 2011-04-06 13:41:56 UTC (rev 5620) @@ -15,6 +15,13 @@ private PropertyPath propertyPath = new PropertyPath(null, typeof(MyClass).GetProperty("Bar")); [Test] + public void WhenMergeWithNullThenNotThrow() + { + var emptyHolder = new CustomizersHolder(); + emptyHolder.Executing(x=> x.Merge(null)).NotThrows(); + } + + [Test] public void MergeShouldMergeAnyMapper() { var emptyHolder = new CustomizersHolder(); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fab...@us...> - 2011-04-06 12:43:48
|
Revision: 5619 http://nhibernate.svn.sourceforge.net/nhibernate/?rev=5619&view=rev Author: fabiomaulo Date: 2011-04-06 12:43:42 +0000 (Wed, 06 Apr 2011) Log Message: ----------- CustomizerHolder Merge Modified Paths: -------------- trunk/nhibernate/src/NHibernate/Mapping/ByCode/Impl/CustomizersHolder.cs trunk/nhibernate/src/NHibernate/NHibernate.csproj trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj Added Paths: ----------- trunk/nhibernate/src/NHibernate.Test/MappingByCode/CustomizerHolderMergeTest.cs Modified: trunk/nhibernate/src/NHibernate/Mapping/ByCode/Impl/CustomizersHolder.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Mapping/ByCode/Impl/CustomizersHolder.cs 2011-04-05 23:07:24 UTC (rev 5618) +++ trunk/nhibernate/src/NHibernate/Mapping/ByCode/Impl/CustomizersHolder.cs 2011-04-06 12:43:42 UTC (rev 5619) @@ -293,8 +293,48 @@ InvokeCustomizers(mapKeyElementCustomizers, member, mapper); } + public void Merge(CustomizersHolder source) + { + MergeDictionary(rootClassCustomizers, source.rootClassCustomizers); + MergeDictionary(subclassCustomizers, source.subclassCustomizers); + MergeDictionary(joinedClassCustomizers, source.joinedClassCustomizers); + MergeDictionary(unionClassCustomizers, source.unionClassCustomizers); + MergeDictionary(componentClassCustomizers, source.componentClassCustomizers); + MergeDictionary(joinCustomizers, source.joinCustomizers); + MergeDictionary(propertyCustomizers, source.propertyCustomizers); + MergeDictionary(manyToOneCustomizers, source.manyToOneCustomizers); + MergeDictionary(oneToOneCustomizers, source.oneToOneCustomizers); + MergeDictionary(anyCustomizers, source.anyCustomizers); + MergeDictionary(setCustomizers, source.setCustomizers); + MergeDictionary(bagCustomizers, source.bagCustomizers); + MergeDictionary(listCustomizers, source.listCustomizers); + MergeDictionary(mapCustomizers, source.mapCustomizers); + MergeDictionary(idBagCustomizers, source.idBagCustomizers); + MergeDictionary(collectionCustomizers, source.collectionCustomizers); + MergeDictionary(componentPropertyCustomizers, source.componentPropertyCustomizers); + MergeDictionary(collectionRelationManyToManyCustomizers, source.collectionRelationManyToManyCustomizers); + MergeDictionary(collectionRelationElementCustomizers, source.collectionRelationElementCustomizers); + MergeDictionary(collectionRelationOneToManyCustomizers, source.collectionRelationOneToManyCustomizers); + MergeDictionary(mapKeyManyToManyCustomizers, source.mapKeyManyToManyCustomizers); + MergeDictionary(mapKeyElementCustomizers, source.mapKeyElementCustomizers); + } + #endregion + private void MergeDictionary<TSubject, TCustomizable>(Dictionary<TSubject, List<Action<TCustomizable>>> destination,Dictionary<TSubject, List<Action<TCustomizable>>> source) + { + foreach (var element in source) + { + List<Action<TCustomizable>> actions; + if (!destination.TryGetValue(element.Key, out actions)) + { + actions = new List<Action<TCustomizable>>(); + destination[element.Key] = actions; + } + actions.AddRange(element.Value); + } + } + private void AddCustomizer<TSubject, TCustomizable>(IDictionary<TSubject, List<Action<TCustomizable>>> customizers, TSubject member, Action<TCustomizable> customizer) { Modified: trunk/nhibernate/src/NHibernate/NHibernate.csproj =================================================================== --- trunk/nhibernate/src/NHibernate/NHibernate.csproj 2011-04-05 23:07:24 UTC (rev 5618) +++ trunk/nhibernate/src/NHibernate/NHibernate.csproj 2011-04-06 12:43:42 UTC (rev 5619) @@ -1774,6 +1774,7 @@ <Install>true</Install> </BootstrapperPackage> </ItemGroup> + <ItemGroup /> <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" /> <!-- To modify your build process, add your task inside one of the targets below and uncomment it. Other similar extension points exist, see Microsoft.Common.targets. Added: trunk/nhibernate/src/NHibernate.Test/MappingByCode/CustomizerHolderMergeTest.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Test/MappingByCode/CustomizerHolderMergeTest.cs (rev 0) +++ trunk/nhibernate/src/NHibernate.Test/MappingByCode/CustomizerHolderMergeTest.cs 2011-04-06 12:43:42 UTC (rev 5619) @@ -0,0 +1,325 @@ +using NHibernate.Mapping.ByCode; +using NHibernate.Mapping.ByCode.Impl; +using NUnit.Framework; +using SharpTestsEx; + +namespace NHibernate.Test.MappingByCode +{ + public class CustomizerHolderMergeTest + { + private class MyClass + { + public string Bar { get; set; } + } + + private PropertyPath propertyPath = new PropertyPath(null, typeof(MyClass).GetProperty("Bar")); + + [Test] + public void MergeShouldMergeAnyMapper() + { + var emptyHolder = new CustomizersHolder(); + var holder = new CustomizersHolder(); + var called = false; + + holder.AddCustomizer(propertyPath, (IAnyMapper x) => called = true); + emptyHolder.Merge(holder); + emptyHolder.InvokeCustomizers(propertyPath, (IAnyMapper)null); + + called.Should().Be.True(); + } + + [Test] + public void MergeShouldMergeBagPropertiesMapper() + { + var emptyHolder = new CustomizersHolder(); + var holder = new CustomizersHolder(); + var called = false; + + holder.AddCustomizer(propertyPath, (IBagPropertiesMapper x) => called = true); + emptyHolder.Merge(holder); + emptyHolder.InvokeCustomizers(propertyPath, (IBagPropertiesMapper)null); + + called.Should().Be.True(); + } + + [Test] + public void MergeShouldMergeIdBagPropertiesMapper() + { + var emptyHolder = new CustomizersHolder(); + var holder = new CustomizersHolder(); + var called = false; + + holder.AddCustomizer(propertyPath, (IIdBagPropertiesMapper x) => called = true); + emptyHolder.Merge(holder); + emptyHolder.InvokeCustomizers(propertyPath, (IIdBagPropertiesMapper)null); + + called.Should().Be.True(); + } + + [Test] + public void MergeShouldMergeCollectionPropertiesMapper() + { + var emptyHolder = new CustomizersHolder(); + var holder = new CustomizersHolder(); + var called = false; + + holder.AddCustomizer(propertyPath, (ICollectionPropertiesMapper x) => called = true); + emptyHolder.Merge(holder); + emptyHolder.InvokeCustomizers(propertyPath, (IBagPropertiesMapper)null); + + called.Should().Be.True(); + } + + [Test] + public void MergeShouldMergeElementMapper() + { + var emptyHolder = new CustomizersHolder(); + var holder = new CustomizersHolder(); + var called = false; + + holder.AddCustomizer(propertyPath, (IElementMapper x) => called = true); + emptyHolder.Merge(holder); + emptyHolder.InvokeCustomizers(propertyPath, (IElementMapper)null); + + called.Should().Be.True(); + } + + [Test] + public void MergeShouldMergeManyToManyMapper() + { + var emptyHolder = new CustomizersHolder(); + var holder = new CustomizersHolder(); + var called = false; + + holder.AddCustomizer(propertyPath, (IManyToManyMapper x) => called = true); + emptyHolder.Merge(holder); + emptyHolder.InvokeCustomizers(propertyPath, (IManyToManyMapper)null); + + called.Should().Be.True(); + } + + [Test] + public void MergeShouldMergeOneToManyMapper() + { + var emptyHolder = new CustomizersHolder(); + var holder = new CustomizersHolder(); + var called = false; + + holder.AddCustomizer(propertyPath, (IOneToManyMapper x) => called = true); + emptyHolder.Merge(holder); + emptyHolder.InvokeCustomizers(propertyPath, (IOneToManyMapper)null); + + called.Should().Be.True(); + } + + [Test] + public void MergeShouldMergeComponentAttributesMapperOnProperty() + { + var emptyHolder = new CustomizersHolder(); + var holder = new CustomizersHolder(); + var called = false; + + holder.AddCustomizer(propertyPath, (IComponentAttributesMapper x) => called = true); + emptyHolder.Merge(holder); + emptyHolder.InvokeCustomizers(propertyPath, (IComponentAttributesMapper)null); + + called.Should().Be.True(); + } + + [Test] + public void MergeShouldMergeListPropertiesMapper() + { + var emptyHolder = new CustomizersHolder(); + var holder = new CustomizersHolder(); + var called = false; + + holder.AddCustomizer(propertyPath, (IListPropertiesMapper x) => called = true); + emptyHolder.Merge(holder); + emptyHolder.InvokeCustomizers(propertyPath, (IListPropertiesMapper)null); + + called.Should().Be.True(); + } + + [Test] + public void MergeShouldMergeManyToOneMapper() + { + var emptyHolder = new CustomizersHolder(); + var holder = new CustomizersHolder(); + var called = false; + + holder.AddCustomizer(propertyPath, (IManyToOneMapper x) => called = true); + emptyHolder.Merge(holder); + emptyHolder.InvokeCustomizers(propertyPath, (IManyToOneMapper)null); + + called.Should().Be.True(); + } + + [Test] + public void MergeShouldMergeMapPropertiesMapper() + { + var emptyHolder = new CustomizersHolder(); + var holder = new CustomizersHolder(); + var called = false; + + holder.AddCustomizer(propertyPath, (IMapPropertiesMapper x) => called = true); + emptyHolder.Merge(holder); + emptyHolder.InvokeCustomizers(propertyPath, (IMapPropertiesMapper)null); + + called.Should().Be.True(); + } + + [Test] + public void MergeShouldMergeMapKeyMapper() + { + var emptyHolder = new CustomizersHolder(); + var holder = new CustomizersHolder(); + var called = false; + + holder.AddCustomizer(propertyPath, (IMapKeyMapper x) => called = true); + emptyHolder.Merge(holder); + emptyHolder.InvokeCustomizers(propertyPath, (IMapKeyMapper)null); + + called.Should().Be.True(); + } + + [Test] + public void MergeShouldMergeMapKeyManyToManyMapper() + { + var emptyHolder = new CustomizersHolder(); + var holder = new CustomizersHolder(); + var called = false; + + holder.AddCustomizer(propertyPath, (IMapKeyManyToManyMapper x) => called = true); + emptyHolder.Merge(holder); + emptyHolder.InvokeCustomizers(propertyPath, (IMapKeyManyToManyMapper)null); + + called.Should().Be.True(); + } + + [Test] + public void MergeShouldMergeOneToOneMapper() + { + var emptyHolder = new CustomizersHolder(); + var holder = new CustomizersHolder(); + var called = false; + + holder.AddCustomizer(propertyPath, (IOneToOneMapper x) => called = true); + emptyHolder.Merge(holder); + emptyHolder.InvokeCustomizers(propertyPath, (IOneToOneMapper)null); + + called.Should().Be.True(); + } + + [Test] + public void MergeShouldMergePropertyMapper() + { + var emptyHolder = new CustomizersHolder(); + var holder = new CustomizersHolder(); + var called = false; + + holder.AddCustomizer(propertyPath, (IPropertyMapper x) => called = true); + emptyHolder.Merge(holder); + emptyHolder.InvokeCustomizers(propertyPath, (IPropertyMapper)null); + + called.Should().Be.True(); + } + + [Test] + public void MergeShouldMergeSetPropertiesMapper() + { + var emptyHolder = new CustomizersHolder(); + var holder = new CustomizersHolder(); + var called = false; + + holder.AddCustomizer(propertyPath, (ISetPropertiesMapper x) => called = true); + emptyHolder.Merge(holder); + emptyHolder.InvokeCustomizers(propertyPath, (ISetPropertiesMapper)null); + + called.Should().Be.True(); + } + + [Test] + public void MergeShouldMergeJoinedSubclassAttributesMapper() + { + var emptyHolder = new CustomizersHolder(); + var holder = new CustomizersHolder(); + var called = false; + + holder.AddCustomizer(typeof(MyClass), (IJoinedSubclassAttributesMapper x) => called = true); + emptyHolder.Merge(holder); + emptyHolder.InvokeCustomizers(typeof(MyClass), (IJoinedSubclassAttributesMapper)null); + + called.Should().Be.True(); + } + + [Test] + public void MergeShouldMergeClassMapper() + { + var emptyHolder = new CustomizersHolder(); + var holder = new CustomizersHolder(); + var called = false; + + holder.AddCustomizer(typeof(MyClass), (IClassMapper x) => called = true); + emptyHolder.Merge(holder); + emptyHolder.InvokeCustomizers(typeof(MyClass), (IClassMapper)null); + + called.Should().Be.True(); + } + + [Test] + public void MergeShouldMergeSubclassMapper() + { + var emptyHolder = new CustomizersHolder(); + var holder = new CustomizersHolder(); + var called = false; + + holder.AddCustomizer(typeof(MyClass), (ISubclassMapper x) => called = true); + emptyHolder.Merge(holder); + emptyHolder.InvokeCustomizers(typeof(MyClass), (ISubclassMapper)null); + + called.Should().Be.True(); + } + + [Test] + public void MergeShouldMergeJoinAttributesMapper() + { + var emptyHolder = new CustomizersHolder(); + var holder = new CustomizersHolder(); + var called = false; + + holder.AddCustomizer(typeof(MyClass), (IJoinAttributesMapper x) => called = true); + emptyHolder.Merge(holder); + emptyHolder.InvokeCustomizers(typeof(MyClass), (IJoinAttributesMapper)null); + + called.Should().Be.True(); + } + + [Test] + public void MergeShouldMergeUnionSubclassAttributesMapper() + { + var emptyHolder = new CustomizersHolder(); + var holder = new CustomizersHolder(); + var called = false; + + holder.AddCustomizer(typeof(MyClass), (IUnionSubclassAttributesMapper x) => called = true); + emptyHolder.Merge(holder); + emptyHolder.InvokeCustomizers(typeof(MyClass), (IUnionSubclassAttributesMapper)null); + + called.Should().Be.True(); + } + + [Test] + public void MergeShouldMergeComponentAttributesMapper() + { + var emptyHolder = new CustomizersHolder(); + var holder = new CustomizersHolder(); + var called = false; + + holder.AddCustomizer(typeof(MyClass), (IComponentAttributesMapper x) => called = true); + emptyHolder.Merge(holder); + emptyHolder.InvokeCustomizers(typeof(MyClass), (IComponentAttributesMapper)null); + + called.Should().Be.True(); + } + } +} \ No newline at end of file Modified: trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2011-04-05 23:07:24 UTC (rev 5618) +++ trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2011-04-06 12:43:42 UTC (rev 5619) @@ -508,6 +508,7 @@ <Compile Include="Linq\ByMethod\SumTests.cs" /> <Compile Include="Logging\Log4NetLoggerTest.cs" /> <Compile Include="Logging\LoggerProviderTest.cs" /> + <Compile Include="MappingByCode\CustomizerHolderMergeTest.cs" /> <Compile Include="MappingByCode\ExplicitlyDeclaredModelTests\SplitPropertiesRegistrationTests.cs" /> <Compile Include="MappingByCode\ExpliticMappingTests\BasicMappingOfSimpleClass.cs" /> <Compile Include="MappingByCode\ExpliticMappingTests\ColumnsNamingConvetions.cs" /> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fab...@us...> - 2011-04-05 23:07:33
|
Revision: 5618 http://nhibernate.svn.sourceforge.net/nhibernate/?rev=5618&view=rev Author: fabiomaulo Date: 2011-04-05 23:07:24 +0000 (Tue, 05 Apr 2011) Log Message: ----------- IdBag on the road Modified Paths: -------------- trunk/nhibernate/src/NHibernate/Mapping/ByCode/IPropertyContainerMapper.cs trunk/nhibernate/src/NHibernate/Mapping/ByCode/Impl/AbstractPropertyContainerMapper.cs trunk/nhibernate/src/NHibernate/Mapping/ByCode/Impl/CustomizersHolder.cs trunk/nhibernate/src/NHibernate/Mapping/ByCode/Impl/CustomizersImpl/JoinCustomizer.cs trunk/nhibernate/src/NHibernate/Mapping/ByCode/Impl/CustomizersImpl/PropertyContainerCustomizer.cs trunk/nhibernate/src/NHibernate/Mapping/ByCode/Impl/ICustomizersHolder.cs trunk/nhibernate/src/NHibernate/Mapping/ByCode/Impl/MapperEventsHandlersDefinitions.cs trunk/nhibernate/src/NHibernate/Mapping/ByCode/ModelMapper.cs trunk/nhibernate/src/NHibernate/NHibernate.csproj trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj Added Paths: ----------- trunk/nhibernate/src/NHibernate/Mapping/ByCode/Impl/CustomizersImpl/IdBagPropertiesCustomizer.cs trunk/nhibernate/src/NHibernate.Test/MappingByCode/ExpliticMappingTests/IdBagMappingTest.cs Modified: trunk/nhibernate/src/NHibernate/Mapping/ByCode/IPropertyContainerMapper.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Mapping/ByCode/IPropertyContainerMapper.cs 2011-04-05 22:03:58 UTC (rev 5617) +++ trunk/nhibernate/src/NHibernate/Mapping/ByCode/IPropertyContainerMapper.cs 2011-04-05 23:07:24 UTC (rev 5618) @@ -19,6 +19,9 @@ void Map(MemberInfo property, Action<IMapPropertiesMapper> collectionMapping, Action<IMapKeyRelation> keyMapping, Action<ICollectionElementRelation> mapping); + + void IdBag(MemberInfo property, Action<IIdBagPropertiesMapper> collectionMapping, + Action<ICollectionElementRelation> mapping); } public interface IPropertyContainerMapper : ICollectionPropertiesContainerMapper, IPlainPropertyContainerMapper {} @@ -45,6 +48,10 @@ void Map<TKey, TElement>(Expression<Func<TEntity, IDictionary<TKey, TElement>>> property, Action<IMapPropertiesMapper<TEntity, TKey, TElement>> collectionMapping, Action<ICollectionElementRelation<TElement>> mapping); + + void IdBag<TElement>(Expression<Func<TEntity, IEnumerable<TElement>>> property, + Action<IIdBagPropertiesMapper<TEntity, TElement>> collectionMapping, + Action<ICollectionElementRelation<TElement>> mapping); } public interface IPropertyContainerMapper<TEntity> : ICollectionPropertiesContainerMapper<TEntity>, IPlainPropertyContainerMapper<TEntity> where TEntity : class {} Modified: trunk/nhibernate/src/NHibernate/Mapping/ByCode/Impl/AbstractPropertyContainerMapper.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Mapping/ByCode/Impl/AbstractPropertyContainerMapper.cs 2011-04-05 22:03:58 UTC (rev 5617) +++ trunk/nhibernate/src/NHibernate/Mapping/ByCode/Impl/AbstractPropertyContainerMapper.cs 2011-04-05 23:07:24 UTC (rev 5618) @@ -61,6 +61,16 @@ AddProperty(hbm); } + public void IdBag(MemberInfo property, Action<IIdBagPropertiesMapper> collectionMapping, Action<ICollectionElementRelation> mapping) + { + var hbm = new HbmIdbag { name = property.Name }; + System.Type propertyType = property.GetPropertyOrFieldType(); + System.Type collectionElementType = propertyType.DetermineCollectionElementType(); + collectionMapping(new IdBagMapper(container, collectionElementType, hbm)); + mapping(new CollectionElementRelation(collectionElementType, MapDoc, rel => hbm.Item = rel)); + AddProperty(hbm); + } + #endregion } } \ No newline at end of file Modified: trunk/nhibernate/src/NHibernate/Mapping/ByCode/Impl/CustomizersHolder.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Mapping/ByCode/Impl/CustomizersHolder.cs 2011-04-05 22:03:58 UTC (rev 5617) +++ trunk/nhibernate/src/NHibernate/Mapping/ByCode/Impl/CustomizersHolder.cs 2011-04-05 23:07:24 UTC (rev 5618) @@ -11,6 +11,9 @@ private readonly Dictionary<PropertyPath, List<Action<IBagPropertiesMapper>>> bagCustomizers = new Dictionary<PropertyPath, List<Action<IBagPropertiesMapper>>>(); + private readonly Dictionary<PropertyPath, List<Action<IIdBagPropertiesMapper>>> idBagCustomizers = + new Dictionary<PropertyPath, List<Action<IIdBagPropertiesMapper>>>(); + private readonly Dictionary<PropertyPath, List<Action<ICollectionPropertiesMapper>>> collectionCustomizers = new Dictionary<PropertyPath, List<Action<ICollectionPropertiesMapper>>>(); @@ -140,6 +143,11 @@ AddCustomizer(mapCustomizers, member, propertyCustomizer); } + public void AddCustomizer(PropertyPath member, Action<IIdBagPropertiesMapper> propertyCustomizer) + { + AddCustomizer(idBagCustomizers, member, propertyCustomizer); + } + public void AddCustomizer(PropertyPath member, Action<ICollectionPropertiesMapper> propertyCustomizer) { AddCustomizer(collectionCustomizers, member, propertyCustomizer); @@ -249,6 +257,12 @@ InvokeCustomizers(mapCustomizers, member, mapper); } + public void InvokeCustomizers(PropertyPath member, IIdBagPropertiesMapper mapper) + { + InvokeCustomizers(collectionCustomizers, member, mapper); + InvokeCustomizers(idBagCustomizers, member, mapper); + } + public void InvokeCustomizers(PropertyPath member, IComponentAttributesMapper mapper) { InvokeCustomizers(componentPropertyCustomizers, member, mapper); Added: trunk/nhibernate/src/NHibernate/Mapping/ByCode/Impl/CustomizersImpl/IdBagPropertiesCustomizer.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Mapping/ByCode/Impl/CustomizersImpl/IdBagPropertiesCustomizer.cs (rev 0) +++ trunk/nhibernate/src/NHibernate/Mapping/ByCode/Impl/CustomizersImpl/IdBagPropertiesCustomizer.cs 2011-04-05 23:07:24 UTC (rev 5618) @@ -0,0 +1,22 @@ +using System; + +namespace NHibernate.Mapping.ByCode.Impl.CustomizersImpl +{ + public class IdBagPropertiesCustomizer<TEntity, TElement> : CollectionPropertiesCustomizer<TEntity, TElement>, IIdBagPropertiesMapper<TEntity, TElement> where TEntity : class + { + public IdBagPropertiesCustomizer(IModelExplicitDeclarationsHolder explicitDeclarationsHolder, PropertyPath propertyPath, ICustomizersHolder customizersHolder) + : base(explicitDeclarationsHolder, propertyPath, customizersHolder) + { + if (explicitDeclarationsHolder == null) + { + throw new ArgumentNullException("explicitDeclarationsHolder"); + } + explicitDeclarationsHolder.AddAsIdBag(propertyPath.LocalMember); + } + + public void Id(Action<ICollectionIdMapper> idMapping) + { + CustomizersHolder.AddCustomizer(PropertyPath, (IIdBagPropertiesMapper x) => x.Id(idMapping)); + } + } +} \ No newline at end of file Modified: trunk/nhibernate/src/NHibernate/Mapping/ByCode/Impl/CustomizersImpl/JoinCustomizer.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Mapping/ByCode/Impl/CustomizersImpl/JoinCustomizer.cs 2011-04-05 22:03:58 UTC (rev 5617) +++ trunk/nhibernate/src/NHibernate/Mapping/ByCode/Impl/CustomizersImpl/JoinCustomizer.cs 2011-04-05 23:07:24 UTC (rev 5618) @@ -164,5 +164,12 @@ ExplicitDeclarationsHolder.AddAsPropertySplit(typeof (TEntity), splitGroupId, member); base.Any(property, idTypeOfMetaType, mapping); } + + public override void IdBag<TElement>(Expression<Func<TEntity, IEnumerable<TElement>>> property, Action<IIdBagPropertiesMapper<TEntity, TElement>> collectionMapping, Action<ICollectionElementRelation<TElement>> mapping) + { + MemberInfo member = TypeExtensions.DecodeMemberAccessExpression(property); + ExplicitDeclarationsHolder.AddAsPropertySplit(typeof(TEntity), splitGroupId, member); + base.IdBag(property, collectionMapping, mapping); + } } } \ No newline at end of file Modified: trunk/nhibernate/src/NHibernate/Mapping/ByCode/Impl/CustomizersImpl/PropertyContainerCustomizer.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Mapping/ByCode/Impl/CustomizersImpl/PropertyContainerCustomizer.cs 2011-04-05 22:03:58 UTC (rev 5617) +++ trunk/nhibernate/src/NHibernate/Mapping/ByCode/Impl/CustomizersImpl/PropertyContainerCustomizer.cs 2011-04-05 23:07:24 UTC (rev 5618) @@ -160,5 +160,18 @@ { Map(property, collectionMapping, keyMapping => { }, mapping); } + + public virtual void IdBag<TElement>(Expression<Func<TEntity, IEnumerable<TElement>>> property, + Action<IIdBagPropertiesMapper<TEntity, TElement>> collectionMapping, + Action<ICollectionElementRelation<TElement>> mapping) + { + MemberInfo member = TypeExtensions.DecodeMemberAccessExpression(property); + collectionMapping(new IdBagPropertiesCustomizer<TEntity, TElement>(explicitDeclarationsHolder, new PropertyPath(null, member), CustomizersHolder)); + mapping(new CollectionElementRelationCustomizer<TElement>(explicitDeclarationsHolder, new PropertyPath(PropertyPath, member), CustomizersHolder)); + + MemberInfo memberOf = TypeExtensions.DecodeMemberAccessExpressionOf(property); + collectionMapping(new IdBagPropertiesCustomizer<TEntity, TElement>(explicitDeclarationsHolder, new PropertyPath(null, memberOf), CustomizersHolder)); + mapping(new CollectionElementRelationCustomizer<TElement>(explicitDeclarationsHolder, new PropertyPath(PropertyPath, memberOf), CustomizersHolder)); + } } } \ No newline at end of file Modified: trunk/nhibernate/src/NHibernate/Mapping/ByCode/Impl/ICustomizersHolder.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Mapping/ByCode/Impl/ICustomizersHolder.cs 2011-04-05 22:03:58 UTC (rev 5617) +++ trunk/nhibernate/src/NHibernate/Mapping/ByCode/Impl/ICustomizersHolder.cs 2011-04-05 23:07:24 UTC (rev 5618) @@ -20,6 +20,7 @@ void AddCustomizer(PropertyPath member, Action<IBagPropertiesMapper> propertyCustomizer); void AddCustomizer(PropertyPath member, Action<IListPropertiesMapper> propertyCustomizer); void AddCustomizer(PropertyPath member, Action<IMapPropertiesMapper> propertyCustomizer); + void AddCustomizer(PropertyPath member, Action<IIdBagPropertiesMapper> propertyCustomizer); void AddCustomizer(PropertyPath member, Action<ICollectionPropertiesMapper> propertyCustomizer); void AddCustomizer(PropertyPath member, Action<IComponentAttributesMapper> propertyCustomizer); @@ -39,6 +40,7 @@ void InvokeCustomizers(PropertyPath member, IBagPropertiesMapper mapper); void InvokeCustomizers(PropertyPath member, IListPropertiesMapper mapper); void InvokeCustomizers(PropertyPath member, IMapPropertiesMapper mapper); + void InvokeCustomizers(PropertyPath member, IIdBagPropertiesMapper mapper); void InvokeCustomizers(PropertyPath member, IComponentAttributesMapper mapper); #region Collection Element relations invokers Modified: trunk/nhibernate/src/NHibernate/Mapping/ByCode/Impl/MapperEventsHandlersDefinitions.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Mapping/ByCode/Impl/MapperEventsHandlersDefinitions.cs 2011-04-05 22:03:58 UTC (rev 5617) +++ trunk/nhibernate/src/NHibernate/Mapping/ByCode/Impl/MapperEventsHandlersDefinitions.cs 2011-04-05 23:07:24 UTC (rev 5618) @@ -22,6 +22,8 @@ public delegate void BagMappingHandler(IModelInspector modelInspector, PropertyPath member, IBagPropertiesMapper propertyCustomizer); + public delegate void IdBagMappingHandler(IModelInspector modelInspector, PropertyPath member, IIdBagPropertiesMapper propertyCustomizer); + public delegate void ListMappingHandler(IModelInspector modelInspector, PropertyPath member, IListPropertiesMapper propertyCustomizer); public delegate void MapMappingHandler(IModelInspector modelInspector, PropertyPath member, IMapPropertiesMapper propertyCustomizer); Modified: trunk/nhibernate/src/NHibernate/Mapping/ByCode/ModelMapper.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Mapping/ByCode/ModelMapper.cs 2011-04-05 22:03:58 UTC (rev 5617) +++ trunk/nhibernate/src/NHibernate/Mapping/ByCode/ModelMapper.cs 2011-04-05 23:07:24 UTC (rev 5618) @@ -82,6 +82,8 @@ public event BagMappingHandler BeforeMapBag; + public event IdBagMappingHandler BeforeMapIdBag; + public event ListMappingHandler BeforeMapList; public event MapMappingHandler BeforeMapMap; @@ -129,6 +131,8 @@ public event BagMappingHandler AfterMapBag; + public event IdBagMappingHandler AfterMapIdBag; + public event ListMappingHandler AfterMapList; public event MapMappingHandler AfterMapMap; @@ -242,6 +246,15 @@ } } + private void InvokeBeforeMapIdBag(PropertyPath member, IIdBagPropertiesMapper propertycustomizer) + { + IdBagMappingHandler handler = BeforeMapIdBag; + if (handler != null) + { + handler(ModelInspector, member, propertycustomizer); + } + } + private void InvokeBeforeMapList(PropertyPath member, IListPropertiesMapper propertycustomizer) { ListMappingHandler handler = BeforeMapList; @@ -404,6 +417,15 @@ } } + private void InvokeAfterMapIdBag(PropertyPath member, IIdBagPropertiesMapper propertycustomizer) + { + IdBagMappingHandler handler = AfterMapIdBag; + if (handler != null) + { + handler(ModelInspector, member, propertycustomizer); + } + } + private void InvokeAfterMapList(PropertyPath member, IListPropertiesMapper propertycustomizer) { ListMappingHandler handler = AfterMapList; @@ -769,6 +791,10 @@ { MapList(member, memberPath, propertyType, propertiesContainer, propertiesContainerType); } + else if (modelInspector.IsIdBag(property)) + { + MapIdBag(member, memberPath, propertyType, propertiesContainer, propertiesContainerType); + } else if (modelInspector.IsBag(property)) { MapBag(member, memberPath, propertyType, propertiesContainer, propertiesContainerType); @@ -888,6 +914,10 @@ { MapList(member, memberPath, propertyType, propertiesContainer, propertiesContainerType); } + else if (modelInspector.IsIdBag(property)) + { + MapIdBag(member, memberPath, propertyType, propertiesContainer, propertiesContainerType); + } else if (modelInspector.IsBag(property)) { MapBag(member, memberPath, propertyType, propertiesContainer, propertiesContainerType); @@ -1075,6 +1105,24 @@ }, cert.Map); } + private void MapIdBag(MemberInfo member, PropertyPath propertyPath, System.Type propertyType, ICollectionPropertiesContainerMapper propertiesContainer, + System.Type propertiesContainerType) + { + System.Type collectionElementType = GetCollectionElementTypeOrThrow(propertiesContainerType, member, propertyType); + ICollectionElementRelationMapper cert = DetermineCollectionElementRelationType(member, propertyPath, collectionElementType); + if(cert is OneToManyRelationMapper) + { + throw new NotSupportedException("id-bag does not suppot one-to-many relation"); + } + propertiesContainer.IdBag(member, collectionPropertiesMapper => + { + InvokeBeforeMapIdBag(propertyPath, collectionPropertiesMapper); + cert.MapCollectionProperties(collectionPropertiesMapper); + ForEachMemberPath(member, propertyPath, pp => customizerHolder.InvokeCustomizers(pp, collectionPropertiesMapper)); + InvokeAfterMapIdBag(propertyPath, collectionPropertiesMapper); + }, cert.Map); + } + private void MapOneToOne(MemberInfo member, PropertyPath propertyPath, IPlainPropertyContainerMapper propertiesContainer) { propertiesContainer.OneToOne(member, oneToOneMapper => Modified: trunk/nhibernate/src/NHibernate/NHibernate.csproj =================================================================== --- trunk/nhibernate/src/NHibernate/NHibernate.csproj 2011-04-05 22:03:58 UTC (rev 5617) +++ trunk/nhibernate/src/NHibernate/NHibernate.csproj 2011-04-05 23:07:24 UTC (rev 5618) @@ -348,6 +348,7 @@ <Compile Include="Mapping\ByCode\Impl\CustomizersImpl\CollectionPropertiesCustomizer.cs" /> <Compile Include="Mapping\ByCode\Impl\CustomizersImpl\ComponentCustomizer.cs" /> <Compile Include="Mapping\ByCode\Impl\CustomizersImpl\ComponentElementCustomizer.cs" /> + <Compile Include="Mapping\ByCode\Impl\CustomizersImpl\IdBagPropertiesCustomizer.cs" /> <Compile Include="Mapping\ByCode\Impl\CustomizersImpl\JoinCustomizer.cs" /> <Compile Include="Mapping\ByCode\Impl\CustomizersImpl\JoinedSubclassCustomizer.cs" /> <Compile Include="Mapping\ByCode\Impl\CustomizersImpl\JoinedSubclassKeyCustomizer.cs" /> Added: trunk/nhibernate/src/NHibernate.Test/MappingByCode/ExpliticMappingTests/IdBagMappingTest.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Test/MappingByCode/ExpliticMappingTests/IdBagMappingTest.cs (rev 0) +++ trunk/nhibernate/src/NHibernate.Test/MappingByCode/ExpliticMappingTests/IdBagMappingTest.cs 2011-04-05 23:07:24 UTC (rev 5618) @@ -0,0 +1,51 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using NHibernate.Cfg.MappingSchema; +using NHibernate.Mapping.ByCode; +using NUnit.Framework; +using SharpTestsEx; + +namespace NHibernate.Test.MappingByCode.ExpliticMappingTests +{ + public class IdBagMappingTest + { + private class Animal + { + public int Id { get; set; } + private ICollection<Animal> children; + public ICollection<Animal> Children + { + get { return children; } + } + } + + [Test] + public void WhenIdBagWithManyToManyThenMapIt() + { + var mapper = new ModelMapper(); + mapper.Class<Animal>(map => + { + map.Id(x => x.Id, idmap => { }); + map.IdBag(x => x.Children, bag => { }, rel=> rel.ManyToMany()); + }); + var hbmMapping = mapper.CompileMappingFor(new[]{ typeof(Animal)}); + var hbmClass = hbmMapping.RootClasses[0]; + var hbmIdbag = hbmClass.Properties.OfType<HbmIdbag>().SingleOrDefault(); + hbmIdbag.Should().Not.Be.Null(); + hbmIdbag.ElementRelationship.Should().Be.InstanceOf<HbmManyToMany>(); + } + + [Test] + public void WhenIdBagWithOneToManyThenThrow() + { + var mapper = new ModelMapper(); + mapper.Class<Animal>(map => + { + map.Id(x => x.Id, idmap => { }); + map.IdBag(x => x.Children, bag => { }, rel => rel.OneToMany()); + }); + mapper.Executing(x=> x.CompileMappingFor(new[] { typeof(Animal) })).Throws<NotSupportedException>(); + } + } +} \ No newline at end of file Modified: trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2011-04-05 22:03:58 UTC (rev 5617) +++ trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2011-04-05 23:07:24 UTC (rev 5618) @@ -519,6 +519,7 @@ <Compile Include="MappingByCode\ExplicitlyDeclaredModelTests\SubclassSequenceRegistrationTests.cs" /> <Compile Include="MappingByCode\ExplicitlyDeclaredModelTests\UnionSubclassMappingStrategyTests.cs" /> <Compile Include="MappingByCode\ExplicitlyDeclaredModelTests\UnionSubclassSequenceRegistrationTests.cs" /> + <Compile Include="MappingByCode\ExpliticMappingTests\IdBagMappingTest.cs" /> <Compile Include="MappingByCode\ExpliticMappingTests\MappingOfPrivateMembersOnRootEntity.cs" /> <Compile Include="MappingByCode\ExpliticMappingTests\NaturalIdTests.cs" /> <Compile Include="MappingByCode\ExpliticMappingTests\PoidTests.cs" /> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fab...@us...> - 2011-04-05 22:04:05
|
Revision: 5617 http://nhibernate.svn.sourceforge.net/nhibernate/?rev=5617&view=rev Author: fabiomaulo Date: 2011-04-05 22:03:58 +0000 (Tue, 05 Apr 2011) Log Message: ----------- IdBag mapper Modified Paths: -------------- trunk/nhibernate/src/NHibernate/Mapping/ByCode/Generators.cs trunk/nhibernate/src/NHibernate/Mapping/ByCode/IGeneratorDef.cs trunk/nhibernate/src/NHibernate/Mapping/ByCode/IIdBagPropertiesMapper.cs trunk/nhibernate/src/NHibernate/Mapping/ByCode/Impl/IdBagMapper.cs trunk/nhibernate/src/NHibernate/NHibernate.csproj trunk/nhibernate/src/NHibernate.Test/MappingByCode/MappersTests/IdBagMapperTest.cs trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj Added Paths: ----------- trunk/nhibernate/src/NHibernate/Mapping/ByCode/Impl/CollectionIdMapper.cs trunk/nhibernate/src/NHibernate.Test/MappingByCode/MappersTests/CollectionIdMapperTests.cs Modified: trunk/nhibernate/src/NHibernate/Mapping/ByCode/Generators.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Mapping/ByCode/Generators.cs 2011-04-05 20:53:30 UTC (rev 5616) +++ trunk/nhibernate/src/NHibernate/Mapping/ByCode/Generators.cs 2011-04-05 22:03:58 UTC (rev 5617) @@ -50,6 +50,16 @@ get { return null; } } + public System.Type DefaultReturnType + { + get { return null; } + } + + public bool SupportedAsCollectionElementId + { + get { return false; } + } + #endregion } @@ -78,6 +88,16 @@ get { return param; } } + public System.Type DefaultReturnType + { + get { return null; } + } + + public bool SupportedAsCollectionElementId + { + get { return false; } + } + #endregion } @@ -95,6 +115,16 @@ get { return null; } } + public System.Type DefaultReturnType + { + get { return typeof(int); } + } + + public bool SupportedAsCollectionElementId + { + get { return true; } + } + #endregion } @@ -112,6 +142,15 @@ get { return null; } } + public System.Type DefaultReturnType + { + get { return typeof(int); } + } + + public bool SupportedAsCollectionElementId + { + get { return true; } + } #endregion } @@ -129,6 +168,15 @@ get { return null; } } + public System.Type DefaultReturnType + { + get { return typeof(Guid); } + } + + public bool SupportedAsCollectionElementId + { + get { return true; } + } #endregion } @@ -146,6 +194,15 @@ get { return null; } } + public System.Type DefaultReturnType + { + get { return typeof(Guid); } + } + + public bool SupportedAsCollectionElementId + { + get { return true; } + } #endregion } @@ -163,6 +220,15 @@ get { return null; } } + public System.Type DefaultReturnType + { + get { return typeof(int); } + } + + public bool SupportedAsCollectionElementId + { + get { return true; } + } #endregion } @@ -180,6 +246,15 @@ get { return null; } } + public System.Type DefaultReturnType + { + get { return typeof(int); } + } + + public bool SupportedAsCollectionElementId + { + get { return true; } + } #endregion } } \ No newline at end of file Modified: trunk/nhibernate/src/NHibernate/Mapping/ByCode/IGeneratorDef.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Mapping/ByCode/IGeneratorDef.cs 2011-04-05 20:53:30 UTC (rev 5616) +++ trunk/nhibernate/src/NHibernate/Mapping/ByCode/IGeneratorDef.cs 2011-04-05 22:03:58 UTC (rev 5617) @@ -4,5 +4,7 @@ { string Class { get; } object Params { get; } + System.Type DefaultReturnType { get; } + bool SupportedAsCollectionElementId { get; } } } \ No newline at end of file Modified: trunk/nhibernate/src/NHibernate/Mapping/ByCode/IIdBagPropertiesMapper.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Mapping/ByCode/IIdBagPropertiesMapper.cs 2011-04-05 20:53:30 UTC (rev 5616) +++ trunk/nhibernate/src/NHibernate/Mapping/ByCode/IIdBagPropertiesMapper.cs 2011-04-05 22:03:58 UTC (rev 5617) @@ -3,11 +3,11 @@ { public interface IIdBagPropertiesMapper : ICollectionPropertiesMapper { - void Id(Action<ICollectionIdMapper> idMapper); + void Id(Action<ICollectionIdMapper> idMapping); } public interface IIdBagPropertiesMapper<TEntity, TElement> : ICollectionPropertiesMapper<TEntity, TElement> where TEntity : class { - void Id(Action<ICollectionIdMapper> idMapper); + void Id(Action<ICollectionIdMapper> idMapping); } } \ No newline at end of file Added: trunk/nhibernate/src/NHibernate/Mapping/ByCode/Impl/CollectionIdMapper.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Mapping/ByCode/Impl/CollectionIdMapper.cs (rev 0) +++ trunk/nhibernate/src/NHibernate/Mapping/ByCode/Impl/CollectionIdMapper.cs 2011-04-05 22:03:58 UTC (rev 5617) @@ -0,0 +1,96 @@ +using System; +using System.Linq; +using NHibernate.Cfg.MappingSchema; +using NHibernate.Type; + +namespace NHibernate.Mapping.ByCode.Impl +{ + public class CollectionIdMapper: ICollectionIdMapper + { + private readonly HbmCollectionId hbmId; + private const string DefaultColumnName = "collection_key"; + private string autosetType; + + public CollectionIdMapper(HbmCollectionId hbmId) + { + this.hbmId = hbmId; + this.hbmId.column1 = DefaultColumnName; + Generator(Generators.Guid); + } + + #region Implementation of IIdMapper + + public void Generator(IGeneratorDef generator) + { + Generator(generator, x => { }); + } + + public void Generator(IGeneratorDef generator, Action<IGeneratorMapper> generatorMapping) + { + if (generator == null) + { + return; + } + if(!generator.SupportedAsCollectionElementId) + { + throw new NotSupportedException("The generator '" + generator.Class + "' cannot be used as collection element id."); + } + ApplyGenerator(generator); + generatorMapping(new GeneratorMapper(hbmId.generator)); + } + + public void Type(IIdentifierType persistentType) + { + if (persistentType != null) + { + hbmId.type = persistentType.Name; + } + } + + public void Column(string name) + { + if (string.IsNullOrEmpty(name)) + { + return; + } + hbmId.column1 = name; + } + + public void Length(int length) + { + hbmId.length = length.ToString(); + } + + private void ApplyGenerator(IGeneratorDef generator) + { + var hbmGenerator = new HbmGenerator { @class = generator.Class }; + object generatorParameters = generator.Params; + if (generatorParameters != null) + { + hbmGenerator.param = (from pi in generatorParameters.GetType().GetProperties() + let pname = pi.Name + let pvalue = pi.GetValue(generatorParameters, null) + select + new HbmParam { name = pname, Text = new[] { ReferenceEquals(pvalue, null) ? "null" : pvalue.ToString() } }). + ToArray(); + } + else + { + hbmGenerator.param = null; + } + hbmId.generator = hbmGenerator; + AutosetTypeThroughGeneratorDef(generator); + } + + #endregion + + private void AutosetTypeThroughGeneratorDef(IGeneratorDef generator) + { + if (Equals(hbmId.type, autosetType) && generator.DefaultReturnType != null) + { + autosetType = generator.DefaultReturnType.GetNhTypeName(); + hbmId.type = autosetType; + } + } + } +} \ No newline at end of file Modified: trunk/nhibernate/src/NHibernate/Mapping/ByCode/Impl/IdBagMapper.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Mapping/ByCode/Impl/IdBagMapper.cs 2011-04-05 20:53:30 UTC (rev 5616) +++ trunk/nhibernate/src/NHibernate/Mapping/ByCode/Impl/IdBagMapper.cs 2011-04-05 22:03:58 UTC (rev 5617) @@ -13,8 +13,9 @@ private readonly KeyMapper keyMapper; private readonly HbmIdbag mapping; private ICacheMapper cacheMapper; + private readonly CollectionIdMapper idMapper; - public IdBagMapper(System.Type ownerType, System.Type elementType, System.Type idType, HbmIdbag mapping) + public IdBagMapper(System.Type ownerType, System.Type elementType, HbmIdbag mapping) { if (ownerType == null) { @@ -36,6 +37,11 @@ mapping.key = new HbmKey(); } keyMapper = new KeyMapper(ownerType, mapping.Key); + if (mapping.collectionid == null) + { + mapping.collectionid = new HbmCollectionId(); + } + idMapper = new CollectionIdMapper(mapping.collectionid); entityPropertyMapper = new AccessorPropertyMapper(ownerType, mapping.Name, x => mapping.access = x); } @@ -185,9 +191,9 @@ mapping.fetchSpecified = mapping.fetch != HbmCollectionFetchMode.Select; } - public void Id(Action<ICollectionIdMapper> idMapper) + public void Id(Action<ICollectionIdMapper> idMapping) { - throw new NotImplementedException(); + idMapping(idMapper); } #endregion Modified: trunk/nhibernate/src/NHibernate/NHibernate.csproj =================================================================== --- trunk/nhibernate/src/NHibernate/NHibernate.csproj 2011-04-05 20:53:30 UTC (rev 5616) +++ trunk/nhibernate/src/NHibernate/NHibernate.csproj 2011-04-05 22:03:58 UTC (rev 5617) @@ -332,6 +332,7 @@ <Compile Include="Mapping\ByCode\Impl\CascadeConverter.cs" /> <Compile Include="Mapping\ByCode\Impl\ClassMapper.cs" /> <Compile Include="Mapping\ByCode\Impl\CollectionElementRelation.cs" /> + <Compile Include="Mapping\ByCode\Impl\CollectionIdMapper.cs" /> <Compile Include="Mapping\ByCode\Impl\ColumnMapper.cs" /> <Compile Include="Mapping\ByCode\Impl\ComponentElementMapper.cs" /> <Compile Include="Mapping\ByCode\Impl\ComponentMapKeyMapper.cs" /> Added: trunk/nhibernate/src/NHibernate.Test/MappingByCode/MappersTests/CollectionIdMapperTests.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Test/MappingByCode/MappersTests/CollectionIdMapperTests.cs (rev 0) +++ trunk/nhibernate/src/NHibernate.Test/MappingByCode/MappersTests/CollectionIdMapperTests.cs 2011-04-05 22:03:58 UTC (rev 5617) @@ -0,0 +1,122 @@ +using System; +using System.Linq; +using NHibernate.Cfg.MappingSchema; +using NHibernate.Mapping.ByCode; +using NHibernate.Mapping.ByCode.Impl; +using NHibernate.Type; +using NUnit.Framework; +using SharpTestsEx; + +namespace NHibernate.Test.MappingByCode.MappersTests +{ + public class CollectionIdMapperTests + { + [Test] + public void WhenCreateThenHasDefaultTypeAndGenerator() + { + var hbmId = new HbmCollectionId(); + new CollectionIdMapper(hbmId); + hbmId.generator.@class.Should().Not.Be.NullOrEmpty(); + hbmId.type.Should().Not.Be.NullOrEmpty(); + } + + [Test] + public void WhenSetGeneratorThenChangeType() + { + var hbmId = new HbmCollectionId(); + new CollectionIdMapper(hbmId).Generator(Generators.HighLow); + + hbmId.generator.@class.Should().Be.EqualTo("hilo"); + hbmId.type.ToLowerInvariant().Should().Contain("int"); + } + + [Test] + public void WhenForceTypeThenNotChangeType() + { + var hbmId = new HbmCollectionId(); + var collectionIdMapper = new CollectionIdMapper(hbmId); + collectionIdMapper.Type((IIdentifierType) NHibernateUtil.Int64); + collectionIdMapper.Generator(Generators.HighLow); + + hbmId.generator.@class.Should().Be.EqualTo("hilo"); + hbmId.type.Should().Be("Int64"); + } + + [Test] + public void CanSetGenerator() + { + var hbmId = new HbmCollectionId(); + new CollectionIdMapper(hbmId).Generator(Generators.HighLow); + hbmId.generator.@class.Should().Be.EqualTo("hilo"); + } + + [Test] + public void CanSetGeneratorWithParameters() + { + var hbmId = new HbmCollectionId(); + new CollectionIdMapper(hbmId).Generator(Generators.HighLow, p => p.Params(new { max_low = 99, where = "TableName" })); + hbmId.generator.@class.Should().Be.EqualTo("hilo"); + hbmId.generator.param.Should().Have.Count.EqualTo(2); + hbmId.generator.param.Select(p => p.name).Should().Have.SameValuesAs("max_low", "where"); + hbmId.generator.param.Select(p => p.GetText()).Should().Have.SameValuesAs("99", "TableName"); + } + + [Test] + public void CanSetGeneratorGuid() + { + var hbmId = new HbmCollectionId(); + new CollectionIdMapper(hbmId).Generator(Generators.Guid); + hbmId.generator.@class.Should().Be.EqualTo("guid"); + } + + [Test] + public void CanSetGeneratorGuidComb() + { + var hbmId = new HbmCollectionId(); + new CollectionIdMapper(hbmId).Generator(Generators.GuidComb); + hbmId.generator.@class.Should().Be.EqualTo("guid.comb"); + } + + [Test] + public void CanSetGeneratorSequence() + { + var hbmId = new HbmCollectionId(); + new CollectionIdMapper(hbmId).Generator(Generators.Sequence); + hbmId.generator.@class.Should().Be.EqualTo("sequence"); + } + + [Test] + public void CanSetGeneratorIdentity() + { + var hbmId = new HbmCollectionId(); + new CollectionIdMapper(hbmId).Generator(Generators.Identity); + hbmId.generator.@class.Should().Be.EqualTo("identity"); + } + + [Test] + public void CantSetGeneratorAssigned() + { + var hbmId = new HbmCollectionId(); + var collectionIdMapper = new CollectionIdMapper(hbmId); + collectionIdMapper.Executing(x=> x.Generator(Generators.Assigned)).Throws<NotSupportedException>(); + } + + [Test] + public void CanSetColumnName() + { + var hbmId = new HbmCollectionId(); + var mapper = new CollectionIdMapper(hbmId); + mapper.Column("MyName"); + hbmId.Columns.Single().name.Should().Be("MyName"); + } + + [Test] + public void CanSetLength() + { + var hbmId = new HbmCollectionId(); + var mapper = new CollectionIdMapper(hbmId); + mapper.Length(10); + hbmId.length.Should().Be("10"); + } + } +} \ No newline at end of file Modified: trunk/nhibernate/src/NHibernate.Test/MappingByCode/MappersTests/IdBagMapperTest.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Test/MappingByCode/MappersTests/IdBagMapperTest.cs 2011-04-05 20:53:30 UTC (rev 5616) +++ trunk/nhibernate/src/NHibernate.Test/MappingByCode/MappersTests/IdBagMapperTest.cs 2011-04-05 22:03:58 UTC (rev 5617) @@ -22,10 +22,41 @@ } [Test] + public void WhenCreatedHasId() + { + var hbm = new HbmIdbag(); + new IdBagMapper(typeof(Animal), typeof(Animal), hbm); + hbm.collectionid.Should().Not.Be.Null(); + } + + [Test] + public void WhenConfigureIdMoreThanOnceThenUseSameMapper() + { + var hbm = new HbmIdbag(); + var mapper = new IdBagMapper(typeof(Animal), typeof(Animal), hbm); + ICollectionIdMapper firstInstance = null; + ICollectionIdMapper secondInstance = null; + mapper.Id(x => firstInstance = x); + mapper.Id(x => secondInstance = x); + + firstInstance.Should().Be.SameInstanceAs(secondInstance); + } + + [Test] + public void WhenConfigureIdThenCallMapper() + { + var hbm = new HbmIdbag(); + var mapper = new IdBagMapper(typeof(Animal), typeof(Animal), hbm); + mapper.Id(x => x.Column("catchMe")); + + hbm.collectionid.Columns.Single().name.Should().Be("catchMe"); + } + + [Test] public void SetInverse() { var hbm = new HbmIdbag(); - var mapper = new IdBagMapper(typeof(Animal), typeof(Animal), typeof(int), hbm); + var mapper = new IdBagMapper(typeof(Animal), typeof(Animal), hbm); mapper.Inverse(true); hbm.Inverse.Should().Be.True(); mapper.Inverse(false); @@ -36,7 +67,7 @@ public void SetMutable() { var hbm = new HbmIdbag(); - var mapper = new IdBagMapper(typeof(Animal), typeof(Animal), typeof(int), hbm); + var mapper = new IdBagMapper(typeof(Animal), typeof(Animal), hbm); mapper.Mutable(true); hbm.Mutable.Should().Be.True(); mapper.Mutable(false); @@ -47,7 +78,7 @@ public void SetWhere() { var hbm = new HbmIdbag(); - var mapper = new IdBagMapper(typeof(Animal), typeof(Animal), typeof(int), hbm); + var mapper = new IdBagMapper(typeof(Animal), typeof(Animal), hbm); mapper.Where("c > 10"); hbm.Where.Should().Be.EqualTo("c > 10"); } @@ -56,7 +87,7 @@ public void SetBatchSize() { var hbm = new HbmIdbag(); - var mapper = new IdBagMapper(typeof(Animal), typeof(Animal), typeof(int), hbm); + var mapper = new IdBagMapper(typeof(Animal), typeof(Animal), hbm); mapper.BatchSize(10); hbm.BatchSize.Should().Be.EqualTo(10); } @@ -65,7 +96,7 @@ public void SetLazy() { var hbm = new HbmIdbag(); - var mapper = new IdBagMapper(typeof(Animal), typeof(Animal), typeof(int), hbm); + var mapper = new IdBagMapper(typeof(Animal), typeof(Animal), hbm); mapper.Lazy(CollectionLazy.Extra); hbm.Lazy.Should().Be.EqualTo(HbmCollectionLazy.Extra); mapper.Lazy(CollectionLazy.NoLazy); @@ -78,7 +109,7 @@ public void CallKeyMapper() { var hbm = new HbmIdbag(); - var mapper = new IdBagMapper(typeof(Animal), typeof(Animal), typeof(int), hbm); + var mapper = new IdBagMapper(typeof(Animal), typeof(Animal), hbm); bool kmCalled = false; mapper.Key(km => kmCalled = true); hbm.Key.Should().Not.Be.Null(); @@ -89,7 +120,7 @@ public void SetCollectionTypeByWrongTypeShouldThrow() { var hbm = new HbmIdbag(); - var mapper = new IdBagMapper(typeof(Animal), typeof(Animal), typeof(int), hbm); + var mapper = new IdBagMapper(typeof(Animal), typeof(Animal), hbm); Executing.This(() => mapper.Type(null)).Should().Throw<ArgumentNullException>(); Executing.This(() => mapper.Type(typeof(object))).Should().Throw<ArgumentOutOfRangeException>(); } @@ -98,7 +129,7 @@ public void SetCollectionTypeByGenericType() { var hbm = new HbmIdbag(); - var mapper = new IdBagMapper(typeof(Animal), typeof(Animal), typeof(int), hbm); + var mapper = new IdBagMapper(typeof(Animal), typeof(Animal), hbm); mapper.Type<FakeUserCollectionType>(); hbm.CollectionType.Should().Contain("FakeUserCollectionType"); } @@ -107,7 +138,7 @@ public void SetCollectionTypeByType() { var hbm = new HbmIdbag(); - var mapper = new IdBagMapper(typeof(Animal), typeof(Animal), typeof(int), hbm); + var mapper = new IdBagMapper(typeof(Animal), typeof(Animal), hbm); mapper.Type(typeof(FakeUserCollectionType)); hbm.CollectionType.Should().Contain("FakeUserCollectionType"); } @@ -116,7 +147,7 @@ public void CanChangeAccessor() { var hbm = new HbmIdbag { name = "Children" }; - var mapper = new IdBagMapper(typeof(Animal), typeof(Animal), typeof(int), hbm); + var mapper = new IdBagMapper(typeof(Animal), typeof(Animal), hbm); mapper.Access(Accessor.Field); hbm.Access.Should().Not.Be.Null(); @@ -126,7 +157,7 @@ public void CanSetCache() { var hbm = new HbmIdbag { name = "Children" }; - var mapper = new IdBagMapper(typeof(Animal), typeof(Animal), typeof(int), hbm); + var mapper = new IdBagMapper(typeof(Animal), typeof(Animal), hbm); mapper.Cache(x => x.Region("pizza")); hbm.cache.Should().Not.Be.Null(); @@ -136,7 +167,7 @@ public void WhenSetTwoCachePropertiesInTwoActionsThenSetTheTwoValuesWithoutLostTheFirst() { var hbm = new HbmIdbag { name = "Children" }; - var mapper = new IdBagMapper(typeof(Animal), typeof(Animal), typeof(int), hbm); + var mapper = new IdBagMapper(typeof(Animal), typeof(Animal), hbm); mapper.Cache(ch => ch.Region("pizza")); mapper.Cache(ch => ch.Usage(CacheUsage.NonstrictReadWrite)); @@ -150,7 +181,7 @@ public void CanSetAFilterThroughAction() { var hbm = new HbmIdbag { name = "Children" }; - var mapper = new IdBagMapper(typeof(Animal), typeof(Animal), typeof(int), hbm); + var mapper = new IdBagMapper(typeof(Animal), typeof(Animal), hbm); mapper.Filter("filter1", f => f.Condition("condition1")); hbm.filter.Length.Should().Be(1); hbm.filter[0].Satisfy(f => f.name == "filter1" && f.condition == "condition1"); @@ -160,7 +191,7 @@ public void CanSetMoreFiltersThroughAction() { var hbm = new HbmIdbag { name = "Children" }; - var mapper = new IdBagMapper(typeof(Animal), typeof(Animal), typeof(int), hbm); + var mapper = new IdBagMapper(typeof(Animal), typeof(Animal), hbm); mapper.Filter("filter1", f => f.Condition("condition1")); mapper.Filter("filter2", f => f.Condition("condition2")); hbm.filter.Length.Should().Be(2); @@ -172,7 +203,7 @@ public void WhenSameNameThenOverrideCondition() { var hbm = new HbmIdbag { name = "Children" }; - var mapper = new IdBagMapper(typeof(Animal), typeof(Animal), typeof(int), hbm); + var mapper = new IdBagMapper(typeof(Animal), typeof(Animal), hbm); mapper.Filter("filter1", f => f.Condition("condition1")); mapper.Filter("filter2", f => f.Condition("condition2")); mapper.Filter("filter1", f => f.Condition("anothercondition1")); @@ -185,7 +216,7 @@ public void WhenActionIsNullThenAddFilterName() { var hbm = new HbmIdbag { name = "Children" }; - var mapper = new IdBagMapper(typeof(Animal), typeof(Animal), typeof(int), hbm); + var mapper = new IdBagMapper(typeof(Animal), typeof(Animal), hbm); mapper.Filter("filter1", null); hbm.filter.Length.Should().Be(1); hbm.filter[0].Satisfy(f => f.name == "filter1" && f.condition == null); @@ -195,7 +226,7 @@ public void SetFetchMode() { var hbm = new HbmIdbag(); - var mapper = new IdBagMapper(typeof(Animal), typeof(Animal), typeof(int), hbm); + var mapper = new IdBagMapper(typeof(Animal), typeof(Animal), hbm); mapper.Fetch(CollectionFetchMode.Subselect); hbm.fetch.Should().Be(HbmCollectionFetchMode.Subselect); hbm.fetchSpecified.Should().Be.True(); Modified: trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2011-04-05 20:53:30 UTC (rev 5616) +++ trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2011-04-05 22:03:58 UTC (rev 5617) @@ -528,6 +528,7 @@ <Compile Include="MappingByCode\For.cs" /> <Compile Include="MappingByCode\MappersTests\AbstractPropertyContainerMapperTest.cs" /> <Compile Include="MappingByCode\MappersTests\ClassMapperWithJoinPropertiesTest.cs" /> + <Compile Include="MappingByCode\MappersTests\CollectionIdMapperTests.cs" /> <Compile Include="MappingByCode\MappersTests\FakeUserCollectionType.cs" /> <Compile Include="MappingByCode\MappersTests\IdBagMapperTest.cs" /> <Compile Include="MappingByCode\MappersTests\JoinMapperTests.cs" /> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fab...@us...> - 2011-04-05 20:53:37
|
Revision: 5616 http://nhibernate.svn.sourceforge.net/nhibernate/?rev=5616&view=rev Author: fabiomaulo Date: 2011-04-05 20:53:30 +0000 (Tue, 05 Apr 2011) Log Message: ----------- Starting id-bag support Modified Paths: -------------- trunk/nhibernate/src/NHibernate/NHibernate.csproj trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj Added Paths: ----------- trunk/nhibernate/src/NHibernate/Mapping/ByCode/ICollectionIdMapper.cs trunk/nhibernate/src/NHibernate/Mapping/ByCode/IIdBagPropertiesMapper.cs trunk/nhibernate/src/NHibernate/Mapping/ByCode/Impl/IdBagMapper.cs trunk/nhibernate/src/NHibernate.Test/MappingByCode/MappersTests/FakeUserCollectionType.cs trunk/nhibernate/src/NHibernate.Test/MappingByCode/MappersTests/IdBagMapperTest.cs Added: trunk/nhibernate/src/NHibernate/Mapping/ByCode/ICollectionIdMapper.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Mapping/ByCode/ICollectionIdMapper.cs (rev 0) +++ trunk/nhibernate/src/NHibernate/Mapping/ByCode/ICollectionIdMapper.cs 2011-04-05 20:53:30 UTC (rev 5616) @@ -0,0 +1,15 @@ +using System; +using NHibernate.Type; + +namespace NHibernate.Mapping.ByCode +{ + public interface ICollectionIdMapper + { + void Generator(IGeneratorDef generator); + void Generator(IGeneratorDef generator, Action<IGeneratorMapper> generatorMapping); + + void Type(IIdentifierType persistentType); + void Column(string name); + void Length(int length); + } +} \ No newline at end of file Added: trunk/nhibernate/src/NHibernate/Mapping/ByCode/IIdBagPropertiesMapper.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Mapping/ByCode/IIdBagPropertiesMapper.cs (rev 0) +++ trunk/nhibernate/src/NHibernate/Mapping/ByCode/IIdBagPropertiesMapper.cs 2011-04-05 20:53:30 UTC (rev 5616) @@ -0,0 +1,13 @@ +using System; +namespace NHibernate.Mapping.ByCode +{ + public interface IIdBagPropertiesMapper : ICollectionPropertiesMapper + { + void Id(Action<ICollectionIdMapper> idMapper); + } + + public interface IIdBagPropertiesMapper<TEntity, TElement> : ICollectionPropertiesMapper<TEntity, TElement> where TEntity : class + { + void Id(Action<ICollectionIdMapper> idMapper); + } +} \ No newline at end of file Added: trunk/nhibernate/src/NHibernate/Mapping/ByCode/Impl/IdBagMapper.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Mapping/ByCode/Impl/IdBagMapper.cs (rev 0) +++ trunk/nhibernate/src/NHibernate/Mapping/ByCode/Impl/IdBagMapper.cs 2011-04-05 20:53:30 UTC (rev 5616) @@ -0,0 +1,272 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Reflection; +using NHibernate.Cfg.MappingSchema; +using NHibernate.UserTypes; + +namespace NHibernate.Mapping.ByCode.Impl +{ + public class IdBagMapper : IIdBagPropertiesMapper + { + private readonly IAccessorPropertyMapper entityPropertyMapper; + private readonly KeyMapper keyMapper; + private readonly HbmIdbag mapping; + private ICacheMapper cacheMapper; + + public IdBagMapper(System.Type ownerType, System.Type elementType, System.Type idType, HbmIdbag mapping) + { + if (ownerType == null) + { + throw new ArgumentNullException("ownerType"); + } + if (elementType == null) + { + throw new ArgumentNullException("elementType"); + } + if (mapping == null) + { + throw new ArgumentNullException("mapping"); + } + OwnerType = ownerType; + ElementType = elementType; + this.mapping = mapping; + if (mapping.Key == null) + { + mapping.key = new HbmKey(); + } + keyMapper = new KeyMapper(ownerType, mapping.Key); + entityPropertyMapper = new AccessorPropertyMapper(ownerType, mapping.Name, x => mapping.access = x); + } + + public System.Type OwnerType { get; private set; } + public System.Type ElementType { get; private set; } + + #region Implementation of ICollectionPropertiesMapper + + public void Inverse(bool value) + { + mapping.inverse = value; + } + + public void Mutable(bool value) + { + mapping.mutable = value; + } + + public void Where(string sqlWhereClause) + { + mapping.where = sqlWhereClause; + } + + public void BatchSize(int value) + { + if (value > 0) + { + mapping.batchsize = value; + mapping.batchsizeSpecified = true; + } + else + { + mapping.batchsize = 0; + mapping.batchsizeSpecified = false; + } + } + + public void Lazy(CollectionLazy collectionLazy) + { + mapping.lazySpecified = true; + switch (collectionLazy) + { + case CollectionLazy.Lazy: + mapping.lazy = HbmCollectionLazy.True; + break; + case CollectionLazy.NoLazy: + mapping.lazy = HbmCollectionLazy.False; + break; + case CollectionLazy.Extra: + mapping.lazy = HbmCollectionLazy.Extra; + break; + } + } + + public void Key(Action<IKeyMapper> keyMapping) + { + keyMapping(keyMapper); + } + + public void OrderBy(MemberInfo property) + { + // TODO: read the mapping of the element to know the column of the property (second-pass) + mapping.orderby = property.Name; + } + + public void OrderBy(string sqlOrderByClause) + { + mapping.orderby = sqlOrderByClause; + } + + public void Sort() {} + public void Sort<TComparer>() {} + + public void Cascade(Cascade cascadeStyle) + { + mapping.cascade = cascadeStyle.ToCascadeString(); + } + + public void Type<TCollection>() where TCollection : IUserCollectionType + { + mapping.collectiontype = typeof (TCollection).AssemblyQualifiedName; + } + + public void Type(System.Type collectionType) + { + if (collectionType == null) + { + throw new ArgumentNullException("collectionType"); + } + if (!typeof (IUserCollectionType).IsAssignableFrom(collectionType)) + { + throw new ArgumentOutOfRangeException("collectionType", + string.Format( + "The collection type should be an implementation of IUserCollectionType.({0})", + collectionType)); + } + mapping.collectiontype = collectionType.AssemblyQualifiedName; + } + + public void Table(string tableName) + { + mapping.table = tableName; + } + + public void Catalog(string catalogName) + { + mapping.catalog = catalogName; + } + + public void Schema(string schemaName) + { + mapping.schema = schemaName; + } + + public void Cache(Action<ICacheMapper> cacheMapping) + { + if (cacheMapper == null) + { + var hbmCache = new HbmCache(); + mapping.cache = hbmCache; + cacheMapper = new CacheMapper(hbmCache); + } + cacheMapping(cacheMapper); + } + + public void Filter(string filterName, Action<IFilterMapper> filterMapping) + { + if (filterMapping == null) + { + filterMapping = x => { }; + } + var hbmFilter = new HbmFilter(); + var filterMapper = new FilterMapper(filterName, hbmFilter); + filterMapping(filterMapper); + Dictionary<string, HbmFilter> filters = mapping.filter != null ? mapping.filter.ToDictionary(f => f.name, f => f) : new Dictionary<string, HbmFilter>(1); + filters[filterName] = hbmFilter; + mapping.filter = filters.Values.ToArray(); + } + + public void Fetch(CollectionFetchMode fetchMode) + { + if (fetchMode == null) + { + return; + } + mapping.fetch = fetchMode.ToHbm(); + mapping.fetchSpecified = mapping.fetch != HbmCollectionFetchMode.Select; + } + + public void Id(Action<ICollectionIdMapper> idMapper) + { + throw new NotImplementedException(); + } + + #endregion + + #region Implementation of IEntityPropertyMapper + + public void Access(Accessor accessor) + { + entityPropertyMapper.Access(accessor); + } + + public void Access(System.Type accessorType) + { + entityPropertyMapper.Access(accessorType); + } + + public void OptimisticLock(bool takeInConsiderationForOptimisticLock) + { + mapping.optimisticlock = takeInConsiderationForOptimisticLock; + } + + #endregion + + #region IIdBagPropertiesMapper Members + + public void Loader(string namedQueryReference) + { + if (mapping.SqlLoader == null) + { + mapping.loader = new HbmLoader(); + } + mapping.loader.queryref = namedQueryReference; + } + + public void SqlInsert(string sql) + { + if (mapping.SqlInsert == null) + { + mapping.sqlinsert = new HbmCustomSQL(); + } + mapping.sqlinsert.Text = new[] {sql}; + } + + public void SqlUpdate(string sql) + { + if (mapping.SqlUpdate == null) + { + mapping.sqlupdate = new HbmCustomSQL(); + } + mapping.sqlupdate.Text = new[] {sql}; + } + + public void SqlDelete(string sql) + { + if (mapping.SqlDelete == null) + { + mapping.sqldelete = new HbmCustomSQL(); + } + mapping.sqldelete.Text = new[] {sql}; + } + + public void SqlDeleteAll(string sql) + { + if (mapping.SqlDeleteAll == null) + { + mapping.sqldeleteall = new HbmCustomSQL(); + } + mapping.sqldeleteall.Text = new[] {sql}; + } + + public void Subselect(string sql) + { + if (mapping.Subselect == null) + { + mapping.subselect = new HbmSubselect(); + } + mapping.subselect.Text = new[] {sql}; + } + + #endregion + } +} \ No newline at end of file Modified: trunk/nhibernate/src/NHibernate/NHibernate.csproj =================================================================== --- trunk/nhibernate/src/NHibernate/NHibernate.csproj 2011-04-05 18:57:28 UTC (rev 5615) +++ trunk/nhibernate/src/NHibernate/NHibernate.csproj 2011-04-05 20:53:30 UTC (rev 5616) @@ -290,6 +290,7 @@ <Compile Include="Mapping\ByCode\ICacheMapper.cs" /> <Compile Include="Mapping\ByCode\IClassMapper.cs" /> <Compile Include="Mapping\ByCode\ICollectionElementRelation.cs" /> + <Compile Include="Mapping\ByCode\ICollectionIdMapper.cs" /> <Compile Include="Mapping\ByCode\ICollectionPropertiesMapper.cs" /> <Compile Include="Mapping\ByCode\ICollectionSqlsMapper.cs" /> <Compile Include="Mapping\ByCode\IColumnMapper.cs" /> @@ -307,6 +308,7 @@ <Compile Include="Mapping\ByCode\IGenerator.cs" /> <Compile Include="Mapping\ByCode\IGeneratorDef.cs" /> <Compile Include="Mapping\ByCode\IGeneratorMapper.cs" /> + <Compile Include="Mapping\ByCode\IIdBagPropertiesMapper.cs" /> <Compile Include="Mapping\ByCode\IIdMapper.cs" /> <Compile Include="Mapping\ByCode\IJoinedSubclassMapper.cs" /> <Compile Include="Mapping\ByCode\IJoinMapper.cs" /> @@ -370,6 +372,7 @@ <Compile Include="Mapping\ByCode\Generators.cs" /> <Compile Include="Mapping\ByCode\Impl\ICandidatePersistentMembersProvider.cs" /> <Compile Include="Mapping\ByCode\Impl\ICustomizersHolder.cs" /> + <Compile Include="Mapping\ByCode\Impl\IdBagMapper.cs" /> <Compile Include="Mapping\ByCode\Impl\IdMapper.cs" /> <Compile Include="Mapping\ByCode\Impl\JoinedSubclassMapper.cs" /> <Compile Include="Mapping\ByCode\Impl\JoinMapper.cs" /> Added: trunk/nhibernate/src/NHibernate.Test/MappingByCode/MappersTests/FakeUserCollectionType.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Test/MappingByCode/MappersTests/FakeUserCollectionType.cs (rev 0) +++ trunk/nhibernate/src/NHibernate.Test/MappingByCode/MappersTests/FakeUserCollectionType.cs 2011-04-05 20:53:30 UTC (rev 5616) @@ -0,0 +1,51 @@ +using System; +using System.Collections; +using NHibernate.Collection; +using NHibernate.Engine; +using NHibernate.Persister.Collection; +using NHibernate.UserTypes; + +namespace NHibernate.Test.MappingByCode.MappersTests +{ + public class FakeUserCollectionType: IUserCollectionType + { + #region Implementation of IUserCollectionType + + public IPersistentCollection Instantiate(ISessionImplementor session, ICollectionPersister persister) + { + throw new NotImplementedException(); + } + + public IPersistentCollection Wrap(ISessionImplementor session, object collection) + { + throw new NotImplementedException(); + } + + public IEnumerable GetElements(object collection) + { + throw new NotImplementedException(); + } + + public bool Contains(object collection, object entity) + { + throw new NotImplementedException(); + } + + public object IndexOf(object collection, object entity) + { + throw new NotImplementedException(); + } + + public object ReplaceElements(object original, object target, ICollectionPersister persister, object owner, IDictionary copyCache, ISessionImplementor session) + { + throw new NotImplementedException(); + } + + public object Instantiate(int anticipatedSize) + { + throw new NotImplementedException(); + } + + #endregion + } +} \ No newline at end of file Added: trunk/nhibernate/src/NHibernate.Test/MappingByCode/MappersTests/IdBagMapperTest.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Test/MappingByCode/MappersTests/IdBagMapperTest.cs (rev 0) +++ trunk/nhibernate/src/NHibernate.Test/MappingByCode/MappersTests/IdBagMapperTest.cs 2011-04-05 20:53:30 UTC (rev 5616) @@ -0,0 +1,210 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using NHibernate.Cfg.MappingSchema; +using NHibernate.Mapping.ByCode; +using NHibernate.Mapping.ByCode.Impl; +using NUnit.Framework; +using SharpTestsEx; + +namespace NHibernate.Test.MappingByCode.MappersTests +{ + public class IdBagMapperTest + { + private class Animal + { + public int Id { get; set; } + private ICollection<Animal> children; + public ICollection<Animal> Children + { + get { return children; } + } + } + + [Test] + public void SetInverse() + { + var hbm = new HbmIdbag(); + var mapper = new IdBagMapper(typeof(Animal), typeof(Animal), typeof(int), hbm); + mapper.Inverse(true); + hbm.Inverse.Should().Be.True(); + mapper.Inverse(false); + hbm.Inverse.Should().Be.False(); + } + + [Test] + public void SetMutable() + { + var hbm = new HbmIdbag(); + var mapper = new IdBagMapper(typeof(Animal), typeof(Animal), typeof(int), hbm); + mapper.Mutable(true); + hbm.Mutable.Should().Be.True(); + mapper.Mutable(false); + hbm.Mutable.Should().Be.False(); + } + + [Test] + public void SetWhere() + { + var hbm = new HbmIdbag(); + var mapper = new IdBagMapper(typeof(Animal), typeof(Animal), typeof(int), hbm); + mapper.Where("c > 10"); + hbm.Where.Should().Be.EqualTo("c > 10"); + } + + [Test] + public void SetBatchSize() + { + var hbm = new HbmIdbag(); + var mapper = new IdBagMapper(typeof(Animal), typeof(Animal), typeof(int), hbm); + mapper.BatchSize(10); + hbm.BatchSize.Should().Be.EqualTo(10); + } + + [Test] + public void SetLazy() + { + var hbm = new HbmIdbag(); + var mapper = new IdBagMapper(typeof(Animal), typeof(Animal), typeof(int), hbm); + mapper.Lazy(CollectionLazy.Extra); + hbm.Lazy.Should().Be.EqualTo(HbmCollectionLazy.Extra); + mapper.Lazy(CollectionLazy.NoLazy); + hbm.Lazy.Should().Be.EqualTo(HbmCollectionLazy.False); + mapper.Lazy(CollectionLazy.Lazy); + hbm.Lazy.Should().Be.EqualTo(HbmCollectionLazy.True); + } + + [Test] + public void CallKeyMapper() + { + var hbm = new HbmIdbag(); + var mapper = new IdBagMapper(typeof(Animal), typeof(Animal), typeof(int), hbm); + bool kmCalled = false; + mapper.Key(km => kmCalled = true); + hbm.Key.Should().Not.Be.Null(); + kmCalled.Should().Be.True(); + } + + [Test] + public void SetCollectionTypeByWrongTypeShouldThrow() + { + var hbm = new HbmIdbag(); + var mapper = new IdBagMapper(typeof(Animal), typeof(Animal), typeof(int), hbm); + Executing.This(() => mapper.Type(null)).Should().Throw<ArgumentNullException>(); + Executing.This(() => mapper.Type(typeof(object))).Should().Throw<ArgumentOutOfRangeException>(); + } + + [Test] + public void SetCollectionTypeByGenericType() + { + var hbm = new HbmIdbag(); + var mapper = new IdBagMapper(typeof(Animal), typeof(Animal), typeof(int), hbm); + mapper.Type<FakeUserCollectionType>(); + hbm.CollectionType.Should().Contain("FakeUserCollectionType"); + } + + [Test] + public void SetCollectionTypeByType() + { + var hbm = new HbmIdbag(); + var mapper = new IdBagMapper(typeof(Animal), typeof(Animal), typeof(int), hbm); + mapper.Type(typeof(FakeUserCollectionType)); + hbm.CollectionType.Should().Contain("FakeUserCollectionType"); + } + + [Test] + public void CanChangeAccessor() + { + var hbm = new HbmIdbag { name = "Children" }; + var mapper = new IdBagMapper(typeof(Animal), typeof(Animal), typeof(int), hbm); + mapper.Access(Accessor.Field); + + hbm.Access.Should().Not.Be.Null(); + } + + [Test] + public void CanSetCache() + { + var hbm = new HbmIdbag { name = "Children" }; + var mapper = new IdBagMapper(typeof(Animal), typeof(Animal), typeof(int), hbm); + mapper.Cache(x => x.Region("pizza")); + + hbm.cache.Should().Not.Be.Null(); + } + + [Test] + public void WhenSetTwoCachePropertiesInTwoActionsThenSetTheTwoValuesWithoutLostTheFirst() + { + var hbm = new HbmIdbag { name = "Children" }; + var mapper = new IdBagMapper(typeof(Animal), typeof(Animal), typeof(int), hbm); + mapper.Cache(ch => ch.Region("pizza")); + mapper.Cache(ch => ch.Usage(CacheUsage.NonstrictReadWrite)); + + var hbmCache = hbm.cache; + hbmCache.Should().Not.Be.Null(); + hbmCache.region.Should().Be("pizza"); + hbmCache.usage.Should().Be(HbmCacheUsage.NonstrictReadWrite); + } + + [Test] + public void CanSetAFilterThroughAction() + { + var hbm = new HbmIdbag { name = "Children" }; + var mapper = new IdBagMapper(typeof(Animal), typeof(Animal), typeof(int), hbm); + mapper.Filter("filter1", f => f.Condition("condition1")); + hbm.filter.Length.Should().Be(1); + hbm.filter[0].Satisfy(f => f.name == "filter1" && f.condition == "condition1"); + } + + [Test] + public void CanSetMoreFiltersThroughAction() + { + var hbm = new HbmIdbag { name = "Children" }; + var mapper = new IdBagMapper(typeof(Animal), typeof(Animal), typeof(int), hbm); + mapper.Filter("filter1", f => f.Condition("condition1")); + mapper.Filter("filter2", f => f.Condition("condition2")); + hbm.filter.Length.Should().Be(2); + hbm.filter.Satisfy(filters => filters.Any(f => f.name == "filter1" && f.condition == "condition1")); + hbm.filter.Satisfy(filters => filters.Any(f => f.name == "filter2" && f.condition == "condition2")); + } + + [Test] + public void WhenSameNameThenOverrideCondition() + { + var hbm = new HbmIdbag { name = "Children" }; + var mapper = new IdBagMapper(typeof(Animal), typeof(Animal), typeof(int), hbm); + mapper.Filter("filter1", f => f.Condition("condition1")); + mapper.Filter("filter2", f => f.Condition("condition2")); + mapper.Filter("filter1", f => f.Condition("anothercondition1")); + hbm.filter.Length.Should().Be(2); + hbm.filter.Satisfy(filters => filters.Any(f => f.name == "filter1" && f.condition == "anothercondition1")); + hbm.filter.Satisfy(filters => filters.Any(f => f.name == "filter2" && f.condition == "condition2")); + } + + [Test] + public void WhenActionIsNullThenAddFilterName() + { + var hbm = new HbmIdbag { name = "Children" }; + var mapper = new IdBagMapper(typeof(Animal), typeof(Animal), typeof(int), hbm); + mapper.Filter("filter1", null); + hbm.filter.Length.Should().Be(1); + hbm.filter[0].Satisfy(f => f.name == "filter1" && f.condition == null); + } + + [Test] + public void SetFetchMode() + { + var hbm = new HbmIdbag(); + var mapper = new IdBagMapper(typeof(Animal), typeof(Animal), typeof(int), hbm); + mapper.Fetch(CollectionFetchMode.Subselect); + hbm.fetch.Should().Be(HbmCollectionFetchMode.Subselect); + hbm.fetchSpecified.Should().Be.True(); + mapper.Fetch(CollectionFetchMode.Join); + hbm.fetch.Should().Be(HbmCollectionFetchMode.Join); + hbm.fetchSpecified.Should().Be.True(); + mapper.Fetch(CollectionFetchMode.Select); + hbm.fetch.Should().Be(HbmCollectionFetchMode.Select); + hbm.fetchSpecified.Should().Be.False(); + } + } +} \ No newline at end of file Modified: trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2011-04-05 18:57:28 UTC (rev 5615) +++ trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2011-04-05 20:53:30 UTC (rev 5616) @@ -528,6 +528,8 @@ <Compile Include="MappingByCode\For.cs" /> <Compile Include="MappingByCode\MappersTests\AbstractPropertyContainerMapperTest.cs" /> <Compile Include="MappingByCode\MappersTests\ClassMapperWithJoinPropertiesTest.cs" /> + <Compile Include="MappingByCode\MappersTests\FakeUserCollectionType.cs" /> + <Compile Include="MappingByCode\MappersTests\IdBagMapperTest.cs" /> <Compile Include="MappingByCode\MappersTests\JoinMapperTests.cs" /> <Compile Include="MappingByCode\MappersTests\SubclassMapperWithJoinPropertiesTest.cs" /> <Compile Include="MappingByCode\NatureDemo\Naturalness\Address.cs" /> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fab...@us...> - 2011-04-05 18:57:34
|
Revision: 5615 http://nhibernate.svn.sourceforge.net/nhibernate/?rev=5615&view=rev Author: fabiomaulo Date: 2011-04-05 18:57:28 +0000 (Tue, 05 Apr 2011) Log Message: ----------- Minor Modified Paths: -------------- trunk/nhibernate/src/NHibernate/Mapping/ByCode/ModelMapper.cs Modified: trunk/nhibernate/src/NHibernate/Mapping/ByCode/ModelMapper.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Mapping/ByCode/ModelMapper.cs 2011-04-05 18:52:02 UTC (rev 5614) +++ trunk/nhibernate/src/NHibernate/Mapping/ByCode/ModelMapper.cs 2011-04-05 18:57:28 UTC (rev 5615) @@ -640,7 +640,7 @@ IJoinMapper joinMapper; if (propertiesOfTheGroup.Count > 0 && classMapper.JoinMappers.TryGetValue(groupId, out joinMapper)) { - MapProperties(type, propertiesOfTheGroup, joinMapper); + MapSplittedProperties(type, propertiesOfTheGroup, joinMapper); propertiesInSplits.UnionWith(propertiesOfTheGroup); } } @@ -725,7 +725,7 @@ IJoinMapper joinMapper; if (propertiesOfTheGroup.Count > 0 && classMapper.JoinMappers.TryGetValue(groupId, out joinMapper)) { - MapProperties(type, propertiesOfTheGroup, joinMapper); + MapSplittedProperties(type, propertiesOfTheGroup, joinMapper); propertiesInSplits.UnionWith(propertiesOfTheGroup); } } @@ -734,7 +734,7 @@ InvokeAfterMapClass(type, classMapper); } - private void MapProperties(System.Type propertiesContainerType, IEnumerable<MemberInfo> propertiesToMap, IJoinMapper propertiesContainer) + private void MapSplittedProperties(System.Type propertiesContainerType, IEnumerable<MemberInfo> propertiesToMap, IJoinMapper propertiesContainer) { foreach (var property in propertiesToMap) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fab...@us...> - 2011-04-05 18:52:08
|
Revision: 5614 http://nhibernate.svn.sourceforge.net/nhibernate/?rev=5614&view=rev Author: fabiomaulo Date: 2011-04-05 18:52:02 +0000 (Tue, 05 Apr 2011) Log Message: ----------- SubclassCustomizer with Joins Modified Paths: -------------- trunk/nhibernate/src/NHibernate/Mapping/ByCode/Impl/SubclassMapper.cs trunk/nhibernate/src/NHibernate/Mapping/ByCode/ModelMapper.cs trunk/nhibernate/src/NHibernate.Test/MappingByCode/ExpliticMappingTests/SubclassPropertiesSplitsTests.cs Modified: trunk/nhibernate/src/NHibernate/Mapping/ByCode/Impl/SubclassMapper.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Mapping/ByCode/Impl/SubclassMapper.cs 2011-04-05 18:28:43 UTC (rev 5613) +++ trunk/nhibernate/src/NHibernate/Mapping/ByCode/Impl/SubclassMapper.cs 2011-04-05 18:52:02 UTC (rev 5614) @@ -33,7 +33,7 @@ #endregion - private Dictionary<string, IJoinMapper> JoinMappers + public Dictionary<string, IJoinMapper> JoinMappers { get { return joinMappers ?? (joinMappers = new Dictionary<string, IJoinMapper>()); } } Modified: trunk/nhibernate/src/NHibernate/Mapping/ByCode/ModelMapper.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Mapping/ByCode/ModelMapper.cs 2011-04-05 18:28:43 UTC (rev 5613) +++ trunk/nhibernate/src/NHibernate/Mapping/ByCode/ModelMapper.cs 2011-04-05 18:52:02 UTC (rev 5614) @@ -622,14 +622,32 @@ } } candidateProperties = candidateProperties ?? membersProvider.GetSubEntityMembers(type, type.BaseType); - IEnumerable<MemberInfo> propertiesToMap = - candidateProperties.Where(p => modelInspector.IsPersistentProperty(p) && !modelInspector.IsPersistentId(p)); InvokeBeforeMapSubclass(type, classMapper); customizerHolder.InvokeCustomizers(type, classMapper); + foreach (var joinMapper in classMapper.JoinMappers.Values) + { + customizerHolder.InvokeCustomizers(type, joinMapper); + } + + var splitGroups = modelInspector.GetPropertiesSplits(type); + var propertiesToMap = candidateProperties.Where(p => modelInspector.IsPersistentProperty(p) && !modelInspector.IsPersistentId(p)); + var propertiesInSplits = new HashSet<MemberInfo>(); + foreach (var splitGroup in splitGroups) + { + var groupId = splitGroup; + var propertiesOfTheGroup = propertiesToMap.Where(p => modelInspector.IsTablePerClassSplit(type, groupId, p)).ToList(); + IJoinMapper joinMapper; + if (propertiesOfTheGroup.Count > 0 && classMapper.JoinMappers.TryGetValue(groupId, out joinMapper)) + { + MapProperties(type, propertiesOfTheGroup, joinMapper); + propertiesInSplits.UnionWith(propertiesOfTheGroup); + } + } + + MapProperties(type, propertiesToMap.Except(propertiesInSplits), classMapper); + InvokeAfterMapSubclass(type, classMapper); - - MapProperties(type, propertiesToMap, classMapper); } private void MapJoinedSubclass(System.Type type, HbmMapping mapping) Modified: trunk/nhibernate/src/NHibernate.Test/MappingByCode/ExpliticMappingTests/SubclassPropertiesSplitsTests.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Test/MappingByCode/ExpliticMappingTests/SubclassPropertiesSplitsTests.cs 2011-04-05 18:28:43 UTC (rev 5613) +++ trunk/nhibernate/src/NHibernate.Test/MappingByCode/ExpliticMappingTests/SubclassPropertiesSplitsTests.cs 2011-04-05 18:52:02 UTC (rev 5614) @@ -75,5 +75,35 @@ inspector.IsTablePerClassSplit(typeof(MyClass), "MyClassSplit2", For<Inherited>.Property(x => x.SomethingB2)).Should().Be.True(); } + [Test] + public void WhenMapSplittedPropertiesThenEachPropertyIsInItsSplitGroup() + { + var inspector = new ExplicitlyDeclaredModel(); + var mapper = new ModelMapper(inspector); + mapper.Class<MyClass>(map => map.Id(x => x.Id, idmap => { })); + mapper.Subclass<Inherited>(map => + { + map.Join("MyClassSplit1", mj => + { + mj.Property(x => x.SomethingA1); + mj.Property(x => x.SomethingA2); + }); + map.Join("MyClassSplit2", mj => + { + mj.Property(x => x.SomethingB1); + mj.Property(x => x.SomethingB2); + }); + map.Property(x => x.Something0); + }); + var hbmDoc = mapper.CompileMappingFor(new[] { typeof(Inherited) }); + + var hbmClass = hbmDoc.SubClasses[0]; + hbmClass.Joins.Select(j => j.table).Should().Have.SameValuesAs("MyClassSplit1", "MyClassSplit2"); + hbmClass.Properties.Single().Name.Should().Be("Something0"); + var hbmSplit1 = hbmClass.Joins.Single(j => "MyClassSplit1" == j.table); + hbmSplit1.Properties.Select(p => p.Name).Should().Have.SameValuesAs("SomethingA1", "SomethingA2"); + var hbmSplit2 = hbmClass.Joins.Single(j => "MyClassSplit2" == j.table); + hbmSplit2.Properties.Select(p => p.Name).Should().Have.SameValuesAs("SomethingB1", "SomethingB2"); + } } } \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fab...@us...> - 2011-04-05 18:28:49
|
Revision: 5613 http://nhibernate.svn.sourceforge.net/nhibernate/?rev=5613&view=rev Author: fabiomaulo Date: 2011-04-05 18:28:43 +0000 (Tue, 05 Apr 2011) Log Message: ----------- registration/execution of Join customizers for Subclass Modified Paths: -------------- trunk/nhibernate/src/NHibernate/Mapping/ByCode/ISubclassMapper.cs trunk/nhibernate/src/NHibernate/Mapping/ByCode/Impl/CustomizersHolder.cs trunk/nhibernate/src/NHibernate/Mapping/ByCode/Impl/CustomizersImpl/SubclassCustomizer.cs trunk/nhibernate/src/NHibernate/Mapping/ByCode/Impl/ICustomizersHolder.cs trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj Added Paths: ----------- trunk/nhibernate/src/NHibernate.Test/MappingByCode/ExpliticMappingTests/SubclassPropertiesSplitsTests.cs Modified: trunk/nhibernate/src/NHibernate/Mapping/ByCode/ISubclassMapper.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Mapping/ByCode/ISubclassMapper.cs 2011-04-05 17:48:10 UTC (rev 5612) +++ trunk/nhibernate/src/NHibernate/Mapping/ByCode/ISubclassMapper.cs 2011-04-05 18:28:43 UTC (rev 5613) @@ -20,5 +20,6 @@ public interface ISubclassMapper<TEntity> : ISubclassAttributesMapper<TEntity>, IPropertyContainerMapper<TEntity> where TEntity : class { + void Join(string splitGroupId, Action<IJoinMapper<TEntity>> splittedMapping); } } \ No newline at end of file Modified: trunk/nhibernate/src/NHibernate/Mapping/ByCode/Impl/CustomizersHolder.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Mapping/ByCode/Impl/CustomizersHolder.cs 2011-04-05 17:48:10 UTC (rev 5612) +++ trunk/nhibernate/src/NHibernate/Mapping/ByCode/Impl/CustomizersHolder.cs 2011-04-05 18:28:43 UTC (rev 5613) @@ -59,8 +59,8 @@ private readonly Dictionary<PropertyPath, List<Action<ISetPropertiesMapper>>> setCustomizers = new Dictionary<PropertyPath, List<Action<ISetPropertiesMapper>>>(); - private readonly Dictionary<System.Type, List<Action<ISubclassAttributesMapper>>> subclassCustomizers = - new Dictionary<System.Type, List<Action<ISubclassAttributesMapper>>>(); + private readonly Dictionary<System.Type, List<Action<ISubclassMapper>>> subclassCustomizers = + new Dictionary<System.Type, List<Action<ISubclassMapper>>>(); private readonly Dictionary<System.Type, List<Action<IUnionSubclassAttributesMapper>>> unionClassCustomizers = new Dictionary<System.Type, List<Action<IUnionSubclassAttributesMapper>>>(); @@ -75,7 +75,7 @@ AddCustomizer(rootClassCustomizers, type, classCustomizer); } - public void AddCustomizer(System.Type type, Action<ISubclassAttributesMapper> classCustomizer) + public void AddCustomizer(System.Type type, Action<ISubclassMapper> classCustomizer) { AddCustomizer(subclassCustomizers, type, classCustomizer); } @@ -180,7 +180,7 @@ InvokeCustomizers(rootClassCustomizers, type, mapper); } - public void InvokeCustomizers(System.Type type, ISubclassAttributesMapper mapper) + public void InvokeCustomizers(System.Type type, ISubclassMapper mapper) { InvokeCustomizers(subclassCustomizers, type, mapper); } Modified: trunk/nhibernate/src/NHibernate/Mapping/ByCode/Impl/CustomizersImpl/SubclassCustomizer.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Mapping/ByCode/Impl/CustomizersImpl/SubclassCustomizer.cs 2011-04-05 17:48:10 UTC (rev 5612) +++ trunk/nhibernate/src/NHibernate/Mapping/ByCode/Impl/CustomizersImpl/SubclassCustomizer.cs 2011-04-05 18:28:43 UTC (rev 5613) @@ -1,10 +1,13 @@ using System; +using System.Collections.Generic; using NHibernate.Persister.Entity; namespace NHibernate.Mapping.ByCode.Impl.CustomizersImpl { public class SubclassCustomizer<TEntity> : PropertyContainerCustomizer<TEntity>, ISubclassMapper<TEntity> where TEntity : class { + private Dictionary<string, IJoinMapper<TEntity>> joinCustomizers; + public SubclassCustomizer(IModelExplicitDeclarationsHolder explicitDeclarationsHolder, ICustomizersHolder customizersHolder) : base(explicitDeclarationsHolder, customizersHolder, null) { @@ -19,51 +22,70 @@ public void DiscriminatorValue(object value) { - CustomizersHolder.AddCustomizer(typeof (TEntity), (ISubclassAttributesMapper m) => m.DiscriminatorValue(value)); + CustomizersHolder.AddCustomizer(typeof (TEntity), (ISubclassMapper m) => m.DiscriminatorValue(value)); } #endregion + private Dictionary<string, IJoinMapper<TEntity>> JoinCustomizers + { + get { return joinCustomizers ?? (joinCustomizers = new Dictionary<string, IJoinMapper<TEntity>>()); } + } + + public void Join(string splitGroupId, Action<IJoinMapper<TEntity>> splittedMapping) + { + // add the customizer only to ensure the creation of the JoinMapper instance for the group + CustomizersHolder.AddCustomizer(typeof(TEntity), (ISubclassMapper m) => m.Join(splitGroupId, j => { })); + + IJoinMapper<TEntity> joinCustomizer; + if (!JoinCustomizers.TryGetValue(splitGroupId, out joinCustomizer)) + { + joinCustomizer = new JoinCustomizer<TEntity>(splitGroupId, ExplicitDeclarationsHolder, CustomizersHolder); + JoinCustomizers.Add(splitGroupId, joinCustomizer); + } + splittedMapping(joinCustomizer); + } + #region Implementation of IEntityAttributesMapper public void EntityName(string value) { - CustomizersHolder.AddCustomizer(typeof (TEntity), (ISubclassAttributesMapper m) => m.EntityName(value)); + CustomizersHolder.AddCustomizer(typeof (TEntity), (ISubclassMapper m) => m.EntityName(value)); } public void Proxy(System.Type proxy) { - CustomizersHolder.AddCustomizer(typeof (TEntity), (ISubclassAttributesMapper m) => m.Proxy(proxy)); + CustomizersHolder.AddCustomizer(typeof (TEntity), (ISubclassMapper m) => m.Proxy(proxy)); } public void Lazy(bool value) { - CustomizersHolder.AddCustomizer(typeof (TEntity), (ISubclassAttributesMapper m) => m.Lazy(value)); + CustomizersHolder.AddCustomizer(typeof (TEntity), (ISubclassMapper m) => m.Lazy(value)); } public void DynamicUpdate(bool value) { - CustomizersHolder.AddCustomizer(typeof (TEntity), (ISubclassAttributesMapper m) => m.DynamicUpdate(value)); + CustomizersHolder.AddCustomizer(typeof (TEntity), (ISubclassMapper m) => m.DynamicUpdate(value)); } public void DynamicInsert(bool value) { - CustomizersHolder.AddCustomizer(typeof (TEntity), (ISubclassAttributesMapper m) => m.DynamicInsert(value)); + CustomizersHolder.AddCustomizer(typeof (TEntity), (ISubclassMapper m) => m.DynamicInsert(value)); } public void BatchSize(int value) { - CustomizersHolder.AddCustomizer(typeof (TEntity), (ISubclassAttributesMapper m) => m.BatchSize(value)); + CustomizersHolder.AddCustomizer(typeof (TEntity), (ISubclassMapper m) => m.BatchSize(value)); } public void SelectBeforeUpdate(bool value) { - CustomizersHolder.AddCustomizer(typeof (TEntity), (ISubclassAttributesMapper m) => m.SelectBeforeUpdate(value)); + CustomizersHolder.AddCustomizer(typeof (TEntity), (ISubclassMapper m) => m.SelectBeforeUpdate(value)); } public void Persister<T>() where T : IEntityPersister { - CustomizersHolder.AddCustomizer(typeof (TEntity), (ISubclassAttributesMapper m) => m.Persister<T>()); + CustomizersHolder.AddCustomizer(typeof (TEntity), (ISubclassMapper m) => m.Persister<T>()); } #endregion @@ -72,27 +94,27 @@ public void Loader(string namedQueryReference) { - CustomizersHolder.AddCustomizer(typeof (TEntity), (ISubclassAttributesMapper m) => m.Loader(namedQueryReference)); + CustomizersHolder.AddCustomizer(typeof (TEntity), (ISubclassMapper m) => m.Loader(namedQueryReference)); } public void SqlInsert(string sql) { - CustomizersHolder.AddCustomizer(typeof (TEntity), (ISubclassAttributesMapper m) => m.SqlInsert(sql)); + CustomizersHolder.AddCustomizer(typeof (TEntity), (ISubclassMapper m) => m.SqlInsert(sql)); } public void SqlUpdate(string sql) { - CustomizersHolder.AddCustomizer(typeof (TEntity), (ISubclassAttributesMapper m) => m.SqlUpdate(sql)); + CustomizersHolder.AddCustomizer(typeof (TEntity), (ISubclassMapper m) => m.SqlUpdate(sql)); } public void SqlDelete(string sql) { - CustomizersHolder.AddCustomizer(typeof (TEntity), (ISubclassAttributesMapper m) => m.SqlDelete(sql)); + CustomizersHolder.AddCustomizer(typeof (TEntity), (ISubclassMapper m) => m.SqlDelete(sql)); } public void Subselect(string sql) { - CustomizersHolder.AddCustomizer(typeof (TEntity), (ISubclassAttributesMapper m) => m.Subselect(sql)); + CustomizersHolder.AddCustomizer(typeof (TEntity), (ISubclassMapper m) => m.Subselect(sql)); } #endregion Modified: trunk/nhibernate/src/NHibernate/Mapping/ByCode/Impl/ICustomizersHolder.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Mapping/ByCode/Impl/ICustomizersHolder.cs 2011-04-05 17:48:10 UTC (rev 5612) +++ trunk/nhibernate/src/NHibernate/Mapping/ByCode/Impl/ICustomizersHolder.cs 2011-04-05 18:28:43 UTC (rev 5613) @@ -5,7 +5,7 @@ public interface ICustomizersHolder { void AddCustomizer(System.Type type, Action<IClassMapper> classCustomizer); - void AddCustomizer(System.Type type, Action<ISubclassAttributesMapper> classCustomizer); + void AddCustomizer(System.Type type, Action<ISubclassMapper> classCustomizer); void AddCustomizer(System.Type type, Action<IJoinedSubclassAttributesMapper> classCustomizer); void AddCustomizer(System.Type type, Action<IUnionSubclassAttributesMapper> classCustomizer); void AddCustomizer(System.Type type, Action<IComponentAttributesMapper> classCustomizer); @@ -24,7 +24,7 @@ void AddCustomizer(PropertyPath member, Action<IComponentAttributesMapper> propertyCustomizer); void InvokeCustomizers(System.Type type, IClassMapper mapper); - void InvokeCustomizers(System.Type type, ISubclassAttributesMapper mapper); + void InvokeCustomizers(System.Type type, ISubclassMapper mapper); void InvokeCustomizers(System.Type type, IJoinedSubclassAttributesMapper mapper); void InvokeCustomizers(System.Type type, IUnionSubclassAttributesMapper mapper); void InvokeCustomizers(System.Type type, IComponentAttributesMapper mapper); Added: trunk/nhibernate/src/NHibernate.Test/MappingByCode/ExpliticMappingTests/SubclassPropertiesSplitsTests.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Test/MappingByCode/ExpliticMappingTests/SubclassPropertiesSplitsTests.cs (rev 0) +++ trunk/nhibernate/src/NHibernate.Test/MappingByCode/ExpliticMappingTests/SubclassPropertiesSplitsTests.cs 2011-04-05 18:28:43 UTC (rev 5613) @@ -0,0 +1,79 @@ +using System.Collections.Generic; +using System.Linq; +using NHibernate.Mapping.ByCode; +using NUnit.Framework; +using SharpTestsEx; + +namespace NHibernate.Test.MappingByCode.ExpliticMappingTests +{ + public class SubclassPropertiesSplitsTests + { + private class MyClass + { + public int Id { get; set; } + } + + private class Inherited : MyClass + { + public string Something0 { get; set; } + public string SomethingA1 { get; set; } + public string SomethingA2 { get; set; } + public string SomethingB1 { get; set; } + public string SomethingB2 { get; set; } + } + + [Test] + public void WhenSplittedPropertiesThenRegisterSplitGroupIds() + { + var inspector = new ExplicitlyDeclaredModel(); + var mapper = new ModelMapper(inspector); + mapper.Subclass<Inherited>(map => + { + map.Join("MyClassSplit1", mj => + { + mj.Property(x => x.SomethingA1); + mj.Property(x => x.SomethingA2); + }); + map.Join("MyClassSplit2", mj => + { + mj.Property(x => x.SomethingB1); + mj.Property(x => x.SomethingB2); + }); + map.Property(x => x.Something0); + }); + + IEnumerable<string> tablePerClassSplits = inspector.GetPropertiesSplits(typeof(Inherited)); + tablePerClassSplits.Should().Have.SameValuesAs("MyClassSplit1", "MyClassSplit2"); + } + + [Test] + public void WhenSplittedPropertiesThenRegister() + { + var inspector = new ExplicitlyDeclaredModel(); + var mapper = new ModelMapper(inspector); + mapper.Subclass<Inherited>(map => + { + map.Join("MyClassSplit1", mj => + { + mj.Property(x => x.SomethingA1); + mj.Property(x => x.SomethingA2); + }); + map.Join("MyClassSplit2", mj => + { + mj.Property(x => x.SomethingB1); + mj.Property(x => x.SomethingB2); + }); + map.Property(x => x.Something0); + }); + + inspector.IsTablePerClassSplit(typeof(MyClass), "MyClassSplit1", For<Inherited>.Property(x => x.Something0)).Should().Be.False(); + inspector.IsTablePerClassSplit(typeof(MyClass), "MyClassSplit2", For<Inherited>.Property(x => x.Something0)).Should().Be.False(); + + inspector.IsTablePerClassSplit(typeof(MyClass), "MyClassSplit1", For<Inherited>.Property(x => x.SomethingA1)).Should().Be.True(); + inspector.IsTablePerClassSplit(typeof(MyClass), "MyClassSplit1", For<Inherited>.Property(x => x.SomethingA2)).Should().Be.True(); + inspector.IsTablePerClassSplit(typeof(MyClass), "MyClassSplit2", For<Inherited>.Property(x => x.SomethingB1)).Should().Be.True(); + inspector.IsTablePerClassSplit(typeof(MyClass), "MyClassSplit2", For<Inherited>.Property(x => x.SomethingB2)).Should().Be.True(); + } + + } +} \ No newline at end of file Modified: trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2011-04-05 17:48:10 UTC (rev 5612) +++ trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2011-04-05 18:28:43 UTC (rev 5613) @@ -523,6 +523,7 @@ <Compile Include="MappingByCode\ExpliticMappingTests\NaturalIdTests.cs" /> <Compile Include="MappingByCode\ExpliticMappingTests\PoidTests.cs" /> <Compile Include="MappingByCode\ExpliticMappingTests\RootClassPropertiesSplitsTests.cs" /> + <Compile Include="MappingByCode\ExpliticMappingTests\SubclassPropertiesSplitsTests.cs" /> <Compile Include="MappingByCode\ExpliticMappingTests\VersionTests.cs" /> <Compile Include="MappingByCode\For.cs" /> <Compile Include="MappingByCode\MappersTests\AbstractPropertyContainerMapperTest.cs" /> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fab...@us...> - 2011-04-05 17:48:16
|
Revision: 5612 http://nhibernate.svn.sourceforge.net/nhibernate/?rev=5612&view=rev Author: fabiomaulo Date: 2011-04-05 17:48:10 +0000 (Tue, 05 Apr 2011) Log Message: ----------- SubclassMapper with Joins Modified Paths: -------------- trunk/nhibernate/src/NHibernate/Mapping/ByCode/ISubclassMapper.cs trunk/nhibernate/src/NHibernate/Mapping/ByCode/Impl/SubclassMapper.cs trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj Added Paths: ----------- trunk/nhibernate/src/NHibernate.Test/MappingByCode/MappersTests/SubclassMapperWithJoinPropertiesTest.cs Modified: trunk/nhibernate/src/NHibernate/Mapping/ByCode/ISubclassMapper.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Mapping/ByCode/ISubclassMapper.cs 2011-04-05 17:26:13 UTC (rev 5611) +++ trunk/nhibernate/src/NHibernate/Mapping/ByCode/ISubclassMapper.cs 2011-04-05 17:48:10 UTC (rev 5612) @@ -1,3 +1,5 @@ +using System; + namespace NHibernate.Mapping.ByCode { public interface ISubclassAttributesMapper : IEntityAttributesMapper, IEntitySqlsMapper @@ -6,12 +8,17 @@ void Extends(System.Type baseType); } - public interface ISubclassMapper : ISubclassAttributesMapper, IPropertyContainerMapper {} + public interface ISubclassMapper : ISubclassAttributesMapper, IPropertyContainerMapper + { + void Join(string splitGroupId, Action<IJoinMapper> splittedMapping); + } public interface ISubclassAttributesMapper<TEntity> : IEntityAttributesMapper, IEntitySqlsMapper where TEntity : class { void DiscriminatorValue(object value); } - public interface ISubclassMapper<TEntity> : ISubclassAttributesMapper<TEntity>, IPropertyContainerMapper<TEntity> where TEntity : class {} + public interface ISubclassMapper<TEntity> : ISubclassAttributesMapper<TEntity>, IPropertyContainerMapper<TEntity> where TEntity : class + { + } } \ No newline at end of file Modified: trunk/nhibernate/src/NHibernate/Mapping/ByCode/Impl/SubclassMapper.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Mapping/ByCode/Impl/SubclassMapper.cs 2011-04-05 17:26:13 UTC (rev 5611) +++ trunk/nhibernate/src/NHibernate/Mapping/ByCode/Impl/SubclassMapper.cs 2011-04-05 17:48:10 UTC (rev 5612) @@ -1,4 +1,5 @@ using System; +using System.Collections.Generic; using System.Linq; using NHibernate.Cfg.MappingSchema; using NHibernate.Persister.Entity; @@ -8,6 +9,7 @@ public class SubclassMapper : AbstractPropertyContainerMapper, ISubclassMapper { private readonly HbmSubclass classMapping = new HbmSubclass(); + private Dictionary<string, IJoinMapper> joinMappers; public SubclassMapper(System.Type subClass, HbmMapping mapDoc) : base(subClass, mapDoc) { @@ -31,6 +33,11 @@ #endregion + private Dictionary<string, IJoinMapper> JoinMappers + { + get { return joinMappers ?? (joinMappers = new Dictionary<string, IJoinMapper>()); } + } + #region ISubclassMapper Members public void DiscriminatorValue(object value) @@ -52,6 +59,21 @@ classMapping.extends = baseType.GetShortClassName(MapDoc); } + public void Join(string splitGroupId, Action<IJoinMapper> splittedMapping) + { + IJoinMapper splitGroup; + if (!JoinMappers.TryGetValue(splitGroupId, out splitGroup)) + { + var hbmJoin = new HbmJoin(); + splitGroup = new JoinMapper(Container, splitGroupId, hbmJoin, MapDoc); + var toAdd = new[] { hbmJoin }; + JoinMappers.Add(splitGroupId, splitGroup); + classMapping.join = classMapping.join == null ? toAdd : classMapping.join.Concat(toAdd).ToArray(); + } + + splittedMapping(splitGroup); + } + #endregion #region Implementation of IEntityAttributesMapper Added: trunk/nhibernate/src/NHibernate.Test/MappingByCode/MappersTests/SubclassMapperWithJoinPropertiesTest.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Test/MappingByCode/MappersTests/SubclassMapperWithJoinPropertiesTest.cs (rev 0) +++ trunk/nhibernate/src/NHibernate.Test/MappingByCode/MappersTests/SubclassMapperWithJoinPropertiesTest.cs 2011-04-05 17:48:10 UTC (rev 5612) @@ -0,0 +1,81 @@ +using System.Linq; +using NHibernate.Cfg.MappingSchema; +using NHibernate.Mapping.ByCode; +using NHibernate.Mapping.ByCode.Impl; +using NUnit.Framework; +using SharpTestsEx; + +namespace NHibernate.Test.MappingByCode.MappersTests +{ + public class SubclassMapperWithJoinPropertiesTest + { + private class MyClass + { + public int Id { get; set; } + } + + private class Inherited : MyClass + { + } + + [Test] + public void WhenDefineJoinThenAddJoinWithTableNameAndKey() + { + var mapdoc = new HbmMapping(); + var mapper = new SubclassMapper(typeof(Inherited), mapdoc); + + mapper.Join("MyTable", x => { }); + + var hbmClass = mapdoc.SubClasses[0]; + var hbmJoin = hbmClass.Joins.Single(); + hbmJoin.table.Should().Be("MyTable"); + hbmJoin.key.Should().Not.Be.Null(); + hbmJoin.key.column1.Should().Not.Be.Null(); + } + + [Test] + public void WhenDefineJoinThenCallJoinMapper() + { + var mapdoc = new HbmMapping(); + var mapper = new SubclassMapper(typeof(Inherited), mapdoc); + var called = false; + mapper.Join("MyTable", x => + { + x.Should().Not.Be.Null(); + called = true; + }); + + called.Should().Be.True(); + } + + [Test] + public void WhenDefineMoreJoinsThenTableNameShouldBeUnique() + { + var mapdoc = new HbmMapping(); + var mapper = new SubclassMapper(typeof(Inherited), mapdoc); + + mapper.Join("T1", x => { }); + mapper.Join("T2", x => { }); + + var hbmClass = mapdoc.SubClasses[0]; + hbmClass.Joins.Should().Have.Count.EqualTo(2); + hbmClass.Joins.Select(x => x.table).Should().Have.UniqueValues(); + } + + [Test] + public void WhenDefineMoreJoinsWithSameIdThenUseSameJoinMapperInstance() + { + var mapdoc = new HbmMapping(); + var mapper = new SubclassMapper(typeof(Inherited), mapdoc); + IJoinMapper firstCallInstance = null; + IJoinMapper secondCallInstance = null; + + mapper.Join("T1", x => firstCallInstance = x); + mapper.Join("T1", x => secondCallInstance = x); + + firstCallInstance.Should().Be.SameInstanceAs(secondCallInstance); + var hbmClass = mapdoc.SubClasses[0]; + hbmClass.Joins.Should().Have.Count.EqualTo(1); + } + } +} \ No newline at end of file Modified: trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2011-04-05 17:26:13 UTC (rev 5611) +++ trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2011-04-05 17:48:10 UTC (rev 5612) @@ -528,6 +528,7 @@ <Compile Include="MappingByCode\MappersTests\AbstractPropertyContainerMapperTest.cs" /> <Compile Include="MappingByCode\MappersTests\ClassMapperWithJoinPropertiesTest.cs" /> <Compile Include="MappingByCode\MappersTests\JoinMapperTests.cs" /> + <Compile Include="MappingByCode\MappersTests\SubclassMapperWithJoinPropertiesTest.cs" /> <Compile Include="MappingByCode\NatureDemo\Naturalness\Address.cs" /> <Compile Include="MappingByCode\NatureDemo\Naturalness\Animal.cs" /> <Compile Include="MappingByCode\NatureDemo\Naturalness\Classification.cs" /> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fab...@us...> - 2011-04-05 17:26:21
|
Revision: 5611 http://nhibernate.svn.sourceforge.net/nhibernate/?rev=5611&view=rev Author: fabiomaulo Date: 2011-04-05 17:26:13 +0000 (Tue, 05 Apr 2011) Log Message: ----------- ClassCustomizer with Joins Modified Paths: -------------- trunk/nhibernate/src/NHibernate/Mapping/ByCode/ExplicitlyDeclaredModel.cs trunk/nhibernate/src/NHibernate/Mapping/ByCode/FakeModelExplicitDeclarationsHolder.cs trunk/nhibernate/src/NHibernate/Mapping/ByCode/IJoinMapper.cs trunk/nhibernate/src/NHibernate/Mapping/ByCode/IModelExplicitDeclarationsHolder.cs trunk/nhibernate/src/NHibernate/Mapping/ByCode/Impl/ClassMapper.cs trunk/nhibernate/src/NHibernate/Mapping/ByCode/Impl/CustomizersHolder.cs trunk/nhibernate/src/NHibernate/Mapping/ByCode/Impl/CustomizersImpl/ClassCustomizer.cs trunk/nhibernate/src/NHibernate/Mapping/ByCode/Impl/CustomizersImpl/PropertyContainerCustomizer.cs trunk/nhibernate/src/NHibernate/Mapping/ByCode/Impl/ICustomizersHolder.cs trunk/nhibernate/src/NHibernate/Mapping/ByCode/ModelMapper.cs trunk/nhibernate/src/NHibernate/NHibernate.csproj trunk/nhibernate/src/NHibernate.Test/MappingByCode/ExpliticMappingTests/RootClassPropertiesSplitsTests.cs trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj Added Paths: ----------- trunk/nhibernate/src/NHibernate/Mapping/ByCode/Impl/CustomizersImpl/JoinCustomizer.cs trunk/nhibernate/src/NHibernate/Mapping/ByCode/Impl/CustomizersImpl/JoinKeyCustomizer.cs trunk/nhibernate/src/NHibernate.Test/MappingByCode/ExplicitlyDeclaredModelTests/SplitPropertiesRegistrationTests.cs Modified: trunk/nhibernate/src/NHibernate/Mapping/ByCode/ExplicitlyDeclaredModel.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Mapping/ByCode/ExplicitlyDeclaredModel.cs 2011-04-05 01:28:51 UTC (rev 5610) +++ trunk/nhibernate/src/NHibernate/Mapping/ByCode/ExplicitlyDeclaredModel.cs 2011-04-05 17:26:13 UTC (rev 5611) @@ -29,6 +29,8 @@ private readonly HashSet<System.Type> tablePerConcreteClassEntities = new HashSet<System.Type>(); private readonly HashSet<MemberInfo> versionProperties = new HashSet<MemberInfo>(); private readonly Dictionary<System.Type, Action<System.Type>> delayedEntityRegistrations = new Dictionary<System.Type, Action<System.Type>>(); + private readonly Dictionary<System.Type, HashSet<string>> typeSplitGroups = new Dictionary<System.Type, HashSet<string>>(); + private readonly Dictionary<MemberInfo, string> memberSplitGroup = new Dictionary<MemberInfo, string>(); #region IModelExplicitDeclarationsHolder Members @@ -132,6 +134,27 @@ get { return properties; } } + public IEnumerable<string> GetSplitGroupsFor(System.Type type) + { + HashSet<string> splitsGroupsIds; + if (typeSplitGroups.TryGetValue(type, out splitsGroupsIds)) + { + return splitsGroupsIds; + } + return Enumerable.Empty<string>(); + } + + public string GetSplitGroupFor(MemberInfo member) + { + var memberKey = member.GetMemberFromDeclaringType(); + string splitGroup; + if (memberSplitGroup.TryGetValue(memberKey, out splitGroup)) + { + return splitGroup; + } + return null; + } + public void AddAsRootEntity(System.Type type) { if (IsComponent(type)) @@ -343,6 +366,32 @@ properties.Add(member); } + public void AddAsPropertySplit(System.Type propertyContainer, string splitGroupId, MemberInfo member) + { + /* Note: if the user "jump/exclude" a class and then map the property in two subclasses the usage of GetMemberFromDeclaringType() may cause a problem + for a legal usage... we will see when the case happen */ + + var memberKey = member.GetMemberFromDeclaringType(); + string splitGroup; + if (!memberSplitGroup.TryGetValue(memberKey, out splitGroup)) + { + AddTypeSplits(propertyContainer, splitGroupId); + memberSplitGroup[memberKey] = splitGroupId; + } + } + + private void AddTypeSplits(System.Type propertyContainer, string splitGroupId) + { + HashSet<string> splitsGroupsIds; + typeSplitGroups.TryGetValue(propertyContainer, out splitsGroupsIds); + if(splitsGroupsIds == null) + { + splitsGroupsIds = new HashSet<string>(); + typeSplitGroups[propertyContainer] = splitsGroupsIds; + } + splitsGroupsIds.Add(splitGroupId); + } + #endregion #region Implementation of IModelInspector @@ -370,7 +419,7 @@ public bool IsTablePerClassSplit(System.Type type, object splitGroupId, MemberInfo member) { - return false; + return Equals(splitGroupId, GetSplitGroupFor(member)); } public bool IsTablePerClassHierarchy(System.Type type) @@ -518,7 +567,7 @@ public IEnumerable<string> GetPropertiesSplits(System.Type type) { - return null; + return GetSplitGroupsFor(type); } } } \ No newline at end of file Modified: trunk/nhibernate/src/NHibernate/Mapping/ByCode/FakeModelExplicitDeclarationsHolder.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Mapping/ByCode/FakeModelExplicitDeclarationsHolder.cs 2011-04-05 01:28:51 UTC (rev 5610) +++ trunk/nhibernate/src/NHibernate/Mapping/ByCode/FakeModelExplicitDeclarationsHolder.cs 2011-04-05 17:26:13 UTC (rev 5611) @@ -1,3 +1,4 @@ +using System; using System.Collections.Generic; using System.Linq; using System.Reflection; @@ -135,6 +136,16 @@ get { return properties; } } + public IEnumerable<string> GetSplitGroupsFor(System.Type type) + { + return Enumerable.Empty<string>(); + } + + public string GetSplitGroupFor(MemberInfo member) + { + return null; + } + public void AddAsRootEntity(System.Type type) {} public void AddAsComponent(System.Type type) {} @@ -176,6 +187,7 @@ public void AddAsMap(MemberInfo member) {} public void AddAsProperty(MemberInfo member) {} + public void AddAsPropertySplit(System.Type propertyContainer, string splitGroupId, MemberInfo member) {} #endregion } Modified: trunk/nhibernate/src/NHibernate/Mapping/ByCode/IJoinMapper.cs =================================================================== (Binary files differ) Modified: trunk/nhibernate/src/NHibernate/Mapping/ByCode/IModelExplicitDeclarationsHolder.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Mapping/ByCode/IModelExplicitDeclarationsHolder.cs 2011-04-05 01:28:51 UTC (rev 5610) +++ trunk/nhibernate/src/NHibernate/Mapping/ByCode/IModelExplicitDeclarationsHolder.cs 2011-04-05 17:26:13 UTC (rev 5611) @@ -28,6 +28,8 @@ IEnumerable<MemberInfo> Arrays { get; } IEnumerable<MemberInfo> Dictionaries { get; } IEnumerable<MemberInfo> Properties { get; } + IEnumerable<string> GetSplitGroupsFor(System.Type type); + string GetSplitGroupFor(MemberInfo member); void AddAsRootEntity(System.Type type); void AddAsComponent(System.Type type); @@ -52,5 +54,6 @@ void AddAsArray(MemberInfo member); void AddAsMap(MemberInfo member); void AddAsProperty(MemberInfo member); + void AddAsPropertySplit(System.Type propertyContainer, string splitGroupId, MemberInfo member); } } \ No newline at end of file Modified: trunk/nhibernate/src/NHibernate/Mapping/ByCode/Impl/ClassMapper.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Mapping/ByCode/Impl/ClassMapper.cs 2011-04-05 01:28:51 UTC (rev 5610) +++ trunk/nhibernate/src/NHibernate/Mapping/ByCode/Impl/ClassMapper.cs 2011-04-05 17:26:13 UTC (rev 5611) @@ -50,7 +50,7 @@ #endregion - private Dictionary<string, IJoinMapper> JoinMappers + public Dictionary<string, IJoinMapper> JoinMappers { get { return joinMappers ?? (joinMappers = new Dictionary<string, IJoinMapper>()); } } Modified: trunk/nhibernate/src/NHibernate/Mapping/ByCode/Impl/CustomizersHolder.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Mapping/ByCode/Impl/CustomizersHolder.cs 2011-04-05 01:28:51 UTC (rev 5610) +++ trunk/nhibernate/src/NHibernate/Mapping/ByCode/Impl/CustomizersHolder.cs 2011-04-05 17:26:13 UTC (rev 5611) @@ -53,8 +53,8 @@ private readonly Dictionary<PropertyPath, List<Action<IPropertyMapper>>> propertyCustomizers = new Dictionary<PropertyPath, List<Action<IPropertyMapper>>>(); - private readonly Dictionary<System.Type, List<Action<IClassAttributesMapper>>> rootClassCustomizers = - new Dictionary<System.Type, List<Action<IClassAttributesMapper>>>(); + private readonly Dictionary<System.Type, List<Action<IClassMapper>>> rootClassCustomizers = + new Dictionary<System.Type, List<Action<IClassMapper>>>(); private readonly Dictionary<PropertyPath, List<Action<ISetPropertiesMapper>>> setCustomizers = new Dictionary<PropertyPath, List<Action<ISetPropertiesMapper>>>(); @@ -65,9 +65,12 @@ private readonly Dictionary<System.Type, List<Action<IUnionSubclassAttributesMapper>>> unionClassCustomizers = new Dictionary<System.Type, List<Action<IUnionSubclassAttributesMapper>>>(); + private readonly Dictionary<System.Type, List<Action<IJoinAttributesMapper>>> joinCustomizers = + new Dictionary<System.Type, List<Action<IJoinAttributesMapper>>>(); + #region ICustomizersHolder Members - public void AddCustomizer(System.Type type, Action<IClassAttributesMapper> classCustomizer) + public void AddCustomizer(System.Type type, Action<IClassMapper> classCustomizer) { AddCustomizer(rootClassCustomizers, type, classCustomizer); } @@ -92,6 +95,11 @@ AddCustomizer(componentClassCustomizers, type, classCustomizer); } + public void AddCustomizer(System.Type type, Action<IJoinAttributesMapper> joinCustomizer) + { + AddCustomizer(joinCustomizers, type, joinCustomizer); + } + public void AddCustomizer(PropertyPath member, Action<IPropertyMapper> propertyCustomizer) { AddCustomizer(propertyCustomizers, member, propertyCustomizer); @@ -167,7 +175,7 @@ AddCustomizer(mapKeyElementCustomizers, member, mapKeyElementCustomizer); } - public void InvokeCustomizers(System.Type type, IClassAttributesMapper mapper) + public void InvokeCustomizers(System.Type type, IClassMapper mapper) { InvokeCustomizers(rootClassCustomizers, type, mapper); } @@ -192,6 +200,11 @@ InvokeCustomizers(componentClassCustomizers, type, mapper); } + public void InvokeCustomizers(System.Type type, IJoinAttributesMapper mapper) + { + InvokeCustomizers(joinCustomizers, type, mapper); + } + public void InvokeCustomizers(PropertyPath member, IPropertyMapper mapper) { InvokeCustomizers(propertyCustomizers, member, mapper); Modified: trunk/nhibernate/src/NHibernate/Mapping/ByCode/Impl/CustomizersImpl/ClassCustomizer.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Mapping/ByCode/Impl/CustomizersImpl/ClassCustomizer.cs 2011-04-05 01:28:51 UTC (rev 5610) +++ trunk/nhibernate/src/NHibernate/Mapping/ByCode/Impl/CustomizersImpl/ClassCustomizer.cs 2011-04-05 17:26:13 UTC (rev 5611) @@ -1,4 +1,5 @@ using System; +using System.Collections.Generic; using System.Linq.Expressions; using System.Reflection; using NHibernate.Persister.Entity; @@ -7,6 +8,8 @@ { public class ClassCustomizer<TEntity> : PropertyContainerCustomizer<TEntity>, IClassMapper<TEntity> where TEntity : class { + private Dictionary<string, IJoinMapper<TEntity>> joinCustomizers; + public ClassCustomizer(IModelExplicitDeclarationsHolder explicitDeclarationsHolder, ICustomizersHolder customizersHolder) : base(explicitDeclarationsHolder, customizersHolder, null) { @@ -17,6 +20,11 @@ explicitDeclarationsHolder.AddAsRootEntity(typeof (TEntity)); } + private Dictionary<string, IJoinMapper<TEntity>> JoinCustomizers + { + get { return joinCustomizers ?? (joinCustomizers = new Dictionary<string, IJoinMapper<TEntity>>()); } + } + #region Implementation of IClassAttributesMapper<TEntity> public void Id(Action<IIdMapper> idMapper) @@ -39,27 +47,27 @@ public void Discriminator(Action<IDiscriminatorMapper> discriminatorMapping) { - CustomizersHolder.AddCustomizer(typeof (TEntity), (IClassAttributesMapper m) => m.Discriminator(discriminatorMapping)); + CustomizersHolder.AddCustomizer(typeof (TEntity), (IClassMapper m) => m.Discriminator(discriminatorMapping)); } public void DiscriminatorValue(object value) { - CustomizersHolder.AddCustomizer(typeof (TEntity), (IClassAttributesMapper m) => m.DiscriminatorValue(value)); + CustomizersHolder.AddCustomizer(typeof(TEntity), (IClassMapper m) => m.DiscriminatorValue(value)); } public void Table(string tableName) { - CustomizersHolder.AddCustomizer(typeof (TEntity), (IClassAttributesMapper m) => m.Table(tableName)); + CustomizersHolder.AddCustomizer(typeof(TEntity), (IClassMapper m) => m.Table(tableName)); } public void Catalog(string catalogName) { - CustomizersHolder.AddCustomizer(typeof (TEntity), (IClassAttributesMapper m) => m.Catalog(catalogName)); + CustomizersHolder.AddCustomizer(typeof(TEntity), (IClassMapper m) => m.Catalog(catalogName)); } public void Schema(string schemaName) { - CustomizersHolder.AddCustomizer(typeof (TEntity), (IClassAttributesMapper m) => m.Schema(schemaName)); + CustomizersHolder.AddCustomizer(typeof(TEntity), (IClassMapper m) => m.Schema(schemaName)); } #endregion @@ -68,20 +76,20 @@ public void Mutable(bool isMutable) { - CustomizersHolder.AddCustomizer(typeof (TEntity), (IClassAttributesMapper m) => m.Mutable(isMutable)); + CustomizersHolder.AddCustomizer(typeof(TEntity), (IClassMapper m) => m.Mutable(isMutable)); } public void Version<TProperty>(Expression<Func<TEntity, TProperty>> versionProperty, Action<IVersionMapper> versionMapping) { MemberInfo member = TypeExtensions.DecodeMemberAccessExpression(versionProperty); ExplicitDeclarationsHolder.AddAsVersionProperty(member); - CustomizersHolder.AddCustomizer(typeof (TEntity), (IClassAttributesMapper m) => m.Version(member, versionMapping)); + CustomizersHolder.AddCustomizer(typeof(TEntity), (IClassMapper m) => m.Version(member, versionMapping)); } public void NaturalId(Action<IBasePlainPropertyContainerMapper<TEntity>> naturalIdPropertiesMapping, Action<INaturalIdAttributesMapper> naturalIdMapping) { naturalIdPropertiesMapping(new NaturalIdCustomizer<TEntity>(ExplicitDeclarationsHolder, CustomizersHolder)); - CustomizersHolder.AddCustomizer(typeof(TEntity), (IClassAttributesMapper m) => m.NaturalId(nidm => naturalIdMapping(nidm))); + CustomizersHolder.AddCustomizer(typeof(TEntity), (IClassMapper m) => m.NaturalId(nidm => naturalIdMapping(nidm))); } public void NaturalId(Action<IBasePlainPropertyContainerMapper<TEntity>> naturalIdPropertiesMapping) @@ -91,67 +99,76 @@ public void Cache(Action<ICacheMapper> cacheMapping) { - CustomizersHolder.AddCustomizer(typeof (TEntity), (IClassAttributesMapper m) => m.Cache(cacheMapping)); + CustomizersHolder.AddCustomizer(typeof(TEntity), (IClassMapper m) => m.Cache(cacheMapping)); } public void Filter(string filterName, Action<IFilterMapper> filterMapping) { - CustomizersHolder.AddCustomizer(typeof (TEntity), (IClassAttributesMapper m) => m.Filter(filterName, filterMapping)); + CustomizersHolder.AddCustomizer(typeof(TEntity), (IClassMapper m) => m.Filter(filterName, filterMapping)); } public void Where(string whereClause) { - CustomizersHolder.AddCustomizer(typeof (TEntity), (IClassAttributesMapper m) => m.Where(whereClause)); + CustomizersHolder.AddCustomizer(typeof(TEntity), (IClassMapper m) => m.Where(whereClause)); } public void SchemaAction(SchemaAction action) { - CustomizersHolder.AddCustomizer(typeof (TEntity), (IClassAttributesMapper m) => m.SchemaAction(action)); + CustomizersHolder.AddCustomizer(typeof(TEntity), (IClassMapper m) => m.SchemaAction(action)); } public void Join(string splitGroupId, Action<IJoinMapper<TEntity>> splittedMapping) { - throw new NotImplementedException(); + // add the customizer only to create the JoinMapper instance + CustomizersHolder.AddCustomizer(typeof(TEntity), (IClassMapper m) => m.Join(splitGroupId, j => { })); + + IJoinMapper<TEntity> joinCustomizer; + if (!JoinCustomizers.TryGetValue(splitGroupId, out joinCustomizer)) + { + joinCustomizer = new JoinCustomizer<TEntity>(splitGroupId, ExplicitDeclarationsHolder, CustomizersHolder); + JoinCustomizers.Add(splitGroupId, joinCustomizer); + } + splittedMapping(joinCustomizer); } public void EntityName(string value) { - CustomizersHolder.AddCustomizer(typeof (TEntity), (IClassAttributesMapper m) => m.EntityName(value)); + CustomizersHolder.AddCustomizer(typeof(TEntity), (IClassMapper m) => m.EntityName(value)); } public void Proxy(System.Type proxy) { - CustomizersHolder.AddCustomizer(typeof (TEntity), (IClassAttributesMapper m) => m.Proxy(proxy)); + CustomizersHolder.AddCustomizer(typeof(TEntity), (IClassMapper m) => m.Proxy(proxy)); } public void Lazy(bool value) { - CustomizersHolder.AddCustomizer(typeof (TEntity), (IClassAttributesMapper m) => m.Lazy(value)); + CustomizersHolder.AddCustomizer(typeof(TEntity), (IClassMapper m) => m.Lazy(value)); } public void DynamicUpdate(bool value) { - CustomizersHolder.AddCustomizer(typeof (TEntity), (IClassAttributesMapper m) => m.DynamicUpdate(value)); + CustomizersHolder.AddCustomizer(typeof(TEntity), (IClassMapper m) => m.DynamicUpdate(value)); } public void DynamicInsert(bool value) { - CustomizersHolder.AddCustomizer(typeof (TEntity), (IClassAttributesMapper m) => m.DynamicInsert(value)); + CustomizersHolder.AddCustomizer(typeof(TEntity), (IClassMapper m) => m.DynamicInsert(value)); } public void BatchSize(int value) { - CustomizersHolder.AddCustomizer(typeof (TEntity), (IClassAttributesMapper m) => m.BatchSize(value)); + CustomizersHolder.AddCustomizer(typeof(TEntity), (IClassMapper m) => m.BatchSize(value)); } public void SelectBeforeUpdate(bool value) { - CustomizersHolder.AddCustomizer(typeof (TEntity), (IClassAttributesMapper m) => m.SelectBeforeUpdate(value)); + CustomizersHolder.AddCustomizer(typeof(TEntity), (IClassMapper m) => m.SelectBeforeUpdate(value)); } public void Persister<T>() where T : IEntityPersister { - CustomizersHolder.AddCustomizer(typeof (TEntity), (IClassAttributesMapper m) => m.Persister<T>()); + CustomizersHolder.AddCustomizer(typeof(TEntity), (IClassMapper m) => m.Persister<T>()); } #endregion @@ -160,27 +177,27 @@ public void Loader(string namedQueryReference) { - CustomizersHolder.AddCustomizer(typeof (TEntity), (IClassAttributesMapper m) => m.Loader(namedQueryReference)); + CustomizersHolder.AddCustomizer(typeof(TEntity), (IClassMapper m) => m.Loader(namedQueryReference)); } public void SqlInsert(string sql) { - CustomizersHolder.AddCustomizer(typeof (TEntity), (IClassAttributesMapper m) => m.SqlInsert(sql)); + CustomizersHolder.AddCustomizer(typeof(TEntity), (IClassMapper m) => m.SqlInsert(sql)); } public void SqlUpdate(string sql) { - CustomizersHolder.AddCustomizer(typeof (TEntity), (IClassAttributesMapper m) => m.SqlUpdate(sql)); + CustomizersHolder.AddCustomizer(typeof(TEntity), (IClassMapper m) => m.SqlUpdate(sql)); } public void SqlDelete(string sql) { - CustomizersHolder.AddCustomizer(typeof (TEntity), (IClassAttributesMapper m) => m.SqlDelete(sql)); + CustomizersHolder.AddCustomizer(typeof(TEntity), (IClassMapper m) => m.SqlDelete(sql)); } public void Subselect(string sql) { - CustomizersHolder.AddCustomizer(typeof (TEntity), (IClassAttributesMapper m) => m.Subselect(sql)); + CustomizersHolder.AddCustomizer(typeof(TEntity), (IClassMapper m) => m.Subselect(sql)); } #endregion Added: trunk/nhibernate/src/NHibernate/Mapping/ByCode/Impl/CustomizersImpl/JoinCustomizer.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Mapping/ByCode/Impl/CustomizersImpl/JoinCustomizer.cs (rev 0) +++ trunk/nhibernate/src/NHibernate/Mapping/ByCode/Impl/CustomizersImpl/JoinCustomizer.cs 2011-04-05 17:26:13 UTC (rev 5611) @@ -0,0 +1,168 @@ +using System; +using System.Collections.Generic; +using System.Linq.Expressions; +using System.Reflection; + +namespace NHibernate.Mapping.ByCode.Impl.CustomizersImpl +{ + public class JoinCustomizer<TEntity> : PropertyContainerCustomizer<TEntity>, IJoinMapper<TEntity> + where TEntity : class + { + private readonly string splitGroupId; + private readonly IKeyMapper<TEntity> keyMapper; + + public JoinCustomizer(string splitGroupId, IModelExplicitDeclarationsHolder explicitDeclarationsHolder, ICustomizersHolder customizersHolder) + : base(explicitDeclarationsHolder, customizersHolder, null) + { + if (explicitDeclarationsHolder == null) + { + throw new ArgumentNullException("explicitDeclarationsHolder"); + } + this.splitGroupId = splitGroupId; + keyMapper = new JoinKeyCustomizer<TEntity>(customizersHolder); + } + + public void Loader(string namedQueryReference) + { + CustomizersHolder.AddCustomizer(typeof(TEntity), (IJoinAttributesMapper m) => m.Loader(namedQueryReference)); + } + + public void SqlInsert(string sql) + { + CustomizersHolder.AddCustomizer(typeof(TEntity), (IJoinAttributesMapper m) => m.SqlInsert(sql)); + } + + public void SqlUpdate(string sql) + { + CustomizersHolder.AddCustomizer(typeof(TEntity), (IJoinAttributesMapper m) => m.SqlUpdate(sql)); + } + + public void SqlDelete(string sql) + { + CustomizersHolder.AddCustomizer(typeof(TEntity), (IJoinAttributesMapper m) => m.SqlDelete(sql)); + } + + public void Subselect(string sql) + { + CustomizersHolder.AddCustomizer(typeof(TEntity), (IJoinAttributesMapper m) => m.Subselect(sql)); + } + + public void Table(string tableName) + { + CustomizersHolder.AddCustomizer(typeof(TEntity), (IJoinAttributesMapper m) => m.Table(tableName)); + } + + public void Catalog(string catalogName) + { + CustomizersHolder.AddCustomizer(typeof(TEntity), (IJoinAttributesMapper m) => m.Catalog(catalogName)); + } + + public void Schema(string schemaName) + { + CustomizersHolder.AddCustomizer(typeof(TEntity), (IJoinAttributesMapper m) => m.Schema(schemaName)); + } + + public void Key(Action<IKeyMapper<TEntity>> keyMapping) + { + keyMapping(keyMapper); + } + + public void Inverse(bool value) + { + CustomizersHolder.AddCustomizer(typeof(TEntity), (IJoinAttributesMapper m) => m.Inverse(value)); + } + + public void Optional(bool isOptional) + { + CustomizersHolder.AddCustomizer(typeof(TEntity), (IJoinAttributesMapper m) => m.Optional(isOptional)); + } + + public void Fetch(FetchKind fetchMode) + { + CustomizersHolder.AddCustomizer(typeof(TEntity), (IJoinAttributesMapper m) => m.Fetch(fetchMode)); + } + + public override void Set<TElement>(Expression<Func<TEntity, IEnumerable<TElement>>> property, Action<ISetPropertiesMapper<TEntity, TElement>> collectionMapping, Action<ICollectionElementRelation<TElement>> mapping) + { + MemberInfo member = TypeExtensions.DecodeMemberAccessExpression(property); + ExplicitDeclarationsHolder.AddAsPropertySplit(typeof (TEntity), splitGroupId, member); + base.Set(property, collectionMapping, mapping); + } + + public override void Bag<TElement>(Expression<Func<TEntity, IEnumerable<TElement>>> property, Action<IBagPropertiesMapper<TEntity, TElement>> collectionMapping, Action<ICollectionElementRelation<TElement>> mapping) + { + MemberInfo member = TypeExtensions.DecodeMemberAccessExpression(property); + ExplicitDeclarationsHolder.AddAsPropertySplit(typeof (TEntity), splitGroupId, member); + base.Bag(property, collectionMapping, mapping); + } + + public override void List<TElement>(Expression<Func<TEntity, IEnumerable<TElement>>> property, Action<IListPropertiesMapper<TEntity, TElement>> collectionMapping, Action<ICollectionElementRelation<TElement>> mapping) + { + MemberInfo member = TypeExtensions.DecodeMemberAccessExpression(property); + ExplicitDeclarationsHolder.AddAsPropertySplit(typeof (TEntity), splitGroupId, member); + base.List(property, collectionMapping, mapping); + } + + public override void Map<TKey, TElement>(Expression<Func<TEntity, IDictionary<TKey, TElement>>> property, Action<IMapPropertiesMapper<TEntity, TKey, TElement>> collectionMapping, Action<IMapKeyRelation<TKey>> keyMapping, Action<ICollectionElementRelation<TElement>> mapping) + { + MemberInfo member = TypeExtensions.DecodeMemberAccessExpression(property); + ExplicitDeclarationsHolder.AddAsPropertySplit(typeof (TEntity), splitGroupId, member); + base.Map(property, collectionMapping, keyMapping, mapping); + } + + public override void Map<TKey, TElement>(Expression<Func<TEntity, IDictionary<TKey, TElement>>> property, Action<IMapPropertiesMapper<TEntity, TKey, TElement>> collectionMapping, Action<ICollectionElementRelation<TElement>> mapping) + { + MemberInfo member = TypeExtensions.DecodeMemberAccessExpression(property); + ExplicitDeclarationsHolder.AddAsPropertySplit(typeof (TEntity), splitGroupId, member); + base.Map(property, collectionMapping, mapping); + } + + public override void Property<TProperty>(Expression<Func<TEntity, TProperty>> property) + { + MemberInfo member = TypeExtensions.DecodeMemberAccessExpression(property); + ExplicitDeclarationsHolder.AddAsPropertySplit(typeof (TEntity), splitGroupId, member); + base.Property(property); + } + + public override void Property<TProperty>(Expression<Func<TEntity, TProperty>> property, Action<IPropertyMapper> mapping) + { + MemberInfo member = TypeExtensions.DecodeMemberAccessExpression(property); + ExplicitDeclarationsHolder.AddAsPropertySplit(typeof (TEntity), splitGroupId, member); + base.Property(property, mapping); + } + + public override void Property(FieldInfo member, Action<IPropertyMapper> mapping) + { + ExplicitDeclarationsHolder.AddAsPropertySplit(typeof (TEntity), splitGroupId, member); + base.Property(member, mapping); + } + + public override void Component<TComponent>(Expression<Func<TEntity, TComponent>> property, Action<IComponentMapper<TComponent>> mapping) + { + MemberInfo member = TypeExtensions.DecodeMemberAccessExpression(property); + ExplicitDeclarationsHolder.AddAsPropertySplit(typeof (TEntity), splitGroupId, member); + base.Component(property, mapping); + } + + public override void ManyToOne<TProperty>(Expression<Func<TEntity, TProperty>> property, Action<IManyToOneMapper> mapping) + { + MemberInfo member = TypeExtensions.DecodeMemberAccessExpression(property); + ExplicitDeclarationsHolder.AddAsPropertySplit(typeof (TEntity), splitGroupId, member); + base.ManyToOne(property, mapping); + } + + public override void ManyToOne<TProperty>(Expression<Func<TEntity, TProperty>> property) + { + MemberInfo member = TypeExtensions.DecodeMemberAccessExpression(property); + ExplicitDeclarationsHolder.AddAsPropertySplit(typeof (TEntity), splitGroupId, member); + base.ManyToOne(property); + } + + public override void Any<TProperty>(Expression<Func<TEntity, TProperty>> property, System.Type idTypeOfMetaType, Action<IAnyMapper> mapping) + { + MemberInfo member = TypeExtensions.DecodeMemberAccessExpression(property); + ExplicitDeclarationsHolder.AddAsPropertySplit(typeof (TEntity), splitGroupId, member); + base.Any(property, idTypeOfMetaType, mapping); + } + } +} \ No newline at end of file Added: trunk/nhibernate/src/NHibernate/Mapping/ByCode/Impl/CustomizersImpl/JoinKeyCustomizer.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Mapping/ByCode/Impl/CustomizersImpl/JoinKeyCustomizer.cs (rev 0) +++ trunk/nhibernate/src/NHibernate/Mapping/ByCode/Impl/CustomizersImpl/JoinKeyCustomizer.cs 2011-04-05 17:26:13 UTC (rev 5611) @@ -0,0 +1,57 @@ +using System; +using System.Linq.Expressions; +using System.Reflection; + +namespace NHibernate.Mapping.ByCode.Impl.CustomizersImpl +{ + public class JoinKeyCustomizer<TEntity> : IKeyMapper<TEntity> + where TEntity : class + { + public JoinKeyCustomizer(ICustomizersHolder customizersHolder) + { + CustomizersHolder = customizersHolder; + } + + public ICustomizersHolder CustomizersHolder { get; private set; } + + #region Implementation of IKeyMapper<TEntity> + + public void Column(Action<IColumnMapper> columnMapper) + { + CustomizersHolder.AddCustomizer(typeof(TEntity), (IJoinAttributesMapper m) => m.Key(x => x.Column(columnMapper))); + } + + public void Columns(params Action<IColumnMapper>[] columnMapper) + { + CustomizersHolder.AddCustomizer(typeof(TEntity), (IJoinAttributesMapper m) => m.Key(x => x.Columns(columnMapper))); + } + + public void Column(string columnName) + { + CustomizersHolder.AddCustomizer(typeof(TEntity), (IJoinAttributesMapper m) => m.Key(x => x.Column(columnName))); + } + + public void OnDelete(OnDeleteAction deleteAction) + { + CustomizersHolder.AddCustomizer(typeof(TEntity), (IJoinAttributesMapper m) => m.Key(x => x.OnDelete(deleteAction))); + } + + public void PropertyRef<TProperty>(Expression<Func<TEntity, TProperty>> propertyGetter) + { + MemberInfo member = TypeExtensions.DecodeMemberAccessExpression(propertyGetter); + CustomizersHolder.AddCustomizer(typeof(TEntity), (IJoinAttributesMapper m) => m.Key(x => x.PropertyRef(member))); + } + + public void Update(bool consideredInUpdateQuery) + { + CustomizersHolder.AddCustomizer(typeof(TEntity), (IJoinAttributesMapper m) => m.Key(x => x.Update(consideredInUpdateQuery))); + } + + public void ForeignKey(string foreingKeyName) + { + CustomizersHolder.AddCustomizer(typeof(TEntity), (IJoinAttributesMapper m) => m.Key(x => x.ForeignKey(foreingKeyName))); + } + + #endregion + } +} \ No newline at end of file Modified: trunk/nhibernate/src/NHibernate/Mapping/ByCode/Impl/CustomizersImpl/PropertyContainerCustomizer.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Mapping/ByCode/Impl/CustomizersImpl/PropertyContainerCustomizer.cs 2011-04-05 01:28:51 UTC (rev 5610) +++ trunk/nhibernate/src/NHibernate/Mapping/ByCode/Impl/CustomizersImpl/PropertyContainerCustomizer.cs 2011-04-05 17:26:13 UTC (rev 5611) @@ -27,7 +27,7 @@ get { return explicitDeclarationsHolder; } } - public void Property<TProperty>(Expression<Func<TEntity, TProperty>> property) + public virtual void Property<TProperty>(Expression<Func<TEntity, TProperty>> property) { Property(property, x => { }); } @@ -97,7 +97,7 @@ explicitDeclarationsHolder.AddAsAny(memberOf); } - public void Set<TElement>(Expression<Func<TEntity, IEnumerable<TElement>>> property, + public virtual void Set<TElement>(Expression<Func<TEntity, IEnumerable<TElement>>> property, Action<ISetPropertiesMapper<TEntity, TElement>> collectionMapping, Action<ICollectionElementRelation<TElement>> mapping) { @@ -110,7 +110,7 @@ mapping(new CollectionElementRelationCustomizer<TElement>(explicitDeclarationsHolder, new PropertyPath(PropertyPath, member), CustomizersHolder)); } - public void Bag<TElement>(Expression<Func<TEntity, IEnumerable<TElement>>> property, + public virtual void Bag<TElement>(Expression<Func<TEntity, IEnumerable<TElement>>> property, Action<IBagPropertiesMapper<TEntity, TElement>> collectionMapping, Action<ICollectionElementRelation<TElement>> mapping) { @@ -123,7 +123,7 @@ mapping(new CollectionElementRelationCustomizer<TElement>(explicitDeclarationsHolder, new PropertyPath(PropertyPath, memberOf), CustomizersHolder)); } - public void List<TElement>(Expression<Func<TEntity, IEnumerable<TElement>>> property, + public virtual void List<TElement>(Expression<Func<TEntity, IEnumerable<TElement>>> property, Action<IListPropertiesMapper<TEntity, TElement>> collectionMapping, Action<ICollectionElementRelation<TElement>> mapping) { @@ -136,7 +136,7 @@ mapping(new CollectionElementRelationCustomizer<TElement>(explicitDeclarationsHolder, new PropertyPath(PropertyPath, member), CustomizersHolder)); } - public void Map<TKey, TElement>(Expression<Func<TEntity, IDictionary<TKey, TElement>>> property, + public virtual void Map<TKey, TElement>(Expression<Func<TEntity, IDictionary<TKey, TElement>>> property, Action<IMapPropertiesMapper<TEntity, TKey, TElement>> collectionMapping, Action<IMapKeyRelation<TKey>> keyMapping, Action<ICollectionElementRelation<TElement>> mapping) @@ -154,7 +154,7 @@ mapping(new CollectionElementRelationCustomizer<TElement>(explicitDeclarationsHolder, memberOfPath, CustomizersHolder)); } - public void Map<TKey, TElement>(Expression<Func<TEntity, IDictionary<TKey, TElement>>> property, + public virtual void Map<TKey, TElement>(Expression<Func<TEntity, IDictionary<TKey, TElement>>> property, Action<IMapPropertiesMapper<TEntity, TKey, TElement>> collectionMapping, Action<ICollectionElementRelation<TElement>> mapping) { Modified: trunk/nhibernate/src/NHibernate/Mapping/ByCode/Impl/ICustomizersHolder.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Mapping/ByCode/Impl/ICustomizersHolder.cs 2011-04-05 01:28:51 UTC (rev 5610) +++ trunk/nhibernate/src/NHibernate/Mapping/ByCode/Impl/ICustomizersHolder.cs 2011-04-05 17:26:13 UTC (rev 5611) @@ -4,11 +4,12 @@ { public interface ICustomizersHolder { - void AddCustomizer(System.Type type, Action<IClassAttributesMapper> classCustomizer); + void AddCustomizer(System.Type type, Action<IClassMapper> classCustomizer); void AddCustomizer(System.Type type, Action<ISubclassAttributesMapper> classCustomizer); void AddCustomizer(System.Type type, Action<IJoinedSubclassAttributesMapper> classCustomizer); void AddCustomizer(System.Type type, Action<IUnionSubclassAttributesMapper> classCustomizer); void AddCustomizer(System.Type type, Action<IComponentAttributesMapper> classCustomizer); + void AddCustomizer(System.Type type, Action<IJoinAttributesMapper> classCustomizer); void AddCustomizer(PropertyPath member, Action<IPropertyMapper> propertyCustomizer); void AddCustomizer(PropertyPath member, Action<IManyToOneMapper> propertyCustomizer); @@ -22,11 +23,12 @@ void AddCustomizer(PropertyPath member, Action<ICollectionPropertiesMapper> propertyCustomizer); void AddCustomizer(PropertyPath member, Action<IComponentAttributesMapper> propertyCustomizer); - void InvokeCustomizers(System.Type type, IClassAttributesMapper mapper); + void InvokeCustomizers(System.Type type, IClassMapper mapper); void InvokeCustomizers(System.Type type, ISubclassAttributesMapper mapper); void InvokeCustomizers(System.Type type, IJoinedSubclassAttributesMapper mapper); void InvokeCustomizers(System.Type type, IUnionSubclassAttributesMapper mapper); void InvokeCustomizers(System.Type type, IComponentAttributesMapper mapper); + void InvokeCustomizers(System.Type type, IJoinAttributesMapper mapper); void InvokeCustomizers(PropertyPath member, IPropertyMapper mapper); void InvokeCustomizers(PropertyPath member, IManyToOneMapper mapper); Modified: trunk/nhibernate/src/NHibernate/Mapping/ByCode/ModelMapper.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Mapping/ByCode/ModelMapper.cs 2011-04-05 01:28:51 UTC (rev 5610) +++ trunk/nhibernate/src/NHibernate/Mapping/ByCode/ModelMapper.cs 2011-04-05 17:26:13 UTC (rev 5611) @@ -685,7 +685,6 @@ InvokeBeforeMapClass(type, classMapper); InvokeClassCustomizers(type, classMapper); - InvokeAfterMapClass(type, classMapper); MemberInfo[] naturalIdPropeties = persistentProperties.Where(mi => modelInspector.IsMemberOfNaturalId(mi)).ToArray(); if (naturalIdPropeties.Length > 0) @@ -698,18 +697,87 @@ } }); } + var splitGroups = modelInspector.GetPropertiesSplits(type); + var propertiesToMap = persistentProperties.Where(mi => !modelInspector.IsVersion(mi)).Except(naturalIdPropeties).ToList(); + var propertiesInSplits = new HashSet<MemberInfo>(); + foreach (var splitGroup in splitGroups) + { + var groupId= splitGroup; + var propertiesOfTheGroup = propertiesToMap.Where(p => modelInspector.IsTablePerClassSplit(type, groupId, p)).ToList(); + IJoinMapper joinMapper; + if (propertiesOfTheGroup.Count > 0 && classMapper.JoinMappers.TryGetValue(groupId, out joinMapper)) + { + MapProperties(type, propertiesOfTheGroup, joinMapper); + propertiesInSplits.UnionWith(propertiesOfTheGroup); + } + } - MapProperties(type, persistentProperties.Where(mi => !modelInspector.IsVersion(mi)).Except(naturalIdPropeties), classMapper); + MapProperties(type, propertiesToMap.Except(propertiesInSplits), classMapper); + InvokeAfterMapClass(type, classMapper); } - private void InvokeClassCustomizers(System.Type type, IClassAttributesMapper classMapper) + private void MapProperties(System.Type propertiesContainerType, IEnumerable<MemberInfo> propertiesToMap, IJoinMapper propertiesContainer) { + foreach (var property in propertiesToMap) + { + MemberInfo member = property; + System.Type propertyType = property.GetPropertyOrFieldType(); + var memberPath = new PropertyPath(null, member); + if (modelInspector.IsProperty(member)) + { + MapProperty(member, memberPath, propertiesContainer); + } + else if (modelInspector.IsAny(member)) + { + MapAny(member, memberPath, propertiesContainer); + } + else if (modelInspector.IsManyToOne(property)) + { + MapManyToOne(member, memberPath, propertiesContainer); + } + else if (modelInspector.IsSet(property)) + { + MapSet(member, memberPath, propertyType, propertiesContainer, propertiesContainerType); + } + else if (modelInspector.IsDictionary(property)) + { + MapDictionary(member, memberPath, propertyType, propertiesContainer, propertiesContainerType); + } + else if (modelInspector.IsArray(property)) + { + throw new NotSupportedException(); + } + else if (modelInspector.IsList(property)) + { + MapList(member, memberPath, propertyType, propertiesContainer, propertiesContainerType); + } + else if (modelInspector.IsBag(property)) + { + MapBag(member, memberPath, propertyType, propertiesContainer, propertiesContainerType); + } + else if (modelInspector.IsComponent(propertyType)) + { + MapComponent(member, memberPath, propertyType, propertiesContainer, propertiesContainerType); + } + else + { + MapProperty(member, memberPath, propertiesContainer); + } + } + } + + private void InvokeClassCustomizers(System.Type type, ClassMapper classMapper) + { InvokeAncestorsCustomizers(type.GetInterfaces(), classMapper); InvokeAncestorsCustomizers(type.GetHierarchyFromBase(), classMapper); customizerHolder.InvokeCustomizers(type, classMapper); + foreach (var joinMapper in classMapper.JoinMappers.Values) + { + customizerHolder.InvokeCustomizers(type, joinMapper); + } } - private void InvokeAncestorsCustomizers(IEnumerable<System.Type> typeAncestors, IClassAttributesMapper classMapper) + private void InvokeAncestorsCustomizers(IEnumerable<System.Type> typeAncestors, IClassMapper classMapper) { // only apply the polymorphic mapping for no entities: // this is to avoid a possible caos in entity-subclassing: @@ -924,7 +992,7 @@ }); } - private void MapBag(MemberInfo member, PropertyPath propertyPath, System.Type propertyType, IPropertyContainerMapper propertiesContainer, + private void MapBag(MemberInfo member, PropertyPath propertyPath, System.Type propertyType, ICollectionPropertiesContainerMapper propertiesContainer, System.Type propertiesContainerType) { System.Type collectionElementType = GetCollectionElementTypeOrThrow(propertiesContainerType, member, propertyType); @@ -938,7 +1006,7 @@ }, cert.Map); } - private void MapList(MemberInfo member, PropertyPath propertyPath, System.Type propertyType, IPropertyContainerMapper propertiesContainer, + private void MapList(MemberInfo member, PropertyPath propertyPath, System.Type propertyType, ICollectionPropertiesContainerMapper propertiesContainer, System.Type propertiesContainerType) { System.Type collectionElementType = GetCollectionElementTypeOrThrow(propertiesContainerType, member, propertyType); @@ -952,7 +1020,7 @@ }, cert.Map); } - private void MapDictionary(MemberInfo member, PropertyPath propertyPath, System.Type propertyType, IPropertyContainerMapper propertiesContainer, + private void MapDictionary(MemberInfo member, PropertyPath propertyPath, System.Type propertyType, ICollectionPropertiesContainerMapper propertiesContainer, System.Type propertiesContainerType) { System.Type dictionaryKeyType = propertyType.DetermineDictionaryKeyType(); @@ -975,7 +1043,7 @@ }, mkrm.Map, cert.Map); } - private void MapSet(MemberInfo member, PropertyPath propertyPath, System.Type propertyType, IPropertyContainerMapper propertiesContainer, + private void MapSet(MemberInfo member, PropertyPath propertyPath, System.Type propertyType, ICollectionPropertiesContainerMapper propertiesContainer, System.Type propertiesContainerType) { System.Type collectionElementType = GetCollectionElementTypeOrThrow(propertiesContainerType, member, propertyType); @@ -989,7 +1057,7 @@ }, cert.Map); } - private void MapOneToOne(MemberInfo member, PropertyPath propertyPath, IPropertyContainerMapper propertiesContainer) + private void MapOneToOne(MemberInfo member, PropertyPath propertyPath, IPlainPropertyContainerMapper propertiesContainer) { propertiesContainer.OneToOne(member, oneToOneMapper => { @@ -1092,7 +1160,7 @@ x.Parent(parentReferenceProperty, componentParentMapper => { -/* TODO */ + /* TODO */ } ); } @@ -1147,7 +1215,7 @@ { x.Parent(parentReferenceProperty, componentParentMapper => { -/* TODO */ + /* TODO */ }); } customizersHolder.InvokeCustomizers(componentPropertyType, x); Modified: trunk/nhibernate/src/NHibernate/NHibernate.csproj =================================================================== --- trunk/nhibernate/src/NHibernate/NHibernate.csproj 2011-04-05 01:28:51 UTC (rev 5610) +++ trunk/nhibernate/src/NHibernate/NHibernate.csproj 2011-04-05 17:26:13 UTC (rev 5611) @@ -345,8 +345,10 @@ <Compile Include="Mapping\ByCode\Impl\CustomizersImpl\CollectionPropertiesCustomizer.cs" /> <Compile Include="Mapping\ByCode\Impl\CustomizersImpl\ComponentCustomizer.cs" /> <Compile Include="Mapping\ByCode\Impl\CustomizersImpl\ComponentElementCustomizer.cs" /> + <Compile Include="Mapping\ByCode\Impl\CustomizersImpl\JoinCustomizer.cs" /> <Compile Include="Mapping\ByCode\Impl\CustomizersImpl\JoinedSubclassCustomizer.cs" /> <Compile Include="Mapping\ByCode\Impl\CustomizersImpl\JoinedSubclassKeyCustomizer.cs" /> + <Compile Include="Mapping\ByCode\Impl\CustomizersImpl\JoinKeyCustomizer.cs" /> <Compile Include="Mapping\ByCode\Impl\CustomizersImpl\ListPropertiesCustomizer.cs" /> <Compile Include="Mapping\ByCode\Impl\CustomizersImpl\ManyToManyCustomizer.cs" /> <Compile Include="Mapping\ByCode\Impl\CustomizersImpl\MapKeyComponentCustomizer.cs" /> Added: trunk/nhibernate/src/NHibernate.Test/MappingByCode/ExplicitlyDeclaredModelTests/SplitPropertiesRegistrationTests.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Test/MappingByCode/ExplicitlyDeclaredModelTests/SplitPropertiesRegistrationTests.cs (rev 0) +++ trunk/nhibernate/src/NHibernate.Test/MappingByCode/ExplicitlyDeclaredModelTests/SplitPropertiesRegistrationTests.cs 2011-04-05 17:26:13 UTC (rev 5611) @@ -0,0 +1,47 @@ +using NHibernate.Mapping.ByCode; +using NUnit.Framework; +using SharpTestsEx; + +namespace NHibernate.Test.MappingByCode.ExplicitlyDeclaredModelTests +{ + public class SplitPropertiesRegistrationTests + { + private class MyClass + { + public string Something { get; set; } + } + + private class Inherited : MyClass + { + public string SomethingElse { get; set; } + } + + [Test] + public void WhenRegisterPropertySplitsThenTypeHasSplitGroups() + { + var inspector = new ExplicitlyDeclaredModel(); + inspector.AddAsPropertySplit(typeof(MyClass), "group", For<MyClass>.Property(x => x.Something)); + inspector.AddAsPropertySplit(typeof(Inherited), "group1", For<Inherited>.Property(x => x.SomethingElse)); + + inspector.GetSplitGroupsFor(typeof(MyClass)).Should().Have.SameValuesAs("group"); + inspector.GetSplitGroupsFor(typeof(Inherited)).Should().Have.SameValuesAs("group1"); + } + + [Test] + public void WhenRegisterPropertySplitMoreThanOnceThenIgnore() + { + var inspector = new ExplicitlyDeclaredModel(); + var memberFromDeclaringType = For<MyClass>.Property(x=> x.Something); + var memberFromReferencedType = typeof(Inherited).GetProperty("Something"); + + inspector.AddAsPropertySplit(typeof(MyClass), "group", memberFromDeclaringType); + inspector.AddAsPropertySplit(typeof(Inherited), "group1", memberFromReferencedType); + + inspector.GetSplitGroupsFor(typeof(MyClass)).Should().Have.SameValuesAs("group"); + inspector.GetSplitGroupsFor(typeof(Inherited)).Should().Be.Empty(); + + inspector.GetSplitGroupFor(memberFromDeclaringType).Should().Be("group"); + inspector.GetSplitGroupFor(memberFromReferencedType).Should().Be("group"); + } + } +} \ No newline at end of file Modified: trunk/nhibernate/src/NHibernate.Test/MappingByCode/ExpliticMappingTests/RootClassPropertiesSplitsTests.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Test/MappingByCode/ExpliticMappingTests/RootClassPropertiesSplitsTests.cs 2011-04-05 01:28:51 UTC (rev 5610) +++ trunk/nhibernate/src/NHibernate.Test/MappingByCode/ExpliticMappingTests/RootClassPropertiesSplitsTests.cs 2011-04-05 17:26:13 UTC (rev 5611) @@ -1,4 +1,5 @@ using System.Collections.Generic; +using System.Linq; using NHibernate.Mapping.ByCode; using NUnit.Framework; using SharpTestsEx; @@ -17,7 +18,7 @@ public string SomethingB2 { get; set; } } - [Test, Ignore("Not implemented yet")] + [Test] public void WhenSplittedPropertiesThenRegisterSplitGroupIds() { var inspector = new ExplicitlyDeclaredModel(); @@ -42,7 +43,7 @@ tablePerClassSplits.Should().Have.SameValuesAs("MyClassSplit1", "MyClassSplit2"); } - [Test, Ignore("Not implemented yet")] + [Test] public void WhenSplittedPropertiesThenRegister() { var inspector = new ExplicitlyDeclaredModel(); @@ -71,5 +72,36 @@ inspector.IsTablePerClassSplit(typeof(MyClass), "MyClassSplit2", For<MyClass>.Property(x => x.SomethingB1)).Should().Be.True(); inspector.IsTablePerClassSplit(typeof(MyClass), "MyClassSplit2", For<MyClass>.Property(x => x.SomethingB2)).Should().Be.True(); } + + [Test] + public void WhenMapSplittedPropertiesThenEachPropertyIsInItsSplitGroup() + { + var inspector = new ExplicitlyDeclaredModel(); + var mapper = new ModelMapper(inspector); + mapper.Class<MyClass>(map => + { + map.Id(x => x.Id, idmap => { }); + map.Join("MyClassSplit1", mj => + { + mj.Property(x => x.SomethingA1); + mj.Property(x => x.SomethingA2); + }); + map.Join("MyClassSplit2", mj => + { + mj.Property(x => x.SomethingB1); + mj.Property(x => x.SomethingB2); + }); + map.Property(x => x.Something0); + }); + var hbmDoc = mapper.CompileMappingFor(new[] { typeof(MyClass) }); + + var hbmClass = hbmDoc.RootClasses[0]; + hbmClass.Joins.Select(j => j.table).Should().Have.SameValuesAs("MyClassSplit1", "MyClassSplit2"); + hbmClass.Properties.Single().Name.Should().Be("Something0"); + var hbmSplit1 = hbmClass.Joins.Single(j => "MyClassSplit1" == j.table); + hbmSplit1.Properties.Select(p => p.Name).Should().Have.SameValuesAs("SomethingA1", "SomethingA2"); + var hbmSplit2 = hbmClass.Joins.Single(j => "MyClassSplit2" == j.table); + hbmSplit2.Properties.Select(p => p.Name).Should().Have.SameValuesAs("SomethingB1", "SomethingB2"); + } } } \ No newline at end of file Modified: trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2011-04-05 01:28:51 UTC (rev 5610) +++ trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2011-04-05 17:26:13 UTC (rev 5611) @@ -508,6 +508,7 @@ <Compile Include="Linq\ByMethod\SumTests.cs" /> <Compile Include="Logging\Log4NetLoggerTest.cs" /> <Compile Include="Logging\LoggerProviderTest.cs" /> + <Compile Include="MappingByCode\ExplicitlyDeclaredModelTests\SplitPropertiesRegistrationTests.cs" /> <Compile Include="MappingByCode\ExpliticMappingTests\BasicMappingOfSimpleClass.cs" /> <Compile Include="MappingByCode\ExpliticMappingTests\ColumnsNamingConvetions.cs" /> <Compile Include="MappingByCode\ExplicitlyDeclaredModelTests\ComponentMappingRegistrationTests.cs" /> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pa...@us...> - 2011-04-05 01:28:58
|
Revision: 5610 http://nhibernate.svn.sourceforge.net/nhibernate/?rev=5610&view=rev Author: patearl Date: 2011-04-05 01:28:51 +0000 (Tue, 05 Apr 2011) Log Message: ----------- Tests for proxied members with ref and out parameters. Modified Paths: -------------- trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj Added Paths: ----------- trunk/nhibernate/src/NHibernate.Test/DynamicProxyTests/ProxiedMembers/ trunk/nhibernate/src/NHibernate.Test/DynamicProxyTests/ProxiedMembers/ClassWithVarietyOfMembers.cs trunk/nhibernate/src/NHibernate.Test/DynamicProxyTests/ProxiedMembers/Fixture.cs trunk/nhibernate/src/NHibernate.Test/DynamicProxyTests/ProxiedMembers/Mapping.hbm.xml Added: trunk/nhibernate/src/NHibernate.Test/DynamicProxyTests/ProxiedMembers/ClassWithVarietyOfMembers.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Test/DynamicProxyTests/ProxiedMembers/ClassWithVarietyOfMembers.cs (rev 0) +++ trunk/nhibernate/src/NHibernate.Test/DynamicProxyTests/ProxiedMembers/ClassWithVarietyOfMembers.cs 2011-04-05 01:28:51 UTC (rev 5610) @@ -0,0 +1,20 @@ +using System; + +namespace NHibernate.Test.DynamicProxyTests.ProxiedMembers +{ + public class ClassWithVarietyOfMembers + { + public virtual int Id { get; set; } + public virtual string Data { get; set; } + + public virtual void Method1(out int x) + { + x = 3; + } + + public virtual void Method2(ref int x) + { + x++; + } + } +} \ No newline at end of file Added: trunk/nhibernate/src/NHibernate.Test/DynamicProxyTests/ProxiedMembers/Fixture.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Test/DynamicProxyTests/ProxiedMembers/Fixture.cs (rev 0) +++ trunk/nhibernate/src/NHibernate.Test/DynamicProxyTests/ProxiedMembers/Fixture.cs 2011-04-05 01:28:51 UTC (rev 5610) @@ -0,0 +1,50 @@ +using System; +using System.Collections; +using System.IO; +using System.Runtime.Serialization; +using System.Runtime.Serialization.Formatters.Binary; +using NUnit.Framework; + +namespace NHibernate.Test.DynamicProxyTests.ProxiedMembers +{ + [TestFixture] + public class Fixture : TestCase + { + protected override IList Mappings + { + get { return new[] { "DynamicProxyTests.ProxiedMembers.Mapping.hbm.xml" }; } + } + + protected override string MappingsAssembly + { + get { return "NHibernate.Test"; } + } + + [Test] + [Ignore] + public void Proxy() + { + ISession s = OpenSession(); + ClassWithVarietyOfMembers c = new ClassWithVarietyOfMembers {Id = 1, Data = "some data"}; + s.Save(c); + s.Flush(); + s.Close(); + + s = OpenSession(); + c = (ClassWithVarietyOfMembers)s.Load(typeof(ClassWithVarietyOfMembers), c.Id); + Assert.IsFalse(NHibernateUtil.IsInitialized(c)); + + int x; + c.Method1(out x); + Assert.AreEqual(3, x); + + x = 4; + c.Method2(ref x); + Assert.AreEqual(5, x); + + s.Delete(c); + s.Flush(); + s.Close(); + } + } +} \ No newline at end of file Added: trunk/nhibernate/src/NHibernate.Test/DynamicProxyTests/ProxiedMembers/Mapping.hbm.xml =================================================================== --- trunk/nhibernate/src/NHibernate.Test/DynamicProxyTests/ProxiedMembers/Mapping.hbm.xml (rev 0) +++ trunk/nhibernate/src/NHibernate.Test/DynamicProxyTests/ProxiedMembers/Mapping.hbm.xml 2011-04-05 01:28:51 UTC (rev 5610) @@ -0,0 +1,11 @@ +<?xml version="1.0" encoding="utf-8" ?> +<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" + assembly="NHibernate.Test" + namespace="NHibernate.Test.DynamicProxyTests.ProxiedMembers"> + <class name="ClassWithVarietyOfMembers"> + <id name="Id"> + <generator class="assigned" /> + </id> + <property name="Data" /> + </class> +</hibernate-mapping> \ No newline at end of file Modified: trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2011-04-04 20:53:35 UTC (rev 5609) +++ trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2011-04-05 01:28:51 UTC (rev 5610) @@ -222,6 +222,8 @@ <Compile Include="DynamicProxyTests\InterfaceProxySerializationTests\ProxyFixture.cs" /> <Compile Include="DynamicProxyTests\InterfaceWithEqualsGethashcodeTests.cs" /> <Compile Include="DynamicProxyTests\LazyFieldInterceptorSerializable.cs" /> + <Compile Include="DynamicProxyTests\ProxiedMembers\ClassWithVarietyOfMembers.cs" /> + <Compile Include="DynamicProxyTests\ProxiedMembers\Fixture.cs" /> <Compile Include="EngineTest\CallableParserFixture.cs" /> <Compile Include="EngineTest\NativeSQLQueryNonScalarReturnTest.cs" /> <Compile Include="EngineTest\NativeSQLQueryScalarReturnTest.cs" /> @@ -2535,6 +2537,7 @@ <EmbeddedResource Include="NHSpecificTest\NH1291AnonExample\Mappings.hbm.xml" /> </ItemGroup> <ItemGroup> + <EmbeddedResource Include="DynamicProxyTests\ProxiedMembers\Mapping.hbm.xml" /> <EmbeddedResource Include="NHSpecificTest\SqlConverterAndMultiQuery\Mappings.hbm.xml" /> <EmbeddedResource Include="NHSpecificTest\NH2489\Mappings.hbm.xml" /> <EmbeddedResource Include="NHSpecificTest\NH2603\Mappings.hbm.xml" /> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fab...@us...> - 2011-04-04 20:53:41
|
Revision: 5609 http://nhibernate.svn.sourceforge.net/nhibernate/?rev=5609&view=rev Author: fabiomaulo Date: 2011-04-04 20:53:35 +0000 (Mon, 04 Apr 2011) Log Message: ----------- refactorized public API Modified Paths: -------------- trunk/nhibernate/src/NHibernate/Mapping/ByCode/ExplicitlyDeclaredModel.cs trunk/nhibernate/src/NHibernate/Mapping/ByCode/IClassMapper.cs trunk/nhibernate/src/NHibernate/Mapping/ByCode/IModelInspector.cs trunk/nhibernate/src/NHibernate/Mapping/ByCode/Impl/CustomizersImpl/ClassCustomizer.cs trunk/nhibernate/src/NHibernate.Test/MappingByCode/ExpliticMappingTests/RootClassPropertiesSplitsTests.cs Modified: trunk/nhibernate/src/NHibernate/Mapping/ByCode/ExplicitlyDeclaredModel.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Mapping/ByCode/ExplicitlyDeclaredModel.cs 2011-04-04 20:33:50 UTC (rev 5608) +++ trunk/nhibernate/src/NHibernate/Mapping/ByCode/ExplicitlyDeclaredModel.cs 2011-04-04 20:53:35 UTC (rev 5609) @@ -515,5 +515,10 @@ { return delayedEntityRegistrations.ContainsKey(type); } + + public IEnumerable<string> GetPropertiesSplits(System.Type type) + { + return null; + } } } \ No newline at end of file Modified: trunk/nhibernate/src/NHibernate/Mapping/ByCode/IClassMapper.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Mapping/ByCode/IClassMapper.cs 2011-04-04 20:33:50 UTC (rev 5608) +++ trunk/nhibernate/src/NHibernate/Mapping/ByCode/IClassMapper.cs 2011-04-04 20:53:35 UTC (rev 5609) @@ -54,6 +54,6 @@ public interface IClassMapper<TEntity> : IClassAttributesMapper<TEntity>, IPropertyContainerMapper<TEntity> where TEntity : class { - void Join(Action<IJoinMapper<TEntity>> splittedMapping); + void Join(string splitGroupId, Action<IJoinMapper<TEntity>> splittedMapping); } } \ No newline at end of file Modified: trunk/nhibernate/src/NHibernate/Mapping/ByCode/IModelInspector.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Mapping/ByCode/IModelInspector.cs 2011-04-04 20:33:50 UTC (rev 5608) +++ trunk/nhibernate/src/NHibernate/Mapping/ByCode/IModelInspector.cs 2011-04-04 20:53:35 UTC (rev 5609) @@ -1,3 +1,4 @@ +using System.Collections.Generic; using System.Reflection; namespace NHibernate.Mapping.ByCode @@ -32,5 +33,6 @@ bool IsArray(MemberInfo role); bool IsDictionary(MemberInfo role); bool IsProperty(MemberInfo member); + IEnumerable<string> GetPropertiesSplits(System.Type type); } } \ No newline at end of file Modified: trunk/nhibernate/src/NHibernate/Mapping/ByCode/Impl/CustomizersImpl/ClassCustomizer.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Mapping/ByCode/Impl/CustomizersImpl/ClassCustomizer.cs 2011-04-04 20:33:50 UTC (rev 5608) +++ trunk/nhibernate/src/NHibernate/Mapping/ByCode/Impl/CustomizersImpl/ClassCustomizer.cs 2011-04-04 20:53:35 UTC (rev 5609) @@ -109,7 +109,7 @@ CustomizersHolder.AddCustomizer(typeof (TEntity), (IClassAttributesMapper m) => m.SchemaAction(action)); } - public void Join(Action<IJoinMapper<TEntity>> splittedMapping) + public void Join(string splitGroupId, Action<IJoinMapper<TEntity>> splittedMapping) { throw new NotImplementedException(); } Modified: trunk/nhibernate/src/NHibernate.Test/MappingByCode/ExpliticMappingTests/RootClassPropertiesSplitsTests.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Test/MappingByCode/ExpliticMappingTests/RootClassPropertiesSplitsTests.cs 2011-04-04 20:33:50 UTC (rev 5608) +++ trunk/nhibernate/src/NHibernate.Test/MappingByCode/ExpliticMappingTests/RootClassPropertiesSplitsTests.cs 2011-04-04 20:53:35 UTC (rev 5609) @@ -1,3 +1,4 @@ +using System.Collections.Generic; using NHibernate.Mapping.ByCode; using NUnit.Framework; using SharpTestsEx; @@ -17,6 +18,31 @@ } [Test, Ignore("Not implemented yet")] + public void WhenSplittedPropertiesThenRegisterSplitGroupIds() + { + var inspector = new ExplicitlyDeclaredModel(); + var mapper = new ModelMapper(inspector); + mapper.Class<MyClass>(map => + { + map.Id(x => x.Id, idmap => { }); + map.Join("MyClassSplit1", mj => + { + mj.Property(x => x.SomethingA1); + mj.Property(x => x.SomethingA2); + }); + map.Join("MyClassSplit2", mj => + { + mj.Property(x => x.SomethingB1); + mj.Property(x => x.SomethingB2); + }); + map.Property(x => x.Something0); + }); + + IEnumerable<string> tablePerClassSplits = inspector.GetPropertiesSplits(typeof(MyClass)); + tablePerClassSplits.Should().Have.SameValuesAs("MyClassSplit1", "MyClassSplit2"); + } + + [Test, Ignore("Not implemented yet")] public void WhenSplittedPropertiesThenRegister() { var inspector = new ExplicitlyDeclaredModel(); @@ -24,15 +50,13 @@ mapper.Class<MyClass>(map => { map.Id(x => x.Id, idmap => { }); - map.Join(mj=> + map.Join("MyClassSplit1", mj=> { - mj.Table("MyClassSplit1"); mj.Property(x => x.SomethingA1); mj.Property(x => x.SomethingA2); }); - map.Join(mj => + map.Join("MyClassSplit2", mj => { - mj.Table("MyClassSplit2"); mj.Property(x => x.SomethingB1); mj.Property(x => x.SomethingB2); }); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fab...@us...> - 2011-04-04 20:33:56
|
Revision: 5608 http://nhibernate.svn.sourceforge.net/nhibernate/?rev=5608&view=rev Author: fabiomaulo Date: 2011-04-04 20:33:50 +0000 (Mon, 04 Apr 2011) Log Message: ----------- Minor Modified Paths: -------------- trunk/nhibernate/src/NHibernate/Mapping/ByCode/IClassMapper.cs trunk/nhibernate/src/NHibernate/Mapping/ByCode/Impl/ClassMapper.cs Modified: trunk/nhibernate/src/NHibernate/Mapping/ByCode/IClassMapper.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Mapping/ByCode/IClassMapper.cs 2011-04-04 19:47:46 UTC (rev 5607) +++ trunk/nhibernate/src/NHibernate/Mapping/ByCode/IClassMapper.cs 2011-04-04 20:33:50 UTC (rev 5608) @@ -24,7 +24,12 @@ public interface IClassMapper : IClassAttributesMapper, IPropertyContainerMapper { - void Join(string tableName, Action<IJoinMapper> splittedMapping); + /// <summary> + /// Using the Join, it is possible to split properties of one class to several tables, when there's a 1-to-1 relationship between the table + /// </summary> + /// <param name="splitGroupId">The split-group identifier. By default it is assigned to the join-table-name</param> + /// <param name="splittedMapping">The lambda to map the join.</param> + void Join(string splitGroupId, Action<IJoinMapper> splittedMapping); } public interface IClassAttributesMapper<TEntity> : IEntityAttributesMapper, IEntitySqlsMapper where TEntity : class Modified: trunk/nhibernate/src/NHibernate/Mapping/ByCode/Impl/ClassMapper.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Mapping/ByCode/Impl/ClassMapper.cs 2011-04-04 19:47:46 UTC (rev 5607) +++ trunk/nhibernate/src/NHibernate/Mapping/ByCode/Impl/ClassMapper.cs 2011-04-04 20:33:50 UTC (rev 5608) @@ -174,15 +174,15 @@ classMapping.schemaaction = action.ToSchemaActionString(); } - public void Join(string tableName, Action<IJoinMapper> splittedMapping) + public void Join(string splitGroupId, Action<IJoinMapper> splittedMapping) { IJoinMapper splitGroup; - if(!JoinMappers.TryGetValue(tableName, out splitGroup)) + if(!JoinMappers.TryGetValue(splitGroupId, out splitGroup)) { var hbmJoin = new HbmJoin(); - splitGroup = new JoinMapper(Container, tableName, hbmJoin, MapDoc); + splitGroup = new JoinMapper(Container, splitGroupId, hbmJoin, MapDoc); var toAdd = new[] { hbmJoin }; - JoinMappers.Add(tableName, splitGroup); + JoinMappers.Add(splitGroupId, splitGroup); classMapping.Items1 = classMapping.Items1 == null ? toAdd : classMapping.Items1.Concat(toAdd).ToArray(); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fab...@us...> - 2011-04-04 19:47:52
|
Revision: 5607 http://nhibernate.svn.sourceforge.net/nhibernate/?rev=5607&view=rev Author: fabiomaulo Date: 2011-04-04 19:47:46 +0000 (Mon, 04 Apr 2011) Log Message: ----------- ClassMapper with Joins Modified Paths: -------------- trunk/nhibernate/src/NHibernate/Mapping/ByCode/IClassMapper.cs trunk/nhibernate/src/NHibernate/Mapping/ByCode/Impl/ClassMapper.cs trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj Added Paths: ----------- trunk/nhibernate/src/NHibernate.Test/MappingByCode/MappersTests/ClassMapperWithJoinPropertiesTest.cs Modified: trunk/nhibernate/src/NHibernate/Mapping/ByCode/IClassMapper.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Mapping/ByCode/IClassMapper.cs 2011-04-04 18:28:31 UTC (rev 5606) +++ trunk/nhibernate/src/NHibernate/Mapping/ByCode/IClassMapper.cs 2011-04-04 19:47:46 UTC (rev 5607) @@ -24,7 +24,7 @@ public interface IClassMapper : IClassAttributesMapper, IPropertyContainerMapper { - void Join(Action<IJoinMapper> splittedMapping); + void Join(string tableName, Action<IJoinMapper> splittedMapping); } public interface IClassAttributesMapper<TEntity> : IEntityAttributesMapper, IEntitySqlsMapper where TEntity : class Modified: trunk/nhibernate/src/NHibernate/Mapping/ByCode/Impl/ClassMapper.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Mapping/ByCode/Impl/ClassMapper.cs 2011-04-04 18:28:31 UTC (rev 5606) +++ trunk/nhibernate/src/NHibernate/Mapping/ByCode/Impl/ClassMapper.cs 2011-04-04 19:47:46 UTC (rev 5607) @@ -11,6 +11,7 @@ { private readonly HbmClass classMapping; private readonly IIdMapper idMapper; + private Dictionary<string, IJoinMapper> joinMappers; private ICacheMapper cacheMapper; private IDiscriminatorMapper discriminatorMapper; private INaturalIdMapper naturalIdMapper; @@ -49,6 +50,11 @@ #endregion + private Dictionary<string, IJoinMapper> JoinMappers + { + get { return joinMappers ?? (joinMappers = new Dictionary<string, IJoinMapper>()); } + } + #region Implementation of IClassMapper public void Id(Action<IIdMapper> mapper) @@ -168,9 +174,19 @@ classMapping.schemaaction = action.ToSchemaActionString(); } - public void Join(Action<IJoinMapper> splittedMapping) + public void Join(string tableName, Action<IJoinMapper> splittedMapping) { - throw new NotImplementedException(); + IJoinMapper splitGroup; + if(!JoinMappers.TryGetValue(tableName, out splitGroup)) + { + var hbmJoin = new HbmJoin(); + splitGroup = new JoinMapper(Container, tableName, hbmJoin, MapDoc); + var toAdd = new[] { hbmJoin }; + JoinMappers.Add(tableName, splitGroup); + classMapping.Items1 = classMapping.Items1 == null ? toAdd : classMapping.Items1.Concat(toAdd).ToArray(); + } + + splittedMapping(splitGroup); } #endregion Added: trunk/nhibernate/src/NHibernate.Test/MappingByCode/MappersTests/ClassMapperWithJoinPropertiesTest.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Test/MappingByCode/MappersTests/ClassMapperWithJoinPropertiesTest.cs (rev 0) +++ trunk/nhibernate/src/NHibernate.Test/MappingByCode/MappersTests/ClassMapperWithJoinPropertiesTest.cs 2011-04-04 19:47:46 UTC (rev 5607) @@ -0,0 +1,89 @@ +using System.Linq; +using NHibernate.Cfg.MappingSchema; +using NHibernate.Mapping.ByCode; +using NHibernate.Mapping.ByCode.Impl; +using NUnit.Framework; +using SharpTestsEx; + +namespace NHibernate.Test.MappingByCode.MappersTests +{ + public class ClassMapperWithJoinPropertiesTest + { + private class MyClass + { + public int Id { get; set; } + } + + [Test] + public void WhenDefineJoinThenAddJoinWithTableNameAndKey() + { + var mapdoc = new HbmMapping(); + var mapper = new ClassMapper(typeof(MyClass), mapdoc, For<MyClass>.Property(x=> x.Id)); + mapper.Join("MyTable",x => { }); + + var hbmClass = mapdoc.RootClasses[0]; + var hbmJoin = hbmClass.Joins.Single(); + hbmJoin.table.Should().Be("MyTable"); + hbmJoin.key.Should().Not.Be.Null(); + hbmJoin.key.column1.Should().Not.Be.Null(); + } + + [Test] + public void WhenDefineJoinThenCallJoinMapper() + { + var mapdoc = new HbmMapping(); + var mapper = new ClassMapper(typeof(MyClass), mapdoc, For<MyClass>.Property(x => x.Id)); + var called = false; + mapper.Join("MyTable", x => + { + x.Should().Not.Be.Null(); + called = true; + }); + + called.Should().Be.True(); + } + + //[Test] + //public void WhenDefineJoinTableNameAsTableOfRootThenThrows() + //{ + // We can't give support to this check. + // The name of the table of the root-class may change during the mapping process where the name of the joined table is immutable (or...perhaps what is really immutable is the Id used in the explicit mapping ;) ) + // We are using the name of the joined table as id for the splitted property group. I can't find another way to be 100% sure to re-use the same + // instance of JoinMapper when the Join method is used more than once. + // The case of "inconsistent" name should be checked by binders since the problem is the same using XML mappings + // + // var mapdoc = new HbmMapping(); + // var mapper = new ClassMapper(typeof(MyClass), mapdoc, For<MyClass>.Property(x => x.Id)); + // Executing.This(()=> mapper.Join("MyClass", x => { })).Should().Throw<MappingException>(); + //} + + [Test] + public void WhenDefineMoreJoinsThenTableNameShouldBeUnique() + { + var mapdoc = new HbmMapping(); + var mapper = new ClassMapper(typeof(MyClass), mapdoc, For<MyClass>.Property(x => x.Id)); + mapper.Join("T1", x => { }); + mapper.Join("T2",x => { }); + + var hbmClass = mapdoc.RootClasses[0]; + hbmClass.Joins.Should().Have.Count.EqualTo(2); + hbmClass.Joins.Select(x=> x.table).Should().Have.UniqueValues(); + } + + [Test] + public void WhenDefineMoreJoinsWithSameIdThenUseSameJoinMapperInstance() + { + var mapdoc = new HbmMapping(); + var mapper = new ClassMapper(typeof(MyClass), mapdoc, For<MyClass>.Property(x => x.Id)); + IJoinMapper firstCallInstance = null; + IJoinMapper secondCallInstance = null; + + mapper.Join("T1", x => firstCallInstance = x); + mapper.Join("T1", x => secondCallInstance = x); + + firstCallInstance.Should().Be.SameInstanceAs(secondCallInstance); + var hbmClass = mapdoc.RootClasses[0]; + hbmClass.Joins.Should().Have.Count.EqualTo(1); + } + } +} \ No newline at end of file Modified: trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2011-04-04 18:28:31 UTC (rev 5606) +++ trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2011-04-04 19:47:46 UTC (rev 5607) @@ -523,6 +523,7 @@ <Compile Include="MappingByCode\ExpliticMappingTests\VersionTests.cs" /> <Compile Include="MappingByCode\For.cs" /> <Compile Include="MappingByCode\MappersTests\AbstractPropertyContainerMapperTest.cs" /> + <Compile Include="MappingByCode\MappersTests\ClassMapperWithJoinPropertiesTest.cs" /> <Compile Include="MappingByCode\MappersTests\JoinMapperTests.cs" /> <Compile Include="MappingByCode\NatureDemo\Naturalness\Address.cs" /> <Compile Include="MappingByCode\NatureDemo\Naturalness\Animal.cs" /> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fab...@us...> - 2011-04-04 18:28:37
|
Revision: 5606 http://nhibernate.svn.sourceforge.net/nhibernate/?rev=5606&view=rev Author: fabiomaulo Date: 2011-04-04 18:28:31 +0000 (Mon, 04 Apr 2011) Log Message: ----------- JoinMapper done Modified Paths: -------------- trunk/nhibernate/src/NHibernate/Mapping/ByCode/Impl/JoinMapper.cs trunk/nhibernate/src/NHibernate.Test/MappingByCode/MappersTests/JoinMapperTests.cs Modified: trunk/nhibernate/src/NHibernate/Mapping/ByCode/Impl/JoinMapper.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Mapping/ByCode/Impl/JoinMapper.cs 2011-04-04 18:22:58 UTC (rev 5605) +++ trunk/nhibernate/src/NHibernate/Mapping/ByCode/Impl/JoinMapper.cs 2011-04-04 18:28:31 UTC (rev 5606) @@ -1,4 +1,5 @@ using System; +using System.Linq; using NHibernate.Cfg.MappingSchema; namespace NHibernate.Mapping.ByCode.Impl @@ -56,6 +57,12 @@ protected override void AddProperty(object property) { + if (property == null) + { + throw new ArgumentNullException("property"); + } + var toAdd = new[] { property }; + hbmJoin.Items = hbmJoin.Items == null ? toAdd : hbmJoin.Items.Concat(toAdd).ToArray(); } public void Loader(string namedQueryReference) Modified: trunk/nhibernate/src/NHibernate.Test/MappingByCode/MappersTests/JoinMapperTests.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Test/MappingByCode/MappersTests/JoinMapperTests.cs 2011-04-04 18:22:58 UTC (rev 5605) +++ trunk/nhibernate/src/NHibernate.Test/MappingByCode/MappersTests/JoinMapperTests.cs 2011-04-04 18:28:31 UTC (rev 5606) @@ -214,5 +214,17 @@ firstCallInstance.Should().Be.SameInstanceAs(secondCallInstance); } + + [Test] + public void WhenAddPropertyThenAddItem() + { + var mapdoc = new HbmMapping(); + var hbmJoin = new HbmJoin(); + var mapper = new JoinMapper(typeof(MyClass), "AA", hbmJoin, mapdoc); + + mapper.Property(For<MyClass>.Property(mc => mc.Something), x => { }); + + hbmJoin.Properties.Should().Have.Count.EqualTo(1); + } } } \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fab...@us...> - 2011-04-04 18:23:04
|
Revision: 5605 http://nhibernate.svn.sourceforge.net/nhibernate/?rev=5605&view=rev Author: fabiomaulo Date: 2011-04-04 18:22:58 +0000 (Mon, 04 Apr 2011) Log Message: ----------- Port test from ConfORM Modified Paths: -------------- trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj Added Paths: ----------- trunk/nhibernate/src/NHibernate.Test/MappingByCode/MappersTests/AbstractPropertyContainerMapperTest.cs Added: trunk/nhibernate/src/NHibernate.Test/MappingByCode/MappersTests/AbstractPropertyContainerMapperTest.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Test/MappingByCode/MappersTests/AbstractPropertyContainerMapperTest.cs (rev 0) +++ trunk/nhibernate/src/NHibernate.Test/MappingByCode/MappersTests/AbstractPropertyContainerMapperTest.cs 2011-04-04 18:22:58 UTC (rev 5605) @@ -0,0 +1,148 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using NHibernate.Cfg.MappingSchema; +using NHibernate.Mapping.ByCode.Impl; +using NUnit.Framework; +using SharpTestsEx; + +namespace NHibernate.Test.MappingByCode.MappersTests +{ + public class AbstractPropertyContainerMapperTest + { + private class EntitySimple + { + public string Name { get; set; } + } + private class InheritedEntitySimple : EntitySimple + { + } + + private class OtherSimple + { + public string Name { get; set; } + } + + private class MyClass + { + public object Reference { get; set; } + } + private class MyClassWithDictionary + { + public IDictionary<string, string> Dictionary { get; set; } + } + + [Test] + public void CantCreateWithoutHbmMapping() + { + Executing.This(() => new HackPropertyContainerMapper(typeof(EntitySimple), null)).Should().Throw<ArgumentNullException>(); + } + + [Test] + public void CantCreateWithoutContainerType() + { + Executing.This(() => new HackPropertyContainerMapper(null, new HbmMapping())).Should().Throw<ArgumentNullException>(); + } + + [Test] + public void CanAddSimpleProperty() + { + var properties = new List<object>(); + var map = new StubPropertyContainerMapper<EntitySimple>(properties); + map.Property(typeof (EntitySimple).GetProperty("Name"), x => { }); + + properties.Should().Have.Count.EqualTo(1); + properties.First().Should().Be.OfType<HbmProperty>().And.ValueOf.Name.Should().Be.EqualTo("Name"); + } + + [Test] + public void CallPropertyMapper() + { + var properties = new List<object>(); + var map = new StubPropertyContainerMapper<EntitySimple>(properties); + var called = false; + map.Property(typeof(EntitySimple).GetProperty("Name"), x => called = true ); + + called.Should().Be.True(); + } + + [Test] + public void CantAddPropertyOfNotInheritedType() + { + var map = new StubPropertyContainerMapper<OtherSimple>(new List<object>()); + Executing.This(() => map.Property(typeof(EntitySimple).GetProperty("Name"), x => { })).Should().Throw<ArgumentOutOfRangeException>(); + } + + [Test] + public void CanAddPropertyOfInheritedType() + { + var properties = new List<object>(); + var map = new StubPropertyContainerMapper<InheritedEntitySimple>(properties); + map.Property(typeof(InheritedEntitySimple).GetProperty("Name"), x => { }); + + properties.Should().Have.Count.EqualTo(1); + properties.First().Should().Be.OfType<HbmProperty>().And.ValueOf.Name.Should().Be.EqualTo("Name"); + } + + [Test] + public void CallAnyMapper() + { + var properties = new List<object>(); + var map = new StubPropertyContainerMapper<EntitySimple>(properties); + var called = false; + map.Any(typeof(MyClass).GetProperty("Reference"), typeof(int), x => called = true); + + called.Should().Be.True(); + } + + [Test] + public void CallDictionaryMappers() + { + var properties = new List<object>(); + var map = new StubPropertyContainerMapper<EntitySimple>(properties); + var collectionPropsCalled = false; + var keyRelationCalled = false; + var elementRelationCalled = false; + map.Map(typeof (MyClassWithDictionary).GetProperty("Dictionary"), cp => collectionPropsCalled = true, + km => keyRelationCalled = true, er => elementRelationCalled = true); + + collectionPropsCalled.Should().Be.True(); + keyRelationCalled.Should().Be.True(); + elementRelationCalled.Should().Be.True(); + } + + private class HackPropertyContainerMapper : AbstractPropertyContainerMapper + { + public HackPropertyContainerMapper(System.Type container, HbmMapping mapDoc) : base(container, mapDoc) {} + + #region Overrides of AbstractPropertyContainerMapper + + protected override void AddProperty(object property) + { + throw new NotImplementedException(); + } + + #endregion + } + + private class StubPropertyContainerMapper<T> : AbstractPropertyContainerMapper + { + private readonly ICollection<object> elements; + + public StubPropertyContainerMapper(ICollection<object> elements) + : base(typeof(T), new HbmMapping()) + { + this.elements = elements; + } + + #region Overrides of AbstractClassMapping<StateProvince> + + protected override void AddProperty(object property) + { + elements.Add(property); + } + + #endregion + } + } +} \ No newline at end of file Modified: trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2011-04-04 17:49:26 UTC (rev 5604) +++ trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2011-04-04 18:22:58 UTC (rev 5605) @@ -522,6 +522,7 @@ <Compile Include="MappingByCode\ExpliticMappingTests\RootClassPropertiesSplitsTests.cs" /> <Compile Include="MappingByCode\ExpliticMappingTests\VersionTests.cs" /> <Compile Include="MappingByCode\For.cs" /> + <Compile Include="MappingByCode\MappersTests\AbstractPropertyContainerMapperTest.cs" /> <Compile Include="MappingByCode\MappersTests\JoinMapperTests.cs" /> <Compile Include="MappingByCode\NatureDemo\Naturalness\Address.cs" /> <Compile Include="MappingByCode\NatureDemo\Naturalness\Animal.cs" /> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fab...@us...> - 2011-04-04 17:49:32
|
Revision: 5604 http://nhibernate.svn.sourceforge.net/nhibernate/?rev=5604&view=rev Author: fabiomaulo Date: 2011-04-04 17:49:26 +0000 (Mon, 04 Apr 2011) Log Message: ----------- JoinMapper full attributes managed Modified Paths: -------------- trunk/nhibernate/src/NHibernate/Mapping/ByCode/Impl/JoinMapper.cs trunk/nhibernate/src/NHibernate.Test/MappingByCode/MappersTests/JoinMapperTests.cs Modified: trunk/nhibernate/src/NHibernate/Mapping/ByCode/Impl/JoinMapper.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Mapping/ByCode/Impl/JoinMapper.cs 2011-04-04 17:31:15 UTC (rev 5603) +++ trunk/nhibernate/src/NHibernate/Mapping/ByCode/Impl/JoinMapper.cs 2011-04-04 17:49:26 UTC (rev 5604) @@ -18,6 +18,7 @@ public class JoinMapper: AbstractPropertyContainerMapper,IJoinMapper { private readonly HbmJoin hbmJoin; + private readonly KeyMapper keyMapper; public JoinMapper(System.Type container, string splitGroupId, HbmJoin hbmJoin, HbmMapping mapDoc) : base(container, mapDoc) { @@ -35,6 +36,11 @@ { throw new ArgumentOutOfRangeException("splitGroupId", "The table-name cant be empty."); } + if (hbmJoin.key == null) + { + hbmJoin.key = new HbmKey { column1 = container.Name.ToLowerInvariant() + "_key" }; + } + keyMapper = new KeyMapper(container, hbmJoin.key); } public event TableNameChangedHandler TableNameChanged; @@ -125,6 +131,7 @@ public void Key(Action<IKeyMapper> keyMapping) { + keyMapping(keyMapper); } public void Inverse(bool value) Modified: trunk/nhibernate/src/NHibernate.Test/MappingByCode/MappersTests/JoinMapperTests.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Test/MappingByCode/MappersTests/JoinMapperTests.cs 2011-04-04 17:31:15 UTC (rev 5603) +++ trunk/nhibernate/src/NHibernate.Test/MappingByCode/MappersTests/JoinMapperTests.cs 2011-04-04 17:49:26 UTC (rev 5604) @@ -176,5 +176,43 @@ mapper.Fetch(FetchKind.Select); hbmJoin.fetch.Should().Be(HbmJoinFetch.Select); } + + [Test] + public void CallKeyMapper() + { + var mapdoc = new HbmMapping(); + var hbmJoin = new HbmJoin(); + var mapper = new JoinMapper(typeof(MyClass), "AA", hbmJoin, mapdoc); + var keyMapperCalled = false; + + mapper.Key(km => keyMapperCalled = true); + + keyMapperCalled.Should().Be.True(); + } + + [Test] + public void WhenCallKeyMapperThenKeyMapperIsNotNull() + { + var mapdoc = new HbmMapping(); + var hbmJoin = new HbmJoin(); + var mapper = new JoinMapper(typeof(MyClass), "AA", hbmJoin, mapdoc); + + mapper.Key(km => km.Should().Not.Be.Null()); + } + + [Test] + public void WhenCallKeyMapperMoreThanOnceThenKeyMapperIsTheSame() + { + var mapdoc = new HbmMapping(); + var hbmJoin = new HbmJoin(); + var mapper = new JoinMapper(typeof(MyClass), "AA", hbmJoin, mapdoc); + IKeyMapper firstCallInstance = null; + IKeyMapper secondCallInstance= null; + + mapper.Key(km => firstCallInstance = km); + mapper.Key(km => secondCallInstance = km); + + firstCallInstance.Should().Be.SameInstanceAs(secondCallInstance); + } } } \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |