Ejemplo n.º 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));
                }
            }
        }
Ejemplo n.º 2
0
        public async Task SetRowCol <T>(Nuid id, string table_name, long row, int col, T value)
        {
            if (value == null)
            {
                return;
            }

            Entity entity = EntityManager.Get(id);

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

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

                NList row_value = table.GetRow(row);
                BatchCahceList.Add(NList.New().Add((int)CacheOption.SetRow).Add(id).Add(table_name).Add(row).Add(row_value));
                await CallbackTable(id, table_name, TableEvent.SetCol, result);
            }
            else
            {
                if (id.Origin == Identity)
                {
                    NList row_value = NList.New();
                    NList old_value = await GetCacheRowValue(id, table_name, row);

                    T old_row_value = old_value.Get <T>(col);
                    row_value.Append(old_value);
                    row_value.Set(col, value);

                    if (await SetCacheRow(id, table_name, row, row_value))
                    {
                        NList result = NList.New();
                        result.Add(row);
                        result.Add(col);
                        result.Add(old_row_value);
                        result.Add(value);

                        await CallbackTable(id, table_name, TableEvent.SetCol, result);
                    }
                }
                else
                {
                    INode node = GrainFactory.GetGrain <INode>(id.Origin);
                    await node.SetRowCol(id, table_name, row, col, value);
                }
            }
        }
Ejemplo n.º 3
0
        public async Task SetField <T>(Nuid id, string field_name, T field_value)
        {
            if (field_value == null)
            {
                return;
            }

            Entity entity = EntityManager.Get(id);

            if (entity != null)
            {
                Field field = entity.GetField(field_name);
                if (field == null)
                {
                    return;
                }

                NList result;
                if (!field.TrySet(field_value, out result))
                {
                    return;
                }

                BatchCahceList.Add(NList.New().Add((int)CacheOption.SetField).Add(id).Add(field_name).Add(ProtoUtils.Serialize(field_value)));

                await CallbackField(id, field_name, FieldEvent.Change, result);
            }
            else
            {
                if (id.Origin == Identity)
                {
                    T old_value = await GetCacheField <T>(id, field_name);

                    if (await SetCacheField(id, field_name, field_value))
                    {
                        NList result = NList.New();
                        result.Add(old_value);
                        result.Add(field_value);
                        await CallbackField(id, field_name, FieldEvent.Change, result);
                    }
                }
                else
                {
                    INode node = GrainFactory.GetGrain <INode>(id.Origin);
                    await node.SetField(id, field_name, field_value);
                }
            }
        }
Ejemplo n.º 4
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);
                }
            }
        }
Ejemplo n.º 5
0
        public async Task <Nuid> Create(Nuid id, string type, NList args)
        {
            if (id.Origin == Identity)
            {
                Entity entity = EntityManager.Create(id, type);
                if (entity == null)
                {
                    return(Nuid.Empty);
                }

                BatchCahceList.Add(NList.New().Add((int)CacheOption.SetEntity).Add(id).Add(type));

                await CallbackEntity(id, EntityEvent.OnCreate, args);
            }
            else
            {
                INode node = GrainFactory.GetGrain <INode>(id.Origin);
                return(await node.Create(id, type, args));
            }

            return(id);
        }
Ejemplo n.º 6
0
        public async Task ClearTable(Nuid id, string table_name)
        {
            Entity entity = EntityManager.Get(id);

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

                if (table.IsEmpty)
                {
                    return;
                }

                table.Clear();

                BatchCahceList.Add(NList.New().Add((int)CacheOption.ClearTable).Add(id).Add(table_name));
                await CallbackTable(id, table_name, TableEvent.Clear, NList.Empty);
            }
            else
            {
                if (id.Origin == Identity)
                {
                    if (await ClearCacheTable(id, table_name))
                    {
                        await CallbackTable(id, table_name, TableEvent.Clear, NList.Empty);
                    }
                }
                else
                {
                    INode node = GrainFactory.GetGrain <INode>(id.Origin);
                    await node.ClearTable(id, table_name);
                }
            }
        }