Beispiel #1
0
 public CollectionService(PageService pager, IndexService indexer, DataService data, TransactionService trans, Logger log)
 {
     _pager   = pager;
     _indexer = indexer;
     _data    = data;
     _trans   = trans;
     _log     = log;
 }
Beispiel #2
0
 /// <summary>
 /// Create instances for all engine services
 /// </summary>
 private void InitializeServices()
 {
     _cache       = new CacheService(_disk, _log);
     _pager       = new PageService(_disk, _crypto, _cache, _log);
     _indexer     = new IndexService(_pager, _log);
     _data        = new DataService(_pager, _log);
     _trans       = new TransactionService(_disk, _crypto, _pager, _cache, _cacheSize, _log);
     _collections = new CollectionService(_pager, _indexer, _data, _trans, _log);
 }
Beispiel #3
0
 internal override IEnumerable <IndexNode> ExecuteIndex(IndexService indexer, CollectionIndex index)
 {
     foreach (var value in _values.Distinct())
     {
         foreach (var node in Query.EQ(this.Field, value).ExecuteIndex(indexer, index))
         {
             yield return(node);
         }
     }
 }
Beispiel #4
0
        internal override IEnumerable <IndexNode> Run(CollectionPage col, IndexService indexer)
        {
            var left  = _left.Run(col, indexer);
            var right = _right.Run(col, indexer);

            // if any query (left/right) is FullScan, this query is full scan too
            this.UseIndex  = _left.UseIndex && _right.UseIndex;
            this.UseFilter = _left.UseFilter || _right.UseFilter;

            return(left.Union(right, new IndexNodeComparer()));
        }
Beispiel #5
0
        internal override IEnumerable <IndexNode> ExecuteIndex(IndexService indexer, CollectionIndex index)
        {
            // define order
            var order = _start.CompareTo(_end) <= 0 ? Query.Ascending : Query.Descending;

            // find first indexNode
            var node = indexer.Find(index, _start, true, order);

            // returns (or not) equals start value
            while (node != null)
            {
                var diff = node.Key.CompareTo(_start);

                // if current value are not equals start, go out this loop
                if (diff != 0)
                {
                    break;
                }

                if (_startEquals)
                {
                    yield return(node);
                }

                node = indexer.GetNode(node.NextPrev(0, order));
            }

            // navigate using next[0] do next node - if less or equals returns
            while (node != null)
            {
                var diff = node.Key.CompareTo(_end);

                if (_endEquals && diff == 0)
                {
                    yield return(node);
                }
                else if (diff == -order)
                {
                    yield return(node);
                }
                else
                {
                    break;
                }

                node = indexer.GetNode(node.NextPrev(0, order));
            }
        }
Beispiel #6
0
        internal override IEnumerable <IndexNode> Run(CollectionPage col, IndexService indexer)
        {
            // run base query
            var result = _query.Run(col, indexer);

            this.UseIndex  = _query.UseIndex;
            this.UseFilter = _query.UseFilter;

            if (_query.UseIndex)
            {
                // if is by index, resolve here
                var all = new QueryAll("_id", _order).Run(col, indexer);

                return(all.Except(result, new IndexNodeComparer()));
            }
            else
            {
                // if is by document, must return all nodes to be ExecuteDocument after
                return(result);
            }
        }
Beispiel #7
0
        internal override IEnumerable <IndexNode> ExecuteIndex(IndexService indexer, CollectionIndex index)
        {
            foreach (var node in indexer.FindAll(index, Query.Ascending))
            {
                // compares only with are same type
                if (node.Key.Type == _value.Type || (node.Key.IsNumber && _value.IsNumber))
                {
                    var diff = node.Key.CompareTo(_value);

                    if (diff == 1 || (!_equals && diff == 0))
                    {
                        break;
                    }

                    if (node.IsHeadTail(index))
                    {
                        yield break;
                    }

                    yield return(node);
                }
            }
        }
Beispiel #8
0
 internal override IEnumerable <IndexNode> ExecuteIndex(IndexService indexer, CollectionIndex index)
 {
     return(indexer.FindAll(index, _order));
 }
Beispiel #9
0
 /// <summary>
 /// Abstract method that must be implement for index seek/scan - Returns IndexNodes that match with index
 /// </summary>
 internal abstract IEnumerable <IndexNode> ExecuteIndex(IndexService indexer, CollectionIndex index);
Beispiel #10
0
 internal override IEnumerable <IndexNode> ExecuteIndex(IndexService indexer, CollectionIndex index)
 {
     throw new NotSupportedException();
 }
Beispiel #11
0
 internal override IEnumerable <IndexNode> ExecuteIndex(IndexService indexer, CollectionIndex index)
 {
     yield break;
 }
Beispiel #12
0
 internal override IEnumerable <IndexNode> ExecuteIndex(IndexService indexer, CollectionIndex index)
 {
     return(indexer
            .FindAll(index, Query.Ascending)
            .Where(x => x.Key.CompareTo(_value) != 0));
 }
Beispiel #13
0
 internal override IEnumerable <IndexNode> ExecuteIndex(IndexService indexer, CollectionIndex index)
 {
     return(indexer
            .FindAll(index, Query.Ascending)
            .Where(x => x.Key.IsString && x.Key.AsString.Contains(_value)));
 }