Mercurial > hg > Database > jungle-network
annotate src/main/java/alice/jungle/transaction/JungleUpdater.java @ 192:3202a2a427b1 default tip
bug fix
author | tatsuki |
---|---|
date | Tue, 20 Jan 2015 09:30:59 +0900 |
parents | 495ac60d7f5f |
children |
rev | line source |
---|---|
113 | 1 package alice.jungle.transaction; |
85 | 2 |
3 import java.nio.ByteBuffer; | |
4 | |
5 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.JungleTreeEditor; | |
6 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.Command; | |
118
f64ff5bd66f5
Implements persistent for bbs app and Fixed bug JungleUpdater
one
parents:
115
diff
changeset
|
7 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.NodePath; |
85 | 8 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.operations.NodeOperation; |
9 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.operations.TreeOperation; | |
10 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Either; | |
11 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Error; | |
12 | |
13 public class JungleUpdater { | |
14 | |
15 public JungleUpdater() { | |
16 | |
17 } | |
18 | |
115 | 19 public static Either<Error, JungleTreeEditor> edit(JungleTreeEditor _editor ,Iterable<TreeOperation> _log) { |
85 | 20 JungleTreeEditor editor = _editor; |
21 Either<Error, JungleTreeEditor> either = null; | |
22 for (TreeOperation op : _log) { | |
123 | 23 NodePath path = op.getNodePath(); |
24 NodeOperation nodeOp = op.getNodeOperation(); | |
25 either = _edit(editor, path, nodeOp, nodeOp.getPosition()); | |
85 | 26 if(either.isA()) { |
27 return either; | |
28 } | |
29 editor = either.b(); | |
30 } | |
31 return either; | |
32 } | |
33 | |
123 | 34 /* |
35 * This method decide node position by param. | |
36 */ | |
37 public static Either<Error, JungleTreeEditor> edit(JungleTreeEditor _editor ,Iterable<TreeOperation> _log, int pos) { | |
38 JungleTreeEditor editor = _editor; | |
39 Either<Error, JungleTreeEditor> either = null; | |
40 for (TreeOperation op : _log) { | |
41 NodePath path = op.getNodePath(); | |
42 NodeOperation nodeOp = op.getNodeOperation(); | |
43 either = _edit(editor, path, nodeOp, pos); | |
44 if(either.isA()) { | |
45 return either; | |
46 } | |
47 editor = either.b(); | |
48 } | |
49 return either; | |
50 } | |
51 | |
52 | |
53 private static Either<Error, JungleTreeEditor> _edit(JungleTreeEditor editor, NodePath path, | |
54 NodeOperation nodeOp, int pos) { | |
55 String key = ""; | |
56 Command c = nodeOp.getCommand(); | |
192 | 57 System.out.println("path = " + path.toString()); |
85 | 58 switch (c) { |
59 case PUT_ATTRIBUTE: | |
60 key = nodeOp.getKey(); | |
61 ByteBuffer value = nodeOp.getValue(); | |
192 | 62 System.out.println("key = " + key + " : " + "value = " + new String(value.array())); |
85 | 63 return editor.putAttribute(path, key, value); |
64 case DELETE_ATTRIBUTE: | |
65 key = nodeOp.getKey(); | |
66 return editor.deleteAttribute(path, key); | |
67 case APPEND_CHILD: | |
68 return editor.addNewChildAt(path, pos); | |
69 case DELETE_CHILD: | |
70 return editor.deleteChildAt(path, 0); | |
71 } | |
72 return null; | |
123 | 73 } |
74 | |
85 | 75 } |