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