private static DeliveryConvertor DetermineWideningDeliveryConvertor(
            bool firstParameterIsEPStatement,
            EPStatement statement,
            Type[] selectClauseTypes,
            Type[] parameterTypes,
            MethodInfo method,
            string runtimeURI)
        {
            var needWidener = false;
            for (var i = 0; i < selectClauseTypes.Length; i++) {
                var optionalWidener = GetWidener(i, selectClauseTypes[i], parameterTypes[i], method, statement.Name);
                if (optionalWidener != null) {
                    needWidener = true;
                    break;
                }
            }

            if (!needWidener) {
                return firstParameterIsEPStatement
                    ? new DeliveryConvertorNullWStatement(statement)
                    : (DeliveryConvertor) DeliveryConvertorNull.INSTANCE;
            }

            var wideners = new TypeWidenerSPI[selectClauseTypes.Length];
            for (var i = 0; i < selectClauseTypes.Length; i++) {
                wideners[i] = GetWidener(i, selectClauseTypes[i], parameterTypes[i], method, statement.Name);
            }

            return firstParameterIsEPStatement
                ? new DeliveryConvertorWidenerWStatement(wideners, statement)
                : (DeliveryConvertor) new DeliveryConvertorWidener(wideners);
        }
Exemplo n.º 2
0
 public ExprEvalWithTypeWidener(
     TypeWidenerSPI widener,
     ExprNode validated,
     Type targetType)
 {
     this.widener = widener;
     this.validated = validated;
     this.targetType = targetType;
 }
 public SelectExprProcessorEvalAvroArrayCoercer(
     ExprForge forge,
     TypeWidenerSPI widener,
     Type resultType)
 {
     _forge = forge;
     _widener = widener;
     EvaluationType = resultType;
 }
Exemplo n.º 4
0
 public VariableTriggerWriteArrayElementForge(
     string variableName,
     ExprForge indexExpression,
     TypeWidenerSPI widener)
 {
     this.variableName    = variableName;
     this.indexExpression = indexExpression;
     this.widener         = widener;
 }
 internal Item(
     int toIndex,
     int optionalFromIndex,
     ExprForge forge,
     TypeWidenerSPI optionalWidener)
 {
     ToIndex = toIndex;
     OptionalFromIndex = optionalFromIndex;
     Forge = forge;
     OptionalWidener = optionalWidener;
 }
 internal Item(
     int toIndex,
     string optionalPropertyName,
     ExprForge forge,
     TypeWidenerSPI optionalWidener)
 {
     ToIndex = toIndex;
     OptionalPropertyName = optionalPropertyName;
     Forge = forge;
     OptionalWidener = optionalWidener;
 }
Exemplo n.º 7
0
 public InternalEventRouterWriterArrayElementForge(
     ExprNode indexExpression,
     ExprNode rhsExpression,
     TypeWidenerSPI widener,
     string propertyName)
 {
     _indexExpression = indexExpression;
     _rhsExpression   = rhsExpression;
     _widener         = widener;
     _propertyName    = propertyName;
 }
Exemplo n.º 8
0
            internal Item(
                JsonUnderlyingField toField,
                JsonUnderlyingField optionalFromField,
                ExprForge forge,
                TypeWidenerSPI optionalWidener)
            {
                if (toField == null)
                {
                    throw new ArgumentException("Null to-field");
                }

                this.toField           = toField;
                this.optionalFromField = optionalFromField;
                this.forge             = forge;
                this.optionalWidener   = optionalWidener;
            }
Exemplo n.º 9
0
        public static CodegenExpression CodegenWidener(
            TypeWidenerSPI widener,
            CodegenMethod method,
            Type originator,
            CodegenClassScope classScope)
        {
            var widen = new CodegenExpressionLambda(method.Block).WithParam<object>("input");
            var anonymousClass = NewInstance<ProxyTypeWidener>(widen);

            //var anonymousClass = NewAnonymousClass(method.Block, typeof(TypeWidener));
            //var widen = CodegenMethod.MakeParentNode(typeof(object), originator, classScope)
            //    .AddParam(typeof(object), "input");
            //anonymousClass.AddMethod("widen", widen);

            var widenResult = widener.WidenCodegen(Ref("input"), method, classScope);
            widen.Block.BlockReturn(widenResult);
            return anonymousClass;
        }
Exemplo n.º 10
0
 public EventBeanUpdateItemForge(
     ExprForge expression,
     string optionalPropertyName,
     EventPropertyWriterSPI optionalWriter,
     bool notNullableField,
     TypeWidenerSPI optionalWidener,
     bool useUntypedAssignment,
     bool useTriggeringEvent,
     EventBeanUpdateItemArray optionalArray)
 {
     Expression = expression;
     OptionalPropertyName = optionalPropertyName;
     OptionalWriter = optionalWriter;
     IsNotNullableField = notNullableField;
     OptionalWidener = optionalWidener;
     IsUseUntypedAssignment = useUntypedAssignment;
     IsUseTriggeringEvent = useTriggeringEvent;
     OptionalArray = optionalArray;
 }
        private static SelectExprProcessorForge InitializeJoinWildcardInternal(
            EventType eventType,
            ISet<WriteablePropertyDescriptor> writables,
            string[] streamNames,
            EventType[] streamTypes,
            string statementName,
            ImportServiceCompileTime importService,
            EventTypeAvroHandler eventTypeAvroHandler)
        {
            var typeWidenerCustomizer = eventTypeAvroHandler.GetTypeWidenerCustomizer(eventType);
            IList<WriteablePropertyDescriptor> writablePropertiesList = new List<WriteablePropertyDescriptor>();
            IList<ExprForge> forgesList = new List<ExprForge>();
            IList<TypeWidenerSPI> widenersList = new List<TypeWidenerSPI>();

            // loop over all columns selected, if any
            for (var i = 0; i < streamNames.Length; i++) {
                WriteablePropertyDescriptor selectedWritable = null;
                TypeWidenerSPI widener = null;

                foreach (var desc in writables) {
                    if (!desc.PropertyName.Equals(streamNames[i])) {
                        continue;
                    }

                    try {
                        widener = TypeWidenerFactory.GetCheckPropertyAssignType(
                            streamNames[i],
                            streamTypes[i].UnderlyingType,
                            desc.PropertyType,
                            desc.PropertyName,
                            false,
                            typeWidenerCustomizer,
                            statementName);
                    }
                    catch (TypeWidenerException ex) {
                        throw new ExprValidationException(ex.Message, ex);
                    }

                    selectedWritable = desc;
                    break;
                }

                if (selectedWritable == null) {
                    var message = "Stream underlying object for stream '" +
                                  streamNames[i] +
                                  "' could not be assigned to any of the properties of the underlying type (missing column names, event property or setter method?)";
                    throw new ExprValidationException(message);
                }

                ExprForge forge = new ExprForgeStreamUnderlying(i, streamTypes[i].UnderlyingType);

                // add
                writablePropertiesList.Add(selectedWritable);
                forgesList.Add(forge);
                widenersList.Add(widener);
            }

            // assign
            var writableProperties = writablePropertiesList.ToArray();
            var exprForges = forgesList.ToArray();
            var wideners = widenersList.ToArray();

            EventBeanManufacturerForge eventManufacturer;
            try {
                eventManufacturer = EventTypeUtility.GetManufacturer(
                    eventType,
                    writableProperties,
                    importService,
                    false,
                    eventTypeAvroHandler);
            }
            catch (EventBeanManufactureException e) {
                throw new ExprValidationException(e.Message, e);
            }

            return new SelectExprInsertNativeWidening(eventType, eventManufacturer, exprForges, wideners);
        }
        private static SelectExprProcessorForge InitializeSetterManufactor(
            EventType eventType,
            ISet<WriteablePropertyDescriptor> writables,
            bool isUsingWildcard,
            StreamTypeService typeService,
            ExprForge[] expressionForges,
            string[] columnNames,
            object[] expressionReturnTypes,
            string statementName,
            ImportServiceCompileTime importService,
            EventTypeAvroHandler eventTypeAvroHandler)
        {
            var typeWidenerCustomizer = eventTypeAvroHandler.GetTypeWidenerCustomizer(eventType);
            IList<WriteablePropertyDescriptor> writablePropertiesList = new List<WriteablePropertyDescriptor>();
            IList<ExprForge> forgesList = new List<ExprForge>();
            IList<TypeWidenerSPI> widenersList = new List<TypeWidenerSPI>();

            // loop over all columns selected, if any
            for (var i = 0; i < columnNames.Length; i++) {
                WriteablePropertyDescriptor selectedWritable = null;
                TypeWidenerSPI widener = null;
                var forge = expressionForges[i];

                foreach (var desc in writables) {
                    if (!desc.PropertyName.Equals(columnNames[i])) {
                        continue;
                    }

                    var columnType = expressionReturnTypes[i];
                    if (columnType == null) {
                        try {
                            TypeWidenerFactory.GetCheckPropertyAssignType(
                                columnNames[i],
                                null,
                                desc.PropertyType,
                                desc.PropertyName,
                                false,
                                typeWidenerCustomizer,
                                statementName);
                        }
                        catch (TypeWidenerException ex) {
                            throw new ExprValidationException(ex.Message, ex);
                        }
                    }
                    else if (columnType is EventType) {
                        var columnEventType = (EventType) columnType;
                        var returnType = columnEventType.UnderlyingType;
                        try {
                            widener = TypeWidenerFactory.GetCheckPropertyAssignType(
                                columnNames[i],
                                columnEventType.UnderlyingType,
                                desc.PropertyType,
                                desc.PropertyName,
                                false,
                                typeWidenerCustomizer,
                                statementName);
                        }
                        catch (TypeWidenerException ex) {
                            throw new ExprValidationException(ex.Message, ex);
                        }

                        // handle evaluator returning an event
                        if (TypeHelper.IsSubclassOrImplementsInterface(returnType, desc.PropertyType)) {
                            selectedWritable = desc;
                            widener = new ProxyTypeWidenerSPI {
                                ProcWidenResultType = () => desc.PropertyType,
                                ProcWiden = input => {
                                    if (input is EventBean eventBean) {
                                        return eventBean.Underlying;
                                    }

                                    return input;
                                },

                                ProcWidenCodegen = (
                                    expression,
                                    codegenMethodScope,
                                    codegenClassScope) => {
                                    var method = codegenMethodScope
                                        .MakeChild(typeof(object), typeof(TypeWidenerSPI), codegenClassScope)
                                        .AddParam(typeof(object), "input")
                                        .Block
                                        .IfCondition(InstanceOf(Ref("input"), typeof(EventBean)))
                                        .BlockReturn(
                                            ExprDotName(Cast(typeof(EventBean), Ref("input")), "Underlying"))
                                        .MethodReturn(Ref("input"));
                                    return LocalMethodBuild(method).Pass(expression).Call();
                                }
                            };
                            continue;
                        }

                        // find stream
                        var streamNum = 0;
                        for (var j = 0; j < typeService.EventTypes.Length; j++) {
                            if (typeService.EventTypes[j] == columnEventType) {
                                streamNum = j;
                                break;
                            }
                        }

                        forge = new ExprForgeStreamUnderlying(
                            streamNum,
                            typeService.EventTypes[streamNum].UnderlyingType);
                    }
                    else if (columnType is EventType[]) {
                        // handle case where the select-clause contains an fragment array
                        var columnEventType = ((EventType[]) columnType)[0];
                        var componentReturnType = columnEventType.UnderlyingType;
                        var arrayReturnType = componentReturnType.MakeArrayType();

                        var allowObjectArrayToCollectionConversion = eventType is AvroSchemaEventType;
                        try {
                            widener = TypeWidenerFactory.GetCheckPropertyAssignType(
                                columnNames[i],
                                arrayReturnType,
                                desc.PropertyType,
                                desc.PropertyName,
                                allowObjectArrayToCollectionConversion,
                                typeWidenerCustomizer,
                                statementName);
                        }
                        catch (TypeWidenerException ex) {
                            throw new ExprValidationException(ex.Message, ex);
                        }

                        var inner = forge;
                        forge = new ExprForgeStreamWithInner(inner, componentReturnType);
                    }
                    else if (!(columnType is Type columnAsType)) {
                        var message = "Invalid assignment of column '" +
                                      columnNames[i] +
                                      "' of type '" +
                                      columnType +
                                      "' to event property '" +
                                      desc.PropertyName +
                                      "' typed as '" +
                                      desc.PropertyType.CleanName() +
                                      "', column and parameter types mismatch";
                        throw new ExprValidationException(message);
                    }
                    else {
                        try {
                            widener = TypeWidenerFactory.GetCheckPropertyAssignType(
                                columnNames[i],
                                (Type) columnType,
                                desc.PropertyType,
                                desc.PropertyName,
                                false,
                                typeWidenerCustomizer,
                                statementName);
                        }
                        catch (TypeWidenerException ex) {
                            throw new ExprValidationException(ex.Message, ex);
                        }
                    }

                    selectedWritable = desc;
                    break;
                }

                if (selectedWritable == null) {
                    var message = "Column '" +
                                  columnNames[i] +
                                  "' could not be assigned to any of the properties of the underlying type (missing column names, event property, setter method or constructor?)";
                    throw new ExprValidationException(message);
                }

                // add
                writablePropertiesList.Add(selectedWritable);
                forgesList.Add(forge);
                widenersList.Add(widener);
            }

            // handle wildcard
            if (isUsingWildcard) {
                var sourceType = typeService.EventTypes[0];
                foreach (var eventPropDescriptor in sourceType.PropertyDescriptors) {
                    if (eventPropDescriptor.IsRequiresIndex || eventPropDescriptor.IsRequiresMapKey) {
                        continue;
                    }

                    WriteablePropertyDescriptor selectedWritable = null;
                    TypeWidenerSPI widener = null;
                    ExprForge forge = null;

                    foreach (var writableDesc in writables) {
                        if (!writableDesc.PropertyName.Equals(eventPropDescriptor.PropertyName)) {
                            continue;
                        }

                        try {
                            widener = TypeWidenerFactory.GetCheckPropertyAssignType(
                                eventPropDescriptor.PropertyName,
                                eventPropDescriptor.PropertyType,
                                writableDesc.PropertyType,
                                writableDesc.PropertyName,
                                false,
                                typeWidenerCustomizer,
                                statementName);
                        }
                        catch (TypeWidenerException ex) {
                            throw new ExprValidationException(ex.Message, ex);
                        }

                        selectedWritable = writableDesc;

                        var propertyName = eventPropDescriptor.PropertyName;
                        var getter = ((EventTypeSPI) sourceType).GetGetterSPI(propertyName);
                        forge = new ExprForgeStreamWithGetter(getter);
                        break;
                    }

                    if (selectedWritable == null) {
                        var message = "Event property '" +
                                      eventPropDescriptor.PropertyName +
                                      "' could not be assigned to any of the properties of the underlying type (missing column names, event property, setter method or constructor?)";
                        throw new ExprValidationException(message);
                    }

                    writablePropertiesList.Add(selectedWritable);
                    forgesList.Add(forge);
                    widenersList.Add(widener);
                }
            }

            // assign
            var writableProperties = writablePropertiesList.ToArray();
            var exprForges = forgesList.ToArray();
            var wideners = widenersList.ToArray();

            EventBeanManufacturerForge eventManufacturer;
            try {
                eventManufacturer = EventTypeUtility.GetManufacturer(
                    eventType,
                    writableProperties,
                    importService,
                    false,
                    eventTypeAvroHandler);
            }
            catch (EventBeanManufactureException e) {
                throw new ExprValidationException(e.Message, e);
            }
            
            if (eventManufacturer == null) {
                return null;
            }

            return new SelectExprInsertNativeWidening(eventType, eventManufacturer, exprForges, wideners);
        }
Exemplo n.º 13
0
        public static InternalEventRouterDescForge GetValidatePreprocessing(
            EventType eventType,
            UpdateDesc desc,
            Attribute[] annotations)
        {
            if (!(eventType is EventTypeSPI)) {
                throw new ExprValidationException(
                    "Update statements require the event type to implement the " + typeof(EventTypeSPI) + " interface");
            }

            var eventTypeSPI = (EventTypeSPI) eventType;

            var size = desc.Assignments.Count;
            var wideners = new TypeWidenerSPI[size];
            var properties = new string[size];
            var expressions = new ExprNode[size];
            for (var i = 0; i < size; i++) {
                var onSet = desc.Assignments[i];
                var assignmentPair = ExprNodeUtilityValidate.CheckGetAssignmentToProp(onSet.Expression);
                if (assignmentPair == null) {
                    throw new ExprValidationException(
                        "Missing property assignment expression in assignment number " + i);
                }

                properties[i] = assignmentPair.First;
                expressions[i] = assignmentPair.Second;
                var writableProperty = eventTypeSPI.GetWritableProperty(assignmentPair.First);

                if (writableProperty == null) {
                    throw new ExprValidationException(
                        "Property '" + assignmentPair.First + "' is not available for write access");
                }

                try {
                    wideners[i] = TypeWidenerFactory.GetCheckPropertyAssignType(
                        ExprNodeUtilityPrint.ToExpressionStringMinPrecedenceSafe(assignmentPair.Second),
                        assignmentPair.Second.Forge.EvaluationType,
                        writableProperty.PropertyType,
                        assignmentPair.First,
                        false,
                        null,
                        null);
                }
                catch (TypeWidenerException ex) {
                    throw new ExprValidationException(ex.Message, ex);
                }
            }

            // check copy-able
            var copyMethod = eventTypeSPI.GetCopyMethodForge(properties);
            if (copyMethod == null) {
                throw new ExprValidationException(
                    "The update-clause requires the underlying event representation to support copy (via Serializable by default)");
            }

            return new InternalEventRouterDescForge(
                copyMethod,
                wideners,
                eventType,
                annotations,
                desc.OptionalWhereClause,
                properties,
                expressions);
        }