Mercurial > hg > Members > shoshi > TreeCMSv2
annotate src/treecms/tree/cassandra/v1/CassandraTreeEditor.java @ 16:bb9760760744
commit
author | shoshi |
---|---|
date | Sat, 21 May 2011 04:46:00 +0900 |
parents | 12604eb6b615 |
children |
rev | line source |
---|---|
4
f5ed85be5640
finished treecms.cassandra.v1 implementation (not tested yet)
shoshi
parents:
diff
changeset
|
1 package treecms.tree.cassandra.v1; |
f5ed85be5640
finished treecms.cassandra.v1 implementation (not tested yet)
shoshi
parents:
diff
changeset
|
2 |
6 | 3 import java.util.LinkedList; |
4 | |
5 import treecms.api.Node; | |
4
f5ed85be5640
finished treecms.cassandra.v1 implementation (not tested yet)
shoshi
parents:
diff
changeset
|
6 import treecms.api.TreeEditor; |
f5ed85be5640
finished treecms.cassandra.v1 implementation (not tested yet)
shoshi
parents:
diff
changeset
|
7 import treecms.merger.Merger; |
f5ed85be5640
finished treecms.cassandra.v1 implementation (not tested yet)
shoshi
parents:
diff
changeset
|
8 import treecms.merger.ReplaceMerger; |
16 | 9 import treecms.tree.util.NodeData; |
4
f5ed85be5640
finished treecms.cassandra.v1 implementation (not tested yet)
shoshi
parents:
diff
changeset
|
10 |
6 | 11 class CassandraTreeEditor extends CassandraTree implements TreeEditor |
4
f5ed85be5640
finished treecms.cassandra.v1 implementation (not tested yet)
shoshi
parents:
diff
changeset
|
12 { |
f5ed85be5640
finished treecms.cassandra.v1 implementation (not tested yet)
shoshi
parents:
diff
changeset
|
13 public CassandraTreeEditor(CassandraTree _tree,CassandraForest _forest) |
f5ed85be5640
finished treecms.cassandra.v1 implementation (not tested yet)
shoshi
parents:
diff
changeset
|
14 { |
f5ed85be5640
finished treecms.cassandra.v1 implementation (not tested yet)
shoshi
parents:
diff
changeset
|
15 super(_tree.m_root,_forest); |
f5ed85be5640
finished treecms.cassandra.v1 implementation (not tested yet)
shoshi
parents:
diff
changeset
|
16 } |
f5ed85be5640
finished treecms.cassandra.v1 implementation (not tested yet)
shoshi
parents:
diff
changeset
|
17 |
f5ed85be5640
finished treecms.cassandra.v1 implementation (not tested yet)
shoshi
parents:
diff
changeset
|
18 @Override |
f5ed85be5640
finished treecms.cassandra.v1 implementation (not tested yet)
shoshi
parents:
diff
changeset
|
19 public boolean commit(boolean _force) |
f5ed85be5640
finished treecms.cassandra.v1 implementation (not tested yet)
shoshi
parents:
diff
changeset
|
20 { |
f5ed85be5640
finished treecms.cassandra.v1 implementation (not tested yet)
shoshi
parents:
diff
changeset
|
21 return false; |
f5ed85be5640
finished treecms.cassandra.v1 implementation (not tested yet)
shoshi
parents:
diff
changeset
|
22 } |
f5ed85be5640
finished treecms.cassandra.v1 implementation (not tested yet)
shoshi
parents:
diff
changeset
|
23 |
f5ed85be5640
finished treecms.cassandra.v1 implementation (not tested yet)
shoshi
parents:
diff
changeset
|
24 @Override |
f5ed85be5640
finished treecms.cassandra.v1 implementation (not tested yet)
shoshi
parents:
diff
changeset
|
25 public boolean pull() |
f5ed85be5640
finished treecms.cassandra.v1 implementation (not tested yet)
shoshi
parents:
diff
changeset
|
26 { |
f5ed85be5640
finished treecms.cassandra.v1 implementation (not tested yet)
shoshi
parents:
diff
changeset
|
27 return false; |
f5ed85be5640
finished treecms.cassandra.v1 implementation (not tested yet)
shoshi
parents:
diff
changeset
|
28 } |
f5ed85be5640
finished treecms.cassandra.v1 implementation (not tested yet)
shoshi
parents:
diff
changeset
|
29 |
f5ed85be5640
finished treecms.cassandra.v1 implementation (not tested yet)
shoshi
parents:
diff
changeset
|
30 @Override |
f5ed85be5640
finished treecms.cassandra.v1 implementation (not tested yet)
shoshi
parents:
diff
changeset
|
31 public boolean check() |
f5ed85be5640
finished treecms.cassandra.v1 implementation (not tested yet)
shoshi
parents:
diff
changeset
|
32 { |
f5ed85be5640
finished treecms.cassandra.v1 implementation (not tested yet)
shoshi
parents:
diff
changeset
|
33 return false; |
f5ed85be5640
finished treecms.cassandra.v1 implementation (not tested yet)
shoshi
parents:
diff
changeset
|
34 } |
f5ed85be5640
finished treecms.cassandra.v1 implementation (not tested yet)
shoshi
parents:
diff
changeset
|
35 |
f5ed85be5640
finished treecms.cassandra.v1 implementation (not tested yet)
shoshi
parents:
diff
changeset
|
36 @Override |
f5ed85be5640
finished treecms.cassandra.v1 implementation (not tested yet)
shoshi
parents:
diff
changeset
|
37 public void merge() |
f5ed85be5640
finished treecms.cassandra.v1 implementation (not tested yet)
shoshi
parents:
diff
changeset
|
38 { |
f5ed85be5640
finished treecms.cassandra.v1 implementation (not tested yet)
shoshi
parents:
diff
changeset
|
39 Merger merger = new ReplaceMerger(); |
6 | 40 } |
41 | |
42 @Override | |
43 public synchronized Node updateTree(Node _target,NodeData _newData) | |
44 { | |
45 LinkedList<CassandraNode> path = findPath(m_root,(CassandraNode)_target,_newData); | |
4
f5ed85be5640
finished treecms.cassandra.v1 implementation (not tested yet)
shoshi
parents:
diff
changeset
|
46 |
6 | 47 if(path == null) |
48 { | |
49 //not found. | |
50 return null; | |
51 } | |
52 | |
53 | |
54 //clone | |
55 | |
56 | |
57 m_root = path.peekFirst(); | |
58 return path.peekLast(); | |
59 } | |
60 | |
61 CassandraNode cloneNode(CassandraNode _target,NodeData _newData) | |
62 { | |
63 CassandraNode clone = (CassandraNode)m_forest.createNode(_target.getID().update(),_newData); | |
64 m_table.put(clone.getID().getUUID(),clone); | |
65 return clone; | |
66 } | |
67 | |
68 LinkedList<CassandraNode> findPath(CassandraNode _parent,CassandraNode _target,NodeData _newData) | |
69 { | |
70 if(_parent.getID().isFamily(_target.getID())){ | |
71 //find. | |
72 LinkedList<CassandraNode> path = new LinkedList<CassandraNode>(); | |
73 path.addFirst(_target); | |
74 return path; | |
75 } | |
76 | |
77 for(Node child : _parent.getData().list()){ | |
78 LinkedList<CassandraNode> path = findPath((CassandraNode)child,_target,_newData); | |
79 if(path != null){ | |
80 path.addFirst(_parent); | |
81 return path; | |
82 } | |
83 } | |
84 | |
85 return null; //not found. | |
4
f5ed85be5640
finished treecms.cassandra.v1 implementation (not tested yet)
shoshi
parents:
diff
changeset
|
86 } |
f5ed85be5640
finished treecms.cassandra.v1 implementation (not tested yet)
shoshi
parents:
diff
changeset
|
87 } |