public static async Task <IMutateInResult <TDocument> > MutateInAsync <TDocument>(
            this ICouchbaseCollection collection, string id, Action <MutateInSpecBuilder <TDocument> > configureBuilder,
            MutateInOptions?options = null)
        {
            var serializer = options?.SerializerValue ??
                             collection.Scope.Bucket.Cluster.ClusterServices.GetRequiredService <ITypeSerializer>();

            var mutateInSpec = new MutateInSpecBuilder <TDocument>(serializer);

            configureBuilder(mutateInSpec);

            return(new MutateInResult <TDocument>(
                       await collection.MutateInAsync(id, mutateInSpec.Specs, options).ConfigureAwait(false)));
        }
Example #2
0
        public async Task <IMutateInResult> MutateInAsync(string id, IEnumerable <MutateInSpec> specs,
                                                          MutateInOptions?options = null)
        {
            //sanity check for deferred bootstrapping errors
            _bucket.ThrowIfBootStrapFailed();

            //Get the collection ID
            await PopulateCidAsync().ConfigureAwait(false);

            options ??= MutateInOptions.Default;

            //resolve StoreSemantics to SubdocDocFlags
            var docFlags = SubdocDocFlags.None;

            switch (options.StoreSemanticsValue)
            {
            case StoreSemantics.Replace:
                break;

            case StoreSemantics.Upsert:
                docFlags |= SubdocDocFlags.UpsertDocument;
                break;

            case StoreSemantics.Insert:
                docFlags |= SubdocDocFlags.InsertDocument;
                break;

            case StoreSemantics.AccessDeleted:
                docFlags |= SubdocDocFlags.AccessDeleted;
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }

            if (options.CreateAsDeletedValue)
            {
                if (!_bucket.BucketConfig?.BucketCapabilities.Contains(BucketCapabilities.CREATE_AS_DELETED) == true)
                {
                    throw new FeatureNotAvailableException(nameof(BucketCapabilities.CREATE_AS_DELETED));
                }

                docFlags |= SubdocDocFlags.CreateAsDeleted;
            }

            if (options.AccessDeletedValue)
            {
                docFlags |= SubdocDocFlags.AccessDeleted;
            }

            using var rootSpan = RootSpan(OuterRequestSpans.ServiceSpan.Kv.MutateIn);
            using var mutation = new MultiMutation <byte[]>(id, specs)
                  {
                      BucketName      = _bucket.Name,
                      Cas             = options.CasValue,
                      Cid             = Cid,
                      CName           = Name,
                      SName           = ScopeName,
                      Expires         = options.ExpiryValue.ToTtl(),
                      DurabilityLevel = options.DurabilityLevel,
                      DocFlags        = docFlags,
                      Span            = rootSpan
                  };
            _operationConfigurator.Configure(mutation, options);

            using var cts = CreateRetryTimeoutCancellationTokenSource(options, mutation, out var tokenPair);
            await _bucket.RetryAsync(mutation, tokenPair).ConfigureAwait(false);

#pragma warning disable 618 // MutateInResult is marked obsolete until it is made internal
            return(new MutateInResult(mutation.GetCommandValues(), mutation.Cas, mutation.MutationToken,
                                      options.SerializerValue ?? mutation.Transcoder.Serializer));

#pragma warning restore 618
        }
        public async Task <IMutateInResult> MutateInAsync(string id, IEnumerable <MutateInSpec> specs, MutateInOptions?options = null)
        {
            //sanity check for deferred bootstrapping errors
            _bucket.ThrowIfBootStrapFailed();

            options ??= new MutateInOptions();
            // convert new style specs into old style builder
            var builder = new MutateInBuilder <byte[]>(null, null, id, specs);

            //resolve StoreSemantics to SubdocDocFlags
            var docFlags = SubdocDocFlags.None;

            switch (options.StoreSemanticsValue)
            {
            case StoreSemantics.Replace:
                break;

            case StoreSemantics.Upsert:
                docFlags |= SubdocDocFlags.UpsertDocument;
                break;

            case StoreSemantics.Insert:
                docFlags |= SubdocDocFlags.InsertDocument;
                break;

            case StoreSemantics.AccessDeleted:
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }

            using var mutation = new MultiMutation <byte[]>
                  {
                      Key             = id,
                      BucketName      = _bucket.Name,
                      Builder         = builder,
                      Cid             = Cid,
                      DurabilityLevel = options.DurabilityLevel,
                      Transcoder      = _transcoder,
                      DocFlags        = docFlags
                  };
            await _bucket.SendAsync(mutation, options.TokenValue, options.TimeoutValue).ConfigureAwait(false);

            return(new MutateInResult(mutation.GetCommandValues(), mutation.Cas, mutation.MutationToken,
                                      options.SerializerValue ?? _transcoder.Serializer));
        }
Example #4
0
 public Task <IMutateInResult> MutateInAsync(string id, IEnumerable <MutateInSpec> specs, MutateInOptions?options = null)
 {
     throw new NotImplementedException();
 }
        public static Task <IMutateInResult> MutateInAsync(this ICouchbaseCollection collection, string id,
                                                           Action <MutateInSpecBuilder> configureBuilder, MutateInOptions?options)
        {
            var mutateInSpec = new MutateInSpecBuilder();

            configureBuilder(mutateInSpec);

            return(collection.MutateInAsync(id, mutateInSpec.Specs, options));
        }
Example #6
0
        public async Task <IMutateInResult> MutateInAsync(string id, IEnumerable <MutateInSpec> specs, MutateInOptions?options = null)
        {
            //sanity check for deferred bootstrapping errors
            _bucket.ThrowIfBootStrapFailed();

            options ??= new MutateInOptions();
            // convert new style specs into old style builder
            var builder = new MutateInBuilder <byte[]>(null, null, id, specs);

            //resolve StoreSemantics to SubdocDocFlags
            var docFlags = SubdocDocFlags.None;

            switch (options.StoreSemanticsValue)
            {
            case StoreSemantics.Replace:
                break;

            case StoreSemantics.Upsert:
                docFlags |= SubdocDocFlags.UpsertDocument;
                break;

            case StoreSemantics.Insert:
                docFlags |= SubdocDocFlags.InsertDocument;
                break;

            case StoreSemantics.AccessDeleted:
                docFlags |= SubdocDocFlags.AccessDeleted;
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }

            if (options.CreateAsDeletedValue)
            {
                if (!_bucket.BucketConfig?.BucketCapabilities.Contains(BucketCapabilities.CREATE_AS_DELETED) == true)
                {
                    throw new FeatureNotAvailableException(nameof(BucketCapabilities.CREATE_AS_DELETED));
                }

                docFlags |= SubdocDocFlags.CreateAsDeleted;
            }

            if (options.AccessDeletedValue)
            {
                docFlags |= SubdocDocFlags.AccessDeleted;
            }

            using var rootSpan = RootSpan(OperationNames.MultiMutationSubdocMutate);
            using var mutation = new MultiMutation <byte[]>
                  {
                      Key             = id,
                      BucketName      = _bucket.Name,
                      Builder         = builder,
                      Cid             = Cid,
                      CName           = Name,
                      Expires         = options.ExpiryValue.ToTtl(),
                      DurabilityLevel = options.DurabilityLevel,
                      DocFlags        = docFlags,
                      Span            = rootSpan
                  };
            _operationConfigurator.Configure(mutation, options);

            await RetryUntilTimeoutOrSuccessAsync(options.TokenValue, options.TimeoutValue, mutation).ConfigureAwait(false);

            return(new MutateInResult(mutation.GetCommandValues(), mutation.Cas, mutation.MutationToken,
                                      options.SerializerValue ?? mutation.Transcoder.Serializer));
        }
 public Task <IMutateInResult> MutateInAsync(string id, IEnumerable <MutateInSpec> specs, MutateInOptions?options = null)
 {
     return(Task.FromResult(new Mock <IMutateInResult>().Object));
 }
Example #8
0
        public async Task <IMutateInResult> MutateInAsync(string id, IEnumerable <MutateInSpec> specs,
                                                          MutateInOptions?options = null)
        {
            //sanity check for deferred bootstrapping errors
            _bucket.ThrowIfBootStrapFailed();

            //Check to see if the CID is needed
            if (RequiresCid())
            {
                //Get the collection ID
                await PopulateCidAsync().ConfigureAwait(false);
            }

            options ??= MutateInOptions.Default;

            //Reality check for preserveTtl server support
            if (!_bucket.Context.SupportsPreserveTtl && options.PreserveTtlValue)
            {
                throw new FeatureNotAvailableException(
                          "This version of Couchbase Server does not support preserving expiry when modifying documents.");
            }

            //resolve StoreSemantics to SubdocDocFlags
            var docFlags = SubdocDocFlags.None;

            switch (options.StoreSemanticsValue)
            {
            case StoreSemantics.Replace:
                break;

            case StoreSemantics.Upsert:
                docFlags |= SubdocDocFlags.UpsertDocument;
                break;

            case StoreSemantics.Insert:
                docFlags |= SubdocDocFlags.InsertDocument;
                break;

            case StoreSemantics.AccessDeleted:
                docFlags |= SubdocDocFlags.AccessDeleted;
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }

            if (options.CreateAsDeletedValue)
            {
                if (!_bucket.CurrentConfig?.BucketCapabilities.Contains(BucketCapabilities.CREATE_AS_DELETED) == true)
                {
                    throw new FeatureNotAvailableException(nameof(BucketCapabilities.CREATE_AS_DELETED));
                }

                docFlags |= SubdocDocFlags.CreateAsDeleted;
            }

            if (options.AccessDeletedValue)
            {
                docFlags |= SubdocDocFlags.AccessDeleted;
            }

            using var rootSpan = RootSpan(OuterRequestSpans.ServiceSpan.Kv.MutateIn, options.RequestSpanValue);
            using var mutation = new MultiMutation <byte[]>(id, specs)
                  {
                      BucketName      = _bucket.Name,
                      Cas             = options.CasValue,
                      Cid             = Cid,
                      CName           = Name,
                      SName           = ScopeName,
                      Expires         = options.ExpiryValue.ToTtl(),
                      DurabilityLevel = options.DurabilityLevel,
                      DocFlags        = docFlags,
                      Span            = rootSpan,
                      PreserveTtl     = options.PreserveTtlValue
                  };
            _operationConfigurator.Configure(mutation, options);
            if (mutation.Transcoder != null && options.SerializerValue != null)
            {
                mutation.Transcoder.Serializer = options.SerializerValue !;
            }

            using var ctp = CreateRetryTimeoutCancellationTokenSource(options, mutation);
            await _bucket.RetryAsync(mutation, ctp.TokenPair).ConfigureAwait(false);

#pragma warning disable 618 // MutateInResult is marked obsolete until it is made internal
            return(new MutateInResult(mutation.GetCommandValues(), mutation.Cas, mutation.MutationToken,
                                      options.SerializerValue ?? mutation.Transcoder?.Serializer ?? Core.IO.Serializers.DefaultSerializer.Instance));

#pragma warning restore 618
        }