示例#1
0
        public static string HbmFileNameFromAsmQualTypeName(string asmFullName, bool prependDir = false)
        {
            if (string.IsNullOrWhiteSpace(asmFullName) || !NfReflect.IsFullAssemblyQualTypeName(asmFullName))
            {
                return(HbmFileName(asmFullName));
            }

            var nfName = new NfTypeName(asmFullName);

            var tbl  = nfName.Namespace.Replace($"{nfName.AssemblySimpleName}.", string.Empty) + "." + nfName.ClassName;
            var flNm = HbmFileName(tbl);

            return(prependDir ? Path.Combine(Settings.HbmDirectory, flNm) : flNm);
        }
示例#2
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];
            }
        }
示例#3
0
        /// <summary>
        /// Parses a hbm.xml file into this runtime equiv.
        /// being intended for code generation.
        /// </summary>
        /// <param name="hbmXmlFilePath"></param>
        public HbmFileContent(string hbmXmlFilePath)
        {
            _simpleProperties       = new Dictionary <string, string>();
            _fkProperties           = new Dictionary <string, string>();
            _listProperties         = new Dictionary <string, string>();
            _compositeKeyProperties = new Dictionary <string, string>();

            _keyColumns    = new Dictionary <string, ColumnMetadata>();
            _simpleColumns = new Dictionary <string, ColumnMetadata>();
            _fkColumns     = new Dictionary <string, List <ColumnMetadata> >();
            _listColumns   = new Dictionary <string, List <ColumnMetadata> >();

            _spConstNames = new List <HbmStoredProxNames>();
            _keyManyToOnePropertyNames = new List <string>();
            _allPkColumns = new Dictionary <string, string>();

            if (!File.Exists(hbmXmlFilePath))
            {
                throw new ItsDeadJim(string.Format("There isn't any xml file at '{0}'", hbmXmlFilePath));
            }

            _fileNamePath = hbmXmlFilePath;
            _hbmXml       = new XmlDocument();
            _hbmXml.LoadXml(File.ReadAllText(_fileNamePath));
            _nsMgr = new XmlNamespaceManager(_hbmXml.NameTable);
            _nsMgr.AddNamespace(NS, Globals.HBM_XML_NS);

            _classNode =
                _hbmXml.SelectSingleNode(CreateXpath(HbmXmlNames.HIBERNATE_MAPPING, HbmXmlNames.CLASS), _nsMgr) as
                XmlElement;
            if (_classNode == null)
            {
                throw new ItsDeadJim(string.Format("The top-level 'class' node is missing from the xml file at '{0}'", hbmXmlFilePath));
            }

            IsCompositeKey =
                _hbmXml.SelectSingleNode(CreateXpath(HbmXmlNames.HIBERNATE_MAPPING, HbmXmlNames.CLASS, HbmXmlNames.COMPOSITE_ID), _nsMgr) != null;

            var tableNameAttr = _classNode.Attributes[HbmXmlNames.TABLE];

            if (tableNameAttr != null)
            {
                _tableName = tableNameAttr.Value;
            }

            var attrTypeName = GetAttrVal(CreateXpath(HbmXmlNames.HIBERNATE_MAPPING, HbmXmlNames.CLASS), HbmXmlNames.NAME);

            if (NfReflect.IsFullAssemblyQualTypeName(attrTypeName))
            {
                _asmQualTypeName = attrTypeName;
                var nfName = new NfTypeName(attrTypeName);
                _className = nfName.ClassName;
                _namespace = nfName.Namespace;
            }
            else
            {
                _className       = NfReflect.GetTypeNameWithoutNamespace(attrTypeName);
                _namespace       = NfReflect.GetNamespaceWithoutTypeName(attrTypeName);
                _asmQualTypeName = Compose.ClassName(_className, _namespace);
            }

            _dbSchema = GetAttrVal(CreateXpath(HbmXmlNames.HIBERNATE_MAPPING, HbmXmlNames.CLASS), HbmXmlNames.SCHEMA);

            //the stored prox will not have a schema qualifier so try to derive it from the file name
            if (string.IsNullOrWhiteSpace(_dbSchema))
            {
                var ff = Path.GetFileName(_fileNamePath);
                if (!string.IsNullOrWhiteSpace(ff) && ff.Split('.').Length > 3)
                {
                    _dbSchema = ff.Split('.')[0];
                }
                else
                {
                    _dbSchema = "Dbo";
                }
            }

            //get id/composite-id node
            GetIdNode();

            //get id's name and type
            GetIdName();

            //get flat-data's names and types
            GetFlatProperties();

            //get FKs names and types
            GetFkProperties();

            //get IList names and types
            GetListProperties();

            //get stored proc names
            GetStoredProcNames();

            //get composite key's properties
            GetCompositeKeyProperties();

            //condense a list of what is just on this table
            GetAllPkColumns();
        }