Mercurial > hg > Members > kazuma > jungle-ormapper
comparison src/main/java/jp/ac/u_ryukyu/ie/cr/jungle/store/impl/logger/LoggingAttributes.java @ 0:44465893e8b8
first Commit
author | Kazuma |
---|---|
date | Wed, 30 Nov 2016 01:47:55 +0900 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:44465893e8b8 |
---|---|
1 package jp.ac.u_ryukyu.ie.cr.jungle.store.impl.logger; | |
2 | |
3 import jp.ac.u_ryukyu.ie.cr.jungle.store.impl.TreeNode; | |
4 import jp.ac.u_ryukyu.ie.cr.jungle.store.impl.TreeNodeAttributes; | |
5 import jp.ac.u_ryukyu.ie.cr.jungle.store.operations.DeleteAttributeOperation; | |
6 import jp.ac.u_ryukyu.ie.cr.jungle.store.operations.NodeOperation; | |
7 import jp.ac.u_ryukyu.ie.cr.jungle.store.operations.PutAttributeOperation; | |
8 import jp.ac.u_ryukyu.ie.cr.jungle.util.DefaultEither; | |
9 import jp.ac.u_ryukyu.ie.cr.jungle.util.Either; | |
10 import jp.ac.u_ryukyu.ie.cr.jungle.util.Error; | |
11 | |
12 import java.nio.ByteBuffer; | |
13 | |
14 public class LoggingAttributes //implements EditableAttributes | |
15 { | |
16 private final TreeNode wrap; | |
17 private final OperationLog log; | |
18 | |
19 public LoggingAttributes(TreeNode _wrap,OperationLog _log) | |
20 { | |
21 wrap = _wrap; | |
22 log = _log; | |
23 } | |
24 | |
25 public ByteBuffer get(String _key) | |
26 { | |
27 TreeNodeAttributes attributes = wrap.getAttributes(); | |
28 return attributes.get(_key); | |
29 } | |
30 | |
31 private Either<Error,LoggingNode> edit(NodeOperation _op) | |
32 { | |
33 Either<Error,TreeNode> either = _op.invoke(wrap); | |
34 if(either.isA()){ | |
35 return DefaultEither.newA(either.a()); | |
36 } | |
37 | |
38 TreeNode newNode = either.b(); | |
39 OperationLog newLog = log.add(_op); | |
40 LoggingNode newLogNode = new LoggingNode(newNode,newLog); | |
41 | |
42 return DefaultEither.newB(newLogNode); | |
43 } | |
44 | |
45 public Either<Error,LoggingNode> delete(final String _key) | |
46 { | |
47 | |
48 DeleteAttributeOperation deleteAttribute = new DeleteAttributeOperation(_key); | |
49 return edit(deleteAttribute); | |
50 } | |
51 | |
52 public Either<Error,LoggingNode> put(final String _key,final ByteBuffer _value) | |
53 { | |
54 PutAttributeOperation putAttribute = new PutAttributeOperation(_key,_value); | |
55 return edit(putAttribute); | |
56 } | |
57 } |