示例#1
0
        public virtual IList <ColumnMetaData[]> collectDlineageRelations(Dlineage dlineage, columnImpactResult impactResult)
        {
            IList <ColumnMetaData[]> relations = new List <ColumnMetaData[]>();

            if (dlineage == null || impactResult == null)
            {
                return(relations);
            }
            database[] dataMetaInfos = dlineage.DataMetaInfos;
            if (dataMetaInfos == null)
            {
                return(relations);
            }

            MetaScanner scanner = new MetaScanner(dlineage);

            targetColumn[] targetColumns = impactResult.columns;
            if (impactResult != null && targetColumns != null)
            {
                for (int z = 0; z < targetColumns.Length; z++)
                {
                    targetColumn target = targetColumns[z];
                    if (target.linkTables != null && target.columns != null)
                    {
                        linkTable[] links = target.linkTables;
                        for (int i = 0; i < links.Length; i++)
                        {
                            linkTable link = links[i];

                            for (int j = 0; j < target.columns.Length; j++)
                            {
                                sourceColumn source = target.columns[j];

                                if ("true".Equals(source.orphan))
                                {
                                    continue;
                                }

                                if (!string.ReferenceEquals(source.clause, null))
                                {
                                    if ("select".Equals(link.type, StringComparison.CurrentCultureIgnoreCase))
                                    {
                                        if (!"select".Equals(source.clause, StringComparison.CurrentCultureIgnoreCase))
                                        {
                                            continue;
                                        }
                                    }
                                    if ("view".Equals(link.type, StringComparison.CurrentCultureIgnoreCase))
                                    {
                                        if (!"select".Equals(source.clause, StringComparison.CurrentCultureIgnoreCase))
                                        {
                                            continue;
                                        }
                                    }
                                    if ("insert".Equals(link.type, StringComparison.CurrentCultureIgnoreCase))
                                    {
                                        if (!"select".Equals(source.clause, StringComparison.CurrentCultureIgnoreCase))
                                        {
                                            continue;
                                        }
                                    }
                                    if ("update".Equals(link.type, StringComparison.CurrentCultureIgnoreCase))
                                    {
                                        if (!"assign".Equals(source.clause, StringComparison.CurrentCultureIgnoreCase) && !"select".Equals(source.clause, StringComparison.CurrentCultureIgnoreCase))
                                        {
                                            continue;
                                        }
                                    }
                                    if ("merge".Equals(link.type, StringComparison.CurrentCultureIgnoreCase))
                                    {
                                        if (!"assign".Equals(source.clause, StringComparison.CurrentCultureIgnoreCase) && !"select".Equals(source.clause, StringComparison.CurrentCultureIgnoreCase))
                                        {
                                            continue;
                                        }
                                    }
                                }

                                string sourceTableName = null;
                                if (!string.ReferenceEquals(source.tableOwner, null) && !"unknown".Equals(source.tableOwner, StringComparison.CurrentCultureIgnoreCase))
                                {
                                    sourceTableName = source.tableOwner + "." + source.tableName;
                                }
                                else
                                {
                                    sourceTableName = source.tableName;
                                }

                                ColumnMetaData sourceColumn = scanner.getColumnMetaData(sourceTableName + "." + source.name);

                                string targetTableName = null;
                                if (!string.ReferenceEquals(link.tableOwner, null) && !"unknown".Equals(link.tableOwner, StringComparison.CurrentCultureIgnoreCase))
                                {
                                    targetTableName = link.tableOwner + "." + link.tableName;
                                }
                                else
                                {
                                    targetTableName = link.tableName;
                                }

                                ColumnMetaData targetColumn = scanner.getColumnMetaData(targetTableName, link.name);

                                if (sourceColumn != null && targetColumn != null)
                                {
                                    relations.Add(new ColumnMetaData[] { targetColumn, sourceColumn });
                                }
                                else
                                {
                                    if (sourceColumn == null)
                                    {
                                        Console.Error.WriteLine(sourceTableName + "." + source.name + " should not be null.");
                                    }

                                    if (targetColumn == null)
                                    {
                                        Console.Error.WriteLine(targetTableName + "." + link.name + " should not be null.");
                                    }
                                }
                            }
                        }
                    }
                }
            }

            return(relations);
        }
示例#2
0
        private void appendColumnRelations(columnImpactResult impactResult, Element dlineageRelation)
        {
            targetColumn[] targetColumns = impactResult.columns;
            if (impactResult != null && targetColumns != null)
            {
                for (int z = 0; z < targetColumns.Length; z++)
                {
                    targetColumn target = targetColumns[z];
                    if (target.linkTables != null && target.columns != null)
                    {
                        linkTable[] links = target.linkTables;
                        for (int i = 0; i < links.Length; i++)
                        {
                            linkTable link = links[i];
                            for (int j = 0; j < target.columns.Length; j++)
                            {
                                sourceColumn source = target.columns[j];

                                if ("true".Equals(source.orphan))
                                {
                                    continue;
                                }

                                if (!string.ReferenceEquals(source.clause, null))
                                {
                                    if ("select".Equals(link.type, StringComparison.CurrentCultureIgnoreCase))
                                    {
                                        if (!"select".Equals(source.clause, StringComparison.CurrentCultureIgnoreCase))
                                        {
                                            continue;
                                        }
                                    }
                                    if ("view".Equals(link.type, StringComparison.CurrentCultureIgnoreCase))
                                    {
                                        if (!"select".Equals(source.clause, StringComparison.CurrentCultureIgnoreCase))
                                        {
                                            continue;
                                        }
                                    }
                                    if ("insert".Equals(link.type, StringComparison.CurrentCultureIgnoreCase))
                                    {
                                        if (!"select".Equals(source.clause, StringComparison.CurrentCultureIgnoreCase))
                                        {
                                            continue;
                                        }
                                    }
                                    if ("update".Equals(link.type, StringComparison.CurrentCultureIgnoreCase))
                                    {
                                        if (!"assign".Equals(source.clause, StringComparison.CurrentCultureIgnoreCase) && !"select".Equals(source.clause, StringComparison.CurrentCultureIgnoreCase))
                                        {
                                            continue;
                                        }
                                    }
                                    if ("merge".Equals(link.type, StringComparison.CurrentCultureIgnoreCase))
                                    {
                                        if (!"assign".Equals(source.clause, StringComparison.CurrentCultureIgnoreCase) && !"select".Equals(source.clause, StringComparison.CurrentCultureIgnoreCase))
                                        {
                                            continue;
                                        }
                                    }
                                }

                                Element relationNode = new Element("relation");

                                Element sourceNode = new Element("source");

                                sourceNode.Add(new XAttribute("column", source.name));
                                sourceNode.Add(new XAttribute("coordinate", source.coordinate));
                                if (!string.ReferenceEquals(source.tableOwner, null) && !"unknown".Equals(source.tableOwner, StringComparison.CurrentCultureIgnoreCase))
                                {
                                    sourceNode.Add(new XAttribute("table", source.tableOwner + "." + source.tableName));
                                }
                                else
                                {
                                    sourceNode.Add(new XAttribute("table", source.tableName));
                                }

                                Element targetNode = new Element("target");

                                targetNode.Add(new XAttribute("column", link.name));

                                if (!string.ReferenceEquals(target.aliasCoordinate, null))
                                {
                                    targetNode.Add(new XAttribute("coordinate", target.aliasCoordinate));
                                }
                                else
                                {
                                    targetNode.Add(new XAttribute("coordinate", link.coordinate));
                                }
                                if (!string.ReferenceEquals(link.tableOwner, null) && !"unknown".Equals(link.tableOwner, StringComparison.CurrentCultureIgnoreCase))
                                {
                                    targetNode.Add(new XAttribute("table", link.tableOwner + "." + link.tableName));
                                }
                                else
                                {
                                    targetNode.Add(new XAttribute("table", link.tableName));
                                }

                                relationNode.Add(sourceNode);
                                relationNode.Add(targetNode);

                                bool append = true;
                                IEnumerator <Element> iter = dlineageRelation.Elements().GetEnumerator();
                                while (iter.MoveNext())
                                {
                                    if (iter.Current.Equals(relationNode))
                                    {
                                        append = false;
                                        break;
                                    }
                                }
                                if (append)
                                {
                                    dlineageRelation.Add(relationNode);
                                }
                            }
                        }
                    }
                }
            }
        }