From: Michael D. <mik...@us...> - 2004-12-10 16:40:14
|
Update of /cvsroot/nhibernate/nhibernate/src/NHibernate/Cfg In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv14749/NHibernate/Cfg Modified Files: Binder.cs Log Message: NH-131: Describe joined-subclasses and subclasses in seperate files. Also refactored the test a little bit. Going to being moving away from the NHibernate.DomainModel and just include everything in the TestFixture. Making the domain classes smaller and easier to demonstrate the conepts. Borrowed some of the ideas from hibernate 3 Index: Binder.cs =================================================================== RCS file: /cvsroot/nhibernate/nhibernate/src/NHibernate/Cfg/Binder.cs,v retrieving revision 1.33 retrieving revision 1.34 diff -C2 -d -r1.33 -r1.34 *** Binder.cs 29 Oct 2004 05:58:06 -0000 1.33 --- Binder.cs 10 Dec 2004 16:40:04 -0000 1.34 *************** *** 966,980 **** else if ( "subclass".Equals(name) ) { ! Subclass subclass = new Subclass(model); ! BindSubclass( subnode, subclass, mappings ); ! model.AddSubclass(subclass); ! mappings.AddClass(subclass); } else if ( "joined-subclass".Equals(name) ) { ! Subclass subclass = new Subclass(model); ! BindJoinedSubclass( subnode, subclass, mappings); ! model.AddSubclass(subclass); ! mappings.AddClass(subclass); } if ( value!=null) --- 966,974 ---- else if ( "subclass".Equals(name) ) { ! HandleSubclass( model, mappings, subnode ); } else if ( "joined-subclass".Equals(name) ) { ! HandleJoinedSubclass( model, mappings, subnode ); } if ( value!=null) *************** *** 1059,1063 **** } else if ( "index-many-to-any".Equals(name) ) ! { Any any = new Any( model.Table ); BindAny( subnode, any, model.IsOneToMany ); model.Index = any; } } if ( !model.IsInverse ) model.Index.CreateForeignKey(); --- 1053,1061 ---- } else if ( "index-many-to-any".Equals(name) ) ! { ! Any any = new Any( model.Table ); ! BindAny( subnode, any, model.IsOneToMany ); ! model.Index = any; ! } } if ( !model.IsInverse ) model.Index.CreateForeignKey(); *************** *** 1131,1135 **** } else if ( "many-to-any".Equals(name) ) ! { Any element = new Any( model.Table ); model.Element = element; BindAny(subnode, element, true); } else if ( "jcs-cache".Equals(name) ) { --- 1129,1137 ---- } else if ( "many-to-any".Equals(name) ) ! { ! Any element = new Any( model.Table ); ! model.Element = element; ! BindAny(subnode, element, true); ! } else if ( "jcs-cache".Equals(name) ) { *************** *** 1181,1184 **** --- 1183,1198 ---- } + foreach(XmlNode n in hmNode.SelectNodes(nsPrefix + ":subclass", nsmgr) ) + { + PersistentClass superModel = GetSuperclass(model, n); + HandleSubclass(superModel, model, n); + } + + foreach(XmlNode n in hmNode.SelectNodes(nsPrefix + ":joined-subclass", nsmgr) ) + { + PersistentClass superModel = GetSuperclass(model, n); + HandleJoinedSubclass(superModel, model, n); + } + foreach(XmlNode n in hmNode.SelectNodes(nsPrefix + ":query", nsmgr) ) { *************** *** 1209,1212 **** --- 1223,1266 ---- } + private static void HandleJoinedSubclass( PersistentClass model, Mappings mappings, XmlNode subnode ) + { + Subclass subclass = new Subclass( model ); + BindJoinedSubclass( subnode, subclass, mappings ); + model.AddSubclass( subclass ); + mappings.AddClass( subclass ); + } + + private static void HandleSubclass( PersistentClass model, Mappings mappings, XmlNode subnode ) + { + Subclass subclass = new Subclass( model ); + BindSubclass( subnode, subclass, mappings ); + model.AddSubclass( subclass ); + mappings.AddClass( subclass ); + } + + private static PersistentClass GetSuperclass( Mappings model, XmlNode subnode ) + { + XmlAttribute extendsAttr = subnode.Attributes["extends"]; + if( extendsAttr == null ) + throw new MappingException( "'extends' attribute is not found." ); + String extendsValue = extendsAttr.Value; + System.Type superclass; + try + { + superclass = ReflectHelper.ClassForName( extendsValue ); + } + catch( Exception e ) + { + throw new MappingException( "extended class not found: " + extendsValue, e ); + } + PersistentClass superModel = model.GetClass( superclass ); + + if( superModel == null ) + { + throw new MappingException( "Cannot extend unmapped class: " + extendsValue ); + } + return superModel; + } + public abstract class SecondPass { |