Esempio n. 1
0
        public void Attach(EventType parentEventType, StatementContext statementContext, ViewFactory optionalParentFactory, IList <ViewFactory> parentViewFactories)
        {
            _eventType = parentEventType;

            // define built-in fields
            var builtinTypeDef = ExpressionViewOAFieldEnumExtensions.AsMapOfTypes(_eventType);

            _builtinMapType = statementContext.EventAdapterService.CreateAnonymousObjectArrayType(
                statementContext.StatementId + "_exprview", builtinTypeDef);

            StreamTypeService streamTypeService = new StreamTypeServiceImpl(new EventType[] { _eventType, _builtinMapType }, new String[2], new bool[2], statementContext.EngineURI, false);

            // validate expression
            ExpiryExpression = ViewFactorySupport.ValidateExpr(ViewName, statementContext, ExpiryExpression, streamTypeService, 0);

            var summaryVisitor = new ExprNodeSummaryVisitor();

            ExpiryExpression.Accept(summaryVisitor);
            if (summaryVisitor.HasSubselect || summaryVisitor.HasStreamSelect || summaryVisitor.HasPreviousPrior)
            {
                throw new ViewParameterException("Invalid expiry expression: Sub-select, previous or prior functions are not supported in this context");
            }

            var returnType = ExpiryExpression.ExprEvaluator.ReturnType;

            if (returnType.GetBoxedType() != typeof(bool?))
            {
                throw new ViewParameterException("Invalid return value for expiry expression, expected a bool return value but received " + returnType.GetParameterAsString());
            }

            // determine variables used, if any
            var visitor = new ExprNodeVariableVisitor();

            ExpiryExpression.Accept(visitor);
            VariableNames = visitor.VariableNames;

            // determine aggregation nodes, if any
            var aggregateNodes = new List <ExprAggregateNode>();

            ExprAggregateNodeUtil.GetAggregatesBottomUp(ExpiryExpression, aggregateNodes);
            if (aggregateNodes.IsNotEmpty())
            {
                try {
                    AggregationServiceFactoryDesc = AggregationServiceFactoryFactory.GetService(
                        Collections.GetEmptyList <ExprAggregateNode>(),
                        Collections.GetEmptyMap <ExprNode, String>(),
                        Collections.GetEmptyList <ExprDeclaredNode>(),
                        null, aggregateNodes,
                        Collections.GetEmptyList <ExprAggregateNode>(),
                        Collections.GetEmptyList <ExprAggregateNodeGroupKey>(), false,
                        statementContext.Annotations,
                        statementContext.VariableService, false, false, null, null,
                        AggregationServiceFactoryServiceImpl.DEFAULT_FACTORY,
                        streamTypeService.EventTypes,
                        statementContext.MethodResolutionService, null,
                        statementContext.ContextName,
                        null, null);
                }
                catch (ExprValidationException ex) {
                    throw new ViewParameterException(ex.Message, ex);
                }
            }
        }