示例#1
0
        public async Task <long> AddRow(Nuid id, string table_name, NList value)
        {
            if (NList.IsEmpty(value))
            {
                return(Global.INVALID_ROW);
            }

            Entity entity = EntityManager.Get(id);

            if (entity != null)
            {
                Table table = entity.GetTable(table_name);
                if (table == null)
                {
                    return(Global.INVALID_ROW);
                }

                NList result;
                if (!table.TryAddRow(value, out result))
                {
                    return(Global.INVALID_ROW);
                }

                long  row       = result.Get <long>(0);
                NList row_value = result.Get <NList>(1);
                BatchCahceList.Add(NList.New().Add((int)CacheOption.SetRow).Add(id).Add(table_name).Add(row).Add(row_value));

                await CallbackTable(id, table_name, TableEvent.AddRow, result);

                return(row);
            }
            else
            {
                if (id.Origin == Identity)
                {
                    long row = IdUtils.RGen.CreateId();
                    if (await SetCacheRow(id, table_name, row, value))
                    {
                        NList result = NList.New();
                        result.Add(row);
                        result.Append(value);

                        await CallbackTable(id, table_name, TableEvent.AddRow, result);

                        return(row);
                    }
                    else
                    {
                        return(Global.INVALID_ROW);
                    }
                }
                else
                {
                    INode node = GrainFactory.GetGrain <INode>(id.Origin);
                    return(await node.AddRow(id, table_name, value));
                }
            }
        }
示例#2
0
        public async Task SetRowValue(Nuid id, string table_name, long row, NList value)
        {
            if (NList.IsEmpty(value))
            {
                return;
            }

            Entity entity = EntityManager.Get(id);

            if (entity != null)
            {
                Table table = entity.GetTable(table_name);
                if (table == null)
                {
                    return;
                }

                NList result;
                if (!table.TrySetRow(row, value, out result))
                {
                    return;
                }

                BatchCahceList.Add(NList.New().Add((int)CacheOption.SetRow).Add(id).Add(table_name).Add(row).Add(value));
                await CallbackTable(id, table_name, TableEvent.SetRow, result);
            }
            else
            {
                if (id.Origin == Identity)
                {
                    if (await SetCacheRow(id, table_name, row, value))
                    {
                        NList result = NList.New();
                        result.Add(row);
                        result.Append(value);
                        await CallbackTable(id, table_name, TableEvent.SetRow, result);
                    }
                }
                else
                {
                    INode node = GrainFactory.GetGrain <INode>(id.Origin);
                    await node.SetRowValue(id, table_name, row, value);
                }
            }
        }