Mercurial > hg > Members > tatsuki > bench > jungle-core
annotate src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/transaction/DefaultJungleTreeEditor.java @ 100:9a7b7af838e0
add index TreeNodeEditor
but node use
author | one |
---|---|
date | Thu, 11 Sep 2014 03:10:03 +0900 |
parents | ef68358ed0e8 |
children | c297f0015d9e |
rev | line source |
---|---|
37 | 1 package jp.ac.u_ryukyu.ie.cr.shoshi.jungle.transaction; |
2 | |
3 import java.nio.ByteBuffer; | |
78 | 4 |
100 | 5 import fj.data.TreeMap; |
37 | 6 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.JungleTreeEditor; |
7 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.NodePath; | |
53 | 8 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.TreeEditor; |
9 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.TreeNode; | |
10 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.logger.DefaultTreeOperationLog; | |
92 | 11 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.logger.LoggingNode; |
53 | 12 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.logger.OperationLog; |
13 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.logger.TreeOperationLog; | |
14 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.operations.DefaultTreeOperation; | |
15 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.operations.NodeOperation; | |
16 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.operations.TreeOperation; | |
49
e3a507fd57a4
modified TreeEditor and JungleTreeEditor (not done yet)
Shoshi TAMAKI
parents:
46
diff
changeset
|
17 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.trasnformer.AppendChildAt; |
53 | 18 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.trasnformer.DeleteAttribute; |
19 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.trasnformer.DeleteChildAt; | |
37 | 20 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.trasnformer.NodeEditor; |
53 | 21 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.trasnformer.PutAttribute; |
38
cb9fabaedfd4
added tests and changed testing provider to junit47
Shoshi TAMAKI
parents:
37
diff
changeset
|
22 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.DefaultEither; |
37 | 23 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Either; |
24 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Error; | |
53 | 25 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.IterableConverter; |
100 | 26 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Pair; |
37 | 27 |
86 | 28 public class DefaultJungleTreeEditor implements JungleTreeEditor |
37 | 29 { |
86 | 30 private final TransactionManager txManager; |
81 | 31 private final TreeNode root; |
53 | 32 private final TreeEditor editor; |
33 private final TreeOperationLog log; | |
100 | 34 private Pair<TreeMap<String,TreeNode>,TreeMap<String,String>> index; |
35 | |
36 public DefaultJungleTreeEditor(TreeNode _root,TransactionManager _txManager,TreeEditor _editor, Pair<TreeMap<String,TreeNode>,TreeMap<String,String>> index) | |
53 | 37 { |
100 | 38 this(_root,_txManager,_editor,new DefaultTreeOperationLog(), index); |
53 | 39 } |
40 | |
100 | 41 public DefaultJungleTreeEditor(TreeNode newNode,TransactionManager _txManager,TreeEditor _editor,TreeOperationLog _log, Pair<TreeMap<String,TreeNode>,TreeMap<String,String>> index) |
37 | 42 { |
100 | 43 this.root = newNode; |
44 this.txManager = _txManager; | |
45 this.editor = _editor; | |
46 this.log = _log; | |
47 this.index = index; | |
37 | 48 } |
49 | |
53 | 50 private Either<Error,JungleTreeEditor> _edit(final NodePath _path,NodeEditor _e) |
46 | 51 { |
87 | 52 //LoggingNodeHook hook = new LoggingNodeHook(_e); |
92 | 53 Either<Error,LoggingNode> either = editor.edit(root,_path,_e); |
38
cb9fabaedfd4
added tests and changed testing provider to junit47
Shoshi TAMAKI
parents:
37
diff
changeset
|
54 if(either.isA()){ |
cb9fabaedfd4
added tests and changed testing provider to junit47
Shoshi TAMAKI
parents:
37
diff
changeset
|
55 return DefaultEither.newA(either.a()); |
cb9fabaedfd4
added tests and changed testing provider to junit47
Shoshi TAMAKI
parents:
37
diff
changeset
|
56 } |
37 | 57 |
92 | 58 LoggingNode newLogging = either.b(); |
59 OperationLog newLog = newLogging.getOperationLog(); | |
60 TreeNode newNode = newLogging.getWrap(); | |
37 | 61 |
53 | 62 IterableConverter.Converter<TreeOperation,NodeOperation> converter = new IterableConverter.Converter<TreeOperation,NodeOperation>(){ |
63 @Override | |
64 public TreeOperation conv(NodeOperation _b){ | |
65 return new DefaultTreeOperation(_path,_b); | |
66 } | |
67 }; | |
38
cb9fabaedfd4
added tests and changed testing provider to junit47
Shoshi TAMAKI
parents:
37
diff
changeset
|
68 |
53 | 69 Iterable<TreeOperation> iterable = new IterableConverter<TreeOperation,NodeOperation>(newLog,converter); |
70 DefaultTreeOperationLog treeOperationLog = new DefaultTreeOperationLog(iterable,newLog.length()); | |
71 TreeOperationLog newTreeOpLog = log.append(treeOperationLog); | |
38
cb9fabaedfd4
added tests and changed testing provider to junit47
Shoshi TAMAKI
parents:
37
diff
changeset
|
72 |
100 | 73 JungleTreeEditor newEditor = new DefaultJungleTreeEditor(newNode,txManager,editor,newTreeOpLog, index); |
53 | 74 return DefaultEither.newB(newEditor); |
37 | 75 } |
53 | 76 |
37 | 77 @Override |
53 | 78 public Either<Error,JungleTreeEditor> addNewChildAt(NodePath _path, int _pos) |
37 | 79 { |
53 | 80 AppendChildAt appendChildAt = new AppendChildAt(_pos); |
81 return _edit(_path,appendChildAt); | |
37 | 82 } |
83 | |
84 @Override | |
53 | 85 public Either<Error,JungleTreeEditor> deleteChildAt(NodePath _path, int _pos) |
37 | 86 { |
53 | 87 DeleteChildAt deleteChildAt = new DeleteChildAt(_pos); |
88 return _edit(_path,deleteChildAt); | |
89 } | |
90 | |
91 @Override | |
92 public Either<Error,JungleTreeEditor> putAttribute(NodePath _path,String _key,ByteBuffer _value) | |
93 { | |
94 PutAttribute putAttribute = new PutAttribute(_key,_value); | |
95 return _edit(_path,putAttribute); | |
37 | 96 } |
97 | |
98 @Override | |
53 | 99 public Either<Error,JungleTreeEditor> deleteAttribute(NodePath _path, String _key) |
37 | 100 { |
53 | 101 DeleteAttribute deleteAttribute = new DeleteAttribute(_key); |
102 return _edit(_path,deleteAttribute); | |
37 | 103 } |
104 | |
105 @Override | |
53 | 106 public Either<Error,JungleTreeEditor> edit(NodePath _path,NodeEditor _editor) |
37 | 107 { |
53 | 108 return _edit(_path,_editor); |
109 } | |
110 | |
111 @Override | |
112 public Either<Error,JungleTreeEditor> success() | |
113 { | |
86 | 114 Either<Error,TransactionManager> either = txManager.commit(root,log); |
38
cb9fabaedfd4
added tests and changed testing provider to junit47
Shoshi TAMAKI
parents:
37
diff
changeset
|
115 if(either.isA()){ |
cb9fabaedfd4
added tests and changed testing provider to junit47
Shoshi TAMAKI
parents:
37
diff
changeset
|
116 return DefaultEither.newA(either.a()); |
cb9fabaedfd4
added tests and changed testing provider to junit47
Shoshi TAMAKI
parents:
37
diff
changeset
|
117 } |
cb9fabaedfd4
added tests and changed testing provider to junit47
Shoshi TAMAKI
parents:
37
diff
changeset
|
118 |
86 | 119 TransactionManager newTxManager = either.b(); |
100 | 120 JungleTreeEditor newTreeEditor = new DefaultJungleTreeEditor(root,newTxManager,editor, index); |
45 | 121 |
122 return DefaultEither.newB(newTreeEditor); | |
37 | 123 } |
124 | |
45 | 125 @Override |
126 public String getID() | |
127 { | |
128 return txManager.getUUID(); | |
129 } | |
130 | |
131 @Override | |
132 public String getRevision() | |
133 { | |
134 return Long.toString(txManager.getRevision()); | |
135 } | |
53 | 136 |
137 @Override | |
81 | 138 public TreeNode getRoot() |
53 | 139 { |
140 return null; | |
141 } | |
37 | 142 } |