Esempio n. 1
0
 protected FilterParamIndexDoubleRangeBase(FilterSpecLookupable lookupable, IReaderWriterLock readWriteLock, FilterOperator filterOperator)
     : base(filterOperator, lookupable)
 {
     Ranges = new OrderedDictionary <DoubleRange, EventEvaluator>(new DoubleRangeComparator());
     _rangesNullEndpoints = new Dictionary <DoubleRange, EventEvaluator>();
     _rangesRwLock        = readWriteLock;
 }
 public FilterSpecParamContextProp(FilterSpecLookupable lookupable, FilterOperator filterOperator, String contextPropertyName, EventPropertyGetter getter, Coercer numberCoercer)
     : base(lookupable, filterOperator)
 {
     _contextPropertyName = contextPropertyName;
     _getter        = getter;
     _numberCoercer = numberCoercer;
 }
Esempio n. 3
0
 public FilterParamIndexIn(FilterSpecLookupable lookupable, IReaderWriterLock readWriteLock)
     : base(FilterOperator.IN_LIST_OF_VALUES, lookupable)
 {
     _constantsMap       = new Dictionary <Object, IList <EventEvaluator> >().WithNullSupport();
     _evaluatorsMap      = new Dictionary <MultiKeyUntyped, EventEvaluator>();
     _constantsMapRwLock = readWriteLock;
 }
Esempio n. 4
0
        /// <summary>
        /// Ctor.
        /// </summary>
        /// <param name="lookupable">is the event property name</param>
        /// <param name="filterOperator">is expected to be the IN-list operator</param>
        /// <param name="listofValues">is a list of constants and event property names</param>
        /// <throws>ArgumentException for illegal args</throws>
        public FilterSpecParamIn(FilterSpecLookupable lookupable, FilterOperator filterOperator, IList <FilterSpecParamInValue> listofValues)
            : base(lookupable, filterOperator)
        {
            _listOfValues = listofValues;

            bool isAllConstants = false;

            foreach (FilterSpecParamInValue value in listofValues)
            {
                if (value is InSetOfValuesEventProp || value is InSetOfValuesContextProp)
                {
                    isAllConstants = false;
                    break;
                }
            }

            if (isAllConstants)
            {
                Object[] constants = new Object[_listOfValues.Count];
                int      count     = 0;
                foreach (FilterSpecParamInValue valuePlaceholder in _listOfValues)
                {
                    constants[count++] = valuePlaceholder.GetFilterValue(null, null);
                }
                _inListConstantsOnly = new MultiKeyUntyped(constants);
            }

            if ((filterOperator != FilterOperator.IN_LIST_OF_VALUES) && ((filterOperator != FilterOperator.NOT_IN_LIST_OF_VALUES)))
            {
                throw new ArgumentException("Illegal filter operator " + filterOperator + " supplied to " +
                                            "in-values filter parameter");
            }
        }
Esempio n. 5
0
        /// <summary>
        /// Ctor.
        /// </summary>
        /// <param name="lookupable">is the lookup-able</param>
        /// <param name="filterOperator">is expected to be the BOOLEAN_EXPR operator</param>
        /// <param name="exprNode">represents the boolean expression</param>
        /// <param name="taggedEventTypes">is null if the expression doesn't need other streams, or is filled with a ordered list of stream names and types</param>
        /// <param name="arrayEventTypes">is a map of name tags and event type per tag for repeat-expressions that generate an array of events</param>
        /// <param name="variableService">provides access to variables</param>
        /// <param name="tableService">The table service.</param>
        /// <param name="eventAdapterService">for creating event types and event beans</param>
        /// <param name="configurationInformation">The configuration information.</param>
        /// <param name="statementName">Name of the statement.</param>
        /// <param name="hasSubquery">if set to <c>true</c> [has subquery].</param>
        /// <param name="hasTableAccess">if set to <c>true</c> [has table access].</param>
        /// <exception cref="System.ArgumentException">Invalid filter operator for filter expression node</exception>
        /// <throws>IllegalArgumentException for illegal args</throws>
        public FilterSpecParamExprNode(
            FilterSpecLookupable lookupable,
            FilterOperator filterOperator,
            ExprNode exprNode,
            IDictionary <string, Pair <EventType, string> > taggedEventTypes,
            IDictionary <string, Pair <EventType, string> > arrayEventTypes,
            VariableService variableService,
            TableService tableService,
            EventAdapterService eventAdapterService,
            ConfigurationInformation configurationInformation,
            string statementName,
            bool hasSubquery,
            bool hasTableAccess)
            : base(lookupable, filterOperator)
        {
            if (filterOperator != FilterOperator.BOOLEAN_EXPRESSION)
            {
                throw new ArgumentException("Invalid filter operator for filter expression node");
            }
            _exprNode                 = exprNode;
            _taggedEventTypes         = taggedEventTypes;
            _arrayEventTypes          = arrayEventTypes;
            _variableService          = variableService;
            _tableService             = tableService;
            _eventAdapterService      = eventAdapterService;
            _useLargeThreadingProfile = configurationInformation.EngineDefaults.ExecutionConfig.ThreadingProfile == ConfigurationEngineDefaults.ThreadingProfile.LARGE;
            _hasFilterStreamSubquery  = hasSubquery;
            _hasTableAccess           = hasTableAccess;

            var visitor = new ExprNodeVariableVisitor();

            exprNode.Accept(visitor);
            _hasVariable = visitor.HasVariables;
        }
Esempio n. 6
0
        /// <summary>
        ///     Find an index that matches one of the filter parameters passed.
        ///     The parameter type and index type match up if the property name and
        ///     filter operator are the same for the index and the filter parameter.
        ///     For instance, for a filter parameter of "count EQUALS 10", the index against property "count" with
        ///     operator type EQUALS will be returned, if present.
        ///     NOTE: The caller is expected to obtain locks, if necessary, on the collections passed in.
        ///     NOTE: Doesn't match non-property based index - thus bool expressions don't get found and are always entered as a
        ///     new index
        /// </summary>
        /// <param name="parameters">is the list of sorted filter parameters</param>
        /// <param name="indizes">is the collection of indexes</param>
        /// <returns>
        ///     A matching pair of filter parameter and index, if any matches were found. Null if no matches were found.
        /// </returns>
        public static Pair<FilterValueSetParam, FilterParamIndexBase> FindIndex(
            ICollection<FilterValueSetParam> parameters,
            IList<FilterParamIndexBase> indizes)
        {
            foreach (FilterValueSetParam parameter in parameters)
            {
                FilterSpecLookupable lookupable = parameter.Lookupable;
                FilterOperator @operator = parameter.FilterOperator;

                foreach (FilterParamIndexBase index in indizes)
                {
                    // if property-based index, we prefer this in matching
                    if (index is FilterParamIndexLookupableBase)
                    {
                        var propBasedIndex = (FilterParamIndexLookupableBase) index;
                        if ((lookupable.Equals(propBasedIndex.Lookupable)) &&
                            (@operator.Equals(propBasedIndex.FilterOperator)))
                        {
                            return new Pair<FilterValueSetParam, FilterParamIndexBase>(parameter, index);
                        }
                    }
                    else if (index is FilterParamIndexBooleanExpr && parameters.Count == 1)
                    {
                        // if bool-expression then match only if this is the last parameter,
                        // all others considered are higher order and sort ahead
                        if (@operator.Equals(FilterOperator.BOOLEAN_EXPRESSION))
                        {
                            return new Pair<FilterValueSetParam, FilterParamIndexBase>(parameter, index);
                        }
                    }
                }
            }

            return null;
        }
Esempio n. 7
0
 public void RegisterNonPropertyExpression(
     string statementName,
     EventType eventType,
     FilterSpecLookupable lookupable)
 {
     // default implementation, no action required
 }
Esempio n. 8
0
        /// <summary>
        /// Constructor.
        /// </summary>
        /// <param name="lookupable">is the lookupable</param>
        /// <param name="filterOperator">is the type of compare</param>
        /// <param name="resultEventAsName">is the name of the result event from which to get a property value to compare</param>
        /// <param name="resultEventIndex">index</param>
        /// <param name="resultEventProperty">is the name of the property to get from the named result event</param>
        /// <param name="isMustCoerce">indicates on whether numeric coercion must be performed</param>
        /// <param name="numberCoercer">interface to use to perform coercion</param>
        /// <param name="coercionType">indicates the numeric coercion type to use</param>
        /// <param name="statementName">Name of the statement.</param>
        /// <throws>ArgumentException if an operator was supplied that does not take a single constant value</throws>
        public FilterSpecParamEventPropIndexed(FilterSpecLookupable lookupable,
                                               FilterOperator filterOperator,
                                               String resultEventAsName,
                                               int resultEventIndex,
                                               String resultEventProperty,
                                               bool isMustCoerce,
                                               Coercer numberCoercer,
                                               Type coercionType,
                                               String statementName)
            : base(lookupable, filterOperator)
        {
            _resultEventAsName   = resultEventAsName;
            _resultEventIndex    = resultEventIndex;
            _resultEventProperty = resultEventProperty;
            _isMustCoerce        = isMustCoerce;
            _numberCoercer       = numberCoercer;
            _coercionType        = coercionType;
            _statementName       = statementName;

            if (filterOperator.IsRangeOperator())
            {
                throw new ArgumentException("Illegal filter operator " + filterOperator + " supplied to " +
                                            "event property filter parameter");
            }
        }
Esempio n. 9
0
 public FilterParamIndexDoubleRange(FilterSpecLookupable lookupable, IReaderWriterLock readWriteLock, FilterOperator filterOperator)
     : base(lookupable, readWriteLock, filterOperator)
 {
     if (!(filterOperator.IsRangeOperator()))
     {
         throw new ArgumentException("Invalid filter operator " + filterOperator);
     }
 }
Esempio n. 10
0
 public FilterParamIndexNotIn(FilterSpecLookupable lookupable, IReaderWriterLock readWriteLock)
     : base(FilterOperator.NOT_IN_LIST_OF_VALUES, lookupable)
 {
     _constantsMap          = new Dictionary <object, ISet <EventEvaluator> >().WithNullSupport();
     _filterValueEvaluators = new Dictionary <MultiKeyUntyped, EventEvaluator>();
     _evaluatorsSet         = new HashSet <EventEvaluator>();
     _constantsMapRwLock    = readWriteLock;
 }
Esempio n. 11
0
 public FilterSpecParamAdvancedIndexQuadTreePointRegion(
     FilterSpecLookupable lookupable,
     FilterOperator filterOperator, 
     FilterSpecParamFilterForEvalDouble xEval,
     FilterSpecParamFilterForEvalDouble yEval)
     : base(lookupable, filterOperator)
 {
     _xEval = xEval;
     _yEval = yEval;
 }
Esempio n. 12
0
 public FilterSpecParamAdvancedIndexQuadTreeMXCIF(FilterSpecLookupable lookupable, FilterOperator filterOperator,
     FilterSpecParamFilterForEvalDouble xEval, FilterSpecParamFilterForEvalDouble yEval,
     FilterSpecParamFilterForEvalDouble widthEval, FilterSpecParamFilterForEvalDouble heightEval)
     : base(lookupable, filterOperator)
 {
     _xEval = xEval;
     _yEval = yEval;
     _widthEval = widthEval;
     _heightEval = heightEval;
 }
Esempio n. 13
0
        /// <summary>Constructor. </summary>
        /// <param name="lookupable">is the lookupable</param>
        /// <param name="filterOperator">is the type of compare</param>
        /// <param name="filterConstant">contains the value to match against the event's property value</param>
        /// <throws>ArgumentException if an operator was supplied that does not take a single constant value</throws>
        public FilterSpecParamConstant(FilterSpecLookupable lookupable, FilterOperator filterOperator, Object filterConstant)
            : base(lookupable, filterOperator)
        {
            _filterConstant = filterConstant;

            if (filterOperator.IsRangeOperator())
            {
                throw new ArgumentException("Illegal filter operator " + filterOperator + " supplied to " +
                                            "constant filter parameter");
            }
        }
Esempio n. 14
0
 private static FilterSpecParamExprNode MakeBooleanExprParam(ExprNode exprNode, FilterSpecCompilerArgs args)
 {
     bool hasSubselectFilterStream = DetermineSubselectFilterStream(exprNode);
     bool hasTableAccess = DetermineTableAccessFilterStream(exprNode);
     var lookupable = new FilterSpecLookupable(
         FilterSpecCompiler.PROPERTY_NAME_BOOLEAN_EXPRESSION, null, exprNode.ExprEvaluator.ReturnType);
     return new FilterSpecParamExprNode(
         lookupable, FilterOperator.BOOLEAN_EXPRESSION, exprNode, args.TaggedEventTypes, args.ArrayEventTypes,
         args.VariableService, args.TableService, args.EventAdapterService, args.ConfigurationInformation,
         args.StatementName, hasSubselectFilterStream, hasTableAccess);
 }
Esempio n. 15
0
        /// <summary>Constructor. </summary>
        /// <param name="lookupable">is the lookupable</param>
        /// <param name="filterOperator">is the type of range operator</param>
        /// <param name="min">is the begin point of the range</param>
        /// <param name="max">is the end point of the range</param>
        /// <throws>ArgumentException if an operator was supplied that does not take a double range value</throws>
        public FilterSpecParamRange(FilterSpecLookupable lookupable, FilterOperator filterOperator, FilterSpecParamRangeValue min, FilterSpecParamRangeValue max)
            : base(lookupable, filterOperator)
        {
            _min = min;
            _max = max;

            if (!(filterOperator.IsRangeOperator()) && (!filterOperator.IsInvertedRangeOperator()))
            {
                throw new ArgumentException("Illegal filter operator " + filterOperator + " supplied to " +
                                            "range filter parameter");
            }
        }
Esempio n. 16
0
 public bool Equals(FilterSpecLookupable other)
 {
     if (ReferenceEquals(null, other))
     {
         return(false);
     }
     if (ReferenceEquals(this, other))
     {
         return(true);
     }
     return(Expression.Equals(other.Expression) && Equals(other.ReturnType, ReturnType));
 }
 public FilterParamIndexQuadTreeMXCIF(IReaderWriterLock readWriteLock, FilterSpecLookupable lookupable)
     : base(FilterOperator.ADVANCED_INDEX, lookupable)
 {
     _readWriteLock = readWriteLock;
     _advancedIndex = (FilterSpecLookupableAdvancedIndex) lookupable;
     var quadTreeConfig = _advancedIndex.QuadTreeConfig;
     _quadTree = MXCIFQuadTreeFactory<object>.Make(
         quadTreeConfig.X, 
         quadTreeConfig.Y, 
         quadTreeConfig.Width, 
         quadTreeConfig.Height);
 }
Esempio n. 18
0
        public FilterParamIndexCompare(FilterSpecLookupable lookupable, IReaderWriterLock readWriteLock, FilterOperator filterOperator)
            : base(filterOperator, lookupable)
        {
            _constantsMap       = new OrderedDictionary <Object, EventEvaluator>();
            _constantsMapRwLock = readWriteLock;

            if ((filterOperator != FilterOperator.GREATER) &&
                (filterOperator != FilterOperator.GREATER_OR_EQUAL) &&
                (filterOperator != FilterOperator.LESS) &&
                (filterOperator != FilterOperator.LESS_OR_EQUAL))
            {
                throw new ArgumentException("Invalid filter operator for index of " + filterOperator);
            }
        }
        // expressions automatically coerce to the most upwards type
        // filters require the same type
        private static object HandleConstantsCoercion(FilterSpecLookupable lookupable, object constant)

        {
            var identNodeType = lookupable.ReturnType;
            if (!identNodeType.IsNumeric())
            {
                return constant; // no coercion required, other type checking performed by expression this comes from
            }

            if (constant == null) // null constant type
            {
                return null;
            }

            if (!constant.GetType().CanCoerce(identNodeType))
            {
                ThrowConversionError(constant.GetType(), identNodeType, lookupable.Expression);
            }

            var identNodeTypeBoxed = identNodeType.GetBoxedType();
            return CoercerFactory.CoerceBoxed(constant, identNodeTypeBoxed);
        }
Esempio n. 20
0
        /// <summary>
        ///     Determine among the passed in filter parameters any parameter that matches the given index on property name and
        ///     filter operator type. Returns null if none of the parameters matches the index.
        /// </summary>
        /// <param name="parameters">is the filter parameter list</param>
        /// <param name="index">is a filter parameter constant value index</param>
        /// <returns>filter parameter, or null if no matching parameter found.</returns>
        public static FilterValueSetParam FindParameter(
            ICollection<FilterValueSetParam> parameters,
            FilterParamIndexBase index)
        {
            if (index is FilterParamIndexLookupableBase)
            {
                var propBasedIndex = (FilterParamIndexLookupableBase) index;
                FilterSpecLookupable indexLookupable = propBasedIndex.Lookupable;
                FilterOperator indexOperator = propBasedIndex.FilterOperator;

                foreach (FilterValueSetParam parameter in parameters)
                {
                    FilterSpecLookupable lookupable = parameter.Lookupable;
                    FilterOperator paramOperator = parameter.FilterOperator;

                    if ((lookupable.Equals(indexLookupable)) &&
                        (paramOperator.Equals(indexOperator)))
                    {
                        return parameter;
                    }
                }
            }
            else
            {
                foreach (FilterValueSetParam parameter in parameters)
                {
                    FilterOperator paramOperator = parameter.FilterOperator;

                    if (paramOperator.Equals(index.FilterOperator))
                    {
                        return parameter;
                    }
                }
            }

            return null;
        }
Esempio n. 21
0
        public void TestNodeGetSet()
        {
            FilterHandle exprOne = new SupportFilterHandle();

            // Check pre-conditions
            Assert.IsTrue(_testNode.NodeRWLock != null);
            Assert.IsFalse(_testNode.Contains(exprOne));
            Assert.AreEqual(0, _testNode.FilterCallbackCount);
            Assert.AreEqual(0, _testNode.Indizes.Count);
            Assert.IsTrue(_testNode.IsEmpty());

            _testNode.Add(exprOne);

            // Check after add
            Assert.IsTrue(_testNode.Contains(exprOne));
            Assert.AreEqual(1, _testNode.FilterCallbackCount);
            Assert.IsFalse(_testNode.IsEmpty());

            // Add an indexOne
            EventType            eventType  = SupportEventTypeFactory.CreateBeanType(typeof(SupportBean));
            FilterSpecLookupable lookupable = new FilterSpecLookupable("IntPrimitive", eventType.GetGetter("IntPrimitive"), eventType.GetPropertyType("IntPrimitive"), false);
            FilterParamIndexBase indexOne   = new SupportFilterParamIndex(lookupable);

            _testNode.Add(indexOne);

            // Check after add
            Assert.AreEqual(1, _testNode.Indizes.Count);
            Assert.AreEqual(indexOne, _testNode.Indizes.FirstOrDefault());

            // Check removes
            Assert.IsTrue(_testNode.Remove(exprOne));
            Assert.IsFalse(_testNode.IsEmpty());
            Assert.IsFalse(_testNode.Remove(exprOne));
            Assert.IsTrue(_testNode.Remove(indexOne));
            Assert.IsFalse(_testNode.Remove(indexOne));
            Assert.IsTrue(_testNode.IsEmpty());
        }
Esempio n. 22
0
 public FilterParamIndexNotEquals(FilterSpecLookupable lookupable, IReaderWriterLock readWriteLock)
     : base(lookupable, readWriteLock, FilterOperator.NOT_EQUAL)
 {
 }
Esempio n. 23
0
 public FilterParamIndexEqualsIs(FilterSpecLookupable lookupable, IReaderWriterLock readWriteLock)
     : base(lookupable, readWriteLock, FilterOperator.IS)
 {
 }
Esempio n. 24
0
 /// <summary>Ctor. </summary>
 /// <param name="lookupable">stuff to use to interrogate</param>
 /// <param name="filterOperator">operator to apply</param>
 /// <param name="filterValue">value to look for</param>
 public FilterValueSetParamImpl(FilterSpecLookupable lookupable, FilterOperator filterOperator, Object filterValue)
 {
     _lookupable     = lookupable;
     _filterOperator = filterOperator;
     _filterValue    = filterValue;
 }
Esempio n. 25
0
 /// <summary>Constructor. </summary>
 /// <param name="filterOperator">is the type of comparison performed.</param>
 /// <param name="lookupable">is the lookupable</param>
 protected FilterParamIndexLookupableBase(FilterOperator filterOperator, FilterSpecLookupable lookupable)
     : base(filterOperator)
 {
     Lookupable = lookupable;
 }
Esempio n. 26
0
 protected FilterParamIndexEqualsBase(FilterSpecLookupable lookupable, IReaderWriterLock readWriteLock, FilterOperator filterOperator)
     : base(filterOperator, lookupable)
 {
     ConstantsMap       = new Dictionary <Object, EventEvaluator>().WithNullSupport();
     ConstantsMapRwLock = readWriteLock;
 }
Esempio n. 27
0
        /// <summary>
        /// Factory for indexes that store filter parameter constants for a given event property and filter operator.
        /// <para />
        /// Does not perform any check of validity of property name.
        /// </summary>
        /// <param name="lookupable">The lookupable.</param>
        /// <param name="lockFactory">The lock factory.</param>
        /// <param name="filterOperator">is the type of index to use</param>
        /// <returns>
        /// the proper index based on the filter operator type
        /// </returns>
        /// <exception cref="System.ArgumentException">Cannot create filter index instance for filter operator  + filterOperator</exception>
        public static FilterParamIndexBase CreateIndex(FilterSpecLookupable lookupable, FilterServiceGranularLockFactory lockFactory, FilterOperator filterOperator)
        {
            FilterParamIndexBase index;
            Type returnValueType = lookupable.ReturnType;

            // Handle all EQUAL comparisons
            if (filterOperator == FilterOperator.EQUAL)
            {
                index = new FilterParamIndexEquals(lookupable, lockFactory.ObtainNew());
                return(index);
            }

            // Handle all NOT-EQUAL comparisons
            if (filterOperator == FilterOperator.NOT_EQUAL)
            {
                index = new FilterParamIndexNotEquals(lookupable, lockFactory.ObtainNew());
                return(index);
            }

            if (filterOperator == FilterOperator.IS)
            {
                index = new FilterParamIndexEqualsIs(lookupable, lockFactory.ObtainNew());
                return(index);
            }

            if (filterOperator == FilterOperator.IS_NOT)
            {
                index = new FilterParamIndexNotEqualsIs(lookupable, lockFactory.ObtainNew());
                return(index);
            }

            // Handle all GREATER, LESS etc. comparisons
            if ((filterOperator == FilterOperator.GREATER) ||
                (filterOperator == FilterOperator.GREATER_OR_EQUAL) ||
                (filterOperator == FilterOperator.LESS) ||
                (filterOperator == FilterOperator.LESS_OR_EQUAL))
            {
                if (returnValueType != typeof(String))
                {
                    index = new FilterParamIndexCompare(lookupable, lockFactory.ObtainNew(), filterOperator);
                }
                else
                {
                    index = new FilterParamIndexCompareString(lookupable, lockFactory.ObtainNew(), filterOperator);
                }
                return(index);
            }

            // Handle all normal and inverted RANGE comparisons
            if (filterOperator.IsRangeOperator())
            {
                if (returnValueType != typeof(String))
                {
                    index = new FilterParamIndexDoubleRange(lookupable, lockFactory.ObtainNew(), filterOperator);
                }
                else
                {
                    index = new FilterParamIndexStringRange(lookupable, lockFactory.ObtainNew(), filterOperator);
                }
                return(index);
            }
            if (filterOperator.IsInvertedRangeOperator())
            {
                if (returnValueType != typeof(String))
                {
                    return(new FilterParamIndexDoubleRangeInverted(lookupable, lockFactory.ObtainNew(), filterOperator));
                }
                else
                {
                    return(new FilterParamIndexStringRangeInverted(lookupable, lockFactory.ObtainNew(), filterOperator));
                }
            }

            // Handle all IN and NOT IN comparisons
            if (filterOperator == FilterOperator.IN_LIST_OF_VALUES)
            {
                return(new FilterParamIndexIn(lookupable, lockFactory.ObtainNew()));
            }
            if (filterOperator == FilterOperator.NOT_IN_LIST_OF_VALUES)
            {
                return(new FilterParamIndexNotIn(lookupable, lockFactory.ObtainNew()));
            }

            // Handle all bool expression
            if (filterOperator == FilterOperator.BOOLEAN_EXPRESSION)
            {
                return(new FilterParamIndexBooleanExpr(lockFactory.ObtainNew()));
            }
            throw new ArgumentException("Cannot create filter index instance for filter operator " + filterOperator);
        }
Esempio n. 28
0
 protected FilterSpecParam(FilterSpecLookupable lookupable, FilterOperator filterOperator)
 {
     Lookupable     = lookupable;
     FilterOperator = filterOperator;
 }
Esempio n. 29
0
        /// <summary>
        /// Ctor.
        /// </summary>
        /// <param name="lookupable">is the event property or function</param>
        /// <param name="filterOperator">is expected to be the IN-list operator</param>
        /// <param name="listofValues">is a list of constants and event property names</param>
        /// <exception cref="ArgumentException">for illegal args</exception>
        public FilterSpecParamIn(
            FilterSpecLookupable lookupable,
            FilterOperator filterOperator,
            IList<FilterSpecParamInValue> listofValues)
            : base(lookupable, filterOperator)
        {
            _listOfValues = listofValues;

            foreach (FilterSpecParamInValue value in listofValues)
            {
                Type returnType = value.ReturnType;
                if (TypeHelper.IsCollectionMapOrArray(returnType))
                {
                    _hasCollMapOrArray = true;
                    break;
                }
            }

            if (_hasCollMapOrArray)
            {
                _adders = new InValueAdder[listofValues.Count];
                for (int i = 0; i < listofValues.Count; i++)
                {
                    Type returnType = listofValues[0].ReturnType;
                    if (returnType == null)
                    {
                        _adders[i] = InValueAdderPlain.INSTANCE;
                    }
                    else if (returnType.IsArray)
                    {
                        _adders[i] = InValueAdderArray.INSTANCE;
                    }
                    else if (returnType.IsGenericDictionary())
                    {
                        _adders[i] = InValueAdderMap.INSTANCE;
                    }
                    else if (returnType.IsGenericCollection())
                    {
                        _adders[i] = InValueAdderColl.INSTANCE;
                    }
                    else
                    {
                        _adders[i] = InValueAdderPlain.INSTANCE;
                    }
                }
            }

            bool isAllConstants = true;
            foreach (FilterSpecParamInValue value in listofValues)
            {
                if (!value.IsConstant)
                {
                    isAllConstants = false;
                    break;
                }
            }

            if (isAllConstants)
            {
                _inListConstantsOnly = GetFilterValues(null, null);
            }

            if ((filterOperator != FilterOperator.IN_LIST_OF_VALUES) &&
                ((filterOperator != FilterOperator.NOT_IN_LIST_OF_VALUES)))
            {
                throw new ArgumentException(
                    "Illegal filter operator " + filterOperator + " supplied to " +
                    "in-values filter parameter");
            }
        }
Esempio n. 30
0
        /// <summary>
        /// Factory for indexes that store filter parameter constants for a given event property and filter operator.
        /// <para />
        /// Does not perform any check of validity of property name.
        /// </summary>
        /// <param name="lookupable">The lookupable.</param>
        /// <param name="lockFactory">The lock factory.</param>
        /// <param name="filterOperator">is the type of index to use</param>
        /// <returns>
        /// the proper index based on the filter operator type
        /// </returns>
        /// <exception cref="System.ArgumentException">Cannot create filter index instance for filter operator  + filterOperator</exception>
        public static FilterParamIndexBase CreateIndex(
            FilterSpecLookupable lookupable,
            FilterServiceGranularLockFactory lockFactory,
            FilterOperator filterOperator)
        {
            FilterParamIndexBase index;
            Type returnValueType = lookupable.ReturnType;

            // Handle all EQUAL comparisons
            if (filterOperator == FilterOperator.EQUAL)
            {
                index = new FilterParamIndexEquals(lookupable, lockFactory.ObtainNew());
                return(index);
            }

            // Handle all NOT-EQUAL comparisons
            if (filterOperator == FilterOperator.NOT_EQUAL)
            {
                index = new FilterParamIndexNotEquals(lookupable, lockFactory.ObtainNew());
                return(index);
            }

            if (filterOperator == FilterOperator.IS)
            {
                index = new FilterParamIndexEqualsIs(lookupable, lockFactory.ObtainNew());
                return(index);
            }

            if (filterOperator == FilterOperator.IS_NOT)
            {
                index = new FilterParamIndexNotEqualsIs(lookupable, lockFactory.ObtainNew());
                return(index);
            }

            // Handle all GREATER, LESS etc. comparisons
            if ((filterOperator == FilterOperator.GREATER) ||
                (filterOperator == FilterOperator.GREATER_OR_EQUAL) ||
                (filterOperator == FilterOperator.LESS) ||
                (filterOperator == FilterOperator.LESS_OR_EQUAL))
            {
                if (returnValueType != typeof(String))
                {
                    index = new FilterParamIndexCompare(lookupable, lockFactory.ObtainNew(), filterOperator);
                }
                else
                {
                    index = new FilterParamIndexCompareString(lookupable, lockFactory.ObtainNew(), filterOperator);
                }
                return(index);
            }

            // Handle all normal and inverted RANGE comparisons
            if (filterOperator.IsRangeOperator())
            {
                if (returnValueType != typeof(String))
                {
                    index = new FilterParamIndexDoubleRange(lookupable, lockFactory.ObtainNew(), filterOperator);
                }
                else
                {
                    index = new FilterParamIndexStringRange(lookupable, lockFactory.ObtainNew(), filterOperator);
                }
                return(index);
            }
            if (filterOperator.IsInvertedRangeOperator())
            {
                if (returnValueType != typeof(String))
                {
                    return(new FilterParamIndexDoubleRangeInverted(lookupable, lockFactory.ObtainNew(), filterOperator));
                }
                else
                {
                    return(new FilterParamIndexStringRangeInverted(lookupable, lockFactory.ObtainNew(), filterOperator));
                }
            }

            // Handle all IN and NOT IN comparisons
            if (filterOperator == FilterOperator.IN_LIST_OF_VALUES)
            {
                return(new FilterParamIndexIn(lookupable, lockFactory.ObtainNew()));
            }
            if (filterOperator == FilterOperator.NOT_IN_LIST_OF_VALUES)
            {
                return(new FilterParamIndexNotIn(lookupable, lockFactory.ObtainNew()));
            }

            // Handle all bool expression
            if (filterOperator == FilterOperator.BOOLEAN_EXPRESSION)
            {
                return(new FilterParamIndexBooleanExpr(lockFactory.ObtainNew()));
            }

            // Handle advanced-index
            if (filterOperator == FilterOperator.ADVANCED_INDEX)
            {
                FilterSpecLookupableAdvancedIndex advLookable = (FilterSpecLookupableAdvancedIndex)lookupable;
                if (advLookable.IndexType.Equals(EngineImportApplicationDotMethodPointInsideRectangle.INDEX_TYPE_NAME))
                {
                    return(new FilterParamIndexQuadTreePointRegion(lockFactory.ObtainNew(), lookupable));
                }
                else if (advLookable.IndexType.Equals(EngineImportApplicationDotMethodRectangeIntersectsRectangle.INDEX_TYPE_NAME))
                {
                    return(new FilterParamIndexQuadTreeMXCIF(lockFactory.ObtainNew(), lookupable));
                }
                else
                {
                    throw new IllegalStateException("Unrecognized index type " + advLookable.IndexType);
                }
            }

            throw new ArgumentException("Cannot create filter index instance for filter operator " + filterOperator);
        }