Example #1
0
            protected override void SetCurrent()
            {
                var ravenJObject = enumerator.Current;

                query.InvokeAfterStreamExecuted(ref ravenJObject);

                var    meta = ravenJObject.Value <RavenJObject>(Constants.Metadata);
                string key  = null;
                Etag   etag = null;

                if (meta != null)
                {
                    key = meta.Value <string>("@id") ??
                          meta.Value <string>(Constants.DocumentIdFieldName) ??
                          ravenJObject.Value <string>(Constants.DocumentIdFieldName);

                    var value = meta.Value <string>("@etag");
                    if (value != null)
                    {
                        etag = Etag.Parse(value);
                    }
                }

                Current = new StreamResult <T>
                {
                    Document = queryOperation.Deserialize <T>(ravenJObject),
                    Etag     = etag,
                    Key      = key,
                    Metadata = meta
                };
            }
Example #2
0
        public TResult[] LoadStartingWith <TTransformer, TResult>(string keyPrefix, string matches = null, int start = 0,
                                                                  int pageSize = 25, string exclude = null,
                                                                  RavenPagingInformation pagingInformation = null,
                                                                  Action <ILoadConfiguration> configure    = null,
                                                                  string skipAfter = null)
            where TTransformer : AbstractTransformerCreationTask, new()
        {
            IncrementRequestCount();
            var transformer = new TTransformer().TransformerName;

            var configuration = new RavenLoadConfiguration();

            if (configure != null)
            {
                configure(configuration);
            }

            var queryOperation = new QueryOperation(this, "Load/StartingWith", null, null, false, TimeSpan.Zero, null, null, false);

            return
                (DatabaseCommands.StartsWith(keyPrefix, matches, start, pageSize, exclude: exclude,
                                             pagingInformation: pagingInformation, transformer: transformer, transformerParameters: configuration.TransformerParameters,
                                             skipAfter: skipAfter)
                 .Select(document => queryOperation.Deserialize <TResult>(document.ToJson()))
                 .ToArray());
        }
            private StreamResult <T> CreateStreamResult(BlittableJsonReaderObject json)
            {
                var metadata     = json.GetMetadata();
                var changeVector = metadata.GetChangeVector();

                //MapReduce indexes return reduce results that don't have @id property
                metadata.TryGetId(out string id);
                var entity = QueryOperation.Deserialize <T>(id, json, metadata, _fieldsToFetch, true, _parent);

                var streamResult = new StreamResult <T>
                {
                    ChangeVector = changeVector,
                    Id           = id,
                    Document     = entity,
                    Metadata     = new MetadataAsDictionary(metadata)
                };

                return(streamResult);
            }
Example #4
0
            private StreamResult <T> CreateStreamResult(BlittableJsonReaderObject json)
            {
                var metadata     = json.GetMetadata();
                var changeVector = BlittableJsonExtensions.GetChangeVector(metadata);
                var id           = metadata.GetId();

                json = _parent.Context.ReadObject(json, id);
                var entity = QueryOperation.Deserialize <T>(id, json, metadata, _projectionFields, true, _parent);

                var streamResult = new StreamResult <T>
                {
                    ChangeVector = changeVector,
                    Id           = id,
                    Document     = entity,
                    Metadata     = new MetadataAsDictionary(metadata)
                };

                return(streamResult);
            }
Example #5
0
        private StreamResult <T> CreateStreamResult <T>(BlittableJsonReaderObject json, string[] projectionFields)
        {
            var metadata     = json.GetMetadata();
            var changeVector = BlittableJsonExtensions.GetChangeVector(metadata);
            var id           = metadata.GetId();

            //TODO - Investigate why ConvertToEntity fails if we don't call ReadObject before
            json = Context.ReadObject(json, id);
            var entity = QueryOperation.Deserialize <T>(id, json, metadata, projectionFields, true, this);

            var streamResult = new StreamResult <T>
            {
                ChangeVector = changeVector,
                Id           = id,
                Document     = entity,
                Metadata     = new MetadataAsDictionary(metadata)
            };

            return(streamResult);
        }
Example #6
0
        public Task <IEnumerable <TResult> > LoadStartingWithAsync <TTransformer, TResult>(string keyPrefix, string matches = null, int start = 0, int pageSize = 25,
                                                                                           string exclude = null, RavenPagingInformation pagingInformation = null,
                                                                                           Action <ILoadConfiguration> configure = null,
                                                                                           string skipAfter = null, CancellationToken token = default(CancellationToken)) where TTransformer : AbstractTransformerCreationTask, new()
        {
            var transformer = new TTransformer().TransformerName;

            var configuration = new RavenLoadConfiguration();

            if (configure != null)
            {
                configure(configuration);
            }
            var queryOperation = new QueryOperation(this, "Load/StartingWith", null, null, false, TimeSpan.Zero, null, null, false);

            return(AsyncDatabaseCommands.StartsWithAsync(keyPrefix, matches, start, pageSize, exclude: exclude,
                                                         pagingInformation: pagingInformation, transformer: transformer,
                                                         transformerParameters: configuration.TransformerParameters,
                                                         skipAfter: skipAfter, token: token)
                   .ContinueWith(
                       task => (IEnumerable <TResult>)task.Result.Select(x => queryOperation.Deserialize <TResult>(x.ToJson())).ToList(), token));
        }
Example #7
0
        private StreamResult <T> CreateStreamResult <T>(BlittableJsonReaderObject json, FieldsToFetchToken fieldsToFetch)
        {
            var metadata     = json.GetMetadata();
            var changeVector = metadata.GetChangeVector();

            //MapReduce indexes return reduce results that don't have @id property
            metadata.TryGetId(out string id);

            //TODO - Investigate why ConvertToEntity fails if we don't call ReadObject before
            json = Context.ReadObject(json, id);
            var entity = QueryOperation.Deserialize <T>(id, json, metadata, fieldsToFetch, true, this);

            var streamResult = new StreamResult <T>
            {
                ChangeVector = changeVector,
                Id           = id,
                Document     = entity,
                Metadata     = new MetadataAsDictionary(metadata)
            };

            return(streamResult);
        }
        public TResult[] LoadStartingWith <TTransformer, TResult>(string keyPrefix, string matches = null, int start = 0,
                                                                  int pageSize = 25, string exclude = null,
                                                                  RavenPagingInformation pagingInformation = null,
                                                                  Action <ILoadConfiguration> configure    = null,
                                                                  string skipAfter = null) where TTransformer : AbstractTransformerCreationTask, new()
        {
            var transformer = new TTransformer().TransformerName;

            var configuration = new RavenLoadConfiguration();

            if (configure != null)
            {
                configure(configuration);
            }

            IncrementRequestCount();
            var shards = GetCommandsToOperateOn(new ShardRequestData
            {
                EntityType = typeof(TResult),
                Keys       = { keyPrefix }
            });

            var results = shardStrategy.ShardAccessStrategy.Apply(shards, new ShardRequestData
            {
                EntityType = typeof(TResult),
                Keys       = { keyPrefix }
            },
                                                                  (dbCmd, i) =>
                                                                  dbCmd.StartsWith(keyPrefix, matches, start, pageSize,
                                                                                   exclude: exclude, transformer: transformer,
                                                                                   transformerParameters: configuration.TransformerParameters,
                                                                                   skipAfter: skipAfter));
            var queryOperation = new QueryOperation(this, "Load/StartingWith", null, null, false, TimeSpan.Zero, null, null, false);

            return(results.SelectMany(x => x).Select(x => queryOperation.Deserialize <TResult>(x.ToJson()))
                   .ToArray());
        }