Mercurial > hg > Members > tatsuki > bench > jungle-core
changeset 104:f9a0e7069811
delete worning halfway
line wrap: on
line diff
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/DefaultJungle.java Fri Sep 12 14:37:09 2014 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/DefaultJungle.java Fri Sep 12 16:22:22 2014 +0900 @@ -21,7 +21,6 @@ import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.traverser.DefaultTraverser; 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; public class DefaultJungle implements Jungle { @@ -30,7 +29,7 @@ private String uuid; private TreeEditor editor; - public static void main(String _args[]) + public static void main(String args[]) { DefaultJungle j = new DefaultJungle(null,"hoge",new DefaultTreeEditor(new DefaultTraverser())); JungleTree t = j.createNewTree("fuga"); @@ -47,22 +46,22 @@ e1.success(); } - public DefaultJungle(Journal _journal,String _uuid,TreeEditor _editor) + public DefaultJungle(Journal journal,String uuid,TreeEditor editor) { - journal = new NullJournal(); - trees = new ConcurrentHashMap<String,JungleTree>(); - uuid = _uuid; - editor = _editor; + this.journal = new NullJournal(); + this.trees = new ConcurrentHashMap<String,JungleTree>(); + this.uuid = uuid; + this.editor = editor; } @Override - public JungleTree getTreeByName(String _name) + public JungleTree getTreeByName(String name) { - return trees.get(_name); + return trees.get(name); } @Override - public JungleTree createNewTree(final String _name) + public JungleTree createNewTree(final String name) { ChangeList list = new ChangeList(){ @Override @@ -76,17 +75,16 @@ } @Override public String getTreeName() { - return _name; + return name; } }; DefaultTreeNode root = new DefaultTreeNode(); - ChangeSet set = new DefaultChangeSet(root,null,list,uuid,_name,0,null); + TreeMap<String,List<TreeNode>> index = TreeMap.empty(Ord.stringOrd); + ChangeSet set = new DefaultChangeSet(root,null,list,uuid,name,0,index); DefaultTreeContext tc = new DefaultTreeContext(root,set); - TreeMap<String, String> attributeIndex = TreeMap.empty(Ord.stringOrd); - TreeMap<String,TreeNode> nodeIndex = TreeMap.empty(Ord.stringOrd); - JungleTree newTree = new DefaultJungleTree(tc,uuid,journal.getWriter(),editor , new Pair<TreeMap<String,TreeNode>,TreeMap<String,String>>(nodeIndex, attributeIndex)); - if(trees.putIfAbsent(_name,newTree) != null){ + JungleTree newTree = new DefaultJungleTree(tc,uuid,journal.getWriter(),editor); + if(trees.putIfAbsent(name,newTree) != null){ return null; } return newTree;
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/DefaultJungleTree.java Fri Sep 12 14:37:09 2014 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/DefaultJungleTree.java Fri Sep 12 16:22:22 2014 +0900 @@ -1,17 +1,17 @@ package jp.ac.u_ryukyu.ie.cr.shoshi.jungle; -import fj.data.HashMap; +import fj.data.List; import fj.data.TreeMap; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.persistent.ChangeListWriter; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.ChangeSet; 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.transaction.AtomicReservableReference; +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.transaction.DefaultJungleIndexTreeEditor; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.transaction.DefaultJungleTreeEditor; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.transaction.DefaultTransactionManager; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.transaction.TreeContext; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.traverser.InterfaceTraverser; -import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Pair; public class DefaultJungleTree implements JungleTree @@ -20,15 +20,13 @@ private final String uuid; private final ChangeListWriter writer; private final TreeEditor editor; - Pair<TreeMap<String,TreeNode>,TreeMap<String,String>> index; - public DefaultJungleTree(TreeContext _tc,String _uuid,ChangeListWriter _writer,TreeEditor _editor, Pair<TreeMap<String,TreeNode>,TreeMap<String,String>> index) + public DefaultJungleTree(TreeContext tc,String uuid,ChangeListWriter writer,TreeEditor editor) { - this.repository = new AtomicReservableReference<TreeContext>(_tc); - this.uuid = _uuid; - this.writer = _writer; - this.editor = _editor; - this.index = index; + this.repository = new AtomicReservableReference<TreeContext>(tc); + this.uuid = uuid; + this.writer = writer; + this.editor = editor; } @Override @@ -39,6 +37,18 @@ TreeNode root = tc.getTreeNode(); return new DefaultJungleTreeEditor(root,txManager,editor); } + + @Override + public JungleTreeEditor getIndexTreeEditor() + { + TreeContext tc = repository.get(); + DefaultTransactionManager txManager = new DefaultTransactionManager(writer,tc,repository,uuid); + TreeNode root = tc.getTreeNode(); + ChangeSet cs = tc.getChangeSet(); + TreeMap<String,List<TreeNode>> newIndex = cs.getIndex(); + return new DefaultJungleIndexTreeEditor(root,txManager,editor,newIndex); + } + @Override public JungleTreeEditor getLocalTreeEditor() @@ -56,11 +66,15 @@ @Override public InterfaceTraverser getTraverser() { - return new InterfaceTraverser(getRootNode(), index, getTreeEditor()); + TreeContext tc = repository.get(); + ChangeSet cs = tc.getChangeSet(); + return new InterfaceTraverser(getRootNode(), cs.getIndex(), getTreeEditor()); } @Override - public Pair<TreeMap<String,TreeNode>,TreeMap<String,String>> getIndex() { - return index; + public TreeMap<String,List<TreeNode>> getIndex() { + TreeContext tc = repository.get(); + ChangeSet cs = tc.getChangeSet(); + return cs.getIndex(); } }
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/Jungle.java Fri Sep 12 14:37:09 2014 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/Jungle.java Fri Sep 12 16:22:22 2014 +0900 @@ -3,6 +3,6 @@ public interface Jungle { - public JungleTree getTreeByName(String _name); - public JungleTree createNewTree(String _name); + public JungleTree getTreeByName(String name); + public JungleTree createNewTree(String name); }
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/JungleTree.java Fri Sep 12 14:37:09 2014 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/JungleTree.java Fri Sep 12 16:22:22 2014 +0900 @@ -1,10 +1,10 @@ package jp.ac.u_ryukyu.ie.cr.shoshi.jungle; +import fj.data.List; import fj.data.TreeMap; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.TreeNode; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.traverser.InterfaceTraverser; -import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Pair; public interface JungleTree { @@ -12,5 +12,6 @@ public InterfaceTraverser getTraverser(); public JungleTreeEditor getLocalTreeEditor(); public TreeNode getRootNode(); - public Pair<TreeMap<String,TreeNode>,TreeMap<String,String>> getIndex(); + public TreeMap<String,List<TreeNode>> getIndex(); + public JungleTreeEditor getIndexTreeEditor(); }
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/JungleTreeEditor.java Fri Sep 12 14:37:09 2014 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/JungleTreeEditor.java Fri Sep 12 16:22:22 2014 +0900 @@ -13,11 +13,11 @@ { public TreeNode getRoot(); - public Either<Error,JungleTreeEditor> addNewChildAt(NodePath _path,int _pos); - public Either<Error,JungleTreeEditor> deleteChildAt(NodePath _path,int _pos); - public Either<Error,JungleTreeEditor> putAttribute(NodePath _path,String _key,ByteBuffer _value); - public Either<Error,JungleTreeEditor> deleteAttribute(NodePath _path,String _key); - public Either<Error,JungleTreeEditor> edit(NodePath _path,NodeEditor _editor); + public Either<Error,JungleTreeEditor> addNewChildAt(NodePath path,int pos); + public Either<Error,JungleTreeEditor> deleteChildAt(NodePath path,int pos); + public Either<Error,JungleTreeEditor> putAttribute(NodePath path,String key,ByteBuffer value); + public Either<Error,JungleTreeEditor> deleteAttribute(NodePath path,String key); + public Either<Error,JungleTreeEditor> edit(NodePath path,NodeEditor editor); public Either<Error,JungleTreeEditor> success(); public String getID();
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/persistent/DefaultChangeListReader.java Fri Sep 12 14:37:09 2014 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/persistent/DefaultChangeListReader.java Fri Sep 12 16:22:22 2014 +0900 @@ -14,11 +14,11 @@ private ByteBuffer buf; private FileChannel ch; - DefaultChangeListReader(FileChannel _ch,ByteBuffer _buf,long _pos) + DefaultChangeListReader(FileChannel ch,ByteBuffer buf,long pos) { - pos = _pos; - buf = _buf; - ch = _ch; + this.pos = pos; + this.buf = buf; + this.ch = ch; } @Override
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/persistent/DefaultChangeListWriter.java Fri Sep 12 14:37:09 2014 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/persistent/DefaultChangeListWriter.java Fri Sep 12 16:22:22 2014 +0900 @@ -7,15 +7,15 @@ public class DefaultChangeListWriter implements ChangeListWriter { - public DefaultChangeListWriter(ByteBuffer _buf) + public DefaultChangeListWriter(ByteBuffer buf) { } @Override - public synchronized Result write(ChangeList _operations) + public synchronized Result write(ChangeList operations) { - for(TreeOperation op : _operations){ + for(TreeOperation op : operations){ ByteBuffer treeOpBuf = serializeTreeOperation(op); } return null;
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/persistent/DefaultJournal.java Fri Sep 12 14:37:09 2014 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/persistent/DefaultJournal.java Fri Sep 12 16:22:22 2014 +0900 @@ -51,7 +51,7 @@ { private final ChangeListWriter writer; - public static void main(String _args[]) throws Exception + public static void main(String args[]) throws Exception { RandomAccessFile f = new RandomAccessFile("./miscs/1.dat","rw"); MappedByteBuffer a = f.getChannel().map(MapMode.READ_WRITE,10,10); @@ -80,11 +80,11 @@ writer = null; } - public static Either<Error,DefaultJournal> newInstance(String _fileName) + public static Either<Error,DefaultJournal> newInstance(String fileName) { RandomAccessFile journal = null; try{ - journal = new RandomAccessFile(_fileName,"rw"); + journal = new RandomAccessFile(fileName,"rw"); FileChannel ch = journal.getChannel(); long length = journal.length(); ByteBuffer readBuf = ch.map(MapMode.READ_ONLY,0,READ_BUFFER_SIZE);
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/persistent/DefaultJournalWriter.java Fri Sep 12 14:37:09 2014 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/persistent/DefaultJournalWriter.java Fri Sep 12 16:22:22 2014 +0900 @@ -13,16 +13,16 @@ } - public static Either<Error,DefaultJournalWriter> newInstance(String _fileName) + public static Either<Error,DefaultJournalWriter> newInstance(String fileName) { RandomAccessFile journal = null; try{ - journal = new RandomAccessFile(_fileName,"rw"); + journal = new RandomAccessFile(fileName,"rw"); //FileChannel ch = journal.getChannel(); long length = journal.length(); - }catch(FileNotFoundException _e){ + }catch(FileNotFoundException e){ - }catch(IOException _e){ + }catch(IOException e){ }
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/store/ChangeSet.java Fri Sep 12 14:37:09 2014 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/store/ChangeSet.java Fri Sep 12 16:22:22 2014 +0900 @@ -6,7 +6,6 @@ import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.persistent.ChangeList; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.TreeNode; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.operations.TreeOperation; -import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Pair; public interface ChangeSet {
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/store/TreeEditor.java Fri Sep 12 14:37:09 2014 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/store/TreeEditor.java Fri Sep 12 16:22:22 2014 +0900 @@ -1,15 +1,12 @@ package jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store; -import fj.data.TreeMap; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.TreeNode; -import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.logger.LoggingNode; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.trasnformer.NodeEditor; 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 jp.ac.u_ryukyu.ie.cr.tatsuki.jungle.store.index.Logging; public interface TreeEditor { - public Either<Error,Logging> edit(TreeNode _root,NodePath _path,NodeEditor _transformer); + public Either<Error,Logging> edit(TreeNode root,NodePath path,NodeEditor transformer); }
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/store/impl/DefaultNodePath.java Fri Sep 12 14:37:09 2014 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/store/impl/DefaultNodePath.java Fri Sep 12 16:22:22 2014 +0900 @@ -12,7 +12,7 @@ { private final List<Integer> path; - public static void main(String _args[]) + public static void main(String args[]) { DefaultNodePath p = new DefaultNodePath(); p = p.add(1).add(2).add(3).add(4); @@ -24,9 +24,9 @@ path = List.list(-1); } - private DefaultNodePath(List<Integer> _path) + private DefaultNodePath(List<Integer> path) { - path = _path; + this.path = path; } @Override @@ -36,9 +36,9 @@ } @Override - public DefaultNodePath add(int _pos) + public DefaultNodePath add(int pos) { - List<Integer> newPath = path.snoc(_pos); + List<Integer> newPath = path.snoc(pos); return new DefaultNodePath(newPath); } @@ -68,15 +68,15 @@ List<List<Integer>> inits = path.inits(); inits = inits.filter(new F<List<Integer>,Boolean>(){ @Override - public Boolean f(List<Integer> _init){ - return _init.length() != 0; + public Boolean f(List<Integer> init){ + return init.length() != 0; } }); return inits.map(new F<List<Integer>,DefaultNodePath>(){ @Override - public DefaultNodePath f(List<Integer> _path){ - return new DefaultNodePath(_path); + public DefaultNodePath f(List<Integer> path){ + return new DefaultNodePath(path); } }); }
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/store/impl/DefaultTreeEditor.java Fri Sep 12 14:37:09 2014 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/store/impl/DefaultTreeEditor.java Fri Sep 12 16:22:22 2014 +0900 @@ -3,7 +3,6 @@ import fj.data.List; 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.logger.LoggingNode; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.trasnformer.NodeEditor; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.traverser.DefaultEvaluator; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.traverser.Direction; @@ -18,34 +17,34 @@ { private final Traverser traverser; - public DefaultTreeEditor(Traverser _traverser) + public DefaultTreeEditor(Traverser traverser) { - traverser = _traverser; + this.traverser = traverser; } @Override - public Either<Error,Logging> edit(TreeNode _root,NodePath _path,NodeEditor _editor) + public Either<Error,Logging> edit(TreeNode root,NodePath path,NodeEditor editor) { - DefaultEvaluator e = new DefaultEvaluator(_path); + DefaultEvaluator e = new DefaultEvaluator(path); //TraversableNodeWrapper<T> wrap = new TraversableNodeWrapper<T>(_root); - Either<Error, Traversal> either = traverser.traverse(_root,e); + Either<Error, Traversal> either = traverser.traverse(root,e); if(either.isA()){ return DefaultEither.newA(either.a()); } Traversal t = either.b(); - Either<Error,Logging> ret = clone(t,_editor); + Either<Error,Logging> ret = clone(t,editor); return ret; } - private Either<Error,Logging> clone(Traversal _t,NodeEditor _editor) + private Either<Error,Logging> clone(Traversal t,NodeEditor editor) { // copying nodes from bottom to root List<Direction<TreeNode>> path = List.nil(); - for(Direction<TreeNode> direction : _t){ + for(Direction<TreeNode> direction : t){ path = path.cons(direction); } @@ -53,7 +52,7 @@ Direction<TreeNode> targetDirection = path.head(); TreeNode target = targetDirection.getTarget(); //EditableNodeWrapper<T> wrapper = new EditableNodeWrapper<T>(target); - Either<Error,Logging> either = _editor.edit(target); + Either<Error,Logging> either = editor.edit(target); if(either.isA()){ return DefaultEither.newA(either.a()); } @@ -77,7 +76,7 @@ } TreeNode newRoot = child; - Logging logNode = _editor.wrap(newRoot,newWrap.getOperationLog()); + Logging logNode = editor.wrap(newRoot,newWrap.getOperationLog()); return DefaultEither.newB(logNode); } } \ No newline at end of file
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/store/impl/TreeNode.java Fri Sep 12 14:37:09 2014 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/store/impl/TreeNode.java Fri Sep 12 16:22:22 2014 +0900 @@ -1,7 +1,6 @@ package jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.core.AttributesContainer; -import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.logger.OperationLog; public interface TreeNode extends AttributesContainer {
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/store/impl/TreeNodeChildren.java Fri Sep 12 14:37:09 2014 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/store/impl/TreeNodeChildren.java Fri Sep 12 16:22:22 2014 +0900 @@ -7,9 +7,9 @@ public interface TreeNodeChildren extends Children { - public Either<Error,TreeNode> addNewChildAt(int _pos); - public Either<Error,TreeNode> deleteChildAt(int _pos); - public Either<Error,TreeNode> addNewChildAt(int _pos,TreeNode _newChild); - public Either<Error,TreeNode> replaceNode(int _pos,TreeNode _replacement); + public Either<Error,TreeNode> addNewChildAt(int pos); + public Either<Error,TreeNode> deleteChildAt(int pos); + public Either<Error,TreeNode> addNewChildAt(int pos,TreeNode newChild); + public Either<Error,TreeNode> replaceNode(int pos,TreeNode replacement); public List<TreeNode> getChildrenAsRawList(); } \ 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/shoshi/jungle/transaction/DefaultJungleIndexTreeEditor.java Fri Sep 12 16:22:22 2014 +0900 @@ -0,0 +1,132 @@ +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.AppendChildAtIndex; +import jp.ac.u_ryukyu.ie.cr.tatsuki.jungle.store.index.DeleteAttributeIndex; +import jp.ac.u_ryukyu.ie.cr.tatsuki.jungle.store.index.DeleteChildAtIndex; +import jp.ac.u_ryukyu.ie.cr.tatsuki.jungle.store.index.Logging; +import jp.ac.u_ryukyu.ie.cr.tatsuki.jungle.store.index.PutAttributeIndex; + +public class DefaultJungleIndexTreeEditor extends DefaultJungleTreeEditor +{ + private final TransactionManager txManager; + private final TreeNode root; + private final TreeEditor editor; + private final TreeOperationLog log; + private TreeMap<String,List<TreeNode>> index; + + public DefaultJungleIndexTreeEditor(TreeNode _root,TransactionManager _txManager,TreeEditor _editor, TreeMap<String,List<TreeNode>> index) + { + this(_root,_txManager,_editor,new DefaultTreeOperationLog(), index); + } + + public DefaultJungleIndexTreeEditor(TreeNode newNode,TransactionManager _txManager,TreeEditor _editor,TreeOperationLog _log, TreeMap<String,List<TreeNode>> index) + { + super(newNode, _txManager, _editor , _log); + this.root = newNode; + this.txManager = _txManager; + this.editor = _editor; + this.log = _log; + this.index = index; + } + + private Either<Error,JungleTreeEditor> _edit(final NodePath _path,NodeEditor _e) + { + //LoggingNodeHook hook = new LoggingNodeHook(_e); + Either<Error,Logging> either = editor.edit(root,_path,_e); + if(either.isA()){ + return DefaultEither.newA(either.a()); + } + + Logging newLogging = either.b(); + OperationLog newLog = newLogging.getOperationLog(); + TreeNode newNode = newLogging.getWrap(); + index = newLogging.getIndex(); + 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); + + JungleTreeEditor newEditor = new DefaultJungleIndexTreeEditor(newNode,txManager,editor,newTreeOpLog, index); + return DefaultEither.newB(newEditor); + } + + @Override + public Either<Error,JungleTreeEditor> addNewChildAt(NodePath _path, int _pos) + { + AppendChildAtIndex appendChildAt = new AppendChildAtIndex(_pos, index); + return _edit(_path,appendChildAt); + } + + @Override + public Either<Error,JungleTreeEditor> deleteChildAt(NodePath _path, int _pos) + { + DeleteChildAtIndex deleteChildAt = new DeleteChildAtIndex(_pos, index); + return _edit(_path,deleteChildAt); + } + + @Override + public Either<Error,JungleTreeEditor> putAttribute(NodePath _path,String _key,ByteBuffer _value) + { + PutAttributeIndex putAttribute = new PutAttributeIndex(_key,_value, index); + return _edit(_path,putAttribute); + } + + @Override + public Either<Error,JungleTreeEditor> deleteAttribute(NodePath _path, String _key) + { + DeleteAttributeIndex deleteAttribute = new DeleteAttributeIndex(_key, index); + return _edit(_path,deleteAttribute); + } + + @Override + public Either<Error,JungleTreeEditor> edit(NodePath _path,NodeEditor _editor) + { + return _edit(_path,_editor); + } + + @Override + public Either<Error,JungleTreeEditor> success() + { + Either<Error,TransactionManager> either = txManager.commit(root,log, index); + if(either.isA()){ + return DefaultEither.newA(either.a()); + } + + TransactionManager newTxManager = either.b(); + JungleTreeEditor newTreeEditor = new DefaultJungleIndexTreeEditor(root,newTxManager,editor, index); + + return DefaultEither.newB(newTreeEditor); + } + +}
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/transaction/DefaultTreeNode.java Fri Sep 12 14:37:09 2014 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/transaction/DefaultTreeNode.java Fri Sep 12 16:22:22 2014 +0900 @@ -6,7 +6,6 @@ import fj.data.List; import fj.data.TreeMap; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.TreeNode; -import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.logger.DefaultOperationLog; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.logger.OperationLog; public class DefaultTreeNode implements TreeNode
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/traverser/InterfaceTraverser.java Fri Sep 12 14:37:09 2014 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/traverser/InterfaceTraverser.java Fri Sep 12 16:22:22 2014 +0900 @@ -2,6 +2,7 @@ import java.util.Iterator; +import fj.data.List; import fj.data.TreeMap; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.JungleTree; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.JungleTreeEditor; @@ -18,16 +19,14 @@ InterfaceTraverser traverser; TreeNode node; - TreeMap<String, TreeNode> nodeIndex; - TreeMap<String, String> attributeIndex; + TreeMap<String,List<TreeNode>> index; JungleTreeEditor editor; public InterfaceTraverser(TreeNode _root, - Pair<TreeMap<String, TreeNode>, TreeMap<String, String>> index, + TreeMap<String,List<TreeNode>> index, JungleTreeEditor editor) { this.node = _root; - this.nodeIndex = index.left(); - this.attributeIndex = index.right(); + this.index = index; this.editor = editor; }
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/tatsuki/jungle/store/index/LoggingIndexAttributes.java Fri Sep 12 14:37:09 2014 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/tatsuki/jungle/store/index/LoggingIndexAttributes.java Fri Sep 12 16:22:22 2014 +0900 @@ -3,6 +3,7 @@ import java.nio.ByteBuffer; import fj.data.List; +import fj.data.Option; import fj.data.TreeMap; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.TreeNode; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.logger.LoggingAttributes; @@ -70,9 +71,17 @@ TreeNode newNode = logNode.getWrap(); OperationLog newLog = logNode.getOperationLog(); String indexKey = new String(value.array()); - List<TreeNode> list = index.get(indexKey).some(); - list = list.cons(newNode); - index.set(indexKey, list); + Option<List<TreeNode>> opList = index.get(indexKey); + if (opList.isNone()) { + List<TreeNode> list = List.nil(); + list.cons(newNode); + String str = new String(value.array()); + index.set(str,list); + } else { + List<TreeNode> list = opList.some(); + list = list.cons(newNode); + index.set(indexKey, list); + } Logging logIndexNode = new LoggingIndexNode(newNode, newLog, index); return DefaultEither.newB(logIndexNode); }
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/tatsuki/jungle/store/index/LoggingIndexNode.java Fri Sep 12 14:37:09 2014 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/tatsuki/jungle/store/index/LoggingIndexNode.java Fri Sep 12 16:22:22 2014 +0900 @@ -27,6 +27,7 @@ super(wrap, log); this.wrap = wrap; this.log = log; + this.index = index; } @Override @@ -37,7 +38,7 @@ @Override public LoggingAttributes getAttributes() { - return new LoggingAttributes(wrap,log); + return new LoggingIndexAttributes(wrap,log,index); } @Override