Mercurial > hg > Database > jungle-sharp
view Main/jungle-network/transaction/NetworkTransactionManager.cs @ 20:1f99e150f336
fix folder and add Object Mapper.
author | Kazuma Takeda |
---|---|
date | Thu, 15 Dec 2016 22:52:48 +0900 |
parents | |
children | f2ea780b3e80 |
line wrap: on
line source
using UnityEngine; using System.Collections; using System.Collections.Generic; namespace JungleDB { public class NetworkTransactionManager : TransactionManager { private readonly AtomicReference<TreeContext> Repository; private readonly TreeContext TContext; private readonly ChangeListWriter Writer; private readonly string Uuid; private readonly string TreeName; public NetworkTransactionManager (string name, ChangeListWriter writer, TreeContext tcon, AtomicReference<TreeContext> repo, string uid) { this.Repository = repo; this.TContext = tcon; this.Writer = writer; this.Uuid = uid; this.TreeName = name; } public Either<Error, TransactionManager> commit (TreeNode newRoot, TreeOperationLog log) { long currentRevision = this.TContext.getRevision(); long nextRevision = currentRevision + 1; ChangeList list = new InnerChangeList(this.Uuid, this.TreeName); InterfaceTraverser traverser = new InterfaceTraverser(newRoot, true); // not create index. TreeContext newTreeContext = new DefaultTreeContext(newRoot, this.TContext, list, this.Uuid, this.TreeName, nextRevision, traverser); if (this.Repository.CompareAndSet(newTreeContext.prev(), newTreeContext)) { TransactionManager txmanager = new NetworkTransactionManager(this.TreeName, this.Writer, newTreeContext, this.Repository, this.Uuid); return DefaultEither<Error, TransactionManager>.newB(txmanager); } return DefaultEither<Error, TransactionManager>.newA((Error) new DefaultError()); } public long getRevision () { return this.TContext.getRevision(); } public string getUUID () { return this.Uuid; } public Either<Error, TransactionManager> firstcommit(TreeNode _newRoot, TreeOperationLog _log) { return null; } public class InnerChangeList : ChangeList { string uuid; string name; IEnumerator IEnumerable.GetEnumerator() { return this.GetEnumerator(); } public IEnumerator<TreeOperation> GetEnumerator() { return iterator (); } // construct public InnerChangeList(string _uuid, string _name) { this.uuid = _uuid; this.name = _name; } public IEnumerator<TreeOperation> iterator() { List<TreeOperation> nil = new List<TreeOperation>(); return nil.iterator(); } public string uuids() { return uuid; } public string getTreeName() { return name; } public TreeOperationLog getLog() { return new DefaultTreeOperationLog(); } } } }