|
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 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-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/ByC...
[truncated message content] |
|
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 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 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 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 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);
+ hbm...@cl...().Not.Be.NullOrEmpty();
+ hbmId.type.Should().Not.Be.NullOrEmpty();
+ }
+
+ [Test]
+ public void WhenSetGeneratorThenChangeType()
+ {
+ var hbmId = new HbmCollectionId();
+ new CollectionIdMapper(hbmId).Generator(Generators.HighLow);
+
+ hbm...@cl...().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);
+
+ hbm...@cl...().Be.EqualTo("hilo");
+ hbmId.type.Should().Be("Int64");
+ }
+
+ [Test]
+ public void CanSetGenerator()
+ {
+ var hbmId = new HbmCollectionId();
+ new CollectionIdMapper(hbmId).Generator(Generators.HighLow);
+ hbm...@cl...().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" }));
+ hbm...@cl...().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);
+ hbm...@cl...().Be.EqualTo("guid");
+ }
+
+ [Test]
+ public void CanSetGeneratorGuidComb()
+ {
+ var hbmId = new HbmCollectionId();
+ new CollectionIdMapper(hbmId).Generator(Generators.GuidComb);
+ hbm...@cl...().Be.EqualTo("guid.comb");
+ }
+
+ [Test]
+ public void CanSetGeneratorSequence()
+ {
+ var hbmId = new HbmCollectionId();
+ new CollectionIdMapper(hbmId).Generator(Generators.Sequence);
+ hbm...@cl...().Be.EqualTo("sequence");
+ }
+
+ [Test]
+ public void CanSetGeneratorIdentity()
+ {
+ var hbmId = new HbmCollectionId();
+ new CollectionIdMapper(hbmId).Generator(Generators.Identity);
+ hbm...@cl...().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 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-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-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 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 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 memb...
[truncated message content] |
|
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();
+ hbm...@cl...().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 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();
+ hbm...@cl...().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: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();
- hbm...@cl...().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 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-07 17:20:01
|
Revision: 5629
http://nhibernate.svn.sourceforge.net/nhibernate/?rev=5629&view=rev
Author: fabiomaulo
Date: 2011-04-07 17:19:55 +0000 (Thu, 07 Apr 2011)
Log Message:
-----------
Fix NH-2622
Modified Paths:
--------------
trunk/nhibernate/src/NHibernate/NHibernate.csproj
trunk/nhibernate/src/NHibernate/Proxy/DynamicProxy/DefaultArgumentHandler.cs
trunk/nhibernate/src/NHibernate/Proxy/DynamicProxy/DefaultMethodEmitter.cs
trunk/nhibernate/src/NHibernate.Test/DynamicProxyTests/ProxiedMembers/Fixture.cs
Added Paths:
-----------
trunk/nhibernate/src/NHibernate/Proxy/DynamicProxy/OpCodesMap.cs
Modified: trunk/nhibernate/src/NHibernate/NHibernate.csproj
===================================================================
--- trunk/nhibernate/src/NHibernate/NHibernate.csproj 2011-04-06 21:06:29 UTC (rev 5628)
+++ trunk/nhibernate/src/NHibernate/NHibernate.csproj 2011-04-07 17:19:55 UTC (rev 5629)
@@ -499,6 +499,7 @@
<Compile Include="Proxy\DynamicProxy\IProxy.cs" />
<Compile Include="Proxy\DynamicProxy\IProxyCache.cs" />
<Compile Include="Proxy\DynamicProxy\IProxyMethodBuilder.cs" />
+ <Compile Include="Proxy\DynamicProxy\OpCodesMap.cs" />
<Compile Include="Proxy\DynamicProxy\ProxyCache.cs" />
<Compile Include="Proxy\DynamicProxy\ProxyCacheEntry.cs" />
<Compile Include="Proxy\DynamicProxy\ProxyDummy.cs" />
Modified: trunk/nhibernate/src/NHibernate/Proxy/DynamicProxy/DefaultArgumentHandler.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/Proxy/DynamicProxy/DefaultArgumentHandler.cs 2011-04-06 21:06:29 UTC (rev 5628)
+++ trunk/nhibernate/src/NHibernate/Proxy/DynamicProxy/DefaultArgumentHandler.cs 2011-04-07 17:19:55 UTC (rev 5629)
@@ -6,7 +6,6 @@
#endregion
-using System;
using System.Reflection;
using System.Reflection.Emit;
@@ -37,7 +36,7 @@
int argumentPosition = 1;
foreach (ParameterInfo param in parameters)
{
- System.Type parameterType = param.ParameterType;
+ System.Type parameterType = param.ParameterType.IsByRef ? param.ParameterType.GetElementType() : param.ParameterType;
// args[N] = argumentN (pseudocode)
IL.Emit(OpCodes.Ldloc_S, 0);
IL.Emit(OpCodes.Ldc_I4, index);
@@ -54,9 +53,17 @@
IL.Emit(OpCodes.Ldarg, argumentPosition);
- bool isGeneric = parameterType.IsGenericParameter;
+ if (param.ParameterType.IsByRef)
+ {
+ OpCode ldindInstruction;
+ if(!OpCodesMap.TryGetLdindOpCode(param.ParameterType.GetElementType(), out ldindInstruction))
+ {
+ ldindInstruction = OpCodes.Ldind_Ref;
+ }
+ IL.Emit(ldindInstruction);
+ }
- if (parameterType.IsValueType || isGeneric)
+ if (parameterType.IsValueType || param.ParameterType.IsByRef || parameterType.IsGenericParameter)
{
IL.Emit(OpCodes.Box, parameterType);
}
Modified: trunk/nhibernate/src/NHibernate/Proxy/DynamicProxy/DefaultMethodEmitter.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/Proxy/DynamicProxy/DefaultMethodEmitter.cs 2011-04-06 21:06:29 UTC (rev 5628)
+++ trunk/nhibernate/src/NHibernate/Proxy/DynamicProxy/DefaultMethodEmitter.cs 2011-04-07 17:19:55 UTC (rev 5629)
@@ -30,7 +30,6 @@
private static readonly ConstructorInfo notImplementedConstructor = typeof(NotImplementedException).GetConstructor(new System.Type[0]);
- private static readonly Dictionary<string, OpCode> stindMap = new Dictionary<string, OpCode>();
private readonly IArgumentHandler _argumentHandler;
static DefaultMethodEmitter()
@@ -43,23 +42,6 @@
};
infoConstructor = typeof (InvocationInfo).GetConstructor(constructorTypes);
-
-
- stindMap["Bool&"] = OpCodes.Stind_I1;
- stindMap["Int8&"] = OpCodes.Stind_I1;
- stindMap["Uint8&"] = OpCodes.Stind_I1;
-
- stindMap["Int16&"] = OpCodes.Stind_I2;
- stindMap["Uint16&"] = OpCodes.Stind_I2;
-
- stindMap["Uint32&"] = OpCodes.Stind_I4;
- stindMap["Int32&"] = OpCodes.Stind_I4;
-
- stindMap["IntPtr"] = OpCodes.Stind_I4;
- stindMap["Uint64&"] = OpCodes.Stind_I8;
- stindMap["Int64&"] = OpCodes.Stind_I8;
- stindMap["Float32&"] = OpCodes.Stind_R4;
- stindMap["Float64&"] = OpCodes.Stind_R8;
}
public DefaultMethodEmitter() : this(new DefaultArgumentHandler()) {}
@@ -124,8 +106,8 @@
IL.Emit(OpCodes.Ldloc_1);
IL.Emit(OpCodes.Callvirt, handlerMethod);
- SaveRefArguments(IL, parameters);
PackageReturnType(method, IL);
+ SaveRefArguments(IL, parameters);
IL.Emit(OpCodes.Ret);
}
@@ -158,8 +140,7 @@
IL.Emit(OpCodes.Ldc_I4, param.Position);
IL.Emit(OpCodes.Ldelem_Ref);
- typeName = typeName.Replace("&", "");
- System.Type unboxedType = System.Type.GetType(typeName);
+ System.Type unboxedType = param.ParameterType.GetElementType();
IL.Emit(OpCodes.Unbox_Any, unboxedType);
@@ -170,23 +151,16 @@
private static OpCode GetStindInstruction(System.Type parameterType)
{
- if (parameterType.IsClass && !parameterType.Name.EndsWith("&"))
+ if (parameterType.IsByRef)
{
- return OpCodes.Stind_Ref;
+ OpCode stindOpCode;
+ if(OpCodesMap.TryGetStindOpCode(parameterType.GetElementType(), out stindOpCode))
+ {
+ return stindOpCode;
+ }
}
-
- string typeName = parameterType.Name;
-
- if (!stindMap.ContainsKey(typeName) && parameterType.IsByRef)
- {
- return OpCodes.Stind_Ref;
- }
-
- Debug.Assert(stindMap.ContainsKey(typeName));
- OpCode result = stindMap[typeName];
-
- return result;
+ return OpCodes.Stind_Ref;
}
private void PushStackTrace(ILGenerator IL)
Added: trunk/nhibernate/src/NHibernate/Proxy/DynamicProxy/OpCodesMap.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/Proxy/DynamicProxy/OpCodesMap.cs (rev 0)
+++ trunk/nhibernate/src/NHibernate/Proxy/DynamicProxy/OpCodesMap.cs 2011-04-07 17:19:55 UTC (rev 5629)
@@ -0,0 +1,50 @@
+using System;
+using System.Collections.Generic;
+using System.Reflection.Emit;
+
+namespace NHibernate.Proxy.DynamicProxy
+{
+ public static class OpCodesMap
+ {
+ private static readonly Dictionary<System.Type, OpCode> LdindMap = new Dictionary<System.Type, OpCode>
+ {
+ {typeof (Boolean), OpCodes.Ldind_I1},
+ {typeof (SByte), OpCodes.Ldind_I1},
+ {typeof (Byte), OpCodes.Ldind_U1},
+ {typeof (Char), OpCodes.Ldind_I2},
+ {typeof (Int16), OpCodes.Ldind_I2},
+ {typeof (Int32), OpCodes.Ldind_I4},
+ {typeof (Int64), OpCodes.Ldind_I8},
+ {typeof (UInt16), OpCodes.Ldind_U2},
+ {typeof (UInt32), OpCodes.Ldind_U4},
+ {typeof (UInt64), OpCodes.Ldind_I8},
+ {typeof (Single), OpCodes.Ldind_R4},
+ {typeof (Double), OpCodes.Ldind_R8},
+ };
+ private static readonly Dictionary<System.Type, OpCode> StindMap = new Dictionary<System.Type, OpCode>
+ {
+ {typeof (Boolean), OpCodes.Stind_I1},
+ {typeof (SByte), OpCodes.Stind_I1},
+ {typeof (Byte), OpCodes.Stind_I1},
+ {typeof (Char), OpCodes.Stind_I2},
+ {typeof (Int16), OpCodes.Stind_I2},
+ {typeof (Int32), OpCodes.Stind_I4},
+ {typeof (Int64), OpCodes.Stind_I8},
+ {typeof (UInt16), OpCodes.Stind_I2},
+ {typeof (UInt32), OpCodes.Stind_I4},
+ {typeof (UInt64), OpCodes.Stind_I8},
+ {typeof (Single), OpCodes.Stind_R4},
+ {typeof (Double), OpCodes.Stind_R8},
+ };
+
+ public static bool TryGetLdindOpCode(System.Type valueType, out OpCode opCode)
+ {
+ return LdindMap.TryGetValue(valueType, out opCode);
+ }
+
+ public static bool TryGetStindOpCode(System.Type valueType, out OpCode opCode)
+ {
+ return StindMap.TryGetValue(valueType, out opCode);
+ }
+ }
+}
\ 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 21:06:29 UTC (rev 5628)
+++ trunk/nhibernate/src/NHibernate.Test/DynamicProxyTests/ProxiedMembers/Fixture.cs 2011-04-07 17:19:55 UTC (rev 5629)
@@ -20,7 +20,6 @@
public class Fixture
{
[Test]
- [Ignore]
public void Proxy()
{
var factory = new ProxyFactory();
@@ -28,11 +27,11 @@
int x;
c.Method1(out x);
- x.Should().Be(3);
+ Assert.AreEqual(3, x);
x = 4;
c.Method2(ref x);
- x.Should().Be(5);
+ Assert.AreEqual(5, x);
}
}
}
\ 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-07 23:21:28
|
Revision: 5634
http://nhibernate.svn.sourceforge.net/nhibernate/?rev=5634&view=rev
Author: fabiomaulo
Date: 2011-04-07 23:21:21 +0000 (Thu, 07 Apr 2011)
Log Message:
-----------
Fix NH-2632 + minor refactoring
Modified Paths:
--------------
trunk/nhibernate/src/NHibernate/Persister/Entity/AbstractEntityPersister.cs
trunk/nhibernate/src/NHibernate/Tuple/Entity/EntityMetamodel.cs
trunk/nhibernate/src/NHibernate.Test/GhostProperty/GhostPropertyFixture.cs
trunk/nhibernate/src/NHibernate.Test/LazyProperty/LazyPropertyFixture.cs
trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2632/Fixture.cs
Modified: trunk/nhibernate/src/NHibernate/Persister/Entity/AbstractEntityPersister.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/Persister/Entity/AbstractEntityPersister.cs 2011-04-07 20:44:05 UTC (rev 5633)
+++ trunk/nhibernate/src/NHibernate/Persister/Entity/AbstractEntityPersister.cs 2011-04-07 23:21:21 UTC (rev 5634)
@@ -332,7 +332,8 @@
#region PROPERTIES
- bool lazyAvailable = IsInstrumented(EntityMode.Poco);
+ // NH: see consistence with the implementation on EntityMetamodel where we are disabling lazy-properties for no lazy entities
+ bool lazyAvailable = IsInstrumented(EntityMode.Poco) && entityMetamodel.IsLazy;
int hydrateSpan = entityMetamodel.PropertySpan;
propertyColumnSpans = new int[hydrateSpan];
Modified: trunk/nhibernate/src/NHibernate/Tuple/Entity/EntityMetamodel.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/Tuple/Entity/EntityMetamodel.cs 2011-04-07 20:44:05 UTC (rev 5633)
+++ trunk/nhibernate/src/NHibernate/Tuple/Entity/EntityMetamodel.cs 2011-04-07 23:21:21 UTC (rev 5634)
@@ -8,6 +8,7 @@
using NHibernate.Mapping;
using NHibernate.Type;
using NHibernate.Util;
+using Array = NHibernate.Mapping.Array;
namespace NHibernate.Tuple.Entity
{
@@ -126,19 +127,47 @@
bool foundUpdateGeneratedValue = false;
bool foundNonIdentifierPropertyNamedId = false;
HasPocoRepresentation = persistentClass.HasPocoRepresentation;
+
+ // NH: WARNING if we have to disable lazy/unproxy properties we have to do it in the whole process.
+ lazy = persistentClass.IsLazy && (!persistentClass.HasPocoRepresentation || !ReflectHelper.IsFinalClass(persistentClass.ProxyInterface));
+ lazyAvailable &= lazy; // <== Disable lazy properties if the class is marked with lazy=false
+
+ bool hadLazyProperties = false;
+ bool hadNoProxyRelations = false;
foreach (Mapping.Property prop in persistentClass.PropertyClosureIterator)
{
- // NH: A lazy property is a simple property marked with lazy=true or a relation (in this case many-to-one or one-to-one marked as "no-proxy")
- bool lazyProperty = prop.IsLazy && lazyAvailable && (!prop.IsEntityRelation || prop.UnwrapProxy);
+ if (prop.IsLazy)
+ {
+ hadLazyProperties = true;
+ }
+ if(prop.UnwrapProxy)
+ {
+ hadNoProxyRelations = true;
+ }
+ // NH: A lazy property is a simple property marked with lazy=true
+ bool islazyProperty = prop.IsLazy && lazyAvailable && (!prop.IsEntityRelation || prop.UnwrapProxy);
+ // NH: A Relation (in this case many-to-one or one-to-one) marked as "no-proxy"
+ var isUnwrapProxy = prop.UnwrapProxy && lazyAvailable;
+
+ if (islazyProperty || isUnwrapProxy)
+ {
+ // NH: verify property proxiability
+ var getter = prop.GetGetter(persistentClass.MappedClass);
+ if (getter.Method == null || getter.Method.IsDefined(typeof(CompilerGeneratedAttribute), false) == false)
+ {
+ log.ErrorFormat("Lazy or no-proxy property {0}.{1} is not an auto property, which may result in uninitialized property access", persistentClass.EntityName, prop.Name);
+ }
+ }
+
if (prop == persistentClass.Version)
{
tempVersionProperty = i;
- properties[i] = PropertyFactory.BuildVersionProperty(prop, lazyProperty);
+ properties[i] = PropertyFactory.BuildVersionProperty(prop, islazyProperty);
}
else
{
- properties[i] = PropertyFactory.BuildStandardProperty(prop, lazyProperty);
+ properties[i] = PropertyFactory.BuildStandardProperty(prop, islazyProperty);
}
if (prop.IsNaturalIdentifier)
@@ -151,16 +180,16 @@
foundNonIdentifierPropertyNamedId = true;
}
- if (lazyProperty)
+ if (islazyProperty)
{
hasLazy = true;
}
- if (prop.UnwrapProxy)
+ if (isUnwrapProxy)
{
hasUnwrapProxyForProperties = true;
}
- propertyLaziness[i] = lazyProperty;
+ propertyLaziness[i] = islazyProperty;
propertyNames[i] = properties[i].Name;
propertyTypes[i] = properties[i].Type;
@@ -170,7 +199,7 @@
insertInclusions[i] = DetermineInsertValueGenerationType(prop, properties[i]);
updateInclusions[i] = DetermineUpdateValueGenerationType(prop, properties[i]);
propertyVersionability[i] = properties[i].IsVersionable;
- nonlazyPropertyUpdateability[i] = properties[i].IsUpdateable && !lazyProperty;
+ nonlazyPropertyUpdateability[i] = properties[i].IsUpdateable && !islazyProperty;
propertyCheckability[i] = propertyUpdateability[i]
||
(propertyTypes[i].IsAssociationType
@@ -224,36 +253,24 @@
versionPropertyIndex = tempVersionProperty;
hasLazyProperties = hasLazy;
- lazy = persistentClass.IsLazy
- && (!persistentClass.HasPocoRepresentation || !ReflectHelper.IsFinalClass(persistentClass.ProxyInterface));
+ if(hadLazyProperties && !hasLazy)
+ {
+ log.WarnFormat("Disabled lazy properies fetching for {0} beacuse it does not support lazy at the entity level", name);
+ }
if (hasLazy)
{
- if (lazy == false)
- {
- log.WarnFormat("Disabled lazy properies fetching for {0} beacuse it does not support lazy at the entity level", name);
- hasLazyProperties = false;
- }
- else
- {
- log.Info("lazy property fetching available for: " + name);
- VerifyCanInterceptPropertiesForLazyOrGhostProperties(persistentClass);
- }
+ log.Info("lazy property fetching available for: " + name);
}
- if(hasUnwrapProxyForProperties)
+
+ if(hadNoProxyRelations && !hasUnwrapProxyForProperties)
{
- if (lazy == false)
- {
- log.WarnFormat("Disabled ghost properies fetching for {0} beacuse it does not support lazy at the entity level", name);
- hasUnwrapProxyForProperties = false;
- }
- else
- {
- log.Info("Ghost property fetching available for: " + name);
- if (hasLazy == false) // avoid double checking
- VerifyCanInterceptPropertiesForLazyOrGhostProperties(persistentClass);
- }
+ log.WarnFormat("Disabled ghost properies fetching for {0} beacuse it does not support lazy at the entity level", name);
}
+ if (hasUnwrapProxyForProperties)
+ {
+ log.Info("no-proxy property fetching available for: " + name);
+ }
mutable = persistentClass.IsMutable;
@@ -303,23 +320,6 @@
public bool HasPocoRepresentation { get; private set; }
- private static void VerifyCanInterceptPropertiesForLazyOrGhostProperties(PersistentClass persistentClass)
- {
- foreach (var prop in persistentClass.PropertyClosureIterator)
- {
- if (prop.IsLazy == false &&
- prop.UnwrapProxy == false)
- continue;
-
- var getter = prop.GetGetter(persistentClass.MappedClass);
- if(getter.Method == null ||
- getter.Method.IsDefined(typeof(CompilerGeneratedAttribute), false) == false)
- {
- log.ErrorFormat("Lazy or ghost property {0}.{1} is not an auto property, which may result in uninitialized property access", persistentClass.EntityName, prop.Name);
- }
- }
- }
-
private ValueInclusion DetermineInsertValueGenerationType(Mapping.Property mappingProperty, StandardProperty runtimeProperty)
{
if (runtimeProperty.IsInsertGenerated)
Modified: trunk/nhibernate/src/NHibernate.Test/GhostProperty/GhostPropertyFixture.cs
===================================================================
--- trunk/nhibernate/src/NHibernate.Test/GhostProperty/GhostPropertyFixture.cs 2011-04-07 20:44:05 UTC (rev 5633)
+++ trunk/nhibernate/src/NHibernate.Test/GhostProperty/GhostPropertyFixture.cs 2011-04-07 23:21:21 UTC (rev 5634)
@@ -69,7 +69,7 @@
[Test]
public void ShouldGenerateErrorForNonAutoPropGhostProp()
{
- Assert.IsTrue(log.Contains("Lazy or ghost property NHibernate.Test.GhostProperty.Order.Payment is not an auto property, which may result in uninitialized property access"));
+ Assert.IsTrue(log.Contains("NHibernate.Test.GhostProperty.Order.Payment is not an auto property, which may result in uninitialized property access"));
}
[Test]
Modified: trunk/nhibernate/src/NHibernate.Test/LazyProperty/LazyPropertyFixture.cs
===================================================================
--- trunk/nhibernate/src/NHibernate.Test/LazyProperty/LazyPropertyFixture.cs 2011-04-07 20:44:05 UTC (rev 5633)
+++ trunk/nhibernate/src/NHibernate.Test/LazyProperty/LazyPropertyFixture.cs 2011-04-07 23:21:21 UTC (rev 5634)
@@ -76,7 +76,7 @@
[Test]
public void ShouldGenerateErrorForNonAutoPropLazyProp()
{
- Assert.IsTrue(log.Contains("Lazy or ghost property NHibernate.Test.LazyProperty.Book.ALotOfText is not an auto property, which may result in uninitialized property access"));
+ Assert.IsTrue(log.Contains("NHibernate.Test.LazyProperty.Book.ALotOfText is not an auto property, which may result in uninitialized property access"));
}
[Test]
Modified: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2632/Fixture.cs
===================================================================
--- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2632/Fixture.cs 2011-04-07 20:44:05 UTC (rev 5633)
+++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2632/Fixture.cs 2011-04-07 23:21:21 UTC (rev 5634)
@@ -86,7 +86,7 @@
}
}
- [Test, Ignore("Not fixed yet")]
+ [Test]
public void GettingCustomerDoesNotThrow()
{
using (var scenario = new Scenario(Sfi))
@@ -95,7 +95,9 @@
{
Customer customer = null;
Executing.This(()=> customer = session.Get<Customer>(scenario.CustomerId)).Should().NotThrow();
- NHibernateUtil.IsInitialized(customer.Address).Should().Be.False();
+ // An entity defined with lazy=false can't have lazy properties (as reported by the WARNING; see EntityMetamodel class)
+ NHibernateUtil.IsInitialized(customer.Address).Should().Be.True();
+ customer.Address.Should().Be("Bah?!??");
}
}
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <fab...@us...> - 2011-04-08 05:00:35
|
Revision: 5635
http://nhibernate.svn.sourceforge.net/nhibernate/?rev=5635&view=rev
Author: fabiomaulo
Date: 2011-04-08 05:00:29 +0000 (Fri, 08 Apr 2011)
Log Message:
-----------
Fix NH-2627
Modified Paths:
--------------
trunk/nhibernate/src/NHibernate/Impl/CriteriaImpl.cs
trunk/nhibernate/src/NHibernate.Test/Criteria/CriteriaQueryTest.cs
Modified: trunk/nhibernate/src/NHibernate/Impl/CriteriaImpl.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/Impl/CriteriaImpl.cs 2011-04-07 23:21:21 UTC (rev 5634)
+++ trunk/nhibernate/src/NHibernate/Impl/CriteriaImpl.cs 2011-04-08 05:00:29 UTC (rev 5635)
@@ -588,7 +588,7 @@
"Could not find parent for subcriteria in the previous subcriteria. If you see this error, it is a bug");
}
Subcriteria clonedSubCriteria =
- new Subcriteria(clone, currentParent, subcriteria.Path, subcriteria.Alias, subcriteria.JoinType);
+ new Subcriteria(clone, currentParent, subcriteria.Path, subcriteria.Alias, subcriteria.JoinType, subcriteria.WithClause);
clonedSubCriteria.SetLockMode(subcriteria.LockMode);
newParents[subcriteria] = clonedSubCriteria;
}
Modified: trunk/nhibernate/src/NHibernate.Test/Criteria/CriteriaQueryTest.cs
===================================================================
--- trunk/nhibernate/src/NHibernate.Test/Criteria/CriteriaQueryTest.cs 2011-04-07 23:21:21 UTC (rev 5634)
+++ trunk/nhibernate/src/NHibernate.Test/Criteria/CriteriaQueryTest.cs 2011-04-08 05:00:29 UTC (rev 5635)
@@ -2890,6 +2890,31 @@
Assert.IsNull(result[1]);
Assert.IsNull(result[2]);
}
+
+ // test != on one existing value (using clone)
+ var criteria = session.CreateCriteria<Student>()
+ .CreateAlias("PreferredCourse", "pc", JoinType.LeftOuterJoin,
+ Restrictions.Not(Restrictions.Eq("pc.CourseCode", "HIB-A")))
+ .SetProjection(Property.ForName("pc.CourseCode"))
+ .AddOrder(Order.Asc("pc.CourseCode"));
+ var clonedCriteria = CriteriaTransformer.Clone(criteria);
+ result = clonedCriteria.List<string>();
+
+ Assert.AreEqual(3, result.Count);
+
+ // can't be sure of NULL comparison ordering aside from they should
+ // either come first or last
+ if (result[0] == null)
+ {
+ Assert.IsNull(result[1]);
+ Assert.AreEqual("HIB-B", result[2]);
+ }
+ else
+ {
+ Assert.AreEqual("HIB-B", result[0]);
+ Assert.IsNull(result[1]);
+ Assert.IsNull(result[2]);
+ }
session.Delete(gavin);
session.Delete(leonardo);
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <fab...@us...> - 2011-04-08 05:11:40
|
Revision: 5636
http://nhibernate.svn.sourceforge.net/nhibernate/?rev=5636&view=rev
Author: fabiomaulo
Date: 2011-04-08 05:11:33 +0000 (Fri, 08 Apr 2011)
Log Message:
-----------
Fix NH-2612
Modified Paths:
--------------
trunk/nhibernate/src/NHibernate/NHibernate.csproj
trunk/nhibernate/src/NHibernate.Test/GhostProperty/GhostPropertyFixture.cs
trunk/nhibernate/src/NHibernate.Test/HQL/Ast/QuerySubstitutionTest.cs
trunk/nhibernate/src/NHibernate.Test/Linq/CustomExtensionsExample.cs
trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2228/Fixture.cs
trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2527/FixtureWithNoBatcher.cs
Added Paths:
-----------
trunk/nhibernate/src/NHibernate/Cfg/ConfigurationExtensions.cs
Removed Paths:
-------------
trunk/nhibernate/src/NHibernate/Cfg/Loquacious/ConfigurationExtensions.cs
Copied: trunk/nhibernate/src/NHibernate/Cfg/ConfigurationExtensions.cs (from rev 5634, trunk/nhibernate/src/NHibernate/Cfg/Loquacious/ConfigurationExtensions.cs)
===================================================================
--- trunk/nhibernate/src/NHibernate/Cfg/ConfigurationExtensions.cs (rev 0)
+++ trunk/nhibernate/src/NHibernate/Cfg/ConfigurationExtensions.cs 2011-04-08 05:11:33 UTC (rev 5636)
@@ -0,0 +1,145 @@
+using System;
+using NHibernate.Cfg.Loquacious;
+using NHibernate.Context;
+using NHibernate.Hql;
+using NHibernate.Linq.Functions;
+using NHibernate.Util;
+
+namespace NHibernate.Cfg
+{
+ public static class ConfigurationExtensions
+ {
+ public static IFluentSessionFactoryConfiguration SessionFactory(this Configuration configuration)
+ {
+ return new FluentSessionFactoryConfiguration(configuration);
+ }
+
+ public static Configuration SessionFactoryName(this Configuration configuration, string sessionFactoryName)
+ {
+ configuration.SetProperty(Environment.SessionFactoryName, sessionFactoryName);
+ return configuration;
+ }
+
+ public static Configuration Cache(this Configuration configuration, Action<ICacheConfigurationProperties> cacheProperties)
+ {
+ cacheProperties(new CacheConfigurationProperties(configuration));
+ return configuration;
+ }
+
+ public static Configuration CollectionTypeFactory<TCollecionsFactory>(this Configuration configuration)
+ {
+ configuration.SetProperty(Environment.CollectionTypeFactoryClass,
+ typeof(TCollecionsFactory).AssemblyQualifiedName);
+ return configuration;
+ }
+
+ public static Configuration Proxy(this Configuration configuration, Action<IProxyConfigurationProperties> proxyProperties)
+ {
+ proxyProperties(new ProxyConfigurationProperties(configuration));
+ return configuration;
+ }
+
+ public static Configuration HqlQueryTranslator<TQueryTranslator>(this Configuration configuration) where TQueryTranslator : IQueryTranslatorFactory
+ {
+ configuration.SetProperty(Environment.QueryTranslator, typeof(TQueryTranslator).AssemblyQualifiedName);
+ return configuration;
+ }
+
+ public static Configuration LinqToHqlGeneratorsRegistry<TLinqToHqlGeneratorsRegistry>(this Configuration configuration) where TLinqToHqlGeneratorsRegistry : ILinqToHqlGeneratorsRegistry
+ {
+ configuration.SetProperty(Environment.LinqToHqlGeneratorsRegistry, typeof(TLinqToHqlGeneratorsRegistry).AssemblyQualifiedName);
+ return configuration;
+ }
+
+ public static Configuration CurrentSessionContext<TCurrentSessionContext>(this Configuration configuration) where TCurrentSessionContext : ICurrentSessionContext
+ {
+ configuration.SetProperty(Environment.CurrentSessionContextClass, typeof(TCurrentSessionContext).AssemblyQualifiedName);
+ return configuration;
+ }
+
+ public static Configuration Mappings(this Configuration configuration, Action<IMappingsConfigurationProperties> mappingsProperties)
+ {
+ mappingsProperties(new MappingsConfigurationProperties(configuration));
+ return configuration;
+ }
+
+ public static Configuration DataBaseIntegration(this Configuration configuration, Action<IDbIntegrationConfigurationProperties> dataBaseIntegration)
+ {
+ dataBaseIntegration(new DbIntegrationConfigurationProperties(configuration));
+ return configuration;
+ }
+
+ public static Configuration EntityCache<TEntity>(this Configuration configuration, Action<IEntityCacheConfigurationProperties<TEntity>> entityCacheConfiguration)
+ where TEntity : class
+ {
+ var ecc = new EntityCacheConfigurationProperties<TEntity>();
+ entityCacheConfiguration(ecc);
+ if (ecc.Strategy.HasValue)
+ {
+ configuration.SetCacheConcurrencyStrategy(typeof(TEntity).FullName, EntityCacheUsageParser.ToString(ecc.Strategy.Value),
+ ecc.RegionName);
+ }
+ foreach (var collection in ecc.Collections)
+ {
+ configuration.SetCollectionCacheConcurrencyStrategy(collection.Key,
+ EntityCacheUsageParser.ToString(collection.Value.Strategy),
+ collection.Value.RegionName);
+ }
+ return configuration;
+ }
+
+ /// <summary>
+ /// Add a type-definition for mappings.
+ /// </summary>
+ /// <typeparam name="TDef">The peristent type.</typeparam>
+ /// <param name="configuration">The <see cref="Configuration"/> where add the type-definition.</param>
+ /// <param name="typeDefConfiguration">The custom configuration action.</param>
+ /// <returns>The <see cref="Configuration"/>.</returns>
+ /// <remarks>
+ /// <para>
+ /// <list type="bullet">
+ /// <listheader>
+ /// <description>Depending on where you will use the type-definition in the mapping the
+ /// <typeparamref name="TDef"/> can be :
+ /// </description>
+ ///</listheader>
+ ///<item>
+ /// <term><see cref="NHibernate.UserTypes.IUserType"/></term>
+ ///</item>
+ ///<item>
+ /// <term><see cref="NHibernate.UserTypes.IUserCollectionType"/></term>
+ ///</item>
+ ///<item>
+ /// <term><see cref="NHibernate.UserTypes.IUserVersionType"/></term>
+ ///</item>
+ ///<item>
+ /// <term><see cref="NHibernate.Id.IPersistentIdentifierGenerator"/> </term>
+ ///</item>
+ ///</list>
+ /// </para>
+ /// </remarks>
+ public static Configuration TypeDefinition<TDef>(this Configuration configuration, Action<ITypeDefConfigurationProperties> typeDefConfiguration)
+ where TDef : class
+ {
+ if (typeDefConfiguration == null)
+ {
+ return configuration;
+ }
+ var tdConfiguration = new TypeDefConfigurationProperties<TDef>();
+ typeDefConfiguration(tdConfiguration);
+ if(string.IsNullOrEmpty(tdConfiguration.Alias))
+ {
+ return configuration;
+ }
+ var mappings = GetMappings(configuration);
+ mappings.AddTypeDef(tdConfiguration.Alias, typeof(TDef).AssemblyQualifiedName, tdConfiguration.Properties.ToTypeParameters());
+ return configuration;
+ }
+
+ private static Mappings GetMappings(Configuration configuration)
+ {
+ Dialect.Dialect dialect = Dialect.Dialect.GetDialect(configuration.Properties);
+ return configuration.CreateMappings(dialect);
+ }
+ }
+}
\ No newline at end of file
Deleted: trunk/nhibernate/src/NHibernate/Cfg/Loquacious/ConfigurationExtensions.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/Cfg/Loquacious/ConfigurationExtensions.cs 2011-04-08 05:00:29 UTC (rev 5635)
+++ trunk/nhibernate/src/NHibernate/Cfg/Loquacious/ConfigurationExtensions.cs 2011-04-08 05:11:33 UTC (rev 5636)
@@ -1,144 +0,0 @@
-using System;
-using NHibernate.Context;
-using NHibernate.Hql;
-using NHibernate.Linq.Functions;
-using NHibernate.Util;
-
-namespace NHibernate.Cfg.Loquacious
-{
- public static class ConfigurationExtensions
- {
- public static IFluentSessionFactoryConfiguration SessionFactory(this Configuration configuration)
- {
- return new FluentSessionFactoryConfiguration(configuration);
- }
-
- public static Configuration SessionFactoryName(this Configuration configuration, string sessionFactoryName)
- {
- configuration.SetProperty(Environment.SessionFactoryName, sessionFactoryName);
- return configuration;
- }
-
- public static Configuration Cache(this Configuration configuration, Action<ICacheConfigurationProperties> cacheProperties)
- {
- cacheProperties(new CacheConfigurationProperties(configuration));
- return configuration;
- }
-
- public static Configuration CollectionTypeFactory<TCollecionsFactory>(this Configuration configuration)
- {
- configuration.SetProperty(Environment.CollectionTypeFactoryClass,
- typeof(TCollecionsFactory).AssemblyQualifiedName);
- return configuration;
- }
-
- public static Configuration Proxy(this Configuration configuration, Action<IProxyConfigurationProperties> proxyProperties)
- {
- proxyProperties(new ProxyConfigurationProperties(configuration));
- return configuration;
- }
-
- public static Configuration HqlQueryTranslator<TQueryTranslator>(this Configuration configuration) where TQueryTranslator : IQueryTranslatorFactory
- {
- configuration.SetProperty(Environment.QueryTranslator, typeof(TQueryTranslator).AssemblyQualifiedName);
- return configuration;
- }
-
- public static Configuration LinqToHqlGeneratorsRegistry<TLinqToHqlGeneratorsRegistry>(this Configuration configuration) where TLinqToHqlGeneratorsRegistry : ILinqToHqlGeneratorsRegistry
- {
- configuration.SetProperty(Environment.LinqToHqlGeneratorsRegistry, typeof(TLinqToHqlGeneratorsRegistry).AssemblyQualifiedName);
- return configuration;
- }
-
- public static Configuration CurrentSessionContext<TCurrentSessionContext>(this Configuration configuration) where TCurrentSessionContext : ICurrentSessionContext
- {
- configuration.SetProperty(Environment.CurrentSessionContextClass, typeof(TCurrentSessionContext).AssemblyQualifiedName);
- return configuration;
- }
-
- public static Configuration Mappings(this Configuration configuration, Action<IMappingsConfigurationProperties> mappingsProperties)
- {
- mappingsProperties(new MappingsConfigurationProperties(configuration));
- return configuration;
- }
-
- public static Configuration DataBaseIntegration(this Configuration configuration, Action<IDbIntegrationConfigurationProperties> dataBaseIntegration)
- {
- dataBaseIntegration(new DbIntegrationConfigurationProperties(configuration));
- return configuration;
- }
-
- public static Configuration EntityCache<TEntity>(this Configuration configuration, Action<IEntityCacheConfigurationProperties<TEntity>> entityCacheConfiguration)
- where TEntity : class
- {
- var ecc = new EntityCacheConfigurationProperties<TEntity>();
- entityCacheConfiguration(ecc);
- if (ecc.Strategy.HasValue)
- {
- configuration.SetCacheConcurrencyStrategy(typeof(TEntity).FullName, EntityCacheUsageParser.ToString(ecc.Strategy.Value),
- ecc.RegionName);
- }
- foreach (var collection in ecc.Collections)
- {
- configuration.SetCollectionCacheConcurrencyStrategy(collection.Key,
- EntityCacheUsageParser.ToString(collection.Value.Strategy),
- collection.Value.RegionName);
- }
- return configuration;
- }
-
- /// <summary>
- /// Add a type-definition for mappings.
- /// </summary>
- /// <typeparam name="TDef">The peristent type.</typeparam>
- /// <param name="configuration">The <see cref="Configuration"/> where add the type-definition.</param>
- /// <param name="typeDefConfiguration">The custom configuration action.</param>
- /// <returns>The <see cref="Configuration"/>.</returns>
- /// <remarks>
- /// <para>
- /// <list type="bullet">
- /// <listheader>
- /// <description>Depending on where you will use the type-definition in the mapping the
- /// <typeparamref name="TDef"/> can be :
- /// </description>
- ///</listheader>
- ///<item>
- /// <term><see cref="NHibernate.UserTypes.IUserType"/></term>
- ///</item>
- ///<item>
- /// <term><see cref="NHibernate.UserTypes.IUserCollectionType"/></term>
- ///</item>
- ///<item>
- /// <term><see cref="NHibernate.UserTypes.IUserVersionType"/></term>
- ///</item>
- ///<item>
- /// <term><see cref="NHibernate.Id.IPersistentIdentifierGenerator"/> </term>
- ///</item>
- ///</list>
- /// </para>
- /// </remarks>
- public static Configuration TypeDefinition<TDef>(this Configuration configuration, Action<ITypeDefConfigurationProperties> typeDefConfiguration)
- where TDef : class
- {
- if (typeDefConfiguration == null)
- {
- return configuration;
- }
- var tdConfiguration = new TypeDefConfigurationProperties<TDef>();
- typeDefConfiguration(tdConfiguration);
- if(string.IsNullOrEmpty(tdConfiguration.Alias))
- {
- return configuration;
- }
- var mappings = GetMappings(configuration);
- mappings.AddTypeDef(tdConfiguration.Alias, typeof(TDef).AssemblyQualifiedName, tdConfiguration.Properties.ToTypeParameters());
- return configuration;
- }
-
- private static Mappings GetMappings(Configuration configuration)
- {
- Dialect.Dialect dialect = Dialect.Dialect.GetDialect(configuration.Properties);
- return configuration.CreateMappings(dialect);
- }
- }
-}
\ No newline at end of file
Modified: trunk/nhibernate/src/NHibernate/NHibernate.csproj
===================================================================
--- trunk/nhibernate/src/NHibernate/NHibernate.csproj 2011-04-08 05:00:29 UTC (rev 5635)
+++ trunk/nhibernate/src/NHibernate/NHibernate.csproj 2011-04-08 05:11:33 UTC (rev 5636)
@@ -676,7 +676,7 @@
<Compile Include="Cfg\FilterSecondPassArgs.cs" />
<Compile Include="Cfg\Hbm2ddlKeyWords.cs" />
<Compile Include="Cfg\Loquacious\CacheConfiguration.cs" />
- <Compile Include="Cfg\Loquacious\ConfigurationExtensions.cs" />
+ <Compile Include="Cfg\ConfigurationExtensions.cs" />
<Compile Include="Cfg\Loquacious\DbIntegrationConfiguration.cs" />
<Compile Include="Cfg\Loquacious\EntityCacheConfigurationProperties.cs" />
<Compile Include="Cfg\Loquacious\FluentSessionFactoryConfiguration.cs" />
Modified: trunk/nhibernate/src/NHibernate.Test/GhostProperty/GhostPropertyFixture.cs
===================================================================
--- trunk/nhibernate/src/NHibernate.Test/GhostProperty/GhostPropertyFixture.cs 2011-04-08 05:00:29 UTC (rev 5635)
+++ trunk/nhibernate/src/NHibernate.Test/GhostProperty/GhostPropertyFixture.cs 2011-04-08 05:11:33 UTC (rev 5636)
@@ -1,4 +1,5 @@
using System.Collections;
+using NHibernate.Cfg;
using NHibernate.Cfg.Loquacious;
using NHibernate.Tuple.Entity;
using NUnit.Framework;
Modified: trunk/nhibernate/src/NHibernate.Test/HQL/Ast/QuerySubstitutionTest.cs
===================================================================
--- trunk/nhibernate/src/NHibernate.Test/HQL/Ast/QuerySubstitutionTest.cs 2011-04-08 05:00:29 UTC (rev 5635)
+++ trunk/nhibernate/src/NHibernate.Test/HQL/Ast/QuerySubstitutionTest.cs 2011-04-08 05:11:33 UTC (rev 5636)
@@ -1,4 +1,5 @@
using System.Collections.Generic;
+using NHibernate.Cfg;
using NUnit.Framework;
using NHibernate.Cfg.Loquacious;
using SharpTestsEx;
Modified: trunk/nhibernate/src/NHibernate.Test/Linq/CustomExtensionsExample.cs
===================================================================
--- trunk/nhibernate/src/NHibernate.Test/Linq/CustomExtensionsExample.cs 2011-04-08 05:00:29 UTC (rev 5635)
+++ trunk/nhibernate/src/NHibernate.Test/Linq/CustomExtensionsExample.cs 2011-04-08 05:11:33 UTC (rev 5636)
@@ -3,6 +3,7 @@
using System.Linq.Expressions;
using System.Reflection;
using System.Text.RegularExpressions;
+using NHibernate.Cfg;
using NHibernate.Cfg.Loquacious;
using NHibernate.Hql.Ast;
using NHibernate.Linq;
Modified: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2228/Fixture.cs
===================================================================
--- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2228/Fixture.cs 2011-04-08 05:00:29 UTC (rev 5635)
+++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2228/Fixture.cs 2011-04-08 05:11:33 UTC (rev 5636)
@@ -1,4 +1,5 @@
using System;
+using NHibernate.Cfg;
using NUnit.Framework;
using NHibernate.Cfg.Loquacious;
using SharpTestsEx;
Modified: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2527/FixtureWithNoBatcher.cs
===================================================================
--- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2527/FixtureWithNoBatcher.cs 2011-04-08 05:00:29 UTC (rev 5635)
+++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2527/FixtureWithNoBatcher.cs 2011-04-08 05:11:33 UTC (rev 5636)
@@ -1,4 +1,5 @@
using NHibernate.AdoNet;
+using NHibernate.Cfg;
using NHibernate.Cfg.Loquacious;
using NUnit.Framework;
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <fab...@us...> - 2011-04-08 05:24:55
|
Revision: 5637
http://nhibernate.svn.sourceforge.net/nhibernate/?rev=5637&view=rev
Author: fabiomaulo
Date: 2011-04-08 05:24:48 +0000 (Fri, 08 Apr 2011)
Log Message:
-----------
Minor refactoring (class renaming thinking in NH-2611)
Modified Paths:
--------------
trunk/nhibernate/src/NHibernate/Linq/LinqExtensionMethods.cs
trunk/nhibernate/src/NHibernate/Linq/NhQueryable.cs
trunk/nhibernate/src/NHibernate/NHibernate.csproj
Added Paths:
-----------
trunk/nhibernate/src/NHibernate/Linq/DefaultQueryProvider.cs
Removed Paths:
-------------
trunk/nhibernate/src/NHibernate/Linq/NhQueryProvider.cs
Copied: trunk/nhibernate/src/NHibernate/Linq/DefaultQueryProvider.cs (from rev 5634, trunk/nhibernate/src/NHibernate/Linq/NhQueryProvider.cs)
===================================================================
--- trunk/nhibernate/src/NHibernate/Linq/DefaultQueryProvider.cs (rev 0)
+++ trunk/nhibernate/src/NHibernate/Linq/DefaultQueryProvider.cs 2011-04-08 05:24:48 UTC (rev 5637)
@@ -0,0 +1,177 @@
+using System;
+using System.Collections;
+using System.Collections.Generic;
+using System.Linq;
+using System.Linq.Expressions;
+using System.Reflection;
+using NHibernate.Engine;
+using NHibernate.Impl;
+using NHibernate.Type;
+
+namespace NHibernate.Linq
+{
+ public class DefaultQueryProvider : IQueryProvider
+ {
+ private readonly ISessionImplementor _session;
+
+ public DefaultQueryProvider(ISessionImplementor session)
+ {
+ _session = session;
+ }
+
+ public object Execute(Expression expression)
+ {
+ IQuery query;
+ NhLinqExpression nhQuery;
+ NhLinqExpression nhLinqExpression = PrepareQuery(expression, out query, out nhQuery);
+
+ return ExecuteQuery(nhLinqExpression, query, nhQuery);
+ }
+
+ public object ExecuteFuture(Expression expression)
+ {
+ IQuery query;
+ NhLinqExpression nhQuery;
+ NhLinqExpression nhLinqExpression = PrepareQuery(expression, out query, out nhQuery);
+ return ExecuteFutureQuery(nhLinqExpression, query, nhQuery);
+ }
+
+ private NhLinqExpression PrepareQuery(Expression expression, out IQuery query, out NhLinqExpression nhQuery)
+ {
+ var nhLinqExpression = new NhLinqExpression(expression);
+
+ query = _session.CreateQuery(nhLinqExpression);
+
+ nhQuery = query.As<ExpressionQueryImpl>().QueryExpression.As<NhLinqExpression>();
+
+ SetParameters(query, nhLinqExpression.ParameterValuesByName);
+ SetResultTransformerAndAdditionalCriteria(query, nhQuery, nhLinqExpression.ParameterValuesByName);
+ return nhLinqExpression;
+ }
+
+ private object ExecuteFutureQuery(NhLinqExpression nhLinqExpression, IQuery query, NhLinqExpression nhQuery)
+ {
+ MethodInfo method;
+ if (nhLinqExpression.ReturnType == NhLinqExpressionReturnType.Sequence)
+ {
+ method = typeof (IQuery).GetMethod("Future").MakeGenericMethod(nhQuery.Type);
+ }
+ else
+ {
+ method = typeof(IQuery).GetMethod("FutureValue").MakeGenericMethod(nhQuery.Type);
+ }
+
+ var result = method.Invoke(query, new object[0]);
+
+
+
+ if (nhQuery.ExpressionToHqlTranslationResults.PostExecuteTransformer != null)
+ {
+ ((IDelayedValue) result).ExecuteOnEval = nhQuery.ExpressionToHqlTranslationResults.PostExecuteTransformer;
+ }
+
+ return result;
+
+ }
+
+ private object ExecuteQuery(NhLinqExpression nhLinqExpression, IQuery query, NhLinqExpression nhQuery)
+ {
+ var results = query.List();
+
+ if (nhQuery.ExpressionToHqlTranslationResults.PostExecuteTransformer != null)
+ {
+ try
+ {
+ return nhQuery.ExpressionToHqlTranslationResults.PostExecuteTransformer.DynamicInvoke(results.AsQueryable());
+ }
+ catch (TargetInvocationException e)
+ {
+ throw e.InnerException;
+ }
+ }
+
+ if (nhLinqExpression.ReturnType == NhLinqExpressionReturnType.Sequence)
+ {
+ return results.AsQueryable();
+ }
+
+ return results[0];
+ }
+
+ public TResult Execute<TResult>(Expression expression)
+ {
+ return (TResult) Execute(expression);
+ }
+
+ public IQueryable CreateQuery(Expression expression)
+ {
+ var m = ReflectionHelper.GetMethodDefinition((DefaultQueryProvider p) => p.CreateQuery<object>(null)).MakeGenericMethod(expression.Type.GetGenericArguments()[0]);
+
+ return (IQueryable) m.Invoke(this, new[] {expression});
+ }
+
+ public IQueryable<T> CreateQuery<T>(Expression expression)
+ {
+ return new NhQueryable<T>(this, expression);
+ }
+
+ static void SetParameters(IQuery query, IDictionary<string, Tuple<object, IType>> parameters)
+ {
+ foreach (var parameterName in query.NamedParameters)
+ {
+ var param = parameters[parameterName];
+
+ if (param.First == null)
+ {
+ if (typeof(ICollection).IsAssignableFrom(param.Second.ReturnedClass))
+ {
+ query.SetParameterList(parameterName, null, param.Second);
+ }
+ else
+ {
+ query.SetParameter(parameterName, null, param.Second);
+ }
+ }
+ else
+ {
+ if (param.First is ICollection)
+ {
+ query.SetParameterList(parameterName, (ICollection) param.First);
+ }
+ else if (param.Second != null)
+ {
+ query.SetParameter(parameterName, param.First, param.Second);
+ }
+ else
+ {
+ query.SetParameter(parameterName, param.First);
+ }
+ }
+ }
+ }
+
+ public void SetResultTransformerAndAdditionalCriteria(IQuery query, NhLinqExpression nhExpression, IDictionary<string, Tuple<object, IType>> parameters)
+ {
+ query.SetResultTransformer(nhExpression.ExpressionToHqlTranslationResults.ResultTransformer);
+
+ foreach (var criteria in nhExpression.ExpressionToHqlTranslationResults.AdditionalCriteria)
+ {
+ criteria(query, parameters);
+ }
+ }
+ }
+
+ public class Tuple<T1, T2>
+ {
+ public T1 First { get; set; }
+ public T2 Second { get; set; }
+
+ }
+
+ public class Tuple<T1, T2, T3>
+ {
+ public T1 First { get; set; }
+ public T2 Second { get; set; }
+ public T3 Third { get; set; }
+ }
+}
\ No newline at end of file
Modified: trunk/nhibernate/src/NHibernate/Linq/LinqExtensionMethods.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/Linq/LinqExtensionMethods.cs 2011-04-08 05:11:33 UTC (rev 5636)
+++ trunk/nhibernate/src/NHibernate/Linq/LinqExtensionMethods.cs 2011-04-08 05:24:48 UTC (rev 5637)
@@ -53,7 +53,7 @@
throw new NotSupportedException("You can also use the AsFuture() method on NhQueryable");
- var future = ((NhQueryProvider)nhQueryable.Provider).ExecuteFuture(nhQueryable.Expression);
+ var future = ((DefaultQueryProvider)nhQueryable.Provider).ExecuteFuture(nhQueryable.Expression);
return (IEnumerable<T>)future;
}
@@ -63,7 +63,7 @@
if (nhQueryable == null)
throw new NotSupportedException("You can also use the AsFuture() method on NhQueryable");
- var future = ((NhQueryProvider)nhQueryable.Provider).ExecuteFuture(nhQueryable.Expression);
+ var future = ((DefaultQueryProvider)nhQueryable.Provider).ExecuteFuture(nhQueryable.Expression);
if(future is DelayedEnumerator<T>)
{
return new FutureValue<T>(() => ((IEnumerable<T>) future));
Deleted: trunk/nhibernate/src/NHibernate/Linq/NhQueryProvider.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/Linq/NhQueryProvider.cs 2011-04-08 05:11:33 UTC (rev 5636)
+++ trunk/nhibernate/src/NHibernate/Linq/NhQueryProvider.cs 2011-04-08 05:24:48 UTC (rev 5637)
@@ -1,177 +0,0 @@
-using System;
-using System.Collections;
-using System.Collections.Generic;
-using System.Linq;
-using System.Linq.Expressions;
-using System.Reflection;
-using NHibernate.Engine;
-using NHibernate.Impl;
-using NHibernate.Type;
-
-namespace NHibernate.Linq
-{
- public class NhQueryProvider : IQueryProvider
- {
- private readonly ISessionImplementor _session;
-
- public NhQueryProvider(ISessionImplementor session)
- {
- _session = session;
- }
-
- public object Execute(Expression expression)
- {
- IQuery query;
- NhLinqExpression nhQuery;
- NhLinqExpression nhLinqExpression = PrepareQuery(expression, out query, out nhQuery);
-
- return ExecuteQuery(nhLinqExpression, query, nhQuery);
- }
-
- public object ExecuteFuture(Expression expression)
- {
- IQuery query;
- NhLinqExpression nhQuery;
- NhLinqExpression nhLinqExpression = PrepareQuery(expression, out query, out nhQuery);
- return ExecuteFutureQuery(nhLinqExpression, query, nhQuery);
- }
-
- private NhLinqExpression PrepareQuery(Expression expression, out IQuery query, out NhLinqExpression nhQuery)
- {
- var nhLinqExpression = new NhLinqExpression(expression);
-
- query = _session.CreateQuery(nhLinqExpression);
-
- nhQuery = query.As<ExpressionQueryImpl>().QueryExpression.As<NhLinqExpression>();
-
- SetParameters(query, nhLinqExpression.ParameterValuesByName);
- SetResultTransformerAndAdditionalCriteria(query, nhQuery, nhLinqExpression.ParameterValuesByName);
- return nhLinqExpression;
- }
-
- private object ExecuteFutureQuery(NhLinqExpression nhLinqExpression, IQuery query, NhLinqExpression nhQuery)
- {
- MethodInfo method;
- if (nhLinqExpression.ReturnType == NhLinqExpressionReturnType.Sequence)
- {
- method = typeof (IQuery).GetMethod("Future").MakeGenericMethod(nhQuery.Type);
- }
- else
- {
- method = typeof(IQuery).GetMethod("FutureValue").MakeGenericMethod(nhQuery.Type);
- }
-
- var result = method.Invoke(query, new object[0]);
-
-
-
- if (nhQuery.ExpressionToHqlTranslationResults.PostExecuteTransformer != null)
- {
- ((IDelayedValue) result).ExecuteOnEval = nhQuery.ExpressionToHqlTranslationResults.PostExecuteTransformer;
- }
-
- return result;
-
- }
-
- private object ExecuteQuery(NhLinqExpression nhLinqExpression, IQuery query, NhLinqExpression nhQuery)
- {
- var results = query.List();
-
- if (nhQuery.ExpressionToHqlTranslationResults.PostExecuteTransformer != null)
- {
- try
- {
- return nhQuery.ExpressionToHqlTranslationResults.PostExecuteTransformer.DynamicInvoke(results.AsQueryable());
- }
- catch (TargetInvocationException e)
- {
- throw e.InnerException;
- }
- }
-
- if (nhLinqExpression.ReturnType == NhLinqExpressionReturnType.Sequence)
- {
- return results.AsQueryable();
- }
-
- return results[0];
- }
-
- public TResult Execute<TResult>(Expression expression)
- {
- return (TResult) Execute(expression);
- }
-
- public IQueryable CreateQuery(Expression expression)
- {
- var m = ReflectionHelper.GetMethodDefinition((NhQueryProvider p) => p.CreateQuery<object>(null)).MakeGenericMethod(expression.Type.GetGenericArguments()[0]);
-
- return (IQueryable) m.Invoke(this, new[] {expression});
- }
-
- public IQueryable<T> CreateQuery<T>(Expression expression)
- {
- return new NhQueryable<T>(this, expression);
- }
-
- static void SetParameters(IQuery query, IDictionary<string, Tuple<object, IType>> parameters)
- {
- foreach (var parameterName in query.NamedParameters)
- {
- var param = parameters[parameterName];
-
- if (param.First == null)
- {
- if (typeof(ICollection).IsAssignableFrom(param.Second.ReturnedClass))
- {
- query.SetParameterList(parameterName, null, param.Second);
- }
- else
- {
- query.SetParameter(parameterName, null, param.Second);
- }
- }
- else
- {
- if (param.First is ICollection)
- {
- query.SetParameterList(parameterName, (ICollection) param.First);
- }
- else if (param.Second != null)
- {
- query.SetParameter(parameterName, param.First, param.Second);
- }
- else
- {
- query.SetParameter(parameterName, param.First);
- }
- }
- }
- }
-
- public void SetResultTransformerAndAdditionalCriteria(IQuery query, NhLinqExpression nhExpression, IDictionary<string, Tuple<object, IType>> parameters)
- {
- query.SetResultTransformer(nhExpression.ExpressionToHqlTranslationResults.ResultTransformer);
-
- foreach (var criteria in nhExpression.ExpressionToHqlTranslationResults.AdditionalCriteria)
- {
- criteria(query, parameters);
- }
- }
- }
-
- public class Tuple<T1, T2>
- {
- public T1 First { get; set; }
- public T2 Second { get; set; }
-
- }
-
- public class Tuple<T1, T2, T3>
- {
- public T1 First { get; set; }
- public T2 Second { get; set; }
- public T3 Third { get; set; }
- }
-}
\ No newline at end of file
Modified: trunk/nhibernate/src/NHibernate/Linq/NhQueryable.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/Linq/NhQueryable.cs 2011-04-08 05:11:33 UTC (rev 5636)
+++ trunk/nhibernate/src/NHibernate/Linq/NhQueryable.cs 2011-04-08 05:24:48 UTC (rev 5637)
@@ -12,7 +12,7 @@
{
// This constructor is called by our users, create a new IQueryExecutor.
public NhQueryable(ISessionImplementor session)
- : base(new NhQueryProvider(session))
+ : base(new DefaultQueryProvider(session))
{
}
Modified: trunk/nhibernate/src/NHibernate/NHibernate.csproj
===================================================================
--- trunk/nhibernate/src/NHibernate/NHibernate.csproj 2011-04-08 05:11:33 UTC (rev 5636)
+++ trunk/nhibernate/src/NHibernate/NHibernate.csproj 2011-04-08 05:24:48 UTC (rev 5637)
@@ -933,7 +933,7 @@
<Compile Include="Linq\Visitors\ExpressionParameterVisitor.cs" />
<Compile Include="Linq\NhLinqExpression.cs" />
<Compile Include="Linq\NhLinqExpressionReturnType.cs" />
- <Compile Include="Linq\NhQueryProvider.cs" />
+ <Compile Include="Linq\DefaultQueryProvider.cs" />
<Compile Include="Linq\Visitors\ExpressionKeyVisitor.cs" />
<Compile Include="Linq\GroupBy\GroupByAggregateDetectionVisitor.cs" />
<Compile Include="Linq\GroupBy\AggregatingGroupByRewriter.cs" />
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <fab...@us...> - 2011-04-08 14:13:27
|
Revision: 5641
http://nhibernate.svn.sourceforge.net/nhibernate/?rev=5641&view=rev
Author: fabiomaulo
Date: 2011-04-08 14:13:21 +0000 (Fri, 08 Apr 2011)
Log Message:
-----------
Fix NH-2633
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/Mapping/ByCode/Impl/CustomizersImpl/ComponentCustomizer.cs
trunk/nhibernate/src/NHibernate/Mapping/ByCode/Impl/ExplicitDeclarationsHolder.cs
trunk/nhibernate/src/NHibernate/Mapping/ByCode/ModelExplicitDeclarationsHolderExtensions.cs
trunk/nhibernate/src/NHibernate.Test/MappingByCode/ModelExplicitDeclarationsHolderMergeTest.cs
trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj
Added Paths:
-----------
trunk/nhibernate/src/NHibernate.Test/MappingByCode/ExpliticMappingTests/ClassWithComponentsTest.cs
Modified: trunk/nhibernate/src/NHibernate/Mapping/ByCode/ExplicitlyDeclaredModel.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/Mapping/ByCode/ExplicitlyDeclaredModel.cs 2011-04-08 05:48:54 UTC (rev 5640)
+++ trunk/nhibernate/src/NHibernate/Mapping/ByCode/ExplicitlyDeclaredModel.cs 2011-04-08 14:13:21 UTC (rev 5641)
@@ -19,9 +19,9 @@
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> persistentProperties = new HashSet<MemberInfo>();
private readonly HashSet<MemberInfo> poids = new HashSet<MemberInfo>();
private readonly HashSet<MemberInfo> properties = new HashSet<MemberInfo>();
+ private readonly HashSet<MemberInfo> persistentMembers = new HashSet<MemberInfo>();
private readonly HashSet<System.Type> rootEntities = new HashSet<System.Type>();
private readonly HashSet<MemberInfo> sets = new HashSet<MemberInfo>();
private readonly HashSet<System.Type> tablePerClassEntities = new HashSet<System.Type>();
@@ -135,6 +135,11 @@
get { return properties; }
}
+ public IEnumerable<MemberInfo> PersistentMembers
+ {
+ get { return persistentMembers; }
+ }
+
public IEnumerable<SplitDefinition> SplitDefinitions
{
get { return splitDefinitions; }
@@ -284,94 +289,99 @@
public void AddAsOneToOneRelation(MemberInfo member)
{
- persistentProperties.Add(member);
+ persistentMembers.Add(member);
oneToOneRelations.Add(member);
}
public void AddAsManyToOneRelation(MemberInfo member)
{
- persistentProperties.Add(member);
+ persistentMembers.Add(member);
manyToOneRelations.Add(member);
}
public void AddAsManyToManyRelation(MemberInfo member)
{
- persistentProperties.Add(member);
+ persistentMembers.Add(member);
manyToManyRelations.Add(member);
}
public void AddAsOneToManyRelation(MemberInfo member)
{
- persistentProperties.Add(member);
+ persistentMembers.Add(member);
oneToManyRelations.Add(member);
}
public void AddAsAny(MemberInfo member)
{
- persistentProperties.Add(member);
+ persistentMembers.Add(member);
any.Add(member);
}
public void AddAsPoid(MemberInfo member)
{
- persistentProperties.Add(member);
+ persistentMembers.Add(member);
poids.Add(member);
}
public void AddAsVersionProperty(MemberInfo member)
{
- persistentProperties.Add(member);
+ persistentMembers.Add(member);
versionProperties.Add(member);
}
public void AddAsNaturalId(MemberInfo member)
{
- persistentProperties.Add(member);
+ persistentMembers.Add(member);
naturalIds.Add(member);
}
public void AddAsSet(MemberInfo member)
{
- persistentProperties.Add(member);
+ persistentMembers.Add(member);
sets.Add(member);
}
public void AddAsBag(MemberInfo member)
{
- persistentProperties.Add(member);
+ persistentMembers.Add(member);
bags.Add(member);
}
public void AddAsIdBag(MemberInfo member)
{
- persistentProperties.Add(member);
+ persistentMembers.Add(member);
idBags.Add(member);
}
public void AddAsList(MemberInfo member)
{
- persistentProperties.Add(member);
+ persistentMembers.Add(member);
lists.Add(member);
}
public void AddAsArray(MemberInfo member)
{
- persistentProperties.Add(member);
+ persistentMembers.Add(member);
arrays.Add(member);
}
public void AddAsMap(MemberInfo member)
{
- persistentProperties.Add(member);
+ persistentMembers.Add(member);
dictionaries.Add(member);
}
public void AddAsProperty(MemberInfo member)
{
- persistentProperties.Add(member);
+ persistentMembers.Add(member);
properties.Add(member);
}
+ public void AddAsPersistentMember(MemberInfo member)
+ {
+ persistentMembers.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
@@ -484,7 +494,7 @@
public bool IsPersistentProperty(MemberInfo member)
{
- return persistentProperties.Contains(member);
+ return persistentMembers.Contains(member);
}
public bool IsSet(MemberInfo role)
Modified: trunk/nhibernate/src/NHibernate/Mapping/ByCode/FakeModelExplicitDeclarationsHolder.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/Mapping/ByCode/FakeModelExplicitDeclarationsHolder.cs 2011-04-08 05:48:54 UTC (rev 5640)
+++ trunk/nhibernate/src/NHibernate/Mapping/ByCode/FakeModelExplicitDeclarationsHolder.cs 2011-04-08 14:13:21 UTC (rev 5641)
@@ -21,6 +21,7 @@
private readonly IEnumerable<MemberInfo> oneToOneRelations = Enumerable.Empty<MemberInfo>();
private readonly IEnumerable<MemberInfo> poids = Enumerable.Empty<MemberInfo>();
private readonly IEnumerable<MemberInfo> properties = Enumerable.Empty<MemberInfo>();
+ private readonly IEnumerable<MemberInfo> persistentMembers = new HashSet<MemberInfo>();
private readonly IEnumerable<System.Type> rootEntities = Enumerable.Empty<System.Type>();
private readonly IEnumerable<MemberInfo> sets = Enumerable.Empty<MemberInfo>();
private readonly IEnumerable<System.Type> tablePerClassEntities = Enumerable.Empty<System.Type>();
@@ -137,6 +138,11 @@
get { return properties; }
}
+ public IEnumerable<MemberInfo> PersistentMembers
+ {
+ get { return persistentMembers; }
+ }
+
public IEnumerable<SplitDefinition> SplitDefinitions
{
get { return splitDefinitions; }
@@ -193,6 +199,8 @@
public void AddAsMap(MemberInfo member) {}
public void AddAsProperty(MemberInfo member) {}
+ public void AddAsPersistentMember(MemberInfo member){}
+
public void AddAsPropertySplit(System.Type propertyContainer, string splitGroupId, MemberInfo member) {}
#endregion
Modified: trunk/nhibernate/src/NHibernate/Mapping/ByCode/IModelExplicitDeclarationsHolder.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/Mapping/ByCode/IModelExplicitDeclarationsHolder.cs 2011-04-08 05:48:54 UTC (rev 5640)
+++ trunk/nhibernate/src/NHibernate/Mapping/ByCode/IModelExplicitDeclarationsHolder.cs 2011-04-08 14:13:21 UTC (rev 5641)
@@ -42,6 +42,7 @@
IEnumerable<MemberInfo> Arrays { get; }
IEnumerable<MemberInfo> Dictionaries { get; }
IEnumerable<MemberInfo> Properties { get; }
+ IEnumerable<MemberInfo> PersistentMembers { get; }
IEnumerable<SplitDefinition> SplitDefinitions { get; }
IEnumerable<string> GetSplitGroupsFor(System.Type type);
@@ -70,6 +71,7 @@
void AddAsArray(MemberInfo member);
void AddAsMap(MemberInfo member);
void AddAsProperty(MemberInfo member);
+ void AddAsPersistentMember(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/CustomizersImpl/ComponentCustomizer.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/Mapping/ByCode/Impl/CustomizersImpl/ComponentCustomizer.cs 2011-04-08 05:48:54 UTC (rev 5640)
+++ trunk/nhibernate/src/NHibernate/Mapping/ByCode/Impl/CustomizersImpl/ComponentCustomizer.cs 2011-04-08 14:13:21 UTC (rev 5641)
@@ -25,6 +25,10 @@
throw new ArgumentNullException("explicitDeclarationsHolder");
}
explicitDeclarationsHolder.AddAsComponent(typeof (TComponent));
+ if(propertyPath != null)
+ {
+ explicitDeclarationsHolder.AddAsPersistentMember(propertyPath.LocalMember);
+ }
}
#region Implementation of IComponentMapper<TComponent>
Modified: trunk/nhibernate/src/NHibernate/Mapping/ByCode/Impl/ExplicitDeclarationsHolder.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/Mapping/ByCode/Impl/ExplicitDeclarationsHolder.cs 2011-04-08 05:48:54 UTC (rev 5640)
+++ trunk/nhibernate/src/NHibernate/Mapping/ByCode/Impl/ExplicitDeclarationsHolder.cs 2011-04-08 14:13:21 UTC (rev 5641)
@@ -1,3 +1,4 @@
+using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
@@ -20,6 +21,7 @@
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<MemberInfo> persistentMembers = 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>();
@@ -130,6 +132,11 @@
get { return properties; }
}
+ public IEnumerable<MemberInfo> PersistentMembers
+ {
+ get { return persistentMembers; }
+ }
+
public IEnumerable<SplitDefinition> SplitDefinitions
{
get { return splitDefinitions; }
@@ -245,6 +252,11 @@
properties.Add(member);
}
+ public void AddAsPersistentMember(MemberInfo member)
+ {
+ persistentMembers.Add(member);
+ }
+
public void AddAsPropertySplit(System.Type propertyContainer, string splitGroupId, MemberInfo member)
{
splitDefinitions.Add(new SplitDefinition(propertyContainer, splitGroupId, member));
Modified: trunk/nhibernate/src/NHibernate/Mapping/ByCode/ModelExplicitDeclarationsHolderExtensions.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/Mapping/ByCode/ModelExplicitDeclarationsHolderExtensions.cs 2011-04-08 05:48:54 UTC (rev 5640)
+++ trunk/nhibernate/src/NHibernate/Mapping/ByCode/ModelExplicitDeclarationsHolderExtensions.cs 2011-04-08 14:13:21 UTC (rev 5641)
@@ -1,7 +1,4 @@
-using System;
-using System.Collections.Generic;
using System.Linq;
-using System.Reflection;
namespace NHibernate.Mapping.ByCode
{
@@ -37,6 +34,7 @@
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.PersistentMembers.ToArray(), destination.AddAsPersistentMember);
System.Array.ForEach(source.SplitDefinitions.ToArray(), x => destination.AddAsPropertySplit(x.On, x.GroupId, x.Member));
}
}
Added: trunk/nhibernate/src/NHibernate.Test/MappingByCode/ExpliticMappingTests/ClassWithComponentsTest.cs
===================================================================
--- trunk/nhibernate/src/NHibernate.Test/MappingByCode/ExpliticMappingTests/ClassWithComponentsTest.cs (rev 0)
+++ trunk/nhibernate/src/NHibernate.Test/MappingByCode/ExpliticMappingTests/ClassWithComponentsTest.cs 2011-04-08 14:13:21 UTC (rev 5641)
@@ -0,0 +1,61 @@
+using System;
+using System.Linq;
+using NHibernate.Cfg.MappingSchema;
+using NHibernate.Mapping.ByCode;
+using NUnit.Framework;
+using SharpTestsEx;
+
+namespace NHibernate.Test.MappingByCode.ExpliticMappingTests
+{
+ public class ClassWithComponentsTest
+ {
+ public class Person1
+ {
+ public int Id { get; set; }
+ public string Test { get; set; }
+ public Name Name { get; set; }
+ public Address Address { get; set; }
+ }
+ public class Name
+ {
+ public string First { get; set; }
+ public string Last { get; set; }
+ }
+
+ public class Address
+ {
+ public string Street { get; set; }
+ public int CivicNumber { get; set; }
+ }
+ [Test]
+ public void ComponentMappingJustOnceDemo()
+ {
+ var mapper = new ModelMapper();
+ mapper.Component<Name>(comp =>
+ {
+ comp.Property(name => name.First);
+ comp.Property(name => name.Last);
+ });
+ mapper.Component<Address>(comp =>
+ {
+ comp.Property(address => address.CivicNumber);
+ comp.Property(address => address.Street);
+ });
+ mapper.Class<Person1>(cm =>
+ {
+ cm.Id(person => person.Id, map => map.Generator(Generators.HighLow));
+ cm.Property(person => person.Test);
+ cm.Component(person => person.Name, comp => { });
+ cm.Component(person => person.Address, comp => { });
+ });
+
+ var hbmMapping = mapper.CompileMappingForAllExplicitAddedEntities();
+
+ var hbmClass = hbmMapping.RootClasses[0];
+
+ var hbmComponents = hbmClass.Properties.OfType<HbmComponent>();
+ hbmComponents.Should().Have.Count.EqualTo(2);
+ hbmComponents.Select(x => x.Name).Should().Have.SameValuesAs("Name","Address");
+ }
+ }
+}
\ No newline at end of file
Modified: trunk/nhibernate/src/NHibernate.Test/MappingByCode/ModelExplicitDeclarationsHolderMergeTest.cs
===================================================================
--- trunk/nhibernate/src/NHibernate.Test/MappingByCode/ModelExplicitDeclarationsHolderMergeTest.cs 2011-04-08 05:48:54 UTC (rev 5640)
+++ trunk/nhibernate/src/NHibernate.Test/MappingByCode/ModelExplicitDeclarationsHolderMergeTest.cs 2011-04-08 14:13:21 UTC (rev 5641)
@@ -29,6 +29,17 @@
}
[Test]
+ public void MergePersistentMembers()
+ {
+ var destination = new ExplicitDeclarationsHolder();
+ var source = new ExplicitDeclarationsHolder();
+ source.AddAsPersistentMember(property);
+
+ destination.Merge(source);
+ destination.PersistentMembers.Should().Have.Count.EqualTo(1);
+ }
+
+ [Test]
public void MergeProperties()
{
var destination = new ExplicitDeclarationsHolder();
Modified: trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj
===================================================================
--- trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2011-04-08 05:48:54 UTC (rev 5640)
+++ trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2011-04-08 14:13:21 UTC (rev 5641)
@@ -509,6 +509,7 @@
<Compile Include="Linq\ByMethod\SumTests.cs" />
<Compile Include="Logging\Log4NetLoggerTest.cs" />
<Compile Include="Logging\LoggerProviderTest.cs" />
+ <Compile Include="MappingByCode\ExpliticMappingTests\ClassWithComponentsTest.cs" />
<Compile Include="MappingByCode\ExpliticMappingTests\ConformistMappingRegistrationTests\ClassMappingRegistrationTest.cs" />
<Compile Include="MappingByCode\CustomizerHolderMergeTest.cs" />
<Compile Include="MappingByCode\ExplicitlyDeclaredModelTests\SplitPropertiesRegistrationTests.cs" />
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <fab...@us...> - 2011-04-08 14:47:21
|
Revision: 5642
http://nhibernate.svn.sourceforge.net/nhibernate/?rev=5642&view=rev
Author: fabiomaulo
Date: 2011-04-08 14:47:15 +0000 (Fri, 08 Apr 2011)
Log Message:
-----------
-Fixed class without poid property/field
-simplified API
Modified Paths:
--------------
trunk/nhibernate/src/NHibernate/Mapping/ByCode/IClassMapper.cs
trunk/nhibernate/src/NHibernate/Mapping/ByCode/Impl/CustomizersImpl/ClassCustomizer.cs
trunk/nhibernate/src/NHibernate/Mapping/ByCode/Impl/IdMapper.cs
trunk/nhibernate/src/NHibernate.Test/MappingByCode/ExpliticMappingTests/BasicMappingOfSimpleClass.cs
Modified: trunk/nhibernate/src/NHibernate/Mapping/ByCode/IClassMapper.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/Mapping/ByCode/IClassMapper.cs 2011-04-08 14:13:21 UTC (rev 5641)
+++ trunk/nhibernate/src/NHibernate/Mapping/ByCode/IClassMapper.cs 2011-04-08 14:47:15 UTC (rev 5642)
@@ -34,7 +34,7 @@
public interface IClassAttributesMapper<TEntity> : IEntityAttributesMapper, IEntitySqlsMapper where TEntity : class
{
- void Id(Action<IIdMapper> idMapper);
+ void Id<TProperty>(Expression<Func<TEntity, TProperty>> idProperty);
void Id<TProperty>(Expression<Func<TEntity, TProperty>> idProperty, Action<IIdMapper> idMapper);
void Id(FieldInfo idProperty, Action<IIdMapper> idMapper);
void Discriminator(Action<IDiscriminatorMapper> discriminatorMapping);
Modified: trunk/nhibernate/src/NHibernate/Mapping/ByCode/Impl/CustomizersImpl/ClassCustomizer.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/Mapping/ByCode/Impl/CustomizersImpl/ClassCustomizer.cs 2011-04-08 14:13:21 UTC (rev 5641)
+++ trunk/nhibernate/src/NHibernate/Mapping/ByCode/Impl/CustomizersImpl/ClassCustomizer.cs 2011-04-08 14:47:15 UTC (rev 5642)
@@ -27,21 +27,28 @@
#region Implementation of IClassAttributesMapper<TEntity>
- public void Id(Action<IIdMapper> idMapper)
+ public void Id<TProperty>(Expression<Func<TEntity, TProperty>> idProperty)
{
- CustomizersHolder.AddCustomizer(typeof (TEntity), m => m.Id(idMapper));
+ Id(idProperty, x => { });
}
public void Id<TProperty>(Expression<Func<TEntity, TProperty>> idProperty, Action<IIdMapper> idMapper)
{
- MemberInfo member = TypeExtensions.DecodeMemberAccessExpression(idProperty);
- ExplicitDeclarationsHolder.AddAsPoid(member);
+ MemberInfo member = null;
+ if (idProperty != null)
+ {
+ member = TypeExtensions.DecodeMemberAccessExpression(idProperty);
+ ExplicitDeclarationsHolder.AddAsPoid(member);
+ }
CustomizersHolder.AddCustomizer(typeof (TEntity), m => m.Id(member, idMapper));
}
public void Id(FieldInfo idProperty, Action<IIdMapper> idMapper)
{
- ExplicitDeclarationsHolder.AddAsPoid(idProperty);
+ if (idProperty != null)
+ {
+ ExplicitDeclarationsHolder.AddAsPoid(idProperty);
+ }
CustomizersHolder.AddCustomizer(typeof(TEntity), m => m.Id(idProperty, idMapper));
}
Modified: trunk/nhibernate/src/NHibernate/Mapping/ByCode/Impl/IdMapper.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/Mapping/ByCode/Impl/IdMapper.cs 2011-04-08 14:13:21 UTC (rev 5641)
+++ trunk/nhibernate/src/NHibernate/Mapping/ByCode/Impl/IdMapper.cs 2011-04-08 14:47:15 UTC (rev 5642)
@@ -75,6 +75,11 @@
private void ApplyGenerator(IGeneratorDef generator)
{
var hbmGenerator = new HbmGenerator {@class = generator.Class};
+ if(hbmId.name == null)
+ {
+ // no member for the id
+ hbmId.type1 = generator.DefaultReturnType.GetNhTypeName();
+ }
object generatorParameters = generator.Params;
if (generatorParameters != null)
{
Modified: trunk/nhibernate/src/NHibernate.Test/MappingByCode/ExpliticMappingTests/BasicMappingOfSimpleClass.cs
===================================================================
--- trunk/nhibernate/src/NHibernate.Test/MappingByCode/ExpliticMappingTests/BasicMappingOfSimpleClass.cs 2011-04-08 14:13:21 UTC (rev 5641)
+++ trunk/nhibernate/src/NHibernate.Test/MappingByCode/ExpliticMappingTests/BasicMappingOfSimpleClass.cs 2011-04-08 14:47:15 UTC (rev 5642)
@@ -1,3 +1,4 @@
+using System;
using System.Linq;
using NHibernate.Cfg.MappingSchema;
using NHibernate.Mapping.ByCode;
@@ -32,6 +33,24 @@
}
[Test]
+ public void WhenMapClassWithoutIdThenApplyTypeOfGeneratorDef()
+ {
+ var mapper = new ModelMapper();
+ mapper.Class<MyClass>(ca => ca.Id(null, map =>
+ {
+ map.Column("MyClassId");
+ map.Generator(Generators.HighLow, gmap => gmap.Params(new { max_low = 100 }));
+ }));
+ 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.column1.Should().Be("MyClassId");
+ hbmId.type1.Should().Be(NHibernateUtil.Int32.Name);
+ }
+
+ [Test]
public void WhenDuplicatePropertiesDoesNotDuplicateMapping()
{
var mapper = new ModelMapper();
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <fab...@us...> - 2011-04-08 17:16:35
|
Revision: 5643
http://nhibernate.svn.sourceforge.net/nhibernate/?rev=5643&view=rev
Author: fabiomaulo
Date: 2011-04-08 17:16:28 +0000 (Fri, 08 Apr 2011)
Log Message:
-----------
Composite-elements with nested-composite-elements fix
Modified Paths:
--------------
trunk/nhibernate/src/NHibernate/Mapping/ByCode/Impl/CustomizersImpl/ComponentElementCustomizer.cs
trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj
Added Paths:
-----------
trunk/nhibernate/src/NHibernate.Test/MappingByCode/ExpliticMappingTests/BagOfNestedComponentsWithParentTest.cs
Modified: trunk/nhibernate/src/NHibernate/Mapping/ByCode/Impl/CustomizersImpl/ComponentElementCustomizer.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/Mapping/ByCode/Impl/CustomizersImpl/ComponentElementCustomizer.cs 2011-04-08 14:47:15 UTC (rev 5642)
+++ trunk/nhibernate/src/NHibernate/Mapping/ByCode/Impl/CustomizersImpl/ComponentElementCustomizer.cs 2011-04-08 17:16:28 UTC (rev 5643)
@@ -19,20 +19,25 @@
this.explicitDeclarationsHolder = explicitDeclarationsHolder;
this.propertyPath = propertyPath;
this.customizersHolder = customizersHolder;
+ explicitDeclarationsHolder.AddAsComponent(typeof(TComponent));
+ if (propertyPath != null)
+ {
+ explicitDeclarationsHolder.AddAsPersistentMember(propertyPath.LocalMember);
+ }
}
#region IComponentElementMapper<TComponent> Members
public void Parent<TProperty>(Expression<Func<TComponent, TProperty>> parent) where TProperty : class
{
- MemberInfo member = TypeExtensions.DecodeMemberAccessExpression(parent);
- customizersHolder.AddCustomizer(typeof (TComponent), (IComponentAttributesMapper x) => x.Parent(member));
+ Parent(parent, x => { });
}
public void Parent<TProperty>(Expression<Func<TComponent, TProperty>> parent, Action<IComponentParentMapper> parentMapping) where TProperty : class
{
MemberInfo member = TypeExtensions.DecodeMemberAccessExpression(parent);
customizersHolder.AddCustomizer(typeof (TComponent), (IComponentAttributesMapper x) => x.Parent(member, parentMapping));
+ explicitDeclarationsHolder.AddAsPersistentMember(member);
}
public void Update(bool consideredInUpdateQuery)
@@ -61,6 +66,8 @@
customizersHolder.AddCustomizer(new PropertyPath(propertyPath, member), mapping);
MemberInfo memberOf = TypeExtensions.DecodeMemberAccessExpressionOf(property);
customizersHolder.AddCustomizer(new PropertyPath(propertyPath, memberOf), mapping);
+ explicitDeclarationsHolder.AddAsProperty(member);
+ explicitDeclarationsHolder.AddAsProperty(memberOf);
}
public void Property<TProperty>(Expression<Func<TComponent, TProperty>> property)
@@ -83,6 +90,8 @@
customizersHolder.AddCustomizer(new PropertyPath(propertyPath, member), mapping);
MemberInfo memberOf = TypeExtensions.DecodeMemberAccessExpressionOf(property);
customizersHolder.AddCustomizer(new PropertyPath(propertyPath, memberOf), mapping);
+ explicitDeclarationsHolder.AddAsManyToOneRelation(member);
+ explicitDeclarationsHolder.AddAsManyToOneRelation(memberOf);
}
public void ManyToOne<TProperty>(Expression<Func<TComponent, TProperty>> property) where TProperty : class
Added: trunk/nhibernate/src/NHibernate.Test/MappingByCode/ExpliticMappingTests/BagOfNestedComponentsWithParentTest.cs
===================================================================
--- trunk/nhibernate/src/NHibernate.Test/MappingByCode/ExpliticMappingTests/BagOfNestedComponentsWithParentTest.cs (rev 0)
+++ trunk/nhibernate/src/NHibernate.Test/MappingByCode/ExpliticMappingTests/BagOfNestedComponentsWithParentTest.cs 2011-04-08 17:16:28 UTC (rev 5643)
@@ -0,0 +1,122 @@
+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 BagOfNestedComponentsWithParentTest
+ {
+ private class Person
+ {
+ public int Id { get; set; }
+ public ICollection<Address> Addresses { get; set; }
+ }
+
+ private class Address
+ {
+ public Person Owner { get; set; }
+ public string Street { get; set; }
+ public Number Number { get; set; }
+ }
+
+ private class Number
+ {
+ public Address OwnerAddress { get; set; }
+ public int Block { get; set; }
+ }
+
+ [Test]
+ public void WhenMapClasByClassThenAutodiscoverParent()
+ {
+ var mapper = new ModelMapper();
+ mapper.Component<Address>(cm =>
+ {
+ cm.ManyToOne(x => x.Owner);
+ cm.Property(x => x.Street);
+ cm.Component(x => x.Number, y => { });
+ });
+ mapper.Component<Number>(cm =>
+ {
+ cm.Component(x => x.OwnerAddress, map => { });
+ cm.Property(x => x.Block);
+ });
+ mapper.Class<Person>(cm =>
+ {
+ cm.Id(x => x.Id);
+ cm.Bag(x => x.Addresses, cp => { }, cr => { });
+ });
+ HbmMapping mapping = mapper.CompileMappingFor(new[] { typeof(Person) });
+ VerifyMapping(mapping);
+ }
+
+ [Test]
+ public void WhenMapClassWithWrongElementsThenAutodiscoverParent()
+ {
+ // In this case the user will use wrong mapping-elements as ManyToOne and Component (he should realize that it end in an infinite loop)
+ var mapper = new ModelMapper();
+ mapper.Class<Person>(cm =>
+ {
+ cm.Id(x => x.Id);
+ cm.Bag(x => x.Addresses, cp => { }, cr => cr.Component(ce =>
+ {
+ ce.ManyToOne(x => x.Owner);
+ ce.Property(x => x.Street);
+ ce.Component(x => x.Number, y =>
+ {
+ y.Component(x => x.OwnerAddress, map => { });
+ y.Property(x => x.Block);
+ });
+ }));
+ });
+ HbmMapping mapping = mapper.CompileMappingFor(new[] { typeof(Person) });
+ VerifyMapping(mapping);
+ }
+
+ [Test]
+ public void WhenMapClassElementsThenMapParent()
+ {
+ var mapper = new ModelMapper();
+ mapper.Class<Person>(cm =>
+ {
+ cm.Id(x => x.Id);
+ cm.Bag(x => x.Addresses, cp => { }, cr => cr.Component(ce =>
+ {
+ ce.Parent(x => x.Owner);
+ ce.Property(x => x.Street);
+ ce.Component(x => x.Number, y =>
+ {
+ y.Parent(x => x.OwnerAddress, map => { });
+ y.Property(x => x.Block);
+ });
+ }));
+ });
+ HbmMapping mapping = mapper.CompileMappingFor(new[] { typeof(Person) });
+ VerifyMapping(mapping);
+ }
+
+ private void VerifyMapping(HbmMapping mapping)
+ {
+ HbmClass rc = mapping.RootClasses.First(r => r.Name.Contains("Person"));
+ var relation = rc.Properties.First(p => p.Name == "Addresses");
+ var collection = (HbmBag)relation;
+ collection.ElementRelationship.Should().Be.OfType<HbmCompositeElement>();
+ var elementRelation = (HbmCompositeElement)collection.ElementRelationship;
+ elementRelation.Class.Should().Contain("Address");
+ elementRelation.Properties.Should().Have.Count.EqualTo(2);
+ elementRelation.Properties.Select(p => p.Name).Should().Have.SameValuesAs("Street", "Number");
+ elementRelation.Parent.Should().Not.Be.Null();
+ elementRelation.Parent.name.Should().Be.EqualTo("Owner");
+ // Nested
+ var propertyNestedRelation = elementRelation.Properties.FirstOrDefault(p => p.Name == "Number");
+ propertyNestedRelation.Should().Not.Be.Null().And.Be.OfType<HbmNestedCompositeElement>();
+ var nestedRelation = (HbmNestedCompositeElement) propertyNestedRelation;
+ nestedRelation.Class.Should().Contain("Number");
+ nestedRelation.Properties.Should().Have.Count.EqualTo(1);
+ nestedRelation.Parent.Should().Not.Be.Null();
+ nestedRelation.Parent.name.Should().Be.EqualTo("OwnerAddress");
+ }
+ }
+}
\ 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-08 14:47:15 UTC (rev 5642)
+++ trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2011-04-08 17:16:28 UTC (rev 5643)
@@ -509,6 +509,7 @@
<Compile Include="Linq\ByMethod\SumTests.cs" />
<Compile Include="Logging\Log4NetLoggerTest.cs" />
<Compile Include="Logging\LoggerProviderTest.cs" />
+ <Compile Include="MappingByCode\ExpliticMappingTests\BagOfNestedComponentsWithParentTest.cs" />
<Compile Include="MappingByCode\ExpliticMappingTests\ClassWithComponentsTest.cs" />
<Compile Include="MappingByCode\ExpliticMappingTests\ConformistMappingRegistrationTests\ClassMappingRegistrationTest.cs" />
<Compile Include="MappingByCode\CustomizerHolderMergeTest.cs" />
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|