Mercurial > hg > Members > shoshi > TreeCMSv2
view src/treecms/tree/cassandra/v1/CassandraTreeEditor.java @ 16:bb9760760744
commit
author | shoshi |
---|---|
date | Sat, 21 May 2011 04:46:00 +0900 |
parents | 12604eb6b615 |
children |
line wrap: on
line source
package treecms.tree.cassandra.v1; import java.util.LinkedList; import treecms.api.Node; import treecms.api.TreeEditor; import treecms.merger.Merger; import treecms.merger.ReplaceMerger; import treecms.tree.util.NodeData; 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. } }