|
From: <fab...@us...> - 2009-06-07 23:03:20
|
Revision: 4428
http://nhibernate.svn.sourceforge.net/nhibernate/?rev=4428&view=rev
Author: fabiomaulo
Date: 2009-06-07 23:03:14 +0000 (Sun, 07 Jun 2009)
Log Message:
-----------
Fix NH-1817
Modified Paths:
--------------
trunk/nhibernate/src/NHibernate/Cfg/XmlHbmBinding/ClassIdBinder.cs
trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj
Added Paths:
-----------
trunk/nhibernate/src/NHibernate.Test/TypeParameters/DefinedTypeForIdFixture.cs
trunk/nhibernate/src/NHibernate.Test/TypeParameters/EntityCustomId.cs
trunk/nhibernate/src/NHibernate.Test/TypeParameters/EntityCustomId.hbm.xml
Modified: trunk/nhibernate/src/NHibernate/Cfg/XmlHbmBinding/ClassIdBinder.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/Cfg/XmlHbmBinding/ClassIdBinder.cs 2009-06-07 14:58:43 UTC (rev 4427)
+++ trunk/nhibernate/src/NHibernate/Cfg/XmlHbmBinding/ClassIdBinder.cs 2009-06-07 23:03:14 UTC (rev 4428)
@@ -98,8 +98,22 @@
if (idSchema.generator.@class == null)
throw new MappingException("no class given for generator");
- id.IdentifierGeneratorStrategy = idSchema.generator.@class;
- id.IdentifierGeneratorProperties = GetGeneratorProperties(idSchema, id);
+ // NH Differen behavior : specific feature NH-1817
+ TypeDef typeDef = mappings.GetTypeDef(idSchema.generator.@class);
+ if (typeDef != null)
+ {
+ id.IdentifierGeneratorStrategy = typeDef.TypeClass;
+ // parameters on the property mapping should override parameters in the typedef
+ var allParameters = new Dictionary<string, string>(typeDef.Parameters);
+ ArrayHelper.AddAll(allParameters, GetGeneratorProperties(idSchema, id));
+
+ id.IdentifierGeneratorProperties = allParameters;
+ }
+ else
+ {
+ id.IdentifierGeneratorStrategy = idSchema.generator.@class;
+ id.IdentifierGeneratorProperties = GetGeneratorProperties(idSchema, id);
+ }
}
}
Modified: trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj
===================================================================
--- trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2009-06-07 14:58:43 UTC (rev 4427)
+++ trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2009-06-07 23:03:14 UTC (rev 4428)
@@ -1234,6 +1234,8 @@
<Compile Include="TransformTests\AliasToBeanResultTransformerFixture.cs" />
<Compile Include="TransformTests\Simple.cs" />
<Compile Include="TypeParameters\DefaultValueIntegerType.cs" />
+ <Compile Include="TypeParameters\DefinedTypeForIdFixture.cs" />
+ <Compile Include="TypeParameters\EntityCustomId.cs" />
<Compile Include="TypeParameters\TypeParameterTest.cs" />
<Compile Include="TypeParameters\Widget.cs" />
<Compile Include="TypesTest\BinaryBlobClass.cs" />
@@ -1897,6 +1899,7 @@
<EmbeddedResource Include="CacheTest\EntityWithFilters.xml" />
<EmbeddedResource Include="Classic\EntityWithLifecycle.hbm.xml" />
<Content Include="DynamicEntity\package.html" />
+ <EmbeddedResource Include="TypeParameters\EntityCustomId.hbm.xml" />
<EmbeddedResource Include="Tools\hbm2ddl\SchemaMetadataUpdaterTest\HeavyEntity.hbm.xml" />
<EmbeddedResource Include="NHSpecificTest\NH1182\Mappings.hbm.xml" />
<EmbeddedResource Include="NHSpecificTest\NH1171\Mappings.hbm.xml" />
Added: trunk/nhibernate/src/NHibernate.Test/TypeParameters/DefinedTypeForIdFixture.cs
===================================================================
--- trunk/nhibernate/src/NHibernate.Test/TypeParameters/DefinedTypeForIdFixture.cs (rev 0)
+++ trunk/nhibernate/src/NHibernate.Test/TypeParameters/DefinedTypeForIdFixture.cs 2009-06-07 23:03:14 UTC (rev 4428)
@@ -0,0 +1,56 @@
+using System.Collections;
+using NHibernate.Mapping;
+using NUnit.Framework;
+
+namespace NHibernate.Test.TypeParameters
+{
+ [TestFixture]
+ public class DefinedTypeForIdFixture : TestCase
+ {
+ protected override IList Mappings
+ {
+ get { return new[] { "TypeParameters.EntityCustomId.hbm.xml" }; }
+ }
+
+ protected override string MappingsAssembly
+ {
+ get { return "NHibernate.Test"; }
+ }
+
+ [Test]
+ public void HasParametrizedId()
+ {
+ var pc = cfg.GetClassMapping(typeof(EntityCustomId));
+ var idMap = (SimpleValue)pc.IdentifierProperty.Value;
+ Assert.That(idMap.IdentifierGeneratorStrategy, Is.EqualTo("NHibernate.Id.TableHiLoGenerator, NHibernate"));
+ Assert.That(idMap.IdentifierGeneratorProperties["max_lo"], Is.EqualTo("99"));
+ }
+
+ [Test]
+ [Description("Ensure the parametrized generator is working.")]
+ public void Save()
+ {
+ object savedId1;
+ object savedId2;
+
+ using (ISession s = OpenSession())
+ using (ITransaction t = s.BeginTransaction())
+ {
+ savedId1 = s.Save(new EntityCustomId());
+ savedId2 = s.Save(new EntityCustomId());
+ t.Commit();
+ }
+
+ Assert.That(savedId1, Is.LessThan(200), "should be work with custo parameters");
+ Assert.That(savedId1, Is.GreaterThan(99));
+ Assert.That(savedId2, Is.EqualTo((int)savedId1 + 1));
+
+ using (ISession s = OpenSession())
+ using (ITransaction t = s.BeginTransaction())
+ {
+ s.CreateQuery("delete from EntityCustomId").ExecuteUpdate();
+ t.Commit();
+ }
+ }
+ }
+}
\ No newline at end of file
Added: trunk/nhibernate/src/NHibernate.Test/TypeParameters/EntityCustomId.cs
===================================================================
--- trunk/nhibernate/src/NHibernate.Test/TypeParameters/EntityCustomId.cs (rev 0)
+++ trunk/nhibernate/src/NHibernate.Test/TypeParameters/EntityCustomId.cs 2009-06-07 23:03:14 UTC (rev 4428)
@@ -0,0 +1,8 @@
+namespace NHibernate.Test.TypeParameters
+{
+ public class EntityCustomId
+ {
+ public int Id { get; set; }
+ public string Name { get; set; }
+ }
+}
\ No newline at end of file
Added: trunk/nhibernate/src/NHibernate.Test/TypeParameters/EntityCustomId.hbm.xml
===================================================================
--- trunk/nhibernate/src/NHibernate.Test/TypeParameters/EntityCustomId.hbm.xml (rev 0)
+++ trunk/nhibernate/src/NHibernate.Test/TypeParameters/EntityCustomId.hbm.xml 2009-06-07 23:03:14 UTC (rev 4428)
@@ -0,0 +1,17 @@
+<?xml version="1.0" encoding="utf-8" ?>
+<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
+ assembly="NHibernate.Test"
+ namespace="NHibernate.Test.TypeParameters"
+ default-lazy='false'>
+
+ <typedef name="HighLow" class="NHibernate.Id.TableHiLoGenerator, NHibernate">
+ <param name="max_lo">99</param>
+ </typedef>
+
+ <class name="EntityCustomId">
+ <id name="Id">
+ <generator class="HighLow"/>
+ </id>
+ <property name="Name"/>
+ </class>
+</hibernate-mapping>
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|