Mercurial > hg > Members > shoshi > jungle > jungle-core
changeset 118:baa1e2e7c503
add IndexEditor
author | one |
---|---|
date | Tue, 30 Sep 2014 13:16:10 +0900 |
parents | 74723b26ad96 |
children | 70228f5e081f |
files | src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/transaction/IndexJungleTreeEditor.java src/main/java/jp/ac/u_ryukyu/ie/cr/tatsuki/jungle/store/index/DeleteIndexEditor.java src/main/java/jp/ac/u_ryukyu/ie/cr/tatsuki/jungle/store/index/IndexEditor.java src/main/java/jp/ac/u_ryukyu/ie/cr/tatsuki/jungle/store/index/PutIndexEditor.java |
diffstat | 4 files changed, 221 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/transaction/IndexJungleTreeEditor.java Tue Sep 30 13:16:10 2014 +0900 @@ -0,0 +1,174 @@ +package jp.ac.u_ryukyu.ie.cr.shoshi.jungle.transaction; + +import java.nio.ByteBuffer; + +import fj.data.List; +import fj.data.TreeMap; +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.JungleTreeEditor; +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.NodePath; +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.TreeEditor; +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.TreeNode; +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.logger.DefaultTreeOperationLog; +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.logger.LoggingNode; +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.logger.OperationLog; +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.logger.TreeOperationLog; +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.operations.DefaultTreeOperation; +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.operations.NodeOperation; +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.operations.TreeOperation; +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.trasnformer.AppendChildAt; +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.trasnformer.DeleteAttribute; +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.trasnformer.DeleteChildAt; +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.trasnformer.NodeEditor; +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.trasnformer.PutAttribute; +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.DefaultEither; +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Either; +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Error; +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.IterableConverter; +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Pair; +import jp.ac.u_ryukyu.ie.cr.tatsuki.jungle.store.index.DeleteIndexEditor; +import jp.ac.u_ryukyu.ie.cr.tatsuki.jungle.store.index.IndexEditor; +import jp.ac.u_ryukyu.ie.cr.tatsuki.jungle.store.index.PutIndexEditor; + +public class IndexJungleTreeEditor implements JungleTreeEditor +{ + private final TransactionManager txManager; + private final TreeNode root; + private final TreeEditor editor; + private final TreeOperationLog log; + private TreeMap<String, TreeMap<String, List<Pair<TreeNode, NodePath>>>> index; + +// public DefaultJungleTreeEditor(TreeNode root) +// { +// this(root,txManager,_editor,new DefaultTreeOperationLog()); +// } + + public TreeMap<String, TreeMap<String, List<Pair<TreeNode, NodePath>>>> getIndex() { + return index; + } + + public void setIndex( + TreeMap<String, TreeMap<String, List<Pair<TreeNode, NodePath>>>> index) { + this.index = index; + } + + public IndexJungleTreeEditor(TreeNode _root,TransactionManager _txManager,TreeEditor _editor, TreeMap<String, TreeMap<String, List<Pair<TreeNode, NodePath>>>> index) + { + this(_root,_txManager,_editor,new DefaultTreeOperationLog(), index); + } + + public IndexJungleTreeEditor(TreeNode newNode,TransactionManager _txManager,TreeEditor _editor,TreeOperationLog _log, TreeMap<String, TreeMap<String, List<Pair<TreeNode, NodePath>>>> index) + { + this.root = newNode; + this.txManager = _txManager; + this.editor = _editor; + this.log = _log; + this.index = index; + } + + private Either<Error,IndexJungleTreeEditor> _edit(final NodePath _path,NodeEditor _e) + { + Either<Error,LoggingNode> either = editor.edit(root,_path,_e); + if(either.isA()){ + return DefaultEither.newA(either.a()); + } + + LoggingNode newLogging = either.b(); + OperationLog newLog = newLogging.getOperationLog(); + TreeNode newNode = newLogging.getWrap(); + + IterableConverter.Converter<TreeOperation,NodeOperation> converter = new IterableConverter.Converter<TreeOperation,NodeOperation>(){ + @Override + public TreeOperation conv(NodeOperation _b){ + return new DefaultTreeOperation(_path,_b); + } + }; + + Iterable<TreeOperation> iterable = new IterableConverter<TreeOperation,NodeOperation>(newLog,converter); + DefaultTreeOperationLog treeOperationLog = new DefaultTreeOperationLog(iterable,newLog.length()); + TreeOperationLog newTreeOpLog = log.append(treeOperationLog); + + IndexJungleTreeEditor newEditor = new IndexJungleTreeEditor(newNode,txManager,editor,newTreeOpLog, index); + return DefaultEither.newB(newEditor); + } + + @Override + public Either<Error,JungleTreeEditor> addNewChildAt(NodePath _path, int _pos) + { + AppendChildAt appendChildAt = new AppendChildAt(_pos); + Either<Error,IndexJungleTreeEditor> either = _edit(_path,appendChildAt); + JungleTreeEditor editor = either.b(); + Either<Error,JungleTreeEditor> newEither = DefaultEither.newB(editor); + return newEither; + } + + @Override + public Either<Error,JungleTreeEditor> deleteChildAt(NodePath _path, int _pos) + { + DeleteChildAt deleteChildAt = new DeleteChildAt(_pos); + Either<Error,IndexJungleTreeEditor> either = _edit(_path,deleteChildAt); + JungleTreeEditor editor = either.b(); + Either<Error,JungleTreeEditor> newEither = DefaultEither.newB(editor); + return newEither; + } + + @Override + public Either<Error,JungleTreeEditor> putAttribute(NodePath _path,String _key,ByteBuffer _value) + { + PutAttribute putAttribute = new PutAttribute(_key,_value); + Either<Error,IndexJungleTreeEditor> either = _edit(_path,putAttribute); + PutIndexEditor indexEditor = new PutIndexEditor(); + Either<Error,JungleTreeEditor> newEither = indexEditor.edit(either.b()); + return newEither; + } + + @Override + public Either<Error,JungleTreeEditor> deleteAttribute(NodePath _path, String _key) + { + DeleteAttribute deleteAttribute = new DeleteAttribute(_key); + Either<Error,IndexJungleTreeEditor> either = _edit(_path,deleteAttribute); + DeleteIndexEditor indexEditor = new DeleteIndexEditor(); + Either<Error,JungleTreeEditor> newEither = indexEditor.edit(either.b()); + return newEither; + } + + @Override + public Either<Error,JungleTreeEditor> edit(NodePath _path,NodeEditor _editor) + { + Either<Error,IndexJungleTreeEditor> either = _edit(_path,_editor); + JungleTreeEditor editor = either.b(); + Either<Error,JungleTreeEditor> newEither = DefaultEither.newB(editor); + return newEither; + } + + @Override + public Either<Error,JungleTreeEditor> success() + { + Either<Error,TransactionManager> either = txManager.commit(root,log,null); + if(either.isA()){ + return DefaultEither.newA(either.a()); + } + + TransactionManager newTxManager = either.b(); + JungleTreeEditor newTreeEditor = new DefaultJungleTreeEditor(root,newTxManager,editor); + + return DefaultEither.newB(newTreeEditor); + } + + @Override + public String getID() + { + return txManager.getUUID(); + } + + @Override + public String getRevision() + { + return Long.toString(txManager.getRevision()); + } + + @Override + public TreeNode getRoot() + { + return root; + } +} \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/tatsuki/jungle/store/index/DeleteIndexEditor.java Tue Sep 30 13:16:10 2014 +0900 @@ -0,0 +1,16 @@ +package jp.ac.u_ryukyu.ie.cr.tatsuki.jungle.store.index; + +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.JungleTreeEditor; +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.transaction.IndexJungleTreeEditor; +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Either; +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Error; + +public class DeleteIndexEditor implements IndexEditor { + + @Override + public Either<Error, JungleTreeEditor> edit(IndexJungleTreeEditor e) { + // TODO Auto-generated method stub + return null; + } + +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/tatsuki/jungle/store/index/IndexEditor.java Tue Sep 30 13:16:10 2014 +0900 @@ -0,0 +1,15 @@ +package jp.ac.u_ryukyu.ie.cr.tatsuki.jungle.store.index; + +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.JungleTreeEditor; +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.NodePath; +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.TreeNode; +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.transaction.IndexJungleTreeEditor; +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Either; +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Error; +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Pair; +import fj.data.List; +import fj.data.TreeMap; + +public interface IndexEditor { + public Either<Error,JungleTreeEditor> edit(IndexJungleTreeEditor e); +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/tatsuki/jungle/store/index/PutIndexEditor.java Tue Sep 30 13:16:10 2014 +0900 @@ -0,0 +1,16 @@ +package jp.ac.u_ryukyu.ie.cr.tatsuki.jungle.store.index; + + +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.JungleTreeEditor; +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.transaction.IndexJungleTreeEditor; +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Either; +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Error; + +public class PutIndexEditor implements IndexEditor { + + @Override + public Either<Error,JungleTreeEditor> edit(IndexJungleTreeEditor e) { + // TODO Auto-generated method stub + return null; + } +}