Exemplo n.º 1
0
		public override void Respond(IHttpContext context)
		{
			var databaseBulkOperations = new DatabaseBulkOperations(Database, GetRequestTransaction(context));
			switch (context.Request.HttpMethod)
			{                
				case "POST":
					Batch(context);
					break;
				case "DELETE":
					OnBulkOperation(context, databaseBulkOperations.DeleteByIndex);
					break;
				case "PATCH":
					var patchRequestJson = context.ReadJsonArray();
					var patchRequests = patchRequestJson.Cast<RavenJObject>().Select(PatchRequest.FromJson).ToArray();
					OnBulkOperation(context, (index, query, allowStale) =>
						databaseBulkOperations.UpdateByIndex(index, query, patchRequests, allowStale));
					break;
				case "EVAL":
					var advPatchRequestJson = context.ReadJsonObject<RavenJObject>();
					var advPatch = ScriptedPatchRequest.FromJson(advPatchRequestJson);
					OnBulkOperation(context, (index, query, allowStale) =>
						databaseBulkOperations.UpdateByIndex(index, query, advPatch, allowStale));
					break;
			}
		}
		public HttpResponseMessage BulkDelete(string id)
		{
            using (var cts = new CancellationTokenSource())
            using (var timeout = cts.TimeoutAfter(DatabasesLandlord.SystemConfiguration.DatbaseOperationTimeout))
            {
                var databaseBulkOperations = new DatabaseBulkOperations(Database, GetRequestTransaction(), cts.Token, timeout);
                return OnBulkOperation(databaseBulkOperations.DeleteByIndex, id);
            }
		}
		public async Task<HttpResponseMessage> BulkPatch(string id)
		{
            using (var cts = new CancellationTokenSource())
            using (var timeout = cts.TimeoutAfter(DatabasesLandlord.SystemConfiguration.DatbaseOperationTimeout))
            {
                var databaseBulkOperations = new DatabaseBulkOperations(Database, GetRequestTransaction(), cts.Token, timeout);
                var patchRequestJson = await ReadJsonArrayAsync();
                var patchRequests = patchRequestJson.Cast<RavenJObject>().Select(PatchRequest.FromJson).ToArray();
                return OnBulkOperation((index, query, allowStale) => databaseBulkOperations.UpdateByIndex(index, query, patchRequests, allowStale), id);
            }
		}
		public HttpResponseMessage BulkDelete(string id)
		{
            // we don't use using because execution is async
		    var cts = new CancellationTokenSource();
		    var timeout = cts.TimeoutAfter(DatabasesLandlord.SystemConfiguration.DatabaseOperationTimeout);

	            var indexDefinition = Database.IndexDefinitionStorage.GetIndexDefinition(id);
				if (indexDefinition == null)
					throw new IndexDoesNotExistsException(string.Format("Index '{0}' does not exist.", id));

				if (indexDefinition.IsMapReduce)
					throw new InvalidOperationException("Cannot execute DeleteByIndex operation on Map-Reduce indexes.");


                var databaseBulkOperations = new DatabaseBulkOperations(Database, GetRequestTransaction(), cts, timeout);
            return OnBulkOperation(databaseBulkOperations.DeleteByIndex, id, cts, timeout);
            }
Exemplo n.º 5
0
        public async Task<HttpResponseMessage> BulkEval(string id)
        {
            RavenJObject advPatchRequestJson;

            try
            {
                advPatchRequestJson = await ReadJsonObjectAsync<RavenJObject>();
            }
            catch (InvalidOperationException e)
            {
                Log.DebugException("Failed to deserialize document batch request." , e);
                return GetMessageWithObject(new
                {
                    Message = "Could not understand json, please check its validity."
                }, (HttpStatusCode)422); //http code 422 - Unprocessable entity

            }
            catch (InvalidDataException e)
            {
                Log.DebugException("Failed to deserialize document batch request." , e);
                return GetMessageWithObject(new
                {
                    e.Message
                }, (HttpStatusCode)422); //http code 422 - Unprocessable entity
            }

            // we don't use using because execution is async
            var cts = new CancellationTokenSource();
            var timeout = cts.TimeoutAfter(DatabasesLandlord.SystemConfiguration.DatabaseOperationTimeout);

            var databaseBulkOperations = new DatabaseBulkOperations(Database, GetRequestTransaction(), cts, timeout);

            var advPatch = ScriptedPatchRequest.FromJson(advPatchRequestJson);
            return OnBulkOperation((index, query, options) => databaseBulkOperations.UpdateByIndex(index, query, advPatch, options), id, timeout);
        }
		public async Task<HttpResponseMessage> BulkEval(string id)
		{
            // we don't use using because execution is async
		    var cts = new CancellationTokenSource();
		    var timeout = cts.TimeoutAfter(DatabasesLandlord.SystemConfiguration.DatabaseOperationTimeout);

                var databaseBulkOperations = new DatabaseBulkOperations(Database, GetRequestTransaction(), cts, timeout);
                var advPatchRequestJson = await ReadJsonObjectAsync<RavenJObject>();
                var advPatch = ScriptedPatchRequest.FromJson(advPatchRequestJson);
            return OnBulkOperation((index, query, allowStale) => databaseBulkOperations.UpdateByIndex(index, query, advPatch, allowStale), id, cts, timeout);
            }