public UpdateRowRequest(RowUpdateChange rowUpdateChange)
 {
     this.RowUpdateChange = rowUpdateChange;
     this.TableName       = rowUpdateChange.TableName;
     this.Condition       = rowUpdateChange.Condition;
     this.PrimaryKey      = rowUpdateChange.PrimaryKey;
 }
Пример #2
0
        /// <summary>
        /// 更新行的时候,指定某一列为原子自增列,并对这一列进行原子自增
        /// </summary>
        public static void Increment(int incrementValue)
        {
            Console.WriteLine("Start set increment column...");
            OTSClient otsClient = Config.GetClient();

            // 定义行的主键,必须与创建表时的TableMeta中定义的一致
            PrimaryKey primaryKey = new PrimaryKey
            {
                { Pk1, new ColumnValue(0) },
                { Pk2, new ColumnValue("abc") }
            };
            RowUpdateChange rowUpdateChange = new RowUpdateChange(TableName, primaryKey);

            rowUpdateChange.ReturnType        = ReturnType.RT_AFTER_MODIFY;
            rowUpdateChange.ReturnColumnNames = new List <string>()
            {
                IncrementCol
            };
            //设置一个原子自增列,这一列从0开始自增,每次增增加1。
            rowUpdateChange.Increment(new Column(IncrementCol, new ColumnValue(incrementValue)));

            UpdateRowRequest updateRowRequest = new UpdateRowRequest(rowUpdateChange);

            var response = otsClient.UpdateRow(updateRowRequest);

            Console.WriteLine("set Increment column succeed,Increment result:" + response.Row.GetColumns()[0].Value);
        }
Пример #3
0
        public static byte[] BuildRowUpdateChangeWithHeader(RowUpdateChange rowChange)
        {
            List <PlainBufferCell> pkCells = new List <PlainBufferCell>();

            foreach (var column in rowChange.GetPrimaryKey().GetPrimaryKeyColumns())
            {
                pkCells.Add(PlainBufferConversion.ToPlainBufferCell(column));
            }

            List <PlainBufferCell> cells = new List <PlainBufferCell>();

            if (rowChange.GetColumnsToUpdate().Count > 0)
            {
                foreach (Tuple <Column, RowChangeType> column in rowChange.GetColumnsToUpdate())
                {
                    switch (column.Item2)
                    {
                    case RowChangeType.PUT:
                        cells.Add(PlainBufferConversion.ToPlainBufferCell(column.Item1, false, false, false, (byte)0x0));
                        break;

                    case RowChangeType.DELETE:
                        cells.Add(PlainBufferConversion.ToPlainBufferCell(column.Item1, true, false, true, PlainBufferConsts.DELETE_ONE_VERSION));
                        break;

                    case RowChangeType.DELETE_ALL:
                        cells.Add(PlainBufferConversion.ToPlainBufferCell(column.Item1, true, true, true, PlainBufferConsts.DELETE_ALL_VERSION));
                        break;

                    case RowChangeType.INCREMENT:
                        cells.Add(PlainBufferConversion.ToPlainBufferCell(column.Item1, false, true, true, PlainBufferConsts.INCREMENT));
                        break;
                    }
                }
            }

            PlainBufferRow row = new PlainBufferRow(pkCells, cells, false);

            int size = ComputePlainBufferRowWithHeader(row);
            PlainBufferOutputStream      output      = new PlainBufferOutputStream(size);
            PlainBufferCodedOutputStream codedOutput = new PlainBufferCodedOutputStream(output);

            codedOutput.WriteRowWithHeader(row);

            if (!output.IsFull())
            {
                throw new IOException("Bug: serialize row update change failed.");
            }

            return(output.GetBuffer());
        }
        public UpdateRowRequest(string tableName, Condition condition, PrimaryKey primaryKey,
                                UpdateOfAttribute updateOfAttribute)
        {
            TableName         = tableName;
            Condition         = condition;
            PrimaryKey        = primaryKey;
            UpdateOfAttribute = updateOfAttribute;
            RowUpdateChange   = new RowUpdateChange(tableName, primaryKey)
            {
                Condition = condition
            };

            RowUpdateChange.FromUpdateOfAtrribute(updateOfAttribute);
        }