Mercurial > hg > Members > tatsuki > bench > jungle-core
comparison src/main/java/jp/ac/u_ryukyu/ie/cr/tatsuki/jungle/store/index/PutIndexEditor.java @ 128:9c46e5c2ffac
edit PutIndexEditor
author | one |
---|---|
date | Tue, 14 Oct 2014 15:06:02 +0900 |
parents | baa1e2e7c503 |
children | bb53330364f1 |
comparison
equal
deleted
inserted
replaced
127:b2c1fd513feb | 128:9c46e5c2ffac |
---|---|
1 package jp.ac.u_ryukyu.ie.cr.tatsuki.jungle.store.index; | 1 package jp.ac.u_ryukyu.ie.cr.tatsuki.jungle.store.index; |
2 | 2 |
3 | 3 |
4 | |
5 import fj.Ord; | |
6 import fj.data.List; | |
7 import fj.data.Option; | |
8 import fj.data.TreeMap; | |
4 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.JungleTreeEditor; | 9 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.JungleTreeEditor; |
10 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.NodePath; | |
11 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.TreeEditor; | |
12 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.TreeNode; | |
13 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.logger.TreeOperationLog; | |
5 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.transaction.IndexJungleTreeEditor; | 14 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.transaction.IndexJungleTreeEditor; |
15 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.transaction.TransactionManager; | |
16 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.DefaultEither; | |
6 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Either; | 17 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Either; |
7 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Error; | 18 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Error; |
19 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Pair; | |
20 import jp.ac.u_ryukyu.ie.cr.tatsuki.jungle.query.PathNodeIndexIterator; | |
21 | |
22 import java.nio.ByteBuffer; | |
8 | 23 |
9 public class PutIndexEditor implements IndexEditor { | 24 public class PutIndexEditor implements IndexEditor { |
10 | 25 |
26 String key; | |
27 String attribute; | |
28 NodePath path; | |
29 TransactionManager txManager; | |
30 TreeNode root; | |
31 TreeEditor editor; | |
32 TreeOperationLog log; | |
33 | |
34 public PutIndexEditor(String key, ByteBuffer attribute,NodePath path) { | |
35 this.key = key; | |
36 this.attribute = new String(attribute.array()); | |
37 this.path = path; | |
38 } | |
39 | |
11 @Override | 40 @Override |
12 public Either<Error,JungleTreeEditor> edit(IndexJungleTreeEditor e) { | 41 public Either<Error, JungleTreeEditor> edit(TreeNode root,TransactionManager txManager,TreeEditor editor,TreeOperationLog log,TreeMap<String, TreeMap<String, List<Pair<TreeNode, NodePath>>>> index) { |
13 // TODO Auto-generated method stub | 42 TreeNode target = getTarget(root, path); |
14 return null; | 43 TreeMap<String, TreeMap<String, List<Pair<TreeNode, NodePath>>>> newIndex = editIndex(target, path, key, attribute,index); |
44 IndexJungleTreeEditor newEditor = new IndexJungleTreeEditor(root,txManager,editor,log, newIndex); | |
45 Either<Error, JungleTreeEditor> either = DefaultEither.newB(newEditor); | |
46 return either; | |
15 } | 47 } |
48 | |
49 public TreeMap<String, TreeMap<String, List<Pair<TreeNode, NodePath>>>> editIndex(TreeNode target, NodePath path, String key, String attribute,TreeMap<String, TreeMap<String, List<Pair<TreeNode, NodePath>>>> index){ | |
50 | |
51 Option<TreeMap<String, List<Pair<TreeNode, NodePath>>>> innerIndexOp = index.get(key); | |
52 Pair<TreeNode, NodePath> pathNode = new Pair<TreeNode, NodePath>(target,path); | |
53 | |
54 if (attribute != null) { | |
55 if (innerIndexOp.isNone()) { | |
56 | |
57 TreeMap<String, List<Pair<TreeNode, NodePath>>> innerIndex = TreeMap.empty(Ord.stringOrd); | |
58 List<Pair<TreeNode, NodePath>> list = List.nil(); | |
59 list = list.cons(pathNode); | |
60 innerIndex = innerIndex.set(attribute, list); | |
61 TreeMap<String, TreeMap<String, List<Pair<TreeNode, NodePath>>>> newIndex = index.set(key, innerIndex); | |
62 return newIndex; | |
63 } else { | |
64 | |
65 TreeMap<String, List<Pair<TreeNode, NodePath>>> innerIndex = innerIndexOp.some(); | |
66 innerIndex.set(attribute, null); | |
67 Option<List<Pair<TreeNode, NodePath>>> opList = innerIndex.get(attribute); | |
68 | |
69 if (opList.isNone()) { | |
70 | |
71 List<Pair<TreeNode, NodePath>> list = List.nil(); | |
72 list = list.cons(pathNode); | |
73 innerIndex = innerIndex.set(attribute, list); | |
74 | |
75 } else { | |
76 | |
77 List<Pair<TreeNode, NodePath>> list = opList.some(); | |
78 list = list.cons(pathNode); | |
79 innerIndex = innerIndex.set(attribute, list); | |
80 | |
81 } | |
82 TreeMap<String, TreeMap<String, List<Pair<TreeNode, NodePath>>>> newIndex = index.set(key, innerIndex); | |
83 return newIndex; | |
84 } | |
85 } | |
86 return index; | |
87 } | |
88 | |
89 public TreeNode getTarget(TreeNode node , NodePath path){ | |
90 Pair<Integer, NodePath> pathNode = path.pop(); | |
91 Either<Error, TreeNode> either = node.getChildren().at(pathNode.left()); | |
92 if (either.isA()) | |
93 return node; | |
94 TreeNode child = either.b(); | |
95 TreeNode target = getTarget(child,pathNode.right()); | |
96 return target; | |
97 } | |
98 | |
16 } | 99 } |