263
|
1 package jp.ac.u_ryukyu.ie.cr.jungle.transaction.editor.jungleTreeEditor;
|
|
2
|
265
|
3 import jp.ac.u_ryukyu.ie.cr.jungle.transaction.node.TreeNode;
|
263
|
4 import jp.ac.u_ryukyu.ie.cr.jungle.store.logger.DefaultTreeOperationLog;
|
|
5 import jp.ac.u_ryukyu.ie.cr.jungle.store.logger.LoggingNode;
|
265
|
6 import jp.ac.u_ryukyu.ie.cr.jungle.store.logger.OperationLog;
|
263
|
7 import jp.ac.u_ryukyu.ie.cr.jungle.store.logger.TreeOperationLog;
|
|
8 import jp.ac.u_ryukyu.ie.cr.jungle.store.nodepath.NodePath;
|
265
|
9 import jp.ac.u_ryukyu.ie.cr.jungle.store.operations.DefaultTreeOperation;
|
|
10 import jp.ac.u_ryukyu.ie.cr.jungle.store.operations.NodeOperation;
|
|
11 import jp.ac.u_ryukyu.ie.cr.jungle.store.operations.TreeOperation;
|
263
|
12 import jp.ac.u_ryukyu.ie.cr.jungle.store.trasnformer.AppendChildAt;
|
|
13 import jp.ac.u_ryukyu.ie.cr.jungle.store.trasnformer.NodeEditor;
|
|
14 import jp.ac.u_ryukyu.ie.cr.jungle.transaction.TransactionManager;
|
|
15 import jp.ac.u_ryukyu.ie.cr.jungle.transaction.editor.treeEditor.TreeEditor;
|
|
16 import jp.ac.u_ryukyu.ie.cr.jungle.util.DefaultEither;
|
|
17 import jp.ac.u_ryukyu.ie.cr.jungle.util.Either;
|
|
18 import jp.ac.u_ryukyu.ie.cr.jungle.util.Error;
|
265
|
19 import jp.ac.u_ryukyu.ie.cr.jungle.util.IterableConverter;
|
263
|
20
|
|
21 import java.nio.ByteBuffer;
|
|
22
|
|
23 import static jp.ac.u_ryukyu.ie.cr.jungle.transaction.editor.Error.TreeEditorError.NOT_USE_METHOD;
|
|
24
|
|
25 /**
|
|
26 * Created by e115731 on 2016/12/11.
|
|
27 */
|
|
28 public class DefaultDifferenceJungleTreeEditor implements JungleTreeEditor {
|
|
29
|
|
30 private final TransactionManager txManager;
|
|
31 private final TreeNode root;
|
|
32 private final TreeEditor editor;
|
|
33 private final TreeOperationLog log;
|
|
34
|
|
35 public DefaultDifferenceJungleTreeEditor(TreeNode _root, TransactionManager _txManager, TreeEditor _editor) {
|
|
36 this(_root, _txManager, _editor, new DefaultTreeOperationLog());
|
|
37 }
|
|
38
|
|
39
|
|
40 public DefaultDifferenceJungleTreeEditor(TreeNode newNode, TransactionManager _txManager, TreeEditor _editor, TreeOperationLog _log) {
|
|
41 this.root = newNode;
|
|
42 this.txManager = _txManager;
|
|
43 this.editor = _editor;
|
|
44 this.log = _log;
|
|
45 }
|
|
46
|
|
47 private Either<Error, JungleTreeEditor> _edit(final NodePath _path, NodeEditor _e) {
|
|
48 Either<Error, LoggingNode> either = editor.edit(root, _path, _e);
|
265
|
49 if(either.isA()){
|
|
50 return DefaultEither.newA(either.a());
|
|
51 }
|
|
52
|
|
53 LoggingNode newLogging = either.b();
|
|
54 OperationLog newLog = newLogging.getOperationLog();
|
|
55 TreeNode newNode = newLogging.getWrap();
|
|
56
|
|
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 };
|
|
63
|
|
64 Iterable<TreeOperation> iterable = new IterableConverter<>(newLog,converter);
|
|
65 DefaultTreeOperationLog treeOperationLog = new DefaultTreeOperationLog(iterable,newLog.length());
|
|
66 TreeOperationLog newTreeOpLog = log.append(treeOperationLog);
|
|
67
|
|
68 JungleTreeEditor newEditor = new DefaultDifferenceJungleTreeEditor(newNode,txManager,editor,newTreeOpLog);
|
|
69 return DefaultEither.newB(newEditor);
|
263
|
70 }
|
|
71
|
|
72
|
|
73 @Override
|
|
74 public Either<Error, JungleTreeEditor> addNewChildAt(NodePath path, int pos) {
|
|
75 AppendChildAt appendChildAt = new AppendChildAt(pos);
|
|
76 return _edit(path,appendChildAt);
|
|
77 }
|
|
78
|
|
79 @Override
|
|
80 public Either<Error, JungleTreeEditor> deleteChildAt(NodePath path, int pos) {
|
|
81 return null;
|
|
82 }
|
|
83
|
|
84 @Override
|
|
85 public Either<Error, JungleTreeEditor> putAttribute(NodePath path, String key, ByteBuffer value) {
|
|
86 return null;
|
|
87 }
|
|
88
|
|
89 @Override
|
|
90 public Either<Error, JungleTreeEditor> deleteAttribute(NodePath path, String key) {
|
|
91 return null;
|
|
92 }
|
|
93
|
|
94 @Override
|
|
95 public Either<Error, JungleTreeEditor> replaceNewRootNode() {
|
|
96 return null;
|
|
97 }
|
|
98
|
|
99 @Override
|
|
100 public Either<Error, JungleTreeEditor> edit(NodePath path, NodeEditor editor) {
|
|
101 return null;
|
|
102 }
|
|
103
|
|
104 @Override
|
|
105 public Either<Error, JungleTreeEditor> success() {
|
|
106 return null;
|
|
107 }
|
|
108
|
|
109 @Override
|
|
110 public Either<Error, JungleTreeEditor> flushSuccess() {
|
|
111 return null;
|
|
112 }
|
|
113
|
|
114 @Override
|
|
115 public Either<Error, JungleTreeEditor> moveChild(NodePath path, int childNum, String move) {
|
|
116 return DefaultEither.newA(NOT_USE_METHOD);
|
|
117 }
|
|
118 }
|