Mercurial > hg > Members > tatsuki > bench > jungle-core
changeset 46:e7d94437ca2f
added sample
author | Shoshi TAMAKI |
---|---|
date | Tue, 05 Feb 2013 18:19:11 +0900 |
parents | fb00d7b147c8 |
children | 22d8966ab672 |
files | src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/DefaultJungle.java src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/core/App.java src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/transaction/DefaultJungleTreeEditor.java |
diffstat | 3 files changed, 39 insertions(+), 4 deletions(-) [+] |
line wrap: on
line diff
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/DefaultJungle.java Tue Feb 05 02:04:34 2013 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/DefaultJungle.java Tue Feb 05 18:19:11 2013 +0900 @@ -44,6 +44,9 @@ DefaultNode node = new DefaultNode(); DefaultChangeSet set = new DefaultChangeSet(node,null,list,uuid,0); DefaultJungleTree newTree = new DefaultJungleTree(set,uuid,journal.getWriter()); + if(trees.putIfAbsent(_name,newTree) != null){ + return null; + } return newTree; } }
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/core/App.java Tue Feb 05 02:04:34 2013 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/core/App.java Tue Feb 05 18:19:11 2013 +0900 @@ -1,5 +1,13 @@ package jp.ac.u_ryukyu.ie.cr.shoshi.jungle.core; +import java.nio.ByteBuffer; + +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.DefaultJungle; +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.impl.DefaultNodePath; +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Either; + /** * Hello world! * @@ -8,6 +16,22 @@ { public static void main( String[] args ) { - System.out.println( "Hello World!" ); + DefaultJungle jungle = new DefaultJungle("sample"); + jungle.createNewTree("hoge"); + JungleTree tree = jungle.getTreeByName("hoge"); + JungleTreeEditor editor = tree.getTreeEditor(); + DefaultNodePath path = new DefaultNodePath(); + + String key = "key"; + ByteBuffer value = ByteBuffer.wrap(key.getBytes()); + + Either<Error,JungleTreeEditor> either = editor.putAttribute(path,"key",value); + JungleTreeEditor e = either.b(); + e.success(); + + Node root = tree.getRootNode(); + ByteBuffer v = root.getAttributes().get(key); + String str = new String(v.array()); + System.out.println(str); } }
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/transaction/DefaultJungleTreeEditor.java Tue Feb 05 02:04:34 2013 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/transaction/DefaultJungleTreeEditor.java Tue Feb 05 18:19:11 2013 +0900 @@ -32,6 +32,14 @@ traverser = _traverser; } + public DefaultJungleTreeEditor(LoggingNode<ClonableDefaultNode> _loggingNode,TransactionManager _txManager,Traverser _traverser) + { + root = _loggingNode.getWrapper().getWrapped(); + txManager = _txManager; + editor = new DefaultTreeEditor<LoggingNode<ClonableDefaultNode>>(_loggingNode,_traverser); + traverser = _traverser; + } + @Override public Either<Error,DefaultJungleTreeEditor> appendChild(NodePath _path, int _pos) { @@ -43,7 +51,7 @@ DefaultTreeEditor<LoggingNode<ClonableDefaultNode>> newTreeEditor = either.b(); DefaultNode newRoot = newTreeEditor.getRootNode().getWrapper().getWrapped(); - return DefaultEither.newB(new DefaultJungleTreeEditor(newRoot,txManager,traverser)); + return DefaultEither.newB(new DefaultJungleTreeEditor(newTreeEditor.getRootNode(),txManager,traverser)); } @Override @@ -57,7 +65,7 @@ DefaultTreeEditor<LoggingNode<ClonableDefaultNode>> newTreeEditor = either.b(); DefaultNode newRoot = newTreeEditor.getRootNode().getWrapper().getWrapped(); - return DefaultEither.newB(new DefaultJungleTreeEditor(newRoot,txManager,traverser)); + return DefaultEither.newB(new DefaultJungleTreeEditor(newTreeEditor.getRootNode(),txManager,traverser)); } @Override @@ -71,7 +79,7 @@ DefaultTreeEditor<LoggingNode<ClonableDefaultNode>> newTreeEditor = either.b(); DefaultNode newRoot = newTreeEditor.getRootNode().getWrapper().getWrapped(); - return DefaultEither.newB(new DefaultJungleTreeEditor(newRoot,txManager,traverser)); + return DefaultEither.newB(new DefaultJungleTreeEditor(newTreeEditor.getRootNode(),txManager,traverser)); } @Override