示例#1
0
        public void Load(TableInfo table_info)
        {
            this.row_map = table_info.DataMap;

            foreach (string index in table_info.Index)
            {
                this.index_map[index] = new IndexData();
            }

            this.ReflushIndex();
        }
示例#2
0
        public Dictionary <string, string> Select(string condition)
        {
            RowMap search_row_map            = this.Filter(condition, "Select", false);
            Dictionary <string, string> data = new Dictionary <string, string>();

            foreach (KeyValuePair <string, RowData> pair in search_row_map)
            {
                data[pair.Key] = this.RowDataToJson(pair.Value);
            }
            return(data);
        }
示例#3
0
        public Dictionary <string, string> Delete(string condition)
        {
            RowMap search_row_map            = this.Filter(condition, "Delete", true);
            Dictionary <string, string> data = new Dictionary <string, string>();

            foreach (KeyValuePair <string, RowData> pair in search_row_map)
            {
                this.row_map.Remove(pair.Key);
                this.OnRemoveRowData(pair.Key, pair.Value);
                data[pair.Key] = this.RowDataToJson(pair.Value);
            }
            return(data);
        }
示例#4
0
        public Dictionary <string, string> Update(string condition, string json)
        {
            RowMap search_row_map            = this.Filter(condition, "Update", true);
            Dictionary <string, string> data = new Dictionary <string, string>();

            foreach (KeyValuePair <string, RowData> pair in search_row_map)
            {
                this.OnRemoveRowData(pair.Key, this.row_map[pair.Key]);
                this.row_map[pair.Key] = this.JsonToRowData(json);
                this.OnAddRowData(pair.Key, this.row_map[pair.Key]);
                data[pair.Key] = this.RowDataToJson(this.row_map[pair.Key]);
            }
            return(data);
        }
示例#5
0
        private RowMap Filter(string condition, string handle, bool is_warn = false)
        {
            JObject cond = (JObject)JsonConvert.DeserializeObject(condition);

            RowMap search_row_map = new RowMap();

            //有指定UID先筛选
            if (cond.ContainsKey("UID"))
            {
                JObject target = (JObject)JsonConvert.DeserializeObject(cond["UID"].ToString());
                if (target["op"].ToString().Equals("=="))
                {
                    string uid = target["value"].ToString();
                    if (!this.row_map.ContainsKey(uid))
                    {
                        if (is_warn)
                        {
                            throw new Exception(string.Format("{0} Table:{1} Error | Not Exist Uid:{2}", handle, this.table_name, uid));
                        }
                        return(search_row_map);
                    }
                    search_row_map[uid] = this.row_map[uid];
                }
                else
                {
                    search_row_map = this.row_map;
                }
            }
            else
            {
                search_row_map = this.row_map;
            }

            //筛选条件先与后或
            if (cond.Count > (cond.ContainsKey("$or") ? 1 : 0))
            {
                search_row_map = this.FilterCondition(search_row_map, cond, true);
            }

            if (cond.ContainsKey("$or") && ((JObject)cond["$or"]).Count > 0)
            {
                search_row_map = this.FilterCondition(search_row_map, (JObject)cond["$or"], false);
            }

            return(search_row_map);
        }
示例#6
0
        private RowMap FilterCondition(RowMap search_row_map, JObject cond, bool and_cond)
        {
            bool need_check = false;

            //先用索引筛选一遍
            RowMap and_filter_map = search_row_map;
            RowMap or_filter_map  = new RowMap();

            foreach (KeyValuePair <string, JToken> pair in cond)
            {
                if (!pair.Key.Equals("$or"))
                {
                    string value = pair.Value.ToString();
                    if (this.index_map.ContainsKey(pair.Key))
                    {
                        if (!this.index_map[pair.Key].ContainsKey(value))
                        {
                            //与条件筛选出的数据为空
                            if (and_cond)
                            {
                                return(new RowMap());
                            }
                        }
                        else
                        {
                            RowMap filter_row_map = new RowMap();
                            foreach (string uid in this.index_map[pair.Key][value])
                            {
                                if (search_row_map.ContainsKey(uid))
                                {
                                    if (and_cond)
                                    {
                                        if (and_filter_map.ContainsKey(uid))
                                        {
                                            filter_row_map[uid] = this.row_map[uid];
                                        }
                                    }
                                    else
                                    {
                                        or_filter_map[uid] = this.row_map[uid];
                                    }
                                }
                            }
                            and_filter_map = filter_row_map;
                        }
                    }
                    else
                    {
                        need_check = true;
                    }
                }
            }

            //存在没有索引的条件,需要遍历判断
            if (need_check)
            {
                RowMap filter_row_map = new RowMap();
                foreach (KeyValuePair <string, RowData> pair in search_row_map)
                {
                    string uid = pair.Key;
                    if (this.CheckCondition(uid, pair.Value, cond, and_cond))
                    {
                        filter_row_map[uid] = this.row_map[uid];
                    }
                }
                search_row_map = filter_row_map;
            }
            return(search_row_map);
        }