You can subscribe to this list here.
2004 |
Jan
|
Feb
|
Mar
|
Apr
(248) |
May
(82) |
Jun
(90) |
Jul
(177) |
Aug
(253) |
Sep
(157) |
Oct
(151) |
Nov
(143) |
Dec
(278) |
---|---|---|---|---|---|---|---|---|---|---|---|---|
2005 |
Jan
(152) |
Feb
(107) |
Mar
(177) |
Apr
(133) |
May
(259) |
Jun
(81) |
Jul
(119) |
Aug
(306) |
Sep
(416) |
Oct
(240) |
Nov
(329) |
Dec
(206) |
2006 |
Jan
(466) |
Feb
(382) |
Mar
(153) |
Apr
(162) |
May
(133) |
Jun
(21) |
Jul
(18) |
Aug
(37) |
Sep
(97) |
Oct
(114) |
Nov
(110) |
Dec
(28) |
2007 |
Jan
(74) |
Feb
(65) |
Mar
(49) |
Apr
(76) |
May
(43) |
Jun
(15) |
Jul
(68) |
Aug
(55) |
Sep
(63) |
Oct
(59) |
Nov
(70) |
Dec
(66) |
2008 |
Jan
(71) |
Feb
(60) |
Mar
(120) |
Apr
(31) |
May
(48) |
Jun
(81) |
Jul
(107) |
Aug
(51) |
Sep
(80) |
Oct
(83) |
Nov
(83) |
Dec
(79) |
2009 |
Jan
(83) |
Feb
(110) |
Mar
(97) |
Apr
(91) |
May
(291) |
Jun
(250) |
Jul
(197) |
Aug
(58) |
Sep
(54) |
Oct
(122) |
Nov
(68) |
Dec
(34) |
2010 |
Jan
(50) |
Feb
(17) |
Mar
(63) |
Apr
(61) |
May
(84) |
Jun
(81) |
Jul
(138) |
Aug
(144) |
Sep
(78) |
Oct
(26) |
Nov
(30) |
Dec
(61) |
2011 |
Jan
(33) |
Feb
(35) |
Mar
(166) |
Apr
(221) |
May
(109) |
Jun
(76) |
Jul
(27) |
Aug
(37) |
Sep
(1) |
Oct
(4) |
Nov
(2) |
Dec
(1) |
2012 |
Jan
|
Feb
|
Mar
(2) |
Apr
(2) |
May
|
Jun
|
Jul
(1) |
Aug
|
Sep
(1) |
Oct
|
Nov
(1) |
Dec
|
2013 |
Jan
|
Feb
(1) |
Mar
|
Apr
|
May
|
Jun
|
Jul
(1) |
Aug
(1) |
Sep
(3) |
Oct
(2) |
Nov
|
Dec
(1) |
2014 |
Jan
(1) |
Feb
(1) |
Mar
(3) |
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
From: <fab...@us...> - 2011-04-27 21:53:37
|
Revision: 5778 http://nhibernate.svn.sourceforge.net/nhibernate/?rev=5778&view=rev Author: fabiomaulo Date: 2011-04-27 21:53:31 +0000 (Wed, 27 Apr 2011) Log Message: ----------- Merge of Dynamic-compo customizers 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-27 21:49:11 UTC (rev 5777) +++ trunk/nhibernate/src/NHibernate/Mapping/ByCode/Impl/CustomizersHolder.cs 2011-04-27 21:53:31 UTC (rev 5778) @@ -353,6 +353,7 @@ MergeDictionary(collectionRelationOneToManyCustomizers, source.collectionRelationOneToManyCustomizers); MergeDictionary(mapKeyManyToManyCustomizers, source.mapKeyManyToManyCustomizers); MergeDictionary(mapKeyElementCustomizers, source.mapKeyElementCustomizers); + MergeDictionary(dynamicComponentCustomizers, source.dynamicComponentCustomizers); } #endregion Modified: trunk/nhibernate/src/NHibernate.Test/MappingByCode/CustomizerHolderMergeTest.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Test/MappingByCode/CustomizerHolderMergeTest.cs 2011-04-27 21:49:11 UTC (rev 5777) +++ trunk/nhibernate/src/NHibernate.Test/MappingByCode/CustomizerHolderMergeTest.cs 2011-04-27 21:53:31 UTC (rev 5778) @@ -328,5 +328,20 @@ called.Should().Be.True(); } + + [Test] + public void MergeShouldMergeDynamicComponentAttributesMapper() + { + var emptyHolder = new CustomizersHolder(); + var holder = new CustomizersHolder(); + var called = false; + + holder.AddCustomizer(propertyPath, (IDynamicComponentAttributesMapper x) => called = true); + emptyHolder.Merge(holder); + emptyHolder.InvokeCustomizers(propertyPath, (IDynamicComponentAttributesMapper)null); + + called.Should().Be.True(); + } + } } \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fab...@us...> - 2011-04-27 21:49:18
|
Revision: 5777 http://nhibernate.svn.sourceforge.net/nhibernate/?rev=5777&view=rev Author: fabiomaulo Date: 2011-04-27 21:49:11 +0000 (Wed, 27 Apr 2011) Log Message: ----------- Impl DynamicComponentCustomizer to set dynamic-component attributes Modified Paths: -------------- trunk/nhibernate/src/NHibernate/Mapping/ByCode/IDynamicComponentAttributesMapper.cs trunk/nhibernate/src/NHibernate/Mapping/ByCode/Impl/CustomizersImpl/DynamicComponentCustomizer.cs trunk/nhibernate/src/NHibernate/Mapping/ByCode/Impl/DynamicComponentMapper.cs trunk/nhibernate/src/NHibernate.Test/MappingByCode/ExpliticMappingTests/DynamicComponentMappingTests.cs Modified: trunk/nhibernate/src/NHibernate/Mapping/ByCode/IDynamicComponentAttributesMapper.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Mapping/ByCode/IDynamicComponentAttributesMapper.cs 2011-04-27 20:51:43 UTC (rev 5776) +++ trunk/nhibernate/src/NHibernate/Mapping/ByCode/IDynamicComponentAttributesMapper.cs 2011-04-27 21:49:11 UTC (rev 5777) @@ -4,6 +4,7 @@ { void Update(bool consideredInUpdateQuery); void Insert(bool consideredInInsertQuery); + void Unique(bool unique); } public interface IDynamicComponentMapper : IDynamicComponentAttributesMapper, IPropertyContainerMapper { } @@ -12,6 +13,7 @@ { void Update(bool consideredInUpdateQuery); void Insert(bool consideredInInsertQuery); + void Unique(bool unique); } public interface IDynamicComponentMapper<TComponent> : IDynamicComponentAttributesMapper<TComponent>, IPropertyContainerMapper<TComponent> where TComponent : class { } Modified: trunk/nhibernate/src/NHibernate/Mapping/ByCode/Impl/CustomizersImpl/DynamicComponentCustomizer.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Mapping/ByCode/Impl/CustomizersImpl/DynamicComponentCustomizer.cs 2011-04-27 20:51:43 UTC (rev 5776) +++ trunk/nhibernate/src/NHibernate/Mapping/ByCode/Impl/CustomizersImpl/DynamicComponentCustomizer.cs 2011-04-27 21:49:11 UTC (rev 5777) @@ -22,29 +22,34 @@ public void Access(Accessor accessor) { - throw new NotImplementedException(); + CustomizersHolder.AddCustomizer(PropertyPath, (IDynamicComponentAttributesMapper m) => m.Access(accessor)); } public void Access(System.Type accessorType) { - throw new NotImplementedException(); + CustomizersHolder.AddCustomizer(PropertyPath, (IDynamicComponentAttributesMapper m) => m.Access(accessorType)); } public void OptimisticLock(bool takeInConsiderationForOptimisticLock) { - throw new NotImplementedException(); + CustomizersHolder.AddCustomizer(PropertyPath, (IDynamicComponentAttributesMapper m) => m.OptimisticLock(takeInConsiderationForOptimisticLock)); } public void Update(bool consideredInUpdateQuery) { - throw new NotImplementedException(); + CustomizersHolder.AddCustomizer(PropertyPath, (IDynamicComponentAttributesMapper m) => m.Update(consideredInUpdateQuery)); } public void Insert(bool consideredInInsertQuery) { - throw new NotImplementedException(); + CustomizersHolder.AddCustomizer(PropertyPath, (IDynamicComponentAttributesMapper m) => m.Insert(consideredInInsertQuery)); } + public void Unique(bool unique) + { + CustomizersHolder.AddCustomizer(PropertyPath, (IDynamicComponentAttributesMapper m) => m.Unique(unique)); + } + #endregion } } \ No newline at end of file Modified: trunk/nhibernate/src/NHibernate/Mapping/ByCode/Impl/DynamicComponentMapper.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Mapping/ByCode/Impl/DynamicComponentMapper.cs 2011-04-27 20:51:43 UTC (rev 5776) +++ trunk/nhibernate/src/NHibernate/Mapping/ByCode/Impl/DynamicComponentMapper.cs 2011-04-27 21:49:11 UTC (rev 5777) @@ -163,5 +163,10 @@ { component.insert = consideredInInsertQuery; } + + public void Unique(bool unique) + { + component.unique = unique; + } } } \ No newline at end of file Modified: trunk/nhibernate/src/NHibernate.Test/MappingByCode/ExpliticMappingTests/DynamicComponentMappingTests.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Test/MappingByCode/ExpliticMappingTests/DynamicComponentMappingTests.cs 2011-04-27 20:51:43 UTC (rev 5776) +++ trunk/nhibernate/src/NHibernate.Test/MappingByCode/ExpliticMappingTests/DynamicComponentMappingTests.cs 2011-04-27 21:49:11 UTC (rev 5777) @@ -13,7 +13,12 @@ private class Person { public int Id { get; set; } - public IDictionary Info { get; set; } + private IDictionary info; + public IDictionary Info + { + get { return info; } + set { info = value; } + } } [Test] @@ -48,5 +53,32 @@ var hbmDynamicComponent = hbmClass.Properties.OfType<HbmDynamicComponent>().Single(); hbmDynamicComponent.Properties.OfType<HbmProperty>().Select(x => x.type1).All(x=> x.Satisfy(value=> !string.IsNullOrEmpty(value))); } + + [Test] + public void WhenMapDynCompoAttributesThenMapAttributes() + { + var mapper = new ModelMapper(); + mapper.Class<Person>(map => + { + map.Id(x => x.Id, idmap => { }); + map.Component(x => x.Info, new { MyInt = 5}, z => + { + z.Access(Accessor.Field); + z.Insert(false); + z.Update(false); + z.Unique(true); + z.OptimisticLock(false); + }); + }); + + var hbmMapping = mapper.CompileMappingFor(new[] { typeof(Person) }); + var hbmClass = hbmMapping.RootClasses[0]; + var hbmDynamicComponent = hbmClass.Properties.OfType<HbmDynamicComponent>().SingleOrDefault(); + hbmDynamicComponent.access.Should().Contain("field"); + hbmDynamicComponent.insert.Should().Be.False(); + hbmDynamicComponent.update.Should().Be.False(); + hbmDynamicComponent.optimisticlock.Should().Be.False(); + hbmDynamicComponent.unique.Should().Be.True(); + } } } \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fab...@us...> - 2011-04-27 20:51:49
|
Revision: 5776 http://nhibernate.svn.sourceforge.net/nhibernate/?rev=5776&view=rev Author: fabiomaulo Date: 2011-04-27 20:51:43 +0000 (Wed, 27 Apr 2011) Log Message: ----------- Minor fix (cleaned mapping when empty natural-id is defined) Modified Paths: -------------- trunk/nhibernate/src/NHibernate/Mapping/ByCode/Impl/ClassMapper.cs trunk/nhibernate/src/NHibernate/Mapping/ByCode/Impl/NaturalIdMapper.cs trunk/nhibernate/src/NHibernate.Test/MappingByCode/ExpliticMappingTests/ComposedIdTests.cs trunk/nhibernate/src/NHibernate.Test/MappingByCode/ExpliticMappingTests/NaturalIdTests.cs Modified: trunk/nhibernate/src/NHibernate/Mapping/ByCode/Impl/ClassMapper.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Mapping/ByCode/Impl/ClassMapper.cs 2011-04-27 18:54:47 UTC (rev 5775) +++ trunk/nhibernate/src/NHibernate/Mapping/ByCode/Impl/ClassMapper.cs 2011-04-27 20:51:43 UTC (rev 5776) @@ -196,9 +196,7 @@ { if (naturalIdMapper == null) { - var hbmNaturalId = new HbmNaturalId(); - classMapping.naturalid = hbmNaturalId; - naturalIdMapper = new NaturalIdMapper(Container, hbmNaturalId, MapDoc); + naturalIdMapper = new NaturalIdMapper(Container, classMapping, MapDoc); } naturalIdMapping(naturalIdMapper); } Modified: trunk/nhibernate/src/NHibernate/Mapping/ByCode/Impl/NaturalIdMapper.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Mapping/ByCode/Impl/NaturalIdMapper.cs 2011-04-27 18:54:47 UTC (rev 5775) +++ trunk/nhibernate/src/NHibernate/Mapping/ByCode/Impl/NaturalIdMapper.cs 2011-04-27 20:51:43 UTC (rev 5776) @@ -6,11 +6,17 @@ { public class NaturalIdMapper : AbstractBasePropertyContainerMapper, INaturalIdMapper { + private readonly HbmClass classMapping; private readonly HbmNaturalId naturalIdmapping; - public NaturalIdMapper(System.Type rootClass, HbmNaturalId naturalIdmapping, HbmMapping mapDoc) : base(rootClass, mapDoc) + public NaturalIdMapper(System.Type rootClass, HbmClass classMapping, HbmMapping mapDoc) : base(rootClass, mapDoc) { - this.naturalIdmapping = naturalIdmapping; + if (classMapping == null) + { + throw new ArgumentNullException("classMapping"); + } + this.classMapping = classMapping; + naturalIdmapping = new HbmNaturalId(); } #region Overrides of AbstractBasePropertyContainerMapper @@ -21,6 +27,10 @@ { throw new ArgumentNullException("property"); } + if(classMapping.naturalid == null) + { + classMapping.naturalid = naturalIdmapping; + } var toAdd = new[] {property}; naturalIdmapping.Items = naturalIdmapping.Items == null ? toAdd : naturalIdmapping.Items.Concat(toAdd).ToArray(); } Modified: trunk/nhibernate/src/NHibernate.Test/MappingByCode/ExpliticMappingTests/ComposedIdTests.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Test/MappingByCode/ExpliticMappingTests/ComposedIdTests.cs 2011-04-27 18:54:47 UTC (rev 5775) +++ trunk/nhibernate/src/NHibernate.Test/MappingByCode/ExpliticMappingTests/ComposedIdTests.cs 2011-04-27 20:51:43 UTC (rev 5776) @@ -109,10 +109,7 @@ HbmClass hbmClass = hbmMapping.RootClasses[0]; HbmCompositeId hbmCompositId = hbmClass.CompositeId; hbmCompositId.Items.Should().Have.Count.EqualTo(2); - if(hbmClass.naturalid != null) - { - hbmClass.naturalid.Items.Should().Be.Null(); - } + hbmClass.naturalid.Should().Be.Null(); hbmClass.Properties.Should().Be.Empty(); } } Modified: trunk/nhibernate/src/NHibernate.Test/MappingByCode/ExpliticMappingTests/NaturalIdTests.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Test/MappingByCode/ExpliticMappingTests/NaturalIdTests.cs 2011-04-27 18:54:47 UTC (rev 5775) +++ trunk/nhibernate/src/NHibernate.Test/MappingByCode/ExpliticMappingTests/NaturalIdTests.cs 2011-04-27 20:51:43 UTC (rev 5776) @@ -27,7 +27,7 @@ } [Test] - public void WhenDefineRootEntityThenRegister() + public void WhenDefineNaturalIdThenRegister() { var inspector = new ExplicitlyDeclaredModel(); var mapper = new ModelMapper(inspector); @@ -51,5 +51,19 @@ inspector.IsMemberOfNaturalId(For<MyClass>.Property(x => x.MyComponent)).Should().Be.True(); inspector.IsMemberOfNaturalId(For<MyClass>.Property(x => x.Any)).Should().Be.True(); } + + [Test] + public void WhenDefineEmptyNaturalIdThenNoMapIt() + { + var mapper = new ModelMapper(); + mapper.Class<MyClass>(map => + { + map.Id(x => x.Id, idmap => { }); + map.NaturalId(nidm =>{}); + }); + var hbmMapping = mapper.CompileMappingFor(new[] { typeof(MyClass) }); + var hbmClass = hbmMapping.RootClasses[0]; + hbmClass.naturalid.Should().Be.Null(); + } } } \ 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-27 18:54:54
|
Revision: 5775 http://nhibernate.svn.sourceforge.net/nhibernate/?rev=5775&view=rev Author: fabiomaulo Date: 2011-04-27 18:54:47 +0000 (Wed, 27 Apr 2011) Log Message: ----------- The end composed-id Modified Paths: -------------- trunk/nhibernate/src/NHibernate/Mapping/ByCode/IClassMapper.cs trunk/nhibernate/src/NHibernate/Mapping/ByCode/ICompositeIdMapper.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/ICustomizersHolder.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/ComponentAsIdLikeComponetAttributesMapper.cs trunk/nhibernate/src/NHibernate/Mapping/ByCode/Impl/CustomizersImpl/ComponentAsIdCustomizer.cs trunk/nhibernate/src/NHibernate/Mapping/ByCode/Impl/CustomizersImpl/ComposedIdCustomizer.cs trunk/nhibernate/src/NHibernate.Test/MappingByCode/ExpliticMappingTests/ComponentAsIdTests.cs trunk/nhibernate/src/NHibernate.Test/MappingByCode/ExpliticMappingTests/ComposedIdTests.cs Modified: trunk/nhibernate/src/NHibernate/Mapping/ByCode/IClassMapper.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Mapping/ByCode/IClassMapper.cs 2011-04-27 14:36:13 UTC (rev 5774) +++ trunk/nhibernate/src/NHibernate/Mapping/ByCode/IClassMapper.cs 2011-04-27 18:54:47 UTC (rev 5775) @@ -42,10 +42,10 @@ void Id<TProperty>(Expression<Func<TEntity, TProperty>> idProperty, Action<IIdMapper> idMapper); void Id(FieldInfo idProperty, Action<IIdMapper> idMapper); - //void ComponentAsId<TComponent>(Expression<Func<TEntity, TComponent>> idProperty) where TComponent : class; - //void ComponentAsId<TComponent>(Expression<Func<TEntity, TComponent>> idProperty, Action<IComponentAsIdMapper<TComponent>> idMapper) where TComponent : class; + void ComponentAsId<TComponent>(Expression<Func<TEntity, TComponent>> idProperty) where TComponent : class; + void ComponentAsId<TComponent>(Expression<Func<TEntity, TComponent>> idProperty, Action<IComponentAsIdMapper<TComponent>> idMapper) where TComponent : class; - //void ComposedId(Action<IComposedIdMapper<TEntity>> idPropertiesMapping); + void ComposedId(Action<IComposedIdMapper<TEntity>> idPropertiesMapping); void Discriminator(Action<IDiscriminatorMapper> discriminatorMapping); void DiscriminatorValue(object value); Modified: trunk/nhibernate/src/NHibernate/Mapping/ByCode/ICompositeIdMapper.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Mapping/ByCode/ICompositeIdMapper.cs 2011-04-27 14:36:13 UTC (rev 5774) +++ trunk/nhibernate/src/NHibernate/Mapping/ByCode/ICompositeIdMapper.cs 2011-04-27 18:54:47 UTC (rev 5775) @@ -23,6 +23,7 @@ void Class<TConcrete>() where TConcrete : TComponent; } - public interface IComponentAsIdMapper<TComponent> : IComponentAsIdAttributesMapper<TComponent>, IMinimalPlainPropertyContainerMapper<TComponent> where TComponent : class { } + public interface IComponentAsIdMapper<TComponent> : IComponentAsIdAttributesMapper<TComponent>, IMinimalPlainPropertyContainerMapper<TComponent> + { } } \ No newline at end of file Added: trunk/nhibernate/src/NHibernate/Mapping/ByCode/Impl/ComponentAsIdLikeComponetAttributesMapper.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Mapping/ByCode/Impl/ComponentAsIdLikeComponetAttributesMapper.cs (rev 0) +++ trunk/nhibernate/src/NHibernate/Mapping/ByCode/Impl/ComponentAsIdLikeComponetAttributesMapper.cs 2011-04-27 18:54:47 UTC (rev 5775) @@ -0,0 +1,53 @@ +using System; +using System.Reflection; + +namespace NHibernate.Mapping.ByCode.Impl +{ + public class ComponentAsIdLikeComponetAttributesMapper : IComponentAttributesMapper + { + private readonly IComponentAsIdMapper realMapper; + + public ComponentAsIdLikeComponetAttributesMapper(IComponentAsIdMapper realMapper) + { + if (realMapper == null) + { + throw new ArgumentNullException("realMapper"); + } + this.realMapper = realMapper; + } + + #region IComponentAttributesMapper Members + + public void Access(Accessor accessor) + { + realMapper.Access(accessor); + } + + public void Access(System.Type accessorType) + { + realMapper.Access(accessorType); + } + + public void OptimisticLock(bool takeInConsiderationForOptimisticLock) {} + + public void Parent(MemberInfo parent) + { + // the mapping of the Parent can be used as a ManyToOne but could be strange to have a bidirectional relation in the PK + } + + public void Parent(MemberInfo parent, Action<IComponentParentMapper> parentMapping) {} + + public void Update(bool consideredInUpdateQuery) {} + + public void Insert(bool consideredInInsertQuery) {} + + public void Lazy(bool isLazy) {} + + public void Class(System.Type componentType) + { + realMapper.Class(componentType); + } + + #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-27 14:36:13 UTC (rev 5774) +++ trunk/nhibernate/src/NHibernate/Mapping/ByCode/Impl/CustomizersHolder.cs 2011-04-27 18:54:47 UTC (rev 5775) @@ -33,6 +33,9 @@ private readonly Dictionary<PropertyPath, List<Action<IComponentAttributesMapper>>> componentPropertyCustomizers = new Dictionary<PropertyPath, List<Action<IComponentAttributesMapper>>>(); + private readonly Dictionary<PropertyPath, List<Action<IComponentAsIdAttributesMapper>>> componentAsIdPropertyCustomizers = + new Dictionary<PropertyPath, List<Action<IComponentAsIdAttributesMapper>>>(); + private readonly Dictionary<PropertyPath, List<Action<IDynamicComponentAttributesMapper>>> dynamicComponentCustomizers = new Dictionary<PropertyPath, List<Action<IDynamicComponentAttributesMapper>>>(); @@ -162,6 +165,11 @@ AddCustomizer(componentPropertyCustomizers, member, propertyCustomizer); } + public void AddCustomizer(PropertyPath member, Action<IComponentAsIdAttributesMapper> propertyCustomizer) + { + AddCustomizer(componentAsIdPropertyCustomizers, member, propertyCustomizer); + } + public void AddCustomizer(PropertyPath member, Action<IDynamicComponentAttributesMapper> propertyCustomizer) { AddCustomizer(dynamicComponentCustomizers, member, propertyCustomizer); @@ -282,6 +290,11 @@ InvokeCustomizers(componentPropertyCustomizers, member, mapper); } + public void InvokeCustomizers(PropertyPath member, IComponentAsIdAttributesMapper mapper) + { + InvokeCustomizers(componentAsIdPropertyCustomizers, member, mapper); + } + public void InvokeCustomizers(PropertyPath member, IDynamicComponentAttributesMapper mapper) { InvokeCustomizers(dynamicComponentCustomizers, 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-27 14:36:13 UTC (rev 5774) +++ trunk/nhibernate/src/NHibernate/Mapping/ByCode/Impl/CustomizersImpl/ClassCustomizer.cs 2011-04-27 18:54:47 UTC (rev 5775) @@ -52,6 +52,23 @@ CustomizersHolder.AddCustomizer(typeof(TEntity), m => m.Id(idProperty, idMapper)); } + public void ComponentAsId<TComponent>(Expression<Func<TEntity, TComponent>> idProperty) where TComponent : class + { + ComponentAsId(idProperty, x => { }); + } + + public void ComponentAsId<TComponent>(Expression<Func<TEntity, TComponent>> idProperty, Action<IComponentAsIdMapper<TComponent>> idMapper) where TComponent : class + { + var member = TypeExtensions.DecodeMemberAccessExpression(idProperty); + var propertyPath = new PropertyPath(null, member); + idMapper(new ComponentAsIdCustomizer<TComponent>(ExplicitDeclarationsHolder, CustomizersHolder, propertyPath)); + } + + public void ComposedId(Action<IComposedIdMapper<TEntity>> idPropertiesMapping) + { + idPropertiesMapping(new ComposedIdCustomizer<TEntity>(ExplicitDeclarationsHolder, CustomizersHolder)); + } + public void Discriminator(Action<IDiscriminatorMapper> discriminatorMapping) { CustomizersHolder.AddCustomizer(typeof (TEntity), (IClassMapper m) => m.Discriminator(discriminatorMapping)); Added: trunk/nhibernate/src/NHibernate/Mapping/ByCode/Impl/CustomizersImpl/ComponentAsIdCustomizer.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Mapping/ByCode/Impl/CustomizersImpl/ComponentAsIdCustomizer.cs (rev 0) +++ trunk/nhibernate/src/NHibernate/Mapping/ByCode/Impl/CustomizersImpl/ComponentAsIdCustomizer.cs 2011-04-27 18:54:47 UTC (rev 5775) @@ -0,0 +1,37 @@ +using System; + +namespace NHibernate.Mapping.ByCode.Impl.CustomizersImpl +{ + public class ComponentAsIdCustomizer<TComponent> : PropertyContainerCustomizer<TComponent>, IComponentAsIdMapper<TComponent> where TComponent : class + { + public ComponentAsIdCustomizer(IModelExplicitDeclarationsHolder explicitDeclarationsHolder, ICustomizersHolder customizersHolder, PropertyPath propertyPath) + : base(explicitDeclarationsHolder, customizersHolder, propertyPath) + { + if (explicitDeclarationsHolder == null) + { + throw new ArgumentNullException("explicitDeclarationsHolder"); + } + if (propertyPath == null) + { + throw new ArgumentNullException("propertyPath"); + } + explicitDeclarationsHolder.AddAsComponent(typeof (TComponent)); + explicitDeclarationsHolder.AddAsPoid(propertyPath.LocalMember); + } + + public void Class<TConcrete>() where TConcrete : TComponent + { + CustomizersHolder.AddCustomizer(PropertyPath, (IComponentAsIdAttributesMapper m) => m.Class(typeof(TConcrete))); + } + + public void Access(Accessor accessor) + { + CustomizersHolder.AddCustomizer(PropertyPath, (IComponentAsIdAttributesMapper m) => m.Access(accessor)); + } + + public void Access(System.Type accessorType) + { + CustomizersHolder.AddCustomizer(PropertyPath, (IComponentAsIdAttributesMapper m) => m.Access(accessorType)); + } + } +} \ No newline at end of file Added: trunk/nhibernate/src/NHibernate/Mapping/ByCode/Impl/CustomizersImpl/ComposedIdCustomizer.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Mapping/ByCode/Impl/CustomizersImpl/ComposedIdCustomizer.cs (rev 0) +++ trunk/nhibernate/src/NHibernate/Mapping/ByCode/Impl/CustomizersImpl/ComposedIdCustomizer.cs 2011-04-27 18:54:47 UTC (rev 5775) @@ -0,0 +1,24 @@ +using System.Reflection; + +namespace NHibernate.Mapping.ByCode.Impl.CustomizersImpl +{ + public class ComposedIdCustomizer<TEntity> : PropertyContainerCustomizer<TEntity>, IComposedIdMapper<TEntity> where TEntity : class + { + public ComposedIdCustomizer(IModelExplicitDeclarationsHolder explicitDeclarationsHolder, ICustomizersHolder customizersHolder) + : base(explicitDeclarationsHolder, customizersHolder, null) {} + + protected override void RegisterPropertyMapping<TProperty>(System.Linq.Expressions.Expression<System.Func<TEntity, TProperty>> property, System.Action<IPropertyMapper> mapping) + { + MemberInfo member = TypeExtensions.DecodeMemberAccessExpression(property); + ExplicitDeclarationsHolder.AddAsPartOfComposedId(member); + base.RegisterPropertyMapping(property, mapping); + } + + protected override void RegisterManyToOneMapping<TProperty>(System.Linq.Expressions.Expression<System.Func<TEntity, TProperty>> property, System.Action<IManyToOneMapper> mapping) + { + MemberInfo member = TypeExtensions.DecodeMemberAccessExpression(property); + ExplicitDeclarationsHolder.AddAsPartOfComposedId(member); + base.RegisterManyToOneMapping(property, mapping); + } + } +} \ 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-27 14:36:13 UTC (rev 5774) +++ trunk/nhibernate/src/NHibernate/Mapping/ByCode/Impl/ICustomizersHolder.cs 2011-04-27 18:54:47 UTC (rev 5775) @@ -24,6 +24,7 @@ void AddCustomizer(PropertyPath member, Action<IIdBagPropertiesMapper> propertyCustomizer); void AddCustomizer(PropertyPath member, Action<ICollectionPropertiesMapper> propertyCustomizer); void AddCustomizer(PropertyPath member, Action<IComponentAttributesMapper> propertyCustomizer); + void AddCustomizer(PropertyPath member, Action<IComponentAsIdAttributesMapper> propertyCustomizer); void AddCustomizer(PropertyPath member, Action<IDynamicComponentAttributesMapper> propertyCustomizer); void InvokeCustomizers(System.Type type, IClassMapper mapper); @@ -44,6 +45,7 @@ void InvokeCustomizers(PropertyPath member, IMapPropertiesMapper mapper); void InvokeCustomizers(PropertyPath member, IIdBagPropertiesMapper mapper); void InvokeCustomizers(PropertyPath member, IComponentAttributesMapper mapper); + void InvokeCustomizers(PropertyPath member, IComponentAsIdAttributesMapper mapper); void InvokeCustomizers(PropertyPath member, IDynamicComponentAttributesMapper mapper); #region Collection Element relations invokers Modified: trunk/nhibernate/src/NHibernate/Mapping/ByCode/ModelMapper.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Mapping/ByCode/ModelMapper.cs 2011-04-27 14:36:13 UTC (rev 5774) +++ trunk/nhibernate/src/NHibernate/Mapping/ByCode/ModelMapper.cs 2011-04-27 18:54:47 UTC (rev 5775) @@ -731,7 +731,42 @@ InvokeBeforeMapClass(type, classMapper); InvokeClassCustomizers(type, classMapper); - MemberInfo[] naturalIdPropeties = persistentProperties.Where(mi => modelInspector.IsMemberOfNaturalId(mi)).ToArray(); + if (poidPropertyOrField != null && modelInspector.IsComponent(poidPropertyOrField.GetPropertyOrFieldType())) + { + classMapper.ComponentAsId(poidPropertyOrField, compoAsId => + { + var memberPath = new PropertyPath(null, poidPropertyOrField); + var componentMapper = new ComponentAsIdLikeComponetAttributesMapper(compoAsId); + InvokeBeforeMapComponent(memberPath, componentMapper); + + System.Type componentType = poidPropertyOrField.GetPropertyOrFieldType(); + IEnumerable<MemberInfo> componentPersistentProperties = + membersProvider.GetComponentMembers(componentType).Where(p => modelInspector.IsPersistentProperty(p)); + + customizerHolder.InvokeCustomizers(componentType, componentMapper); + ForEachMemberPath(poidPropertyOrField, memberPath, pp => customizerHolder.InvokeCustomizers(pp, compoAsId)); + InvokeAfterMapComponent(memberPath, componentMapper); + + foreach (MemberInfo property in componentPersistentProperties) + { + MapComposedIdProperties(compoAsId, new PropertyPath(memberPath, property)); + } + }); + } + + MemberInfo[] composedIdPropeties = persistentProperties.Where(mi => modelInspector.IsMemberOfComposedId(mi)).ToArray(); + if (composedIdPropeties.Length > 0) + { + classMapper.ComposedId(composedIdMapper => + { + foreach (MemberInfo property in composedIdPropeties) + { + MapComposedIdProperties(composedIdMapper, new PropertyPath(null, property)); + } + }); + } + + MemberInfo[] naturalIdPropeties = persistentProperties.Except(composedIdPropeties).Where(mi => modelInspector.IsMemberOfNaturalId(mi)).ToArray(); if (naturalIdPropeties.Length > 0) { classMapper.NaturalId(naturalIdMapper => @@ -743,7 +778,7 @@ }); } var splitGroups = modelInspector.GetPropertiesSplits(type); - var propertiesToMap = persistentProperties.Where(mi => !modelInspector.IsVersion(mi) && !modelInspector.IsVersion(mi.GetMemberFromDeclaringType())).Except(naturalIdPropeties).ToList(); + var propertiesToMap = persistentProperties.Except(naturalIdPropeties).Except(composedIdPropeties).Where(mi => !modelInspector.IsVersion(mi) && !modelInspector.IsVersion(mi.GetMemberFromDeclaringType())).ToList(); var propertiesInSplits = new HashSet<MemberInfo>(); foreach (var splitGroup in splitGroups) { @@ -838,6 +873,34 @@ } } + private void MapComposedIdProperties(IMinimalPlainPropertyContainerMapper composedIdMapper, PropertyPath propertyPath) + { + MemberInfo member = propertyPath.LocalMember; + System.Type propertyType = member.GetPropertyOrFieldType(); + var memberPath = propertyPath; + if (modelInspector.IsProperty(member)) + { + MapProperty(member, memberPath, composedIdMapper); + } + else if (modelInspector.IsManyToOne(member)) + { + MapManyToOne(member, memberPath, composedIdMapper); + } + else if (modelInspector.IsAny(member) || modelInspector.IsComponent(propertyType) || + modelInspector.IsOneToOne(member) || modelInspector.IsSet(member) + || modelInspector.IsDictionary(member) || modelInspector.IsArray(member) + || modelInspector.IsList(member) || modelInspector.IsBag(member)) + { + throw new ArgumentOutOfRangeException("propertyPath", + string.Format("The property {0} of {1} can't be part of composite-id.", + member.Name, member.DeclaringType)); + } + else + { + MapProperty(member, memberPath, composedIdMapper); + } + } + private void MapNaturalIdProperties(System.Type rootEntityType, INaturalIdMapper naturalIdMapper, MemberInfo property) { MemberInfo member = property; @@ -973,7 +1036,7 @@ }); } - private void MapProperty(MemberInfo member, PropertyPath propertyPath, IBasePlainPropertyContainerMapper propertiesContainer) + private void MapProperty(MemberInfo member, PropertyPath propertyPath, IMinimalPlainPropertyContainerMapper propertiesContainer) { propertiesContainer.Property(member, propertyMapper => { @@ -1165,7 +1228,7 @@ }); } - private void MapManyToOne(MemberInfo member, PropertyPath propertyPath, IBasePlainPropertyContainerMapper propertiesContainer) + private void MapManyToOne(MemberInfo member, PropertyPath propertyPath, IMinimalPlainPropertyContainerMapper propertiesContainer) { propertiesContainer.ManyToOne(member, manyToOneMapper => { Modified: trunk/nhibernate/src/NHibernate/NHibernate.csproj =================================================================== --- trunk/nhibernate/src/NHibernate/NHibernate.csproj 2011-04-27 14:36:13 UTC (rev 5774) +++ trunk/nhibernate/src/NHibernate/NHibernate.csproj 2011-04-27 18:54:47 UTC (rev 5775) @@ -297,8 +297,11 @@ <Compile Include="Mapping\ByCode\Conformist\UnionSubclassMapping.cs" /> <Compile Include="Mapping\ByCode\ICompositeIdMapper.cs" /> <Compile Include="Mapping\ByCode\IDynamicComponentAttributesMapper.cs" /> + <Compile Include="Mapping\ByCode\Impl\ComponentAsIdLikeComponetAttributesMapper.cs" /> <Compile Include="Mapping\ByCode\Impl\ComponentAsIdMapper.cs" /> <Compile Include="Mapping\ByCode\Impl\ComposedIdMapper.cs" /> + <Compile Include="Mapping\ByCode\Impl\CustomizersImpl\ComponentAsIdCustomizer.cs" /> + <Compile Include="Mapping\ByCode\Impl\CustomizersImpl\ComposedIdCustomizer.cs" /> <Compile Include="Mapping\ByCode\Impl\CustomizersImpl\DynamicComponentCustomizer.cs" /> <Compile Include="Mapping\ByCode\Impl\DynamicComponentMapper.cs" /> <Compile Include="Mapping\ByCode\PropertyToField.cs" /> Added: trunk/nhibernate/src/NHibernate.Test/MappingByCode/ExpliticMappingTests/ComponentAsIdTests.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Test/MappingByCode/ExpliticMappingTests/ComponentAsIdTests.cs (rev 0) +++ trunk/nhibernate/src/NHibernate.Test/MappingByCode/ExpliticMappingTests/ComponentAsIdTests.cs 2011-04-27 18:54:47 UTC (rev 5775) @@ -0,0 +1,157 @@ +using System.Linq; +using NHibernate.Cfg.MappingSchema; +using NHibernate.Mapping.ByCode; +using NUnit.Framework; +using SharpTestsEx; + +namespace NHibernate.Test.MappingByCode.ExpliticMappingTests +{ + public class ComponentAsIdTests + { + private class MyClass + { + private IMyCompo id; + public IMyCompo Id + { + get { return id; } + set { id = value; } + } + } + + private interface IMyCompo + { + string Code { get; set; } + string Name { get; set; } + } + private class MyComponent : IMyCompo + { + public string Code { get; set; } + public string Name { get; set; } + } + + [Test] + public void WhenPropertyUsedAsComposedIdThenRegister() + { + var inspector = new ExplicitlyDeclaredModel(); + var mapper = new ModelMapper(inspector); + mapper.Class<MyClass>(map => map.ComponentAsId(x => x.Id)); + + inspector.IsPersistentId(For<MyClass>.Property(x => x.Id)).Should().Be.True(); + inspector.IsPersistentProperty(For<MyClass>.Property(x => x.Id)).Should().Be.True(); + inspector.IsComponent(typeof(IMyCompo)).Should().Be.True(); + } + + [Test] + public void WhenMapComponentAsIdThenMapItAndItsProperties() + { + var mapper = new ModelMapper(); + mapper.Class<MyClass>(map => map.ComponentAsId(x => x.Id, idmap => + { + idmap.Property(y => y.Code); + idmap.Property(y => y.Name); + })); + + var hbmMapping = mapper.CompileMappingFor(new[] { typeof(MyClass) }); + var hbmClass = hbmMapping.RootClasses[0]; + var hbmCompositId = hbmClass.CompositeId; + var keyProperties = hbmCompositId.Items.OfType<HbmKeyProperty>(); + keyProperties.Should().Have.Count.EqualTo(2); + keyProperties.Select(x => x.Name).Should().Have.SameValuesAs("Code", "Name"); + } + + [Test] + public void WhenMapComponentAsIdAttributesThenMapAttributes() + { + var mapper = new ModelMapper(); + mapper.Class<MyClass>(map => map.ComponentAsId(x => x.Id, idmap => + { + idmap.Access(Accessor.Field); + idmap.Class<MyComponent>(); + })); + + var hbmMapping = mapper.CompileMappingFor(new[] { typeof(MyClass) }); + var hbmClass = hbmMapping.RootClasses[0]; + var hbmCompositId = hbmClass.CompositeId; + hbmCompositId.access.Should().Contain("field"); + hbmCompositId.@class.Should().Contain("MyComponent"); + } + + [Test] + public void WhenMapComponentUsedAsComponentAsIdThenMapItAndItsProperties() + { + var mapper = new ModelMapper(); + mapper.Component<IMyCompo>(x => + { + x.Property(y => y.Code, pm => pm.Length(10)); + x.Property(y => y.Name); + }); + mapper.Class<MyClass>(map => map.ComponentAsId(x => x.Id)); + + var hbmMapping = mapper.CompileMappingFor(new[] { typeof(MyClass) }); + var hbmClass = hbmMapping.RootClasses[0]; + var hbmCompositId = hbmClass.CompositeId; + var keyProperties = hbmCompositId.Items.OfType<HbmKeyProperty>(); + keyProperties.Should().Have.Count.EqualTo(2); + keyProperties.Select(x => x.Name).Should().Have.SameValuesAs("Code", "Name"); + keyProperties.Where(x => x.Name == "Code").Single().length.Should().Be("10"); + } + + [Test] + public void WhenMapCustomizedComponentUsedAsComponentAsIdWithCustomizationThenUseComponentAsIdCustomization() + { + var mapper = new ModelMapper(); + mapper.Component<IMyCompo>(x => + { + x.Property(y => y.Code, pm=> pm.Length(10)); + x.Property(y => y.Name, pm => pm.Length(20)); + }); + mapper.Class<MyClass>(map => map.ComponentAsId(x => x.Id, idmap => + { + idmap.Property(y => y.Code, pm => pm.Length(15)); + idmap.Property(y => y.Name, pm => pm.Length(25)); + })); + + var hbmMapping = mapper.CompileMappingFor(new[] { typeof(MyClass) }); + var hbmClass = hbmMapping.RootClasses[0]; + var hbmCompositId = hbmClass.CompositeId; + var keyProperties = hbmCompositId.Items.OfType<HbmKeyProperty>(); + keyProperties.Select(x => x.length).Should().Have.SameValuesAs("15", "25"); + } + + [Test] + public void WhenMapAttributesOfCustomizedComponentUsedAsComponentAsIdWithCustomizationThenUseInComponentAsIdCustomization() + { + var mapper = new ModelMapper(); + mapper.Component<IMyCompo>(x => + { + x.Access(Accessor.Field); + x.Class<MyComponent>(); + }); + mapper.Class<MyClass>(map => map.ComponentAsId(x => x.Id)); + + var hbmMapping = mapper.CompileMappingFor(new[] { typeof(MyClass) }); + var hbmClass = hbmMapping.RootClasses[0]; + var hbmCompositId = hbmClass.CompositeId; + hbmCompositId.access.Should().Contain("field"); + hbmCompositId.@class.Should().Contain("MyComponent"); + } + + [Test] + public void WhenMapAttributesOfCustomizedComponentUsedAsComponentAsIdWithCustomizationOverrideThenUseComponentAsIdCustomization() + { + var mapper = new ModelMapper(); + mapper.Component<IMyCompo>(x => + { + x.Access(Accessor.Field); + x.Class<MyComponent>(); + }); + mapper.Class<MyClass>(map => map.ComponentAsId(x => x.Id, idmap => idmap.Access(Accessor.NoSetter))); + + var hbmMapping = mapper.CompileMappingFor(new[] { typeof(MyClass) }); + var hbmClass = hbmMapping.RootClasses[0]; + var hbmCompositId = hbmClass.CompositeId; + hbmCompositId.access.Should().Contain("nosetter"); + hbmCompositId.@class.Should().Contain("MyComponent"); + } + } +} \ No newline at end of file Added: trunk/nhibernate/src/NHibernate.Test/MappingByCode/ExpliticMappingTests/ComposedIdTests.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Test/MappingByCode/ExpliticMappingTests/ComposedIdTests.cs (rev 0) +++ trunk/nhibernate/src/NHibernate.Test/MappingByCode/ExpliticMappingTests/ComposedIdTests.cs 2011-04-27 18:54:47 UTC (rev 5775) @@ -0,0 +1,119 @@ +using System; +using NHibernate.Cfg.MappingSchema; +using NHibernate.Mapping.ByCode; +using NUnit.Framework; +using SharpTestsEx; + +namespace NHibernate.Test.MappingByCode.ExpliticMappingTests +{ + public class ComposedIdTests + { + private class MyClass + { + public int Code { get; set; } + private MyOther relation; + public MyOther Relation + { + get { return relation; } + set { relation = value; } + } + } + + private class MyOther + { + public int Id { get; set; } + } + + [Test] + public void WhenPropertyUsedAsComposedIdThenRegister() + { + var inspector = new ExplicitlyDeclaredModel(); + var mapper = new ModelMapper(inspector); + mapper.Class<MyClass>(map => + map.ComposedId(cm=> + { + cm.Property(x => x.Code); + cm.ManyToOne(x => x.Relation); + }) + ); + + inspector.IsMemberOfComposedId(For<MyClass>.Property(x => x.Code)).Should().Be.True(); + inspector.IsMemberOfComposedId(For<MyClass>.Property(x => x.Relation)).Should().Be.True(); + inspector.IsPersistentProperty(For<MyClass>.Property(x => x.Code)).Should().Be.True(); + inspector.IsPersistentProperty(For<MyClass>.Property(x => x.Relation)).Should().Be.True(); + inspector.IsPersistentId(For<MyClass>.Property(x => x.Code)).Should().Be.False(); + inspector.IsPersistentId(For<MyClass>.Property(x => x.Relation)).Should().Be.False(); + } + + [Test] + public void WhenPropertyUsedAsComposedIdThenNotUsedAsSimpleProperties() + { + var mapper = new ModelMapper(); + mapper.Class<MyClass>(map => + map.ComposedId(cm => + { + cm.Property(x => x.Code); + cm.ManyToOne(x => x.Relation); + }) + ); + var hbmMapping = mapper.CompileMappingFor(new[] { typeof(MyClass) }); + var hbmClass = hbmMapping.RootClasses[0]; + var hbmCompositId = hbmClass.CompositeId; + hbmCompositId.Items.Should().Have.Count.EqualTo(2); + hbmClass.Properties.Should().Be.Empty(); + } + + [Test] + public void WhenPropertyUsedAsComposedIdAndPropertiesThenNotUsedAsSimpleProperties() + { + var mapper = new ModelMapper(); + mapper.Class<MyClass>(map => + { + map.ComposedId(cm => + { + cm.Property(x => x.Code); + cm.ManyToOne(x => x.Relation); + }); + map.Property(x => x.Code); + map.ManyToOne(x => x.Relation); + } + ); + HbmMapping hbmMapping = mapper.CompileMappingFor(new[] {typeof (MyClass)}); + HbmClass hbmClass = hbmMapping.RootClasses[0]; + HbmCompositeId hbmCompositId = hbmClass.CompositeId; + hbmCompositId.Items.Should().Have.Count.EqualTo(2); + hbmClass.Properties.Should().Be.Empty(); + } + + [Test] + public void WhenPropertyUsedAsComposedIdAndPropertiesAndNaturalIdThenMapOnlyAsComposedId() + { + var mapper = new ModelMapper(); + mapper.Class<MyClass>(map => + { + map.ComposedId(cm => + { + cm.Property(x => x.Code); + cm.ManyToOne(x => x.Relation); + }); + map.NaturalId(nm => + { + nm.Property(x => x.Code); + nm.ManyToOne(x => x.Relation); + }); + map.Property(x => x.Code); + map.ManyToOne(x => x.Relation); + } + ); + HbmMapping hbmMapping = mapper.CompileMappingFor(new[] { typeof(MyClass) }); + HbmClass hbmClass = hbmMapping.RootClasses[0]; + HbmCompositeId hbmCompositId = hbmClass.CompositeId; + hbmCompositId.Items.Should().Have.Count.EqualTo(2); + if(hbmClass.naturalid != null) + { + hbmClass.naturalid.Items.Should().Be.Null(); + } + hbmClass.Properties.Should().Be.Empty(); + } + } +} \ 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-27 14:36:13 UTC (rev 5774) +++ trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2011-04-27 18:54:47 UTC (rev 5775) @@ -519,6 +519,8 @@ <Compile Include="MappingByCode\ConventionModelMapperTests\VersionOnBaseClassIntegrationTest.cs" /> <Compile Include="MappingByCode\ExpliticMappingTests\BagOfNestedComponentsWithParentTest.cs" /> <Compile Include="MappingByCode\ExpliticMappingTests\ClassWithComponentsTest.cs" /> + <Compile Include="MappingByCode\ExpliticMappingTests\ComponentAsIdTests.cs" /> + <Compile Include="MappingByCode\ExpliticMappingTests\ComposedIdTests.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-27 14:36:22
|
Revision: 5774 http://nhibernate.svn.sourceforge.net/nhibernate/?rev=5774&view=rev Author: fabiomaulo Date: 2011-04-27 14:36:13 +0000 (Wed, 27 Apr 2011) Log Message: ----------- IModelInspector and IModelExplicitDeclarationsHolder managing composed-id 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/IModelInspector.cs trunk/nhibernate/src/NHibernate/Mapping/ByCode/Impl/ExplicitDeclarationsHolder.cs trunk/nhibernate/src/NHibernate/Mapping/ByCode/ModelExplicitDeclarationsHolderExtensions.cs trunk/nhibernate/src/NHibernate/Mapping/ByCode/SimpleModelInspector.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-27 13:53:14 UTC (rev 5773) +++ trunk/nhibernate/src/NHibernate/Mapping/ByCode/ExplicitlyDeclaredModel.cs 2011-04-27 14:36:13 UTC (rev 5774) @@ -17,6 +17,7 @@ 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> composedIds = 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>(); @@ -92,6 +93,11 @@ get { return poids; } } + public IEnumerable<MemberInfo> ComposedIds + { + get { return composedIds; } + } + public IEnumerable<MemberInfo> VersionProperties { get { return versionProperties; } @@ -330,6 +336,12 @@ poids.Add(member); } + public void AddAsPartOfComposedId(MemberInfo member) + { + persistentMembers.Add(member); + composedIds.Add(member); + } + public void AddAsVersionProperty(MemberInfo member) { persistentMembers.Add(member); @@ -502,6 +514,11 @@ return poids.Contains(member); } + public bool IsMemberOfComposedId(MemberInfo member) + { + return composedIds.Contains(member); + } + public virtual bool IsVersion(MemberInfo member) { return versionProperties.Contains(member); Modified: trunk/nhibernate/src/NHibernate/Mapping/ByCode/FakeModelExplicitDeclarationsHolder.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Mapping/ByCode/FakeModelExplicitDeclarationsHolder.cs 2011-04-27 13:53:14 UTC (rev 5773) +++ trunk/nhibernate/src/NHibernate/Mapping/ByCode/FakeModelExplicitDeclarationsHolder.cs 2011-04-27 14:36:13 UTC (rev 5774) @@ -1,4 +1,3 @@ -using System; using System.Collections.Generic; using System.Linq; using System.Reflection; @@ -20,6 +19,7 @@ private readonly IEnumerable<MemberInfo> oneToManyRelations = Enumerable.Empty<MemberInfo>(); private readonly IEnumerable<MemberInfo> oneToOneRelations = Enumerable.Empty<MemberInfo>(); private readonly IEnumerable<MemberInfo> poids = Enumerable.Empty<MemberInfo>(); + private readonly IEnumerable<MemberInfo> composedIds = Enumerable.Empty<MemberInfo>(); private readonly IEnumerable<MemberInfo> properties = Enumerable.Empty<MemberInfo>(); private readonly IEnumerable<MemberInfo> dynamicComponents = Enumerable.Empty<MemberInfo>(); private readonly IEnumerable<MemberInfo> persistentMembers = new HashSet<MemberInfo>(); @@ -94,6 +94,11 @@ get { return poids; } } + public IEnumerable<MemberInfo> ComposedIds + { + get { return composedIds; } + } + public IEnumerable<MemberInfo> VersionProperties { get { return versionProperties; } @@ -192,6 +197,7 @@ public void AddAsAny(MemberInfo member) {} public void AddAsPoid(MemberInfo member) {} + public void AddAsPartOfComposedId(MemberInfo member) {} public void AddAsVersionProperty(MemberInfo member) {} Modified: trunk/nhibernate/src/NHibernate/Mapping/ByCode/IModelExplicitDeclarationsHolder.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Mapping/ByCode/IModelExplicitDeclarationsHolder.cs 2011-04-27 13:53:14 UTC (rev 5773) +++ trunk/nhibernate/src/NHibernate/Mapping/ByCode/IModelExplicitDeclarationsHolder.cs 2011-04-27 14:36:13 UTC (rev 5774) @@ -32,6 +32,7 @@ IEnumerable<MemberInfo> Any { get; } IEnumerable<MemberInfo> Poids { get; } + IEnumerable<MemberInfo> ComposedIds { get; } IEnumerable<MemberInfo> VersionProperties { get; } IEnumerable<MemberInfo> NaturalIds { get; } @@ -63,6 +64,7 @@ void AddAsAny(MemberInfo member); void AddAsPoid(MemberInfo member); + void AddAsPartOfComposedId(MemberInfo member); void AddAsVersionProperty(MemberInfo member); void AddAsNaturalId(MemberInfo member); Modified: trunk/nhibernate/src/NHibernate/Mapping/ByCode/IModelInspector.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Mapping/ByCode/IModelInspector.cs 2011-04-27 13:53:14 UTC (rev 5773) +++ trunk/nhibernate/src/NHibernate/Mapping/ByCode/IModelInspector.cs 2011-04-27 14:36:13 UTC (rev 5774) @@ -21,6 +21,7 @@ bool IsAny(MemberInfo member); bool IsPersistentId(MemberInfo member); + bool IsMemberOfComposedId(MemberInfo member); bool IsVersion(MemberInfo member); bool IsMemberOfNaturalId(MemberInfo member); Modified: trunk/nhibernate/src/NHibernate/Mapping/ByCode/Impl/ExplicitDeclarationsHolder.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Mapping/ByCode/Impl/ExplicitDeclarationsHolder.cs 2011-04-27 13:53:14 UTC (rev 5773) +++ trunk/nhibernate/src/NHibernate/Mapping/ByCode/Impl/ExplicitDeclarationsHolder.cs 2011-04-27 14:36:13 UTC (rev 5774) @@ -19,6 +19,7 @@ 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> composedIds = new HashSet<MemberInfo>(); private readonly HashSet<MemberInfo> properties = new HashSet<MemberInfo>(); private readonly HashSet<MemberInfo> dynamicComponents = new HashSet<MemberInfo>(); private readonly Dictionary<MemberInfo, System.Type> dynamicComponentTemplates = new Dictionary<MemberInfo, System.Type>(); @@ -88,6 +89,11 @@ get { return poids; } } + public IEnumerable<MemberInfo> ComposedIds + { + get { return composedIds; } + } + public IEnumerable<MemberInfo> VersionProperties { get { return versionProperties; } @@ -220,6 +226,11 @@ poids.Add(member); } + public void AddAsPartOfComposedId(MemberInfo member) + { + composedIds.Add(member); + } + public void AddAsVersionProperty(MemberInfo member) { versionProperties.Add(member); Modified: trunk/nhibernate/src/NHibernate/Mapping/ByCode/ModelExplicitDeclarationsHolderExtensions.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Mapping/ByCode/ModelExplicitDeclarationsHolderExtensions.cs 2011-04-27 13:53:14 UTC (rev 5773) +++ trunk/nhibernate/src/NHibernate/Mapping/ByCode/ModelExplicitDeclarationsHolderExtensions.cs 2011-04-27 14:36:13 UTC (rev 5774) @@ -24,6 +24,7 @@ System.Array.ForEach(source.Any.ToArray(), destination.AddAsAny); System.Array.ForEach(source.Poids.ToArray(), destination.AddAsPoid); + System.Array.ForEach(source.ComposedIds.ToArray(), destination.AddAsPartOfComposedId); System.Array.ForEach(source.VersionProperties.ToArray(), destination.AddAsVersionProperty); System.Array.ForEach(source.NaturalIds.ToArray(), destination.AddAsNaturalId); Modified: trunk/nhibernate/src/NHibernate/Mapping/ByCode/SimpleModelInspector.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Mapping/ByCode/SimpleModelInspector.cs 2011-04-27 13:53:14 UTC (rev 5773) +++ trunk/nhibernate/src/NHibernate/Mapping/ByCode/SimpleModelInspector.cs 2011-04-27 14:36:13 UTC (rev 5774) @@ -472,6 +472,16 @@ declaredModel.AddAsDynamicComponent(member, componentTemplate); } + IEnumerable<MemberInfo> IModelExplicitDeclarationsHolder.ComposedIds + { + get { return declaredModel.ComposedIds; } + } + + void IModelExplicitDeclarationsHolder.AddAsPartOfComposedId(MemberInfo member) + { + declaredModel.AddAsPartOfComposedId(member); + } + #endregion #region Implementation of IModelInspector @@ -554,6 +564,11 @@ return isPersistentId(member, declaredResult); } + bool IModelInspector.IsMemberOfComposedId(MemberInfo member) + { + return declaredModel.IsPersistentId(member); + } + bool IModelInspector.IsVersion(MemberInfo member) { bool declaredResult = declaredModel.IsVersion(member); Modified: trunk/nhibernate/src/NHibernate.Test/MappingByCode/ModelExplicitDeclarationsHolderMergeTest.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Test/MappingByCode/ModelExplicitDeclarationsHolderMergeTest.cs 2011-04-27 13:53:14 UTC (rev 5773) +++ trunk/nhibernate/src/NHibernate.Test/MappingByCode/ModelExplicitDeclarationsHolderMergeTest.cs 2011-04-27 14:36:13 UTC (rev 5774) @@ -271,6 +271,17 @@ destination.GetDynamicComponentTemplate(property).Should().Be(typeof(MyClass)); } + [Test] + public void MergeComposedId() + { + var destination = new ExplicitDeclarationsHolder(); + var source = new ExplicitDeclarationsHolder(); + source.AddAsPartOfComposedId(property); + + destination.Merge(source); + destination.ComposedIds.Should().Have.Count.EqualTo(1); + } + #region Nested type: MyClass private class MyClass This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fab...@us...> - 2011-04-27 13:53:25
|
Revision: 5773 http://nhibernate.svn.sourceforge.net/nhibernate/?rev=5773&view=rev Author: fabiomaulo Date: 2011-04-27 13:53:14 +0000 (Wed, 27 Apr 2011) Log Message: ----------- Minor (fixed TYPO) Modified Paths: -------------- trunk/nhibernate/src/NHibernate/Mapping/ByCode/ExplicitlyDeclaredModel.cs trunk/nhibernate/src/NHibernate/Mapping/ByCode/Impl/ClassMapper.cs Modified: trunk/nhibernate/src/NHibernate/Mapping/ByCode/ExplicitlyDeclaredModel.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Mapping/ByCode/ExplicitlyDeclaredModel.cs 2011-04-27 13:51:34 UTC (rev 5772) +++ trunk/nhibernate/src/NHibernate/Mapping/ByCode/ExplicitlyDeclaredModel.cs 2011-04-27 13:53:14 UTC (rev 5773) @@ -177,7 +177,7 @@ { if (IsComponent(type)) { - throw new MappingException(string.Format("Abiguous mapping of {0}. It was registered as entity and as component", type.FullName)); + throw new MappingException(string.Format("Ambiguous mapping of {0}. It was registered as entity and as component", type.FullName)); } rootEntities.Add(type); } @@ -187,7 +187,7 @@ var rootEntity = GetRootEntityOrNull(type); if (rootEntity != null) { - throw new MappingException(string.Format("Abiguous mapping of {0}. It was registered as entity and as component", type.FullName)); + throw new MappingException(string.Format("Ambiguous mapping of {0}. It was registered as entity and as component", type.FullName)); } components.Add(type); } @@ -201,18 +201,18 @@ { if (IsComponent(type)) { - throw new MappingException(string.Format("Abiguous mapping of {0}. It was registered as entity and as component", type.FullName)); + throw new MappingException(string.Format("Ambiguous mapping of {0}. It was registered as entity and as component", type.FullName)); } var rootEntity = GetRootEntityOrNull(type); if (rootEntity != null) { if (rootEntity.Equals(type)) { - throw new MappingException(string.Format("Abiguous mapping of {0}. It was registered as root-entity and as subclass for table-per-class strategy", type.FullName)); + throw new MappingException(string.Format("Ambiguous mapping of {0}. It was registered as root-entity and as subclass for table-per-class strategy", type.FullName)); } if (IsMappedFor(tablePerClassHierarchyEntities, type) || IsMappedFor(tablePerConcreteClassEntities, type)) { - throw new MappingException(string.Format("Abiguous mapping of {0}. It was registered with more than one class-hierarchy strategy", type.FullName)); + throw new MappingException(string.Format("Ambiguous mapping of {0}. It was registered with more than one class-hierarchy strategy", type.FullName)); } tablePerClassEntities.Add(rootEntity); } @@ -235,18 +235,18 @@ { if (IsComponent(type)) { - throw new MappingException(string.Format("Abiguous mapping of {0}. It was registered as entity and as component", type.FullName)); + throw new MappingException(string.Format("Ambiguous mapping of {0}. It was registered as entity and as component", type.FullName)); } var rootEntity = GetRootEntityOrNull(type); if (rootEntity != null) { if (rootEntity.Equals(type)) { - throw new MappingException(string.Format("Abiguous mapping of {0}. It was registered as root-entity and as subclass for table-per-class-hierarchy strategy", type.FullName)); + throw new MappingException(string.Format("Ambiguous mapping of {0}. It was registered as root-entity and as subclass for table-per-class-hierarchy strategy", type.FullName)); } if (IsMappedFor(tablePerClassEntities, type) || IsMappedFor(tablePerConcreteClassEntities, type)) { - throw new MappingException(string.Format("Abiguous mapping of {0}. It was registered with more than one class-hierarchy strategy", type.FullName)); + throw new MappingException(string.Format("Ambiguous mapping of {0}. It was registered with more than one class-hierarchy strategy", type.FullName)); } tablePerClassHierarchyEntities.Add(rootEntity); } @@ -269,18 +269,18 @@ { if (IsComponent(type)) { - throw new MappingException(string.Format("Abiguous mapping of {0}. It was registered as entity and as component", type.FullName)); + throw new MappingException(string.Format("Ambiguous mapping of {0}. It was registered as entity and as component", type.FullName)); } var rootEntity = GetRootEntityOrNull(type); if (rootEntity != null) { if (rootEntity.Equals(type)) { - throw new MappingException(string.Format("Abiguous mapping of {0}. It was registered as root-entity and as subclass for table-per-concrete-class strategy", type.FullName)); + throw new MappingException(string.Format("Ambiguous mapping of {0}. It was registered as root-entity and as subclass for table-per-concrete-class strategy", type.FullName)); } if (IsMappedFor(tablePerClassEntities, type) || IsMappedFor(tablePerClassHierarchyEntities, type)) { - throw new MappingException(string.Format("Abiguous mapping of {0}. It was registered with more than one class-hierarchy strategy", type.FullName)); + throw new MappingException(string.Format("Ambiguous mapping of {0}. It was registered with more than one class-hierarchy strategy", type.FullName)); } tablePerConcreteClassEntities.Add(rootEntity); } Modified: trunk/nhibernate/src/NHibernate/Mapping/ByCode/Impl/ClassMapper.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Mapping/ByCode/Impl/ClassMapper.cs 2011-04-27 13:51:34 UTC (rev 5772) +++ trunk/nhibernate/src/NHibernate/Mapping/ByCode/Impl/ClassMapper.cs 2011-04-27 13:53:14 UTC (rev 5773) @@ -71,7 +71,7 @@ if(id == null) { var propertyDescription = idProperty != null ? " '" + idProperty.Name + "'" : ", with generator, "; - throw new MappingException(string.Format("Abiguous mapping of {0} id. A ComponentAsId or a ComposedId was used and you are trying to map the property{1} as id.", + throw new MappingException(string.Format("Ambiguous mapping of {0} id. A ComponentAsId or a ComposedId was used and you are trying to map the property{1} as id.", Container.FullName, propertyDescription)); } mapper(new IdMapper(idProperty, id)); @@ -93,12 +93,12 @@ } if (composedIdWasUsed) { - throw new MappingException(string.Format("Abiguous mapping of {0} id. A composed id was defined and you are trying to map the component {1}, of property '{2}', as id for {0}." + throw new MappingException(string.Format("Ambiguous mapping of {0} id. A composed id was defined and you are trying to map the component {1}, of property '{2}', as id for {0}." , Container.FullName, idProperty.GetPropertyOrFieldType().FullName, idProperty.Name)); } if (simpleIdPropertyWasUsed) { - throw new MappingException(string.Format("Abiguous mapping of {0} id. An id property, with generator, was defined and you are trying to map the component {1}, of property '{2}', as id for {0}." + throw new MappingException(string.Format("Ambiguous mapping of {0} id. An id property, with generator, was defined and you are trying to map the component {1}, of property '{2}', as id for {0}." , Container.FullName, idProperty.GetPropertyOrFieldType().FullName, idProperty.Name)); } var id = classMapping.Item as HbmCompositeId; @@ -115,11 +115,11 @@ { if(componentAsIdWasUsed) { - throw new MappingException(string.Format("Abiguous mapping of {0} id. A Component as id was used and you are trying to map an id composed by various properties of {0}.", Container.FullName)); + throw new MappingException(string.Format("Ambiguous mapping of {0} id. A Component as id was used and you are trying to map an id composed by various properties of {0}.", Container.FullName)); } if (simpleIdPropertyWasUsed) { - throw new MappingException(string.Format("Abiguous mapping of {0} id. An id property, with generator, was defined and you are trying to map an id composed by various properties of {0}.", Container.FullName)); + throw new MappingException(string.Format("Ambiguous mapping of {0} id. An id property, with generator, was defined and you are trying to map an id composed by various properties of {0}.", Container.FullName)); } var id = classMapping.Item as HbmCompositeId; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fab...@us...> - 2011-04-27 13:51:46
|
Revision: 5772 http://nhibernate.svn.sourceforge.net/nhibernate/?rev=5772&view=rev Author: fabiomaulo Date: 2011-04-27 13:51:34 +0000 (Wed, 27 Apr 2011) Log Message: ----------- Implemented ambiguous mapping checking for Id Modified Paths: -------------- 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/ClassMapperTests/CheckMixingPOIDStrategiesTests.cs Modified: trunk/nhibernate/src/NHibernate/Mapping/ByCode/Impl/ClassMapper.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Mapping/ByCode/Impl/ClassMapper.cs 2011-04-27 12:08:50 UTC (rev 5771) +++ trunk/nhibernate/src/NHibernate/Mapping/ByCode/Impl/ClassMapper.cs 2011-04-27 13:51:34 UTC (rev 5772) @@ -11,6 +11,9 @@ { private readonly HbmClass classMapping; private readonly IIdMapper idMapper; + private bool simpleIdPropertyWasUsed; + private bool composedIdWasUsed; + private bool componentAsIdWasUsed; private Dictionary<string, IJoinMapper> joinMappers; private ICacheMapper cacheMapper; private IDiscriminatorMapper discriminatorMapper; @@ -64,16 +67,40 @@ public void Id(MemberInfo idProperty, Action<IIdMapper> mapper) { - var id = (HbmId) classMapping.Item; + var id = classMapping.Item as HbmId; + if(id == null) + { + var propertyDescription = idProperty != null ? " '" + idProperty.Name + "'" : ", with generator, "; + throw new MappingException(string.Format("Abiguous mapping of {0} id. A ComponentAsId or a ComposedId was used and you are trying to map the property{1} as id.", + Container.FullName, propertyDescription)); + } mapper(new IdMapper(idProperty, id)); + if(idProperty != null) + { + simpleIdPropertyWasUsed = true; + } } public void ComponentAsId(MemberInfo idProperty, Action<IComponentAsIdMapper> mapper) { + if (idProperty == null) + { + return; + } if (!IsMemberSupportedByMappedContainer(idProperty)) { throw new ArgumentOutOfRangeException("idProperty", "Can't use, as component id property, a property of another graph"); } + if (composedIdWasUsed) + { + throw new MappingException(string.Format("Abiguous mapping of {0} id. A composed id was defined and you are trying to map the component {1}, of property '{2}', as id for {0}." + , Container.FullName, idProperty.GetPropertyOrFieldType().FullName, idProperty.Name)); + } + if (simpleIdPropertyWasUsed) + { + throw new MappingException(string.Format("Abiguous mapping of {0} id. An id property, with generator, was defined and you are trying to map the component {1}, of property '{2}', as id for {0}." + , Container.FullName, idProperty.GetPropertyOrFieldType().FullName, idProperty.Name)); + } var id = classMapping.Item as HbmCompositeId; if(id == null) { @@ -81,10 +108,20 @@ classMapping.Item = id; } mapper(new ComponentAsIdMapper(idProperty.GetPropertyOrFieldType(), idProperty, id, mapDoc)); + componentAsIdWasUsed = true; } public void ComposedId(Action<IComposedIdMapper> idPropertiesMapping) { + if(componentAsIdWasUsed) + { + throw new MappingException(string.Format("Abiguous mapping of {0} id. A Component as id was used and you are trying to map an id composed by various properties of {0}.", Container.FullName)); + } + if (simpleIdPropertyWasUsed) + { + throw new MappingException(string.Format("Abiguous mapping of {0} id. An id property, with generator, was defined and you are trying to map an id composed by various properties of {0}.", Container.FullName)); + } + var id = classMapping.Item as HbmCompositeId; if (id == null) { @@ -92,6 +129,7 @@ classMapping.Item = id; } idPropertiesMapping(new ComposedIdMapper(Container, id, mapDoc)); + composedIdWasUsed = true; } public void Discriminator(Action<IDiscriminatorMapper> discriminatorMapping) Added: trunk/nhibernate/src/NHibernate.Test/MappingByCode/MappersTests/ClassMapperTests/CheckMixingPOIDStrategiesTests.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Test/MappingByCode/MappersTests/ClassMapperTests/CheckMixingPOIDStrategiesTests.cs (rev 0) +++ trunk/nhibernate/src/NHibernate.Test/MappingByCode/MappersTests/ClassMapperTests/CheckMixingPOIDStrategiesTests.cs 2011-04-27 13:51:34 UTC (rev 5772) @@ -0,0 +1,99 @@ +using NHibernate.Cfg.MappingSchema; +using NHibernate.Mapping.ByCode.Impl; +using NUnit.Framework; +using SharpTestsEx; + +namespace NHibernate.Test.MappingByCode.MappersTests.ClassMapperTests +{ + public class CheckMixingPoidStrategiesTests + { + private class PersonId + { + public string Email { get; set; } + } + + private class Person + { + private PersonId id; + public PersonId Id + { + get { return id; } + } + + public int Poid { get; set; } + public string Name { get; set; } + } + + [Test] + public void WhenMixComposedIdWithComponentAsIdThenThrows() + { + var mapdoc = new HbmMapping(); + var mapper = new ClassMapper(typeof (Person), mapdoc, For<Person>.Property(x => x.Id)); + + mapper.ComposedId(map => map.Property(For<Person>.Property(x => x.Name), pm => { })); + Executing.This(() => + mapper.ComponentAsId(For<Person>.Property(x => x.Id), map => map.Property(For<PersonId>.Property(x => x.Email), pm => { })) + ).Should().Throw<MappingException>(); + } + + [Test] + public void WhenMixComponentAsIdWithComposedIdThenThrows() + { + var mapdoc = new HbmMapping(); + var mapper = new ClassMapper(typeof(Person), mapdoc, For<Person>.Property(x => x.Id)); + + mapper.ComponentAsId(For<Person>.Property(x => x.Id), map => map.Property(For<PersonId>.Property(x => x.Email), pm => { })); + Executing.This(() => + mapper.ComposedId(map => map.Property(For<Person>.Property(x => x.Name), pm => { })) + ).Should().Throw<MappingException>(); + } + + [Test] + public void WhenMixComposedIdWithSimpleIdThenThrows() + { + var mapdoc = new HbmMapping(); + var mapper = new ClassMapper(typeof(Person), mapdoc, For<Person>.Property(x => x.Id)); + + mapper.ComposedId(map => map.Property(For<Person>.Property(x => x.Name), pm => { })); + Executing.This(() => + mapper.Id(For<Person>.Property(x => x.Poid), pm => { }) + ).Should().Throw<MappingException>(); + } + + [Test] + public void WhenMixComponentAsIdWithSimpleIdThenThrows() + { + var mapdoc = new HbmMapping(); + var mapper = new ClassMapper(typeof(Person), mapdoc, For<Person>.Property(x => x.Id)); + + mapper.ComponentAsId(For<Person>.Property(x => x.Id), map => map.Property(For<PersonId>.Property(x => x.Email), pm => { })); + Executing.This(() => + mapper.Id(For<Person>.Property(x => x.Poid), pm => { }) + ).Should().Throw<MappingException>(); + } + + [Test] + public void WhenMixSimpleIdWithComposedIdThenThrows() + { + var mapdoc = new HbmMapping(); + var mapper = new ClassMapper(typeof(Person), mapdoc, For<Person>.Property(x => x.Id)); + + mapper.Id(For<Person>.Property(x => x.Poid), pm => { }); + Executing.This(() => + mapper.ComposedId(map => map.Property(For<Person>.Property(x => x.Name), pm => { })) + ).Should().Throw<MappingException>(); + } + + [Test] + public void WhenMixSimpleIdWithComponentAsIdThenThrows() + { + var mapdoc = new HbmMapping(); + var mapper = new ClassMapper(typeof(Person), mapdoc, For<Person>.Property(x => x.Id)); + + mapper.Id(For<Person>.Property(x => x.Poid), pm => { }); + Executing.This(() => + mapper.ComponentAsId(For<Person>.Property(x => x.Id), map => map.Property(For<PersonId>.Property(x => x.Email), pm => { })) + ).Should().Throw<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-27 12:08:50 UTC (rev 5771) +++ trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2011-04-27 13:51:34 UTC (rev 5772) @@ -548,6 +548,7 @@ <Compile Include="MappingByCode\ExpliticMappingTests\VersionTests.cs" /> <Compile Include="MappingByCode\For.cs" /> <Compile Include="MappingByCode\MappersTests\AbstractPropertyContainerMapperTest.cs" /> + <Compile Include="MappingByCode\MappersTests\ClassMapperTests\CheckMixingPOIDStrategiesTests.cs" /> <Compile Include="MappingByCode\MappersTests\ClassMapperTests\ClassMapperWithJoinPropertiesTest.cs" /> <Compile Include="MappingByCode\MappersTests\ClassMapperTests\ComponetAsIdTests.cs" /> <Compile Include="MappingByCode\MappersTests\ClassMapperTests\ComposedIdTests.cs" /> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fab...@us...> - 2011-04-27 12:09:01
|
Revision: 5771 http://nhibernate.svn.sourceforge.net/nhibernate/?rev=5771&view=rev Author: fabiomaulo Date: 2011-04-27 12:08:50 +0000 (Wed, 27 Apr 2011) Log Message: ----------- ClassMapper with ComponentAsId and ComposedId Modified Paths: -------------- trunk/nhibernate/src/NHibernate/Mapping/ByCode/IClassMapper.cs trunk/nhibernate/src/NHibernate/Mapping/ByCode/Impl/ClassMapper.cs trunk/nhibernate/src/NHibernate/Mapping/ByCode/Impl/ComposedIdMapper.cs trunk/nhibernate/src/NHibernate.Test/MappingByCode/MappersTests/ComposedIdMapperTests.cs trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj Added Paths: ----------- trunk/nhibernate/src/NHibernate.Test/MappingByCode/MappersTests/ClassMapperTests/ComponetAsIdTests.cs trunk/nhibernate/src/NHibernate.Test/MappingByCode/MappersTests/ClassMapperTests/ComposedIdTests.cs Modified: trunk/nhibernate/src/NHibernate/Mapping/ByCode/IClassMapper.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Mapping/ByCode/IClassMapper.cs 2011-04-27 09:49:57 UTC (rev 5770) +++ trunk/nhibernate/src/NHibernate/Mapping/ByCode/IClassMapper.cs 2011-04-27 12:08:50 UTC (rev 5771) @@ -8,6 +8,10 @@ { void Id(Action<IIdMapper> idMapper); void Id(MemberInfo idProperty, Action<IIdMapper> idMapper); + + void ComponentAsId(MemberInfo idProperty, Action<IComponentAsIdMapper> idMapper); + void ComposedId(Action<IComposedIdMapper> idPropertiesMapping); + void Discriminator(Action<IDiscriminatorMapper> discriminatorMapping); void DiscriminatorValue(object value); void Table(string tableName); @@ -37,6 +41,12 @@ 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 ComponentAsId<TComponent>(Expression<Func<TEntity, TComponent>> idProperty) where TComponent : class; + //void ComponentAsId<TComponent>(Expression<Func<TEntity, TComponent>> idProperty, Action<IComponentAsIdMapper<TComponent>> idMapper) where TComponent : class; + + //void ComposedId(Action<IComposedIdMapper<TEntity>> idPropertiesMapping); + void Discriminator(Action<IDiscriminatorMapper> discriminatorMapping); void DiscriminatorValue(object value); void Table(string tableName); Modified: trunk/nhibernate/src/NHibernate/Mapping/ByCode/Impl/ClassMapper.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Mapping/ByCode/Impl/ClassMapper.cs 2011-04-27 09:49:57 UTC (rev 5770) +++ trunk/nhibernate/src/NHibernate/Mapping/ByCode/Impl/ClassMapper.cs 2011-04-27 12:08:50 UTC (rev 5771) @@ -68,6 +68,32 @@ mapper(new IdMapper(idProperty, id)); } + public void ComponentAsId(MemberInfo idProperty, Action<IComponentAsIdMapper> mapper) + { + if (!IsMemberSupportedByMappedContainer(idProperty)) + { + throw new ArgumentOutOfRangeException("idProperty", "Can't use, as component id property, a property of another graph"); + } + var id = classMapping.Item as HbmCompositeId; + if(id == null) + { + id = new HbmCompositeId(); + classMapping.Item = id; + } + mapper(new ComponentAsIdMapper(idProperty.GetPropertyOrFieldType(), idProperty, id, mapDoc)); + } + + public void ComposedId(Action<IComposedIdMapper> idPropertiesMapping) + { + var id = classMapping.Item as HbmCompositeId; + if (id == null) + { + id = new HbmCompositeId(); + classMapping.Item = id; + } + idPropertiesMapping(new ComposedIdMapper(Container, id, mapDoc)); + } + public void Discriminator(Action<IDiscriminatorMapper> discriminatorMapping) { if (discriminatorMapper == null) Modified: trunk/nhibernate/src/NHibernate/Mapping/ByCode/Impl/ComposedIdMapper.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Mapping/ByCode/Impl/ComposedIdMapper.cs 2011-04-27 09:49:57 UTC (rev 5770) +++ trunk/nhibernate/src/NHibernate/Mapping/ByCode/Impl/ComposedIdMapper.cs 2011-04-27 12:08:50 UTC (rev 5771) @@ -7,11 +7,13 @@ { public class ComposedIdMapper : IComposedIdMapper { + private readonly System.Type container; private readonly HbmCompositeId id; private readonly HbmMapping mapDoc; - public ComposedIdMapper(HbmCompositeId id, HbmMapping mapDoc) + public ComposedIdMapper(System.Type container, HbmCompositeId id, HbmMapping mapDoc) { + this.container = container; this.id = id; this.mapDoc = mapDoc; } Added: trunk/nhibernate/src/NHibernate.Test/MappingByCode/MappersTests/ClassMapperTests/ComponetAsIdTests.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Test/MappingByCode/MappersTests/ClassMapperTests/ComponetAsIdTests.cs (rev 0) +++ trunk/nhibernate/src/NHibernate.Test/MappingByCode/MappersTests/ClassMapperTests/ComponetAsIdTests.cs 2011-04-27 12:08:50 UTC (rev 5771) @@ -0,0 +1,85 @@ +using System; +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.ClassMapperTests +{ + public class ComponetAsIdTests + { + private class PersonId + { + public string Email { get; set; } + public User User { get; set; } + } + + private class Person + { + private PersonId id; + public PersonId Id + { + get { return id; } + } + + public string Name { get; set; } + } + + private class User + { + public int Id { get; set; } + } + + [Test] + public void WhenClassWithComponentIdThenTheIdIsConpositeId() + { + var mapdoc = new HbmMapping(); + var mapper = new ClassMapper(typeof(Person), mapdoc, For<Person>.Property(x => x.Id)); + + mapper.ComponentAsId(For<Person>.Property(x => x.Id), map => + { + map.Property(For<PersonId>.Property(x => x.Email), pm => { }); + map.ManyToOne(For<PersonId>.Property(x => x.User), pm => { }); + }); + var hbmClass = mapdoc.RootClasses[0]; + hbmClass.Id.Should().Be.Null(); + var hbmCompositeId = hbmClass.CompositeId; + hbmCompositeId.Should().Not.Be.Null(); + hbmCompositeId.@class.Should().Not.Be.Null(); + hbmCompositeId.Items.Should().Have.Count.EqualTo(2); + hbmCompositeId.Items.Select(x => x.GetType()).Should().Have.SameValuesAs(typeof(HbmKeyProperty),typeof(HbmKeyManyToOne)); + } + + [Test] + public void WhenComponentIdCustomizedMoreThanOnceThenMerge() + { + var mapdoc = new HbmMapping(); + var mapper = new ClassMapper(typeof(Person), mapdoc, For<Person>.Property(x => x.Id)); + + mapper.ComponentAsId(For<Person>.Property(x => x.Id), map => + { + map.Property(For<PersonId>.Property(x => x.Email), pm => { }); + map.ManyToOne(For<PersonId>.Property(x => x.User), pm => { }); + }); + mapper.ComponentAsId(For<Person>.Property(x => x.Id), map => map.Access(Accessor.Field)); + + var hbmClass = mapdoc.RootClasses[0]; + hbmClass.Id.Should().Be.Null(); + var hbmCompositeId = hbmClass.CompositeId; + hbmCompositeId.Items.Should().Have.Count.EqualTo(2); + hbmCompositeId.access.Should().Contain("field"); + } + + [Test] + public void WhenMapExternalMemberAsComponentIdThenThrows() + { + var mapdoc = new HbmMapping(); + var mapper = new ClassMapper(typeof(Person), mapdoc, For<Person>.Property(x => x.Id)); + + mapper.Executing(m => m.ComponentAsId(For<User>.Property(x => x.Id), map => map.Access(Accessor.Field))).Throws<ArgumentOutOfRangeException>(); + } + + } +} \ No newline at end of file Added: trunk/nhibernate/src/NHibernate.Test/MappingByCode/MappersTests/ClassMapperTests/ComposedIdTests.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Test/MappingByCode/MappersTests/ClassMapperTests/ComposedIdTests.cs (rev 0) +++ trunk/nhibernate/src/NHibernate.Test/MappingByCode/MappersTests/ClassMapperTests/ComposedIdTests.cs 2011-04-27 12:08:50 UTC (rev 5771) @@ -0,0 +1,57 @@ +using System.Linq; +using NHibernate.Cfg.MappingSchema; +using NHibernate.Mapping.ByCode.Impl; +using NUnit.Framework; +using SharpTestsEx; + +namespace NHibernate.Test.MappingByCode.MappersTests.ClassMapperTests +{ + public class ComposedIdTests + { + private class Person + { + public string Email { get; set; } + public User User { get; set; } + } + + private class User + { + public int Id { get; set; } + } + + [Test] + public void WhenClassWithComposedIdThenTheIdIsConpositeId() + { + var mapdoc = new HbmMapping(); + var mapper = new ClassMapper(typeof(Person), mapdoc, null); + + mapper.ComposedId(map => + { + map.Property(For<Person>.Property(x => x.Email), pm => { }); + map.ManyToOne(For<Person>.Property(x => x.User), pm => { }); + }); + var hbmClass = mapdoc.RootClasses[0]; + hbmClass.Id.Should().Be.Null(); + var hbmCompositeId = hbmClass.CompositeId; + hbmCompositeId.Should().Not.Be.Null(); + hbmCompositeId.@class.Should().Be.Null(); + hbmCompositeId.Items.Should().Have.Count.EqualTo(2); + hbmCompositeId.Items.Select(x => x.GetType()).Should().Have.SameValuesAs(typeof(HbmKeyProperty), typeof(HbmKeyManyToOne)); + } + + [Test] + public void WhenComposedIdCustomizedMoreThanOnceThenMerge() + { + var mapdoc = new HbmMapping(); + var mapper = new ClassMapper(typeof(Person), mapdoc, null); + + mapper.ComposedId(map => map.Property(For<Person>.Property(x => x.Email), pm => { })); + mapper.ComposedId(map => map.ManyToOne(For<Person>.Property(x => x.User), pm => { })); + + var hbmClass = mapdoc.RootClasses[0]; + hbmClass.Id.Should().Be.Null(); + var hbmCompositeId = hbmClass.CompositeId; + hbmCompositeId.Items.Should().Have.Count.EqualTo(2); + } + } +} \ No newline at end of file Modified: trunk/nhibernate/src/NHibernate.Test/MappingByCode/MappersTests/ComposedIdMapperTests.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Test/MappingByCode/MappersTests/ComposedIdMapperTests.cs 2011-04-27 09:49:57 UTC (rev 5770) +++ trunk/nhibernate/src/NHibernate.Test/MappingByCode/MappersTests/ComposedIdMapperTests.cs 2011-04-27 12:08:50 UTC (rev 5771) @@ -24,7 +24,7 @@ { var mapdoc = new HbmMapping(); var compositeId = new HbmCompositeId(); - var mapper = new ComposedIdMapper(compositeId, mapdoc); + var mapper = new ComposedIdMapper(typeof(Person), compositeId, mapdoc); mapper.Property(For<Person>.Property(ts => ts.Email), x => { }); @@ -38,7 +38,7 @@ { var mapdoc = new HbmMapping(); var compositeId = new HbmCompositeId(); - var mapper = new ComposedIdMapper(compositeId, mapdoc); + var mapper = new ComposedIdMapper(typeof(Person), compositeId, mapdoc); var called = false; mapper.Property(For<Person>.Property(ts => ts.Email), x => called = true); @@ -51,7 +51,7 @@ { var mapdoc = new HbmMapping(); var compositeId = new HbmCompositeId(); - var mapper = new ComposedIdMapper(compositeId, mapdoc); + var mapper = new ComposedIdMapper(typeof(Person), compositeId, mapdoc); mapper.ManyToOne(For<Person>.Property(ts => ts.User), x => { }); @@ -65,7 +65,7 @@ { var mapdoc = new HbmMapping(); var compositeId = new HbmCompositeId(); - var mapper = new ComposedIdMapper(compositeId, mapdoc); + var mapper = new ComposedIdMapper(typeof(Person), compositeId, mapdoc); var called = false; mapper.ManyToOne(For<Person>.Property(ts => ts.User), x => called = true); Modified: trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2011-04-27 09:49:57 UTC (rev 5770) +++ trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2011-04-27 12:08:50 UTC (rev 5771) @@ -549,6 +549,8 @@ <Compile Include="MappingByCode\For.cs" /> <Compile Include="MappingByCode\MappersTests\AbstractPropertyContainerMapperTest.cs" /> <Compile Include="MappingByCode\MappersTests\ClassMapperTests\ClassMapperWithJoinPropertiesTest.cs" /> + <Compile Include="MappingByCode\MappersTests\ClassMapperTests\ComponetAsIdTests.cs" /> + <Compile Include="MappingByCode\MappersTests\ClassMapperTests\ComposedIdTests.cs" /> <Compile Include="MappingByCode\MappersTests\ClassMapperTests\SetPersisterTests.cs" /> <Compile Include="MappingByCode\MappersTests\ClassMapperTests\TablesSincronizationTests.cs" /> <Compile Include="MappingByCode\MappersTests\CollectionIdMapperTests.cs" /> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ric...@us...> - 2011-04-27 09:50:04
|
Revision: 5770 http://nhibernate.svn.sourceforge.net/nhibernate/?rev=5770&view=rev Author: ricbrown Date: 2011-04-27 09:49:57 +0000 (Wed, 27 Apr 2011) Log Message: ----------- Added test-dialect for Firebird to allow defaulting to embedded client. Modified Paths: -------------- trunk/nhibernate/src/NHibernate.Test/GeneratedTest/ComponentOwner.hbm.xml trunk/nhibernate/src/NHibernate.Test/Generatedkeys/Select/MyEntity.hbm.xml trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj trunk/nhibernate/teamcity.build Added Paths: ----------- trunk/nhibernate/src/NHibernate.Test/DialectTest/FirebirdClientDialect.cs Added: trunk/nhibernate/src/NHibernate.Test/DialectTest/FirebirdClientDialect.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Test/DialectTest/FirebirdClientDialect.cs (rev 0) +++ trunk/nhibernate/src/NHibernate.Test/DialectTest/FirebirdClientDialect.cs 2011-04-27 09:49:57 UTC (rev 5770) @@ -0,0 +1,14 @@ +using NHibernate.Cfg; +using NHibernate.Dialect; + +namespace NHibernate.Test.DialectTest +{ + public class FirebirdClientDialect : FirebirdDialect + { + public FirebirdClientDialect() : base() + { + // overrides default driver to allow tests to run using embedded client + DefaultProperties[Environment.ConnectionDriver] = "NHibernate.Driver.FirebirdClientDriver"; + } + } +} Modified: trunk/nhibernate/src/NHibernate.Test/GeneratedTest/ComponentOwner.hbm.xml =================================================================== --- trunk/nhibernate/src/NHibernate.Test/GeneratedTest/ComponentOwner.hbm.xml 2011-04-26 22:15:51 UTC (rev 5769) +++ trunk/nhibernate/src/NHibernate.Test/GeneratedTest/ComponentOwner.hbm.xml 2011-04-27 09:49:57 UTC (rev 5770) @@ -70,6 +70,7 @@ <![CDATA[DROP TRIGGER t_iu_part_gen_comp]]> </drop> <dialect-scope name="NHibernate.Dialect.FirebirdDialect"/> + <dialect-scope name="NHibernate.Test.DialectTest.FirebirdClientDialect"/> </database-object> </hibernate-mapping> \ No newline at end of file Modified: trunk/nhibernate/src/NHibernate.Test/Generatedkeys/Select/MyEntity.hbm.xml =================================================================== --- trunk/nhibernate/src/NHibernate.Test/Generatedkeys/Select/MyEntity.hbm.xml 2011-04-26 22:15:51 UTC (rev 5769) +++ trunk/nhibernate/src/NHibernate.Test/Generatedkeys/Select/MyEntity.hbm.xml 2011-04-27 09:49:57 UTC (rev 5770) @@ -21,6 +21,7 @@ DROP GENERATOR MYGENERATOR; </drop> <dialect-scope name="NHibernate.Dialect.FirebirdDialect"/> + <dialect-scope name="NHibernate.Test.DialectTest.FirebirdClientDialect"/> </database-object> <database-object> @@ -36,8 +37,9 @@ <drop> DROP TRIGGER my_entity_BI; </drop> - <dialect-scope name="NHibernate.Dialect.FirebirdDialect"/> - </database-object> + <dialect-scope name="NHibernate.Dialect.FirebirdDialect"/> + <dialect-scope name="NHibernate.Test.DialectTest.FirebirdClientDialect"/> + </database-object> <database-object> <create> Modified: trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2011-04-26 22:15:51 UTC (rev 5769) +++ trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2011-04-27 09:49:57 UTC (rev 5770) @@ -211,6 +211,7 @@ <Compile Include="Criteria\MaterialResource.cs" /> <Compile Include="Criteria\ProjectionsTest.cs" /> <Compile Include="Criteria\Reptile.cs" /> + <Compile Include="DialectTest\FirebirdClientDialect.cs" /> <Compile Include="DialectTest\MsSqlCe40DialectFixture.cs" /> <Compile Include="DriverTest\DbProviderFactoryDriveConnectionCommandProviderTest.cs" /> <Compile Include="DriverTest\ReflectionBasedDriverTest.cs" /> Modified: trunk/nhibernate/teamcity.build =================================================================== --- trunk/nhibernate/teamcity.build 2011-04-26 22:15:51 UTC (rev 5769) +++ trunk/nhibernate/teamcity.build 2011-04-27 09:49:57 UTC (rev 5770) @@ -35,7 +35,7 @@ <target name="setup-teamcity-firebird32"> <property name="nhibernate.connection.driver_class" value="NHibernate.Driver.FirebirdClientDriver" /> - <property name="nhibernate.dialect" value="NHibernate.Dialect.FirebirdDialect" /> + <property name="nhibernate.dialect" value="NHibernate.Test.DialectTest.FirebirdClientDialect, NHibernate.Test" /> <property name="nhibernate.connection.connection_string" value="Database=NHibernate.fdb;ServerType=1;UserID=SYSDBA" /> <copy todir="${bin.dir}"> <fileset basedir="${root.dir}/lib/teamcity/firebird/x86"> @@ -51,7 +51,7 @@ <property name="nunit-console" value="${tools.dir}/NUnit/nunit-console.exe" /> <property name="nunit.found" value="true" /> <property name="nhibernate.connection.driver_class" value="NHibernate.Driver.FirebirdClientDriver" /> - <property name="nhibernate.dialect" value="NHibernate.Dialect.FirebirdDialect" /> + <property name="nhibernate.dialect" value="NHibernate.Test.DialectTest.FirebirdClientDialect, NHibernate.Test" /> <property name="nhibernate.connection.connection_string" value="Database=NHibernate.fdb;ServerType=1;UserID=SYSDBA" /> <copy todir="${bin.dir}"> <fileset basedir="${root.dir}/lib/teamcity/firebird/x64"> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fab...@us...> - 2011-04-26 22:15:57
|
Revision: 5769 http://nhibernate.svn.sourceforge.net/nhibernate/?rev=5769&view=rev Author: fabiomaulo Date: 2011-04-26 22:15:51 +0000 (Tue, 26 Apr 2011) Log Message: ----------- ComponentAsIdMapper Modified Paths: -------------- trunk/nhibernate/src/NHibernate/NHibernate.csproj trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj Added Paths: ----------- trunk/nhibernate/src/NHibernate/Mapping/ByCode/Impl/ComponentAsIdMapper.cs trunk/nhibernate/src/NHibernate.Test/MappingByCode/MappersTests/ComponentAsIdTests.cs Added: trunk/nhibernate/src/NHibernate/Mapping/ByCode/Impl/ComponentAsIdMapper.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Mapping/ByCode/Impl/ComponentAsIdMapper.cs (rev 0) +++ trunk/nhibernate/src/NHibernate/Mapping/ByCode/Impl/ComponentAsIdMapper.cs 2011-04-26 22:15:51 UTC (rev 5769) @@ -0,0 +1,66 @@ +using System; +using System.Linq; +using System.Reflection; +using NHibernate.Cfg.MappingSchema; + +namespace NHibernate.Mapping.ByCode.Impl +{ + public class ComponentAsIdMapper: IComponentAsIdMapper + { + private readonly IAccessorPropertyMapper accessorPropertyMapper; + private readonly HbmCompositeId id; + private readonly HbmMapping mapDoc; + + public ComponentAsIdMapper(System.Type componentType, MemberInfo declaringTypeMember, HbmCompositeId id, HbmMapping mapDoc) + { + this.id = id; + this.mapDoc = mapDoc; + id.@class = componentType.GetShortClassName(mapDoc); + accessorPropertyMapper = new AccessorPropertyMapper(declaringTypeMember.DeclaringType, declaringTypeMember.Name, x => id.access = x); + } + + public HbmCompositeId CompositeId + { + get { return id; } + } + + public void Access(Accessor accessor) + { + accessorPropertyMapper.Access(accessor); + } + + public void Access(System.Type accessorType) + { + accessorPropertyMapper.Access(accessorType); + } + + public void Class(System.Type componentType) + { + id.@class = componentType.GetShortClassName(mapDoc); + } + + public void Property(MemberInfo property, Action<IPropertyMapper> mapping) + { + var hbmProperty = new HbmKeyProperty { name = property.Name }; + mapping(new KeyPropertyMapper(property, hbmProperty)); + AddProperty(hbmProperty); + } + + public void ManyToOne(MemberInfo property, Action<IManyToOneMapper> mapping) + { + var hbm = new HbmKeyManyToOne { name = property.Name }; + mapping(new KeyManyToOneMapper(property, hbm, mapDoc)); + AddProperty(hbm); + } + + protected void AddProperty(object property) + { + if (property == null) + { + throw new ArgumentNullException("property"); + } + var toAdd = new[] { property }; + id.Items = id.Items == null ? toAdd : id.Items.Concat(toAdd).ToArray(); + } + } +} \ No newline at end of file Modified: trunk/nhibernate/src/NHibernate/NHibernate.csproj =================================================================== --- trunk/nhibernate/src/NHibernate/NHibernate.csproj 2011-04-26 19:20:39 UTC (rev 5768) +++ trunk/nhibernate/src/NHibernate/NHibernate.csproj 2011-04-26 22:15:51 UTC (rev 5769) @@ -297,6 +297,7 @@ <Compile Include="Mapping\ByCode\Conformist\UnionSubclassMapping.cs" /> <Compile Include="Mapping\ByCode\ICompositeIdMapper.cs" /> <Compile Include="Mapping\ByCode\IDynamicComponentAttributesMapper.cs" /> + <Compile Include="Mapping\ByCode\Impl\ComponentAsIdMapper.cs" /> <Compile Include="Mapping\ByCode\Impl\ComposedIdMapper.cs" /> <Compile Include="Mapping\ByCode\Impl\CustomizersImpl\DynamicComponentCustomizer.cs" /> <Compile Include="Mapping\ByCode\Impl\DynamicComponentMapper.cs" /> Added: trunk/nhibernate/src/NHibernate.Test/MappingByCode/MappersTests/ComponentAsIdTests.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Test/MappingByCode/MappersTests/ComponentAsIdTests.cs (rev 0) +++ trunk/nhibernate/src/NHibernate.Test/MappingByCode/MappersTests/ComponentAsIdTests.cs 2011-04-26 22:15:51 UTC (rev 5769) @@ -0,0 +1,93 @@ +using System.Linq; +using NHibernate.Cfg.MappingSchema; +using NHibernate.Mapping.ByCode.Impl; +using NUnit.Framework; +using SharpTestsEx; + +namespace NHibernate.Test.MappingByCode.MappersTests +{ + public class ComponentAsIdTests + { + private class PersonId + { + public string Email { get; set; } + public User User { get; set; } + } + + private class Person + { + public PersonId Id { get; set; } + public string Name { get; set; } + } + + private class User + { + public int Id { get; set; } + } + + [Test] + public void WhenCreatedThenSetTheComponentClass() + { + var mapdoc = new HbmMapping(); + var component = new HbmCompositeId(); + new ComponentAsIdMapper(typeof(PersonId), For<Person>.Property(x=> x.Id), component, mapdoc); + + component.@class.Should().Contain("PersonId"); + } + + [Test] + public void CanMapProperty() + { + var mapdoc = new HbmMapping(); + var compositeId = new HbmCompositeId(); + var mapper = new ComponentAsIdMapper(typeof(PersonId), For<Person>.Property(x => x.Id), compositeId, mapdoc); + + mapper.Property(For<PersonId>.Property(ts => ts.Email), x => { }); + + compositeId.Items.Should().Have.Count.EqualTo(1); + compositeId.Items.First().Should().Be.OfType<HbmKeyProperty>(); + compositeId.Items.OfType<HbmKeyProperty>().First().Name.Should().Be.EqualTo("Email"); + } + + [Test] + public void CallPropertyMapper() + { + var mapdoc = new HbmMapping(); + var compositeId = new HbmCompositeId(); + var mapper = new ComponentAsIdMapper(typeof(PersonId), For<Person>.Property(x => x.Id), compositeId, mapdoc); + var called = false; + + mapper.Property(For<PersonId>.Property(ts => ts.Email), x => called = true); + + called.Should().Be.True(); + } + + [Test] + public void CanMapManyToOne() + { + var mapdoc = new HbmMapping(); + var compositeId = new HbmCompositeId(); + var mapper = new ComponentAsIdMapper(typeof(PersonId), For<Person>.Property(x => x.Id), compositeId, mapdoc); + + mapper.ManyToOne(For<PersonId>.Property(ts => ts.User), x => { }); + + compositeId.Items.Should().Have.Count.EqualTo(1); + compositeId.Items.First().Should().Be.OfType<HbmKeyManyToOne>(); + compositeId.Items.OfType<HbmKeyManyToOne>().First().Name.Should().Be.EqualTo("User"); + } + + [Test] + public void CallMapManyToOneMapper() + { + var mapdoc = new HbmMapping(); + var compositeId = new HbmCompositeId(); + var mapper = new ComponentAsIdMapper(typeof(PersonId), For<Person>.Property(x => x.Id), compositeId, mapdoc); + var called = false; + + mapper.ManyToOne(For<PersonId>.Property(ts => ts.User), x => called = true); + + 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-26 19:20:39 UTC (rev 5768) +++ trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2011-04-26 22:15:51 UTC (rev 5769) @@ -551,6 +551,7 @@ <Compile Include="MappingByCode\MappersTests\ClassMapperTests\SetPersisterTests.cs" /> <Compile Include="MappingByCode\MappersTests\ClassMapperTests\TablesSincronizationTests.cs" /> <Compile Include="MappingByCode\MappersTests\CollectionIdMapperTests.cs" /> + <Compile Include="MappingByCode\MappersTests\ComponentAsIdTests.cs" /> <Compile Include="MappingByCode\MappersTests\ComposedIdMapperTests.cs" /> <Compile Include="MappingByCode\MappersTests\DynamicComponentMapperTests\AnyPropertyOnDynamicCompoTests.cs" /> <Compile Include="MappingByCode\MappersTests\DynamicComponentMapperTests\BagPropertyOnDynamicCompoTests.cs" /> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fab...@us...> - 2011-04-26 19:20:46
|
Revision: 5768 http://nhibernate.svn.sourceforge.net/nhibernate/?rev=5768&view=rev Author: fabiomaulo Date: 2011-04-26 19:20:39 +0000 (Tue, 26 Apr 2011) Log Message: ----------- ComposedIdMapper Modified Paths: -------------- trunk/nhibernate/src/NHibernate/NHibernate.csproj trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj Added Paths: ----------- trunk/nhibernate/src/NHibernate/Mapping/ByCode/Impl/ComposedIdMapper.cs trunk/nhibernate/src/NHibernate.Test/MappingByCode/MappersTests/ComposedIdMapperTests.cs Added: trunk/nhibernate/src/NHibernate/Mapping/ByCode/Impl/ComposedIdMapper.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Mapping/ByCode/Impl/ComposedIdMapper.cs (rev 0) +++ trunk/nhibernate/src/NHibernate/Mapping/ByCode/Impl/ComposedIdMapper.cs 2011-04-26 19:20:39 UTC (rev 5768) @@ -0,0 +1,52 @@ +using System; +using System.Linq; +using System.Reflection; +using NHibernate.Cfg.MappingSchema; + +namespace NHibernate.Mapping.ByCode.Impl +{ + public class ComposedIdMapper : IComposedIdMapper + { + private readonly HbmCompositeId id; + private readonly HbmMapping mapDoc; + + public ComposedIdMapper(HbmCompositeId id, HbmMapping mapDoc) + { + this.id = id; + this.mapDoc = mapDoc; + } + + public HbmCompositeId ComposedId + { + get { return id; } + } + + #region IComposedIdMapper Members + + public void Property(MemberInfo property, Action<IPropertyMapper> mapping) + { + var hbmProperty = new HbmKeyProperty {name = property.Name}; + mapping(new KeyPropertyMapper(property, hbmProperty)); + AddProperty(hbmProperty); + } + + public void ManyToOne(MemberInfo property, Action<IManyToOneMapper> mapping) + { + var hbm = new HbmKeyManyToOne {name = property.Name}; + mapping(new KeyManyToOneMapper(property, hbm, mapDoc)); + AddProperty(hbm); + } + + #endregion + + protected void AddProperty(object property) + { + if (property == null) + { + throw new ArgumentNullException("property"); + } + var toAdd = new[] {property}; + id.Items = id.Items == null ? toAdd : id.Items.Concat(toAdd).ToArray(); + } + } +} \ No newline at end of file Modified: trunk/nhibernate/src/NHibernate/NHibernate.csproj =================================================================== --- trunk/nhibernate/src/NHibernate/NHibernate.csproj 2011-04-26 17:36:57 UTC (rev 5767) +++ trunk/nhibernate/src/NHibernate/NHibernate.csproj 2011-04-26 19:20:39 UTC (rev 5768) @@ -297,6 +297,7 @@ <Compile Include="Mapping\ByCode\Conformist\UnionSubclassMapping.cs" /> <Compile Include="Mapping\ByCode\ICompositeIdMapper.cs" /> <Compile Include="Mapping\ByCode\IDynamicComponentAttributesMapper.cs" /> + <Compile Include="Mapping\ByCode\Impl\ComposedIdMapper.cs" /> <Compile Include="Mapping\ByCode\Impl\CustomizersImpl\DynamicComponentCustomizer.cs" /> <Compile Include="Mapping\ByCode\Impl\DynamicComponentMapper.cs" /> <Compile Include="Mapping\ByCode\PropertyToField.cs" /> Added: trunk/nhibernate/src/NHibernate.Test/MappingByCode/MappersTests/ComposedIdMapperTests.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Test/MappingByCode/MappersTests/ComposedIdMapperTests.cs (rev 0) +++ trunk/nhibernate/src/NHibernate.Test/MappingByCode/MappersTests/ComposedIdMapperTests.cs 2011-04-26 19:20:39 UTC (rev 5768) @@ -0,0 +1,76 @@ +using System.Linq; +using NHibernate.Cfg.MappingSchema; +using NHibernate.Mapping.ByCode.Impl; +using NUnit.Framework; +using SharpTestsEx; + +namespace NHibernate.Test.MappingByCode.MappersTests +{ + public class ComposedIdMapperTests + { + private class Person + { + public string Email { get; set; } + public User User { get; set; } + } + + private class User + { + public int Id { get; set; } + } + + [Test] + public void CanMapProperty() + { + var mapdoc = new HbmMapping(); + var compositeId = new HbmCompositeId(); + var mapper = new ComposedIdMapper(compositeId, mapdoc); + + mapper.Property(For<Person>.Property(ts => ts.Email), x => { }); + + compositeId.Items.Should().Have.Count.EqualTo(1); + compositeId.Items.First().Should().Be.OfType<HbmKeyProperty>(); + compositeId.Items.OfType<HbmKeyProperty>().First().Name.Should().Be.EqualTo("Email"); + } + + [Test] + public void CallPropertyMapper() + { + var mapdoc = new HbmMapping(); + var compositeId = new HbmCompositeId(); + var mapper = new ComposedIdMapper(compositeId, mapdoc); + var called = false; + + mapper.Property(For<Person>.Property(ts => ts.Email), x => called = true); + + called.Should().Be.True(); + } + + [Test] + public void CanMapManyToOne() + { + var mapdoc = new HbmMapping(); + var compositeId = new HbmCompositeId(); + var mapper = new ComposedIdMapper(compositeId, mapdoc); + + mapper.ManyToOne(For<Person>.Property(ts => ts.User), x => { }); + + compositeId.Items.Should().Have.Count.EqualTo(1); + compositeId.Items.First().Should().Be.OfType<HbmKeyManyToOne>(); + compositeId.Items.OfType<HbmKeyManyToOne>().First().Name.Should().Be.EqualTo("User"); + } + + [Test] + public void CallMapManyToOneMapper() + { + var mapdoc = new HbmMapping(); + var compositeId = new HbmCompositeId(); + var mapper = new ComposedIdMapper(compositeId, mapdoc); + var called = false; + + mapper.ManyToOne(For<Person>.Property(ts => ts.User), x => called = true); + + 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-26 17:36:57 UTC (rev 5767) +++ trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2011-04-26 19:20:39 UTC (rev 5768) @@ -551,6 +551,7 @@ <Compile Include="MappingByCode\MappersTests\ClassMapperTests\SetPersisterTests.cs" /> <Compile Include="MappingByCode\MappersTests\ClassMapperTests\TablesSincronizationTests.cs" /> <Compile Include="MappingByCode\MappersTests\CollectionIdMapperTests.cs" /> + <Compile Include="MappingByCode\MappersTests\ComposedIdMapperTests.cs" /> <Compile Include="MappingByCode\MappersTests\DynamicComponentMapperTests\AnyPropertyOnDynamicCompoTests.cs" /> <Compile Include="MappingByCode\MappersTests\DynamicComponentMapperTests\BagPropertyOnDynamicCompoTests.cs" /> <Compile Include="MappingByCode\MappersTests\DynamicComponentMapperTests\ComponentPropertyOnDynamicCompoTests.cs" /> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fab...@us...> - 2011-04-26 17:37:03
|
Revision: 5767 http://nhibernate.svn.sourceforge.net/nhibernate/?rev=5767&view=rev Author: fabiomaulo Date: 2011-04-26 17:36:57 +0000 (Tue, 26 Apr 2011) Log Message: ----------- preparing the painful note (composite-id) Modified Paths: -------------- trunk/nhibernate/src/NHibernate/Mapping/ByCode/ICompositeIdMapper.cs Modified: trunk/nhibernate/src/NHibernate/Mapping/ByCode/ICompositeIdMapper.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Mapping/ByCode/ICompositeIdMapper.cs 2011-04-26 17:17:59 UTC (rev 5766) +++ trunk/nhibernate/src/NHibernate/Mapping/ByCode/ICompositeIdMapper.cs 2011-04-26 17:36:57 UTC (rev 5767) @@ -1,9 +1,7 @@ namespace NHibernate.Mapping.ByCode { - public interface ICompositeIdAttributesMapper {} + public interface IComposedIdMapper : IMinimalPlainPropertyContainerMapper {} - public interface ICompositeIdMapper : ICompositeIdAttributesMapper, IMinimalPlainPropertyContainerMapper {} - public interface IComponentAsIdAttributesMapper : IAccessorPropertyMapper { /// <summary> @@ -18,6 +16,8 @@ public interface IComponentAsIdMapper : IComponentAsIdAttributesMapper, IMinimalPlainPropertyContainerMapper { } + public interface IComposedIdMapper<TEntity> : IMinimalPlainPropertyContainerMapper<TEntity> where TEntity : class { } + public interface IComponentAsIdAttributesMapper<TComponent> : IAccessorPropertyMapper { void Class<TConcrete>() where TConcrete : TComponent; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fab...@us...> - 2011-04-26 17:18:06
|
Revision: 5766 http://nhibernate.svn.sourceforge.net/nhibernate/?rev=5766&view=rev Author: fabiomaulo Date: 2011-04-26 17:17:59 +0000 (Tue, 26 Apr 2011) Log Message: ----------- preparing the painful note (composite-id) Modified Paths: -------------- trunk/nhibernate/src/NHibernate/Mapping/ByCode/IPlainPropertyContainerMapper.cs trunk/nhibernate/src/NHibernate/NHibernate.csproj Added Paths: ----------- trunk/nhibernate/src/NHibernate/Mapping/ByCode/ICompositeIdMapper.cs Added: trunk/nhibernate/src/NHibernate/Mapping/ByCode/ICompositeIdMapper.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Mapping/ByCode/ICompositeIdMapper.cs (rev 0) +++ trunk/nhibernate/src/NHibernate/Mapping/ByCode/ICompositeIdMapper.cs 2011-04-26 17:17:59 UTC (rev 5766) @@ -0,0 +1,28 @@ +namespace NHibernate.Mapping.ByCode +{ + public interface ICompositeIdAttributesMapper {} + + public interface ICompositeIdMapper : ICompositeIdAttributesMapper, IMinimalPlainPropertyContainerMapper {} + + public interface IComponentAsIdAttributesMapper : IAccessorPropertyMapper + { + /// <summary> + /// Force the component to a different type than the one of the property. + /// </summary> + /// <param name="componentType">Mapped component type.</param> + /// <remarks> + /// Useful when the property is an interface and you need the mapping to a concrete class mapped as component. + /// </remarks> + void Class(System.Type componentType); + } + + public interface IComponentAsIdMapper : IComponentAsIdAttributesMapper, IMinimalPlainPropertyContainerMapper { } + + public interface IComponentAsIdAttributesMapper<TComponent> : IAccessorPropertyMapper + { + void Class<TConcrete>() where TConcrete : TComponent; + } + + public interface IComponentAsIdMapper<TComponent> : IComponentAsIdAttributesMapper<TComponent>, IMinimalPlainPropertyContainerMapper<TComponent> where TComponent : class { } + +} \ No newline at end of file Modified: trunk/nhibernate/src/NHibernate/Mapping/ByCode/IPlainPropertyContainerMapper.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Mapping/ByCode/IPlainPropertyContainerMapper.cs 2011-04-26 13:58:16 UTC (rev 5765) +++ trunk/nhibernate/src/NHibernate/Mapping/ByCode/IPlainPropertyContainerMapper.cs 2011-04-26 17:17:59 UTC (rev 5766) @@ -5,14 +5,17 @@ namespace NHibernate.Mapping.ByCode { - public interface IBasePlainPropertyContainerMapper + public interface IMinimalPlainPropertyContainerMapper { void Property(MemberInfo property, Action<IPropertyMapper> mapping); + void ManyToOne(MemberInfo property, Action<IManyToOneMapper> mapping); + } + public interface IBasePlainPropertyContainerMapper : IMinimalPlainPropertyContainerMapper + { void Component(MemberInfo property, Action<IComponentMapper> mapping); void Component(MemberInfo property, Action<IDynamicComponentMapper> mapping); - void ManyToOne(MemberInfo property, Action<IManyToOneMapper> mapping); void Any(MemberInfo property, System.Type idTypeOfMetaType, Action<IAnyMapper> mapping); } @@ -21,12 +24,18 @@ void OneToOne(MemberInfo property, Action<IOneToOneMapper> mapping); } - public interface IBasePlainPropertyContainerMapper<TContainer> + public interface IMinimalPlainPropertyContainerMapper<TContainer> { void Property<TProperty>(Expression<Func<TContainer, TProperty>> property); void Property<TProperty>(Expression<Func<TContainer, TProperty>> property, Action<IPropertyMapper> mapping); void Property(FieldInfo member, Action<IPropertyMapper> mapping); + void ManyToOne<TProperty>(Expression<Func<TContainer, TProperty>> property, Action<IManyToOneMapper> mapping) where TProperty : class; + void ManyToOne<TProperty>(Expression<Func<TContainer, TProperty>> property) where TProperty : class; + } + + public interface IBasePlainPropertyContainerMapper<TContainer> : IMinimalPlainPropertyContainerMapper<TContainer> + { void Component<TComponent>(Expression<Func<TContainer, TComponent>> property, Action<IComponentMapper<TComponent>> mapping) where TComponent : class; void Component<TComponent>(Expression<Func<TContainer, TComponent>> property) where TComponent : class; @@ -35,9 +44,6 @@ TComponent dynamicComponentTemplate, Action<IDynamicComponentMapper<TComponent>> mapping) where TComponent : class; - void ManyToOne<TProperty>(Expression<Func<TContainer, TProperty>> property, Action<IManyToOneMapper> mapping) where TProperty : class; - void ManyToOne<TProperty>(Expression<Func<TContainer, TProperty>> property) where TProperty : class; - void Any<TProperty>(Expression<Func<TContainer, TProperty>> property, System.Type idTypeOfMetaType, Action<IAnyMapper> mapping) where TProperty : class; } Modified: trunk/nhibernate/src/NHibernate/NHibernate.csproj =================================================================== --- trunk/nhibernate/src/NHibernate/NHibernate.csproj 2011-04-26 13:58:16 UTC (rev 5765) +++ trunk/nhibernate/src/NHibernate/NHibernate.csproj 2011-04-26 17:17:59 UTC (rev 5766) @@ -295,6 +295,7 @@ <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\ICompositeIdMapper.cs" /> <Compile Include="Mapping\ByCode\IDynamicComponentAttributesMapper.cs" /> <Compile Include="Mapping\ByCode\Impl\CustomizersImpl\DynamicComponentCustomizer.cs" /> <Compile Include="Mapping\ByCode\Impl\DynamicComponentMapper.cs" /> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fab...@us...> - 2011-04-26 13:58:22
|
Revision: 5765 http://nhibernate.svn.sourceforge.net/nhibernate/?rev=5765&view=rev Author: fabiomaulo Date: 2011-04-26 13:58:16 +0000 (Tue, 26 Apr 2011) Log Message: ----------- Fix NH-2674 Modified Paths: -------------- trunk/nhibernate/src/NHibernate/Criterion/QueryOver.cs trunk/nhibernate/src/NHibernate/ISession.cs trunk/nhibernate/src/NHibernate/Impl/SessionImpl.cs Modified: trunk/nhibernate/src/NHibernate/Criterion/QueryOver.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Criterion/QueryOver.cs 2011-04-25 23:01:50 UTC (rev 5764) +++ trunk/nhibernate/src/NHibernate/Criterion/QueryOver.cs 2011-04-26 13:58:16 UTC (rev 5765) @@ -31,6 +31,16 @@ return new QueryOver<T,T>(alias); } + public static QueryOver<T, T> Of<T>(string entityName) + { + return new QueryOver<T, T>(entityName); + } + + public static QueryOver<T, T> Of<T>(string entityName, Expression<Func<T>> alias) + { + return new QueryOver<T, T>(entityName, alias); + } + public ICriteria UnderlyingCriteria { get { return criteria; } @@ -275,6 +285,12 @@ criteria = impl; } + protected internal QueryOver(string entityName) + { + impl = new CriteriaImpl(entityName, null); + criteria = impl; + } + protected internal QueryOver(Expression<Func<TSubType>> alias) { string aliasPath = ExpressionProcessor.FindMemberExpression(alias.Body); @@ -282,6 +298,13 @@ criteria = impl; } + protected internal QueryOver(string entityName, Expression<Func<TSubType>> alias) + { + string aliasPath = ExpressionProcessor.FindMemberExpression(alias.Body); + impl = new CriteriaImpl(entityName, aliasPath, null); + criteria = impl; + } + protected internal QueryOver(CriteriaImpl impl) { this.impl = impl; Modified: trunk/nhibernate/src/NHibernate/ISession.cs =================================================================== --- trunk/nhibernate/src/NHibernate/ISession.cs 2011-04-25 23:01:50 UTC (rev 5764) +++ trunk/nhibernate/src/NHibernate/ISession.cs 2011-04-26 13:58:16 UTC (rev 5765) @@ -714,17 +714,35 @@ /// Creates a new <c>IQueryOver<T></c> for the entity class. /// </summary> /// <typeparam name="T">The entity class</typeparam> - /// <returns>An ICriteria<T> object</returns> + /// <returns>An IQueryOver<T> object</returns> IQueryOver<T,T> QueryOver<T>() where T : class; /// <summary> /// Creates a new <c>IQueryOver<T></c> for the entity class. /// </summary> /// <typeparam name="T">The entity class</typeparam> - /// <returns>An ICriteria<T> object</returns> + /// <param name="alias">The alias of the entity</param> + /// <returns>An IQueryOver<T> object</returns> IQueryOver<T,T> QueryOver<T>(Expression<Func<T>> alias) where T : class; /// <summary> + /// Creates a new <c>IQueryOver{T};</c> for the entity class. + /// </summary> + /// <typeparam name="T">The entity class</typeparam> + /// <param name="entityName">The name of the entity to Query</param> + /// <returns>An IQueryOver{T} object</returns> + IQueryOver<T, T> QueryOver<T>(string entityName) where T : class; + + /// <summary> + /// Creates a new <c>IQueryOver{T}</c> for the entity class. + /// </summary> + /// <typeparam name="T">The entity class</typeparam> + /// <param name="entityName">The name of the entity to Query</param> + /// <param name="alias">The alias of the entity</param> + /// <returns>An IQueryOver{T} object</returns> + IQueryOver<T, T> QueryOver<T>(string entityName, Expression<Func<T>> alias) where T : class; + + /// <summary> /// Create a new instance of <c>Query</c> for the given query string /// </summary> /// <param name="queryString">A hibernate query string</param> Modified: trunk/nhibernate/src/NHibernate/Impl/SessionImpl.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Impl/SessionImpl.cs 2011-04-25 23:01:50 UTC (rev 5764) +++ trunk/nhibernate/src/NHibernate/Impl/SessionImpl.cs 2011-04-26 13:58:16 UTC (rev 5765) @@ -1862,6 +1862,25 @@ } } + public IQueryOver<T, T> QueryOver<T>(string entityName) where T : class + { + using (new SessionIdLoggingContext(SessionId)) + { + CheckAndUpdateSessionStatus(); + return new QueryOver<T, T>(new CriteriaImpl(entityName, this)); + } + } + + public IQueryOver<T, T> QueryOver<T>(string entityName, Expression<Func<T>> alias) where T : class + { + using (new SessionIdLoggingContext(SessionId)) + { + CheckAndUpdateSessionStatus(); + string aliasPath = ExpressionProcessor.FindMemberExpression(alias.Body); + return new QueryOver<T, T>(new CriteriaImpl(entityName, aliasPath, this)); + } + } + public override IList List(CriteriaImpl criteria) { using (new SessionIdLoggingContext(SessionId)) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fab...@us...> - 2011-04-25 23:01:57
|
Revision: 5764 http://nhibernate.svn.sourceforge.net/nhibernate/?rev=5764&view=rev Author: fabiomaulo Date: 2011-04-25 23:01:50 +0000 (Mon, 25 Apr 2011) Log Message: ----------- Optimized (as possible) NH-2583 storing time Modified Paths: -------------- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2583/AbstractMassTestingFixture.cs Modified: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2583/AbstractMassTestingFixture.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2583/AbstractMassTestingFixture.cs 2011-04-25 21:14:13 UTC (rev 5763) +++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2583/AbstractMassTestingFixture.cs 2011-04-25 23:01:50 UTC (rev 5764) @@ -5,11 +5,25 @@ using System.Collections.Generic; using System.Linq; using System.Linq.Expressions; +using Environment = NHibernate.Cfg.Environment; namespace NHibernate.Test.NHSpecificTest.NH2583 { public abstract class AbstractMassTestingFixture : BugTestCase { + public const int BatchSize = 200; + protected override void Configure(Configuration configuration) + { + base.Configure(configuration); + configuration.DataBaseIntegration(x => x.BatchSize = BatchSize+5); + List<string> cacheSettings = new List<string>(configuration.Properties.Keys.Where(x => x.Contains("cache"))); + foreach (var cacheSetting in cacheSettings) + { + configuration.Properties.Remove(cacheSetting); + } + configuration.SetProperty(Environment.UseSecondLevelCache, "false"); + + } private class ValueTuple<T1, T2, T3, T4, T5, T6, T7> { public T1 Item1; @@ -87,63 +101,57 @@ } } + protected int RunTest<T1, T2, T3, T4, T5, T6, T7>(Expression<Func<MyBO, bool>> condition, SetterTuple<T1, T2, T3, T4, T5, T6, T7> setters) + { + if (condition == null) + { + throw new ArgumentNullException("condition"); + } + if (setters == null) + { + throw new ArgumentNullException("setters"); + } + IEnumerable<int> expectedIds; - protected int RunTest<T1, T2, T3, T4, T5, T6, T7>(Expression<Func<MyBO, bool>> condition, SetterTuple<T1, T2, T3, T4, T5, T6, T7> setters) - { - if (condition == null) - { - throw new ArgumentNullException("condition"); - } - if (setters == null) - { - throw new ArgumentNullException("setters"); - } - IEnumerable<int> expectedIds; + // Setup + using (var session = OpenSession()) + { + expectedIds = CreateObjects(session, setters, condition.Compile()); + } - // Setup - using (var session = OpenSession()) - { - using (session.BeginTransaction()) - { - using (var tx = session.BeginTransaction()) - { - expectedIds = CreateObjects(session, setters, condition.Compile()); - tx.Commit(); - } - } - } + try + { + // Test + using (var session = OpenSession()) + { + session.CacheMode = CacheMode.Ignore; + session.DefaultReadOnly = true; + using (session.BeginTransaction()) + { + return TestAndAssert(condition, session, expectedIds); + } + } - try - { - // Test - using (var session = OpenSession()) - { - using (session.BeginTransaction()) - { - return TestAndAssert(condition, session, expectedIds); - } - } + } + finally + { + // Teardown + using (var session = OpenSession()) + { + using (var tx = session.BeginTransaction()) + { + DeleteAll<MyBO>(session); + DeleteAll<MyRef1>(session); + DeleteAll<MyRef2>(session); + DeleteAll<MyRef3>(session); + tx.Commit(); + } + } + } + } - } - finally - { - // Teardown - using (var session = OpenSession()) - { - using (var tx = session.BeginTransaction()) - { - DeleteAll<MyBO>(session); - DeleteAll<MyRef1>(session); - DeleteAll<MyRef2>(session); - DeleteAll<MyRef3>(session); - tx.Commit(); - } - } - } - } + protected abstract int TestAndAssert(Expression<Func<MyBO, bool>> condition, ISession session, IEnumerable<int> expectedIds); - protected abstract int TestAndAssert(Expression<Func<MyBO, bool>> condition, ISession session, IEnumerable<int> expectedIds); - protected static SetterTuple<T1, T2, T3, T4, T5, T6, T7> Setters<T1, T2, T3, T4, T5, T6, T7>(Action<MyBO, ISession, T1> set1, Action<MyBO, ISession, T2> set2, Action<MyBO, ISession, T3> set3, @@ -210,31 +218,50 @@ var expectedIds = new List<int>(); bool thereAreSomeWithTrue = false; bool thereAreSomeWithFalse = false; - foreach (var q in GetAllTestCases<T1, T2, T3, T4, T5, T6, T7>()) + var allTestCases = GetAllTestCases<T1, T2, T3, T4, T5, T6, T7>().ToList(); + var i = 0; + foreach (var q in allTestCases) + { + MyBO bo = new MyBO(); + setters.Set(bo, session, q.Item1, q.Item2, q.Item3, q.Item4, q.Item5, q.Item6, q.Item7); + try + { + if (condition(bo)) + { + expectedIds.Add(bo.Id); + thereAreSomeWithTrue = true; + } + else + { + thereAreSomeWithFalse = true; + } + if ((i%BatchSize) == 0) + { + if (session.Transaction.IsActive) + { + session.Transaction.Commit(); + session.Clear(); + } + session.BeginTransaction(); + } + session.Save(bo); + i++; + } + catch (NullReferenceException) + { + // ignore - we only check consistency with Linq2Objects in non-failing cases; + // emulating the outer-join logic for exceptional cases in Lin2Objects is IMO very hard. + } + } + if (session.Transaction.IsActive) + { + session.Transaction.Commit(); + session.Clear(); + } + + Console.WriteLine("Congratulation!! you have saved "+ i +" entities."); + if (!thereAreSomeWithTrue) { - MyBO bo = new MyBO(); - setters.Set(bo, session, q.Item1, q.Item2, q.Item3, q.Item4, q.Item5, q.Item6, q.Item7); - try - { - if (condition(bo)) - { - expectedIds.Add(bo.Id); - thereAreSomeWithTrue = true; - } - else - { - thereAreSomeWithFalse = true; - } - session.Save(bo); - } - catch (NullReferenceException) - { - // ignore - we only check consistency with Linq2Objects in non-failing cases; - // emulating the outer-join logic for exceptional cases in Lin2Objects is IMO very hard. - } - } - if (!thereAreSomeWithTrue) - { throw new ArgumentException("Condition is false for all - not a good test", "condition"); } if (!thereAreSomeWithFalse) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fab...@us...> - 2011-04-25 21:14:19
|
Revision: 5763 http://nhibernate.svn.sourceforge.net/nhibernate/?rev=5763&view=rev Author: fabiomaulo Date: 2011-04-25 21:14:13 +0000 (Mon, 25 Apr 2011) Log Message: ----------- Partial fix test running-time for NH-2583 Modified Paths: -------------- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2583/AbstractMassTestingFixture.cs trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2583/ManualTestFixture.cs trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2583/SelfJoinTestFixture.cs Modified: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2583/AbstractMassTestingFixture.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2583/AbstractMassTestingFixture.cs 2011-04-25 21:13:23 UTC (rev 5762) +++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2583/AbstractMassTestingFixture.cs 2011-04-25 21:14:13 UTC (rev 5763) @@ -1,3 +1,4 @@ +using NHibernate.Cfg; using NHibernate.Linq; using NUnit.Framework; using System; @@ -201,10 +202,7 @@ private static void DeleteAll<T>(ISession session) { - foreach (var bo in session.Query<T>()) - { - session.Delete(bo); - } + session.CreateQuery("delete from " + typeof(T).Name).ExecuteUpdate(); } private static IEnumerable<int> CreateObjects<T1, T2, T3, T4, T5, T6, T7>(ISession session, SetterTuple<T1, T2, T3, T4, T5, T6, T7> setters, Func<MyBO, bool> condition) Modified: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2583/ManualTestFixture.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2583/ManualTestFixture.cs 2011-04-25 21:13:23 UTC (rev 5762) +++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2583/ManualTestFixture.cs 2011-04-25 21:14:13 UTC (rev 5763) @@ -330,10 +330,7 @@ private static void DeleteAll<T>(ISession session) { - foreach (var bo in session.Query<T>()) - { - session.Delete(bo); - } + session.CreateQuery("delete from " + typeof(T).Name).ExecuteUpdate(); } } } Modified: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2583/SelfJoinTestFixture.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2583/SelfJoinTestFixture.cs 2011-04-25 21:13:23 UTC (rev 5762) +++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2583/SelfJoinTestFixture.cs 2011-04-25 21:14:13 UTC (rev 5763) @@ -136,10 +136,7 @@ { using (var tx = session.BeginTransaction()) { - foreach (var bo in session.Query<MyBO>()) - { - session.Delete(bo); - } + session.CreateQuery("delete from MyBO").ExecuteUpdate(); tx.Commit(); } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fab...@us...> - 2011-04-25 21:13:29
|
Revision: 5762 http://nhibernate.svn.sourceforge.net/nhibernate/?rev=5762&view=rev Author: fabiomaulo Date: 2011-04-25 21:13:23 +0000 (Mon, 25 Apr 2011) Log Message: ----------- Fix NH-2505 Modified Paths: -------------- trunk/nhibernate/src/NHibernate/Linq/Visitors/HqlGeneratorExpressionTreeVisitor.cs trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj Added Paths: ----------- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2505/ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2505/Fixture.cs Modified: trunk/nhibernate/src/NHibernate/Linq/Visitors/HqlGeneratorExpressionTreeVisitor.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Linq/Visitors/HqlGeneratorExpressionTreeVisitor.cs 2011-04-25 13:48:32 UTC (rev 5761) +++ trunk/nhibernate/src/NHibernate/Linq/Visitors/HqlGeneratorExpressionTreeVisitor.cs 2011-04-25 21:13:23 UTC (rev 5762) @@ -213,17 +213,7 @@ // Need to check for boolean equality if (lhs is HqlBooleanExpression || rhs is HqlBooleanExpression) { - lhs = - _hqlTreeBuilder.Case( - new [] { _hqlTreeBuilder.When(lhs, _hqlTreeBuilder.Constant(true)) }, - _hqlTreeBuilder.Constant(false)); - - rhs = - _hqlTreeBuilder.Case( - new [] { _hqlTreeBuilder.When(rhs, _hqlTreeBuilder.Constant(true)) }, - _hqlTreeBuilder.Constant(false)); - - return _hqlTreeBuilder.Equality(lhs, rhs); + return ResolveBooleanEquality(expression, lhs, rhs, (l, r) => _hqlTreeBuilder.Equality(l, r)); } // Check for nulls on left or right. @@ -246,23 +236,12 @@ case ExpressionType.NotEqual: // Need to check for boolean in-equality - if (lhs is HqlBooleanExpression || rhs is HqlBooleanExpression) - { - lhs = - _hqlTreeBuilder.Case( - new [] { _hqlTreeBuilder.When(lhs, _hqlTreeBuilder.Constant(true)) }, - _hqlTreeBuilder.Constant(false)); + if (lhs is HqlBooleanExpression || rhs is HqlBooleanExpression) + { + return ResolveBooleanEquality(expression, lhs, rhs, (l, r) => _hqlTreeBuilder.Inequality(l, r)); + } - rhs = - _hqlTreeBuilder.Case( - new [] { _hqlTreeBuilder.When(rhs, _hqlTreeBuilder.Constant(true)) }, - _hqlTreeBuilder.Constant(false)); - - return _hqlTreeBuilder.Inequality(lhs, rhs); - - } - - // Check for nulls on left or right. + // Check for nulls on left or right. if (expression.Right is ConstantExpression && expression.Right.Type.IsNullableOrReference() && ((ConstantExpression)expression.Right).Value == null) @@ -330,7 +309,49 @@ throw new InvalidOperationException(); } - protected HqlTreeNode VisitUnaryExpression(UnaryExpression expression) + private HqlTreeNode ResolveBooleanEquality(BinaryExpression expression, HqlExpression lhs, HqlExpression rhs, + Func<HqlExpression, HqlExpression, HqlTreeNode> applyResultExpressions) + { + if (!(lhs is HqlBooleanExpression) && !(rhs is HqlBooleanExpression)) + { + throw new InvalidOperationException("Invalid operators for ResolveBooleanEquality, this may indicate a bug in NHibernate"); + } + + HqlExpression leftHqlExpression = GetExpressionForBooleanEquality(expression.Left, lhs); + HqlExpression rightHqlExpression = GetExpressionForBooleanEquality(expression.Right, rhs); + return applyResultExpressions(leftHqlExpression, rightHqlExpression); + } + + private HqlExpression GetExpressionForBooleanEquality(Expression @operator, HqlExpression original) + { + //When the expression is a constant then use the constant + var operandEx = @operator as ConstantExpression; + if (operandEx != null) + { + NamedParameter namedParameter; + if (_parameters.ConstantToParameterMap.TryGetValue(operandEx, out namedParameter)) + { + _parameters.RequiredHqlParameters.Add(new NamedParameterDescriptor(namedParameter.Name, null, new[] { _parameters.RequiredHqlParameters.Count + 1 }, false)); + return _hqlTreeBuilder.Parameter(namedParameter.Name).AsExpression(); + } + + return _hqlTreeBuilder.Constant(operandEx.Value); + } + + //When the expression is a member-access not nullable then use the HbmDot + var memberAccessExpression = @operator as MemberExpression; + if (ExpressionType.MemberAccess.Equals(@operator.NodeType) && memberAccessExpression != null && typeof(bool).Equals(memberAccessExpression.Type)) + { + // this case make the difference when the property "Value" of a nullable type is used (ignore the null since the user is explicity checking the Value) + return original; + } + + //When the expression is a member-access nullable then use the "case" clause to transform it to boolean (to use always .NET meaning instead leave the DB the behavior for null) + //When the expression is a complex-expression then use the "case" clause to transform it to boolean + return _hqlTreeBuilder.Case(new[] {_hqlTreeBuilder.When(original, _hqlTreeBuilder.Constant(true))}, _hqlTreeBuilder.Constant(false)); + } + + protected HqlTreeNode VisitUnaryExpression(UnaryExpression expression) { switch (expression.NodeType) { Added: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2505/Fixture.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2505/Fixture.cs (rev 0) +++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2505/Fixture.cs 2011-04-25 21:13:23 UTC (rev 5762) @@ -0,0 +1,175 @@ +using System; +using System.Linq; +using System.Text.RegularExpressions; +using NHibernate.Cfg.MappingSchema; +using NHibernate.Linq; +using NHibernate.Mapping.ByCode; +using NUnit.Framework; +using SharpTestsEx; + +namespace NHibernate.Test.NHSpecificTest.NH2505 +{ + public class MyClass + { + public virtual Guid Id { get; set; } + public virtual bool Alive { get; set; } + public virtual bool? MayBeAlive { get; set; } + public virtual int Something { get; set; } + } + public class Fixture: TestCaseMappingByCode + { + private Regex caseClause = new Regex("case",RegexOptions.IgnoreCase); + protected override HbmMapping GetMappings() + { + var mapper = new ConventionModelMapper(); + mapper.BeforeMapClass += (mi, t, x) => x.Id(map=> map.Generator(Generators.Guid)); + return mapper.CompileMappingFor(new[] { typeof(MyClass) }); + } + + private class Scenario: IDisposable + { + private readonly ISessionFactory factory; + + public Scenario(ISessionFactory factory) + { + this.factory = factory; + using (var session= factory.OpenSession()) + { + session.Save(new MyClass { Alive = true }); + session.Save(new MyClass { Alive = false, MayBeAlive = true }); + session.Flush(); + } + } + + public void Dispose() + { + using (var session = factory.OpenSession()) + { + session.CreateQuery("delete from MyClass").ExecuteUpdate(); + session.Flush(); + } + } + } + + [Test] + public void WhenQueryConstantEqualToMemberThenDoesNotUseTheCaseConstructor() + { + using (new Scenario(Sfi)) + { + using (var session = OpenSession()) + { + using (var sqls = new SqlLogSpy()) + { + session.Query<MyClass>().Where(x => x.Alive == false).Should().Have.Count.EqualTo(1); + caseClause.Matches(sqls.GetWholeLog()).Count.Should().Be(0); + } + using (var sqls = new SqlLogSpy()) + { + session.Query<MyClass>().Where(x => true == x.Alive).Should().Have.Count.EqualTo(1); + caseClause.Matches(sqls.GetWholeLog()).Count.Should().Be(0); + } + } + } + } + + [Test] + public void WhenQueryConstantNotEqualToMemberThenDoesNotUseTheCaseConstructor() + { + using (new Scenario(Sfi)) + { + using (var session = OpenSession()) + { + using (var sqls = new SqlLogSpy()) + { + session.Query<MyClass>().Where(x => x.Alive != false).Should().Have.Count.EqualTo(1); + caseClause.Matches(sqls.GetWholeLog()).Count.Should().Be(0); + } + using (var sqls = new SqlLogSpy()) + { + session.Query<MyClass>().Where(x => true != x.Alive).Should().Have.Count.EqualTo(1); + caseClause.Matches(sqls.GetWholeLog()).Count.Should().Be(0); + } + } + } + } + + [Test] + public void WhenQueryComplexEqualToComplexThentUseTheCaseConstructorForBoth() + { + using (new Scenario(Sfi)) + { + using (var session = OpenSession()) + { + using (var sqls = new SqlLogSpy()) + { + session.Query<MyClass>().Where(x => (5 > x.Something) == (x.Something < 10)).ToList(); + caseClause.Matches(sqls.GetWholeLog()).Count.Should().Be(2); + } + } + } + } + + [Test] + public void WhenQueryConstantEqualToNullableMemberThenUseTheCaseConstructorForMember() + { + using (new Scenario(Sfi)) + { + using (var session = OpenSession()) + { + using (var sqls = new SqlLogSpy()) + { + session.Query<MyClass>().Where(x => x.MayBeAlive == false).Should().Have.Count.EqualTo(1); + caseClause.Matches(sqls.GetWholeLog()).Count.Should().Be(1); + } + using (var sqls = new SqlLogSpy()) + { + session.Query<MyClass>().Where(x => true == x.MayBeAlive).Should().Have.Count.EqualTo(1); + caseClause.Matches(sqls.GetWholeLog()).Count.Should().Be(1); + } + } + } + } + + [Test] + public void WhenQueryConstantEqualToNullableMemberValueThenDoesNotUseTheCaseConstructorForMember() + { + using (new Scenario(Sfi)) + { + using (var session = OpenSession()) + { + using (var sqls = new SqlLogSpy()) + { + session.Query<MyClass>().Where(x => x.MayBeAlive.Value == false).ToList(); + caseClause.Matches(sqls.GetWholeLog()).Count.Should().Be(1); + } + using (var sqls = new SqlLogSpy()) + { + session.Query<MyClass>().Where(x => true == x.MayBeAlive.Value).ToList(); + caseClause.Matches(sqls.GetWholeLog()).Count.Should().Be(1); + } + } + } + } + + [Test] + public void WhenQueryConstantNotEqualToNullableMemberThenUseTheCaseConstructorForMember() + { + using (new Scenario(Sfi)) + { + using (var session = OpenSession()) + { + using (var sqls = new SqlLogSpy()) + { + session.Query<MyClass>().Where(x => x.MayBeAlive != false).Should().Have.Count.EqualTo(1); + caseClause.Matches(sqls.GetWholeLog()).Count.Should().Be(1); + } + using (var sqls = new SqlLogSpy()) + { + session.Query<MyClass>().Where(x => true != x.MayBeAlive).Should().Have.Count.EqualTo(1); + caseClause.Matches(sqls.GetWholeLog()).Count.Should().Be(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-25 13:48:32 UTC (rev 5761) +++ trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2011-04-25 21:13:23 UTC (rev 5762) @@ -763,6 +763,7 @@ <Compile Include="NHSpecificTest\NH2490\Fixture.cs" /> <Compile Include="NHSpecificTest\NH2490\Model.cs" /> <Compile Include="NHSpecificTest\NH2491\Fixture.cs" /> + <Compile Include="NHSpecificTest\NH2505\Fixture.cs" /> <Compile Include="NHSpecificTest\NH2507\Animal.cs" /> <Compile Include="NHSpecificTest\NH2507\Fixture.cs" /> <Compile Include="NHSpecificTest\NH2527\FixtureWithNoBatcher.cs" /> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fab...@us...> - 2011-04-25 13:48:38
|
Revision: 5761 http://nhibernate.svn.sourceforge.net/nhibernate/?rev=5761&view=rev Author: fabiomaulo Date: 2011-04-25 13:48:32 +0000 (Mon, 25 Apr 2011) Log Message: ----------- Fix NH-2551 Modified Paths: -------------- trunk/nhibernate/src/NHibernate/Impl/SessionFactoryImpl.cs trunk/nhibernate/src/NHibernate/Util/ReflectHelper.cs Modified: trunk/nhibernate/src/NHibernate/Impl/SessionFactoryImpl.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Impl/SessionFactoryImpl.cs 2011-04-25 12:15:29 UTC (rev 5760) +++ trunk/nhibernate/src/NHibernate/Impl/SessionFactoryImpl.cs 2011-04-25 13:48:32 UTC (rev 5761) @@ -613,7 +613,7 @@ { try { - clazz = ReflectHelper.ClassForFullName(className); + clazz = ReflectHelper.ClassForFullNameOrNull(className); } catch (Exception) { Modified: trunk/nhibernate/src/NHibernate/Util/ReflectHelper.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Util/ReflectHelper.cs 2011-04-25 12:15:29 UTC (rev 5760) +++ trunk/nhibernate/src/NHibernate/Util/ReflectHelper.cs 2011-04-25 13:48:32 UTC (rev 5761) @@ -192,37 +192,53 @@ /// the method try to find the System.Type scanning all Assemblies of the <see cref="AppDomain.CurrentDomain"/>. /// </remarks> /// <exception cref="TypeLoadException">If no System.Type was found for <paramref name="classFullName"/>.</exception> - public static System.Type ClassForFullName(string classFullName) + public static System.Type ClassForFullName(string classFullName) { - System.Type result = null; - AssemblyQualifiedTypeName parsedName = TypeNameParser.Parse(classFullName); - if (!string.IsNullOrEmpty(parsedName.Assembly)) - { - result = TypeFromAssembly(parsedName, false); - } - else - { - if (!string.IsNullOrEmpty(classFullName)) - { - Assembly[] ass = AppDomain.CurrentDomain.GetAssemblies(); - foreach (Assembly a in ass) - { - result = a.GetType(classFullName, false, false); - if (result != null) - break; //<<<<<================ - } - } - } - if (result == null) - { - string message = "Could not load type " + classFullName + ". Possible cause: the assembly was not loaded or not specified."; - throw new TypeLoadException(message); - } + var result = ClassForFullNameOrNull(classFullName); + if (result == null) + { + string message = "Could not load type " + classFullName + ". Possible cause: the assembly was not loaded or not specified."; + throw new TypeLoadException(message); + } - return result; + return result; } - public static System.Type TypeFromAssembly(string type, string assembly, bool throwIfError) + /// <summary> + /// Load a System.Type given is't name. + /// </summary> + /// <param name="classFullName">The class FullName or AssemblyQualifiedName</param> + /// <returns>The System.Type or null</returns> + /// <remarks> + /// If the <paramref name="classFullName"/> don't represent an <see cref="System.Type.AssemblyQualifiedName"/> + /// the method try to find the System.Type scanning all Assemblies of the <see cref="AppDomain.CurrentDomain"/>. + /// </remarks> + public static System.Type ClassForFullNameOrNull(string classFullName) + { + System.Type result = null; + AssemblyQualifiedTypeName parsedName = TypeNameParser.Parse(classFullName); + if (!string.IsNullOrEmpty(parsedName.Assembly)) + { + result = TypeFromAssembly(parsedName, false); + } + else + { + if (!string.IsNullOrEmpty(classFullName)) + { + Assembly[] ass = AppDomain.CurrentDomain.GetAssemblies(); + foreach (Assembly a in ass) + { + result = a.GetType(classFullName, false, false); + if (result != null) + break; //<<<<<================ + } + } + } + + return result; + } + + public static System.Type TypeFromAssembly(string type, string assembly, bool throwIfError) { return TypeFromAssembly(new AssemblyQualifiedTypeName(type, assembly), throwIfError); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fab...@us...> - 2011-04-25 12:15:35
|
Revision: 5760 http://nhibernate.svn.sourceforge.net/nhibernate/?rev=5760&view=rev Author: fabiomaulo Date: 2011-04-25 12:15:29 +0000 (Mon, 25 Apr 2011) Log Message: ----------- Minor (commented the possible breaking change) Modified Paths: -------------- trunk/nhibernate/releasenotes.txt Modified: trunk/nhibernate/releasenotes.txt =================================================================== --- trunk/nhibernate/releasenotes.txt 2011-04-25 12:12:59 UTC (rev 5759) +++ trunk/nhibernate/releasenotes.txt 2011-04-25 12:15:29 UTC (rev 5760) @@ -8,6 +8,7 @@ * - ICollectionPersister added property to fix [NH-2489] * [NH-2605] Refactorize MultiQuery/MultiCriteria implementation to delegate responsibility to IDrive (IDrive changed). * For users who don't look at Log-ERROR, to prevent wrong behavior when lazy-properties are used the DynamicProxyValidator validates the accessability of properties setters. + * For those implementing IDrive without inherit from DriveBase: IDrive.AdjustCommand Build 3.2.0.Aplha2 (rev5715) ============================= This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fab...@us...> - 2011-04-25 12:13:06
|
Revision: 5759 http://nhibernate.svn.sourceforge.net/nhibernate/?rev=5759&view=rev Author: fabiomaulo Date: 2011-04-25 12:12:59 +0000 (Mon, 25 Apr 2011) Log Message: ----------- Fix NH-2661 implementing a new drive for MsSQL-2008 Modified Paths: -------------- trunk/nhibernate/src/NHibernate/AdoNet/AbstractBatcher.cs trunk/nhibernate/src/NHibernate/AdoNet/NonBatchingBatcher.cs trunk/nhibernate/src/NHibernate/AdoNet/SqlClientBatchingBatcher.cs trunk/nhibernate/src/NHibernate/Dialect/MsSql2008Dialect.cs trunk/nhibernate/src/NHibernate/Driver/DriverBase.cs trunk/nhibernate/src/NHibernate/Driver/IDriver.cs trunk/nhibernate/src/NHibernate/NHibernate.csproj trunk/nhibernate/src/NHibernate.Test/App.config trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2660And2661/Test.cs Added Paths: ----------- trunk/nhibernate/src/NHibernate/Driver/Sql2008ClientDriver.cs Modified: trunk/nhibernate/src/NHibernate/AdoNet/AbstractBatcher.cs =================================================================== --- trunk/nhibernate/src/NHibernate/AdoNet/AbstractBatcher.cs 2011-04-25 05:57:46 UTC (rev 5758) +++ trunk/nhibernate/src/NHibernate/AdoNet/AbstractBatcher.cs 2011-04-25 12:12:59 UTC (rev 5759) @@ -57,7 +57,7 @@ factory = connectionManager.Factory; } - private IDriver Driver + protected IDriver Driver { get { return factory.ConnectionProvider.Driver; } } Modified: trunk/nhibernate/src/NHibernate/AdoNet/NonBatchingBatcher.cs =================================================================== --- trunk/nhibernate/src/NHibernate/AdoNet/NonBatchingBatcher.cs 2011-04-25 05:57:46 UTC (rev 5758) +++ trunk/nhibernate/src/NHibernate/AdoNet/NonBatchingBatcher.cs 2011-04-25 12:12:59 UTC (rev 5759) @@ -36,6 +36,7 @@ public override void AddToBatch(IExpectation expectation) { IDbCommand cmd = CurrentCommand; + Driver.AdjustCommand(cmd); int rowCount = ExecuteNonQuery(cmd); expectation.VerifyOutcomeNonBatched(rowCount, cmd); } Modified: trunk/nhibernate/src/NHibernate/AdoNet/SqlClientBatchingBatcher.cs =================================================================== --- trunk/nhibernate/src/NHibernate/AdoNet/SqlClientBatchingBatcher.cs 2011-04-25 05:57:46 UTC (rev 5758) +++ trunk/nhibernate/src/NHibernate/AdoNet/SqlClientBatchingBatcher.cs 2011-04-25 12:12:59 UTC (rev 5759) @@ -1,5 +1,7 @@ using System.Data; using System.Data.Common; +using System.Data.SqlClient; +using System.Linq; using System.Text; using NHibernate.AdoNet.Util; using NHibernate.Exceptions; @@ -49,7 +51,7 @@ { totalExpectedRowsAffected += expectation.ExpectedRowCount; IDbCommand batchUpdate = CurrentCommand; - + Driver.AdjustCommand(batchUpdate); string lineWithParameters = null; var sqlStatementLogger = Factory.Settings.SqlStatementLogger; if (sqlStatementLogger.IsDebugEnabled || log.IsDebugEnabled) Modified: trunk/nhibernate/src/NHibernate/Dialect/MsSql2008Dialect.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Dialect/MsSql2008Dialect.cs 2011-04-25 05:57:46 UTC (rev 5758) +++ trunk/nhibernate/src/NHibernate/Dialect/MsSql2008Dialect.cs 2011-04-25 12:12:59 UTC (rev 5759) @@ -1,5 +1,7 @@ using System.Data; +using NHibernate.Cfg; using NHibernate.Dialect.Function; +using NHibernate.Driver; namespace NHibernate.Dialect { @@ -30,5 +32,11 @@ RegisterKeyword("time"); RegisterKeyword("hierarchyid"); } + + protected override void RegisterDefaultProperties() + { + base.RegisterDefaultProperties(); + DefaultProperties[Environment.ConnectionDriver] = typeof(Sql2008ClientDriver).AssemblyQualifiedName; + } } } \ No newline at end of file Modified: trunk/nhibernate/src/NHibernate/Driver/DriverBase.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Driver/DriverBase.cs 2011-04-25 05:57:46 UTC (rev 5758) +++ trunk/nhibernate/src/NHibernate/Driver/DriverBase.cs 2011-04-25 12:12:59 UTC (rev 5759) @@ -255,6 +255,7 @@ public void PrepareCommand(IDbCommand command) { + AdjustCommand(command); OnBeforePrepare(command); if (SupportsPreparingCommands && prepareSql) @@ -272,6 +273,19 @@ { } + /// <summary> + /// Override to make any adjustments to each IDbCommand object before it added to the batcher. + /// </summary> + /// <param name="command">The command.</param> + /// <remarks> + /// This method is similar to the <see cref="OnBeforePrepare"/> but, instead be called just before execute the command (that can be a batch) + /// is executed before add each single command to the batcher and before <see cref="OnBeforePrepare"/> . + /// If you have to adjust parameters values/type (when the command is full filled) this is a good place where do it. + /// </remarks> + public virtual void AdjustCommand(IDbCommand command) + { + } + public IDbDataParameter GenerateOutputParameter(IDbCommand command) { IDbDataParameter param = GenerateParameter(command, "ReturnValue", SqlTypeFactory.Int32); Modified: trunk/nhibernate/src/NHibernate/Driver/IDriver.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Driver/IDriver.cs 2011-04-25 05:57:46 UTC (rev 5758) +++ trunk/nhibernate/src/NHibernate/Driver/IDriver.cs 2011-04-25 12:12:59 UTC (rev 5759) @@ -73,7 +73,7 @@ /// Prepare the <paramref name="command" /> by calling <see cref="IDbCommand.Prepare()" />. /// May be a no-op if the driver does not support preparing commands, or for any other reason. /// </summary> - /// <param name="command"></param> + /// <param name="command">The command.</param> void PrepareCommand(IDbCommand command); /// <summary> @@ -99,5 +99,15 @@ IResultSetsCommand GetResultSetsCommand(ISessionImplementor session); bool SupportsMultipleQueries { get; } + + /// <summary> + /// Make any adjustments to each IDbCommand object before it is added to the batcher. + /// </summary> + /// <param name="command">The command.</param> + /// <remarks> + /// This method should be executed before add each single command to the batcher. + /// If you have to adjust parameters values/type (when the command is full filled) this is a good place where do it. + /// </remarks> + void AdjustCommand(IDbCommand command); } } \ No newline at end of file Added: trunk/nhibernate/src/NHibernate/Driver/Sql2008ClientDriver.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Driver/Sql2008ClientDriver.cs (rev 0) +++ trunk/nhibernate/src/NHibernate/Driver/Sql2008ClientDriver.cs 2011-04-25 12:12:59 UTC (rev 5759) @@ -0,0 +1,28 @@ +using System; +using System.Data; +using System.Data.SqlClient; +using System.Linq; + +namespace NHibernate.Driver +{ + public class Sql2008ClientDriver : SqlClientDriver + { + protected override void InitializeParameter(IDbDataParameter dbParam, string name, SqlTypes.SqlType sqlType) + { + base.InitializeParameter(dbParam, name, sqlType); + if (sqlType.DbType == DbType.Time) + { + ((SqlParameter) dbParam).SqlDbType = SqlDbType.Time; + } + } + + public override void AdjustCommand(IDbCommand command) + { + foreach (var parameter in command.Parameters.Cast<SqlParameter>().Where(x => x.SqlDbType == SqlDbType.Time && (x.Value is DateTime))) + { + var dateTimeValue = (DateTime)parameter.Value; + parameter.Value = dateTimeValue.TimeOfDay; + } + } + } +} \ No newline at end of file Modified: trunk/nhibernate/src/NHibernate/NHibernate.csproj =================================================================== --- trunk/nhibernate/src/NHibernate/NHibernate.csproj 2011-04-25 05:57:46 UTC (rev 5758) +++ trunk/nhibernate/src/NHibernate/NHibernate.csproj 2011-04-25 12:12:59 UTC (rev 5759) @@ -157,6 +157,7 @@ <Compile Include="Driver\OleDbDriver.cs" /> <Compile Include="Driver\OracleClientDriver.cs" /> <Compile Include="Driver\OracleDataClientDriver.cs" /> + <Compile Include="Driver\Sql2008ClientDriver.cs" /> <Compile Include="Driver\SqlClientDriver.cs" /> <Compile Include="Driver\BasicResultSetsCommand.cs" /> <Compile Include="Driver\SQLiteDriver.cs" /> Modified: trunk/nhibernate/src/NHibernate.Test/App.config =================================================================== --- trunk/nhibernate/src/NHibernate.Test/App.config 2011-04-25 05:57:46 UTC (rev 5758) +++ trunk/nhibernate/src/NHibernate.Test/App.config 2011-04-25 12:12:59 UTC (rev 5759) @@ -53,7 +53,6 @@ <property name="format_sql">true</property> <!-- This is the System.Data.dll provider for MSSQL Server --> - <property name="connection.driver_class">NHibernate.Driver.SqlClientDriver</property> <property name="dialect">NHibernate.Dialect.MsSql2008Dialect</property> <property name="connection.connection_string">Server=localhost\sqlexpress;initial catalog=nhibernate;Integrated Security=SSPI</property> Modified: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2660And2661/Test.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2660And2661/Test.cs 2011-04-25 05:57:46 UTC (rev 5758) +++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2660And2661/Test.cs 2011-04-25 12:12:59 UTC (rev 5759) @@ -1,5 +1,7 @@ using System; +using NHibernate.Cfg; using NHibernate.Dialect; +using NHibernate.Driver; using NUnit.Framework; using SharpTestsEx; @@ -34,6 +36,13 @@ return dialect is MsSql2008Dialect; } + protected override void Configure(Configuration configuration) + { + // to be sure we are using the new drive + base.Configure(configuration); + configuration.DataBaseIntegration(x=> x.Driver<Sql2008ClientDriver>()); + } + [Test, Ignore("workaround to sqlserver DP, not fixed yet")] public void ShouldBeAbleToQueryEntity() { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pa...@us...> - 2011-04-25 05:57:53
|
Revision: 5758 http://nhibernate.svn.sourceforge.net/nhibernate/?rev=5758&view=rev Author: patearl Date: 2011-04-25 05:57:46 +0000 (Mon, 25 Apr 2011) Log Message: ----------- Linq: More tests related to NH-2583, thanks to Harald Mueller. Modified Paths: -------------- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2583/Domain.cs trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2583/MassTestingNotAndDeMorganFixture.cs trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj Added Paths: ----------- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2583/MassTestingMoreOperatorsFixture.cs Modified: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2583/Domain.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2583/Domain.cs 2011-04-25 05:55:52 UTC (rev 5757) +++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2583/Domain.cs 2011-04-25 05:57:46 UTC (rev 5758) @@ -1,261 +1,300 @@ -namespace NHibernate.Test.NHSpecificTest.NH2583 -{ - public class MyRef1 - { - private static int _idCt = 1000; - private int _id; - - public MyRef1() - { - _id = ++_idCt; - } - - public virtual int Id { - get { return _id; } - set { _id = value; } - } - - public virtual int? I1 { get; set; } - public virtual int I2 { get; set; } - public virtual int I3 { get; set; } - - public virtual MyRef2 BO2 { get; set; } - public virtual MyRef3 BO3 { get; set; } - - public virtual MyRef2 GetOrCreateBO2(ISession s) - { - if (BO2 == null) - { - BO2 = new MyRef2(); - s.Save(BO2); - } - return BO2; - } - - public virtual MyRef3 GetOrCreateBO3(ISession s) - { - if (BO3 == null) - { - BO3 = new MyRef3(); - s.Save(BO3); - } - return BO3; - } - } - - public class MyRef2 - { - private static int _idCt = 1000; - private int _id; - - public MyRef2() - { - _id = ++_idCt; - } - - public virtual int Id { - get { return _id; } - set { _id = value; } - } - - public virtual int? J1 { get; set; } - public virtual int J2 { get; set; } - public virtual int J3 { get; set; } - } - - public class MyRef3 - { - private static int _idCt = 3000; - private int _id; - - public MyRef3() - { - _id = ++_idCt; - } - - public virtual int Id { - get { return _id; } - set { _id = value; } - } - - public virtual int L1 { get; set; } - } - - public enum Ignore { Ignore } - public enum TK { Zero, One } - public enum TBO1_I { Null, Zero, One } - public enum TBO2_J { Null, Zero, One } - public enum TBO1_BO2_J { Null, BO1, Zero, One } - public enum TBO1_BO3_L { Null, BO1, Zero, One } - - public class MyBO - { - private static int _idCt = 0; - private int _id; - - public MyBO() - { - _id = ++_idCt; - } - - public virtual int Id { - get { return _id; } - set { _id = value; } - } - - public virtual string Name { get; set; } - public virtual MyBO LeftSon { get; set; } - public virtual MyBO RightSon { get; set; } - public virtual MyRef1 BO1 { get; set; } - public virtual MyRef1 OtherBO1 { get; set; } - public virtual MyRef2 BO2 { get; set; } - public virtual int? K1 { get; set; } - public virtual int K2 { get; set; } - public virtual int K3 { get; set; } - - private MyRef1 GetOrCreateBO1(ISession s) - { - if (BO1 == null) - { - BO1 = new MyRef1(); - s.Save(BO1); - } - return BO1; - } - - private MyRef2 GetOrCreateBO2(ISession s) - { - if (BO2 == null) - { - BO2 = new MyRef2(); - s.Save(BO2); - } - return BO2; - } - - public static void SetK1(MyBO bo, ISession s, TK value) - { - bo.K1 = value == TK.One ? 1 : 0; - } - - public static void SetK2(MyBO bo, ISession s, TK value) - { - bo.K2 = value == TK.One ? 1 : 0; - } - - public static void SetK3(MyBO bo, ISession s, TK value) - { - bo.K3 = value == TK.One ? 1 : 0; - } - - private static void SetBO1_I(MyBO bo, ISession s, TBO1_I value, System.Action<MyRef1, int> set) - { - switch (value) - { - case TBO1_I.Null: - bo.BO1 = null; - break; - case TBO1_I.One: - set(bo.GetOrCreateBO1(s), 1); - break; - case TBO1_I.Zero: - set(bo.GetOrCreateBO1(s), 0); - break; - } - } - - public static void SetBO1_I1(MyBO bo, ISession s, TBO1_I value) - { - SetBO1_I(bo, s, value, (b, i) => b.I1 = i); - } - - public static void SetBO1_I2(MyBO bo, ISession s, TBO1_I value) - { - SetBO1_I(bo, s, value, (b, i) => b.I2 = i); - } - - public static void SetBO1_I3(MyBO bo, ISession s, TBO1_I value) - { - SetBO1_I(bo, s, value, (b, i) => b.I3 = i); - } - - private static void SetBO2_J(MyBO bo, ISession s, TBO2_J value, System.Action<MyRef2, int> set) - { - switch (value) - { - case TBO2_J.Null: - bo.BO2 = null; - break; - case TBO2_J.One: - set(bo.GetOrCreateBO2(s), 1); - break; - case TBO2_J.Zero: - set(bo.GetOrCreateBO2(s), 0); - break; - } - } - - public static void SetBO2_J1(MyBO bo, ISession s, TBO2_J value) - { - SetBO2_J(bo, s, value, (b, i) => b.J1 = i); - } - - public static void SetBO2_J2(MyBO bo, ISession s, TBO2_J value) - { - SetBO2_J(bo, s, value, (b, i) => b.J2 = i); - } - - public static void SetBO2_J3(MyBO bo, ISession s, TBO2_J value) - { - SetBO2_J(bo, s, value, (b, i) => b.J3 = i); - } - - private static void SetBO1_BO2_J(MyBO bo, ISession s, TBO1_BO2_J value, System.Action<MyRef2, int> set) - { - switch (value) - { - case TBO1_BO2_J.Null: - bo.BO1 = null; - break; - case TBO1_BO2_J.BO1: - bo.GetOrCreateBO1(s).BO2 = null; - break; - case TBO1_BO2_J.Zero: - set(bo.GetOrCreateBO1(s).GetOrCreateBO2(s), 0); - break; - case TBO1_BO2_J.One: - set(bo.GetOrCreateBO1(s).GetOrCreateBO2(s), 1); - break; - } - } - - public static void SetBO1_BO2_J1(MyBO bo, ISession s, TBO1_BO2_J value) - { - SetBO1_BO2_J(bo, s, value, (b, i) => b.J1 = i); - } - - public static void Set_BO1_BO2_J2(MyBO bo, ISession s, TBO1_BO2_J value) - { - SetBO1_BO2_J(bo, s, value, (b, i) => b.J2 = i); - } - - public static void SetBO1_BO3_L1(MyBO bo, ISession s, TBO1_BO3_L value) - { - switch (value) - { - case TBO1_BO3_L.Null: - bo.BO1 = null; - break; - case TBO1_BO3_L.BO1: - bo.GetOrCreateBO1(s).BO3 = null; - break; - case TBO1_BO3_L.Zero: - bo.GetOrCreateBO1(s).GetOrCreateBO3(s).L1 = 0; - break; - case TBO1_BO3_L.One: - bo.GetOrCreateBO1(s).GetOrCreateBO3(s).L1 = 1; - break; - } - } - } -} +using System; + +namespace NHibernate.Test.NHSpecificTest.NH2583 +{ + public class MyRef1 + { + private static int _idCt = 1000; + private int _id; + + public MyRef1() + { + _id = ++_idCt; + } + + public virtual int Id + { + get { return _id; } + set { _id = value; } + } + + public virtual int? I1 { get; set; } + public virtual int I2 { get; set; } + public virtual int I3 { get; set; } + + public virtual MyRef2 BO2 { get; set; } + public virtual MyRef3 BO3 { get; set; } + + public virtual MyRef2 GetOrCreateBO2(ISession s) + { + if (BO2 == null) + { + BO2 = new MyRef2(); + s.Save(BO2); + } + return BO2; + } + + public virtual MyRef3 GetOrCreateBO3(ISession s) + { + if (BO3 == null) + { + BO3 = new MyRef3(); + s.Save(BO3); + } + return BO3; + } + } + + public class MyRef2 + { + private static int _idCt = 1000; + private int _id; + + public MyRef2() + { + _id = ++_idCt; + } + + public virtual int Id + { + get { return _id; } + set { _id = value; } + } + + public virtual int? J1 { get; set; } + public virtual int J2 { get; set; } + public virtual int J3 { get; set; } + } + + public class MyRef3 + { + private static int _idCt = 3000; + private int _id; + + public MyRef3() + { + _id = ++_idCt; + } + + public virtual int Id + { + get { return _id; } + set { _id = value; } + } + + public virtual int L1 { get; set; } + } + + public enum Ignore { Ignore } + public enum TK { ValueNull, Zero, One } + public enum TBO1_I { Null, ValueNull, Zero, One } + public enum TBO2_J { Null, ValueNull, Zero, One } + public enum TBO1_BO2_J { Null, BO1, ValueNull, Zero, One } + public enum TBO1_BO3_L { Null, BO1, ValueNull, Zero, One } + + public class MyBO + { + private static int _idCt = 0; + private int _id; + + public MyBO() + { + _id = ++_idCt; + } + + public virtual int Id + { + get { return _id; } + set { _id = value; } + } + + public virtual string Name { get; set; } + public virtual MyBO LeftSon { get; set; } + public virtual MyBO RightSon { get; set; } + public virtual MyRef1 BO1 { get; set; } + public virtual MyRef1 OtherBO1 { get; set; } + public virtual MyRef2 BO2 { get; set; } + public virtual int? K1 { get; set; } + public virtual int K2 { get; set; } + public virtual int K3 { get; set; } + + private MyRef1 GetOrCreateBO1(ISession s) + { + if (BO1 == null) + { + BO1 = new MyRef1(); + s.Save(BO1); + } + return BO1; + } + + private MyRef2 GetOrCreateBO2(ISession s) + { + if (BO2 == null) + { + BO2 = new MyRef2(); + s.Save(BO2); + } + return BO2; + } + + public static void SetK1(MyBO bo, ISession s, TK value) + { + switch (value) + { + case TK.ValueNull: + bo.K1 = null; + break; + case TK.Zero: + bo.K1 = 0; + break; + case TK.One: + bo.K1 = 1; + break; + default: + throw new Exception("Value " + value + " not handled in code"); + } + } + + public static void SetK2(MyBO bo, ISession s, TK value) + { + bo.K2 = value == TK.One ? 1 : 0; + } + + public static void SetK3(MyBO bo, ISession s, TK value) + { + bo.K3 = value == TK.One ? 1 : 0; + } + + private static void SetBO1_I(MyBO bo, ISession s, TBO1_I value, Action<MyRef1, int?> set) + { + switch (value) + { + case TBO1_I.Null: + bo.BO1 = null; + break; + case TBO1_I.ValueNull: + set(bo.GetOrCreateBO1(s), null); + break; + case TBO1_I.Zero: + set(bo.GetOrCreateBO1(s), 0); + break; + case TBO1_I.One: + set(bo.GetOrCreateBO1(s), 1); + break; + default: + throw new Exception("Value " + value + " not handled in code"); + } + } + + public static void SetBO1_I1(MyBO bo, ISession s, TBO1_I value) + { + SetBO1_I(bo, s, value, (b, i) => b.I1 = i); + } + + public static void SetBO1_I2(MyBO bo, ISession s, TBO1_I value) + { + SetBO1_I(bo, s, value, (b, i) => b.I2 = i ?? 0); + } + + public static void SetBO1_I3(MyBO bo, ISession s, TBO1_I value) + { + SetBO1_I(bo, s, value, (b, i) => b.I3 = i ?? 0); + } + + private static void SetBO2_J(MyBO bo, ISession s, TBO2_J value, Action<MyRef2, int?> set) + { + switch (value) + { + case TBO2_J.Null: + bo.BO2 = null; + break; + case TBO2_J.ValueNull: + set(bo.GetOrCreateBO2(s), null); + break; + case TBO2_J.Zero: + set(bo.GetOrCreateBO2(s), 0); + break; + case TBO2_J.One: + set(bo.GetOrCreateBO2(s), 1); + break; + default: + throw new Exception("Value " + value + " not handled in code"); + } + } + + public static void SetBO2_J1(MyBO bo, ISession s, TBO2_J value) + { + SetBO2_J(bo, s, value, (b, i) => b.J1 = i); + } + + public static void SetBO2_J2(MyBO bo, ISession s, TBO2_J value) + { + SetBO2_J(bo, s, value, (b, i) => b.J2 = i ?? 0); + } + + public static void SetBO2_J3(MyBO bo, ISession s, TBO2_J value) + { + SetBO2_J(bo, s, value, (b, i) => b.J3 = i ?? 0); + } + + private static void SetBO1_BO2_J(MyBO bo, ISession s, TBO1_BO2_J value, Action<MyRef2, int?> set) + { + switch (value) + { + case TBO1_BO2_J.Null: + bo.BO1 = null; + break; + case TBO1_BO2_J.BO1: + bo.GetOrCreateBO1(s).BO2 = null; + break; + case TBO1_BO2_J.ValueNull: + set(bo.GetOrCreateBO1(s).GetOrCreateBO2(s), null); + break; + case TBO1_BO2_J.Zero: + set(bo.GetOrCreateBO1(s).GetOrCreateBO2(s), 0); + break; + case TBO1_BO2_J.One: + set(bo.GetOrCreateBO1(s).GetOrCreateBO2(s), 1); + break; + default: + throw new Exception("Value " + value + " not handled in code"); + } + } + + public static void SetBO1_BO2_J1(MyBO bo, ISession s, TBO1_BO2_J value) + { + SetBO1_BO2_J(bo, s, value, (b, i) => b.J1 = i); + } + + public static void Set_BO1_BO2_J2(MyBO bo, ISession s, TBO1_BO2_J value) + { + SetBO1_BO2_J(bo, s, value, (b, i) => b.J2 = i ?? 0); + } + + public static void SetBO1_BO3_L1(MyBO bo, ISession s, TBO1_BO3_L value) + { + switch (value) + { + case TBO1_BO3_L.Null: + bo.BO1 = null; + break; + case TBO1_BO3_L.BO1: + bo.GetOrCreateBO1(s).BO3 = null; + break; + case TBO1_BO3_L.ValueNull: + bo.GetOrCreateBO1(s).GetOrCreateBO3(s).L1 = 0; // L1 is int, not int? + break; + case TBO1_BO3_L.Zero: + bo.GetOrCreateBO1(s).GetOrCreateBO3(s).L1 = 0; + break; + case TBO1_BO3_L.One: + bo.GetOrCreateBO1(s).GetOrCreateBO3(s).L1 = 1; + break; + default: + throw new Exception("Value " + value + " not handled in code"); + } + } + } +} Added: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2583/MassTestingMoreOperatorsFixture.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2583/MassTestingMoreOperatorsFixture.cs (rev 0) +++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2583/MassTestingMoreOperatorsFixture.cs 2011-04-25 05:57:46 UTC (rev 5758) @@ -0,0 +1,121 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Linq.Expressions; +using NHibernate.Linq; +using NUnit.Framework; + +namespace NHibernate.Test.NHSpecificTest.NH2583 +{ + public class MassTestingMoreOperatorsFixture : AbstractMassTestingFixture + { + protected override int TestAndAssert(Expression<Func<MyBO, bool>> condition, ISession session, IEnumerable<int> expectedIds) + { + IQueryable<int?> result = session.Query<MyBO>().Where(condition).Select(bo => (int?)bo.BO1.Id); + + var forceDBRun = result.ToList(); + + IEnumerable<int> resultNullTo0 = forceDBRun.Select(i => i ?? 0); + + var expectedBO1Ids = session.Query<MyBO>().Where(bo => expectedIds.Contains(bo.Id)).Select(bo => bo.BO1 == null ? 0 : bo.BO1.Id).ToList(); + AreEqual(expectedBO1Ids, resultNullTo0.ToArray()); + + // Unused result. + return -1; + } + + // Condition pattern: (A && B) && (C || D) SELECT E + + [Test] + public void TestNestedPlus() + { + RunTest(x => (x.K1 + x.K2) + x.K2 == null || (x.K1 + x.K2) + x.K2 == null, + Setters<TK, TK>(MyBO.SetK1, MyBO.SetK2)); + } + + [Test] + public void TestNestedPlusBehindNot() + { + RunTest(x => !((x.K1 + x.K2) + x.K2 != null), + Setters<TK, TK>(MyBO.SetK1, MyBO.SetK2)); + } + + [Test] + public void TestNestedPlusBehindNotAnd() + { + RunTest(x => !((x.K1 + x.K2) + x.K2 != null && (x.K1 + x.K2) + x.K2 != null), + Setters<TK, TK>(MyBO.SetK1, MyBO.SetK2)); + } + + [Test] + public void TestNestedPlusBehindNotOr() + { + RunTest(x => !((x.K1 + x.K2) + x.K2 != null || (x.K1 + x.K2) + x.K2 != null), + Setters<TK, TK>(MyBO.SetK1, MyBO.SetK2)); + } + + [Test] + public void TestNestedPlusBehindOrNav() + { + RunTest(x => (x.BO1.I1 + x.BO1.I2) + x.BO1.I2 == null || (x.BO1.I1 + x.BO1.I2) + x.BO1.I2 == null, + Setters<TBO1_I, TBO1_I>(MyBO.SetBO1_I1, MyBO.SetBO1_I2)); + } + [Test] + public void TestNestedPlusBehindNotNav() + { + RunTest(x => !((x.BO1.I1 + x.BO1.I2) + x.BO1.I2 != null), + Setters<TBO1_I, TBO1_I>(MyBO.SetBO1_I1, MyBO.SetBO1_I2)); + } + [Test] + public void TestNestedPlusBehindNotAndNav() + { + RunTest(x => !((x.BO1.I1 + x.BO1.I2) + x.BO1.I2 != null && (x.BO1.I1 + x.BO1.I2) + x.BO1.I2 != null), + Setters<TBO1_I, TBO1_I>(MyBO.SetBO1_I1, MyBO.SetBO1_I2)); + } + [Test] + public void TestNestedPlusBehindNotOrNav() + { + RunTest(x => !((x.BO1.I1 + x.BO1.I2) + x.BO1.I2 != null || (x.BO1.I1 + x.BO1.I2) + x.BO1.I2 != null), + Setters<TBO1_I, TBO1_I>(MyBO.SetBO1_I1, MyBO.SetBO1_I2)); + } + + + [Test] + public void TestNestedPlusBehindOrNav2() + { + RunTest(x => (x.BO1.I1 + x.BO1.I2) + x.BO1.I2 == null || (x.BO2.J1 + x.BO2.J2) + x.BO2.J2 == null, + Setters<TBO1_I, TBO1_I, TBO2_J, TBO2_J>(MyBO.SetBO1_I1, MyBO.SetBO1_I2, MyBO.SetBO2_J1, MyBO.SetBO2_J2)); + } + [Test] + public void TestNestedPlusBehindNotOrNav2() + { + RunTest(x => !((x.BO1.I1 + x.BO1.I2) + x.BO1.I2 == null || (x.BO2.J1 + x.BO2.J2) + x.BO2.J2 == null), + Setters<TBO1_I, TBO1_I, TBO2_J, TBO2_J>(MyBO.SetBO1_I1, MyBO.SetBO1_I2, MyBO.SetBO2_J1, MyBO.SetBO2_J2)); + } + [Test] + public void TestNestedPlusBehindNotAndNav2() + { + RunTest(x => !((x.BO1.I1 + x.BO1.I2) + x.BO1.I2 == null && (x.BO2.J1 + x.BO2.J2) + x.BO2.J2 == null), + Setters<TBO1_I, TBO1_I, TBO2_J, TBO2_J>(MyBO.SetBO1_I1, MyBO.SetBO1_I2, MyBO.SetBO2_J1, MyBO.SetBO2_J2)); + } + + [Test] + public void TestNestedPlusBehindOrNav3() + { + RunTest(x => (x.BO1.I1 + x.BO1.I2) + x.BO2.J2 == null || (x.BO2.J1 + x.BO2.J2) + x.BO1.I2 == null, + Setters<TBO1_I, TBO2_J, TBO2_J, TBO1_I>(MyBO.SetBO1_I1, MyBO.SetBO2_J2, MyBO.SetBO2_J1, MyBO.SetBO1_I2)); + } + [Test] + public void TestNestedPlusBehindNotOrNav3() + { + RunTest(x => !((x.BO1.I1 + x.BO1.I2) + x.BO2.J2 == null || (x.BO2.J1 + x.BO2.J2) + x.BO1.I2 == null), + Setters<TBO1_I, TBO2_J, TBO2_J, TBO1_I>(MyBO.SetBO1_I1, MyBO.SetBO2_J2, MyBO.SetBO2_J1, MyBO.SetBO1_I2)); + } + [Test] + public void TestNestedPlusBehindNotAndNav3() + { + RunTest(x => !((x.BO1.I1 + x.BO1.I2) + x.BO2.J2 == null && (x.BO2.J1 + x.BO2.J2) + x.BO1.I2 == null), + Setters<TBO1_I, TBO2_J, TBO2_J, TBO1_I>(MyBO.SetBO1_I1, MyBO.SetBO2_J2, MyBO.SetBO2_J1, MyBO.SetBO1_I2)); + } + } +} Modified: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2583/MassTestingNotAndDeMorganFixture.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2583/MassTestingNotAndDeMorganFixture.cs 2011-04-25 05:55:52 UTC (rev 5757) +++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2583/MassTestingNotAndDeMorganFixture.cs 2011-04-25 05:57:46 UTC (rev 5758) @@ -1,91 +1,126 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Linq.Expressions; -using NHibernate.Linq; -using NUnit.Framework; - -namespace NHibernate.Test.NHSpecificTest.NH2583 -{ - public class MassTestingNotAndDeMorganFixture : AbstractMassTestingFixture - { - protected override int TestAndAssert(Expression<Func<MyBO, bool>> condition, ISession session, IEnumerable<int> expectedIds) - { - var result = session.Query<MyBO>().Where(condition); - AreEqual(expectedIds, result.Select(bo => bo.Id).ToArray()); - return expectedIds.Count(); - } - - [Test] - public void Test_NotUnequalIsTheSameAsEqual() - { - int r1 = RunTest(x => !(x.BO1.I1 != 1), - Setters<TBO1_I>(MyBO.SetBO1_I1)); - int r2 = RunTest(x => x.BO1.I1 == 1, - Setters<TBO1_I>(MyBO.SetBO1_I1)); - Assert.AreEqual(r1, r2); - Assert.Greater(r1, 0); - - r1 = RunTest(x => !(x.BO1.I1 != 1), - Setters<TBO1_I, TBO2_J>(MyBO.SetBO1_I1, MyBO.SetBO2_J1)); - r2 = RunTest(x => x.BO1.I1 == 1, - Setters<TBO1_I, TBO2_J>(MyBO.SetBO1_I1, MyBO.SetBO2_J1)); - Assert.AreEqual(r1, r2); - Assert.Greater(r1, 0); - } - - [Test] - public void Test_NotEqualIsTheSameAsNotequal() - { - int r1 = RunTest(x => !(x.BO1.I1 == 1), - Setters<TBO1_I>(MyBO.SetBO1_I1)); - // ... is the same as ... - int r2 = RunTest(x => x.BO1.I1 != 1, - Setters<TBO1_I>(MyBO.SetBO1_I1)); - Assert.AreEqual(r1, r2); - Assert.Greater(r1, 0); - } - - [Test] - public void Test_DeMorganNotAnd() - { - // BO1.I1 BO2.J1 x.BO1.I1 != 1 x.BO2.J1 != 1 && ! Result (3v-->2v) Linq2Obj - // null null n n n n f - // null 0 n t n n f - // null 1 n f f t t - // 0 null t n n n f - // 0 0 t t t f f f - // 0 1 t f f t t t - // 1 null f n f t t - // 1 0 f t f t t t - // 1 1 f f f t t t - - RunTest(x => !(x.BO1.I1 != 1 && x.BO2.J1 != 1), - Setters<TBO1_I, TBO2_J>(MyBO.SetBO1_I1, MyBO.SetBO2_J1)); - } - - [Test] - public void Test_DeMorganNotOr() - { - int r1 = RunTest(x => !(x.BO1.I1 != 1 || x.BO2.J1 != 1), - Setters<TBO1_I, TBO2_J>(MyBO.SetBO1_I1, MyBO.SetBO2_J1)); - int r2 = RunTest(x => !(x.BO1.I1 != 1) && !(x.BO2.J1 != 1), - Setters<TBO1_I, TBO2_J>(MyBO.SetBO1_I1, MyBO.SetBO2_J1)); - int r3 = RunTest(x => x.BO1.I1 == 1 && x.BO2.J1 == 1, - Setters<TBO1_I, TBO2_J>(MyBO.SetBO1_I1, MyBO.SetBO2_J1)); - Assert.AreEqual(r1, r2); - Assert.AreEqual(r2, r3); - Assert.Greater(r1, 0); - } - - [Test] - public void Test_NotNotCanBeEliminated() - { - int r1 = RunTest(x => !(!(x.BO1.I1 != 1 && x.BO2.J1 != 1)), - Setters<TBO1_I, TBO2_J>(MyBO.SetBO1_I1, MyBO.SetBO2_J1)); - int r2 = RunTest(x => x.BO1.I1 != 1 && x.BO2.J1 != 1, - Setters<TBO1_I, TBO2_J>(MyBO.SetBO1_I1, MyBO.SetBO2_J1)); - Assert.AreEqual(r1, r2); - } - } -} +using System; +using System.Collections.Generic; +using System.Linq; +using System.Linq.Expressions; +using NHibernate.Linq; +using NUnit.Framework; + +namespace NHibernate.Test.NHSpecificTest.NH2583 +{ + public class MassTestingNotAndDeMorganFixture : AbstractMassTestingFixture + { + protected override int TestAndAssert(Expression<Func<MyBO, bool>> condition, ISession session, IEnumerable<int> expectedIds) + { + var result = session.Query<MyBO>().Where(condition); + AreEqual(expectedIds, result.Select(bo => bo.Id).ToArray()); + return expectedIds.Count(); + } + + [Test] + public void Test_NotUnequalIsTheSameAsEqual() + { + int r1 = RunTest(x => !(x.BO1.I1 != 1), + Setters<TBO1_I>(MyBO.SetBO1_I1)); + int r2 = RunTest(x => x.BO1.I1 == 1, + Setters<TBO1_I>(MyBO.SetBO1_I1)); + Assert.AreEqual(r1, r2); + Assert.Greater(r1, 0); + + r1 = RunTest(x => !(x.BO1.I1 != 1), + Setters<TBO1_I, TBO2_J>(MyBO.SetBO1_I1, MyBO.SetBO2_J1)); + r2 = RunTest(x => x.BO1.I1 == 1, + Setters<TBO1_I, TBO2_J>(MyBO.SetBO1_I1, MyBO.SetBO2_J1)); + Assert.AreEqual(r1, r2); + Assert.Greater(r1, 0); + } + + [Test] + public void Test_NotEqualIsTheSameAsNotequal() + { + // Already the following yields different results for I1 == null even though + // it does NOT throw an exception in Linq2Objects: + // ... RunTest(x => x.BO1.I1 != 1, ...); + // * In C# logic, we get null != 1 <=> true + // * In SQL logic, we get null != 1 <=> logical-null => false + + // To exclude this case, we can either make it false in C# ... + int r1 = RunTest(x => x.BO1.I1 != null && x.BO1.I1 != 1, + Setters<TBO1_I>(MyBO.SetBO1_I1)); + // ... or force it to true in SQL + int r2 = RunTest(x => x.BO1.I1 == null || x.BO1.I1 != 1, + Setters<TBO1_I>(MyBO.SetBO1_I1)); + + // Also the following condition yields different results for I1 == null even + // though it does NOT throw an exception in Linq2Objects: + // ... RunTest(x => !(x.BO1.I1 == 1), ...); + // * In C# logic, we get !(null == 1) <=> !(false) <=> true + // * In SQL logic, we get !(null == 1) <=> !(logical-null) <=> logical-null => false + + // Again, to exclude this case, we can either make the inner part true in C# ... + int r3 = RunTest(x => !(x.BO1.I1 == null || x.BO1.I1 == 1), + Setters<TBO1_I>(MyBO.SetBO1_I1)); + // ... or force it to false in SQL: + int r4 = RunTest(x => !(x.BO1.I1 != null && x.BO1.I1 == 1), + Setters<TBO1_I>(MyBO.SetBO1_I1)); + + Assert.Greater(r1, 0); + Assert.Greater(r2, 0); + + // We also expect the !(==) versions to return the same result as the != versions. + Assert.AreEqual(r1, r3); + Assert.AreEqual(r2, r4); + } + + [Test] + public void Test_DeMorganNotAnd() + { + // BO1.I1 BO2.J1 x.BO1.I1 != 1 x.BO2.J1 != 1 && ! Result (3v-->2v) Linq2Obj + // null null n n n n f + // null 0 n t n n f + // null 1 n f f t t + // 0 null t n n n f + // 0 0 t t t f f f + // 0 1 t f f t t t + // 1 null f n f t t + // 1 0 f t f t t t + // 1 1 f f f t t t + + RunTest(x => !(x.BO1.I1 != 1 && x.BO2.J1 != 1), + Setters<TBO1_I, TBO2_J>(MyBO.SetBO1_I1, MyBO.SetBO2_J1)); + } + + [Test] + public void Test_DeMorganNotOr() + { + int r1 = RunTest(x => !(x.BO1.I1 != 1 || x.BO2.J1 != 1), + Setters<TBO1_I, TBO2_J>(MyBO.SetBO1_I1, MyBO.SetBO2_J1)); + int r2 = RunTest(x => !(x.BO1.I1 != 1) && !(x.BO2.J1 != 1), + Setters<TBO1_I, TBO2_J>(MyBO.SetBO1_I1, MyBO.SetBO2_J1)); + int r3 = RunTest(x => x.BO1.I1 == 1 && x.BO2.J1 == 1, + Setters<TBO1_I, TBO2_J>(MyBO.SetBO1_I1, MyBO.SetBO2_J1)); + Assert.AreEqual(r1, r2); + Assert.AreEqual(r2, r3); + Assert.Greater(r1, 0); + } + + [Test] + public void Test_NotNotCanBeEliminated() + { + // The following condition does *not* return the same values if I1 and/or J1 are + // null in Linq2Objects and in Nhib.Linq: + // x => x.BO1.I1 != 1 && x.BO2.J1 != 1, + // First, assume I1 == null and J1 == 0: + // * In C# (Linq2Objects), we get null != 1 && 0 != 1 <=> true && true <=> true + // * In SQL (NHib.Linq), we get null != 1 && <=> logical-null && true <=> logical-null => false + // For I1 == 0 and J1 == null we get the same problem, as the condition is symmetric. + + // To repair this, we force "SQL" to true for nulls: + int r1 = RunTest(x => (x.BO1.I1 == null || x.BO1.I1 != 1) && (x.BO2.J1 == null || x.BO2.J1 != 1), + Setters<TBO1_I, TBO2_J>(MyBO.SetBO1_I1, MyBO.SetBO2_J1)); + int r2 = RunTest(x => !!((x.BO1.I1 == null || x.BO1.I1 != 1) && (x.BO2.J1 == null || x.BO2.J1 != 1)), + Setters<TBO1_I, TBO2_J>(MyBO.SetBO1_I1, MyBO.SetBO2_J1)); + Assert.Greater(r1, 0); + Assert.AreEqual(r1, r2); + } + } +} Modified: trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2011-04-25 05:55:52 UTC (rev 5757) +++ trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2011-04-25 05:57:46 UTC (rev 5758) @@ -778,6 +778,7 @@ <Compile Include="NHSpecificTest\NH2583\AbstractMassTestingFixture.cs" /> <Compile Include="NHSpecificTest\NH2583\Domain.cs" /> <Compile Include="NHSpecificTest\NH2583\ManualTestFixture.cs" /> + <Compile Include="NHSpecificTest\NH2583\MassTestingMoreOperatorsFixture.cs" /> <Compile Include="NHSpecificTest\NH2583\MassTestingNotAndDeMorganFixture.cs" /> <Compile Include="NHSpecificTest\NH2583\MassTestingOneOrTreeFixture.cs" /> <Compile Include="NHSpecificTest\NH2583\MassTestingOrderByFixture.cs" /> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pa...@us...> - 2011-04-25 05:55:59
|
Revision: 5757 http://nhibernate.svn.sourceforge.net/nhibernate/?rev=5757&view=rev Author: patearl Date: 2011-04-25 05:55:52 +0000 (Mon, 25 Apr 2011) Log Message: ----------- Tests: Fixed many tests for PostgreSQL. Modified Paths: -------------- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/Futures/FutureQueryFixture.cs trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/Futures/LinqFutureFixture.cs trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/ManyToOneFilters20Behaviour/Fixture.cs trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/ManyToOneFilters20Behaviour/Mappings.hbm.xml trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1444/Fixture.cs trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1849/Fixture.cs trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1891/FormulaEscaping.hbm.xml trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1895/Mappings.hbm.xml trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1941/Fixture.cs trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1978/Mappings.hbm.xml Modified: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/Futures/FutureQueryFixture.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/Futures/FutureQueryFixture.cs 2011-04-25 03:36:53 UTC (rev 5756) +++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/Futures/FutureQueryFixture.cs 2011-04-25 05:55:52 UTC (rev 5757) @@ -1,4 +1,5 @@ -using NHibernate.Impl; +using NHibernate.Driver; +using NHibernate.Impl; using NUnit.Framework; namespace NHibernate.Test.NHSpecificTest.Futures @@ -121,7 +122,8 @@ var events = logSpy.Appender.GetEvents(); Assert.AreEqual(1, events.Length); var wholeLog = logSpy.GetWholeLog(); - Assert.True(wholeLog.Contains("@p0 = 1 [Type: Int32 (0)], @p1 = 2 [Type: Int32 (0)]")); + string paramPrefix = ((DriverBase) Sfi.ConnectionProvider.Driver).NamedPrefix; + Assert.True(wholeLog.Contains(paramPrefix + "p0 = 1 [Type: Int32 (0)], " + paramPrefix + "p1 = 2 [Type: Int32 (0)]")); } } Modified: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/Futures/LinqFutureFixture.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/Futures/LinqFutureFixture.cs 2011-04-25 03:36:53 UTC (rev 5756) +++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/Futures/LinqFutureFixture.cs 2011-04-25 05:55:52 UTC (rev 5757) @@ -1,4 +1,5 @@ -using NHibernate.Impl; +using NHibernate.Driver; +using NHibernate.Impl; using NUnit.Framework; using NHibernate.Linq; using System.Linq; @@ -155,7 +156,8 @@ var events = logSpy.Appender.GetEvents(); Assert.AreEqual(1, events.Length); var wholeLog = logSpy.GetWholeLog(); - Assert.True(wholeLog.Contains("@p0 = 1 [Type: Int32 (0)], @p1 = 2 [Type: Int32 (0)]")); + string paramPrefix = ((DriverBase)Sfi.ConnectionProvider.Driver).NamedPrefix; + Assert.True(wholeLog.Contains(paramPrefix + "p0 = 1 [Type: Int32 (0)], " + paramPrefix + "p1 = 2 [Type: Int32 (0)]")); } } Modified: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/ManyToOneFilters20Behaviour/Fixture.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/ManyToOneFilters20Behaviour/Fixture.cs 2011-04-25 03:36:53 UTC (rev 5756) +++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/ManyToOneFilters20Behaviour/Fixture.cs 2011-04-25 05:55:52 UTC (rev 5757) @@ -29,9 +29,9 @@ private static void enableFilters(ISession s) { IFilter f = s.EnableFilter("activeChild"); - f.SetParameter("active", 1); + f.SetParameter("active", true); IFilter f2 = s.EnableFilter("alwaysValid"); - f2.SetParameter("always", 1); + f2.SetParameter("always", true); } protected override void OnTearDown() @@ -178,7 +178,7 @@ using (ISession s = OpenSession()) { IFilter f = s.EnableFilter("active"); - f.SetParameter("active", 1); + f.SetParameter("active", true); IList<Parent> resCriteria = joinGraphUsingCriteria(s); IList<Parent> resHql = joinGraphUsingHql(s); @@ -209,7 +209,7 @@ using (ISession s = OpenSession()) { IFilter f = s.EnableFilter("active"); - f.SetParameter("active", 1); + f.SetParameter("active", true); IList<Parent> resCriteria = s.CreateCriteria(typeof(Parent)).SetFetchMode("Children", FetchMode.Join).List<Parent>(); IList<Parent> resHql = s.CreateQuery("select p from Parent p join fetch p.Children").List<Parent>(); Modified: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/ManyToOneFilters20Behaviour/Mappings.hbm.xml =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/ManyToOneFilters20Behaviour/Mappings.hbm.xml 2011-04-25 03:36:53 UTC (rev 5756) +++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/ManyToOneFilters20Behaviour/Mappings.hbm.xml 2011-04-25 05:55:52 UTC (rev 5757) @@ -41,15 +41,15 @@ </class> <filter-def name="activeChild" use-many-to-one="false"> - <filter-param name="active" type="int"/> + <filter-param name="active" type="bool"/> </filter-def> <filter-def name="active" use-many-to-one="false"> - <filter-param name="active" type="int"/> + <filter-param name="active" type="bool"/> </filter-def> <filter-def name="alwaysValid"> - <filter-param name="always" type="int"/> + <filter-param name="always" type="bool"/> </filter-def> </hibernate-mapping> Modified: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1444/Fixture.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1444/Fixture.cs 2011-04-25 03:36:53 UTC (rev 5756) +++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1444/Fixture.cs 2011-04-25 05:55:52 UTC (rev 5757) @@ -1,4 +1,5 @@ using NHibernate.Cfg; +using NHibernate.Driver; using NUnit.Framework; namespace NHibernate.Test.NHSpecificTest.NH1444 @@ -22,7 +23,8 @@ .SetParameter("filternull", !filter.HasValue) .SetParameter("filterval", filter.HasValue ? filter.Value : 0).List<xchild>(); var message = ls.GetWholeLog(); - Assert.That(message, Is.StringContaining("xchild0_.ParentId=xparent1_.Id and (@p0=1 or xparent1_.A<@p1)")); + string paramPrefix = ((DriverBase) Sfi.ConnectionProvider.Driver).NamedPrefix; + Assert.That(message, Is.StringContaining("xchild0_.ParentId=xparent1_.Id and (" + paramPrefix + "p0=" + Dialect.ToBooleanValueString(true) + " or xparent1_.A<" + paramPrefix + "p1)")); } } } Modified: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1849/Fixture.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1849/Fixture.cs 2011-04-25 03:36:53 UTC (rev 5756) +++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1849/Fixture.cs 2011-04-25 05:55:52 UTC (rev 5757) @@ -1,3 +1,4 @@ +using System.Text.RegularExpressions; using NHibernate.Cfg; using NHibernate.Dialect; using NHibernate.Dialect.Function; @@ -18,15 +19,20 @@ [TestFixture] public class Fixture : BugTestCase { + private bool _OrignalDialectIsMsSql2005Dialect; + protected override bool AppliesTo(Dialect.Dialect dialect) { - return dialect is MsSql2005Dialect; + return _OrignalDialectIsMsSql2005Dialect; } protected override void Configure(Configuration configuration) { base.Configure(configuration); + // Ugly hack. + _OrignalDialectIsMsSql2005Dialect = Regex.IsMatch(configuration.GetProperty("dialect"), "MsSql200(5|8)Dialect"); + configuration.SetProperty("dialect", "NHibernate.Test.NHSpecificTest.NH1849.CustomDialect, NHibernate.Test"); } Modified: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1891/FormulaEscaping.hbm.xml =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1891/FormulaEscaping.hbm.xml 2011-04-25 03:36:53 UTC (rev 5756) +++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1891/FormulaEscaping.hbm.xml 2011-04-25 05:55:52 UTC (rev 5757) @@ -12,6 +12,6 @@ <id name="Id" column="id"> <generator class="guid.comb" /> </id> - <property name="Name" /> + <property name="Name" column="`Name`" /> </class> </hibernate-mapping> \ No newline at end of file Modified: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1895/Mappings.hbm.xml =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1895/Mappings.hbm.xml 2011-04-25 03:36:53 UTC (rev 5756) +++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1895/Mappings.hbm.xml 2011-04-25 05:55:52 UTC (rev 5757) @@ -2,7 +2,7 @@ <hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" assembly="NHibernate.Test" namespace="NHibernate.Test.NHSpecificTest.NH1895" default-lazy="false"> - <class name="Order" table="[Order]"> + <class name="Order" table="`Order`"> <id name="Id" type="guid" column="O_Id"> <generator class="assigned" /> </id> Modified: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1941/Fixture.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1941/Fixture.cs 2011-04-25 03:36:53 UTC (rev 5756) +++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1941/Fixture.cs 2011-04-25 05:55:52 UTC (rev 5757) @@ -1,4 +1,5 @@ using System; +using NHibernate.Driver; using NUnit.Framework; namespace NHibernate.Test.NHSpecificTest.NH1941 @@ -18,6 +19,7 @@ [Test] public void CanOverrideStringEnumGetValue() { + string paramPrefix = ((DriverBase) Sfi.ConnectionProvider.Driver).NamedPrefix; using (ISession s = OpenSession()) using (ITransaction tx = s.BeginTransaction()) { @@ -27,7 +29,7 @@ s.Save(person); string log = ls.GetWholeLog(); - Assert.IsTrue(log.Contains("@p0 = 'M'")); + Assert.IsTrue(log.Contains(paramPrefix + "p0 = 'M'")); } using (SqlLogSpy ls = new SqlLogSpy()) @@ -40,7 +42,7 @@ Assert.That(person, Is.Null); string log = ls.GetWholeLog(); - Assert.IsTrue(log.Contains("@p0 = 'F'")); + Assert.IsTrue(log.Contains(paramPrefix + "p0 = 'F'")); } tx.Rollback(); Modified: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1978/Mappings.hbm.xml =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1978/Mappings.hbm.xml 2011-04-25 03:36:53 UTC (rev 5756) +++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1978/Mappings.hbm.xml 2011-04-25 05:55:52 UTC (rev 5757) @@ -13,7 +13,7 @@ <column name="Plan401kID" sql-type="int" not-null="false" /> </many-to-one> </class> - <class name="_401k" lazy="true" table="[401k]"> + <class name="_401k" lazy="true" table="`401k`"> <id name="ID" type="Int32" unsaved-value="0"> <generator class="native" /> </id> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pa...@us...> - 2011-04-25 03:36:59
|
Revision: 5756 http://nhibernate.svn.sourceforge.net/nhibernate/?rev=5756&view=rev Author: patearl Date: 2011-04-25 03:36:53 +0000 (Mon, 25 Apr 2011) Log Message: ----------- Lib: Use Npgsql from trunk (after 2.0.11.91 release) until there's a new release. Fixes problems with DateTime/DbType.Time. Modified Paths: -------------- trunk/nhibernate/lib/teamcity/postgresql/Npgsql.dll Modified: trunk/nhibernate/lib/teamcity/postgresql/Npgsql.dll =================================================================== (Binary files differ) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fab...@us...> - 2011-04-24 14:19:07
|
Revision: 5755 http://nhibernate.svn.sourceforge.net/nhibernate/?rev=5755&view=rev Author: fabiomaulo Date: 2011-04-24 14:19:01 +0000 (Sun, 24 Apr 2011) Log Message: ----------- Fix NH-2569 Modified Paths: -------------- trunk/nhibernate/src/NHibernate/Cfg/XmlHbmBinding/IdGeneratorBinder.cs trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj Added Paths: ----------- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2569/ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2569/Fixture.cs Modified: trunk/nhibernate/src/NHibernate/Cfg/XmlHbmBinding/IdGeneratorBinder.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Cfg/XmlHbmBinding/IdGeneratorBinder.cs 2011-04-23 20:42:26 UTC (rev 5754) +++ trunk/nhibernate/src/NHibernate/Cfg/XmlHbmBinding/IdGeneratorBinder.cs 2011-04-24 14:19:01 UTC (rev 5755) @@ -40,12 +40,12 @@ var results = new Dictionary<string, string>(); if (schema != null) - results.Add(Id.PersistentIdGeneratorParmsNames.Schema, schema); - else if (mappings.SchemaName != null) - results.Add(Id.PersistentIdGeneratorParmsNames.Schema, mappings.Dialect.QuoteForSchemaName(mappings.SchemaName)); + results[Id.PersistentIdGeneratorParmsNames.Schema] = schema; + if (mappings.SchemaName != null) + results[Id.PersistentIdGeneratorParmsNames.Schema] = mappings.Dialect.QuoteForSchemaName(mappings.SchemaName); foreach (HbmParam paramSchema in generatorMapping.param ?? new HbmParam[0]) - results.Add(paramSchema.name, paramSchema.GetText()); + results[paramSchema.name] = paramSchema.GetText(); return results; } Added: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2569/Fixture.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2569/Fixture.cs (rev 0) +++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2569/Fixture.cs 2011-04-24 14:19:01 UTC (rev 5755) @@ -0,0 +1,38 @@ +using NHibernate.Cfg; +using NHibernate.Dialect; +using NHibernate.Mapping; +using NHibernate.Mapping.ByCode; +using NUnit.Framework; +using SharpTestsEx; +namespace NHibernate.Test.NHSpecificTest.NH2569 +{ + public class MyClass + { + public virtual int Id { get; set; } + } + + public class Fixture + { + [Test] + public void WhenMapHiloToDifferentSchemaThanClassThenIdHasTheMappedSchema() + { + var mapper = new ModelMapper(); + mapper.Class<MyClass>(cm => + { + cm.Schema("aSchema"); + cm.Id(x => x.Id, idm => idm.Generator(Generators.HighLow, gm => gm.Params(new + { + table = "hilosequences", + schema="gSchema" + }))); + }); + var conf = new Configuration(); + conf.DataBaseIntegration(x=> x.Dialect<MsSql2008Dialect>()); + conf.AddDeserializedMapping(mapper.CompileMappingForAllExplicitAddedEntities(), "wholeDomain"); + + var mappings = conf.CreateMappings(Dialect.Dialect.GetDialect()); + var pc = mappings.GetClass(typeof(MyClass).FullName); + ((SimpleValue)pc.Identifier).IdentifierGeneratorProperties["schema"].Should().Be("gSchema"); + } + } +} \ 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-23 20:42:26 UTC (rev 5754) +++ trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2011-04-24 14:19:01 UTC (rev 5755) @@ -773,6 +773,7 @@ <Compile Include="NHSpecificTest\NH2554\Model.cs" /> <Compile Include="NHSpecificTest\NH2565\Domain.cs" /> <Compile Include="NHSpecificTest\NH2565\Fixture.cs" /> + <Compile Include="NHSpecificTest\NH2569\Fixture.cs" /> <Compile Include="NHSpecificTest\NH2580\Fixture.cs" /> <Compile Include="NHSpecificTest\NH2583\AbstractMassTestingFixture.cs" /> <Compile Include="NHSpecificTest\NH2583\Domain.cs" /> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fab...@us...> - 2011-04-23 20:42:33
|
Revision: 5754 http://nhibernate.svn.sourceforge.net/nhibernate/?rev=5754&view=rev Author: fabiomaulo Date: 2011-04-23 20:42:26 +0000 (Sat, 23 Apr 2011) Log Message: ----------- Test to check NH-1642 was fixed too Modified Paths: -------------- trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj Added Paths: ----------- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1642/ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1642/AbstractRule.cs trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1642/Mappings.hbm.xml trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1642/TrafficRule.cs trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1642/TrafficRuleSet.cs trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1642/TrafficRuleSetDAOTest.cs Added: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1642/AbstractRule.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1642/AbstractRule.cs (rev 0) +++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1642/AbstractRule.cs 2011-04-23 20:42:26 UTC (rev 5754) @@ -0,0 +1,9 @@ +namespace NHibernate.Test.NHSpecificTest.NH1642 +{ + public abstract class AbstractRule + { + public virtual int id { get; set; } + public virtual string name { get; set; } + public virtual string description { get; set; } + } +} \ No newline at end of file Added: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1642/Mappings.hbm.xml =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1642/Mappings.hbm.xml (rev 0) +++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1642/Mappings.hbm.xml 2011-04-23 20:42:26 UTC (rev 5754) @@ -0,0 +1,40 @@ +<?xml version="1.0" encoding="utf-8" ?> +<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" + namespace="NHibernate.Test.NHSpecificTest.NH1642" + assembly="NHibernate.Test"> + <class name="AbstractRule" table="GENERIC_RULE"> + <id name="id" column="RULE_ID"> + <generator class="identity"/> + </id> + <discriminator column="RULE_TYPE" type="string"/> + + <property name="name" /> + <property name="description"/> + + <subclass name="TrafficRule" discriminator-value="TRAFFIC"> + <join table="TRAFFIC_RULE"> + <key column="RULE_ID"/> + + <property name="effectiveStartDate" column="start_date" /> + <property name="effectiveEndDate" column="end_date" /> + + <many-to-one name="ruleSet" class="TrafficRuleSet" column="RULESET_ID"/> + </join> + + </subclass> + </class> + <class name="TrafficRuleSet" table="TRAFFIC_RULSET"> + <id name="id" column="RULESET_ID"> + <generator class="identity"/> + </id> + + <property name="name"/> + <property name="description" /> + + <bag name="rules" inverse="true" cascade="all"> + <key column="RULESET_ID" on-delete="cascade" /> + <one-to-many class="TrafficRule"/> + </bag> + </class> + +</hibernate-mapping> Added: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1642/TrafficRule.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1642/TrafficRule.cs (rev 0) +++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1642/TrafficRule.cs 2011-04-23 20:42:26 UTC (rev 5754) @@ -0,0 +1,17 @@ +using System; + +namespace NHibernate.Test.NHSpecificTest.NH1642 +{ + public class TrafficRule : AbstractRule + { + public TrafficRule() + { + effectiveStartDate = DateTime.Today; + effectiveEndDate = DateTime.Today; + } + public virtual DateTime effectiveStartDate { get; set; } + public virtual DateTime effectiveEndDate { get; set; } + + public virtual TrafficRuleSet ruleSet { get; set; } + } +} \ No newline at end of file Added: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1642/TrafficRuleSet.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1642/TrafficRuleSet.cs (rev 0) +++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1642/TrafficRuleSet.cs 2011-04-23 20:42:26 UTC (rev 5754) @@ -0,0 +1,12 @@ +using System.Collections.Generic; + +namespace NHibernate.Test.NHSpecificTest.NH1642 +{ + public class TrafficRuleSet + { + public virtual int id { get; set; } + public virtual string name { get; set; } + public virtual string description { get; set; } + public virtual IList<TrafficRule> rules { get; set; } + } +} \ No newline at end of file Added: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1642/TrafficRuleSetDAOTest.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1642/TrafficRuleSetDAOTest.cs (rev 0) +++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1642/TrafficRuleSetDAOTest.cs 2011-04-23 20:42:26 UTC (rev 5754) @@ -0,0 +1,79 @@ +using System; +using System.Collections.Generic; +using NUnit.Framework; + +namespace NHibernate.Test.NHSpecificTest.NH1642 +{ + [TestFixture] + public class TrafficRuleSetDAOTest: BugTestCase + { + private class Scenario: IDisposable + { + private readonly ISessionFactory sessionFactory; + private int ruleSetId; + private string ruleSetName; + + public Scenario(ISessionFactory sessionFactory) + { + this.sessionFactory = sessionFactory; + ruleSetId = 2; + ruleSetName = "RuleSet" + ruleSetId.ToString(); + + using (var session = sessionFactory.OpenSession()) + { + using (var tr = session.BeginTransaction()) + { + TrafficRuleSet ruleSet = new TrafficRuleSet { name = ruleSetName, description = ruleSetName }; + TrafficRule rule = new TrafficRule { ruleSet = ruleSet, name = ruleSetName + "-a", description = "Some description" }; + + ruleSet.rules = new List<TrafficRule> { rule }; + + ruleSetId = (int)session.Save(ruleSet); + tr.Commit(); + } + } + } + + public int RuleSetId + { + get { return ruleSetId; } + } + + public string RuleSetName + { + get { return ruleSetName; } + } + + public void Dispose() + { + using (var session = sessionFactory.OpenSession()) + { + using (var tr = session.BeginTransaction()) + { + session.CreateQuery("delete from TrafficRule").ExecuteUpdate(); + session.CreateQuery("delete from TrafficRuleSet").ExecuteUpdate(); + tr.Commit(); + } + } + } + } + [Test] + public void addRuleSet() + { + using (var scenario = new Scenario(Sfi)) + { + using (var session = OpenSession()) + { + using (var tr = session.BeginTransaction()) + { + TrafficRuleSet fromDb = session.Get<TrafficRuleSet>(scenario.RuleSetId); + Assert.IsNotNull(fromDb); + Assert.AreEqual(fromDb.name, scenario.RuleSetName); + Assert.AreEqual(fromDb.rules[0].name, scenario.RuleSetName + "-a"); + } + } + } + } + + } +} Modified: trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2011-04-23 20:10:49 UTC (rev 5753) +++ trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2011-04-23 20:42:26 UTC (rev 5754) @@ -626,6 +626,10 @@ <Compile Include="NHSpecificTest\NH1323\Domain.cs" /> <Compile Include="NHSpecificTest\NH1421\AnEntity.cs" /> <Compile Include="NHSpecificTest\NH1421\Fixture.cs" /> + <Compile Include="NHSpecificTest\NH1642\AbstractRule.cs" /> + <Compile Include="NHSpecificTest\NH1642\TrafficRule.cs" /> + <Compile Include="NHSpecificTest\NH1642\TrafficRuleSet.cs" /> + <Compile Include="NHSpecificTest\NH1642\TrafficRuleSetDAOTest.cs" /> <Compile Include="NHSpecificTest\NH1836\Entity.cs" /> <Compile Include="NHSpecificTest\NH1836\EntityDTO.cs" /> <Compile Include="NHSpecificTest\NH1836\Fixture.cs" /> @@ -2627,6 +2631,7 @@ <EmbeddedResource Include="NHSpecificTest\NH1291AnonExample\Mappings.hbm.xml" /> </ItemGroup> <ItemGroup> + <EmbeddedResource Include="NHSpecificTest\NH1642\Mappings.hbm.xml" /> <EmbeddedResource Include="Stateless\Contact.hbm.xml" /> <EmbeddedResource Include="Stateless\Fetching\Mappings.hbm.xml" /> <EmbeddedResource Include="NHSpecificTest\NH2660And2661\Mappings.hbm.xml" /> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |