Mercurial > hg > Members > shoshi > TreeCMSv2
view 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 source
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; class CassandraTreeEditor extends CassandraTree implements TreeEditor { public CassandraTreeEditor(CassandraTree _tree,CassandraForest _forest) { super(_tree.m_root,_forest); } @Override public boolean commit(boolean _force) { return false; } @Override public boolean pull() { return false; } @Override public boolean check() { return false; } @Override 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. } }