Mercurial > hg > Members > shoshi > jungle > jungle-core
changeset 37:35e327577b58
added transaction
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/Jungle.java Sat Jan 26 22:52:32 2013 +0900 @@ -0,0 +1,7 @@ +package jp.ac.u_ryukyu.ie.cr.shoshi.jungle; + +public interface Jungle +{ + public JungleTree getTreeByName(String _name); + public JungleTree createNewTree(String _name); +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/JungleTree.java Sat Jan 26 22:52:32 2013 +0900 @@ -0,0 +1,9 @@ +package jp.ac.u_ryukyu.ie.cr.shoshi.jungle; + +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.core.Node; + +public interface JungleTree +{ + public JungleTreeEditor getTreeEditor(); + public Node getRootNode(); +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/JungleTreeEditor.java Sat Jan 26 22:52:32 2013 +0900 @@ -0,0 +1,9 @@ +package jp.ac.u_ryukyu.ie.cr.shoshi.jungle; + +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.Transaction; +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.TreeEditor; + +public interface JungleTreeEditor extends TreeEditor , Transaction<JungleTree> +{ + +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/core/Parent.java Sat Jan 26 22:52:32 2013 +0900 @@ -0,0 +1,6 @@ +package jp.ac.u_ryukyu.ie.cr.shoshi.jungle.core; + +public interface Parent<T> +{ + public Children<T> getChildren(); +}
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/store/Transaction.java Sat Jan 26 18:41:25 2013 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/store/Transaction.java Sat Jan 26 22:52:32 2013 +0900 @@ -1,6 +1,7 @@ package jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Either; +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Error; public interface Transaction<T> {
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/store/TreeEditor.java Sat Jan 26 18:41:25 2013 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/store/TreeEditor.java Sat Jan 26 22:52:32 2013 +0900 @@ -5,11 +5,11 @@ import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Either; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Error; -public interface TreeEditor +public interface TreeEditor<T extends TreeEditor<T>> { - public Either<Error,TreeEditor> appendChild(NodePath _path,int _pos); - public Either<Error,TreeEditor> deleteChild(NodePath _path,int _pos); - public Either<Error,TreeEditor> putAttribute(NodePath _path,String _key,ByteBuffer _value); - public Either<Error,TreeEditor> deleteAttribute(NodePath _path,String _key); - public Either<Error,TreeEditor> edit(NodePath _path,NodeEditor _transformer); + public Either<Error,T> appendChild(NodePath _path,int _pos); + public Either<Error,T> deleteChild(NodePath _path,int _pos); + public Either<Error,T> putAttribute(NodePath _path,String _key,ByteBuffer _value); + public Either<Error,T> deleteAttribute(NodePath _path,String _key); + public Either<Error,T> edit(NodePath _path,NodeEditor _transformer); }
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/store/impl/ClonableAttributes.java Sat Jan 26 22:52:32 2013 +0900 @@ -0,0 +1,8 @@ +package jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl; + +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.trasnformer.EditableAttributes; + +public interface ClonableAttributes<T extends ClonableNode<T>> extends EditableAttributes<T> +{ + +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/store/impl/ClonableChildren.java Sat Jan 26 22:52:32 2013 +0900 @@ -0,0 +1,11 @@ +package jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl; + +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.trasnformer.EditableChildren; +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.trasnformer.EditableNode; +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Either; +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Error; + +public interface ClonableChildren<T extends EditableNode<T>> extends EditableChildren<T> +{ + public Either<Error,T> replaceNode(int _pos,T _replacement); +} \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/store/impl/ClonableNode.java Sat Jan 26 22:52:32 2013 +0900 @@ -0,0 +1,12 @@ +package jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl; + +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.trasnformer.EditableNode; + +public interface ClonableNode<T extends ClonableNode<T>> extends EditableNode<T> +{ + @Override + public ClonableChildren<T> getChildren(); + + @Override + public ClonableAttributes<T> getAttributes(); +}
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/store/impl/DefaultAttributes.java Sat Jan 26 18:41:25 2013 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/store/impl/DefaultAttributes.java Sat Jan 26 22:52:32 2013 +0900 @@ -6,23 +6,23 @@ import fj.data.Option; import fj.data.TreeMap; +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.core.Attributes; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.trasnformer.EditableAttributes; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.trasnformer.EditableNode; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.DefaultEither; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Either; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Error; -public class DefaultAttributes implements EditableAttributes<DefaultNode> +public class DefaultAttributes implements Attributes<String,ByteBuffer> { private final TreeMap<String,ByteBuffer> attrs; - private final List<DefaultNode> children; - public DefaultAttributes(List<DefaultNode> _children,TreeMap<String,ByteBuffer> _attrs) + public DefaultAttributes(TreeMap<String,ByteBuffer> _attrs) { - children = _children; attrs = _attrs; } + /* @Override public Either<Error,DefaultNode> put(String _key,ByteBuffer _value) { @@ -31,6 +31,12 @@ return DefaultEither.newB(newNode); } + */ + + public TreeMap<String,ByteBuffer> getAttributesAsRawMap() + { + return attrs; + } @Override public ByteBuffer get(String _key) @@ -39,16 +45,11 @@ return result.isSome() ? result.some() : null; } + /* @Override public Either<Error,EditableNode> delete(String _key) { return null; } - - @Override - public Object get(Object _key) { - // TODO Auto-generated method stub - return null; - } - + */ }
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/store/impl/DefaultChangeSet.java Sat Jan 26 18:41:25 2013 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,60 +0,0 @@ -package jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl; - -import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.persistent.ChangeList; -import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.ChangeSet; -import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.operations.Operation; - -public class DefaultChangeSet implements ChangeSet -{ - private final ChangeSet prev; - private final String uuid; - private final long revision; - - private final ChangeList changeList; - private final DefaultNode root; - - public DefaultChangeSet(DefaultNode _root,ChangeList _changeList,String _uuid,long _revision,ChangeSet _prev) - { - root = _root; - uuid = _uuid; - revision = _revision; - prev = _prev; - changeList = _changeList; - } - - @Override - public ChangeSet prev() - { - return prev; - } - - @Override - public String uuid() - { - return uuid; - } - - @Override - public long revision() - { - return revision; - } - - @Override - public Iterable<Operation> getOperations() - { - return changeList; - } - - @Override - public DefaultNode getRoot() - { - return root; - } - - @Override - public ChangeList getChangeList() - { - return changeList; - } -}
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/store/impl/DefaultChildren.java Sat Jan 26 18:41:25 2013 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/store/impl/DefaultChildren.java Sat Jan 26 22:52:32 2013 +0900 @@ -1,29 +1,22 @@ package jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl; -import java.nio.ByteBuffer; + import java.util.Iterator; -import fj.P2; import fj.data.List; -import fj.data.TreeMap; +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.core.Children; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.core.Node; -import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.trasnformer.EditableChildren; -import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.trasnformer.EditableNode; -import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.DefaultEither; -import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Either; -import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Error; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.IterableWrapper; -public class DefaultChildren implements EditableChildren<DefaultNode> +public class DefaultChildren implements Children<Node> { private final List<DefaultNode> children; - private final TreeMap<String,ByteBuffer> attrs; - public DefaultChildren(List<DefaultNode> _children,TreeMap<String,ByteBuffer> _attrs) + public DefaultChildren(List<DefaultNode> _children) { children = _children; - attrs = _attrs; } + /* public Either<Error,DefaultNode> replaceNode(DefaultNode _target,int _pos) { if(check(_pos)){ @@ -38,6 +31,7 @@ DefaultNode newNode = new DefaultNode(newList,attrs); return DefaultEither.newB(newNode); } + */ @Override public int size() @@ -45,7 +39,8 @@ return children.length(); } - @Override + /* + public Either<Error,DefaultNode> addNewChildAt(int _pos) { if(!check(_pos)){ @@ -59,7 +54,6 @@ return DefaultEither.newB(newNode); } - @Override public Either<Error,DefaultNode> deleteChildAt(int _pos) { if(!check(_pos)){ @@ -74,13 +68,11 @@ return DefaultEither.newB(newNode); } - public boolean check(int _pos) + */ + + public List<DefaultNode> getChildrenAsRawList() { - if(children.length() < _pos){ - return false; - } - - return true; + return children; } @Override
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/store/impl/DefaultNode.java Sat Jan 26 18:41:25 2013 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/store/impl/DefaultNode.java Sat Jan 26 22:52:32 2013 +0900 @@ -1,15 +1,12 @@ package jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl; import java.nio.ByteBuffer; -import java.util.Iterator; import fj.Ord; import fj.data.List; import fj.data.TreeMap; -import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.trasnformer.EditableNode; -import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.traverser.TraversableChildren; -import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.traverser.TraversableNode; +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.core.Node; -public class DefaultNode implements EditableNode<DefaultNode> , TraversableNode<DefaultNode> +public class DefaultNode implements Node { public List<DefaultNode> children; public TreeMap<String,ByteBuffer> attrs; @@ -36,30 +33,12 @@ @Override public DefaultChildren getChildren() { - return new DefaultChildren(children,attrs); + return new DefaultChildren(children); } @Override public DefaultAttributes getAttributes() { - return new DefaultAttributes(children,attrs); - } - - @Override - public TraversableChildren<DefaultNode> children() - { - return new TraversableChildren<DefaultNode>(){ - @Override - public Iterator<DefaultNode> iterator() - { - return children.iterator(); - } - - @Override - public int size() - { - return children.length(); - } - }; + return new DefaultAttributes(attrs); } }
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/store/impl/DefaultTreeEditor.java Sat Jan 26 18:41:25 2013 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/store/impl/DefaultTreeEditor.java Sat Jan 26 22:52:32 2013 +0900 @@ -1,19 +1,12 @@ package jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl; import java.nio.ByteBuffer; -import java.util.Iterator; import fj.data.List; -import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.core.Node; -import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.persistent.ChangeListWriter; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.NodePath; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.TreeEditor; -import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.TreeEditorError; -import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.logger.Logger; -import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.logger.LoggingNode; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.trasnformer.AppendChildAt; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.trasnformer.DeleteAttribute; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.trasnformer.DeleteChildAt; -import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.trasnformer.EditableNode; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.trasnformer.NodeEditor; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.trasnformer.PutAttribute; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.traverser.DefaultEvaluator; @@ -24,7 +17,7 @@ import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Either; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Error; -public class DefaultTreeEditor<T extends EditableNode<T>> +public class DefaultTreeEditor<T extends ClonableNode<T>> implements TreeEditor { private final T root; @@ -69,63 +62,57 @@ public Either<Error,TreeEditor> edit(NodePath _path,NodeEditor _editor) { DefaultEvaluator e = new DefaultEvaluator(_path); + TraversableNodeWrapper<T> wrap = new TraversableNodeWrapper<T>(root); + Either<Error, Traversal<TraversableNodeWrapper<T>>> either = traverser.traverse(wrap,e); - Either<Error,Traversal<T>> either = traverser.traverse(root,e); if(either.isA()){ return DefaultEither.newA(either.a()); } - Traversal<DefaultNode> t = either.b(); + Traversal<TraversableNodeWrapper<T>> t = either.b(); Either<Error,TreeEditor> ret = clone(t,_editor); return ret; } - private Either<Error,TreeEditor> clone(Traversal<DefaultNode> _t,NodeEditor _editor) + private Either<Error,TreeEditor> clone(Traversal<TraversableNodeWrapper<T>> _t,NodeEditor _editor) { // copying nodes from bottom to root - List<Direction<DefaultNode>> path = List.nil(); - for(Direction<DefaultNode> direction : _t){ + List<Direction<TraversableNodeWrapper<T>>> path = List.nil(); + for(Direction<TraversableNodeWrapper<T>> direction : _t){ path = path.cons(direction); } // target - Direction<DefaultNode> targetDirection = path.head(); - Either<Error,LoggingNode<DefaultNode>> either = _editor.edit(new LoggingNode<DefaultNode>(targetDirection.getTarget())); + Direction<TraversableNodeWrapper<T>> targetDirection = path.head(); + T target = targetDirection.getTarget().getWrapped(); + Either<Error,T> either = _editor.edit(target); if(either.isA()){ return DefaultEither.newA(either.a()); } - LoggingNode<DefaultNode> loggingNode = either.b(); - Logger logger = loggingNode.getLogger(); - DefaultNode newNode = loggingNode.getWrapper(); + T newNode = either.b(); // top int pos = targetDirection.getPosition(); - DefaultNode child = newNode; - for(Direction<DefaultNode> parentDirection : path.tail()){ - DefaultNode parent = parentDirection.getTarget(); - DefaultChildren chs = parent.getChildren(); - Either<Error,DefaultNode> ret = chs.replaceNode(child,pos); + T child = newNode; + for(Direction<TraversableNodeWrapper<T>> parentDirection : path.tail()){ + TraversableNodeWrapper<T> parent = parentDirection.getTarget(); + ClonableChildren<T> chs = parent.getWrapped().getChildren(); + + Either<Error,T> ret = chs.replaceNode(pos,child); if(ret.isA()){ return DefaultEither.newA(ret.a()); } - DefaultNode newParent = ret.b(); + T newParent = ret.b(); child = newParent; pos = parentDirection.getPosition(); } - DefaultNode newRoot = child; - TreeEditor newEditor = new DefaultModifiedTreeEditor(logger); + T newRoot = child; + TreeEditor newEditor = new DefaultTreeEditor<T>(newRoot,traverser); return DefaultEither.newB(newEditor); } - - protected Either<Error,TreeEditor> newEditor(Logger _logger,DefaultNode _newRoot) - { - List<Logger> logs = List.list(_logger); - TreeEditor newEditor = null; - return DefaultEither.newB(_theB); - } } \ No newline at end of file
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/store/impl/TraversableNodeWrapper.java Sat Jan 26 18:41:25 2013 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/store/impl/TraversableNodeWrapper.java Sat Jan 26 22:52:32 2013 +0900 @@ -16,6 +16,11 @@ { wrap = _wrap; } + + public T getWrapped() + { + return wrap; + } @Override public Children<TraversableNodeWrapper<T>> getChildren()
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/store/impl/logger/LoggingAttributes.java Sat Jan 26 18:41:25 2013 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/store/impl/logger/LoggingAttributes.java Sat Jan 26 22:52:32 2013 +0900 @@ -1,6 +1,9 @@ package jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.logger; import java.nio.ByteBuffer; + +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.ClonableAttributes; +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.ClonableNode; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.operations.DeleteAttributeOperation; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.operations.Operation; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.operations.SetAttributeOperation; @@ -10,8 +13,8 @@ import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Either; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Error; -public class LoggingAttributes<T extends EditableNode<T>> - implements EditableAttributes<LoggingNode<T>> +public class LoggingAttributes<T extends ClonableNode<T>> + implements ClonableAttributes<LoggingNode<T>> { private final EditableAttributes<T> wrap; private final Logger log;
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/store/impl/logger/LoggingChildren.java Sat Jan 26 18:41:25 2013 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/store/impl/logger/LoggingChildren.java Sat Jan 26 22:52:32 2013 +0900 @@ -1,22 +1,22 @@ package jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.logger; import java.util.Iterator; +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.ClonableChildren; +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.ClonableNode; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.operations.AppendChildAtOperation; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.operations.DeleteChildAtOperation; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.operations.Operation; -import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.trasnformer.EditableChildren; -import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.trasnformer.EditableNode; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.DefaultEither; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Either; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Error; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.IterableConverter; -public class LoggingChildren<T extends EditableNode<T>> implements EditableChildren<LoggingNode<T>> +public class LoggingChildren<T extends ClonableNode<T>> implements ClonableChildren<LoggingNode<T>> { - private final EditableChildren<T> wrap; + private final ClonableChildren<T> wrap; private final Logger log; - public LoggingChildren(EditableChildren<T> _wrap,Logger _log) + public LoggingChildren(ClonableChildren<T> _wrap,Logger _log) { wrap = _wrap; log = _log; @@ -84,4 +84,17 @@ return DefaultEither.newB(newLoggingNode); } + + @Override + public Either<Error,LoggingNode<T>> replaceNode(int _pos,LoggingNode<T> _replacement) + { + T target = _replacement.getWrapper(); + Either<Error,T> e = wrap.replaceNode(_pos,target); + if(e.isA()){ + return DefaultEither.newA(e.a()); + } + + T newWrap = e.b(); + return DefaultEither.newB(new LoggingNode<T>(newWrap,log)); + } }
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/store/impl/logger/LoggingNode.java Sat Jan 26 18:41:25 2013 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/store/impl/logger/LoggingNode.java Sat Jan 26 22:52:32 2013 +0900 @@ -1,11 +1,14 @@ package jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.logger; +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.ClonableAttributes; +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.ClonableChildren; +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.ClonableNode; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.trasnformer.EditableAttributes; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.trasnformer.EditableChildren; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.trasnformer.EditableNode; -public class LoggingNode<T extends EditableNode<T>> - implements EditableNode<LoggingNode<T>> +public class LoggingNode<T extends ClonableNode<T>> + implements ClonableNode<LoggingNode<T>> { public LoggingNode(T _wrap) { @@ -22,13 +25,13 @@ private final Logger log; @Override - public EditableAttributes<LoggingNode<T>> getAttributes() + public ClonableAttributes<LoggingNode<T>> getAttributes() { return new LoggingAttributes<T>(wrap.getAttributes(),log); } @Override - public EditableChildren<LoggingNode<T>> getChildren() + public ClonableChildren<LoggingNode<T>> getChildren() { return new LoggingChildren<T>(wrap.getChildren(),log); }
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/transaction/ClonableDefaultAttributes.java Sat Jan 26 22:52:32 2013 +0900 @@ -0,0 +1,56 @@ +package jp.ac.u_ryukyu.ie.cr.shoshi.jungle.transaction; + +import java.nio.ByteBuffer; + +import fj.data.TreeMap; +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.DefaultAttributes; +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.ClonableAttributes; +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.DefaultChildren; +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.DefaultNode; +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.DefaultEither; +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Either; +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Error; + +public class ClonableDefaultAttributes implements ClonableAttributes<ClonableDefaultNode> +{ + private final DefaultNode wrap; + + public ClonableDefaultAttributes(DefaultNode _wrap) + { + wrap = _wrap; + } + + @Override + public Either<Error,ClonableDefaultNode> delete(String _key) + { + DefaultAttributes attrs = wrap.getAttributes(); + DefaultChildren children = wrap.getChildren(); + + TreeMap<String,ByteBuffer> raw = attrs.getAttributesAsRawMap(); + TreeMap<String,ByteBuffer> newMap = raw.delete(_key); + + DefaultNode newNode = new DefaultNode(children.getChildrenAsRawList(),newMap); + + return DefaultEither.newB(new ClonableDefaultNode(newNode)); + } + + @Override + public Either<Error, ClonableDefaultNode> put(String _key, ByteBuffer _value) + { + DefaultAttributes attrs = wrap.getAttributes(); + DefaultChildren children = wrap.getChildren(); + + TreeMap<String,ByteBuffer> raw = attrs.getAttributesAsRawMap(); + TreeMap<String,ByteBuffer> newMap = raw.set(_key,_value); + + DefaultNode newNode = new DefaultNode(children.getChildrenAsRawList(),newMap); + + return DefaultEither.newB(new ClonableDefaultNode(newNode)); + } + + @Override + public ByteBuffer get(String _key) + { + return wrap.getAttributes().get(_key); + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/transaction/ClonableDefaultChildren.java Sat Jan 26 22:52:32 2013 +0900 @@ -0,0 +1,108 @@ +package jp.ac.u_ryukyu.ie.cr.shoshi.jungle.transaction; + +import java.nio.ByteBuffer; +import java.util.Iterator; +import fj.P2; +import fj.data.List; +import fj.data.TreeMap; + +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.ClonableChildren; +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.DefaultAttributes; +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.DefaultChildren; +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.DefaultNode; +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.trasnformer.NodeEditorError; +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.DefaultEither; +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Either; +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Error; +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.IterableConverter; + +public class ClonableDefaultChildren implements ClonableChildren<ClonableDefaultNode> +{ + private final DefaultNode node; + + public ClonableDefaultChildren(DefaultNode _node) + { + node = _node; + } + + private boolean boundaryCheck(int _pos) + { + int size = node.getChildren().size(); + if(size <= _pos){ + return false; + } + + return true; + } + + @Override + public Either<Error,ClonableDefaultNode> addNewChildAt(int _pos) + { + if(!boundaryCheck(_pos)){ + return DefaultEither.newA(NodeEditorError.INDEX_OUT_OF_BOUNDS); + } + + DefaultChildren children = node.getChildren(); + DefaultAttributes attrs = node.getAttributes(); + + List<DefaultNode> raw = children.getChildrenAsRawList(); + + P2<List<DefaultNode>,List<DefaultNode>> split = raw.splitAt(_pos); + List<DefaultNode> newChildren = split._1().snoc(new DefaultNode()).append(split._2()); + DefaultNode newNode = new DefaultNode(newChildren,attrs.getAttributesAsRawMap()); + + return DefaultEither.newB(new ClonableDefaultNode(newNode)); + } + + @Override + public Either<Error,ClonableDefaultNode> deleteChildAt(int _pos) + { + if(!boundaryCheck(_pos)){ + return DefaultEither.newA(NodeEditorError.INDEX_OUT_OF_BOUNDS); + } + + DefaultChildren chs = node.getChildren(); + List<DefaultNode> raw = chs.getChildrenAsRawList(); + + P2<List<DefaultNode>,List<DefaultNode>> split = raw.splitAt(_pos); + List<DefaultNode> newChildren = split._1().init().append(split._2()); + + DefaultAttributes attrs = node.getAttributes(); + TreeMap<String, ByteBuffer> map = attrs.getAttributesAsRawMap(); + + DefaultNode newNode = new DefaultNode(newChildren,map); + + return DefaultEither.newB(new ClonableDefaultNode(newNode)); + } + + @Override + public int size() + { + return node.getChildren().size(); + } + + @Override + public Iterator<ClonableDefaultNode> iterator() + { + IterableConverter.Converter<ClonableDefaultNode,DefaultNode> converter = new IterableConverter.Converter<ClonableDefaultNode,DefaultNode>(){ + @Override + public ClonableDefaultNode conv(DefaultNode _b) + { + return new ClonableDefaultNode(_b); + } + }; + + List<DefaultNode> raw = node.getChildren().getChildrenAsRawList(); + return new IterableConverter<ClonableDefaultNode,DefaultNode>(raw,converter).iterator(); + } + + @Override + public Either<Error,ClonableDefaultNode> replaceNode(int _pos,ClonableDefaultNode _replacement) + { + if(!boundaryCheck(_pos)){ + return DefaultEither.newA(NodeEditorError.INDEX_OUT_OF_BOUNDS); + } + + return null; + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/transaction/ClonableDefaultNode.java Sat Jan 26 22:52:32 2013 +0900 @@ -0,0 +1,28 @@ +package jp.ac.u_ryukyu.ie.cr.shoshi.jungle.transaction; + +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.ClonableAttributes; +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.ClonableChildren; +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.ClonableNode; +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.DefaultNode; + +public class ClonableDefaultNode implements ClonableNode<ClonableDefaultNode> +{ + private final DefaultNode wrap; + + public ClonableDefaultNode(DefaultNode _wrap) + { + wrap = _wrap; + } + + @Override + public ClonableChildren<ClonableDefaultNode> getChildren() + { + return new ClonableDefaultChildren(wrap); + } + + @Override + public ClonableAttributes<ClonableDefaultNode> getAttributes() + { + return new ClonableDefaultAttributes(wrap); + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/transaction/DefaultJungleTreeEditor.java Sat Jan 26 22:52:32 2013 +0900 @@ -0,0 +1,66 @@ +package jp.ac.u_ryukyu.ie.cr.shoshi.jungle.transaction; + +import java.nio.ByteBuffer; + +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.JungleTree; +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.JungleTreeEditor; +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.NodePath; +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.TreeEditor; +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.DefaultNode; +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.DefaultTreeEditor; +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.logger.LoggingNode; +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.trasnformer.NodeEditor; +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Either; +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Error; + +public class DefaultJungleTreeEditor implements JungleTreeEditor +{ + private final TransactionManager txManager; + private final DefaultNode root; + private final DefaultTreeEditor<LoggingNode<ClonableDefaultNode>> editor; + + public DefaultJungleTreeEditor(DefaultNode _root,TransactionManager _txManager) + { + root = _root; + txManager = _txManager; + } + + @Override + public Either<Error,JungleTreeEditor> appendChild(NodePath _path, int _pos) + { + + + return null; + } + + @Override + public Either<Error,TreeEditor> deleteChild(NodePath _path, int _pos) + { + return null; + } + + @Override + public Either<Error,TreeEditor> putAttribute(NodePath _path,String _key,ByteBuffer _value) + { + return null; + } + + @Override + public Either<Error, TreeEditor> deleteAttribute(NodePath _path, String _key) + { + return null; + } + + @Override + public Either<Error,TreeEditor> edit(NodePath _path,NodeEditor _transformer) + { + return null; + } + + @Override + public Either<Error,JungleTree> success() + { + return null; + } + +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/transaction/TransactionManager.java Sat Jan 26 22:52:32 2013 +0900 @@ -0,0 +1,8 @@ +package jp.ac.u_ryukyu.ie.cr.shoshi.jungle.transaction; + +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.ChangeSet; + +public interface TransactionManager +{ + public boolean commit(ChangeSet _ch); +}