Exemplo n.º 1
0
        /// <summary>Reads the values of multiple entries in the map</summary>
        /// <param name="trans">Transaction used for the operation</param>
        /// <param name="ids">List of the keys to read</param>
        /// <returns>Array of results, in the same order as specified in <paramref name="ids"/>.</returns>
        public async Task <TValue[]> GetValuesAsync([NotNull] IFdbReadOnlyTransaction trans, [NotNull] IEnumerable <TKey> ids)
        {
            if (trans == null)
            {
                throw new ArgumentNullException(nameof(trans));
            }
            if (ids == null)
            {
                throw new ArgumentNullException(nameof(ids));
            }

            var kv = await trans.GetValuesAsync(ids.Select(id => this.Subspace.Keys[id])).ConfigureAwait(false);

            if (kv.Length == 0)
            {
                return(Array.Empty <TValue>());
            }

            var result  = new TValue[kv.Length];
            var decoder = this.ValueEncoder;

            for (int i = 0; i < kv.Length; i++)
            {
                result[i] = decoder.DecodeValue(kv[i]);
            }

            return(result);
        }
Exemplo n.º 2
0
        /// <summary>Return one or more fields of an hashset</summary>
        /// <param name="trans">Transaction that will be used for this request</param>
        /// <param name="id">Unique identifier of the hashset</param>
        /// <param name="fields">List of the fields to read</param>
        /// <returns>Dictionary containing the values of the selected fields, or <see cref="Slice.Empty"/> if that particular field does not exist.</returns>
        public async Task <IDictionary <string, Slice> > GetAsync(IFdbReadOnlyTransaction trans, IVarTuple id, params string[] fields)
        {
            if (trans == null)
            {
                throw new ArgumentNullException(nameof(trans));
            }
            if (id == null)
            {
                throw new ArgumentNullException(nameof(id));
            }
            if (fields == null)
            {
                throw new ArgumentNullException(nameof(fields));
            }

            var keys = TuPack.EncodePrefixedKeys(GetKey(id), fields);

            var values = await trans.GetValuesAsync(keys).ConfigureAwait(false);

            Contract.Debug.Assert(values != null && values.Length == fields.Length);

            var results = new Dictionary <string, Slice>(values.Length, StringComparer.OrdinalIgnoreCase);

            for (int i = 0; i < fields.Length; i++)
            {
                results[fields[i]] = values[i];
            }
            return(results);
        }
Exemplo n.º 3
0
        /// <summary>Return one or more fields of an hashset</summary>
        /// <param name="trans">Transaction that will be used for this request</param>
        /// <param name="id">Unique identifier of the hashset</param>
        /// <param name="fields">List of the fields to read</param>
        /// <returns>Dictionary containing the values of the selected fields, or Slice.Empty if that particular field does not exist.</returns>
        public async Task <IDictionary <string, Slice> > GetAsync(IFdbReadOnlyTransaction trans, IFdbTuple id, string[] fields)
        {
            if (trans == null)
            {
                throw new ArgumentNullException("trans");
            }
            if (id == null)
            {
                throw new ArgumentNullException("id");
            }
            if (fields == null)
            {
                throw new ArgumentNullException("fields");
            }

            var keys = FdbTuple.PackRange(GetKey(id), fields);

            var values = await trans.GetValuesAsync(keys).ConfigureAwait(false);

            Contract.Assert(values != null && values.Length == fields.Length);

            var results = new Dictionary <string, Slice>(values.Length, StringComparer.OrdinalIgnoreCase);

            for (int i = 0; i < fields.Length; i++)
            {
                results[fields[i]] = values[i];
            }
            return(results);
        }
        /// <summary>Reads the values of multiple entries in the map</summary>
        /// <param name="trans">Transaction used for the operation</param>
        /// <param name="ids">List of the keys to read</param>
        /// <returns>Array of results, in the same order as specified in <paramref name="ids"/>.</returns>
        public async Task <Optional <TValue>[]> GetValuesAsync([NotNull] IFdbReadOnlyTransaction trans, [NotNull] IEnumerable <TKey> ids)
        {
            if (trans == null)
            {
                throw new ArgumentNullException("trans");
            }
            if (ids == null)
            {
                throw new ArgumentNullException("ids");
            }

            var results = await trans.GetValuesAsync(this.Location.Keys.Encode(ids)).ConfigureAwait(false);

            return(Optional.DecodeRange(this.ValueEncoder, results));
        }
 public virtual Task <Slice[]> GetValuesAsync(Slice[] keys)
 {
     return(m_transaction.GetValuesAsync(keys));
 }
 public Task <Slice[]> GetValuesAsync([NotNull] IFdbReadOnlyTransaction trans, [NotNull] IEnumerable <T> keys)
 {
     return(trans.GetValuesAsync(EncodeKeyRange(keys)));
 }
		/// <summary>Return one or more fields of an hashset</summary>
		/// <param name="trans">Transaction that will be used for this request</param>
		/// <param name="id">Unique identifier of the hashset</param>
		/// <param name="fields">List of the fields to read</param>
		/// <returns>Dictionary containing the values of the selected fields, or Slice.Empty if that particular field does not exist.</returns>
		public async Task<IDictionary<string, Slice>> GetAsync(IFdbReadOnlyTransaction trans, IFdbTuple id, string[] fields)
		{
			if (trans == null) throw new ArgumentNullException("trans");
			if (id == null) throw new ArgumentNullException("id");
			if (fields == null) throw new ArgumentNullException("fields");

			var keys = FdbTuple.PackRange(GetKey(id), fields);

			var values = await trans.GetValuesAsync(keys).ConfigureAwait(false);
			Contract.Assert(values != null && values.Length == fields.Length);

			var results = new Dictionary<string, Slice>(values.Length, StringComparer.OrdinalIgnoreCase);
			for (int i = 0; i < fields.Length; i++)
			{
				results[fields[i]] = values[i];
			}
			return results;
		}