changeset 20:b3aaff7d9500

fit junglecore
author one
date Fri, 12 Sep 2014 16:26:08 +0900
parents 8e44d61b8a65
children 397d4194e746
files src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/bbs/JungleBulletinBoard.java
diffstat 1 files changed, 45 insertions(+), 15 deletions(-) [+]
line wrap: on
line diff
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/bbs/JungleBulletinBoard.java	Thu Sep 04 13:11:50 2014 +0900
+++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/bbs/JungleBulletinBoard.java	Fri Sep 12 16:26:08 2014 +0900
@@ -12,6 +12,7 @@
 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.DefaultTreeEditor;
 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.TreeNode;
 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.logger.DefaultOperationLog;
+import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.logger.LoggingNode;
 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.logger.OperationLog;
 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.operations.PutAttributeOperation;
 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.trasnformer.NodeEditor;
@@ -20,6 +21,8 @@
 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Either;
 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Error;
 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.IterableConverter;
+import jp.ac.u_ryukyu.ie.cr.tatsuki.jungle.store.index.Logging;
+import jp.ac.u_ryukyu.ie.cr.tatsuki.jungle.store.index.LoggingIndexNode;
 
 public class JungleBulletinBoard implements
 		BulletinBoard {
@@ -53,7 +56,7 @@
 		}
 
 		JungleTree tree = jungle.getTreeByName("boards");
-		JungleTreeEditor editor = tree.getTreeEditor();
+		JungleTreeEditor editor = tree.getIndexTreeEditor();
 		DefaultNodePath root = new DefaultNodePath();
 		Either<Error, JungleTreeEditor> either = editor.addNewChildAt(root, 0);
 		if (either.isA()) {
@@ -61,8 +64,7 @@
 		}
 		editor = either.b();
 
-		either = editor.putAttribute(root.add(0), "name",
-				ByteBuffer.wrap(_name.getBytes()));
+		either = editor.putAttribute(root.add(0), "name", ByteBuffer.wrap(_name.getBytes()));
 		if (either.isA()) {
 			throw new IllegalStateException();
 		}
@@ -73,26 +75,33 @@
 		}
 
 		tree = jungle.getTreeByName(_name);
-		editor = tree.getTreeEditor();
+		editor = tree.getIndexTreeEditor();
 		either = editor.addNewChildAt(root, 0);
 		if (either.isA()) {
 			throw new IllegalStateException();
 		}
 		editor = either.b();
 
-		NodeEditor e = new NodeEditor() {
+	/*	NodeEditor e = new NodeEditor() {
 
-			public Either<Error, TreeNode> edit(TreeNode node) {
+			public Either<Error, Logging> edit(TreeNode node) {
 				node = node.getAttributes().put("author", ByteBuffer.wrap(_author.getBytes())).b();
 				node = node.getAttributes().put("mes", ByteBuffer.wrap(_initMessage.getBytes())).b();
 				node = node.getAttributes().put("key", ByteBuffer.wrap(_editKey.getBytes())).b();
 				System.out.println(node.getAttributes().get("mes"));
 				return DefaultEither.newB(node);
 			}
+
+			public Logging wrap(TreeNode node, OperationLog op) {
+				return new LoggingIndexNode(node ,op, null);
+			}
 			
-		};
-
-		either = editor.edit(root.add(0), e);
+		};*/
+		
+		editor = editor.putAttribute(root.add(0),"author", ByteBuffer.wrap(_author.getBytes())).b();
+		editor = editor.putAttribute(root.add(0),"key", ByteBuffer.wrap(_editKey.getBytes())).b();
+		either = editor.putAttribute(root.add(0),"mes", ByteBuffer.wrap(_initMessage.getBytes()));
+		
 		if (either.isA()) {
 			throw new IllegalStateException();
 		}
@@ -121,8 +130,8 @@
 			}
 			editor = either.b();
 
-			NodeEditor e = new NodeEditor() {
-				public Either<Error, TreeNode> edit(TreeNode node) {
+			/*NodeEditor e = new NodeEditor() {
+				public Either<Error, LoggingNode> edit(LoggingNode node) {
 					node = node.getAttributes().put("author", ByteBuffer.wrap(_author.getBytes())).b();
 					node = node.getAttributes().put("mes", ByteBuffer.wrap(_message.getBytes())).b();
 					node = node.getAttributes().put("key", ByteBuffer.wrap(_editKey.getBytes())).b();
@@ -133,11 +142,22 @@
 
 			path = path.add(size);
 			either = editor.edit(path, e);
+			
 			if (either.isA()) {
 				throw new IllegalStateException();
 			}
 			editor = either.b();
-		} while (editor.success().isA());
+		} while (editor.success().isA());*/
+			
+			editor = editor.putAttribute(path.add(0),"author", ByteBuffer.wrap(_author.getBytes())).b();
+			editor = editor.putAttribute(path.add(0),"key", ByteBuffer.wrap(_editKey.getBytes())).b();
+			either = editor.putAttribute(path.add(0),"mes", ByteBuffer.wrap(_message.getBytes()));
+			
+			if (either.isA()) {
+				throw new IllegalStateException();
+			}
+			editor = either.b();
+		}while (editor.success().isA());
 	}
 
 	public void editMessage(String _board, String _uuid, final String _author,
@@ -149,9 +169,9 @@
 
 			JungleTree tree = jungle.getTreeByName(_board);
 			editor = tree.getTreeEditor();
-			NodeEditor e = new NodeEditor() {
+			/*NodeEditor e = new NodeEditor() {
 
-				public Either<Error, TreeNode> edit(TreeNode node) {
+				public Either<Error, LoggingNode> edit(LoggingNode node) {
 					node = node.getAttributes().put("author", ByteBuffer.wrap(_author.getBytes())).b();
 					node = node.getAttributes().put("mes", ByteBuffer.wrap(_message.getBytes())).b();
 					node = node.getAttributes().put("key", ByteBuffer.wrap(_editKey.getBytes())).b();
@@ -165,7 +185,17 @@
 				throw new IllegalStateException();
 			}
 			editor = either.b();
-		} while (editor.success().isA());
+		} while (editor.success().isA());*/
+			
+			editor = editor.putAttribute(path.add(0),"author", ByteBuffer.wrap(_author.getBytes())).b();
+			editor = editor.putAttribute(path.add(0),"key", ByteBuffer.wrap(_editKey.getBytes())).b();
+			Either<Error, JungleTreeEditor> either = editor.putAttribute(path.add(0),"mes", ByteBuffer.wrap(_message.getBytes()));
+			
+			if (either.isA()) {
+				throw new IllegalStateException();
+			}
+			editor = either.b();
+		}while (editor.success().isA());
 	}
 
 	public Iterable<BoardMessage> getMessages(String _boardName) {