Example #1
0
        /// <summary>
        ///    Builds a batch insert URI.
        /// </summary>
        /// <param name="identifier">The identifier.</param>
        /// <returns></returns>
        /// <exception cref="System.NotImplementedException"></exception>
        public string BuildBatchInsert(Identifier identifier)
        {
            if (!identifier.CanDescribeTable())
            {
                throw new ArgumentException(Resources.ResourceBuilder_MinimumForBatchInsertNotMet);
            }

            return new StringBuilder(identifier.Table).AppendFormat(_appendSegmentFormat, _options.FalseRowKey).ToString();
        }
Example #2
0
        /// <summary>
        ///    Builds a delete-item URI.
        /// </summary>
        /// <param name="identifier">The identifier.</param>
        public string BuildDeleteItem(Identifier identifier)
        {
            if (!identifier.CanDescribeRow())
            {
                throw new ArgumentException(Resources.ResourceBuilder_MinimumForDeleteItemNotMet);
            }

            return BuildFromIdentifier(identifier).ToString();
        }
Example #3
0
        /// <summary>
        ///    Builds a single value storage URI.
        /// </summary>
        /// <param name="identifier">The identifier.</param>
        /// <param name="forReading">
        ///    if set to <c>true</c> this resource will be used for reading.
        /// </param>
        public string BuildSingleValueAccess(Identifier identifier, bool forReading = false)
        {
            if (!identifier.CanDescribeCell())
            {
                throw new ArgumentException(Resources.ResourceBuilder_MinimumForSingleValueAccessNotMet);
            }

            StringBuilder builder = BuildFromIdentifier(identifier);
            return (forReading ? SetMaxVersions(1, builder) : builder).ToString();
        }
Example #4
0
        private static StringBuilder BuildFromIdentifier(Identifier identifier)
        {
            bool hasTimestamp = identifier.Timestamp.HasValue;
            StringBuilder uriBuilder = BuildFromDescriptor(identifier);

            bool columnMissing = identifier.CellDescriptor == null || string.IsNullOrEmpty(identifier.CellDescriptor.Column);
            if (columnMissing && !hasTimestamp)
            {
                return uriBuilder;
            }

            uriBuilder.AppendFormat(_appendSegmentFormat, columnMissing ? _wildCard : identifier.CellDescriptor.Column);

            if (!columnMissing && !string.IsNullOrEmpty(identifier.CellDescriptor.Qualifier))
            {
                uriBuilder.AppendFormat(_appendQualifierFormat, identifier.CellDescriptor.Qualifier);
            }

            if (hasTimestamp)
            {
                uriBuilder.AppendFormat(_appendSegmentFormat, identifier.Timestamp);
            }

            return uriBuilder;
        }
Example #5
0
 /// <summary>
 ///   Gets the first value with an identifier matching the one specified.
 /// </summary>
 /// <param name="cellSet">The cell set.</param>
 /// <param name="identifier">The identifier.</param>
 public static string GetValue(this IEnumerable<Cell> cellSet, Identifier identifier)
 {
     return cellSet.Where(cell => cell.Identifier.Matches(identifier))
     .Select(cell => cell.Value)
     .FirstOrDefault();
 }
Example #6
0
        /// <summary>
        ///   Returns a value indicating whether or not the two identifiers match.
        ///   If a property has not been set on the other identifier, it will not be included
        ///   in the evaluation.
        /// </summary>
        /// <param name="identifier">The identifier.</param>
        /// <param name="other">The other identifier.</param>
        public static bool Matches(this Identifier identifier, Identifier other)
        {
            if (!string.IsNullOrEmpty(other.Table) && other.Table != identifier.Table)
              {
            return false;
              }

              if (!string.IsNullOrEmpty(other.Row) && other.Row != identifier.Row)
              {
            return false;
              }

              HBaseCellDescriptor otherCell = other.CellDescriptor;
              HBaseCellDescriptor currentCell = identifier.CellDescriptor;

              if (otherCell != null && currentCell != null)
              {
            if (!string.IsNullOrEmpty(otherCell.Column) && otherCell.Column != currentCell.Column)
            {
              return false;
            }

            if (!string.IsNullOrEmpty(otherCell.Qualifier) && otherCell.Qualifier != currentCell.Qualifier)
            {
              return false;
            }
              }

              return !other.Timestamp.HasValue || other.Timestamp == identifier.Timestamp;
        }
Example #7
0
		/// <summary>
		///    Writes the value to HBase using the identifier.
		/// </summary>
		/// <param name="identifier">The identifier.</param>
		/// <param name="value">The value.</param>
		public virtual async Task WriteValueAsync(Identifier identifier, string value)
		{
			string contentType = Options.ContentType;
			string resource = _resourceBuilder.BuildSingleValueAccess(identifier);
			string content = _converter.ConvertCell(new Cell(identifier, value));
			IRestResponse response = await SendRequestAsync(Method.POST, resource, contentType, contentType, content);
			_errorProvider.ThrowIfStatusMismatch(response, HttpStatusCode.OK);
		}
Example #8
0
		/// <summary>
		///    Reads the value with the matching identifier.
		/// </summary>
		/// <param name="identifier">The identifier.</param>
		public string ReadValue(Identifier identifier)
		{
			string resource = identifier.Timestamp.HasValue
				? _resourceBuilder.BuildCellOrRowQuery(identifier.ToQuery())
				: _resourceBuilder.BuildSingleValueAccess(identifier, true);

			IRestResponse response = SendRequest(Method.GET, resource, Options.ContentType);
			_errorProvider.ThrowIfStatusMismatch(response, HttpStatusCode.OK, HttpStatusCode.NotFound);

			return _converter.ConvertCells(response.Content, identifier.Table)
				.Select(cell => cell.Value)
				.FirstOrDefault();
		}
Example #9
0
		/// <summary>
		///    Deletes the item with the matching identifier from HBase.
		/// </summary>
		/// <param name="identifier">The identifier.</param>
		public void DeleteItem(Identifier identifier)
		{
			string resource = _resourceBuilder.BuildDeleteItem(identifier);
			IRestResponse response = SendRequest(Method.DELETE, resource, Options.ContentType);
			_errorProvider.ThrowIfStatusMismatch(response, HttpStatusCode.OK);
		}
Example #10
0
		/// <summary>
		///    Writes the cells to HBase.
		/// </summary>
		/// <param name="cells">The cells.</param>
		public void WriteCells(CellSet cells)
		{
			string contentType = Options.ContentType;
			var tableIdentifier = new Identifier { Table = cells.Table };
			string resource = _resourceBuilder.BuildBatchInsert(tableIdentifier);
			IRestResponse response = SendRequest(Method.POST, resource, contentType, contentType, _converter.ConvertCells(cells));
			_errorProvider.ThrowIfStatusMismatch(response, HttpStatusCode.OK);
		}
Example #11
0
        private static Identifier GetIdentifier(Table options)
        {
            var descriptor = options.CreateInstance<TestDescriptor>();

            var identifier = new Identifier
            {
                Table = descriptor.Table,
                Row = descriptor.Row,
                CellDescriptor = new HBaseCellDescriptor
                {
                    Column = descriptor.Column,
                    Qualifier = descriptor.Qualifier
                },
                Timestamp = descriptor.Timestamp
            };
            return identifier;
        }