From: <fab...@us...> - 2008-10-10 21:36:37
|
Revision: 3836 http://nhibernate.svn.sourceforge.net/nhibernate/?rev=3836&view=rev Author: fabiomaulo Date: 2008-10-10 21:36:28 +0000 (Fri, 10 Oct 2008) Log Message: ----------- Some changes in binders (walking to xml entitymode) Modified Paths: -------------- trunk/nhibernate/src/NHibernate/Cfg/XmlHbmBinding/Binder.cs trunk/nhibernate/src/NHibernate/Cfg/XmlHbmBinding/ClassBinder.cs trunk/nhibernate/src/NHibernate/Cfg/XmlHbmBinding/CollectionBinder.cs trunk/nhibernate/src/NHibernate.Test/EntityModeTest/Xml/Basic/Account.hbm.xml trunk/nhibernate/src/NHibernate.Test/EntityModeTest/Xml/Basic/XmlFixture.cs Modified: trunk/nhibernate/src/NHibernate/Cfg/XmlHbmBinding/Binder.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Cfg/XmlHbmBinding/Binder.cs 2008-10-10 19:19:40 UTC (rev 3835) +++ trunk/nhibernate/src/NHibernate/Cfg/XmlHbmBinding/Binder.cs 2008-10-10 21:36:28 UTC (rev 3836) @@ -141,5 +141,11 @@ { return "false".Equals(xmlNodeValue) || "0".Equals(xmlNodeValue); } + + protected static string GetAttributeValue(XmlNode node, string attributeName) + { + XmlAttribute att = node.Attributes[attributeName]; + return att != null ? att.Value : null; + } } } \ No newline at end of file Modified: trunk/nhibernate/src/NHibernate/Cfg/XmlHbmBinding/ClassBinder.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Cfg/XmlHbmBinding/ClassBinder.cs 2008-10-10 19:19:40 UTC (rev 3835) +++ trunk/nhibernate/src/NHibernate/Cfg/XmlHbmBinding/ClassBinder.cs 2008-10-10 21:36:28 UTC (rev 3836) @@ -82,10 +82,11 @@ } else if ("component".Equals(name) || "dynamic-component".Equals(name)) { + string subpath = StringHelper.Qualify(entityName, propertyName); // NH: Modified from H2.1 to allow specifying the type explicitly using class attribute System.Type reflectedClass = GetPropertyType(subnode, model.MappedClass, propertyName); value = new Component(model); - BindComponent(subnode, (Component)value, reflectedClass, entityName, propertyName, true); + BindComponent(subnode, (Component)value, reflectedClass, entityName, propertyName, subpath, true); } else if ("join".Equals(name)) { @@ -124,7 +125,7 @@ if (value != null) { - Property property = CreateProperty(value, propertyName, model.MappedClass, subnode); + Property property = CreateProperty(value, propertyName, model.ClassName, subnode); if (!mutable) property.IsUpdateable = false; if (naturalId) @@ -362,19 +363,13 @@ case "dynamic-component": string subpath = StringHelper.Qualify(path, propertyName); value = new Component(join); - BindComponent( - subnode, - (Component) value, - join.PersistentClass.MappedClass, - propertyName, - subpath, - true); + 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, subnode); + Mapping.Property prop = CreateProperty(value, propertyName, persistentClass.MappedClass.AssemblyQualifiedName, subnode); prop.IsOptional = join.IsOptional; join.AddProperty(prop); } @@ -533,23 +528,27 @@ } protected void BindComponent(XmlNode node, Component model, System.Type reflectedClass, - string className, string path, bool isNullable) + string className, string parentProperty, string path, bool isNullable) { + bool isIdentifierMapper = false; + + model.RoleName = path; + XmlAttribute classNode = node.Attributes["class"]; - if ("dynamic-component".Equals(node.Name)) + if (classNode != null) { - model.IsEmbedded = false; - model.IsDynamic = true; - } - else if (classNode != null) - { model.ComponentClass = ClassForNameChecked( classNode.Value, mappings, "component class not found: {0}"); model.ComponentClassName = FullQualifiedClassName(classNode.Value, mappings); model.IsEmbedded = false; } + else if ("dynamic-component".Equals(node.Name)) + { + model.IsEmbedded = false; + model.IsDynamic = true; + } else if (reflectedClass != null) { model.ComponentClass = reflectedClass; @@ -562,6 +561,9 @@ model.IsEmbedded = true; } + string nodeName = (GetAttributeValue(node, "node") ?? GetAttributeValue(node, "name")) ?? model.Owner.NodeName; + model.NodeName = nodeName; + foreach (XmlNode subnode in node.ChildNodes) { //I am only concerned with elements that are from the nhibernate namespace @@ -612,22 +614,35 @@ : GetPropertyType(subnode, model.ComponentClass, propertyName); value = new Component(model); - BindComponent(subnode, (Component) value, subreflectedClass, className, subpath, isNullable); + BindComponent(subnode, (Component) value, subreflectedClass, className, propertyName, subpath, isNullable); } else if ("parent".Equals(name)) model.ParentProperty = propertyName; if (value != null) - model.AddProperty(CreateProperty(value, propertyName, model.ComponentClass, subnode)); + { + Property property = CreateProperty(value, propertyName, model.ComponentClassName, subnode); + if (isIdentifierMapper) + { + property.IsInsertable = false; + property.IsUpdateable = false; + } + model.AddProperty(property); + } } } - protected Mapping.Property CreateProperty(IValue value, string propertyName, System.Type parentClass, + protected Property CreateProperty(IValue value, string propertyName, string className, XmlNode subnode) { - if (parentClass != null && value.IsSimpleValue) - value.SetTypeUsingReflection(parentClass.AssemblyQualifiedName, propertyName, PropertyAccess(subnode)); + if (string.IsNullOrEmpty(propertyName)) + { + throw new MappingException(subnode.LocalName + " mapping must defined a name attribute [" + className + "]"); + } + if (!string.IsNullOrEmpty(className) && value.IsSimpleValue) + value.SetTypeUsingReflection(className, propertyName, PropertyAccess(subnode)); + // This is done here 'cos we might only know the type here (ugly!) if (value is ToOne) { @@ -638,7 +653,7 @@ } value.CreateForeignKey(); - Mapping.Property prop = new Mapping.Property(); + Property prop = new Property(); prop.Value = value; BindProperty(subnode, prop); Modified: trunk/nhibernate/src/NHibernate/Cfg/XmlHbmBinding/CollectionBinder.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Cfg/XmlHbmBinding/CollectionBinder.cs 2008-10-10 19:19:40 UTC (rev 3835) +++ trunk/nhibernate/src/NHibernate/Cfg/XmlHbmBinding/CollectionBinder.cs 2008-10-10 21:36:28 UTC (rev 3836) @@ -529,7 +529,7 @@ else if ("composite-index".Equals(name) || "composite-map-key".Equals(name)) { Component component = new Component(model); - BindComponent(subnode, component, null, model.Role, "index", model.IsOneToMany); + BindComponent(subnode, component, null, null, null, model.Role + ".index", model.IsOneToMany); model.Index = component; } else if ("index-many-to-any".Equals(name)) @@ -618,7 +618,7 @@ { Component element = new Component(model); model.Element = element; - BindComponent(subnode, element, null, model.Role, "element", true); + BindComponent(subnode, element, null, null, null, model.Role+ ".element", true); } else if ("many-to-any".Equals(name)) { Modified: trunk/nhibernate/src/NHibernate.Test/EntityModeTest/Xml/Basic/Account.hbm.xml =================================================================== --- trunk/nhibernate/src/NHibernate.Test/EntityModeTest/Xml/Basic/Account.hbm.xml 2008-10-10 19:19:40 UTC (rev 3835) +++ trunk/nhibernate/src/NHibernate.Test/EntityModeTest/Xml/Basic/Account.hbm.xml 2008-10-10 21:36:28 UTC (rev 3836) @@ -34,7 +34,7 @@ <id name="accountId" type="string" node="@id"/> <many-to-one name="customer" column="customerId" entity-name="Customer" cascade="all" embed-xml="true" /> <!--not-null="true"--> - <property name="balance" type="big_decimal" node="balance" precision="10" scale="0" /> + <property name="balance" type="big_decimal" node="balance" precision="10" scale="2" /> </class> <class entity-name="Location" node="location"> Modified: trunk/nhibernate/src/NHibernate.Test/EntityModeTest/Xml/Basic/XmlFixture.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Test/EntityModeTest/Xml/Basic/XmlFixture.cs 2008-10-10 19:19:40 UTC (rev 3835) +++ trunk/nhibernate/src/NHibernate.Test/EntityModeTest/Xml/Basic/XmlFixture.cs 2008-10-10 21:36:28 UTC (rev 3836) @@ -43,8 +43,10 @@ <b bId='1' aId='1>foo foo</b> <b bId='2' aId='1>bar bar</b> </a>"; + var baseXml = new XmlDocument(); + baseXml.LoadXml(xml); - XmlElement a=null; + XmlElement a = baseXml.DocumentElement; ISession s = OpenSession(); ITransaction t = s.BeginTransaction(); s.Persist("A", a); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |