|
From: <fab...@us...> - 2009-06-13 21:18:00
|
Revision: 4459
http://nhibernate.svn.sourceforge.net/nhibernate/?rev=4459&view=rev
Author: fabiomaulo
Date: 2009-06-13 21:17:59 +0000 (Sat, 13 Jun 2009)
Log Message:
-----------
Fix NH-1834
Modified Paths:
--------------
trunk/nhibernate/src/NHibernate/Cfg/HbmConstants.cs
trunk/nhibernate/src/NHibernate/Cfg/XmlHbmBinding/ClassBinder.cs
trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj
Added Paths:
-----------
trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1834/
trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1834/A.cs
trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1834/Fixture.cs
trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1834/Mappings.hbm.xml
Modified: trunk/nhibernate/src/NHibernate/Cfg/HbmConstants.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/Cfg/HbmConstants.cs 2009-06-12 15:34:31 UTC (rev 4458)
+++ trunk/nhibernate/src/NHibernate/Cfg/HbmConstants.cs 2009-06-13 21:17:59 UTC (rev 4459)
@@ -8,6 +8,7 @@
public const string nsPrefix = "hbm";
public const string nsKey = nsPrefix + ":key";
public const string nsColumn = nsPrefix + ":column";
+ public const string nsFormula = nsPrefix + ":formula";
public const string nsOneToMany = nsPrefix + ":one-to-many";
public const string nsParam = nsPrefix + ":param";
public const string nsIndex = nsPrefix + ":index";
Modified: trunk/nhibernate/src/NHibernate/Cfg/XmlHbmBinding/ClassBinder.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/Cfg/XmlHbmBinding/ClassBinder.cs 2009-06-12 15:34:31 UTC (rev 4458)
+++ trunk/nhibernate/src/NHibernate/Cfg/XmlHbmBinding/ClassBinder.cs 2009-06-13 21:17:59 UTC (rev 4459)
@@ -849,17 +849,30 @@
private void BindColumnsOrFormula(XmlNode node, SimpleValue simpleValue, string path, bool isNullable)
{
- XmlAttribute formulaNode = node.Attributes["formula"];
- if (formulaNode != null)
+ var formula = GetFormula(node);
+ if (formula != null)
{
- Formula f = new Formula();
- f.FormulaString = formulaNode.InnerText;
+ var f = new Formula { FormulaString = formula };
simpleValue.AddFormula(f);
}
else
BindColumns(node, simpleValue, isNullable, true, path);
}
+ protected string GetFormula(XmlNode node)
+ {
+ XmlAttribute attribute = node.Attributes["formula"];
+ if (attribute != null)
+ {
+ return attribute.InnerText;
+ }
+ else
+ {
+ var fcn = node.SelectSingleNode(HbmConstants.nsFormula, namespaceManager);
+ return fcn != null && !string.IsNullOrEmpty(fcn.InnerText) ? fcn.InnerText : null;
+ }
+ }
+
private void AddManyToOneSecondPass(ManyToOne manyToOne)
{
mappings.AddSecondPass(delegate(IDictionary<string, PersistentClass> persistentClasses)
Added: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1834/A.cs
===================================================================
--- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1834/A.cs (rev 0)
+++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1834/A.cs 2009-06-13 21:17:59 UTC (rev 4459)
@@ -0,0 +1,14 @@
+namespace NHibernate.Test.NHSpecificTest.NH1834
+{
+ public class A
+ {
+ public int Id { get; set; }
+ }
+
+ public class B
+ {
+ public int Id { get; set; }
+ public A A { get; set; }
+ public A A2 { get; set; }
+ }
+}
\ No newline at end of file
Added: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1834/Fixture.cs
===================================================================
--- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1834/Fixture.cs (rev 0)
+++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1834/Fixture.cs 2009-06-13 21:17:59 UTC (rev 4459)
@@ -0,0 +1,49 @@
+using NUnit.Framework;
+
+namespace NHibernate.Test.NHSpecificTest.NH1834
+{
+ [TestFixture]
+ public class Fixture : BugTestCase
+ {
+ protected override void OnSetUp()
+ {
+ base.OnSetUp();
+ var a = new A {Id = 1};
+ var a2 = new A {Id = 2};
+ var b = new B {Id = 1};
+
+ using (ISession session = base.OpenSession())
+ {
+ session.Save(a);
+ session.Save(a2);
+ session.Save(b);
+ session.Flush();
+ }
+ }
+
+ protected override void OnTearDown()
+ {
+ base.OnTearDown();
+ using (ISession session = base.OpenSession())
+ {
+ session.Delete("from B");
+ session.Delete("from A");
+ session.Flush();
+ }
+ }
+
+ [Test]
+ public void OneToManyPropertyWithFormulaNodeShouldWorkLikeFormulaAttrib()
+ {
+ using (ISession session = base.OpenSession())
+ {
+ session.Clear();
+
+ var b = session.Get<B>(1);
+ Assert.IsNotNull(b.A2);
+ Assert.IsNotNull(b.A);
+ Assert.That(b.A.Id == b.A2.Id);
+ }
+ }
+ }
+}
\ No newline at end of file
Added: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1834/Mappings.hbm.xml
===================================================================
--- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1834/Mappings.hbm.xml (rev 0)
+++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1834/Mappings.hbm.xml 2009-06-13 21:17:59 UTC (rev 4459)
@@ -0,0 +1,27 @@
+<?xml version="1.0" encoding="utf-8" ?>
+<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" assembly="NHibernate.Test"
+ namespace="NHibernate.Test.NHSpecificTest.NH1834"
+ default-lazy="false">
+
+
+
+ <class name="A">
+ <id name="Id" type="Int32">
+ <generator class="assigned" />
+ </id>
+ </class>
+
+ <class name="B">
+ <id name="Id" type="Int32">
+ <generator class="assigned" />
+ </id>
+
+ <!--formula attrib should work like formula node-->
+ <many-to-one name="A" class="A" insert="false" update="false">
+ <formula><![CDATA[(select max(A.Id) from A)]]></formula>
+ </many-to-one>
+
+ <many-to-one name="A2" class="A" insert="false" update="false" formula="(select max(A.Id) from A)"/>
+
+ </class>
+</hibernate-mapping>
\ No newline at end of file
Modified: trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj
===================================================================
--- trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2009-06-12 15:34:31 UTC (rev 4458)
+++ trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2009-06-13 21:17:59 UTC (rev 4459)
@@ -503,6 +503,8 @@
<Compile Include="NHSpecificTest\NH1813\Fixture.cs" />
<Compile Include="NHSpecificTest\NH1821\Entity.cs" />
<Compile Include="NHSpecificTest\NH1821\Fixture.cs" />
+ <Compile Include="NHSpecificTest\NH1834\A.cs" />
+ <Compile Include="NHSpecificTest\NH1834\Fixture.cs" />
<Compile Include="NHSpecificTest\NH645\HQLFunctionFixture.cs" />
<Compile Include="HQL\HQLFunctions.cs" />
<Compile Include="HQL\Human.cs" />
@@ -1903,6 +1905,7 @@
<EmbeddedResource Include="Classic\EntityWithLifecycle.hbm.xml" />
<EmbeddedResource Include="Bytecode\Lightweight\ProductLine.hbm.xml" />
<Content Include="DynamicEntity\package.html" />
+ <EmbeddedResource Include="NHSpecificTest\NH1834\Mappings.hbm.xml" />
<EmbeddedResource Include="NHSpecificTest\NH1821\Mappings.hbm.xml" />
<EmbeddedResource Include="TypeParameters\EntityCustomId.hbm.xml" />
<EmbeddedResource Include="Tools\hbm2ddl\SchemaMetadataUpdaterTest\HeavyEntity.hbm.xml" />
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|