Example #1
0
        public CodegenExpression Make(
            CodegenMethodScope parent,
            CodegenClassScope classScope)
        {
            var method = parent.MakeChild(typeof(QueryPlanIndexItem), GetType(), classScope);

            var propertyGetters = EventTypeUtility.GetGetters(eventType, HashProps);
            var propertyTypes = EventTypeUtility.GetPropertyTypes(eventType, HashProps);
            var valueGetter = MultiKeyCodegen.CodegenGetterMayMultiKey(
                eventType, propertyGetters, propertyTypes, HashTypes, HashMultiKeyClasses, method, classScope);

            CodegenExpression rangeGetters;
            if (RangeProps.Length == 0) {
                rangeGetters = NewArrayByLength(typeof(EventPropertyValueGetter), Constant(0));
            }
            else {
                var makeMethod = parent.MakeChild(typeof(EventPropertyValueGetter[]), GetType(), classScope);
                makeMethod.Block.DeclareVar<EventPropertyValueGetter[]>(
                    "getters",
                    NewArrayByLength(typeof(EventPropertyValueGetter), Constant(RangeProps.Length)));
                for (var i = 0; i < RangeProps.Length; i++) {
                    var getter = ((EventTypeSPI) eventType).GetGetterSPI(RangeProps[i]);
                    var getterType = eventType.GetPropertyType(RangeProps[i]);
                    var coercionType = RangeTypes == null ? null : RangeTypes[i];
                    var eval = EventTypeUtility.CodegenGetterWCoerce(
                        getter,
                        getterType,
                        coercionType,
                        method,
                        GetType(),
                        classScope);
                    makeMethod.Block.AssignArrayElement(Ref("getters"), Constant(i), eval);
                }

                makeMethod.Block.MethodReturn(Ref("getters"));
                rangeGetters = LocalMethod(makeMethod);
            }

            CodegenExpression multiKeyTransform = MultiKeyCodegen.CodegenMultiKeyFromArrayTransform(
                HashMultiKeyClasses, method, classScope);

            method.Block.MethodReturn(
                NewInstance<QueryPlanIndexItem>(
                    Constant(HashProps),
                    Constant(HashTypes),
                    valueGetter,
                    multiKeyTransform,
                    HashMultiKeyClasses != null ? HashMultiKeyClasses.GetExprMKSerde(method, classScope) : ConstantNull(),
                    Constant(RangeProps),
                    Constant(RangeTypes),
                    rangeGetters,
                    DataInputOutputSerdeForgeExtensions.CodegenArray(RangeSerdes, method, classScope, null),
                    Constant(IsUnique),
                    AdvancedIndexProvisionDesc == null
                        ? ConstantNull()
                        : AdvancedIndexProvisionDesc.CodegenMake(method, classScope)));
            return LocalMethod(method);
        }
        public CodegenMethod InitializeCodegen(
            CodegenMethodScope parent,
            SAIFFInitializeSymbol symbols,
            CodegenClassScope classScope)
        {
            // add aggregation row+factory+serde as inner classes
            var aggregationClassNames = new AggregationClassNames();
            var inners = AggregationServiceFactoryCompiler.MakeTable(
                AggregationCodegenRowLevelDesc.FromTopOnly(_plan.AggDesc),
                GetType(),
                classScope,
                aggregationClassNames,
                _className);
            classScope.AddInnerClasses(inners);

            var method = parent.MakeChild(typeof(StatementAgentInstanceFactoryCreateTable), GetType(), classScope);

            CodegenExpression primaryKeyGetter = MultiKeyCodegen.CodegenGetterMayMultiKey(
                _plan.InternalEventType, 
                _plan.PrimaryKeyGetters,
                _plan.PrimaryKeyTypes,
                null,
                _plan.PrimaryKeyMultikeyClasses,
                method,
                classScope);
            CodegenExpression fafTransform = MultiKeyCodegen.CodegenMultiKeyFromArrayTransform(
                _plan.PrimaryKeyMultikeyClasses,
                method,
                classScope);
            CodegenExpression intoTableTransform = MultiKeyCodegen.CodegenMultiKeyFromMultiKeyTransform(
                _plan.PrimaryKeyMultikeyClasses,
                method,
                classScope);

            var propertyForgeEval = DataInputOutputSerdeForgeExtensions.CodegenArray(
                _plan.InternalEventTypePropertySerdes,
                method,
                classScope,
                ExprDotName(symbols.GetAddInitSvc(method), EPStatementInitServicesConstants.EVENTTYPERESOLVER));
            
            method.Block
                .DeclareVar<StatementAgentInstanceFactoryCreateTable>("saiff", NewInstance(typeof(StatementAgentInstanceFactoryCreateTable)))
                .SetProperty(Ref("saiff"), "TableName", Constant(_tableName))
                .SetProperty(Ref("saiff"), "PublicEventType", EventTypeUtility.ResolveTypeCodegen(_plan.PublicEventType, symbols.GetAddInitSvc(method)))
                .SetProperty(Ref("saiff"), "EventToPublic", MakeEventToPublic(method, symbols, classScope))
                .SetProperty(Ref("saiff"), "AggregationRowFactory", NewInstanceInner(aggregationClassNames.RowFactoryTop, Ref("this")))
                .SetProperty(Ref("saiff"), "AggregationSerde", NewInstanceInner(aggregationClassNames.RowSerdeTop, Ref("this")))
                .SetProperty(Ref("saiff"), "PrimaryKeyGetter", primaryKeyGetter)
                .SetProperty(Ref("saiff"), "PrimaryKeySerde", _plan.PrimaryKeyMultikeyClasses.GetExprMKSerde(method, classScope))
                .SetProperty(Ref("saiff"), "PropertyForges", propertyForgeEval)
                .SetProperty(Ref("saiff"), "PrimaryKeyObjectArrayTransform", fafTransform)
                .SetProperty(Ref("saiff"), "PrimaryKeyIntoTableTransform", intoTableTransform)

                .ExprDotMethod(symbols.GetAddInitSvc(method), "AddReadyCallback", Ref("saiff"))
                .MethodReturn(Ref("saiff"));
            return method;
        }
Example #3
0
        public CodegenExpression MakeCodegen(
            CodegenMethodScope parent,
            SAIFFInitializeSymbol symbols,
            CodegenClassScope classScope)
        {
            var method = parent.MakeChild(typeof(ContextControllerDetailKeyed), GetType(), classScope);

            method.Block.DeclareVar<ContextControllerDetailKeyedItem[]>(
                "items",
                NewArrayByLength(typeof(ContextControllerDetailKeyedItem), Constant(Items.Count)));
            for (var i = 0; i < Items.Count; i++) {
                method.Block.AssignArrayElement(
                    "items",
                    Constant(i),
                    Items[i].MakeCodegen(method, symbols, classScope));
            }

            method.Block
                .DeclareVar<ContextControllerDetailKeyed>("detail", NewInstance(typeof(ContextControllerDetailKeyed)))
                .SetProperty(Ref("detail"), "Items", Ref("items"))
                .SetProperty(Ref("detail"), "MultiKeyFromObjectArray", MultiKeyCodegen.CodegenMultiKeyFromArrayTransform(MultiKeyClassRef, method, classScope));

            if (OptionalInit != null && !OptionalInit.IsEmpty()) {
                method.Block.DeclareVar<ContextConditionDescriptorFilter[]>(
                    "init",
                    NewArrayByLength(typeof(ContextConditionDescriptorFilter), Constant(OptionalInit.Count)));
                for (var i = 0; i < OptionalInit.Count; i++) {
                    method.Block.AssignArrayElement(
                        "init",
                        Constant(i),
                        Cast(
                            typeof(ContextConditionDescriptorFilter),
                            OptionalInit[i].Make(method, symbols, classScope)));
                }

                method.Block.SetProperty(Ref("detail"), "OptionalInit", Ref("init"));
            }

            if (OptionalTermination != null) {
                method.Block.SetProperty(
                    Ref("detail"),
                    "OptionalTermination",
                    OptionalTermination.Make(method, symbols, classScope));
            }

            method.Block.Expression(
                    ExprDotMethodChain(symbols.GetAddInitSvc(method)).Add("AddReadyCallback", Ref("detail")))
                .MethodReturn(Ref("detail"));
            return LocalMethod(method);
        }