summaryrefslogtreecommitdiffstats
path: root/acf/transaction/init.lua
diff options
context:
space:
mode:
authorKaarle Ritvanen <kaarle.ritvanen@datakunkku.fi>2013-06-27 20:18:54 +0300
committerKaarle Ritvanen <kaarle.ritvanen@datakunkku.fi>2013-06-28 13:24:36 +0300
commit5c960909594d1978f45968f8155ab2afab381298 (patch)
tree40d6de63ce5818a46b05794a4596329c28d4bd5f /acf/transaction/init.lua
parent0d5dade5ab61e5cfd3116893aadcb9b16ba5cfb5 (diff)
downloadacf2-5c960909594d1978f45968f8155ab2afab381298.tar.bz2
acf2-5c960909594d1978f45968f8155ab2afab381298.tar.xz
eliminate data type arguments from transaction and persistence manager intefaces
utilize model topology information instead
Diffstat (limited to 'acf/transaction/init.lua')
-rw-r--r--acf/transaction/init.lua37
1 files changed, 15 insertions, 22 deletions
diff --git a/acf/transaction/init.lua b/acf/transaction/init.lua
index ec83aae..b18c57a 100644
--- a/acf/transaction/init.lua
+++ b/acf/transaction/init.lua
@@ -53,26 +53,25 @@ function Transaction:check()
if not self.backend then error('Transaction already committed') end
end
-function Transaction:get(path, t)
+function Transaction:get(path)
self:check()
if self.deleted[path] then return nil, self.mod_time[path] end
for _, tbl in ipairs{self.added, self.modified} do
if tbl[path] ~= nil then
- return copy(tbl[path][2]), self.mod_time[path]
+ return copy(tbl[path]), self.mod_time[path]
end
end
- local value, timestamp = self.backend:get_if_older(path, self.started, t)
+ local value, timestamp = self.backend:get_if_older(path, self.started)
self.access_time[path] = timestamp
return value, timestamp
end
function Transaction:_set_multiple(mods)
- local function set(path, t, value, new)
+ local function set(path, value, new)
local delete = value == nil
- value = not delete and {t, value} or nil
if self.added[path] == nil and (not new or self.deleted[path]) then
self.modified[path] = value
@@ -81,35 +80,33 @@ function Transaction:_set_multiple(mods)
end
for _, mod in ipairs(mods) do
- local path, t, value = unpack(mod)
+ local path, value = unpack(mod)
local ppath = pth.parent(path)
- local parent = self:get(ppath, 'table')
+ local parent = self:get(ppath)
if parent == nil then
- self:set(ppath, 'table', true)
parent = {}
+ self:set(ppath, parent)
end
local name = pth.name(path)
local old = self:get(path)
- local is_table = t == 'table'
- local delete = not is_table and value == nil
+ local delete = value == nil
if type(old) == 'table' then
if delete then
for _, child in ipairs(old) do self:set(pth.join(path, child)) end
- elseif is_table then return
+ elseif type(value) == 'table' then return
elseif #old > 0 then
error('Cannot assign a primitive value to non-leaf node '..path)
end
end
- if is_table then value = {} end
- set(path, not delete and t or nil, value, old == nil)
+ set(path, value, old == nil)
local function set_parent()
- set(ppath, 'table', parent)
+ set(ppath, parent)
self.mod_time[ppath] = self.mod_time[path]
end
@@ -143,9 +140,9 @@ function Transaction:commit()
local mods = {}
local handled = {}
- local function insert(path, t, value)
+ local function insert(path, value)
assert(not handled[path])
- table.insert(mods, {path, t, value})
+ table.insert(mods, {path, value})
handled[path] = true
end
@@ -153,10 +150,7 @@ function Transaction:commit()
if not handled[path] then
local pp = pth.parent(path)
if self.added[pp] then insert_add(pp) end
-
- local t, value = unpack(self.added[path])
- if t == 'table' then value = nil end
- insert(path, t, value)
+ insert(path, self.added[path])
end
end
@@ -179,8 +173,7 @@ function Transaction:commit()
end
for path, value in pairs(self.modified) do
- local t, v = unpack(value)
- if t ~= 'table' then insert(path, t, v) end
+ if type(value) ~= 'table' then insert(path, value) end
end
for path, _ in pairs(self.added) do insert_add(path) end