blob: b7288ab8ebcb6035504a507ce59f31aab454b733 [file] [log] [blame]
Stephane Barbarie4a2564d2018-07-26 11:02:58 -04001package model
2
3import "fmt"
4
5type Transaction struct {
6 proxy *Proxy
7 txid string
8}
9
10func NewTransaction(proxy *Proxy, txid string) *Transaction {
11 tx := &Transaction{
12 proxy: proxy,
13 txid: txid,
14 }
15 return tx
16}
17func (t *Transaction) Get(path string, depth int, deep bool) *Revision {
18 if t.txid == "" {
19 fmt.Errorf("closed transaction")
20 return nil
21 }
22 // TODO: need to review the return values at the different layers!!!!!
23 return t.proxy.Get(path, depth, deep, t.txid).(*Revision)
24}
25func (t *Transaction) Update(path string, data interface{}, strict bool) *Revision {
26 if t.txid == "" {
27 fmt.Errorf("closed transaction")
28 return nil
29 }
30 return t.proxy.Update(path, data, strict, t.txid).(*Revision)
31}
32func (t *Transaction) Add(path string, data interface{}) *Revision {
33 if t.txid == "" {
34 fmt.Errorf("closed transaction")
35 return nil
36 }
37 return t.proxy.Add(path, data, t.txid).(*Revision)
38}
39func (t *Transaction) Remove(path string) *Revision {
40 if t.txid == "" {
41 fmt.Errorf("closed transaction")
42 return nil
43 }
44 return t.proxy.Remove(path, t.txid).(*Revision)
45}
46func (t *Transaction) Cancel() {
47 t.proxy.cancelTransaction(t.txid)
48 t.txid = ""
49}
50func (t *Transaction) Commit() {
51 t.proxy.commitTransaction(t.txid)
52 t.txid = ""
53}