|
From: <fab...@us...> - 2011-04-19 18:56:15
|
Revision: 5722
http://nhibernate.svn.sourceforge.net/nhibernate/?rev=5722&view=rev
Author: fabiomaulo
Date: 2011-04-19 18:56:09 +0000 (Tue, 19 Apr 2011)
Log Message:
-----------
Apply accessor on component-parent
Modified Paths:
--------------
trunk/nhibernate/src/NHibernate/Mapping/ByCode/ConventionModelMapper.cs
trunk/nhibernate/src/NHibernate/Mapping/ByCode/ModelMapper.cs
trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj
Added Paths:
-----------
trunk/nhibernate/src/NHibernate.Test/MappingByCode/ConventionModelMapperTests/ComponetsParentAccessorTests.cs
Modified: trunk/nhibernate/src/NHibernate/Mapping/ByCode/ConventionModelMapper.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/Mapping/ByCode/ConventionModelMapper.cs 2011-04-19 18:04:58 UTC (rev 5721)
+++ trunk/nhibernate/src/NHibernate/Mapping/ByCode/ConventionModelMapper.cs 2011-04-19 18:56:09 UTC (rev 5722)
@@ -22,6 +22,9 @@
BeforeMapProperty += MemberNoSetterToField;
BeforeMapProperty += MemberReadOnlyAccessor;
+ BeforeMapComponent += ComponentParentToFieldAccessor;
+ BeforeMapComponent += ComponentParentNoSetterToField;
+
BeforeMapBag += MemberToFieldAccessor;
BeforeMapSet += MemberToFieldAccessor;
BeforeMapMap += MemberToFieldAccessor;
@@ -46,6 +49,32 @@
BeforeMapAny += MemberReadOnlyAccessor;
}
+ protected virtual void ComponentParentToFieldAccessor(IModelInspector modelinspector, PropertyPath member, IComponentAttributesMapper componentMapper)
+ {
+ System.Type componentType = member.LocalMember.GetPropertyOrFieldType();
+ IEnumerable<MemberInfo> persistentProperties =
+ MembersProvider.GetComponentMembers(componentType).Where(p => ModelInspector.IsPersistentProperty(p));
+
+ MemberInfo parentReferenceProperty = GetComponentParentReferenceProperty(persistentProperties, member.LocalMember.ReflectedType);
+ if (parentReferenceProperty != null && MatchPropertyToField(parentReferenceProperty))
+ {
+ componentMapper.Parent(parentReferenceProperty, cp=> cp.Access(Accessor.Field));
+ }
+ }
+
+ protected virtual void ComponentParentNoSetterToField(IModelInspector modelinspector, PropertyPath member, IComponentAttributesMapper componentMapper)
+ {
+ System.Type componentType = member.LocalMember.GetPropertyOrFieldType();
+ IEnumerable<MemberInfo> persistentProperties =
+ MembersProvider.GetComponentMembers(componentType).Where(p => ModelInspector.IsPersistentProperty(p));
+
+ MemberInfo parentReferenceProperty = GetComponentParentReferenceProperty(persistentProperties, member.LocalMember.ReflectedType);
+ if (parentReferenceProperty != null && MatchNoSetterProperty(parentReferenceProperty))
+ {
+ componentMapper.Parent(parentReferenceProperty, cp => cp.Access(Accessor.NoSetter));
+ }
+ }
+
protected virtual void MemberReadOnlyAccessor(IModelInspector modelInspector, PropertyPath member, IAccessorPropertyMapper propertyCustomizer)
{
if (MatchReadOnlyProperty(member.LocalMember))
Modified: trunk/nhibernate/src/NHibernate/Mapping/ByCode/ModelMapper.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/Mapping/ByCode/ModelMapper.cs 2011-04-19 18:04:58 UTC (rev 5721)
+++ trunk/nhibernate/src/NHibernate/Mapping/ByCode/ModelMapper.cs 2011-04-19 18:56:09 UTC (rev 5722)
@@ -1038,11 +1038,7 @@
MemberInfo parentReferenceProperty = GetComponentParentReferenceProperty(persistentProperties, propertiesContainerType);
if (parentReferenceProperty != null)
{
- componentMapper.Parent(parentReferenceProperty,
- componentParentMapper =>
- {
- /* TODO */
- });
+ componentMapper.Parent(parentReferenceProperty);
}
customizerHolder.InvokeCustomizers(componentType, componentMapper);
ForEachMemberPath(member, memberPath, pp => customizerHolder.InvokeCustomizers(pp, componentMapper));
@@ -1243,12 +1239,7 @@
MemberInfo parentReferenceProperty = modelMapper.GetComponentParentReferenceProperty(persistentProperties, ownerType);
if (parentReferenceProperty != null)
{
- x.Parent(parentReferenceProperty,
- componentParentMapper =>
- {
- /* TODO */
- }
- );
+ x.Parent(parentReferenceProperty);
}
customizersHolder.InvokeCustomizers(componentType, x);
@@ -1300,10 +1291,7 @@
MemberInfo parentReferenceProperty = modelMapper.GetComponentParentReferenceProperty(componentProperties, componentOwnerType);
if (parentReferenceProperty != null)
{
- x.Parent(parentReferenceProperty, componentParentMapper =>
- {
- /* TODO */
- });
+ x.Parent(parentReferenceProperty);
}
customizersHolder.InvokeCustomizers(componentPropertyType, x);
modelMapper.ForEachMemberPath(member, propertyPath, pp => customizersHolder.InvokeCustomizers(pp, x));
Added: trunk/nhibernate/src/NHibernate.Test/MappingByCode/ConventionModelMapperTests/ComponetsParentAccessorTests.cs
===================================================================
--- trunk/nhibernate/src/NHibernate.Test/MappingByCode/ConventionModelMapperTests/ComponetsParentAccessorTests.cs (rev 0)
+++ trunk/nhibernate/src/NHibernate.Test/MappingByCode/ConventionModelMapperTests/ComponetsParentAccessorTests.cs 2011-04-19 18:56:09 UTC (rev 5722)
@@ -0,0 +1,111 @@
+using System.Collections.Generic;
+using System.Linq;
+using NHibernate.Cfg.MappingSchema;
+using NHibernate.Mapping.ByCode;
+using NUnit.Framework;
+using SharpTestsEx;
+
+namespace NHibernate.Test.MappingByCode.ConventionModelMapperTests
+{
+ public class ComponetsParentAccessorTests
+ {
+ private class MyClass
+ {
+ public int Id { get; set; }
+ public MyCompo Compo { get; set; }
+ public IEnumerable<MyCompo> Compos { get; set; }
+ }
+
+ private class MyCompo
+ {
+ private MyClass parent;
+ public MyClass Parent
+ {
+ get { return parent; }
+ }
+
+ public MyNestedCompo NestedCompo { get; set; }
+ }
+
+ private class MyNestedCompo
+ {
+ private MyCompo owner;
+ public MyCompo Owner
+ {
+ get { return owner; }
+ }
+
+ public string Something { get; set; }
+ }
+
+ private HbmMapping GetMappingWithParentInCompo()
+ {
+ var mapper = new ConventionModelMapper();
+ mapper.Class<MyClass>(x =>
+ {
+ x.Id(c => c.Id);
+ x.Component(c => c.Compo);
+ x.Bag(c => c.Compos, cm => { });
+ });
+ mapper.Component<MyCompo>(x =>
+ {
+ x.Parent(c => c.Parent);
+ x.Component(c => c.NestedCompo);
+ });
+ mapper.Component<MyNestedCompo>(x =>
+ {
+ x.Component(c => c.Owner);
+ x.Property(c => c.Something);
+ });
+ return mapper.CompileMappingForAllExplicitAddedEntities();
+ }
+
+ [Test]
+ public void WhenMapComoponetWithNestBidirectionalComponentThenMapParentAccessor()
+ {
+ HbmMapping mapping = GetMappingWithParentInCompo();
+
+ var hbmClass = mapping.RootClasses[0];
+ var hbmMyCompo = hbmClass.Properties.OfType<HbmComponent>().Single();
+ var hbmMyNestedCompo = hbmMyCompo.Properties.OfType<HbmComponent>().Single();
+
+ hbmMyNestedCompo.Parent.access.Should().Contain("camelcase");
+ }
+
+ [Test]
+ public void WhenCollectionOfComoponetsWithNestBidirectionalComponentThenMapParentAccessor()
+ {
+ HbmMapping mapping = GetMappingWithParentInCompo();
+
+ var hbmClass = mapping.RootClasses[0];
+ var hbmBag = hbmClass.Properties.OfType<HbmBag>().Single();
+
+ var hbmMyCompo = (HbmCompositeElement)hbmBag.ElementRelationship;
+ var hbmMyNestedCompo = hbmMyCompo.Properties.OfType<HbmNestedCompositeElement>().Single();
+
+ hbmMyNestedCompo.Parent.access.Should().Contain("camelcase");
+ }
+
+ [Test, Ignore("No fixed yet. When the parent is an entity it should be managed explicitly as explicitly is managed the relation (Parent instead many-to-one)")]
+ public void WhenMapComoponetWithParentThenMapParentAccessor()
+ {
+ HbmMapping mapping = GetMappingWithParentInCompo();
+
+ var hbmClass = mapping.RootClasses[0];
+ var hbmMyCompo = hbmClass.Properties.OfType<HbmComponent>().Single();
+ hbmMyCompo.Parent.access.Should().Contain("camelcase");
+ }
+
+ [Test, Ignore("No fixed yet. When the parent is an entity it should be managed explicitly as explicitly is managed the relation (Parent instead many-to-one)")]
+ public void WhenCollectionOfComoponetsWithParentThenMapParentAccessor()
+ {
+ HbmMapping mapping = GetMappingWithParentInCompo();
+
+ var hbmClass = mapping.RootClasses[0];
+ var hbmBag = hbmClass.Properties.OfType<HbmBag>().Single();
+
+ var hbmMyCompo = (HbmCompositeElement)hbmBag.ElementRelationship;
+ hbmMyCompo.Parent.access.Should().Contain("camelcase");
+ }
+ }
+}
\ 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-19 18:04:58 UTC (rev 5721)
+++ trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2011-04-19 18:56:09 UTC (rev 5722)
@@ -511,6 +511,7 @@
<Compile Include="Linq\ByMethod\SumTests.cs" />
<Compile Include="Logging\Log4NetLoggerTest.cs" />
<Compile Include="Logging\LoggerProviderTest.cs" />
+ <Compile Include="MappingByCode\ConventionModelMapperTests\ComponetsParentAccessorTests.cs" />
<Compile Include="MappingByCode\ConventionModelMapperTests\PropertyToFieldAccessorTest.cs" />
<Compile Include="MappingByCode\ConventionModelMapperTests\SafePoidTests.cs" />
<Compile Include="MappingByCode\ConventionModelMapperTests\VersionOnBaseClassIntegrationTest.cs" />
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|