|
From: <fab...@us...> - 2009-03-16 16:27:12
|
Revision: 4139
http://nhibernate.svn.sourceforge.net/nhibernate/?rev=4139&view=rev
Author: fabiomaulo
Date: 2009-03-16 16:27:01 +0000 (Mon, 16 Mar 2009)
Log Message:
-----------
Fix NH-1222
Modified Paths:
--------------
trunk/nhibernate/src/NHibernate/Cfg/MappingSchema/Hbm.generated.cs
trunk/nhibernate/src/NHibernate/Cfg/XmlHbmBinding/ClassBinder.cs
trunk/nhibernate/src/NHibernate/NHibernate.csproj
trunk/nhibernate/src/NHibernate/nhibernate-mapping.xsd
trunk/nhibernate/src/NHibernate.Test/Join/Employee.cs
trunk/nhibernate/src/NHibernate.Test/Join/JoinTest.cs
trunk/nhibernate/src/NHibernate.Test/Join/Person.cs
trunk/nhibernate/src/NHibernate.Test/Join/Person.hbm.xml
trunk/nhibernate/src/NHibernate.Tool.HbmXsd/Program.cs
Modified: trunk/nhibernate/src/NHibernate/Cfg/MappingSchema/Hbm.generated.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/Cfg/MappingSchema/Hbm.generated.cs 2009-03-15 16:55:08 UTC (rev 4138)
+++ trunk/nhibernate/src/NHibernate/Cfg/MappingSchema/Hbm.generated.cs 2009-03-16 16:27:01 UTC (rev 4139)
@@ -3780,10 +3780,17 @@
/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute("any", typeof(HbmAny))]
+ [System.Xml.Serialization.XmlElementAttribute("array", typeof(HbmArray))]
+ [System.Xml.Serialization.XmlElementAttribute("bag", typeof(HbmBag))]
[System.Xml.Serialization.XmlElementAttribute("component", typeof(HbmComponent))]
[System.Xml.Serialization.XmlElementAttribute("dynamic-component", typeof(HbmDynamicComponent))]
+ [System.Xml.Serialization.XmlElementAttribute("idbag", typeof(HbmIdbag))]
+ [System.Xml.Serialization.XmlElementAttribute("list", typeof(HbmList))]
[System.Xml.Serialization.XmlElementAttribute("many-to-one", typeof(HbmManyToOne))]
+ [System.Xml.Serialization.XmlElementAttribute("map", typeof(HbmMap))]
+ [System.Xml.Serialization.XmlElementAttribute("primitive-array", typeof(HbmPrimitiveArray))]
[System.Xml.Serialization.XmlElementAttribute("property", typeof(HbmProperty))]
+ [System.Xml.Serialization.XmlElementAttribute("set", typeof(HbmSet))]
public object[] Items;
/// <remarks/>
Modified: trunk/nhibernate/src/NHibernate/Cfg/XmlHbmBinding/ClassBinder.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/Cfg/XmlHbmBinding/ClassBinder.cs 2009-03-15 16:55:08 UTC (rev 4138)
+++ trunk/nhibernate/src/NHibernate/Cfg/XmlHbmBinding/ClassBinder.cs 2009-03-16 16:27:01 UTC (rev 4139)
@@ -348,28 +348,40 @@
string propertyName = nameAttribute == null ? null : nameAttribute.Value;
IValue value = null;
- switch (name)
+ var collectionBinder = new CollectionBinder(this);
+ if (collectionBinder.CanCreate(name))
{
- case "many-to-one":
- value = new ManyToOne(table);
- BindManyToOne(subnode, (ManyToOne) value, propertyName, true);
- break;
- case "any":
- value = new Any(table);
- BindAny(subnode, (Any) value, true);
- break;
- case "property":
- value = new SimpleValue(table);
- BindSimpleValue(subnode, (SimpleValue) value, true, propertyName);
- break;
- case "component":
- case "dynamic-component":
- string subpath = StringHelper.Qualify(path, propertyName);
- value = new Component(join);
- BindComponent(subnode, (Component) value, join.PersistentClass.MappedClass, join.PersistentClass.ClassName, propertyName, subpath, true);
- break;
+ Mapping.Collection collection = collectionBinder.Create(name, subnode, persistentClass.EntityName,
+ propertyName, persistentClass, persistentClass.MappedClass);
+
+ mappings.AddCollection(collection);
+ value = collection;
}
-
+ else
+ {
+ switch (name)
+ {
+ case "many-to-one":
+ value = new ManyToOne(table);
+ BindManyToOne(subnode, (ManyToOne) value, propertyName, true);
+ break;
+ case "any":
+ value = new Any(table);
+ BindAny(subnode, (Any) value, true);
+ break;
+ case "property":
+ value = new SimpleValue(table);
+ BindSimpleValue(subnode, (SimpleValue) value, true, propertyName);
+ break;
+ case "component":
+ case "dynamic-component":
+ string subpath = StringHelper.Qualify(path, propertyName);
+ value = new Component(join);
+ BindComponent(subnode, (Component) value, join.PersistentClass.MappedClass, join.PersistentClass.ClassName,
+ propertyName, subpath, true);
+ break;
+ }
+ }
if (value != null)
{
Mapping.Property prop = CreateProperty(value, propertyName, persistentClass.MappedClass.AssemblyQualifiedName, subnode);
Modified: trunk/nhibernate/src/NHibernate/NHibernate.csproj
===================================================================
--- trunk/nhibernate/src/NHibernate/NHibernate.csproj 2009-03-15 16:55:08 UTC (rev 4138)
+++ trunk/nhibernate/src/NHibernate/NHibernate.csproj 2009-03-16 16:27:01 UTC (rev 4139)
@@ -1149,16 +1149,10 @@
<SubType>
</SubType>
</EmbeddedResource>
- <None Include="nhibernate-configuration.xsx">
- <DependentUpon>nhibernate-configuration.xsd</DependentUpon>
- </None>
<EmbeddedResource Include="nhibernate-mapping.xsd">
<SubType>
</SubType>
</EmbeddedResource>
- <None Include="nhibernate-mapping.xsx">
- <DependentUpon>nhibernate-mapping.xsd</DependentUpon>
- </None>
<None Include="NHibernate.build" />
<None Include="Type\IType.cs.xmldoc" />
</ItemGroup>
Modified: trunk/nhibernate/src/NHibernate/nhibernate-mapping.xsd
===================================================================
--- trunk/nhibernate/src/NHibernate/nhibernate-mapping.xsd 2009-03-15 16:55:08 UTC (rev 4138)
+++ trunk/nhibernate/src/NHibernate/nhibernate-mapping.xsd 2009-03-16 16:27:01 UTC (rev 4139)
@@ -616,6 +616,13 @@
<xs:element ref="component" />
<xs:element ref="dynamic-component" />
<xs:element ref="any" />
+ <xs:element ref="map" />
+ <xs:element ref="set" />
+ <xs:element ref="list" />
+ <xs:element ref="bag" />
+ <xs:element ref="idbag" />
+ <xs:element ref="array" />
+ <xs:element ref="primitive-array" />
</xs:choice>
<xs:element ref="sql-insert" minOccurs="0" />
<xs:element ref="sql-update" minOccurs="0" />
Modified: trunk/nhibernate/src/NHibernate.Test/Join/Employee.cs
===================================================================
--- trunk/nhibernate/src/NHibernate.Test/Join/Employee.cs 2009-03-15 16:55:08 UTC (rev 4138)
+++ trunk/nhibernate/src/NHibernate.Test/Join/Employee.cs 2009-03-16 16:27:01 UTC (rev 4139)
@@ -1,9 +1,14 @@
using System;
+using System.Collections.Generic;
namespace NHibernate.Test.Join
{
public class Employee : Person
{
+ public Employee()
+ {
+ Meetings = new List<Meeting>();
+ }
private string _Title;
public virtual string Title
{
@@ -25,5 +30,13 @@
set { _Salary = value; }
}
+ public virtual IList<Meeting> Meetings { get; set; }
}
+
+ public class Meeting
+ {
+ public virtual int Id { get; set; }
+ public virtual Employee Employee { get; set; }
+ public virtual string Description { get; set; }
+ }
}
Modified: trunk/nhibernate/src/NHibernate.Test/Join/JoinTest.cs
===================================================================
--- trunk/nhibernate/src/NHibernate.Test/Join/JoinTest.cs 2009-03-15 16:55:08 UTC (rev 4138)
+++ trunk/nhibernate/src/NHibernate.Test/Join/JoinTest.cs 2009-03-16 16:27:01 UTC (rev 4139)
@@ -1,3 +1,4 @@
+using Iesi.Collections.Generic;
using log4net;
using NHibernate.Criterion;
using NUnit.Framework;
@@ -154,7 +155,7 @@
Person p = CreatePerson("A guy");
p.HomePhone = null;
p.BusinessPhone = null;
-
+ p.OthersPhones = null;
s.Save(p);
s.Flush();
s.Clear();
@@ -295,7 +296,7 @@
p.Country = "Canada";
p.HomePhone = "555-1234";
p.BusinessPhone = "555-4321";
-
+ p.OthersPhones = new HashedSet<string> {"555-9876", "555-6789"};
return p;
}
@@ -308,7 +309,10 @@
if (!string.Equals(x.Country, y.Country)) return false;
if (!string.Equals(x.HomePhone, y.HomePhone)) return false;
if (!string.Equals(x.BusinessPhone, y.BusinessPhone)) return false;
-
+ if(x.OthersPhones.Count != y.OthersPhones.Count)
+ {
+ return false;
+ }
return true;
}
@@ -399,7 +403,8 @@
p.Title = title;
p.Salary = 100;
-
+ p.Meetings.Add(new Meeting {Employee = p, Description = "salary definition"});
+ p.Meetings.Add(new Meeting { Employee = p, Description = "targets definition" });
return p;
}
@@ -475,7 +480,7 @@
if (!PersonsAreEqual(x, y)) return false;
if (!string.Equals(x.Title, y.Title)) return false;
if (x.Salary != y.Salary) return false;
-
+ if (x.Meetings.Count != y.Meetings.Count) return false;
if (x.Manager != null && y.Manager != null)
{
return x.Manager.Id == y.Manager.Id;
@@ -509,6 +514,9 @@
emp0.Salary = 20000;
emp0.Title = "Title";
emp0.Zip = "Zip";
+ NHibernateUtil.Initialize(emp0.Meetings);
+ NHibernateUtil.Initialize(emp0.OthersPhones);
+ emp0.Meetings.Add(new Meeting { Employee = emp0, Description = "vacation def" });
// Not updating emp0.Sex because it is marked update=false in the mapping file.
s.Flush();
Modified: trunk/nhibernate/src/NHibernate.Test/Join/Person.cs
===================================================================
--- trunk/nhibernate/src/NHibernate.Test/Join/Person.cs 2009-03-15 16:55:08 UTC (rev 4138)
+++ trunk/nhibernate/src/NHibernate.Test/Join/Person.cs 2009-03-16 16:27:01 UTC (rev 4139)
@@ -1,9 +1,14 @@
using System;
+using Iesi.Collections.Generic;
namespace NHibernate.Test.Join
{
public class Person
{
+ public Person()
+ {
+ OthersPhones = new HashedSet<string>();
+ }
private char _Sex;
public virtual char Sex
{
@@ -67,5 +72,6 @@
set { _StuffName = value; }
}
+ public virtual ISet<string> OthersPhones { get; set; }
}
}
\ No newline at end of file
Modified: trunk/nhibernate/src/NHibernate.Test/Join/Person.hbm.xml
===================================================================
--- trunk/nhibernate/src/NHibernate.Test/Join/Person.hbm.xml 2009-03-15 16:55:08 UTC (rev 4138)
+++ trunk/nhibernate/src/NHibernate.Test/Join/Person.hbm.xml 2009-03-16 16:27:01 UTC (rev 4139)
@@ -27,6 +27,10 @@
<key column="phone_id"/>
<property name="HomePhone"/>
<property name="BusinessPhone"/>
+ <set name="OthersPhones" cascade="all" access="property">
+ <key column="phone_id"/>
+ <element column="phone" type="string" length="20"/>
+ </set>
</join>
<join table="inversed_stuff" inverse="true">
@@ -40,6 +44,10 @@
<property name="Title" not-null="true" length="20"/>
<property name="Salary"/>
<many-to-one name="Manager"/>
+ <bag name="Meetings" cascade="all" inverse="true" access="property">
+ <key column="person_id" on-delete="cascade"/>
+ <one-to-many class="Meeting"/>
+ </bag>
</join>
</subclass>
@@ -62,5 +70,12 @@
</join>
</subclass>
</class>
-
+
+ <class name="Meeting">
+ <id name="Id" access="property">
+ <generator class="native"/>
+ </id>
+ <many-to-one name="Employee" column="person_id" access="property"/>
+ <property name="Description" length="100" access="property"/>
+ </class>
</hibernate-mapping>
\ No newline at end of file
Modified: trunk/nhibernate/src/NHibernate.Tool.HbmXsd/Program.cs
===================================================================
--- trunk/nhibernate/src/NHibernate.Tool.HbmXsd/Program.cs 2009-03-15 16:55:08 UTC (rev 4138)
+++ trunk/nhibernate/src/NHibernate.Tool.HbmXsd/Program.cs 2009-03-16 16:27:01 UTC (rev 4139)
@@ -1,17 +1,11 @@
-using System;
-
namespace NHibernate.Tool.HbmXsd
{
public class Program
{
private static void Main(string[] args)
{
- // For debugging: ..\..\..\NHibernate\Cfg\MappingSchema\Hbm.generated.cs
-
- if (args.Length == 1)
- new HbmCodeGenerator().Execute(args[0]);
- else
- Console.WriteLine("usage: HbmXsd <outputfile>");
+ string outFile = args.Length == 0 ? @"..\..\..\NHibernate\Cfg\MappingSchema\Hbm.generated.cs" : args[0];
+ new HbmCodeGenerator().Execute(outFile);
}
}
}
\ No newline at end of file
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|