Mercurial > hg > Members > tatsuki > bench > jungle-core
annotate src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/transaction/DefaultJungleTreeEditor.java @ 93:ef68358ed0e8
Merge with 7058e85875a59d1951cc5eeaa049e4788ea96deb
author | one |
---|---|
date | Sat, 06 Sep 2014 10:18:47 +0900 |
parents | 14ce7a0dedca 4c6b915302a8 |
children | 9a7b7af838e0 |
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; | |
92 | 10 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.logger.LoggingNode; |
53 | 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 { |
87 | 48 //LoggingNodeHook hook = new LoggingNodeHook(_e); |
92 | 49 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
|
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 |
92 | 54 LoggingNode newLogging = either.b(); |
55 OperationLog newLog = newLogging.getOperationLog(); | |
56 TreeNode newNode = newLogging.getWrap(); | |
37 | 57 |
53 | 58 IterableConverter.Converter<TreeOperation,NodeOperation> converter = new IterableConverter.Converter<TreeOperation,NodeOperation>(){ |
59 @Override | |
60 public TreeOperation conv(NodeOperation _b){ | |
61 return new DefaultTreeOperation(_path,_b); | |
62 } | |
63 }; | |
38
cb9fabaedfd4
added tests and changed testing provider to junit47
Shoshi TAMAKI
parents:
37
diff
changeset
|
64 |
53 | 65 Iterable<TreeOperation> iterable = new IterableConverter<TreeOperation,NodeOperation>(newLog,converter); |
66 DefaultTreeOperationLog treeOperationLog = new DefaultTreeOperationLog(iterable,newLog.length()); | |
67 TreeOperationLog newTreeOpLog = log.append(treeOperationLog); | |
38
cb9fabaedfd4
added tests and changed testing provider to junit47
Shoshi TAMAKI
parents:
37
diff
changeset
|
68 |
86 | 69 JungleTreeEditor newEditor = new DefaultJungleTreeEditor(newNode,txManager,editor,newTreeOpLog); |
53 | 70 return DefaultEither.newB(newEditor); |
37 | 71 } |
53 | 72 |
37 | 73 @Override |
53 | 74 public Either<Error,JungleTreeEditor> addNewChildAt(NodePath _path, int _pos) |
37 | 75 { |
53 | 76 AppendChildAt appendChildAt = new AppendChildAt(_pos); |
77 return _edit(_path,appendChildAt); | |
37 | 78 } |
79 | |
80 @Override | |
53 | 81 public Either<Error,JungleTreeEditor> deleteChildAt(NodePath _path, int _pos) |
37 | 82 { |
53 | 83 DeleteChildAt deleteChildAt = new DeleteChildAt(_pos); |
84 return _edit(_path,deleteChildAt); | |
85 } | |
86 | |
87 @Override | |
88 public Either<Error,JungleTreeEditor> putAttribute(NodePath _path,String _key,ByteBuffer _value) | |
89 { | |
90 PutAttribute putAttribute = new PutAttribute(_key,_value); | |
91 return _edit(_path,putAttribute); | |
37 | 92 } |
93 | |
94 @Override | |
53 | 95 public Either<Error,JungleTreeEditor> deleteAttribute(NodePath _path, String _key) |
37 | 96 { |
53 | 97 DeleteAttribute deleteAttribute = new DeleteAttribute(_key); |
98 return _edit(_path,deleteAttribute); | |
37 | 99 } |
100 | |
101 @Override | |
53 | 102 public Either<Error,JungleTreeEditor> edit(NodePath _path,NodeEditor _editor) |
37 | 103 { |
53 | 104 return _edit(_path,_editor); |
105 } | |
106 | |
107 @Override | |
108 public Either<Error,JungleTreeEditor> success() | |
109 { | |
86 | 110 Either<Error,TransactionManager> either = txManager.commit(root,log); |
38
cb9fabaedfd4
added tests and changed testing provider to junit47
Shoshi TAMAKI
parents:
37
diff
changeset
|
111 if(either.isA()){ |
cb9fabaedfd4
added tests and changed testing provider to junit47
Shoshi TAMAKI
parents:
37
diff
changeset
|
112 return DefaultEither.newA(either.a()); |
cb9fabaedfd4
added tests and changed testing provider to junit47
Shoshi TAMAKI
parents:
37
diff
changeset
|
113 } |
cb9fabaedfd4
added tests and changed testing provider to junit47
Shoshi TAMAKI
parents:
37
diff
changeset
|
114 |
86 | 115 TransactionManager newTxManager = either.b(); |
116 JungleTreeEditor newTreeEditor = new DefaultJungleTreeEditor(root,newTxManager,editor); | |
45 | 117 |
118 return DefaultEither.newB(newTreeEditor); | |
37 | 119 } |
120 | |
45 | 121 @Override |
122 public String getID() | |
123 { | |
124 return txManager.getUUID(); | |
125 } | |
126 | |
127 @Override | |
128 public String getRevision() | |
129 { | |
130 return Long.toString(txManager.getRevision()); | |
131 } | |
53 | 132 |
133 @Override | |
81 | 134 public TreeNode getRoot() |
53 | 135 { |
136 return null; | |
137 } | |
37 | 138 } |