コード例 #1
0
ファイル: HTable.cs プロジェクト: leegkon/NHBaseAPI
        /// <summary>
        ///    插入一行新的记录
        /// </summary>
        /// <param name="rowKey">行键信息</param>
        /// <param name="columnInfos">插入的列信息</param>
        /// <exception cref="IOErrorException">IO错误</exception>
        /// <exception cref="ArgumentNullException">参数不能为空</exception>
        /// <exception cref="CommunicationTimeoutException">通信超时</exception>
        /// <exception cref="CommunicationFailException">通信失败</exception>
        /// <exception cref="RegionNotFoundException">找不到对应的RegionServer</exception>
        public void Insert(byte[] rowKey, params ColumnInfo[] columnInfos)
        {
            if (rowKey == null || rowKey.Length == 0)
            {
                throw new ArgumentNullException("rowKey");
            }
            if (columnInfos == null || columnInfos.Length == 0)
            {
                throw new ArgumentNullException("columnInfos");
            }
            Mutation[] mutations = new Mutation[columnInfos.Length];
            for (int i = 0; i < columnInfos.Length; i++)
            {
                mutations[i]            = new Mutation();
                mutations[i].ColumnName = string.Format("{0}:{1}", columnInfos[i].ColumnFamily, columnInfos[i].ColumnName);
                mutations[i].Value      = columnInfos[i].Value;
            }
            IPEndPoint iep = _regionManager.GetRegionByRowKey(rowKey);

            if (iep == null)
            {
                throw new RegionNotFoundException(string.Format("#Couldn't found any matched RS by specified row key: {0}", rowKey));
            }
            _client.InsertRow(TableName, rowKey, iep, mutations);
        }