Mercurial > hg > Members > tatsuki > bench > jungle-core
view src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/store/impl/logger/LoggingAttributes.java @ 152:8a0aa8fc137c
Merge with a2c374a2686b82b0ad30f520412e191b84288fa9
author | one |
---|---|
date | Sat, 22 Nov 2014 15:25:09 +0900 |
parents | 0854f9a9e81d |
children |
line wrap: on
line source
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.TreeNode; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.TreeNodeAttributes; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.operations.DeleteAttributeOperation; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.operations.NodeOperation; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.operations.PutAttributeOperation; 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 LoggingAttributes //implements EditableAttributes { private final TreeNode wrap; private final OperationLog log; public LoggingAttributes(TreeNode _wrap,OperationLog _log) { wrap = _wrap; log = _log; } public ByteBuffer get(String _key) { TreeNodeAttributes attributes = wrap.getAttributes(); return attributes.get(_key); } private Either<Error,LoggingNode> edit(NodeOperation _op) { Either<Error,TreeNode> either = _op.invoke(wrap); if(either.isA()){ return DefaultEither.newA(either.a()); } TreeNode newNode = either.b(); OperationLog newLog = log.add(_op); LoggingNode newLogNode = new LoggingNode(newNode,newLog); return DefaultEither.newB(newLogNode); } public Either<Error,LoggingNode> delete(final String _key) { DeleteAttributeOperation deleteAttribute = new DeleteAttributeOperation(_key); return edit(deleteAttribute); } public Either<Error,LoggingNode> put(final String _key,final ByteBuffer _value) { PutAttributeOperation putAttribute = new PutAttributeOperation(_key,_value); return edit(putAttribute); } }