diff Main/jungle-main/transaction/DefaultTransactionManager.cs @ 20:1f99e150f336

fix folder and add Object Mapper.
author Kazuma Takeda
date Thu, 15 Dec 2016 22:52:48 +0900
parents
children
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Main/jungle-main/transaction/DefaultTransactionManager.cs	Thu Dec 15 22:52:48 2016 +0900
@@ -0,0 +1,94 @@
+using System.Collections.Generic;
+using System.Collections;
+using System;
+
+namespace JungleDB {
+	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