-
Notifications
You must be signed in to change notification settings - Fork 66
/
ormentry.lua
70 lines (58 loc) · 1.43 KB
/
ormentry.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
local setmetatable = setmetatable
local pairs = pairs
local M = {}
local mata = {
__index = M,
}
-- 新建条目数据
function M:new(ormtab, entry_data)
local t = {
_ormtab = ormtab,
_entry_data = entry_data,
_change_map = {}, --变更的条目
}
setmetatable(t, mata)
return t
end
--新增无效条目数据 用于防止缓存穿透
function M:new_invaild(entry_data)
local t = {
_entry_data = entry_data,
_invaild = true,
}
setmetatable(t, mata)
return t
end
-- 获取条目数据的值
function M:get(filed_name)
return self._entry_data[filed_name]
end
-- 修改条目数据的值
function M:set(filed_name, filed_value)
if filed_value == self._entry_data[filed_name] then return end
local ormtab = self._ormtab
ormtab:check_one_filed(filed_name, filed_value)
self._entry_data[filed_name] = filed_value
self._change_map[filed_name] = true --标记变更
ormtab:set_change_entry(self)
end
-- 获取数据表
function M:get_entry_data()
return self._entry_data
end
-- 获取修改条目
function M:get_change_map()
return self._change_map
end
-- 清除变更标记
function M:clear_change()
local change_map = self._change_map
for filed_name in pairs(change_map) do
change_map[filed_name] = nil
end
end
--是否无效条目
function M:is_invaild()
return self._invaild
end
return M