Mercurial > hg > Members > tatsuki > bench > jungle-core
comparison src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/transaction/DefaultJungleTreeEditor.java @ 153:20af7f25ef32
miner change
author | one |
---|---|
date | Tue, 25 Nov 2014 17:52:41 +0900 |
parents | 8a0aa8fc137c |
children | e26462a38ce0 |
comparison
equal
deleted
inserted
replaced
152:8a0aa8fc137c | 153:20af7f25ef32 |
---|---|
21 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.trasnformer.PutAttribute; | 21 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.trasnformer.PutAttribute; |
22 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.DefaultEither; | 22 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.DefaultEither; |
23 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Either; | 23 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Either; |
24 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Error; | 24 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Error; |
25 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.IterableConverter; | 25 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.IterableConverter; |
26 import jp.ac.u_ryukyu.ie.cr.tatsuki.jungle.store.index.Index; | |
27 import jp.ac.u_ryukyu.ie.cr.tatsuki.jungle.store.index.ParentIndex; | |
28 | 26 |
29 public class DefaultJungleTreeEditor implements JungleTreeEditor | 27 public class DefaultJungleTreeEditor implements JungleTreeEditor |
30 { | 28 { |
31 private final TransactionManager txManager; | 29 private final TransactionManager txManager; |
32 private final TreeNode root; | 30 private final TreeNode root; |
33 private final TreeEditor editor; | 31 private final TreeEditor editor; |
34 private final TreeOperationLog log; | 32 private final TreeOperationLog log; |
35 private final Index index; | |
36 private final ParentIndex parentIndex; | |
37 | 33 |
38 // public DefaultJungleTreeEditor(TreeNode root) | |
39 // { | |
40 // this(root,txManager,_editor,new DefaultTreeOperationLog()); | |
41 // } | |
42 | 34 |
43 public DefaultJungleTreeEditor(TreeNode _root,TransactionManager _txManager,TreeEditor _editor, Index index,ParentIndex parentIndex) | 35 public DefaultJungleTreeEditor(TreeNode _root,TransactionManager _txManager,TreeEditor _editor) |
44 { | 36 { |
45 this(_root,_txManager,_editor,new DefaultTreeOperationLog(),index,parentIndex); | 37 this(_root,_txManager,_editor,new DefaultTreeOperationLog()); |
46 } | 38 } |
47 | 39 |
48 | 40 |
49 | 41 |
50 public DefaultJungleTreeEditor(TreeNode newNode,TransactionManager _txManager,TreeEditor _editor,TreeOperationLog _log, Index index,ParentIndex parentIndex) | 42 public DefaultJungleTreeEditor(TreeNode newNode,TransactionManager _txManager,TreeEditor _editor,TreeOperationLog _log) |
51 { | 43 { |
52 this.root = newNode; | 44 this.root = newNode; |
53 this.txManager = _txManager; | 45 this.txManager = _txManager; |
54 this.editor = _editor; | 46 this.editor = _editor; |
55 this.log = _log; | 47 this.log = _log; |
56 this.index = index; | |
57 this.parentIndex = parentIndex; | |
58 } | 48 } |
59 | 49 |
60 private Either<Error,JungleTreeEditor> _edit(final NodePath _path,NodeEditor _e) | 50 private Either<Error,JungleTreeEditor> _edit(final NodePath _path,NodeEditor _e) |
61 { | 51 { |
62 Either<Error,LoggingNode> either = editor.edit(root,_path,_e); | 52 Either<Error,LoggingNode> either = editor.edit(root,_path,_e); |
77 | 67 |
78 Iterable<TreeOperation> iterable = new IterableConverter<TreeOperation,NodeOperation>(newLog,converter); | 68 Iterable<TreeOperation> iterable = new IterableConverter<TreeOperation,NodeOperation>(newLog,converter); |
79 DefaultTreeOperationLog treeOperationLog = new DefaultTreeOperationLog(iterable,newLog.length()); | 69 DefaultTreeOperationLog treeOperationLog = new DefaultTreeOperationLog(iterable,newLog.length()); |
80 TreeOperationLog newTreeOpLog = log.append(treeOperationLog); | 70 TreeOperationLog newTreeOpLog = log.append(treeOperationLog); |
81 | 71 |
82 JungleTreeEditor newEditor = new DefaultJungleTreeEditor(newNode,txManager,editor,newTreeOpLog,index,parentIndex); | 72 JungleTreeEditor newEditor = new DefaultJungleTreeEditor(newNode,txManager,editor,newTreeOpLog); |
83 return DefaultEither.newB(newEditor); | 73 return DefaultEither.newB(newEditor); |
84 } | 74 } |
85 | 75 |
86 @Override | 76 @Override |
87 public Either<Error,JungleTreeEditor> addNewChildAt(NodePath _path, int _pos) | 77 public Either<Error,JungleTreeEditor> addNewChildAt(NodePath _path, int _pos) |
118 } | 108 } |
119 | 109 |
120 @Override | 110 @Override |
121 public Either<Error,JungleTreeEditor> success() | 111 public Either<Error,JungleTreeEditor> success() |
122 { | 112 { |
123 Either<Error,TransactionManager> either = txManager.commit(root,log,index,parentIndex); | 113 Either<Error,TransactionManager> either = txManager.commit(root,log); |
124 if(either.isA()){ | 114 if(either.isA()){ |
125 return DefaultEither.newA(either.a()); | 115 return DefaultEither.newA(either.a()); |
126 } | 116 } |
127 | 117 |
128 TransactionManager newTxManager = either.b(); | 118 TransactionManager newTxManager = either.b(); |
129 JungleTreeEditor newTreeEditor = new DefaultJungleTreeEditor(root,newTxManager,editor,index,parentIndex); | 119 JungleTreeEditor newTreeEditor = new DefaultJungleTreeEditor(root,newTxManager,editor); |
130 | 120 |
131 return DefaultEither.newB(newTreeEditor); | 121 return DefaultEither.newB(newTreeEditor); |
132 } | 122 } |
133 | 123 |
134 @Override | |
135 public String getID() | |
136 { | |
137 return txManager.getUUID(); | |
138 } | |
139 | 124 |
140 @Override | |
141 public String getRevision() | |
142 { | |
143 return Long.toString(txManager.getRevision()); | |
144 } | |
145 | |
146 @Override | |
147 public TreeNode getRoot() | |
148 { | |
149 return root; | |
150 } | |
151 } | 125 } |