Azavea.Open.DAO.ClassMapping.ParseNHibernateXML C# (CSharp) Method

ParseNHibernateXML() private method

private ParseNHibernateXML ( XmlNode hibConfNode, bool includeForeignKeys ) : void
hibConfNode System.Xml.XmlNode
includeForeignKeys bool
return void
        private void ParseNHibernateXML(XmlNode hibConfNode, bool includeForeignKeys)
        {
            TypeName = hibConfNode.Attributes["name"].Value;
            Table = hibConfNode.Attributes["table"].Value;
            foreach (XmlNode node in hibConfNode.ChildNodes)
            {
                try
                {
                    if ("id".Equals(node.Name))
                    {
                        string prop = node.Attributes["name"].Value;
                        string col = node.Attributes["column"].Value;
                        XmlAttribute typeAttr = node.Attributes["type"];
                        string type = typeAttr == null ? null : typeAttr.Value;
                        IdDataColsByObjAttrs[prop] = col;
                        AllDataColsByObjAttrs[prop] = col;
                        AllDataColsInOrder.Add(col);
                        AllObjAttrsByDataCol[col] = prop;
                        Type colType = ParseColumnType(type);
                        DataColTypesByObjAttr[prop] = colType;
                        DataColTypesByDataCol[col] = colType;

                        GeneratorType genType = GeneratorType.NONE;
                        // Check for generator type.
                        foreach (XmlNode idChild in node.ChildNodes)
                        {
                            if ("generator".Equals(idChild.Name))
                            {
                                // ok it is an autogenerated ID of some sort.
                                genType = GeneratorType.AUTO;

                                // See if there is a sequence.
                                foreach (XmlNode idGrandChild in idChild.ChildNodes)
                                {
                                    if ("param".Equals(idGrandChild.Name))
                                    {
                                        if ("sequence".Equals(idGrandChild.Attributes["name"].Value))
                                        {
                                            // We have to load it from a sequence.
                                            genType = GeneratorType.SEQUENCE;
                                            IdSequencesByDataCol[col] = idGrandChild.FirstChild.Value;
                                            // Only support one sequence def per ID.
                                            break;
                                        }
                                    }
                                }
                                // Only support one generator per id.
                                break;
                            }
                        }
                        // Save the generator type.
                        IdGeneratorsByDataCol[col] = genType;
                    }
                    else if ("property".Equals(node.Name) ||
                             ("many-to-one".Equals(node.Name) && includeForeignKeys) ||
                             ("one-to-one".Equals(node.Name) && includeForeignKeys))
                    {
                        string prop = node.Attributes.GetNamedItem("name").Value;
                        string col = node.Attributes.GetNamedItem("column").Value;
                        XmlAttribute typeAttr = node.Attributes["type"];
                        string type = typeAttr == null ? null : typeAttr.Value;
                        NonIdDataColsByObjAttrs[prop] = col;
                        AllDataColsByObjAttrs[prop] = col;
                        AllDataColsInOrder.Add(col);
                        Type colType = ParseColumnType(type);
                        DataColTypesByObjAttr[prop] = colType;
                        DataColTypesByDataCol[col] = colType;
                        AllObjAttrsByDataCol[col] = prop;
                    }
                    else if ("composite-id".Equals(node.Name))
                    {
                        // We support two ways of making composite ids.  The "easy" way
                        // and the "nhibernate" way.  The "easy" way is just put more than
                        // one "id" field in the mapping.  The "nhibernate" way is use
                        // this composite-id tag.
                        foreach (XmlNode compositeCol in node.ChildNodes)
                        {
                            if ("key-property".Equals(compositeCol.Name))
                            {
                                // This is one of the composite columns.
                                string prop = compositeCol.Attributes["name"].Value;
                                string col = compositeCol.Attributes["column"].Value;
                                XmlAttribute typeAttr = compositeCol.Attributes["type"];
                                string type = typeAttr == null ? null : typeAttr.Value;
                                IdDataColsByObjAttrs[prop] = col;
                                AllDataColsByObjAttrs[prop] = col;
                                AllDataColsInOrder.Add(col);
                                AllObjAttrsByDataCol[col] = prop;
                                Type colType = ParseColumnType(type);
                                DataColTypesByObjAttr[prop] = colType;
                                DataColTypesByDataCol[col] = colType;
                                // NHibernate doesn't support generators on composite keys.
                                IdGeneratorsByDataCol[col] = GeneratorType.NONE;
                            }
                        }
                    } // else ignore it.
                }
                catch (Exception e)
                {
                    throw new BadDaoConfigurationException("Error while parsing class map XML for type " +
                                                  TypeName + ", table " + Table + ": " + node.OuterXml, e);
                }
            }
        }