示例#1
0
        public IEnumerable <JsonDocument> GetDocumentsWithIdStartingWith(string idPrefix, int start, int take)
        {
            Api.JetSetCurrentIndex(session, Documents, "by_key");
            Api.MakeKey(session, Documents, idPrefix, Encoding.Unicode, MakeKeyGrbit.NewKey);
            if (Api.TrySeek(session, Documents, SeekGrbit.SeekGE) == false)
            {
                return(Enumerable.Empty <JsonDocument>());
            }

            var optimizer = new OptimizedIndexReader(Session, Documents, take);

            do
            {
                Api.MakeKey(session, Documents, idPrefix, Encoding.Unicode, MakeKeyGrbit.NewKey | MakeKeyGrbit.SubStrLimit);
                if (Api.TrySetIndexRange(session, Documents, SetIndexRangeGrbit.RangeUpperLimit | SetIndexRangeGrbit.RangeInclusive) == false)
                {
                    return(Enumerable.Empty <JsonDocument>());
                }

                while (start > 0)
                {
                    if (Api.TryMoveNext(session, Documents) == false)
                    {
                        return(Enumerable.Empty <JsonDocument>());
                    }
                    start--;
                }

                optimizer.Add();
            } while (Api.TryMoveNext(session, Documents) && optimizer.Count < take);

            return(optimizer.Select(ReadCurrentDocument));
        }
示例#2
0
        public IEnumerable <AttachmentInformation> GetAttachmentsStartingWith(string idPrefix, int start, int pageSize)
        {
            Api.JetSetCurrentIndex(session, Files, "by_name");
            Api.MakeKey(session, Files, idPrefix, Encoding.Unicode, MakeKeyGrbit.NewKey);
            if (Api.TrySeek(session, Files, SeekGrbit.SeekGE) == false)
            {
                return(Enumerable.Empty <AttachmentInformation>());
            }

            var optimizer = new OptimizedIndexReader(Session, Files, pageSize);

            do
            {
                Api.MakeKey(session, Files, idPrefix, Encoding.Unicode, MakeKeyGrbit.NewKey | MakeKeyGrbit.SubStrLimit);
                if (Api.TrySetIndexRange(session, Files, SetIndexRangeGrbit.RangeUpperLimit | SetIndexRangeGrbit.RangeInclusive) == false)
                {
                    return(Enumerable.Empty <AttachmentInformation>());
                }

                while (start > 0)
                {
                    if (Api.TryMoveNext(session, Files) == false)
                    {
                        return(Enumerable.Empty <AttachmentInformation>());
                    }
                    start--;
                }

                optimizer.Add();
            } while (Api.TryMoveNext(session, Files) && optimizer.Count < pageSize);

            return(optimizer.Select(ReadCurrentAttachmentInformation));
        }
示例#3
0
        public IEnumerable <JsonDocument> GetDocumentsAfter(Guid etag, int take)
        {
            Api.JetSetCurrentIndex(session, Documents, "by_etag");
            Api.MakeKey(session, Documents, etag.TransformToValueForEsentSorting(), MakeKeyGrbit.NewKey);
            if (Api.TrySeek(session, Documents, SeekGrbit.SeekGT) == false)
            {
                return(Enumerable.Empty <JsonDocument>());
            }
            var optimizer = new OptimizedIndexReader(Session, Documents, take);

            do
            {
                optimizer.Add();
            } while (Api.TryMoveNext(session, Documents) && optimizer.Count < take);

            return(optimizer.Select(ReadCurrentDocument));
        }
示例#4
0
        public IEnumerable <JsonDocument> GetDocumentsByReverseUpdateOrder(int start, int take)
        {
            Api.JetSetCurrentIndex(session, Documents, "by_etag");
            Api.MoveAfterLast(session, Documents);
            if (TryMoveDocumentRecords(start, backward: true))
            {
                return(Enumerable.Empty <JsonDocument>());
            }
            var optimizer = new OptimizedIndexReader(Session, Documents, take);

            while (Api.TryMovePrevious(session, Documents) && optimizer.Count < take)
            {
                optimizer.Add();
            }

            return(optimizer.Select(ReadCurrentDocument));
        }
示例#5
0
        public IEnumerable <JsonDocument> GetDocumentsByReverseUpdateOrder(int start, int take)
        {
            Api.JetSetCurrentIndex(session, Documents, "by_etag");
            Api.MoveAfterLast(session, Documents);
            for (int i = 0; i < start; i++)
            {
                if (Api.TryMovePrevious(session, Documents) == false)
                {
                    return(Enumerable.Empty <JsonDocument>());
                }
            }
            var optimizer = new OptimizedIndexReader(Session, Documents, take);

            while (Api.TryMovePrevious(session, Documents) && optimizer.Count < take)
            {
                optimizer.Add();
            }

            return(optimizer.Select(ReadCurrentDocument));
        }
示例#6
0
        public IEnumerable <MappedResultInfo> GetMappedResultsReduceKeysAfter(string indexName, Guid lastReducedEtag, bool loadData, int take)
        {
            Api.JetSetCurrentIndex(session, MappedResults, "by_view_and_etag");
            Api.MakeKey(session, MappedResults, indexName, Encoding.Unicode, MakeKeyGrbit.NewKey);
            Api.MakeKey(session, MappedResults, lastReducedEtag, MakeKeyGrbit.None);
            if (Api.TrySeek(session, MappedResults, SeekGrbit.SeekLE) == false)
            {
                return(Enumerable.Empty <MappedResultInfo>());
            }

            var optimizer = new OptimizedIndexReader(Session, MappedResults, take);

            while (
                optimizer.Count < take &&
                Api.RetrieveColumnAsString(session, MappedResults, tableColumnsCache.MappedResultsColumns["view"], Encoding.Unicode, RetrieveColumnGrbit.RetrieveFromIndex) == indexName)
            {
                optimizer.Add();

                // the index is view ascending and etag descending
                // that means that we are going backward to go up
                if (Api.TryMovePrevious(session, MappedResults) == false)
                {
                    break;
                }
            }

            return(optimizer.Select(() => new MappedResultInfo
            {
                ReduceKey = Api.RetrieveColumnAsString(session, MappedResults, tableColumnsCache.MappedResultsColumns["reduce_key"]),
                Etag = new Guid(Api.RetrieveColumn(session, MappedResults, tableColumnsCache.MappedResultsColumns["etag"])),
                Timestamp = Api.RetrieveColumnAsDateTime(session, MappedResults, tableColumnsCache.MappedResultsColumns["timestamp"]).Value,
                Data = loadData
                                        ? Api.RetrieveColumn(session, MappedResults, tableColumnsCache.MappedResultsColumns["data"]).ToJObject()
                                        : null,
            }));
        }
        public IEnumerable <AttachmentInformation> GetAttachmentsAfter(Guid etag, int take)
        {
            Api.JetSetCurrentIndex(session, Files, "by_etag");
            Api.MakeKey(session, Files, etag.TransformToValueForEsentSorting(), MakeKeyGrbit.NewKey);
            if (Api.TrySeek(session, Files, SeekGrbit.SeekGT) == false)
            {
                return(Enumerable.Empty <AttachmentInformation>());
            }

            var optimizer = new OptimizedIndexReader(Session, Files, take);

            do
            {
                optimizer.Add();
            } while (Api.TryMoveNext(session, Files) && optimizer.Count < take);

            return(optimizer.Select(() => new AttachmentInformation
            {
                Size = Api.RetrieveColumnSize(session, Files, tableColumnsCache.FilesColumns["data"]) ?? 0,
                Etag = Api.RetrieveColumn(session, Files, tableColumnsCache.FilesColumns["etag"]).TransfromToGuidWithProperSorting(),
                Key = Api.RetrieveColumnAsString(session, Files, tableColumnsCache.FilesColumns["name"], Encoding.Unicode),
                Metadata = RavenJObject.Parse(Api.RetrieveColumnAsString(session, Files, tableColumnsCache.FilesColumns["metadata"], Encoding.Unicode))
            }));
        }