From: Peter S. <sz...@us...> - 2004-04-29 14:43:30
|
Update of /cvsroot/nhibernate/nhibernate/src/NHibernate/Cfg In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv7736/NHibernate/Cfg Modified Files: Binder.cs Log Message: Sweeping around, fixing small bugs Index: Binder.cs =================================================================== RCS file: /cvsroot/nhibernate/nhibernate/src/NHibernate/Cfg/Binder.cs,v retrieving revision 1.17 retrieving revision 1.18 diff -C2 -d -r1.17 -r1.18 *** Binder.cs 29 Apr 2004 14:00:52 -0000 1.17 --- Binder.cs 29 Apr 2004 14:43:14 -0000 1.18 *************** *** 18,30 **** internal static Dialect.Dialect dialect; ! public static void BindClass(XmlNode node, PersistentClass model, Mappings mapping) { string className = node.Attributes["name"] == null ? null : node.Attributes["name"].Value; // class ! try { model.PersistentClazz = ReflectHelper.ClassForName(className); } ! catch ( Exception cnfe ) { throw new MappingException( "persistent class not found", cnfe); } --- 18,33 ---- internal static Dialect.Dialect dialect; ! public static void BindClass(XmlNode node, PersistentClass model, Mappings mapping) ! { string className = node.Attributes["name"] == null ? null : node.Attributes["name"].Value; // class ! try ! { model.PersistentClazz = ReflectHelper.ClassForName(className); } ! catch ( Exception cnfe ) ! { throw new MappingException( "persistent class not found", cnfe); } *************** *** 32,40 **** //proxy interface XmlAttribute proxyNode = node.Attributes["proxy"]; ! if (proxyNode!=null) { ! try { model.ProxyInterface = ReflectHelper.ClassForName( proxyNode.Value ); } ! catch (Exception cnfe) { throw new MappingException(cnfe); } --- 35,46 ---- //proxy interface XmlAttribute proxyNode = node.Attributes["proxy"]; ! if (proxyNode!=null) ! { ! try ! { model.ProxyInterface = ReflectHelper.ClassForName( proxyNode.Value ); } ! catch (Exception cnfe) ! { throw new MappingException(cnfe); } *************** *** 53,67 **** "true".Equals( dynamicNode.Value ); //import ! if (mapping.IsAutoImport) { mapping.AddImport( StringHelper.GetFullClassname(className), StringHelper.GetClassname(className) ); } } ! public static void BindSubclass(XmlNode node, Subclass model, Mappings mappings) { BindClass(node, model, mappings); ! if ( model.Persister==null ) { model.RootClazz.Persister = typeof(EntityPersister); } --- 59,82 ---- "true".Equals( dynamicNode.Value ); + //dynamic insert + XmlAttribute insertNode = node.Attributes["dynamic-insert"]; + model.DynamicInsert = (insertNode==null) ? + false : + "true".Equals( insertNode.Value ); + //import ! if (mapping.IsAutoImport) ! { mapping.AddImport( StringHelper.GetFullClassname(className), StringHelper.GetClassname(className) ); } } ! public static void BindSubclass(XmlNode node, Subclass model, Mappings mappings) ! { BindClass(node, model, mappings); ! if ( model.Persister==null ) ! { model.RootClazz.Persister = typeof(EntityPersister); } *************** *** 75,84 **** } ! public static void BindJoinedSubclass(XmlNode node, Subclass model, Mappings mappings) { BindClass(node, model, mappings); // joined subclass ! if ( model.Persister==null ) { model.RootClazz.Persister = typeof(NormalizedEntityPersister); } --- 90,101 ---- } ! public static void BindJoinedSubclass(XmlNode node, Subclass model, Mappings mappings) ! { BindClass(node, model, mappings); // joined subclass ! if ( model.Persister==null ) ! { model.RootClazz.Persister = typeof(NormalizedEntityPersister); } *************** *** 87,91 **** XmlAttribute tableNameNode = node.Attributes["table"]; string tableName = (tableNameNode==null) ! ? model.PersistentClazz.Name : tableNameNode.Value; --- 104,108 ---- XmlAttribute tableNameNode = node.Attributes["table"]; string tableName = (tableNameNode==null) ! ? StringHelper.Unqualify( model.PersistentClazz.Name ) : tableNameNode.Value; *************** *** 108,115 **** fk.ReferencedClass = model.Superclass.PersistentClazz; PropertiesFromXML(node, model, mappings); } ! public static void BindRootClass(XmlNode node, RootClass model, Mappings mappings) { BindClass(node, model, mappings); --- 125,134 ---- fk.ReferencedClass = model.Superclass.PersistentClazz; + // properties PropertiesFromXML(node, model, mappings); } ! public static void BindRootClass(XmlNode node, RootClass model, Mappings mappings) ! { BindClass(node, model, mappings); *************** *** 118,122 **** XmlAttribute tableNameNode = node.Attributes["table"]; string tableName = (tableNameNode==null) ! ? model.PersistentClazz.Name : tableNameNode.Value; --- 137,141 ---- XmlAttribute tableNameNode = node.Attributes["table"]; string tableName = (tableNameNode==null) ! ? StringHelper.Unqualify( model.PersistentClazz.Name ) : tableNameNode.Value; *************** *** 130,141 **** //persister XmlAttribute persisterNode = node.Attributes["persister"]; ! if ( persisterNode==null ) { //persister = typeof(EntityPersister); } ! else { ! try { model.Persister = ReflectHelper.ClassForName( persisterNode.Value ); } ! catch (Exception) { throw new MappingException("could not find persister class: " + persisterNode.Value ); } --- 149,164 ---- //persister XmlAttribute persisterNode = node.Attributes["persister"]; ! if ( persisterNode==null ) ! { //persister = typeof(EntityPersister); } ! else ! { ! try ! { model.Persister = ReflectHelper.ClassForName( persisterNode.Value ); } ! catch (Exception) ! { throw new MappingException("could not find persister class: " + persisterNode.Value ); } *************** *** 146,154 **** model.IsMutable = (mutableNode==null) || mutableNode.Value.Equals("true"); //POLYMORPHISM XmlAttribute polyNode = node.Attributes["polymorphism"]; model.IsExplicitPolymorphism = (polyNode!=null) && polyNode.Value.Equals("explicit"); ! foreach(XmlNode subnode in node.ChildNodes) { string name = subnode.LocalName; //Name; string propertyName = GetPropertyName(subnode); --- 169,182 ---- model.IsMutable = (mutableNode==null) || mutableNode.Value.Equals("true"); + //WHERE + XmlAttribute whereNode = node.Attributes["where"]; + if (whereNode!=null) model.Where = whereNode.Value; + //POLYMORPHISM XmlAttribute polyNode = node.Attributes["polymorphism"]; model.IsExplicitPolymorphism = (polyNode!=null) && polyNode.Value.Equals("explicit"); ! foreach(XmlNode subnode in node.ChildNodes) ! { string name = subnode.LocalName; //Name; string propertyName = GetPropertyName(subnode); *************** *** 157,171 **** if(subnode.NamespaceURI!=Configuration.MappingSchemaXMLNS) continue; ! switch( name ) { case "id": Value id = new Value(table); model.Identifier = id; ! if ( propertyName==null) { BindValue(subnode, id, false, RootClass.DefaultIdentifierColumnName); if ( id.Type==null ) throw new MappingException("must specify an identifier type: " + model.PersistentClazz.Name ); model.IdentifierProperty = null; } ! else { BindValue(subnode, id, false, propertyName); id.SetTypeByReflection( model.PersistentClazz, propertyName); --- 185,202 ---- if(subnode.NamespaceURI!=Configuration.MappingSchemaXMLNS) continue; ! switch( name ) ! { case "id": Value id = new Value(table); model.Identifier = id; ! if ( propertyName==null) ! { BindValue(subnode, id, false, RootClass.DefaultIdentifierColumnName); if ( id.Type==null ) throw new MappingException("must specify an identifier type: " + model.PersistentClazz.Name ); model.IdentifierProperty = null; } ! else ! { BindValue(subnode, id, false, propertyName); id.SetTypeByReflection( model.PersistentClazz, propertyName); *************** *** 184,192 **** Component compId = new Component(model); model.Identifier = compId; ! if (propertyName==null) { BindComponent(subnode, compId, null, model.Name + ".id", false, mappings); model.HasEmbeddedIdentifier = compId.IsEmbedded; model.IdentifierProperty = null; ! } else { System.Type reflectedClass = ReflectHelper.GetGetter( model.PersistentClazz, propertyName ).ReturnType; BindComponent(subnode, compId, reflectedClass, model.Name + StringHelper.Dot + propertyName, false, mappings); --- 215,226 ---- Component compId = new Component(model); model.Identifier = compId; ! if (propertyName==null) ! { BindComponent(subnode, compId, null, model.Name + ".id", false, mappings); model.HasEmbeddedIdentifier = compId.IsEmbedded; model.IdentifierProperty = null; ! } ! else ! { System.Type reflectedClass = ReflectHelper.GetGetter( model.PersistentClazz, propertyName ).ReturnType; BindComponent(subnode, compId, reflectedClass, model.Name + StringHelper.Dot + propertyName, false, mappings); *************** *** 197,200 **** --- 231,235 ---- MakeIdentifier(subnode, compId, mappings); break; + case "version": case "timestamp": *************** *** 208,222 **** model.AddProperty(timestampProp); break; case "discriminator": Value discrim = new Value(table); model.Discriminator = discrim; BindValue(subnode, discrim, false, RootClass.DefaultDiscriminatorColumnName); ! if ( discrim.Type==null ) { discrim.Type = NHibernate.String; ! foreach(Column col in discrim.ColumnCollection) { col.Type = NHibernate.String; } } ! if ( subnode.Attributes["force"] != null && "true".Equals( subnode.Attributes["force"].Value ) ) { model.IsForceDiscriminator = true; } --- 243,262 ---- model.AddProperty(timestampProp); break; + case "discriminator": Value discrim = new Value(table); model.Discriminator = discrim; BindValue(subnode, discrim, false, RootClass.DefaultDiscriminatorColumnName); ! if ( discrim.Type==null ) ! { discrim.Type = NHibernate.String; ! foreach(Column col in discrim.ColumnCollection) ! { col.Type = NHibernate.String; } } ! model.Polymorphic = true; ! if ( subnode.Attributes["force"] != null && "true".Equals( subnode.Attributes["force"].Value ) ) ! { model.IsForceDiscriminator = true; } *************** *** 230,240 **** } ! public static void BindColumns(XmlNode node, Value model, bool isNullable, bool autoColumn, string defaultColumnName) { //COLUMN(S) XmlAttribute columnNode = node.Attributes["column"]; ! if ( columnNode==null ) { int count=0; ! //foreach(XmlNode subnode in node.SelectNodes("column")) { ! foreach(XmlNode subnode in node.SelectNodes(nsPrefix + ":column", nsmgr)) { Table table = model.Table; Column col = new Column( model.Type, count++ ); --- 270,282 ---- } ! public static void BindColumns(XmlNode node, Value model, bool isNullable, bool autoColumn, string defaultColumnName) ! { //COLUMN(S) XmlAttribute columnNode = node.Attributes["column"]; ! if ( columnNode==null ) ! { int count=0; ! foreach(XmlNode subnode in node.SelectNodes(nsPrefix + ":column", nsmgr)) ! { Table table = model.Table; Column col = new Column( model.Type, count++ ); *************** *** 245,267 **** //column index XmlAttribute indexNode = subnode.Attributes["index"]; ! if ( indexNode!=null && table!=null ) { table.GetIndex( indexNode.Value ).AddColumn(col); } XmlAttribute uniqueNode = subnode.Attributes["unique-key"]; ! if ( uniqueNode!=null && table!=null ) { table.GetUniqueKey( uniqueNode.Value ).AddColumn(col); } } } ! else { Column col = new Column( model.Type, 0 ); BindColumn(node, col, isNullable); col.Name = columnNode.Value; Table table = model.Table; ! if (table!=null) table.AddColumn(col); model.AddColumn(col); } ! if ( autoColumn && model.ColumnSpan==0 ) { Column col = new Column( model.Type, 0 ); BindColumn(node, col, isNullable); --- 287,315 ---- //column index XmlAttribute indexNode = subnode.Attributes["index"]; ! if ( indexNode!=null && table!=null ) ! { ! //TODO: what do you do about associations?? (second pass compile) table.GetIndex( indexNode.Value ).AddColumn(col); } XmlAttribute uniqueNode = subnode.Attributes["unique-key"]; ! if ( uniqueNode!=null && table!=null ) ! { ! //TODO: what do you do about associations?? (second pass compile) table.GetUniqueKey( uniqueNode.Value ).AddColumn(col); } } } ! else ! { Column col = new Column( model.Type, 0 ); BindColumn(node, col, isNullable); col.Name = columnNode.Value; Table table = model.Table; ! if (table!=null) table.AddColumn(col); //table=null -> an association - fill it in later model.AddColumn(col); } ! if ( autoColumn && model.ColumnSpan==0 ) ! { Column col = new Column( model.Type, 0 ); BindColumn(node, col, isNullable); *************** *** 272,276 **** } ! public static void BindValue(XmlNode node, Value model, bool isNullable) { //TYPE model.Type = GetTypeFromXML(node); --- 320,328 ---- } ! /// <remarks> ! /// Does _not_ automatically make a column if none is specifed by XML ! /// </remarks> ! public static void BindValue(XmlNode node, Value model, bool isNullable) ! { //TYPE model.Type = GetTypeFromXML(node); *************** *** 278,284 **** } ! public static void BindValue(XmlNode node, Value model, bool isNullable, string defaultColumnName) { model.Type = GetTypeFromXML(node); ! BindColumns(node, model, isNullable, true, defaultColumnName); } --- 330,350 ---- } ! /// <remarks> ! /// automatically makes a column with the default name if none is specifed by XML ! /// </remarks> ! public static void BindValue(XmlNode node, Value model, bool isNullable, string defaultColumnName) ! { model.Type = GetTypeFromXML(node); ! XmlAttribute formulaNode = node.Attributes["formula"]; ! if (formulaNode != null) ! { ! Formula f = new Formula(); ! f.FormulaString = formulaNode.InnerText; ! model.Formula = f; ! } ! else ! { ! BindColumns(node, model, isNullable, true, defaultColumnName); ! } } |