# HG changeset patch # User Shoshi TAMAKI # Date 1360055951 -32400 # Node ID e7d94437ca2fec73d05aa54d7f20fd01fb48e939 # Parent fb00d7b147c8c8df3cc2c50cd379b1a4483acad6 added sample diff -r fb00d7b147c8 -r e7d94437ca2f src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/DefaultJungle.java --- 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; } } diff -r fb00d7b147c8 -r e7d94437ca2f src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/core/App.java --- 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 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); } } diff -r fb00d7b147c8 -r e7d94437ca2f src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/transaction/DefaultJungleTreeEditor.java --- 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 _loggingNode,TransactionManager _txManager,Traverser _traverser) + { + root = _loggingNode.getWrapper().getWrapped(); + txManager = _txManager; + editor = new DefaultTreeEditor>(_loggingNode,_traverser); + traverser = _traverser; + } + @Override public Either appendChild(NodePath _path, int _pos) { @@ -43,7 +51,7 @@ DefaultTreeEditor> 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> 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> 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