Skip to content

NH-3779 - Allow map structures as components in mapping by code #420

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 29, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 50 additions & 12 deletions src/NHibernate.Test/NHSpecificTest/NH901/Fixture.cs
Original file line number Diff line number Diff line change
@@ -1,19 +1,13 @@
using System.Collections;
using NHibernate.Cfg;
using NHibernate.Mapping.ByCode;
using NHibernate.Type;
using NUnit.Framework;

using System;
using System.Collections.Generic;
using System.Text;

namespace NHibernate.Test.NHSpecificTest.NH901
{
[TestFixture]
public class Fixture : BugTestCase
public abstract class FixtureBase : TestCase
{
public override string BugNumber
{
get { return "NH901"; }
}

private new ISession OpenSession(IInterceptor interceptor)
{
lastOpenedSession = sessions.OpenSession(interceptor);
Expand Down Expand Up @@ -99,12 +93,56 @@ public void ReplaceValueTypeComponentWithSameValueDoesNotMakeItDirty()
}
}

[TestFixture]
public class Fixture : FixtureBase
{
protected override string MappingsAssembly
{
get { return "NHibernate.Test"; }
}

protected override IList Mappings
{
get { return new[] {"NHSpecificTest.NH901.Mappings.hbm.xml"}; }
}
}

[TestFixture]
public class FixtureByCode : FixtureBase
{
protected override IList Mappings
{
get { return new string[0]; }
}

protected override string MappingsAssembly
{
get { return null; }
}

protected override void AddMappings(Configuration configuration)
{
var mapper = new ModelMapper();
mapper.Class<Person>(rc =>
{
rc.Table("NH901_Person");
rc.Id(x => x.Name, m => m.Generator(Generators.Assigned));
rc.Component(x => x.Address, cm =>
{
cm.Property(x => x.City);
cm.Property(x => x.Street);
});
});
configuration.AddMapping(mapper.CompileMappingForAllExplicitlyAddedEntities());
}
}

public class InterceptorStub : EmptyInterceptor
{
public object entityToCheck;
public bool entityWasDeemedDirty = false;

public override bool OnFlushDirty(object entity, object id, object[] currentState, object[] previousState, string[] propertyNames, NHibernate.Type.IType[] types)
public override bool OnFlushDirty(object entity, object id, object[] currentState, object[] previousState, string[] propertyNames, IType[] types)
{
if (entity == entityToCheck) { entityWasDeemedDirty = true; }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

namespace NHibernate.Mapping.ByCode.Conformist
{
public class ComponentMapping<T> : ComponentCustomizer<T> where T : class
public class ComponentMapping<T> : ComponentCustomizer<T>
{
public ComponentMapping() : base(new ExplicitDeclarationsHolder(), new CustomizersHolder()) { }
}
Expand Down
3 changes: 2 additions & 1 deletion src/NHibernate/Mapping/ByCode/IBagPropertiesMapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@ namespace NHibernate.Mapping.ByCode
{
public interface IBagPropertiesMapper : ICollectionPropertiesMapper {}

public interface IBagPropertiesMapper<TEntity, TElement> : ICollectionPropertiesMapper<TEntity, TElement> where TEntity : class {}
public interface IBagPropertiesMapper<TEntity, TElement> : ICollectionPropertiesMapper<TEntity, TElement>
{}
}
8 changes: 4 additions & 4 deletions src/NHibernate/Mapping/ByCode/IClassMapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,10 @@ public interface IClassAttributesMapper<TEntity> : IEntityAttributesMapper, IEnt
void Id<TProperty>(Expression<Func<TEntity, TProperty>> idProperty, Action<IIdMapper> idMapper);
void Id(string notVisiblePropertyOrFieldName, Action<IIdMapper> idMapper);

void ComponentAsId<TComponent>(Expression<Func<TEntity, TComponent>> idProperty) where TComponent : class;
void ComponentAsId<TComponent>(Expression<Func<TEntity, TComponent>> idProperty, Action<IComponentAsIdMapper<TComponent>> idMapper) where TComponent : class;
void ComponentAsId<TComponent>(string notVisiblePropertyOrFieldName) where TComponent : class;
void ComponentAsId<TComponent>(string notVisiblePropertyOrFieldName, Action<IComponentAsIdMapper<TComponent>> idMapper) where TComponent : class;
void ComponentAsId<TComponent>(Expression<Func<TEntity, TComponent>> idProperty);
void ComponentAsId<TComponent>(Expression<Func<TEntity, TComponent>> idProperty, Action<IComponentAsIdMapper<TComponent>> idMapper);
void ComponentAsId<TComponent>(string notVisiblePropertyOrFieldName);
void ComponentAsId<TComponent>(string notVisiblePropertyOrFieldName, Action<IComponentAsIdMapper<TComponent>> idMapper);

void ComposedId(Action<IComposedIdMapper<TEntity>> idPropertiesMapping);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public interface ICollectionPropertiesMapper : IEntityPropertyMapper, ICollectio
void Persister(System.Type persister);
}

public interface ICollectionPropertiesMapper<TEntity, TElement> : IEntityPropertyMapper, ICollectionSqlsMapper where TEntity : class
public interface ICollectionPropertiesMapper<TEntity, TElement> : IEntityPropertyMapper, ICollectionSqlsMapper
{
void Inverse(bool value);
void Mutable(bool value);
Expand Down
3 changes: 2 additions & 1 deletion src/NHibernate/Mapping/ByCode/IComponentMapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,6 @@ public interface IComponentAttributesMapper<TComponent> : IEntityPropertyMapper
void Class<TConcrete>() where TConcrete : TComponent;
}

public interface IComponentMapper<TComponent> : IComponentAttributesMapper<TComponent>, IPropertyContainerMapper<TComponent> where TComponent : class {}
public interface IComponentMapper<TComponent> : IComponentAttributesMapper<TComponent>, IPropertyContainerMapper<TComponent>
{}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public interface IDynamicComponentAttributesMapper<TComponent> : IEntityProperty
void Unique(bool unique);
}

public interface IDynamicComponentMapper<TComponent> : IDynamicComponentAttributesMapper<TComponent>, IPropertyContainerMapper<TComponent> where TComponent : class { }
public interface IDynamicComponentMapper<TComponent> : IDynamicComponentAttributesMapper<TComponent>, IPropertyContainerMapper<TComponent>
{ }

}
2 changes: 1 addition & 1 deletion src/NHibernate/Mapping/ByCode/IIdBagPropertiesMapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ public interface IIdBagPropertiesMapper : ICollectionPropertiesMapper
void Id(Action<ICollectionIdMapper> idMapping);
}

public interface IIdBagPropertiesMapper<TEntity, TElement> : ICollectionPropertiesMapper<TEntity, TElement> where TEntity : class
public interface IIdBagPropertiesMapper<TEntity, TElement> : ICollectionPropertiesMapper<TEntity, TElement>
{
void Id(Action<ICollectionIdMapper> idMapping);
}
Expand Down
2 changes: 1 addition & 1 deletion src/NHibernate/Mapping/ByCode/IKeyMapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public interface IKeyMapper : IColumnsMapper
void ForeignKey(string foreignKeyName);
}

public interface IKeyMapper<TEntity> : IColumnsMapper where TEntity : class
public interface IKeyMapper<TEntity> : IColumnsMapper
{
void OnDelete(OnDeleteAction deleteAction);
void PropertyRef<TProperty>(Expression<Func<TEntity, TProperty>> propertyGetter);
Expand Down
2 changes: 1 addition & 1 deletion src/NHibernate/Mapping/ByCode/IListPropertiesMapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ public interface IListPropertiesMapper : ICollectionPropertiesMapper
void Index(Action<IListIndexMapper> listIndexMapping);
}

public interface IListPropertiesMapper<TEntity, TElement> : ICollectionPropertiesMapper<TEntity, TElement> where TEntity : class
public interface IListPropertiesMapper<TEntity, TElement> : ICollectionPropertiesMapper<TEntity, TElement>
{
void Index(Action<IListIndexMapper> listIndexMapping);
}
Expand Down
3 changes: 2 additions & 1 deletion src/NHibernate/Mapping/ByCode/IMapPropertiesMapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@ namespace NHibernate.Mapping.ByCode
{
public interface IMapPropertiesMapper : ICollectionPropertiesMapper {}

public interface IMapPropertiesMapper<TEntity, TKey, TElement> : ICollectionPropertiesMapper<TEntity, TElement> where TEntity : class {}
public interface IMapPropertiesMapper<TEntity, TKey, TElement> : ICollectionPropertiesMapper<TEntity, TElement>
{}
}
20 changes: 7 additions & 13 deletions src/NHibernate/Mapping/ByCode/IPlainPropertyContainerMapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,19 +37,13 @@ public interface IMinimalPlainPropertyContainerMapper<TContainer>

public interface IBasePlainPropertyContainerMapper<TContainer> : IMinimalPlainPropertyContainerMapper<TContainer>
{
void Component<TComponent>(Expression<Func<TContainer, TComponent>> property,
Action<IComponentMapper<TComponent>> mapping) where TComponent : class;
void Component<TComponent>(Expression<Func<TContainer, TComponent>> property) where TComponent : class;
void Component<TComponent>(Expression<Func<TContainer, IDictionary>> property,
TComponent dynamicComponentTemplate,
Action<IDynamicComponentMapper<TComponent>> mapping) where TComponent : class;

void Component<TComponent>(string notVisiblePropertyOrFieldName,
Action<IComponentMapper<TComponent>> mapping) where TComponent : class;
void Component<TComponent>(string notVisiblePropertyOrFieldName) where TComponent : class;
void Component<TComponent>(string notVisiblePropertyOrFieldName,
TComponent dynamicComponentTemplate,
Action<IDynamicComponentMapper<TComponent>> mapping) where TComponent : class;
void Component<TComponent>(Expression<Func<TContainer, TComponent>> property, Action<IComponentMapper<TComponent>> mapping);
void Component<TComponent>(Expression<Func<TContainer, TComponent>> property);
void Component<TComponent>(Expression<Func<TContainer, IDictionary>> property, TComponent dynamicComponentTemplate, Action<IDynamicComponentMapper<TComponent>> mapping);

void Component<TComponent>(string notVisiblePropertyOrFieldName, Action<IComponentMapper<TComponent>> mapping);
void Component<TComponent>(string notVisiblePropertyOrFieldName);
void Component<TComponent>(string notVisiblePropertyOrFieldName, TComponent dynamicComponentTemplate, Action<IDynamicComponentMapper<TComponent>> mapping);

void Any<TProperty>(Expression<Func<TContainer, TProperty>> property, System.Type idTypeOfMetaType, Action<IAnyMapper> mapping) where TProperty : class;
void Any<TProperty>(string notVisiblePropertyOrFieldName, System.Type idTypeOfMetaType, Action<IAnyMapper> mapping) where TProperty : class;
Expand Down
5 changes: 3 additions & 2 deletions src/NHibernate/Mapping/ByCode/IPropertyContainerMapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ void IdBag(MemberInfo property, Action<IIdBagPropertiesMapper> collectionMapping

public interface IPropertyContainerMapper : ICollectionPropertiesContainerMapper, IPlainPropertyContainerMapper {}

public interface ICollectionPropertiesContainerMapper<TEntity> where TEntity : class
public interface ICollectionPropertiesContainerMapper<TEntity>
{
void Set<TElement>(Expression<Func<TEntity, IEnumerable<TElement>>> property,
Action<ISetPropertiesMapper<TEntity, TElement>> collectionMapping,
Expand Down Expand Up @@ -92,5 +92,6 @@ void IdBag<TElement>(string notVisiblePropertyOrFieldName,
Action<IIdBagPropertiesMapper<TEntity, TElement>> collectionMapping);
}

public interface IPropertyContainerMapper<TEntity> : ICollectionPropertiesContainerMapper<TEntity>, IPlainPropertyContainerMapper<TEntity> where TEntity : class {}
public interface IPropertyContainerMapper<TEntity> : ICollectionPropertiesContainerMapper<TEntity>, IPlainPropertyContainerMapper<TEntity>
{}
}
3 changes: 2 additions & 1 deletion src/NHibernate/Mapping/ByCode/ISetPropertiesMapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@ namespace NHibernate.Mapping.ByCode
{
public interface ISetPropertiesMapper : ICollectionPropertiesMapper {}

public interface ISetPropertiesMapper<TEntity, TElement> : ICollectionPropertiesMapper<TEntity, TElement> where TEntity : class {}
public interface ISetPropertiesMapper<TEntity, TElement> : ICollectionPropertiesMapper<TEntity, TElement>
{}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace NHibernate.Mapping.ByCode.Impl.CustomizersImpl
{
public class BagPropertiesCustomizer<TEntity, TElement> : CollectionPropertiesCustomizer<TEntity, TElement>, IBagPropertiesMapper<TEntity, TElement> where TEntity : class
public class BagPropertiesCustomizer<TEntity, TElement> : CollectionPropertiesCustomizer<TEntity, TElement>, IBagPropertiesMapper<TEntity, TElement>
{
public BagPropertiesCustomizer(IModelExplicitDeclarationsHolder explicitDeclarationsHolder, PropertyPath propertyPath, ICustomizersHolder customizersHolder)
: base(explicitDeclarationsHolder, propertyPath, customizersHolder)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,29 +66,29 @@ public void Id(string notVisiblePropertyOrFieldName, Action<IIdMapper> idMapper)
CustomizersHolder.AddCustomizer(typeof(TEntity), m => m.Id(member, idMapper));
}

public void ComponentAsId<TComponent>(Expression<Func<TEntity, TComponent>> idProperty) where TComponent : class
public void ComponentAsId<TComponent>(Expression<Func<TEntity, TComponent>> idProperty)
{
ComponentAsId(idProperty, x => { });
}

public void ComponentAsId<TComponent>(Expression<Func<TEntity, TComponent>> idProperty, Action<IComponentAsIdMapper<TComponent>> idMapper) where TComponent : class
public void ComponentAsId<TComponent>(Expression<Func<TEntity, TComponent>> idProperty, Action<IComponentAsIdMapper<TComponent>> idMapper)
{
var memberOf = TypeExtensions.DecodeMemberAccessExpressionOf(idProperty);
RegisterComponentAsIdMapping(idMapper, memberOf);
}

public void ComponentAsId<TComponent>(string notVisiblePropertyOrFieldName) where TComponent : class
public void ComponentAsId<TComponent>(string notVisiblePropertyOrFieldName)
{
ComponentAsId<TComponent>(notVisiblePropertyOrFieldName, x => { });
}

public void ComponentAsId<TComponent>(string notVisiblePropertyOrFieldName, Action<IComponentAsIdMapper<TComponent>> idMapper) where TComponent : class
public void ComponentAsId<TComponent>(string notVisiblePropertyOrFieldName, Action<IComponentAsIdMapper<TComponent>> idMapper)
{
var member = typeof(TEntity).GetPropertyOrFieldMatchingName(notVisiblePropertyOrFieldName);
RegisterComponentAsIdMapping(idMapper, member);
}

private void RegisterComponentAsIdMapping<TComponent>(Action<IComponentAsIdMapper<TComponent>> idMapper, params MemberInfo[] members) where TComponent : class
private void RegisterComponentAsIdMapping<TComponent>(Action<IComponentAsIdMapper<TComponent>> idMapper, params MemberInfo[] members)
{
foreach (var member in members)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
namespace NHibernate.Mapping.ByCode.Impl.CustomizersImpl
{
public class CollectionKeyCustomizer<TEntity> : IKeyMapper<TEntity>
where TEntity : class
{
private readonly PropertyPath propertyPath;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
namespace NHibernate.Mapping.ByCode.Impl.CustomizersImpl
{
public class CollectionPropertiesCustomizer<TEntity, TElement> : ICollectionPropertiesMapper<TEntity, TElement>
where TEntity : class
{
private readonly IKeyMapper<TEntity> keyMapper;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace NHibernate.Mapping.ByCode.Impl.CustomizersImpl
{
public class ComponentAsIdCustomizer<TComponent> : PropertyContainerCustomizer<TComponent>, IComponentAsIdMapper<TComponent> where TComponent : class
public class ComponentAsIdCustomizer<TComponent> : PropertyContainerCustomizer<TComponent>, IComponentAsIdMapper<TComponent>
{
public ComponentAsIdCustomizer(IModelExplicitDeclarationsHolder explicitDeclarationsHolder, ICustomizersHolder customizersHolder, PropertyPath propertyPath)
: base(explicitDeclarationsHolder, customizersHolder, propertyPath)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
namespace NHibernate.Mapping.ByCode.Impl.CustomizersImpl
{
public class ComponentCustomizer<TComponent> : PropertyContainerCustomizer<TComponent>, IComponentMapper<TComponent>, IConformistHoldersProvider
where TComponent : class
{
public ComponentCustomizer(IModelExplicitDeclarationsHolder explicitDeclarationsHolder, ICustomizersHolder customizersHolder)
: base(explicitDeclarationsHolder, customizersHolder, null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace NHibernate.Mapping.ByCode.Impl.CustomizersImpl
{
public class DynamicComponentCustomizer<TComponent> : PropertyContainerCustomizer<TComponent>, IDynamicComponentMapper<TComponent> where TComponent : class
public class DynamicComponentCustomizer<TComponent> : PropertyContainerCustomizer<TComponent>, IDynamicComponentMapper<TComponent>
{
public DynamicComponentCustomizer(IModelExplicitDeclarationsHolder explicitDeclarationsHolder, ICustomizersHolder customizersHolder, PropertyPath propertyPath)
: base(explicitDeclarationsHolder, customizersHolder, propertyPath)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace NHibernate.Mapping.ByCode.Impl.CustomizersImpl
{
public class IdBagPropertiesCustomizer<TEntity, TElement> : CollectionPropertiesCustomizer<TEntity, TElement>, IIdBagPropertiesMapper<TEntity, TElement> where TEntity : class
public class IdBagPropertiesCustomizer<TEntity, TElement> : CollectionPropertiesCustomizer<TEntity, TElement>, IIdBagPropertiesMapper<TEntity, TElement>
{
public IdBagPropertiesCustomizer(IModelExplicitDeclarationsHolder explicitDeclarationsHolder, PropertyPath propertyPath, ICustomizersHolder customizersHolder)
: base(explicitDeclarationsHolder, propertyPath, customizersHolder)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace NHibernate.Mapping.ByCode.Impl.CustomizersImpl
{
public class ListPropertiesCustomizer<TEntity, TElement> : CollectionPropertiesCustomizer<TEntity, TElement>, IListPropertiesMapper<TEntity, TElement> where TEntity : class
public class ListPropertiesCustomizer<TEntity, TElement> : CollectionPropertiesCustomizer<TEntity, TElement>, IListPropertiesMapper<TEntity, TElement>
{
public ListPropertiesCustomizer(IModelExplicitDeclarationsHolder explicitDeclarationsHolder, PropertyPath propertyPath, ICustomizersHolder customizersHolder)
: base(explicitDeclarationsHolder, propertyPath, customizersHolder)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
namespace NHibernate.Mapping.ByCode.Impl.CustomizersImpl
{
public class MapPropertiesCustomizer<TEntity, TKey, TElement> : CollectionPropertiesCustomizer<TEntity, TElement>, IMapPropertiesMapper<TEntity, TKey, TElement>
where TEntity : class
{
public MapPropertiesCustomizer(IModelExplicitDeclarationsHolder explicitDeclarationsHolder, PropertyPath propertyPath, ICustomizersHolder customizersHolder)
: base(explicitDeclarationsHolder, propertyPath, customizersHolder)
Expand Down
Loading