Mercurial > hg > Database > jungle-network
changeset 8:ee93e16d5a3f
implement unconvert and convert method in DefaultTreeOperationLog class
author | one |
---|---|
date | Tue, 11 Jun 2013 05:41:07 +0900 |
parents | b7396f848d78 |
children | 49c0eaa4dce2 |
files | src/jungle/test/datasegment/store/operations/DefaultTreeOperationLogContainer.java |
diffstat | 1 files changed, 43 insertions(+), 6 deletions(-) [+] |
line wrap: on
line diff
--- a/src/jungle/test/datasegment/store/operations/DefaultTreeOperationLogContainer.java Tue Jun 11 05:33:03 2013 +0900 +++ b/src/jungle/test/datasegment/store/operations/DefaultTreeOperationLogContainer.java Tue Jun 11 05:41:07 2013 +0900 @@ -32,9 +32,49 @@ PutAttributeOperation putOp = new PutAttributeOperation(key, b); DefaultNodePath nodePath = new DefaultNodePath(); nodePath = nodePath.add(1).add(2).add(3); - TreeOperation op = new DefaultTreeOperation(nodePath, putOp); + List<TreeOperation> list = new LinkedList<TreeOperation>(); + list.add(op); + list.add(op); + list.add(op); + DefaultTreeOperationLog log = new DefaultTreeOperationLog(list, list.size()); + DefaultTreeOperationLogContainer logContainer = new DefaultTreeOperationLogContainer(); + logContainer.unconvert(log); + + TreeOperationLog convertedLog = logContainer.convert(); + for (TreeOperation treeOp : convertedLog) { + NodePath path = treeOp.getNodePath(); + NodeOperation nodeOp = treeOp.getNodeOperation(); + Command c = nodeOp.getCommand(); + String str = ""; + switch (c) { + case PUT_ATTRIBUTE: + String k = nodeOp.getKey(); + ByteBuffer value = nodeOp.getValue(); + if (value.limit() < 100) { + str = String.format("key:%s,value:%s", k, + new String(value.array())); + } else { + str = String.format("key:%s,value:%d", k, value.limit()); + } + break; + case DELETE_ATTRIBUTE: + str = String.format("key:%s", nodeOp.getKey()); + break; + case APPEND_CHILD: + str = String.format("pos:%d", nodeOp.getPosition()); + break; + case DELETE_CHILD: + str = String.format("pos:%d", nodeOp.getPosition()); + break; + } + System.out.println(String.format("[%s:%s:%s]", c, nodePath, str)); + for (int i: nodePath ) { + System.out.println(i); + } + + } } @@ -49,12 +89,9 @@ for(TreeOperation op : _log) { NodeOperation nOp = op.getNodeOperation(); NodePath nodePath = op.getNodePath(); - DefaultNodeOperationContainer nodeOpContainer = new DefaultNodeOperationContainer(); - nodeOpContainer.unconvert(nOp); - DefaultNodePathContainer nodePathContainer = new DefaultNodePathContainer(); - nodePathContainer.unconvert(nodePath); + DefaultTreeOperation treeOp = new DefaultTreeOperation(nodePath, nOp); DefaultTreeOperationContainer container = new DefaultTreeOperationContainer(); - container.unconvert(nodeOpContainer, nodePathContainer); + container.unconvert(treeOp); Value v = msgpack.unconvert(container); list.add(v); }