Mercurial > hg > Database > jungle-sharp
changeset 30:236a58985e22
error fix, use continue path.
author | Kazuma Takeda |
---|---|
date | Wed, 18 Jan 2017 21:54:26 +0900 |
parents | f7616084d3ab |
children | 1466993c104c |
files | Main/jungle-main/JungleTreeEditor.cs Main/jungle-main/store/impl/DefaultTreeEditor.cs Main/jungle-main/transaction/DefaultJungleTreeEditor.cs Main/jungle-network/transaction/NetworkDefaultJungleTreeEditor.cs |
diffstat | 4 files changed, 211 insertions(+), 200 deletions(-) [+] |
line wrap: on
line diff
--- 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<Error,JungleTreeEditor> addNewChildAt(NodePath path,int pos); Either<Error,JungleTreeEditor> deleteChildAt(NodePath path,int pos); Either<Error,JungleTreeEditor> putAttribute(NodePath path,string key, byte[] value);
--- 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<TreeNode> targetDirection = path.headList (); TreeNode target = targetDirection.getTarget (); Either<Error, LoggingNode> either = editor.edit (target); - if (either.isA ()) { + + if (either.isA ()) return DefaultEither<Error, LoggingNode>.newA (either.a ()); - } LoggingNode newWrap = either.b (); @@ -44,9 +44,9 @@ TreeNodeChildren chs = parentDirection.getTarget ().getChildren (); Either<Error, TreeNode> ret = chs.replaceNode (pos, child); - if (ret.isA ()) { + + if (ret.isA ()) return DefaultEither<Error, LoggingNode>.newA (ret.a ()); - } child = ret.b (); pos = parentDirection.getPosition ();
--- 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<Error,JungleTreeEditor> _edit(NodePath _path, NodeEditor _e) { Either<Error, LoggingNode> either = editor.edit (root, _path, _e); - if (either.isA ()) { + if (either.isA ()) return DefaultEither<Error, JungleTreeEditor>.newA (either.a ()); - } LoggingNode newLogging = either.b (); OperationLog newLog = newLogging.getOperationLog (); TreeNode newNode = newLogging.getWrap (); IterableConverter<TreeOperation,NodeOperation>.Converter<TreeOperation, NodeOperation> converter = new InnerConverter (_path); - + IEnumerable<TreeOperation> iterable = new IterableConverter<TreeOperation, NodeOperation> (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<Error, JungleTreeEditor>.newB (newEditor); }
--- 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<Error,JungleTreeEditor> TreeEditor(NodePath path, NodeEditor editor) - { - //LoggingNodeHook hook = new LoggingNodeHook(_e); - Either<Error,LoggingNode> either = this.Editor.edit(this.Root, path, editor); - if(either.isA()){ - return DefaultEither<Error, JungleTreeEditor>.newA(either.a()); - } - - TreeNode newNode = either.b().getWrap(); - OperationLog newLog = either.b().getOperationLog(); - - // IterableConverter.Converter<TreeOperation,NodeOperation> converter = new IterableConverter.Converter<TreeOperation,NodeOperation>(){ - // public TreeOperation conv(NodeOperation _b){ - // return new DefaultTreeOperation(_path,_b); - // } - // }; - - // I must fix this code. - IterableConverter<TreeOperation,NodeOperation>.Converter<TreeOperation,NodeOperation> converter = new InnerConverter(path); - - IEnumerable<TreeOperation> iterable = new IterableConverter<TreeOperation,NodeOperation>(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<Error, JungleTreeEditor>.newB(newEditor); - } - - - public Either<Error,JungleTreeEditor> addNewChildAt(NodePath _path, int _pos) { - prevPath = _path.add (_pos); - AppendChildAt appendChildAt = new AppendChildAt(_pos); - return this.TreeEditor(_path,appendChildAt); - } - - public Either<Error,JungleTreeEditor> deleteChildAt(NodePath _path, int _pos) - { - DeleteChildAt deleteChildAt = new DeleteChildAt(_pos); - return this.TreeEditor(_path,deleteChildAt); - } - - public Either<Error,JungleTreeEditor> putAttribute(NodePath _path, string _key, byte[] _value) - { - PutAttribute putAttribute = new PutAttribute(_key,_value); - return this.TreeEditor(_path,putAttribute); - } - - public Either<Error,JungleTreeEditor> putAttribute(string _key, byte[] _value) - { - PutAttribute putAttribute = new PutAttribute(_key,_value); - return this.TreeEditor(prevPath, putAttribute); - } - - public Either<Error,JungleTreeEditor> deleteAttribute(NodePath _path, string _key) - { - DeleteAttribute deleteAttribute = new DeleteAttribute(_key); - return this.TreeEditor(_path,deleteAttribute); - } - - public Either<Error,JungleTreeEditor> edit(NodePath _path, NodeEditor _editor) - { - return this.TreeEditor(_path,_editor); - } - - public Either<Error,JungleTreeEditor> commit() - { - Either<Error,TransactionManager> either = TxManager.commit(this.Root, this.Log); - if(either.isA()){ - return DefaultEither<Error, JungleTreeEditor>.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<Error, JungleTreeEditor>.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<TreeOperation> 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<TreeOperation> newLog, string nextRevision) { - // NetworkTreeOperationLog netLog = new NetworkTreeOperationLog(_uuid, _treeName,newLog); - // CodeSegment cs = new LogPutCodeSegment(netLog); - // cs.execute(); - } - - public Either<Error, JungleTreeEditor> replaceNewRootNode() { - // TODO Auto-generated method stub - return null; - } - - public Either<Error, JungleTreeEditor> flushSuccess() { - // TODO Auto-generated method stub - return null; - } - - public class InnerConverter : IterableConverter<TreeOperation,NodeOperation>.Converter<TreeOperation,NodeOperation>{ - 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<Error,JungleTreeEditor> TreeEditor(NodePath path, NodeEditor editor) + { + //LoggingNodeHook hook = new LoggingNodeHook(_e); + Either<Error,LoggingNode> either = this.Editor.edit(this.Root, path, editor); + if(either.isA()){ + return DefaultEither<Error, JungleTreeEditor>.newA(either.a()); + } + + TreeNode newNode = either.b().getWrap(); + OperationLog newLog = either.b().getOperationLog(); + + // IterableConverter.Converter<TreeOperation,NodeOperation> converter = new IterableConverter.Converter<TreeOperation,NodeOperation>(){ + // public TreeOperation conv(NodeOperation _b){ + // return new DefaultTreeOperation(_path,_b); + // } + // }; + + // I must fix this code. + IterableConverter<TreeOperation,NodeOperation>.Converter<TreeOperation,NodeOperation> converter = new InnerConverter(path); + + IEnumerable<TreeOperation> iterable = new IterableConverter<TreeOperation,NodeOperation>(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<Error, JungleTreeEditor>.newB(newEditor); + } + + + public Either<Error,JungleTreeEditor> addNewChildAt(NodePath _path, int _pos) { + prevPath = _path.add (_pos); + AppendChildAt appendChildAt = new AppendChildAt(_pos); + return this.TreeEditor(_path,appendChildAt); + } + + public Either<Error,JungleTreeEditor> deleteChildAt(NodePath _path, int _pos) + { + DeleteChildAt deleteChildAt = new DeleteChildAt(_pos); + return this.TreeEditor(_path,deleteChildAt); + } + + public Either<Error,JungleTreeEditor> putAttribute(NodePath _path, string _key, byte[] _value) + { + PutAttribute putAttribute = new PutAttribute(_key,_value); + return this.TreeEditor(_path,putAttribute); + } + + public Either<Error,JungleTreeEditor> putAttribute(string _key, byte[] _value) + { + PutAttribute putAttribute = new PutAttribute(_key,_value); + return this.TreeEditor(prevPath, putAttribute); + } + + public Either<Error,JungleTreeEditor> deleteAttribute(NodePath _path, string _key) + { + DeleteAttribute deleteAttribute = new DeleteAttribute(_key); + return this.TreeEditor(_path,deleteAttribute); + } + + public Either<Error,JungleTreeEditor> edit(NodePath _path, NodeEditor _editor) + { + return this.TreeEditor(_path,_editor); + } + + public Either<Error,JungleTreeEditor> commit() + { + Either<Error,TransactionManager> either = TxManager.commit(this.Root, this.Log); + if(either.isA()){ + return DefaultEither<Error, JungleTreeEditor>.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<Error, JungleTreeEditor>.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<TreeOperation> 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<TreeOperation> newLog, string nextRevision) { + // NetworkTreeOperationLog netLog = new NetworkTreeOperationLog(_uuid, _treeName,newLog); + // CodeSegment cs = new LogPutCodeSegment(netLog); + // cs.execute(); + } + + public Either<Error, JungleTreeEditor> replaceNewRootNode() { + // TODO Auto-generated method stub + return null; + } + + public Either<Error, JungleTreeEditor> flushSuccess() { + // TODO Auto-generated method stub + return null; + } + + public class InnerConverter : IterableConverter<TreeOperation,NodeOperation>.Converter<TreeOperation,NodeOperation>{ + NodePath path; + + public InnerConverter(NodePath _path) { + path = _path; + } + + + public TreeOperation conv(NodeOperation _b){ + return new DefaultTreeOperation(path,_b); + } + } + } +}