Пример #1
1
        internal override IEnumerable<IndexNode> ExecuteIndex(IndexService indexer, CollectionIndex index)
        {
            var start = _start.Normalize(index.Options);
            var end = _end.Normalize(index.Options);

            // define order
            var order = start.CompareTo(end) <= 0 ? Query.Ascending : Query.Descending;

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

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

                if (diff == 0 || diff != order)
                {
                    yield return node;
                }
                else
                {
                    break;
                }

                node = indexer.GetNode(node.NextPrev(0, order));
            }
        }
Пример #2
0
        internal override IEnumerable <IndexNode> ExecuteIndex(IndexService indexer, CollectionIndex index)
        {
            var start = _start.Normalize(index.Options);
            var end   = _end.Normalize(index.Options);

            // define order
            var order = start.CompareTo(end) <= 0 ? Query.Ascending : Query.Descending;

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

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

                if (diff == 0 || diff != order)
                {
                    yield return(node);
                }
                else
                {
                    break;
                }

                node = indexer.GetNode(node.NextPrev(0, order));
            }
        }
Пример #3
0
        internal override IEnumerable <IndexNode> Run(CollectionPage col, IndexService indexer)
        {
            var result = _query.Run(col, indexer);
            var all    = new QueryAll("_id", _order).Run(col, indexer);

            return(all.Except(result, new IndexNodeComparer()));
        }
Пример #4
0
        internal override IEnumerable <IndexNode> ExecuteIndex(IndexService indexer, CollectionIndex index)
        {
            var value = _value.Normalize(index.Options);
            var node  = indexer.Find(index, value, false, Ascending);

            if (node == null)
            {
                yield break;
            }

            yield return(node);

            if (index.Options.Unique == false)
            {
                // navigate using next[0] do next node - if equals, returns
                while (!node.Next[0].IsEmpty && ((node = indexer.GetNode(node.Next[0])).Key.CompareTo(value) == 0))
                {
                    if (node.IsHeadTail(index))
                    {
                        yield break;
                    }

                    yield return(node);
                }
            }
        }
Пример #5
0
        internal override IEnumerable <IndexNode> ExecuteIndex(IndexService indexer, CollectionIndex index)
        {
            // find first indexNode
            var node = indexer.Find(index, _value, true, Query.Ascending);

            if (node == null)
            {
                yield break;
            }

            // move until next is last
            while (node != null)
            {
                // 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))
                    {
                        if (node.IsHeadTail(index))
                        {
                            yield break;
                        }

                        yield return(node);
                    }
                }

                node = indexer.GetNode(node.Next[0]);
            }
        }
        internal override IEnumerable <IndexNode> ExecuteIndex(IndexService indexer, CollectionIndex index)
        {
            // find first indexNode
            var value = _value.Normalize(index.Options);
            var node  = indexer.Find(index, value, true, Ascending);
            var str   = value.AsString;

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

                // value will not be null because null occurs before string (bsontype sort order)
                if (valueString.StartsWith(str))
                {
                    if (!node.DataBlock.IsEmpty)
                    {
                        yield return(node);
                    }
                }
                else
                {
                    break; // if not more startswith, stop scanning
                }

                node = indexer.GetNode(node.Next[0]);
            }
        }
Пример #7
0
        internal override IEnumerable<IndexNode> ExecuteIndex(IndexService indexer, CollectionIndex index)
        {
            // find first indexNode
            var value = _value.Normalize(index.Options);
            var node = indexer.Find(index, value, true, Query.Ascending);
            var str = value.AsString;

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

                // value will not be null because null occurs before string (bsontype sort order)
                if (valueString.StartsWith(str))
                {
                    if (!node.DataBlock.IsEmpty)
                    {
                        yield return node;
                    }
                }
                else
                {
                    break; // if not more startswith, stop scanning
                }

                node = indexer.GetNode(node.Next[0]);
            }
        }
Пример #8
0
 public CollectionService(CacheService cache, PageService pager, IndexService indexer, DataService data)
 {
     _cache = cache;
     _pager = pager;
     _indexer = indexer;
     _data = data;
 }
Пример #9
0
        internal override IEnumerable<IndexNode> Run(CollectionPage col, IndexService indexer)
        {
            var left = _left.Run(col, indexer);
            var right = _right.Run(col, indexer);

            return left.Union(right, new IndexNodeComparer());
        }
Пример #10
0
        internal override IEnumerable<IndexNode> Run(CollectionPage col, IndexService indexer)
        {
            var result = _query.Run(col, indexer);
            var all = new QueryAll("_id", _order).Run(col, indexer);

            return all.Except(result, new IndexNodeComparer());
        }
Пример #11
0
        internal override IEnumerable <IndexNode> ExecuteIndex(IndexService indexer, CollectionIndex index)
        {
            var v = _value.Normalize(index.Options);

            return(indexer
                   .FindAll(index, Query.Ascending)
                   .Where(x => x.Key.IsString && x.Key.AsString.Contains(v)));
        }
Пример #12
0
 public CollectionService(PageService pager, IndexService indexer, DataService data, TransactionService trans, Logger log)
 {
     _pager   = pager;
     _indexer = indexer;
     _data    = data;
     _trans   = trans;
     _log     = log;
 }
Пример #13
0
        internal override IEnumerable<IndexNode> ExecuteIndex(IndexService indexer, CollectionIndex index)
        {
            var v = _value.Normalize(index.Options);

            return indexer
                .FindAll(index, Query.Ascending)
                .Where(x => x.Key.IsString && x.Key.AsString.Contains(v));
        }
Пример #14
0
 public CollectionService(PageService pager, IndexService indexer, DataService data, TransactionService trans, Logger log)
 {
     _pager = pager;
     _indexer = indexer;
     _data = data;
     _trans = trans;
     _log = log;
 }
Пример #15
0
 /// <summary>
 /// Create instances for all engine services
 /// </summary>
 private void InitializeServices()
 {
     _pager       = new PageService(_disk, _crypto, _log);
     _indexer     = new IndexService(_pager, _log);
     _data        = new DataService(_pager, _log);
     _trans       = new TransactionService(_disk, _crypto, _pager, _cacheSize, _log);
     _collections = new CollectionService(_pager, _indexer, _data, _trans, _log);
 }
Пример #16
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;
         }
     }
 }
Пример #17
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);
         }
     }
 }
Пример #18
0
        internal override IEnumerable<IndexNode> Run(CollectionPage col, IndexService indexer)
        {
            // ignore QueryAll on AND expression (in both sides)
            if (_left is QueryAll) return _right.Run(col, indexer);
            if (_right is QueryAll) return _left.Run(col, indexer);

            var left = _left.Run(col, indexer);
            var right = _right.Run(col, indexer);

            return left.Intersect(right, new IndexNodeComparer());
        }
Пример #19
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()));
        }
Пример #20
0
        /// <summary>
        /// Find witch index will be used and run Execute method
        /// </summary>
        internal virtual IEnumerable <IndexNode> Run(CollectionPage col, IndexService indexer)
        {
            // get index for this query
            var index = col.GetIndex(this.Field);

            // no index? throw an index not found exception to auto-create in LiteDatabse
            if (index == null)
            {
                throw new IndexNotFoundException(col.CollectionName, this.Field);
            }

            // execute query to get all IndexNodes
            return(this.ExecuteIndex(indexer, index));
        }
Пример #21
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));
            }
        }
Пример #22
0
        internal override IEnumerable <IndexNode> Run(CollectionPage col, IndexService indexer)
        {
            // ignore QueryAll on AND expression (in both sides)
            if (_left is QueryAll)
            {
                return(_right.Run(col, indexer));
            }
            if (_right is QueryAll)
            {
                return(_left.Run(col, indexer));
            }

            var left  = _left.Run(col, indexer);
            var right = _right.Run(col, indexer);

            return(left.Intersect(right, new IndexNodeComparer()));
        }
Пример #23
0
        internal override IEnumerable <IndexNode> ExecuteIndex(IndexService indexer, CollectionIndex index)
        {
            foreach (var node in indexer.FindAll(index, Query.Ascending))
            {
                var diff = node.Key.CompareTo(_value);

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

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

                yield return(node);
            }
        }
Пример #24
0
        internal override IEnumerable<IndexNode> ExecuteIndex(IndexService indexer, CollectionIndex index)
        {
            var node = indexer.Find(index, _value, false, Query.Ascending);

            if (node == null) yield break;

            yield return node;

            if (index.Unique == false)
            {
                // navigate using next[0] do next node - if equals, returns
                while (!node.Next[0].IsEmpty && ((node = indexer.GetNode(node.Next[0])).Key.CompareTo(_value) == 0))
                {
                    if (node.IsHeadTail(index)) yield break;

                    yield return node;
                }
            }
        }
Пример #25
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);
            }
        }
Пример #26
0
        public DbEngine(IDiskService disk, Logger log)
        {
            // initialize disk service and check if database exists
            var isNew = disk.Initialize();

            // new database? create new datafile
            if (isNew)
            {
                disk.CreateNew();
            }

            _log  = log;
            _disk = disk;

            // initialize all services
            _cache       = new CacheService();
            _pager       = new PageService(_disk, _cache);
            _indexer     = new IndexService(_pager);
            _data        = new DataService(_pager);
            _collections = new CollectionService(_pager, _indexer, _data);
            _transaction = new TransactionService(_disk, _pager, _cache);
        }
Пример #27
0
        internal override IEnumerable<IndexNode> ExecuteIndex(IndexService indexer, CollectionIndex index)
        {
            // find first indexNode
            var value = _value.Normalize(index.Options);
            var node = indexer.Find(index, value, true, Query.Ascending);

            if (node == null) yield break;

            // move until next is last
            while (node != null)
            {
                var diff = node.Key.CompareTo(value);

                if (diff == 1 || (_equals && diff == 0))
                {
                    if (node.IsHeadTail(index)) yield break;

                    yield return node;
                }

                node = indexer.GetNode(node.Next[0]);
            }
        }
Пример #28
0
        public DbEngine(IDiskService disk, Logger log)
        {
            // initialize disk service and check if database exists
            var isNew = disk.Initialize();

            // new database? just create header page and save it
            if (isNew)
            {
                disk.WritePage(0, new HeaderPage().WritePage());
            }

            _log  = log;
            _disk = disk;

            // initialize all services
            _cache       = new CacheService();
            _pager       = new PageService(_disk, _cache);
            _indexer     = new IndexService(_pager);
            _data        = new DataService(_pager);
            _collections = new CollectionService(_pager, _indexer, _data);
            _transaction = new TransactionService(_disk, _pager, _cache);

            // check user verion
        }
Пример #29
0
 internal override IEnumerable <IndexNode> ExecuteIndex(IndexService indexer, CollectionIndex index)
 {
     yield break;
 }
Пример #30
0
 /// <summary>
 /// Create instances for all engine services
 /// </summary>
 private void InitializeServices()
 {
     _pager = new PageService(_disk, _crypto, _log);
     _indexer = new IndexService(_pager, _log);
     _data = new DataService(_pager, _log);
     _trans = new TransactionService(_disk, _crypto, _pager, _cacheSize, _log);
     _collections = new CollectionService(_pager, _indexer, _data, _trans, _log);
 }
Пример #31
0
 public CollectionService(PageService pager, IndexService indexer, DataService data)
 {
     _pager   = pager;
     _indexer = indexer;
     _data    = data;
 }
Пример #32
0
 internal override IEnumerable<IndexNode> ExecuteIndex(IndexService indexer, CollectionIndex index)
 {
     yield break;
 }
Пример #33
0
 internal override IEnumerable <IndexNode> ExecuteIndex(IndexService indexer, CollectionIndex index)
 {
     return(indexer.FindAll(index, _order));
 }
Пример #34
0
 internal override IEnumerable<IndexNode> ExecuteIndex(IndexService indexer, CollectionIndex index)
 {
     throw new NotSupportedException();
 }
Пример #35
0
 internal override IEnumerable<IndexNode> ExecuteIndex(IndexService indexer, CollectionIndex index)
 {
     return indexer.FindAll(index, _order);
 }
Пример #36
0
        internal override IEnumerable <IndexNode> ExecuteIndex(IndexService indexer, CollectionIndex index)
        {
            this.ExecuteMode = QueryExecuteMode.FullScan;

            return(indexer.FindAll(index, Query.Ascending));
        }
Пример #37
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);
Пример #38
0
        /// <summary>
        /// Find witch index will be used and run Execute method
        /// </summary>
        internal virtual IEnumerable<IndexNode> Run(CollectionPage col, IndexService indexer)
        {
            // get index for this query
            var index = col.GetIndex(this.Field);

            // no index? throw an index not found exception to auto-create in LiteDatabse
            if (index == null) throw new IndexNotFoundException(col.CollectionName, this.Field);

            // execute query to get all IndexNodes
            return this.ExecuteIndex(indexer, index);
        }
Пример #39
0
 internal override IEnumerable <IndexNode> ExecuteIndex(IndexService indexer, CollectionIndex index)
 {
     throw new NotSupportedException();
 }
Пример #40
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);
Пример #41
0
 public CollectionService(PageService pager, IndexService indexer, DataService data)
 {
     _pager = pager;
     _indexer = indexer;
     _data = data;
 }
Пример #42
0
 public CollectionService(PageService pager, IndexService indexer)
 {
     _pager   = pager;
     _indexer = indexer;
 }
Пример #43
0
        internal override IEnumerable <IndexNode> ExecuteIndex(IndexService indexer, CollectionIndex index)
        {
            var value = _value.Normalize(index.Options);

            return(indexer.FindAll(index, Query.Ascending).Where(x => x.Key.CompareTo(value) != 0));
        }
Пример #44
-1
        internal override IEnumerable<IndexNode> ExecuteIndex(IndexService indexer, CollectionIndex index)
        {
            foreach (var node in indexer.FindAll(index, Query.Ascending))
            {
                var diff = node.Key.CompareTo(_value);

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

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

                yield return node;
            }
        }
Пример #45
-1
        internal override IEnumerable<IndexNode> ExecuteIndex(IndexService indexer, CollectionIndex index)
        {
            var value = _value.Normalize(index.Options);

            return indexer.FindAll(index, Query.Ascending).Where(x => x.Key.CompareTo(value) != 0);
        }