# HG changeset patch # User Kazuma Takeda # Date 1484744066 -32400 # Node ID 236a58985e22e8fdd356288f4b5269b53147d28c # Parent f7616084d3ab351d3b3dc1522a1389d545c3aeb1 error fix, use continue path. diff -r f7616084d3ab -r 236a58985e22 Main/jungle-main/JungleTreeEditor.cs --- a/Main/jungle-main/JungleTreeEditor.cs Wed Jan 18 21:02:24 2017 +0900 +++ b/Main/jungle-main/JungleTreeEditor.cs Wed Jan 18 21:54:26 2017 +0900 @@ -1,6 +1,7 @@  namespace JungleDB { public interface JungleTreeEditor { + void SetPrevPath (NodePath path); Either addNewChildAt(NodePath path,int pos); Either deleteChildAt(NodePath path,int pos); Either putAttribute(NodePath path,string key, byte[] value); diff -r f7616084d3ab -r 236a58985e22 Main/jungle-main/store/impl/DefaultTreeEditor.cs --- a/Main/jungle-main/store/impl/DefaultTreeEditor.cs Wed Jan 18 21:02:24 2017 +0900 +++ b/Main/jungle-main/store/impl/DefaultTreeEditor.cs Wed Jan 18 21:54:26 2017 +0900 @@ -31,9 +31,9 @@ Direction targetDirection = path.headList (); TreeNode target = targetDirection.getTarget (); Either either = editor.edit (target); - if (either.isA ()) { + + if (either.isA ()) return DefaultEither.newA (either.a ()); - } LoggingNode newWrap = either.b (); @@ -44,9 +44,9 @@ TreeNodeChildren chs = parentDirection.getTarget ().getChildren (); Either ret = chs.replaceNode (pos, child); - if (ret.isA ()) { + + if (ret.isA ()) return DefaultEither.newA (ret.a ()); - } child = ret.b (); pos = parentDirection.getPosition (); diff -r f7616084d3ab -r 236a58985e22 Main/jungle-main/transaction/DefaultJungleTreeEditor.cs --- a/Main/jungle-main/transaction/DefaultJungleTreeEditor.cs Wed Jan 18 21:02:24 2017 +0900 +++ b/Main/jungle-main/transaction/DefaultJungleTreeEditor.cs Wed Jan 18 21:54:26 2017 +0900 @@ -10,6 +10,10 @@ private TreeOperationLog log; private NodePath prevPath; + public void SetPrevPath (NodePath path) { + this.prevPath = path; + } + public DefaultJungleTreeEditor(TreeNode _root,TransactionManager _txManager,TreeEditor _editor) : this(_root, _txManager, _editor, new DefaultTreeOperationLog()) { @@ -17,7 +21,7 @@ - public DefaultJungleTreeEditor(TreeNode newNode,TransactionManager txManager,TreeEditor editor,TreeOperationLog log) + public DefaultJungleTreeEditor(TreeNode newNode, TransactionManager txManager,TreeEditor editor,TreeOperationLog log) { this.root = newNode; this.txManager = txManager; @@ -30,22 +34,22 @@ private Either _edit(NodePath _path, NodeEditor _e) { Either either = editor.edit (root, _path, _e); - if (either.isA ()) { + if (either.isA ()) return DefaultEither.newA (either.a ()); - } LoggingNode newLogging = either.b (); OperationLog newLog = newLogging.getOperationLog (); TreeNode newNode = newLogging.getWrap (); IterableConverter.Converter converter = new InnerConverter (_path); - + IEnumerable iterable = new IterableConverter (newLog, converter); DefaultTreeOperationLog treeOperationLog = new DefaultTreeOperationLog (iterable, newLog.length ()); TreeOperationLog newTreeOpLog = log.append (treeOperationLog); JungleTreeEditor newEditor = new DefaultJungleTreeEditor (newNode, txManager, editor, newTreeOpLog); + newEditor.SetPrevPath (this.prevPath); return DefaultEither.newB (newEditor); } diff -r f7616084d3ab -r 236a58985e22 Main/jungle-network/transaction/NetworkDefaultJungleTreeEditor.cs --- a/Main/jungle-network/transaction/NetworkDefaultJungleTreeEditor.cs Wed Jan 18 21:02:24 2017 +0900 +++ b/Main/jungle-network/transaction/NetworkDefaultJungleTreeEditor.cs Wed Jan 18 21:54:26 2017 +0900 @@ -1,192 +1,198 @@ -using UnityEngine; -using System.Collections; -using System.Collections.Generic; - -namespace JungleDB { - public class NetworkDefaultJungleTreeEditor : JungleTreeEditor { - private readonly TransactionManager TxManager; - private readonly TreeNode Root; - private readonly TreeEditor Editor; - private readonly string TreeName; - private readonly TreeOperationLog Log; - private bool ExportLog; - - private NodePath prevPath; - - public NetworkDefaultJungleTreeEditor(string tname, TreeNode root, TransactionManager txMan, TreeEditor edit) - { - this.TreeName = tname; - this.Root = root; - this.TxManager = txMan; - this.Editor = edit; - this.Log = new DefaultTreeOperationLog(); - this.ExportLog = true; - } - - public NetworkDefaultJungleTreeEditor(string tname, TreeNode root, TransactionManager txMan, TreeEditor edit, TreeOperationLog log) { - this.TreeName = tname; - this.Root = root; - this.TxManager = txMan; - this.Editor = edit; - this.Log = log; - this.ExportLog = true; - } - - public static NetworkDefaultJungleTreeEditor NewLocalTreeEditor(string tname, TreeNode root, TransactionManager txMan, TreeEditor edit) { - NetworkDefaultJungleTreeEditor treeEditor = new NetworkDefaultJungleTreeEditor(tname, root, txMan, edit, new DefaultTreeOperationLog()); - treeEditor.ExportLog = false; - return treeEditor; - } - - public static NetworkDefaultJungleTreeEditor NewLocalTreeEditor(string tname, TreeNode root, TransactionManager txMan, TreeEditor edit, TreeOperationLog log) { - NetworkDefaultJungleTreeEditor treeEditor = new NetworkDefaultJungleTreeEditor(tname, root, txMan, edit, log); - treeEditor.ExportLog = false; - return treeEditor; - } - - - private Either TreeEditor(NodePath path, NodeEditor editor) - { - //LoggingNodeHook hook = new LoggingNodeHook(_e); - Either either = this.Editor.edit(this.Root, path, editor); - if(either.isA()){ - return DefaultEither.newA(either.a()); - } - - TreeNode newNode = either.b().getWrap(); - OperationLog newLog = either.b().getOperationLog(); - - // IterableConverter.Converter converter = new IterableConverter.Converter(){ - // public TreeOperation conv(NodeOperation _b){ - // return new DefaultTreeOperation(_path,_b); - // } - // }; - - // I must fix this code. - IterableConverter.Converter converter = new InnerConverter(path); - - IEnumerable iterable = new IterableConverter(newLog, converter); - DefaultTreeOperationLog treeOperationLog = new DefaultTreeOperationLog(iterable,newLog.length()); - TreeOperationLog newTreeOpLog = Log.append(treeOperationLog); - - JungleTreeEditor newEditor; - if(this.ExportLog) { - newEditor = new NetworkDefaultJungleTreeEditor(this.TreeName, newNode, this.TxManager, this.Editor, newTreeOpLog); - } else { - newEditor = NetworkDefaultJungleTreeEditor.NewLocalTreeEditor(this.TreeName, newNode, TxManager, this.Editor, newTreeOpLog); - } - return DefaultEither.newB(newEditor); - } - - - public Either addNewChildAt(NodePath _path, int _pos) { - prevPath = _path.add (_pos); - AppendChildAt appendChildAt = new AppendChildAt(_pos); - return this.TreeEditor(_path,appendChildAt); - } - - public Either deleteChildAt(NodePath _path, int _pos) - { - DeleteChildAt deleteChildAt = new DeleteChildAt(_pos); - return this.TreeEditor(_path,deleteChildAt); - } - - public Either putAttribute(NodePath _path, string _key, byte[] _value) - { - PutAttribute putAttribute = new PutAttribute(_key,_value); - return this.TreeEditor(_path,putAttribute); - } - - public Either putAttribute(string _key, byte[] _value) - { - PutAttribute putAttribute = new PutAttribute(_key,_value); - return this.TreeEditor(prevPath, putAttribute); - } - - public Either deleteAttribute(NodePath _path, string _key) - { - DeleteAttribute deleteAttribute = new DeleteAttribute(_key); - return this.TreeEditor(_path,deleteAttribute); - } - - public Either edit(NodePath _path, NodeEditor _editor) - { - return this.TreeEditor(_path,_editor); - } - - public Either commit() - { - Either either = TxManager.commit(this.Root, this.Log); - if(either.isA()){ - return DefaultEither.newA(either.a()); - } - // if(this.ExportLog) { - // try { - // putTreeOperationLog(this.Log); - // } catch (IOException e) { - // return DefaultEither.newA(either.a()); - // } - // } - - TransactionManager newTxManager = either.b(); - JungleTreeEditor newTreeEditor = new NetworkDefaultJungleTreeEditor(this.TreeName, this.Root, newTxManager, this.Editor); - - return DefaultEither.newB(newTreeEditor); - } - - private string getID() - { - return this.TxManager.getUUID(); - } - - private string getRevision() - { - return this.TxManager.getRevision().ToString(); - } - - public string getTreeName() { - return this.TreeName; - } - - public TreeOperationLog getTreeOperationLog() { - return this.Log; - } - - public void putTreeOperationLog(IEnumerable newLog) { - string uuid = getID(); - string treeName = getTreeName(); - string updaterName = getID(); - string revision = getRevision(); - putDataSegment(uuid, treeName, updaterName, newLog, revision); - } - - public void putDataSegment(string _uuid, string _treeName, string _updaterName, IEnumerable newLog, string nextRevision) { - // NetworkTreeOperationLog netLog = new NetworkTreeOperationLog(_uuid, _treeName,newLog); - // CodeSegment cs = new LogPutCodeSegment(netLog); - // cs.execute(); - } - - public Either replaceNewRootNode() { - // TODO Auto-generated method stub - return null; - } - - public Either flushSuccess() { - // TODO Auto-generated method stub - return null; - } - - public class InnerConverter : IterableConverter.Converter{ - NodePath path; - - public InnerConverter(NodePath _path) { - path = _path; - } - - - public TreeOperation conv(NodeOperation _b){ - return new DefaultTreeOperation(path,_b); - } - } - } -} +using UnityEngine; +using System.Collections; +using System.Collections.Generic; + +namespace JungleDB { + public class NetworkDefaultJungleTreeEditor : JungleTreeEditor { + private readonly TransactionManager TxManager; + private readonly TreeNode Root; + private readonly TreeEditor Editor; + private readonly string TreeName; + private readonly TreeOperationLog Log; + private bool ExportLog; + + private NodePath prevPath; + + public void SetPrevPath (NodePath path) { + this.prevPath = path; + } + + public NetworkDefaultJungleTreeEditor(string tname, TreeNode root, TransactionManager txMan, TreeEditor edit) + { + this.TreeName = tname; + this.Root = root; + this.TxManager = txMan; + this.Editor = edit; + this.Log = new DefaultTreeOperationLog(); + this.ExportLog = true; + } + + public NetworkDefaultJungleTreeEditor(string tname, TreeNode root, TransactionManager txMan, TreeEditor edit, TreeOperationLog log) { + this.TreeName = tname; + this.Root = root; + this.TxManager = txMan; + this.Editor = edit; + this.Log = log; + this.ExportLog = true; + } + + public static NetworkDefaultJungleTreeEditor NewLocalTreeEditor(string tname, TreeNode root, TransactionManager txMan, TreeEditor edit) { + NetworkDefaultJungleTreeEditor treeEditor = new NetworkDefaultJungleTreeEditor(tname, root, txMan, edit, new DefaultTreeOperationLog()); + treeEditor.ExportLog = false; + return treeEditor; + } + + public static NetworkDefaultJungleTreeEditor NewLocalTreeEditor(string tname, TreeNode root, TransactionManager txMan, TreeEditor edit, TreeOperationLog log) { + NetworkDefaultJungleTreeEditor treeEditor = new NetworkDefaultJungleTreeEditor(tname, root, txMan, edit, log); + treeEditor.ExportLog = false; + return treeEditor; + } + + + private Either TreeEditor(NodePath path, NodeEditor editor) + { + //LoggingNodeHook hook = new LoggingNodeHook(_e); + Either either = this.Editor.edit(this.Root, path, editor); + if(either.isA()){ + return DefaultEither.newA(either.a()); + } + + TreeNode newNode = either.b().getWrap(); + OperationLog newLog = either.b().getOperationLog(); + + // IterableConverter.Converter converter = new IterableConverter.Converter(){ + // public TreeOperation conv(NodeOperation _b){ + // return new DefaultTreeOperation(_path,_b); + // } + // }; + + // I must fix this code. + IterableConverter.Converter converter = new InnerConverter(path); + + IEnumerable iterable = new IterableConverter(newLog, converter); + DefaultTreeOperationLog treeOperationLog = new DefaultTreeOperationLog(iterable,newLog.length()); + TreeOperationLog newTreeOpLog = Log.append(treeOperationLog); + + JungleTreeEditor newEditor; + if(this.ExportLog) { + newEditor = new NetworkDefaultJungleTreeEditor(this.TreeName, newNode, this.TxManager, this.Editor, newTreeOpLog); + newEditor.SetPrevPath (this.prevPath); + } else { + newEditor = NetworkDefaultJungleTreeEditor.NewLocalTreeEditor(this.TreeName, newNode, TxManager, this.Editor, newTreeOpLog); + newEditor.SetPrevPath (this.prevPath); + } + return DefaultEither.newB(newEditor); + } + + + public Either addNewChildAt(NodePath _path, int _pos) { + prevPath = _path.add (_pos); + AppendChildAt appendChildAt = new AppendChildAt(_pos); + return this.TreeEditor(_path,appendChildAt); + } + + public Either deleteChildAt(NodePath _path, int _pos) + { + DeleteChildAt deleteChildAt = new DeleteChildAt(_pos); + return this.TreeEditor(_path,deleteChildAt); + } + + public Either putAttribute(NodePath _path, string _key, byte[] _value) + { + PutAttribute putAttribute = new PutAttribute(_key,_value); + return this.TreeEditor(_path,putAttribute); + } + + public Either putAttribute(string _key, byte[] _value) + { + PutAttribute putAttribute = new PutAttribute(_key,_value); + return this.TreeEditor(prevPath, putAttribute); + } + + public Either deleteAttribute(NodePath _path, string _key) + { + DeleteAttribute deleteAttribute = new DeleteAttribute(_key); + return this.TreeEditor(_path,deleteAttribute); + } + + public Either edit(NodePath _path, NodeEditor _editor) + { + return this.TreeEditor(_path,_editor); + } + + public Either commit() + { + Either either = TxManager.commit(this.Root, this.Log); + if(either.isA()){ + return DefaultEither.newA(either.a()); + } + // if(this.ExportLog) { + // try { + // putTreeOperationLog(this.Log); + // } catch (IOException e) { + // return DefaultEither.newA(either.a()); + // } + // } + + TransactionManager newTxManager = either.b(); + JungleTreeEditor newTreeEditor = new NetworkDefaultJungleTreeEditor(this.TreeName, this.Root, newTxManager, this.Editor); + + return DefaultEither.newB(newTreeEditor); + } + + private string getID() + { + return this.TxManager.getUUID(); + } + + private string getRevision() + { + return this.TxManager.getRevision().ToString(); + } + + public string getTreeName() { + return this.TreeName; + } + + public TreeOperationLog getTreeOperationLog() { + return this.Log; + } + + public void putTreeOperationLog(IEnumerable newLog) { + string uuid = getID(); + string treeName = getTreeName(); + string updaterName = getID(); + string revision = getRevision(); + putDataSegment(uuid, treeName, updaterName, newLog, revision); + } + + public void putDataSegment(string _uuid, string _treeName, string _updaterName, IEnumerable newLog, string nextRevision) { + // NetworkTreeOperationLog netLog = new NetworkTreeOperationLog(_uuid, _treeName,newLog); + // CodeSegment cs = new LogPutCodeSegment(netLog); + // cs.execute(); + } + + public Either replaceNewRootNode() { + // TODO Auto-generated method stub + return null; + } + + public Either flushSuccess() { + // TODO Auto-generated method stub + return null; + } + + public class InnerConverter : IterableConverter.Converter{ + NodePath path; + + public InnerConverter(NodePath _path) { + path = _path; + } + + + public TreeOperation conv(NodeOperation _b){ + return new DefaultTreeOperation(path,_b); + } + } + } +}