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