Ejemplo n.º 1
0
        public ExecutionPlan GetExecutionPlan(IEnumerable <IExecutable> executables, IEnumerable <Table> tables)
        {
            this.tables = tables;
            var plan = new ExecutionPlan();

            executables = ExecutionPlan.RemoveDataProvidersIfSchema(executables);
            var sortedExecutables = DependencyGraph.TopologicalSort(executables);
            var passes            = DependencyGraph.CreatePasses(sortedExecutables);
            int slot = 0;

            foreach (var pass in passes)
            {
                //Add all schema executables to the current slot
                foreach (var e in pass.Where(e => e.IsSchema() || e.IsSQLRule()))
                {
                    ExecutionUnit unit = new ExecutionUnit(e);
                    plan.AddUnit(unit, slot);
                }

                var dataExes = pass.Where(e => e.IsData()).ToList();
                foreach (var table in tables)
                {
                    foreach (var dataE in dataExes)
                    {
                        if (((IDataExecutable)dataE).SkipTable(table) == false)
                        {
                            plan.AddUnit(new ExecutionUnit(dataE, table), slot);
                        }
                    }
                    slot++;
                }
                //Add finalizers
                dataExes.ForEach(e => plan.AddUnit(new ExecutionUnit(e)
                {
                    Finalize = true
                }, slot));
                if (plan[slot] != null)
                {
                    slot++;
                }
            }

            return(plan);
        }
Ejemplo n.º 2
0
        public ExecutionPlan GetExecutionPlan(IEnumerable <IExecutable> executables, IEnumerable <Table> tables)
        {
            var plan = new ExecutionPlan();

            executables = ExecutionPlan.RemoveDataProvidersIfSchema(executables);
            var executablesSorted = DependencyGraph.TopologicalSort(executables);
            var passes            = DependencyGraph.CreatePasses(executablesSorted);

            int slot = 0;

            foreach (Pass pass in passes)
            {
                foreach (var executable in pass)
                {
                    if (executable.IsSchema())
                    {
                        plan.AddUnit(new ExecutionUnit(executable), slot);
                    }
                    else
                    {
                        foreach (var table in tables)
                        {
                            if (((IDataExecutable)executable).SkipTable(table))
                            {
                                continue;
                            }
                            var unit = new ExecutionUnit(executable, table);
                            plan.AddUnit(unit, slot);
                        }
                    }
                }
                slot++;
                //Finalize all data executables in the previous slot
                pass.Where(e => e.IsData()).ToList().ForEach(e => plan.AddUnit(new ExecutionUnit(e)
                {
                    Finalize = true
                }, slot));
                slot++;
            }

            return(plan);
        }