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