コード例 #1
0
ファイル: Program.cs プロジェクト: SlyNet/HbmToConform
        private static void ReadBagsMaps(XDocument xml, XNamespace ns, MappingModel model)
        {
            CollectionType collectionType = CollectionType.Bag;

            List <CollectionInfo> foundCollections = ReadCollections(xml.Root.Descendants(ns.GetName("class")).FirstOrDefault(), ns, collectionType);

            model.Collections.AddRange(foundCollections);
        }
コード例 #2
0
ファイル: Program.cs プロジェクト: SlyNet/HbmToConform
        private static void ReadDiscriminator(XElement classElement, XNamespace ns, MappingModel model)
        {
            var discriminator = classElement.Descendants(ns.GetName("discriminator")).FirstOrDefault();

            if (discriminator != null)
            {
                var discriminatorModel = new DiscriminatorModel();
                discriminatorModel.ColumnName = discriminator.Attribute("column")?.Value;

                model.Discriminator = discriminatorModel;
            }
        }
コード例 #3
0
ファイル: Program.cs プロジェクト: SlyNet/HbmToConform
        private static void ReadId(XElement classElement, XNamespace ns, MappingModel model)
        {
            var idElement = classElement.Element(ns.GetName("id"));
            var idInfo    = new IdInfo();

            idInfo.ColumnName = idElement.Attribute("column")?.Value;
            idInfo.Name       = idElement.Attribute("name").Value;

            var stringGenerator = idElement.Element(ns.GetName("generator"))?.Attribute("class")?.Value;

            switch (stringGenerator)
            {
            case "guid.comb":
                idInfo.Generator = "Generators.GuidComb";
                break;

            case "assigned":
                idInfo.Generator = "Generators.Assigned";
                break;

            case "identity":
                idInfo.Generator = "Generators.Identity";
                break;

            case "native":
                idInfo.Generator = "Generators.Native";
                break;
            }

            if (idElement.Attribute("access")?.Value != null)
            {
                var xmlAccess = idElement.Attribute("access").Value;
                switch (xmlAccess.ToLower())
                {
                case "property":
                    idInfo.Access = "Accessor.Property";
                    break;

                case "field.camelcase-underscore":
                    idInfo.Access = "Accessor.Field";
                    break;
                }
            }

            idInfo.UnsavedValue = idElement.Attribute("unsaved-value")?.Value;
            if (idInfo.UnsavedValue == Guid.Empty.ToString())
            {
                idInfo.UnsavedValue = "System.Guid.Empty";
            }
            model.Id = idInfo;
        }
コード例 #4
0
ファイル: Program.cs プロジェクト: SlyNet/HbmToConform
        private static void ReadSubClasses(XElement classElement, XNamespace ns, MappingModel model)
        {
            foreach (XElement subclassNode in classElement.Descendants(ns.GetName("subclass")))
            {
                //<subclass name="ncontinuity2.core.domain.SupplierInterimMeasures,ncontinuity2.core" discriminator-value="1" />
                var subclassModel = new SubclassModel();
                var fullClassName = subclassNode.Attribute("name").Value.Split(",")[0];
                var onlyClass     = fullClassName.Split(".", StringSplitOptions.RemoveEmptyEntries).Last();

                subclassModel.ClassName          = onlyClass;
                subclassModel.FullClassName      = fullClassName;
                subclassModel.DiscriminatorValue = subclassNode.Attribute("discriminator-value")?.Value;
                model.Subclasses.Add(subclassModel);
            }
        }
コード例 #5
0
ファイル: Program.cs プロジェクト: SlyNet/HbmToConform
        private static void ProcessSingleFile(FileInfo fileInfo)
        {
            var xml = XDocument.Parse(File.ReadAllText(fileInfo.FullName));

            var model = new MappingModel();
            var ns    = xml.Root.Name.Namespace;

            var classElement = xml.Root.Element(ns.GetName("class"));

            var fullClassName = classElement.Attribute("name").Value.Split(",")[0];
            var onlyClass     = fullClassName.Split(".", StringSplitOptions.RemoveEmptyEntries).Last();

            model.DomainClassName = onlyClass;
            model.FullType        = fullClassName;
            model.ClassTable      = classElement.Attribute("table") !.Value;
            model.BatchSize       = classElement.Attribute("batch-size")?.Value;

            if (bool.TryParse(classElement.Attribute("lazy")?.Value, out bool lazy))
            {
                model.Lazy = lazy;
            }

            ReadId(classElement, ns, model);
            ReadDiscriminator(classElement, ns, model);

            var properties = ReadProperties(xml.Root.Descendants(ns.GetName("class")).FirstOrDefault(), ns);

            model.Properties.AddRange(properties);
            ReadBagsMaps(xml, ns, model);
            ReadSetMaps(xml, ns, model);
            model.ManyToOnes.AddRange(ReadManyToOnes(xml.Root.Descendants(ns.GetName("class")).FirstOrDefault(), ns, model));
            ReadSubClasses(classElement, ns, model);

            var conversion = new MapTemplate();

            conversion.Model = model;

            Console.WriteLine($"Transforming file {Path.GetFileName(fileInfo.Name)}");

            var map = conversion.TransformText();

            File.WriteAllText(Path.Combine(Path.GetDirectoryName(fileInfo.FullName), onlyClass + "Map.cs"), map);
        }
コード例 #6
0
ファイル: Program.cs プロジェクト: SlyNet/HbmToConform
        private static IEnumerable <ManyToOneInfo> ReadManyToOnes(XElement classElement, XNamespace ns, MappingModel model)
        {
            foreach (var manyToOne in classElement.Descendants(ns.GetName("many-to-one")))
            {
                var mtoModel = new ManyToOneInfo();
                mtoModel.Name       = manyToOne.Attribute("name").Value;
                mtoModel.ColumnName = manyToOne.Attribute("column")?.Value;

                if (mtoModel.ColumnName == null)
                {
                    mtoModel.ColumnName = manyToOne.Descendants(ns.GetName("column")).FirstOrDefault()?.Attribute("name")?.Value;
                }

                string notFoundModel = manyToOne.Attribute("not-found")?.Value;
                switch (notFoundModel)
                {
                case "ignore":
                    mtoModel.NotFoundMode = "NotFoundMode.Ignore";
                    break;

                case "exception":
                    mtoModel.NotFoundMode = "NotFoundMode.Exception";
                    break;
                }

                string mtoLazy = manyToOne.Attribute("lazy")?.Value;

                switch (mtoLazy)
                {
                case "proxy":
                    mtoModel.Lazy = "LazyRelation.Proxy";
                    break;

                case "no-proxy":
                    mtoModel.Lazy = "LazyRelation.NoProxy";
                    break;

                case "false":
                    mtoModel.Lazy = "LazyRelation.NoLazy";
                    break;
                }

                string cascade = manyToOne.Attribute("cascade")?.Value;
                if (cascade != null)
                {
                    switch (cascade)
                    {
                    case "all-delete-orphan":
                        mtoModel.Cascade = "Cascade.All | Cascade.DeleteOrphans";
                        break;

                    case "all":
                        mtoModel.Cascade = "Cascade.All";
                        break;

                    case "save-update":
                        mtoModel.Cascade = "Cascade.Persist";
                        break;

                    case "none":
                        mtoModel.Cascade = "Cascade.None";
                        break;
                    }
                }

                mtoModel.NoUpdate = manyToOne.Attribute("update")?.Value == "false";
                mtoModel.NoInsert = manyToOne.Attribute("insert")?.Value == "false";
                mtoModel.NotNull  = manyToOne.Attribute("not-null")?.Value == "true";
                mtoModel.Unique   = manyToOne.Attribute("unique")?.Value;

                yield return(mtoModel);
            }
        }