예제 #1
0
        internal override void Execute(QueryContext queryContext, Predicate nextPredicate)
        {
            if(ChildPredicate!=null)
                ChildPredicate.Execute(queryContext, nextPredicate);

            queryContext.Tree.Reduce();
            CacheEntry entry = null;

            decimal sum = 0;

            if (queryContext.Tree.LeftList.Count > 0)
            {
                foreach (string key in queryContext.Tree.LeftList)
                {
                    object attribValue = queryContext.Index.GetAttributeValue(key, AttributeName);
                    if (attribValue != null)
                    {
                        Type type = attribValue.GetType();
                        if ((type == typeof(bool)) || (type == typeof(DateTime)) || (type == typeof(string)) || (type == typeof(char)))
                            throw new Exception("SUM can only be applied to integral data types.");

                        sum += Convert.ToDecimal(attribValue);
                    }
                }

                base.SetResult(queryContext, AggregateFunctionType.SUM, Decimal.Round(sum, 4));
            }
            else
            {
                base.SetResult(queryContext, AggregateFunctionType.SUM, null);
            }
        }
예제 #2
0
        internal override void Execute(QueryContext queryContext, Predicate nextPredicate)
        {
            if (typename == "*")
                throw new ParserException("Incorrect query format. \'*\' is not supported.");

            if (queryContext.IndexManager == null)
                throw new TypeIndexNotDefined("Index is not defined for '" + typename.ToString() + "'");

            queryContext.TypeName = typename;

            if (queryContext.Index == null) //try to get virtual index
            {
                //in case of DisableException is true, exception will not be thrown, and return new attribute index.
                if (QueryIndexManager.DisableException)
                {
                    queryContext.Index = new AttributeIndex(null, queryContext.Cache.Context.CacheRoot.Name, null);
                    return;
                }

                throw new TypeIndexNotDefined("Index is not defined for '" + typename.ToString() + "'");
            }
            else
            {
                
                //populate the tree for normal queries...
                if (nextPredicate == null && queryContext.PopulateTree)
                {
                    queryContext.Tree.Populate(queryContext.Index.GetEnumerator(typename));
                }
                else
                {
                    nextPredicate.Execute(queryContext, null);
                }
            }
        }
예제 #3
0
        internal override void Execute(QueryContext queryContext, Predicate nextPredicate)
        {
            bool sortAscending = true;
            bool normalizePredicates = true;

            if (Inverse)
                sortAscending = false;

            SortedList list = new SortedList(new QueryResultComparer(sortAscending));

            for (int i = 0; i < members.Count; i++)
            {
                Predicate predicate = (Predicate)members[i];
                bool isOfTypePredicate = predicate is IsOfTypePredicate;

                if (isOfTypePredicate)
                {
                    predicate.Execute(queryContext, (Predicate)members[++i]);
                    normalizePredicates = false;
                }
                else
                {
                    predicate.ExecuteInternal(queryContext, ref list);
                }
            }

            if (normalizePredicates)
            {
                if (Inverse)
                    queryContext.Tree.RightList = GetUnion(list);
                else
                    queryContext.Tree.RightList = GetIntersection(list);
            }
        }
예제 #4
0
        internal override void Execute(QueryContext queryContext, Predicate nextPredicate)
        {
            if(ChildPredicate!=null)
                ChildPredicate.Execute(queryContext, nextPredicate);

            queryContext.Tree.Reduce();
            decimal count = queryContext.Tree.LeftList.Count;
            base.SetResult(queryContext, AggregateFunctionType.COUNT, count);
        }
예제 #5
0
        internal override void Execute(QueryContext queryContext, Predicate nextPredicate)
        {
            if(ChildPredicate!=null)
                ChildPredicate.Execute(queryContext, nextPredicate);

            queryContext.Tree.Reduce();
            CacheEntry entry = null;

            IComparable max = null;
            bool initialized = false;
            Type type = null;
            foreach (string key in queryContext.Tree.LeftList)
            {
                CacheEntry cacheentry = queryContext.Cache.GetEntryInternal(key, false);
                IComparable current = (IComparable)queryContext.Index.GetAttributeValue(key, AttributeName, cacheentry.IndexInfo);

                if (current != null)
                {
                    type = current.GetType();
                    if (type == typeof(bool))
                        throw new Exception("MAX cannot be applied to Boolean data type.");

                    if (!initialized)
                    {
                        max = current;
                        initialized = true;
                    }

                    if (current.CompareTo(max) > 0)
                        max = current;
                }
            }
            if (type != null)
            {

                if ((type != typeof(DateTime)) && (type != typeof(string)) && (type != typeof(char)))
                {
                    if (max != null)
                    {
                        base.SetResult(queryContext, AggregateFunctionType.MAX, Convert.ToDecimal(max));
                        return;
                    }
                }
            }
            base.SetResult(queryContext, AggregateFunctionType.MAX, max);
        }
        /// <summary>
        /// See attribute-level indexes can't be used in this predicate.
        /// </summary>
        /// <param name="queryContext"></param>
        internal override void Execute(QueryContext queryContext, Predicate nextPredicate)
        {
            ArrayList keyList = null;
            pattern = (string)generator.Evaluate(((MemberFunction)functor).MemberName, queryContext.AttributeValues);
            pattern = pattern.Trim('\'');

            AttributeIndex index = queryContext.Index;
            IIndexStore store = ((MemberFunction)functor).GetStore(index);

            if (store != null)
            {
                if (Inverse)
                    keyList = store.GetData(pattern, ComparisonType.NOT_LIKE);
                else
                    keyList = store.GetData(pattern, ComparisonType.LIKE);

                if (keyList != null && keyList.Count > 0)
                {
                    IEnumerator keyListEnum = keyList.GetEnumerator();

                    if (queryContext.PopulateTree)
                    {
                        queryContext.Tree.RightList = keyList;

                        queryContext.PopulateTree = false;
                    }
                    else
                    {
                        while (keyListEnum.MoveNext())
                        {
                            if (queryContext.Tree.LeftList.Contains(keyListEnum.Current))
                                queryContext.Tree.Shift(keyListEnum.Current);
                        }
                    }
                }
            }
            else
            {
                throw new AttributeIndexNotDefined("Index is not defined for attribute '" + ((MemberFunction)functor).MemberName + "'");
            }
        }
예제 #7
0
        internal override void Execute(QueryContext queryContext, Predicate nextPredicate)
        {
            if(ChildPredicate!=null)
                ChildPredicate.Execute(queryContext, nextPredicate);

            queryContext.Tree.Reduce();
            CacheEntry entry = null;

            decimal sum = 0;

            if (queryContext.Tree.LeftList.Count > 0)
            {
                foreach (string key in queryContext.Tree.LeftList)
                {
                    CacheEntry cacheentry = queryContext.Cache.GetEntryInternal(key, false);
                    object attribValue = queryContext.Index.GetAttributeValue(key, AttributeName, cacheentry.IndexInfo);

                    if (attribValue != null)
                    {
                        Type type = attribValue.GetType();
                        if ((type == typeof(bool)) || (type == typeof(DateTime)) || (type == typeof(string)) || (type == typeof(char)))
                            throw new Exception("AVG can only be applied to integral data types.");

                        sum += Convert.ToDecimal(attribValue);
                    }

                }

                AverageResult avgResult = new AverageResult();
                avgResult.Sum = sum;
                avgResult.Count = queryContext.Tree.LeftList.Count;
                //put the count and the sum
                base.SetResult(queryContext, AggregateFunctionType.AVG, avgResult);
            }
            else
            {
                base.SetResult(queryContext, AggregateFunctionType.AVG, null);
            }
        }
예제 #8
0
 internal virtual IDictionary SearchEntriesInternal(Predicate pred, IDictionary values)
 {
     return null;
 }
예제 #9
0
 internal virtual QueryContext SearchInternal(Predicate pred, IDictionary values)
 {
     return null;
 }
예제 #10
0
 internal virtual void Execute(QueryContext queryContext, Predicate nextPredicate) { }
예제 #11
0
        /// <summary>
        ///         /// returns the keylist fullfilling the specified criteria.
        /// </summary>
        /// <param name="queryString">a string describing the search criteria.</param>
        /// <returns>a list of keys.</returns>
        internal override QueryContext SearchInternal(Predicate pred, IDictionary values)
        {
            QueryContext queryContext = new QueryContext(this);
            queryContext.AttributeValues = values;
            queryContext.CacheContext = _context.CacheRoot.Name;

            try
            {
                pred.Execute(queryContext, null);
                return queryContext;
            }
            catch (Exception)
            {
                throw;
            }
        }
예제 #12
0
 internal override QueryContext SearchInternal(Predicate pred, IDictionary values)
 {
     return null;
 }
예제 #13
0
        internal override void Execute(QueryContext queryContext, Predicate nextPredicate)
        {
            AttributeIndex index = queryContext.Index;
            IIndexStore store = ((MemberFunction)functor).GetStore(index);

            if (store != null)
            {
                members = queryContext.AttributeValues[((MemberFunction)functor).MemberName] as ArrayList;

                if (members == null)
                {
                    if (queryContext.AttributeValues.Count > 0)
                    {
                        members = new ArrayList();
                        members.Add(queryContext.AttributeValues[((MemberFunction)functor).MemberName]);
                    }
                    else
                    {
                        throw new Exception("Value(s) not specified for indexed attribute " + ((MemberFunction)functor).MemberName + ".");
                    }
                }

                ArrayList keyList = new ArrayList();

                if (!Inverse)
                {
                    ArrayList distinctMembers = new ArrayList();

                    for (int i = 0; i < members.Count; i++)
                    {
                        if (!distinctMembers.Contains(members[i]))
                        {
                            distinctMembers.Add(members[i]);
                            ArrayList temp = store.GetData(members[i], ComparisonType.EQUALS);
                            if (temp != null)
                                if (temp.Count > 0)
                                    keyList.AddRange(temp);
                        }
                    }
                }
                else
                {
                    ArrayList distinctMembers = new ArrayList();

                    ArrayList temp = store.GetData(members[0], ComparisonType.NOT_EQUALS);
                    if (temp != null)
                    {
                        if (temp.Count > 0)
                        {
                            for (int i = 0; i < members.Count; i++)
                            {
                                if (!distinctMembers.Contains(members[i]))
                                {
                                    distinctMembers.Add(members[i]);         
                                    ArrayList extras = store.GetData(members[i], ComparisonType.EQUALS);
                                    if (extras != null)
                                    {
                                        IEnumerator ie = extras.GetEnumerator();
                                        if (ie != null)
                                        {
                                            while (ie.MoveNext())
                                            {
                                                if (temp.Contains(ie.Current))
                                                    temp.Remove(ie.Current);
                                            }
                                        }
                                    }
                                }
                                keyList = temp;
                            }
                        }
                    }
                }

                if (keyList != null && keyList.Count > 0)
                {
                    IEnumerator keyListEnum = keyList.GetEnumerator();

                    if (queryContext.PopulateTree)
                    {
                       queryContext.Tree.RightList = keyList;

                        queryContext.PopulateTree = false;
                    }
                    else
                    {
                        while (keyListEnum.MoveNext())
                        {
                            if (queryContext.Tree.LeftList.Contains(keyListEnum.Current))
                                queryContext.Tree.Shift(keyListEnum.Current);
                        }
                    }
                }
            }
            else
            {
                throw new AttributeIndexNotDefined("Index is not defined for attribute '" + ((MemberFunction)functor).MemberName + "'");
            }
        }
예제 #14
0
        internal override void Execute(QueryContext queryContext, Predicate nextPredicate)
        {
            throw new ParserException("Incorrect query format. \'" + this.ToString() + "\' not supported.");

        }