Mercurial > hg > Members > shoshi > TreeCMSv2
diff src/treecms/tree/cassandra/v1/CassandraTreeEditor.java @ 6:12604eb6b615
added javadoc
author | shoshi |
---|---|
date | Mon, 14 Mar 2011 23:24:38 +0900 |
parents | f5ed85be5640 |
children | bb9760760744 |
line wrap: on
line diff
--- a/src/treecms/tree/cassandra/v1/CassandraTreeEditor.java Tue Mar 01 01:29:59 2011 +0900 +++ b/src/treecms/tree/cassandra/v1/CassandraTreeEditor.java Mon Mar 14 23:24:38 2011 +0900 @@ -1,10 +1,14 @@ package treecms.tree.cassandra.v1; +import java.util.LinkedList; + +import treecms.api.Node; +import treecms.api.NodeData; import treecms.api.TreeEditor; import treecms.merger.Merger; import treecms.merger.ReplaceMerger; -public class CassandraTreeEditor extends CassandraTree implements TreeEditor +class CassandraTreeEditor extends CassandraTree implements TreeEditor { public CassandraTreeEditor(CassandraTree _tree,CassandraForest _forest) { @@ -33,6 +37,51 @@ public void merge() { Merger merger = new ReplaceMerger(); + } + + @Override + public synchronized Node updateTree(Node _target,NodeData _newData) + { + LinkedList<CassandraNode> path = findPath(m_root,(CassandraNode)_target,_newData); + if(path == null) + { + //not found. + return null; + } + + + //clone + + + m_root = path.peekFirst(); + return path.peekLast(); + } + + CassandraNode cloneNode(CassandraNode _target,NodeData _newData) + { + CassandraNode clone = (CassandraNode)m_forest.createNode(_target.getID().update(),_newData); + m_table.put(clone.getID().getUUID(),clone); + return clone; + } + + LinkedList<CassandraNode> findPath(CassandraNode _parent,CassandraNode _target,NodeData _newData) + { + if(_parent.getID().isFamily(_target.getID())){ + //find. + LinkedList<CassandraNode> path = new LinkedList<CassandraNode>(); + path.addFirst(_target); + return path; + } + + for(Node child : _parent.getData().list()){ + LinkedList<CassandraNode> path = findPath((CassandraNode)child,_target,_newData); + if(path != null){ + path.addFirst(_parent); + return path; + } + } + + return null; //not found. } }