protected internal static void ProcessOutputLimitedLastAllNonBufferedCodegen(
            string methodName,
            ResultSetProcessorRowForAllForge forge,
            CodegenClassScope classScope,
            CodegenMethod method,
            CodegenInstanceAux instance)
        {
            var factory = classScope.AddOrGetDefaultFieldSharable(ResultSetProcessorHelperFactoryField.INSTANCE);

            if (forge.OutputLimitSpec.DisplayLimit == OutputLimitLimitType.ALL) {
                instance.AddMember(NAME_OUTPUTALLHELPER, typeof(ResultSetProcessorRowForAllOutputAllHelper));
                instance.ServiceCtor.Block.AssignRef(
                    NAME_OUTPUTALLHELPER,
                    ExprDotMethod(factory, "MakeRSRowForAllOutputAll", Ref("this"), MEMBER_AGENTINSTANCECONTEXT));
                method.Block.ExprDotMethod(
                    Member(NAME_OUTPUTALLHELPER),
                    methodName,
                    REF_NEWDATA,
                    REF_OLDDATA,
                    REF_ISSYNTHESIZE);
            }
            else if (forge.OutputLimitSpec.DisplayLimit == OutputLimitLimitType.LAST) {
                instance.AddMember(NAME_OUTPUTLASTHELPER, typeof(ResultSetProcessorRowForAllOutputLastHelper));
                instance.ServiceCtor.Block.AssignRef(
                    NAME_OUTPUTLASTHELPER,
                    ExprDotMethod(factory, "MakeRSRowForAllOutputLast", Ref("this"), MEMBER_AGENTINSTANCECONTEXT));
                method.Block.ExprDotMethod(
                    Member(NAME_OUTPUTLASTHELPER),
                    methodName,
                    REF_NEWDATA,
                    REF_OLDDATA,
                    REF_ISSYNTHESIZE);
            }
        }
        public static void ProcessViewResultCodegen(
            ResultSetProcessorRowForAllForge forge,
            CodegenClassScope classScope,
            CodegenMethod method,
            CodegenInstanceAux instance)
        {
            var selectList = GetSelectListEventsAsArrayCodegen(forge, classScope, instance);

            CodegenExpression selectOld;
            if (forge.IsSelectRStream) {
                selectOld = LocalMethod(selectList, ConstantFalse(), REF_ISSYNTHESIZE, ConstantFalse());
            }
            else {
                selectOld = ConstantNull();
            }

            method.Block
                .DeclareVar<EventBean[]>("selectOldEvents", selectOld)
                .DeclareVar<EventBean[]>("eventsPerStream", NewArrayByLength(typeof(EventBean), Constant(1)))
                .StaticMethod(
                    typeof(ResultSetProcessorUtil),
                    METHOD_APPLYAGGVIEWRESULT,
                    MEMBER_AGGREGATIONSVC,
                    MEMBER_AGENTINSTANCECONTEXT,
                    REF_NEWDATA,
                    REF_OLDDATA,
                    Ref("eventsPerStream"))
                .DeclareVar<EventBean[]>(
                    "selectNewEvents",
                    LocalMethod(selectList, ConstantTrue(), REF_ISSYNTHESIZE, ConstantFalse()))
                .IfCondition(And(EqualsNull(Ref("selectNewEvents")), EqualsNull(Ref("selectOldEvents"))))
                .BlockReturn(ConstantNull())
                .MethodReturn(
                    NewInstance<UniformPair<EventBean[]>>(Ref("selectNewEvents"), Ref("selectOldEvents")));
        }
 public static void ProcessOutputLimitedLastAllNonBufferedJoinCodegen(
     ResultSetProcessorRowForAllForge forge,
     CodegenClassScope classScope,
     CodegenMethod method,
     CodegenInstanceAux instance)
 {
     ProcessOutputLimitedLastAllNonBufferedCodegen("ProcessJoin", forge, classScope, method, instance);
 }
 public static void ContinueOutputLimitedLastAllNonBufferedJoinCodegen(
     ResultSetProcessorRowForAllForge forge,
     CodegenMethod method)
 {
     if (forge.OutputLimitSpec.DisplayLimit == OutputLimitLimitType.ALL) {
         method.Block.MethodReturn(ExprDotMethod(Member(NAME_OUTPUTALLHELPER), "OutputJoin", REF_ISSYNTHESIZE));
     }
     else {
         method.Block.MethodReturn(ExprDotMethod(Member(NAME_OUTPUTLASTHELPER), "OutputJoin", REF_ISSYNTHESIZE));
     }
 }
 public static void ProcessOutputLimitedViewCodegen(
     ResultSetProcessorRowForAllForge forge,
     CodegenClassScope classScope,
     CodegenMethod method,
     CodegenInstanceAux instance)
 {
     if (forge.OutputLimitSpec.DisplayLimit == OutputLimitLimitType.LAST) {
         ProcessOutputLimitedViewLastCodegen(forge, classScope, method, instance);
     }
     else {
         ProcessOutputLimitedViewDefaultCodegen(forge, classScope, method, instance);
     }
 }
 public static void GetEnumeratorJoinCodegen(
     ResultSetProcessorRowForAllForge forge,
     CodegenClassScope classScope,
     CodegenMethod method,
     CodegenInstanceAux instance)
 {
     var select = GetSelectListEventsAsArrayCodegen(forge, classScope, instance);
     method.Block
         .DeclareVar<EventBean[]>(
             "result",
             LocalMethod(select, Constant(true), ConstantTrue(), ConstantTrue()))
         .MethodReturn(NewInstance<ArrayEventEnumerator>(Ref("result")));
 }
 protected internal static CodegenMethod ObtainEnumeratorCodegen(
     ResultSetProcessorRowForAllForge forge,
     CodegenClassScope classScope,
     CodegenMethod parent,
     CodegenInstanceAux instance)
 {
     var selectList = GetSelectListEventsAsArrayCodegen(forge, classScope, instance);
     var method = parent.MakeChild(
         typeof(IEnumerator<EventBean>),
         typeof(ResultSetProcessorRowForAllImpl),
         classScope);
     method.Block.DeclareVar<EventBean[]>(
             "events",
             LocalMethod(selectList, ConstantTrue(), ConstantTrue(), ConstantFalse()))
         .IfRefNull("events")
         .BlockReturn(EnumValue(typeof(CollectionUtil), "NULL_EVENT_ITERATOR"))
         .MethodReturn(NewInstance<SingleEventEnumerator>(ArrayAtIndex(Ref("events"), Constant(0))));
     return method;
 }
        protected internal static CodegenMethod GetSelectListEventsAsArrayCodegen(
            ResultSetProcessorRowForAllForge forge,
            CodegenClassScope classScope,
            CodegenInstanceAux instance)
        {
            Consumer<CodegenMethod> code = method => {
                if (forge.OptionalHavingNode != null) {
                    method.Block.IfCondition(
                            Not(
                                LocalMethod(
                                    instance.Methods.GetMethod("EvaluateHavingClause"),
                                    ConstantNull(),
                                    REF_ISNEWDATA,
                                    MEMBER_AGENTINSTANCECONTEXT)))
                        .BlockReturn(ConstantNull());
                }

                method.Block.DeclareVar<EventBean>(
                        "theEvent",
                        ExprDotMethod(
                            MEMBER_SELECTEXPRPROCESSOR,
                            "Process",
                            EnumValue(typeof(CollectionUtil), "EVENTBEANARRAY_EMPTY"),
                            REF_ISNEWDATA,
                            REF_ISSYNTHESIZE,
                            MEMBER_AGENTINSTANCECONTEXT))
                    .DeclareVar<EventBean[]>("result", NewArrayByLength(typeof(EventBean), Constant(1)))
                    .AssignArrayElement("result", Constant(0), Ref("theEvent"))
                    .MethodReturn(Ref("result"));
            };
            return instance.Methods.AddMethod(
                typeof(EventBean[]),
                "GetSelectListEventsAsArray",
                CodegenNamedParam.From(
                    typeof(bool), NAME_ISNEWDATA,
                    typeof(bool), NAME_ISSYNTHESIZE,
                    typeof(bool), "join"),
                typeof(ResultSetProcessorRowForAllImpl),
                classScope,
                code);
        }
        internal static void GetEnumeratorViewCodegen(
            ResultSetProcessorRowForAllForge forge,
            CodegenClassScope classScope,
            CodegenMethod method,
            CodegenInstanceAux instance)
        {
            var obtainMethod = ObtainEnumeratorCodegen(forge, classScope, method, instance);
            if (!forge.IsHistoricalOnly) {
                method.Block.MethodReturn(LocalMethod(obtainMethod));
                return;
            }

            method.Block
                .StaticMethod(
                    typeof(ResultSetProcessorUtil),
                    METHOD_CLEARANDAGGREGATEUNGROUPED,
                    MEMBER_AGENTINSTANCECONTEXT,
                    MEMBER_AGGREGATIONSVC,
                    REF_VIEWABLE)
                .DeclareVar<IEnumerator<EventBean>>("enumerator", LocalMethod(obtainMethod))
                .Expression(ExprDotMethod(MEMBER_AGGREGATIONSVC, "ClearResults", MEMBER_AGENTINSTANCECONTEXT))
                .MethodReturn(Ref("enumerator"));
        }
        protected internal static void ProcessOutputLimitedViewLastCodegen(
            ResultSetProcessorRowForAllForge forge,
            CodegenClassScope classScope,
            CodegenMethod method,
            CodegenInstanceAux instance)
        {
            var getSelectListEventSingle = GetSelectListEventSingleCodegen(forge, classScope, instance);

            method.Block.DeclareVar<EventBean>("lastOldEvent", ConstantNull())
                .DeclareVar<EventBean>("lastNewEvent", ConstantNull())
                .DeclareVar<EventBean[]>("eventsPerStream", NewArrayByLength(typeof(EventBean), Constant(1)));

            {
                var forEach = method.Block.ForEach(typeof(UniformPair<EventBean[]>), "pair", REF_VIEWEVENTSLIST);
                if (forge.IsSelectRStream) {
                    forEach.IfCondition(EqualsNull(Ref("lastOldEvent")))
                        .AssignRef(
                            "lastOldEvent",
                            LocalMethod(getSelectListEventSingle, ConstantFalse(), REF_ISSYNTHESIZE))
                        .BlockEnd();
                }

                forEach.StaticMethod(
                    typeof(ResultSetProcessorUtil),
                    METHOD_APPLYAGGVIEWRESULT,
                    MEMBER_AGGREGATIONSVC,
                    MEMBER_AGENTINSTANCECONTEXT,
                    ExprDotName(Ref("pair"), "First"),
                    ExprDotName(Ref("pair"), "Second"),
                    Ref("eventsPerStream"));
                forEach.AssignRef(
                    "lastNewEvent",
                    LocalMethod(getSelectListEventSingle, ConstantTrue(), REF_ISSYNTHESIZE));
            }

            {
                var ifEmpty = method.Block.IfCondition(ExprDotMethod(REF_VIEWEVENTSLIST, "IsEmpty"));
                if (forge.IsSelectRStream) {
                    ifEmpty.AssignRef(
                            "lastOldEvent",
                            LocalMethod(getSelectListEventSingle, ConstantFalse(), REF_ISSYNTHESIZE))
                        .AssignRef("lastNewEvent", Ref("lastOldEvent"));
                }
                else {
                    ifEmpty.AssignRef(
                        "lastNewEvent",
                        LocalMethod(getSelectListEventSingle, ConstantTrue(), REF_ISSYNTHESIZE));
                }
            }

            method.Block
                .DeclareVar<EventBean[]>(
                    "lastNew",
                    StaticMethod(typeof(CollectionUtil), CollectionUtil.METHOD_TOARRAYMAYNULL, Ref("lastNewEvent")))
                .DeclareVar<EventBean[]>(
                    "lastOld",
                    StaticMethod(typeof(CollectionUtil), CollectionUtil.METHOD_TOARRAYMAYNULL, Ref("lastOldEvent")))
                .IfCondition(And(EqualsNull(Ref("lastNew")), EqualsNull(Ref("lastOld"))))
                .BlockReturn(ConstantNull())
                .MethodReturn(NewInstance<UniformPair<EventBean[]>>(Ref("lastNew"), Ref("lastOld")));
        }
        protected internal static void ProcessOutputLimitedViewDefaultCodegen(
            ResultSetProcessorRowForAllForge forge,
            CodegenClassScope classScope,
            CodegenMethod method,
            CodegenInstanceAux instance)
        {
            var getSelectListEventAddList = GetSelectListEventsAddListCodegen(forge, classScope, instance);
            var getSelectListEventAsArray = GetSelectListEventsAsArrayCodegen(forge, classScope, instance);

            PrefixCodegenNewOldEvents(method.Block, forge.IsSorting, forge.IsSelectRStream);

            method.Block.DeclareVar<EventBean[]>(
                "eventsPerStream",
                NewArrayByLength(typeof(EventBean), Constant(1)));
            var forEach = method.Block.ForEach(typeof(UniformPair<EventBean[]>), "pair", REF_VIEWEVENTSLIST);
            {
                if (forge.IsSelectRStream) {
                    forEach.LocalMethod(
                        getSelectListEventAddList,
                        ConstantFalse(),
                        REF_ISSYNTHESIZE,
                        Ref("oldEvents"));
                    if (forge.IsSorting) {
                        forEach.ExprDotMethod(
                            Ref("oldEventsSortKey"),
                            "Add",
                            ExprDotMethod(
                                REF_ORDERBYPROCESSOR,
                                "GetSortKey",
                                ConstantNull(),
                                ConstantFalse(),
                                MEMBER_AGENTINSTANCECONTEXT));
                    }
                }

                forEach.StaticMethod(
                    typeof(ResultSetProcessorUtil),
                    METHOD_APPLYAGGVIEWRESULT,
                    MEMBER_AGGREGATIONSVC,
                    MEMBER_AGENTINSTANCECONTEXT,
                    ExprDotName(Ref("pair"), "First"),
                    ExprDotName(Ref("pair"), "Second"),
                    Ref("eventsPerStream"));
                forEach.LocalMethod(getSelectListEventAddList, ConstantTrue(), REF_ISSYNTHESIZE, Ref("newEvents"));
                if (forge.IsSorting) {
                    forEach.ExprDotMethod(
                        Ref("newEventsSortKey"),
                        "Add",
                        ExprDotMethod(
                            REF_ORDERBYPROCESSOR,
                            "GetSortKey",
                            ConstantNull(),
                            ConstantTrue(),
                            MEMBER_AGENTINSTANCECONTEXT));
                }

                forEach.BlockEnd();
            }

            var ifEmpty = method.Block.IfCondition(Not(ExprDotMethod(REF_VIEWEVENTSLIST, "IsEmpty")));
            FinalizeOutputMaySortMayRStreamCodegen(
                ifEmpty,
                Ref("newEvents"),
                Ref("newEventsSortKey"),
                Ref("oldEvents"),
                Ref("oldEventsSortKey"),
                forge.IsSelectRStream,
                forge.IsSorting);

            method.Block.CommentFullLine("-- debug comment --");
            method.Block.DeclareVar<EventBean[]>(
                    "newEventsArrX",
                    LocalMethod(getSelectListEventAsArray, ConstantTrue(), REF_ISSYNTHESIZE, ConstantFalse()))
                .DeclareVar<EventBean[]>(
                    "oldEventsArrX",
                    forge.IsSelectRStream
                        ? LocalMethod(getSelectListEventAsArray, ConstantFalse(), REF_ISSYNTHESIZE, ConstantFalse())
                        : ConstantNull())
                .MethodReturn(
                    StaticMethod(
                        typeof(ResultSetProcessorUtil),
                        METHOD_TOPAIRNULLIFALLNULL,
                        Ref("newEventsArrX"),
                        Ref("oldEventsArrX")));
        }