diff src/main/csharp/jp.ac.u-ryukyu.ie.cr/jungle-main/transaction/DefaultTransactionManager.cs @ 17:01a08cf4b2d9

Liq Files
author Kazuma
date Mon, 07 Nov 2016 01:05:24 +0900
parents abe0c247f5a5
children
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/main/csharp/jp.ac.u-ryukyu.ie.cr/jungle-main/transaction/DefaultTransactionManager.cs	Mon Nov 07 01:05:24 2016 +0900
@@ -0,0 +1,94 @@
+using System.Collections.Generic;
+using System.Collections;
+using System;
+
+public class DefaultTransactionManager : TransactionManager {
+	private AtomicReference<TreeContext> repository;
+	private TreeContext tip;
+	private ChangeListWriter writer;
+	private string uuid;
+
+
+	public DefaultTransactionManager(ChangeListWriter _writer, TreeContext _tip, AtomicReference<TreeContext> _repository, string _uuid) {
+		repository = _repository;
+		tip = _tip;
+		writer = _writer;
+		uuid = _uuid;
+	}
+
+	public Either<Error, TransactionManager> commit(TreeNode newRoot, TreeOperationLog _log) {
+		long currentRevision = tip.getRevision();
+		long nextRevision = currentRevision + 1;
+
+		string _treeName = tip.getTreeName();
+		// 通信時に必要?
+		ChangeList list = new InnerChangeList(_log, _treeName, uuid);
+
+		InterfaceTraverser traverser = new InterfaceTraverser(newRoot, true);
+		// traverser.createIndex();
+		TreeContext newTreeContext = new DefaultTreeContext(newRoot , tip, list, uuid, _treeName, nextRevision,traverser);
+		// compare and setがどういう役割か?Javaで
+		if  (repository.CompareAndSet(newTreeContext, newTreeContext.prev())) { // CompareAndSetが成功した場合に処理を実行
+			TransactionManager txManager = new DefaultTransactionManager(writer, newTreeContext, repository, uuid);
+			return DefaultEither<Error, TransactionManager>.newB(txManager);
+		}
+
+		return DefaultEither<Error, TransactionManager>.newA((Error) new DefaultError());
+	}
+
+	public Either<Error, TransactionManager> firstcommit(TreeNode _newRoot, TreeOperationLog _log) {
+		return commit(_newRoot,_log);
+	}
+
+	public string getUUID() {
+		return uuid;
+	}
+
+	public long getRevision() {
+		return tip.getRevision();
+	}
+
+	public class InnerChangeList : ChangeList{
+
+		TreeOperationLog log;
+		string treeName;
+		string uuid;
+
+
+		IEnumerator IEnumerable.GetEnumerator()
+		{
+			// call the generic version of the method
+			return this.GetEnumerator();
+		}
+
+		public IEnumerator<TreeOperation> GetEnumerator()
+		{
+			return iterator ();
+		}
+
+
+		public InnerChangeList(TreeOperationLog _log, string _treeName, string _uuid){
+			this.log = _log;
+			this.treeName = _treeName;
+			this.uuid = _uuid;
+		}
+
+		public IEnumerator<TreeOperation> iterator() {
+			return log.GetEnumerator();
+		}
+
+		public string getTreeName() {
+			return treeName;
+		}
+
+		public TreeOperationLog getLog() {
+			return log;
+		}
+
+		public string uuids() {
+			return uuid;
+		}
+	}
+
+}
+	
\ No newline at end of file