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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
12604eb6b615 added javadoc
shoshi
parents: 4
diff changeset
3 import java.util.LinkedList;
12604eb6b615 added javadoc
shoshi
parents: 4
diff changeset
4
12604eb6b615 added javadoc
shoshi
parents: 4
diff changeset
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
shoshi
parents: 6
diff changeset
9 import treecms.tree.util.NodeData;
4
f5ed85be5640 finished treecms.cassandra.v1 implementation (not tested yet)
shoshi
parents:
diff changeset
10
6
12604eb6b615 added javadoc
shoshi
parents: 4
diff changeset
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
12604eb6b615 added javadoc
shoshi
parents: 4
diff changeset
40 }
12604eb6b615 added javadoc
shoshi
parents: 4
diff changeset
41
12604eb6b615 added javadoc
shoshi
parents: 4
diff changeset
42 @Override
12604eb6b615 added javadoc
shoshi
parents: 4
diff changeset
43 public synchronized Node updateTree(Node _target,NodeData _newData)
12604eb6b615 added javadoc
shoshi
parents: 4
diff changeset
44 {
12604eb6b615 added javadoc
shoshi
parents: 4
diff changeset
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
12604eb6b615 added javadoc
shoshi
parents: 4
diff changeset
47 if(path == null)
12604eb6b615 added javadoc
shoshi
parents: 4
diff changeset
48 {
12604eb6b615 added javadoc
shoshi
parents: 4
diff changeset
49 //not found.
12604eb6b615 added javadoc
shoshi
parents: 4
diff changeset
50 return null;
12604eb6b615 added javadoc
shoshi
parents: 4
diff changeset
51 }
12604eb6b615 added javadoc
shoshi
parents: 4
diff changeset
52
12604eb6b615 added javadoc
shoshi
parents: 4
diff changeset
53
12604eb6b615 added javadoc
shoshi
parents: 4
diff changeset
54 //clone
12604eb6b615 added javadoc
shoshi
parents: 4
diff changeset
55
12604eb6b615 added javadoc
shoshi
parents: 4
diff changeset
56
12604eb6b615 added javadoc
shoshi
parents: 4
diff changeset
57 m_root = path.peekFirst();
12604eb6b615 added javadoc
shoshi
parents: 4
diff changeset
58 return path.peekLast();
12604eb6b615 added javadoc
shoshi
parents: 4
diff changeset
59 }
12604eb6b615 added javadoc
shoshi
parents: 4
diff changeset
60
12604eb6b615 added javadoc
shoshi
parents: 4
diff changeset
61 CassandraNode cloneNode(CassandraNode _target,NodeData _newData)
12604eb6b615 added javadoc
shoshi
parents: 4
diff changeset
62 {
12604eb6b615 added javadoc
shoshi
parents: 4
diff changeset
63 CassandraNode clone = (CassandraNode)m_forest.createNode(_target.getID().update(),_newData);
12604eb6b615 added javadoc
shoshi
parents: 4
diff changeset
64 m_table.put(clone.getID().getUUID(),clone);
12604eb6b615 added javadoc
shoshi
parents: 4
diff changeset
65 return clone;
12604eb6b615 added javadoc
shoshi
parents: 4
diff changeset
66 }
12604eb6b615 added javadoc
shoshi
parents: 4
diff changeset
67
12604eb6b615 added javadoc
shoshi
parents: 4
diff changeset
68 LinkedList<CassandraNode> findPath(CassandraNode _parent,CassandraNode _target,NodeData _newData)
12604eb6b615 added javadoc
shoshi
parents: 4
diff changeset
69 {
12604eb6b615 added javadoc
shoshi
parents: 4
diff changeset
70 if(_parent.getID().isFamily(_target.getID())){
12604eb6b615 added javadoc
shoshi
parents: 4
diff changeset
71 //find.
12604eb6b615 added javadoc
shoshi
parents: 4
diff changeset
72 LinkedList<CassandraNode> path = new LinkedList<CassandraNode>();
12604eb6b615 added javadoc
shoshi
parents: 4
diff changeset
73 path.addFirst(_target);
12604eb6b615 added javadoc
shoshi
parents: 4
diff changeset
74 return path;
12604eb6b615 added javadoc
shoshi
parents: 4
diff changeset
75 }
12604eb6b615 added javadoc
shoshi
parents: 4
diff changeset
76
12604eb6b615 added javadoc
shoshi
parents: 4
diff changeset
77 for(Node child : _parent.getData().list()){
12604eb6b615 added javadoc
shoshi
parents: 4
diff changeset
78 LinkedList<CassandraNode> path = findPath((CassandraNode)child,_target,_newData);
12604eb6b615 added javadoc
shoshi
parents: 4
diff changeset
79 if(path != null){
12604eb6b615 added javadoc
shoshi
parents: 4
diff changeset
80 path.addFirst(_parent);
12604eb6b615 added javadoc
shoshi
parents: 4
diff changeset
81 return path;
12604eb6b615 added javadoc
shoshi
parents: 4
diff changeset
82 }
12604eb6b615 added javadoc
shoshi
parents: 4
diff changeset
83 }
12604eb6b615 added javadoc
shoshi
parents: 4
diff changeset
84
12604eb6b615 added javadoc
shoshi
parents: 4
diff changeset
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 }