Raven.Database.DatabaseBulkOperations.PerformBulkOperation C# (CSharp) Method

PerformBulkOperation() private method

private PerformBulkOperation ( string index, IndexQuery indexQuery, bool allowStale, Func batchOperation ) : Newtonsoft.Json.Linq.JArray
index string
indexQuery Raven.Database.Data.IndexQuery
allowStale bool
batchOperation Func
return Newtonsoft.Json.Linq.JArray
		private JArray PerformBulkOperation(string index, IndexQuery indexQuery, bool allowStale, Func<string, TransactionInformation, object> batchOperation)
		{
			var array = new JArray();
			database.TransactionalStorage.Batch(actions =>
			{
				var bulkIndexQuery = new IndexQuery
				{
					Query = indexQuery.Query,
					Start = indexQuery.Start,
					Cutoff = indexQuery.Cutoff,
					PageSize = int.MaxValue,
					FieldsToFetch = new[] { "__document_id" },
					SortedFields = indexQuery.SortedFields
				};

				bool stale;
				var queryResults = database.QueryDocumentIds(index, bulkIndexQuery, out stale);

				if (stale)
				{
					if (allowStale == false)
					{
						throw new InvalidOperationException(
							"Bulk operation cancelled because the index is stale and allowStale is false");
					}
				}

				foreach (var documentId in queryResults)
				{
					var result = batchOperation(documentId, transactionInformation);
					array.Add(JObject.FromObject(result, new JsonSerializer { Converters = { new JsonEnumConverter() } }));
				}
			});
			return array;
		}
	}