Mercurial > hg > Database > jungle-sharp
comparison 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 |
comparison
equal
deleted
inserted
replaced
19:0865819106cf | 20:1f99e150f336 |
---|---|
1 using System.Collections.Generic; | |
2 using System.Collections; | |
3 using System; | |
4 | |
5 namespace JungleDB { | |
6 public class DefaultTransactionManager : TransactionManager { | |
7 private AtomicReference<TreeContext> repository; | |
8 private TreeContext tip; | |
9 private ChangeListWriter writer; | |
10 private string uuid; | |
11 | |
12 | |
13 public DefaultTransactionManager(ChangeListWriter _writer, TreeContext _tip, AtomicReference<TreeContext> _repository, string _uuid) { | |
14 repository = _repository; | |
15 tip = _tip; | |
16 writer = _writer; | |
17 uuid = _uuid; | |
18 } | |
19 | |
20 public Either<Error, TransactionManager> commit(TreeNode newRoot, TreeOperationLog _log) { | |
21 long currentRevision = tip.getRevision(); | |
22 long nextRevision = currentRevision + 1; | |
23 | |
24 string _treeName = tip.getTreeName(); | |
25 // 通信時に必要? | |
26 ChangeList list = new InnerChangeList(_log, _treeName, uuid); | |
27 | |
28 InterfaceTraverser traverser = new InterfaceTraverser(newRoot, true); | |
29 // traverser.createIndex(); | |
30 TreeContext newTreeContext = new DefaultTreeContext(newRoot , tip, list, uuid, _treeName, nextRevision,traverser); | |
31 // compare and setがどういう役割か?Javaで | |
32 if (repository.CompareAndSet(newTreeContext, newTreeContext.prev())) { // CompareAndSetが成功した場合に処理を実行 | |
33 TransactionManager txManager = new DefaultTransactionManager(writer, newTreeContext, repository, uuid); | |
34 return DefaultEither<Error, TransactionManager>.newB(txManager); | |
35 } | |
36 | |
37 return DefaultEither<Error, TransactionManager>.newA((Error) new DefaultError()); | |
38 } | |
39 | |
40 public Either<Error, TransactionManager> firstcommit(TreeNode _newRoot, TreeOperationLog _log) { | |
41 return commit(_newRoot,_log); | |
42 } | |
43 | |
44 public string getUUID() { | |
45 return uuid; | |
46 } | |
47 | |
48 public long getRevision() { | |
49 return tip.getRevision(); | |
50 } | |
51 | |
52 public class InnerChangeList : ChangeList{ | |
53 | |
54 TreeOperationLog log; | |
55 string treeName; | |
56 string uuid; | |
57 | |
58 | |
59 IEnumerator IEnumerable.GetEnumerator() | |
60 { | |
61 // call the generic version of the method | |
62 return this.GetEnumerator(); | |
63 } | |
64 | |
65 public IEnumerator<TreeOperation> GetEnumerator() | |
66 { | |
67 return iterator (); | |
68 } | |
69 | |
70 | |
71 public InnerChangeList(TreeOperationLog _log, string _treeName, string _uuid){ | |
72 this.log = _log; | |
73 this.treeName = _treeName; | |
74 this.uuid = _uuid; | |
75 } | |
76 | |
77 public IEnumerator<TreeOperation> iterator() { | |
78 return log.GetEnumerator(); | |
79 } | |
80 | |
81 public string getTreeName() { | |
82 return treeName; | |
83 } | |
84 | |
85 public TreeOperationLog getLog() { | |
86 return log; | |
87 } | |
88 | |
89 public string uuids() { | |
90 return uuid; | |
91 } | |
92 } | |
93 } | |
94 } |