Exemplo n.º 1
0
        private void CheckAndReportViewStatistics(string statement, IDependencyHierarchyObject obj)
        {
            var regex = new Regex(obj.SearchOccurencePattern);

            foreach (var m in regex.Matches(statement))
            {
                ReportViewStatistics(obj);
            }
        }
Exemplo n.º 2
0
 private bool ContainsView(IDependencyHierarchyObject obj)
 {
     if (obj.ObjectType == DependencyHierarchyObjectType.View)
     {
         return(true);
     }
     foreach (var d in obj.Dependencies)
     {
         if (ContainsView(d))
         {
             return(true);
         }
     }
     return(false);
 }
Exemplo n.º 3
0
 private void ReportViewStatistics(IDependencyHierarchyObject obj)
 {
     if (obj.ObjectType == DependencyHierarchyObjectType.View)
     {
         statisticsAccumulator.PublishViewStatistics(new StatementViewStatisticsData()
         {
             DatabaseID    = obj.DatabaseID,
             ExecutionDate = context.ExecutionDate,
             ViewID        = obj.ID
         });
     }
     foreach (var d in obj.Dependencies)
     {
         ReportViewStatistics(d);
     }
 }
Exemplo n.º 4
0
        private IDependencyHierarchyObject BuildDependencyObject(IEnumerable <IView> allLoadedViews, IEnumerable <IStoredProcedure> allLoadedProcedures,
                                                                 HashSet <IDependencyHierarchyObject> alreadyBuiltObjects,
                                                                 HashSet <IDependencyHierarchyObject> parents, IDependencyHierarchyObject obj)
        {
            IDependencyHierarchyObject result = obj;

            if (alreadyBuiltObjects.TryGetValue(obj, out var existing))
            {
                result = existing;
            }
            else
            {
                if (!parents.TryGetValue(obj, out var existingParent))
                {
                    var directDependencies = GetDirectDependencies(allLoadedViews, allLoadedProcedures, obj);
                    foreach (var dep in directDependencies)
                    {
                        var newDependency = CreateDependencyHierarchyObject(dep);
                        if (alreadyBuiltObjects.TryGetValue(newDependency, out var existingDependency))
                        {
                            obj.Dependencies.Add(existingDependency);
                        }
                        else
                        {
                            var newParents = new HashSet <IDependencyHierarchyObject>(parents);
                            newParents.Add(obj);
                            var builtDependency = BuildDependencyObject(allLoadedViews, allLoadedProcedures, alreadyBuiltObjects, newParents, newDependency);
                            if (builtDependency != null)
                            {
                                obj.Dependencies.Add(builtDependency);
                            }
                        }
                    }
                }
                else
                {
                    log.Write(SeverityType.Warning, $"Cycle detected when building dependency with id: {obj.ID}.");
                    result = null;
                }
            }
            if (result != null)
            {
                alreadyBuiltObjects.Add(result);
            }
            return(result);
        }
Exemplo n.º 5
0
        private IEnumerable <IDatabaseDependencyObject> GetDirectDependencies(IEnumerable <IView> allLoadedViews, IEnumerable <IStoredProcedure> allLoadedProcedures,
                                                                              IDependencyHierarchyObject obj)
        {
            switch (obj)
            {
            case DependencyHierarchyObject <IView> view:
                return(dependenciesRepository.GetDependenciesForDatabaseObject(obj.ID));

            case DependencyHierarchyObject <IStoredProcedure> proc:
            {
                var definition = proc.DatabaseDependencyObject.Definition.ToLower();
                List <IDatabaseDependencyObject> result = new List <IDatabaseDependencyObject>();
                if (proc.DatabaseDependencyObject.LanguageName.ToLower().Contains("sql"))
                {
                    foreach (var v in allLoadedViews)
                    {
                        var regex = new Regex(CreateSearchOccurencePattern(v));
                        if (regex.IsMatch(definition))
                        {
                            result.Add(v);
                        }
                    }
                    foreach (var p in allLoadedProcedures)
                    {
                        Regex regex = new Regex(CreateSearchOccurencePattern(p));
                        if (regex.IsMatch(definition))
                        {
                            result.Add(p);
                        }
                    }
                }
                return(result);
            }
            }
            return(new HashSet <IDatabaseDependencyObject>(0));
        }