Exemplo n.º 1
0
        private string WriteContainers(CohortAggregateContainer container, IQuerySyntaxHelper syntaxHelper,
                                       Dictionary <CohortQueryBuilderDependency, string> sqlDictionary, int tabs)
        {
            string sql = "";

            //Things we need to output
            var toWriteOut = container.GetOrderedContents().Where(IsEnabled).ToArray();

            if (toWriteOut.Any())
            {
                sql += Environment.NewLine + TabIn("(", tabs) + Environment.NewLine;
            }
            else
            {
                throw new QueryBuildingException($"Container '{container}' is empty, Disable it if you don't want it run'");
            }

            bool firstEntityWritten = false;

            foreach (IOrderable toWrite in toWriteOut)
            {
                if (firstEntityWritten)
                {
                    sql += Environment.NewLine + TabIn(GetSetOperationSql(container.Operation, syntaxHelper.DatabaseType) + Environment.NewLine + Environment.NewLine, tabs);
                }

                if (toWrite is AggregateConfiguration)
                {
                    sql += TabIn(sqlDictionary.Single(kvp => Equals(kvp.Key.CohortSet, toWrite)).Value, tabs);
                }

                if (toWrite is CohortAggregateContainer sub)
                {
                    sql += WriteContainers(sub, syntaxHelper, sqlDictionary, tabs + 1);
                }

                //we have now written the first thing at this level of recursion - all others will need to be separated by the OPERATION e.g. UNION
                firstEntityWritten = true;

                if (StopContainerWhenYouReach != null && StopContainerWhenYouReach.Equals(toWrite))
                {
                    if (tabs != 0)
                    {
                        throw new NotSupportedException("Stopping prematurely only works when the aggregate to stop at is in the top level container");
                    }
                    else
                    {
                        break;
                    }
                }
            }

            //if we outputted anything
            if (toWriteOut.Any())
            {
                sql += Environment.NewLine + TabIn(")", tabs) + Environment.NewLine;
            }

            return(sql);
        }
Exemplo n.º 2
0
        private void AddContainerRecursively(CohortAggregateContainer currentContainer, int tabDepth)
        {
            string tabs;
            string tabplusOne;

            helper.GetTabs(tabDepth, out tabs, out tabplusOne);

            //Things we need to output
            var toWriteOut = currentContainer.GetOrderedContents().Where(IsEnabled).ToArray();

            if (toWriteOut.Any())
            {
                _sql += Environment.NewLine + tabs + "(" + Environment.NewLine;
            }

            bool firstEntityWritten = false;

            foreach (IOrderable toWrite in toWriteOut)
            {
                if (firstEntityWritten)
                {
                    _sql += Environment.NewLine + Environment.NewLine + tabplusOne + currentContainer.Operation + Environment.NewLine + Environment.NewLine;
                }

                if (toWrite is AggregateConfiguration)
                {
                    AddAggregate((AggregateConfiguration)toWrite, tabDepth);
                }

                if (toWrite is CohortAggregateContainer)
                {
                    if (_isExplicitRequestForJoinableInceptionAggregateQuery)
                    {
                        throw new NotSupportedException("Flag _isExplicitRequestForJoinableInceptionAggregateQuery is not supported when outputing an entire container, how did you even manage to set this private flag?");
                    }

                    AddContainerRecursively((CohortAggregateContainer)toWrite, tabDepth + 1);
                }


                //we have now written the first thing at this level of recursion - all others will need to be separated by the OPERATION e.g. UNION
                firstEntityWritten = true;

                if (StopContainerWhenYouReach != null && StopContainerWhenYouReach.Equals(toWrite))
                {
                    if (tabDepth != 0)
                    {
                        throw new NotSupportedException("Stopping prematurely only works when the aggregate to stop at is in the top level container");
                    }
                    else
                    {
                        break;
                    }
                }
            }

            //if we outputted anything
            if (toWriteOut.Any())
            {
                _sql += Environment.NewLine + tabs + ")" + Environment.NewLine;
            }
        }