VOL-1174: Ported transaction support to go data model

Change-Id: I4cabefac36c95f690aa121c71f36b6aaf41180b0
diff --git a/db/model/root.go b/db/model/root.go
index d10e9f1..b4885c1 100644
--- a/db/model/root.go
+++ b/db/model/root.go
@@ -27,7 +27,7 @@
 
 type Root struct {
 	*Node
-	DirtyNodes            map[string]*Node
+	DirtyNodes            map[string][]*Node
 	KvStore               *Backend
 	Loading               bool
 	RevisionClass         interface{}
@@ -38,7 +38,7 @@
 func NewRoot(initialData interface{}, kvStore *Backend, revisionClass interface{}) *Root {
 	root := &Root{}
 	root.KvStore = kvStore
-	root.DirtyNodes = make(map[string]*Node)
+	root.DirtyNodes = make(map[string][]*Node)
 	root.Loading = false
 	if kvStore != nil /*&& TODO: RevisionClass is not a subclass of PersistedRevision ??? */ {
 		revisionClass = reflect.TypeOf(PersistedRevision{})
@@ -63,23 +63,23 @@
 func (r *Root) MakeTxBranch() string {
 	txid_bin, _ := uuid.New().MarshalBinary()
 	txid := hex.EncodeToString(txid_bin)[:12]
-	r.DirtyNodes[txid] = r.Node
+	r.DirtyNodes[txid] = []*Node{r.Node}
 	r.Node.makeTxBranch(txid)
 	return txid
 }
 
 func (r *Root) DeleteTxBranch(txid string) {
-	for _, dirtyNode := range r.DirtyNodes {
+	for _, dirtyNode := range r.DirtyNodes[txid] {
 		dirtyNode.deleteTxBranch(txid)
 	}
 	delete(r.DirtyNodes, txid)
 }
 
 func (r *Root) FoldTxBranch(txid string) {
-	if err := r.Node.mergeTxBranch(txid, true); err != nil {
+	if _, err := r.mergeTxBranch(txid, true); err != nil {
 		r.DeleteTxBranch(txid)
 	} else {
-		r.Node.mergeTxBranch(txid, false)
+		r.mergeTxBranch(txid, false)
 		r.executeCallbacks()
 	}
 }
@@ -120,10 +120,8 @@
 	}
 
 	if txid != "" {
-		//dirtied := r.DirtyNodes[txid]
-
 		trackDirty := func(node *Node) *Branch {
-			//dirtied.Add(Node)
+			r.DirtyNodes[txid] = append(r.DirtyNodes[txid], node)
 			return node.makeTxBranch(txid)
 		}
 		result = r.Node.Update(path, data, strict, txid, trackDirty)
@@ -148,10 +146,8 @@
 	}
 
 	if txid != "" {
-		//dirtied := r.DirtyNodes[txid]
-
 		trackDirty := func(node *Node) *Branch {
-			//dirtied.Add(Node)
+			r.DirtyNodes[txid] = append(r.DirtyNodes[txid], node)
 			return node.makeTxBranch(txid)
 		}
 		result = r.Node.Add(path, data, txid, trackDirty)
@@ -176,10 +172,8 @@
 	}
 
 	if txid != "" {
-		//dirtied := r.DirtyNodes[txid]
-
 		trackDirty := func(node *Node) *Branch {
-			//dirtied.Add(Node)
+			r.DirtyNodes[txid] = append(r.DirtyNodes[txid], node)
 			return node.makeTxBranch(txid)
 		}
 		result = r.Node.Remove(path, txid, trackDirty)