Example #1
0
        protected internal void GetFkProperties()
        {
            var mtoPropNodes =
                _hbmXml.SelectNodes(
                    CreateXpath(HbmXmlNames.HIBERNATE_MAPPING, HbmXmlNames.CLASS, HbmXmlNames.MANY_TO_ONE), _nsMgr);

            if (mtoPropNodes == null)
            {
                return;
            }
            foreach (var mto in mtoPropNodes.Cast <XmlElement>().Where(t => t != null && t.HasAttributes))
            {
                if (mto.Attributes[HbmXmlNames.NAME] == null ||
                    string.IsNullOrWhiteSpace(mto.Attributes[HbmXmlNames.NAME].Value))
                {
                    continue;
                }
                if (mto.Attributes[HbmXmlNames.CLASS] == null ||
                    string.IsNullOrWhiteSpace(mto.Attributes[HbmXmlNames.CLASS].Value))
                {
                    continue;
                }

                var fkName = mto.Attributes[HbmXmlNames.NAME].Value;

                _fkProperties.Add(fkName, mto.Attributes[HbmXmlNames.CLASS].Value);

                if (!mto.HasChildNodes)
                {
                    continue;
                }

                var mtoColumns = new List <ColumnMetadata>();
                var columnNode = mto.FirstChild;
                while (columnNode != null)
                {
                    if (!columnNode.HasChildNodes)
                    {
                        columnNode = columnNode.NextSibling;
                        continue;
                    }

                    var            columnJson = columnNode.FirstChild.InnerText;
                    ColumnMetadata dataOut;
                    if (!ColumnMetadata.TryParseJson(columnJson, out dataOut))
                    {
                        columnNode = columnNode.NextSibling;
                        continue;
                    }
                    mtoColumns.Add(dataOut);

                    columnNode = columnNode.NextSibling;
                }

                AddToFkColumns(fkName, mtoColumns);
            }
        }
Example #2
0
        protected internal void GetListProperties()
        {
            var bagPropNodes = _hbmXml.SelectNodes(CreateXpath(HbmXmlNames.HIBERNATE_MAPPING, HbmXmlNames.CLASS, HbmXmlNames.BAG), _nsMgr);

            if (bagPropNodes == null)
            {
                return;
            }
            foreach (var bag in bagPropNodes.Cast <XmlElement>().Where(t => t != null && t.HasAttributes))
            {
                if (bag.Attributes[HbmXmlNames.NAME] == null || string.IsNullOrWhiteSpace(bag.Attributes[HbmXmlNames.NAME].Value) || !bag.HasChildNodes)
                {
                    continue;
                }
                var otmNode = bag.ChildNodes.Cast <XmlElement>().First(x => x.Name.Contains(HbmXmlNames.ONE_TO_MANY));
                if (otmNode == null || !otmNode.HasAttributes || otmNode.Attributes[HbmXmlNames.CLASS] == null)
                {
                    continue;
                }

                var bagPropertyName = bag.Attributes[HbmXmlNames.NAME].Value;

                AddToListProperties(bagPropertyName, otmNode.Attributes[HbmXmlNames.CLASS].Value);

                var bagKeyNode = bag.ChildNodes.Cast <XmlElement>().FirstOrDefault(x => x.Name == HbmXmlNames.KEY);
                if (bagKeyNode == null)
                {
                    return;
                }

                var bagKeyColumns = new List <ColumnMetadata>();
                var columnNode    = bagKeyNode.FirstChild;
                while (columnNode != null)
                {
                    if (!columnNode.HasChildNodes)
                    {
                        columnNode = columnNode.NextSibling;
                        continue;
                    }

                    var            columnJson = columnNode.FirstChild.InnerText;
                    ColumnMetadata dataOut;
                    if (!ColumnMetadata.TryParseJson(columnJson, out dataOut))
                    {
                        columnNode = columnNode.NextSibling;
                        continue;
                    }
                    bagKeyColumns.Add(dataOut);

                    columnNode = columnNode.NextSibling;
                }
                AddToListColumns(bagPropertyName, bagKeyColumns);
            }
        }
Example #3
0
        protected internal void GetFlatProperties()
        {
            var flatPropNodes = _hbmXml.SelectNodes(CreateXpath(HbmXmlNames.HIBERNATE_MAPPING, HbmXmlNames.CLASS, HbmXmlNames.PROPERTY), _nsMgr);

            if (flatPropNodes == null)
            {
                return;
            }
            foreach (var fp in flatPropNodes.Cast <XmlElement>().Where(t => t != null && t.HasAttributes))
            {
                if (fp.Attributes[HbmXmlNames.NAME] == null || string.IsNullOrWhiteSpace(fp.Attributes[HbmXmlNames.NAME].Value))
                {
                    continue;
                }
                var flatPropKey      = fp.Attributes[HbmXmlNames.NAME].Value;
                var csIsNullableChar = "?";

                var csTypeName = Lexicon.Hbm2NetTypes[(fp.Attributes[HbmXmlNames.TYPE].Value)] ?? string.Empty;

                if (fp.Attributes[HbmXmlNames.NOT_NULL] != null &&
                    string.Equals(fp.Attributes[HbmXmlNames.NOT_NULL].Value, bool.TrueString,
                                  StringComparison.OrdinalIgnoreCase))
                {
                    csIsNullableChar = string.Empty;
                }
                if (csTypeName == "string" || csTypeName == "System.String" || csTypeName.StartsWith("NoFuture"))
                {
                    csIsNullableChar = string.Empty;
                }

                AddToSimpleProperties(flatPropKey, string.Format("{0}{1}", csTypeName, csIsNullableChar));

                //add the comment data
                if (!fp.HasChildNodes || !fp.FirstChild.HasChildNodes)
                {
                    continue;
                }
                var            columnNode = fp.FirstChild;
                var            columnJson = columnNode.FirstChild.InnerText;
                ColumnMetadata dataOut;
                if (ColumnMetadata.TryParseJson(columnJson, out dataOut))
                {
                    AddToSimpleColumns(flatPropKey, dataOut);
                }
            }
        }
Example #4
0
        protected internal void GetIdName()
        {
            _idName = _idNode.Attributes[HbmXmlNames.NAME].Value;

            var idTypeAttr = _idNode.Attributes[HbmXmlNames.TYPE] ?? _idNode.Attributes[HbmXmlNames.CLASS];

            if (idTypeAttr == null)
            {
                throw new ItsDeadJim(
                          string.Format(
                              "Found the ID node but did not find either the attribute 'type' nor 'class' in hbm.xml file at '{0}'",
                              _fileNamePath));
            }

            _idType = idTypeAttr.Value;
            if (string.IsNullOrWhiteSpace(IdType))
            {
                throw new ItsDeadJim(
                          string.Format(
                              "Found the ID and an attribute (either 'type' or 'class') but its value is empty in hbm.xml file at '{0}'",
                              _fileNamePath));
            }

            if (IsCompositeKey)
            {
                _idType = NfReflect.IsFullAssemblyQualTypeName(IdType)
                    ? (new NfTypeName(IdType)).FullName
                    : IdType;
            }
            else
            {
                if (_idNode.HasChildNodes && _idNode.FirstChild.HasChildNodes)
                {
                    var            columnNode = _idNode.FirstChild;
                    var            columnJson = columnNode.FirstChild.InnerText;
                    ColumnMetadata dataOut;
                    if (ColumnMetadata.TryParseJson(columnJson, out dataOut))
                    {
                        AddToKeyColumns(IdName, dataOut);
                    }
                }
                _idType = Lexicon.Hbm2NetTypes[IdType];
            }
        }
Example #5
0
        protected internal void GetCompositeKeyProperties()
        {
            if (!IsCompositeKey)
            {
                return;
            }
            var kmtoProps =
                _hbmXml.SelectNodes(
                    CreateXpath(HbmXmlNames.HIBERNATE_MAPPING, HbmXmlNames.CLASS, HbmXmlNames.COMPOSITE_ID,
                                HbmXmlNames.KEY_MANY_TO_ONE), _nsMgr);
            var keyProps = _hbmXml.SelectNodes(
                CreateXpath(HbmXmlNames.HIBERNATE_MAPPING, HbmXmlNames.CLASS, HbmXmlNames.COMPOSITE_ID,
                            HbmXmlNames.KEY_PROPERTY), _nsMgr);

            if (kmtoProps != null)
            {
                foreach (
                    var kmto in
                    kmtoProps.Cast <XmlElement>()
                    .Where(
                        t =>
                        t != null && t.HasAttributes && t.Attributes[HbmXmlNames.NAME] != null &&
                        t.Attributes[HbmXmlNames.CLASS] != null))
                {
                    var kpName = kmto.Attributes[HbmXmlNames.NAME].Value;
                    var kpType = (new NfTypeName(kmto.Attributes[HbmXmlNames.CLASS].Value)).FullName;

                    //filter list used in GetAllTablesColumns
                    _keyManyToOnePropertyNames.Add(kpName);
                    AddToCompositeKeyProperties(kpName, kpType);

                    //add the comment data
                    if (!kmto.HasChildNodes)
                    {
                        continue;
                    }

                    var columnNode = kmto.FirstChild;
                    while (columnNode != null)
                    {
                        if (!columnNode.HasChildNodes)
                        {
                            columnNode = columnNode.NextSibling;
                            continue;
                        }

                        var pn =
                            Compose.PropertyName(
                                columnNode.Attributes[HbmXmlNames.NAME].Value.Replace("[", string.Empty)
                                .Replace("]", string.Empty));
                        var            columnJson = columnNode.FirstChild.InnerText;
                        ColumnMetadata dataOut;
                        if (!ColumnMetadata.TryParseJson(columnJson, out dataOut))
                        {
                            columnNode = columnNode.NextSibling;
                            continue;
                        }
                        AddToKeyColumns(pn, dataOut);

                        columnNode = columnNode.NextSibling;
                    }
                }
            }
            if (keyProps == null)
            {
                return;
            }
            foreach (
                var kp in
                keyProps.Cast <XmlElement>()
                .Where(
                    t =>
                    t != null && t.HasAttributes && t.Attributes[HbmXmlNames.NAME] != null &&
                    t.Attributes[HbmXmlNames.TYPE] != null))
            {
                var kpName = kp.Attributes[HbmXmlNames.NAME].Value;
                var kpType = Lexicon.Hbm2NetTypes[(kp.Attributes[HbmXmlNames.TYPE].Value)];
                AddToCompositeKeyProperties(kpName, kpType);
                if (!kp.HasChildNodes || !kp.FirstChild.HasChildNodes)
                {
                    continue;
                }
                var            columnNode = kp.FirstChild;
                var            columnJson = columnNode.FirstChild.InnerText;
                ColumnMetadata dataOut;
                if (ColumnMetadata.TryParseJson(columnJson, out dataOut))
                {
                    AddToKeyColumns(kpName, dataOut);
                }
            }
        }